diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buf_text.c | 5 | ||||
-rw-r--r-- | src/buf_text.h | 8 | ||||
-rw-r--r-- | src/diff_output.c | 7 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/buf_text.c b/src/buf_text.c index a7122dc0c..0104a9057 100644 --- a/src/buf_text.c +++ b/src/buf_text.c @@ -109,6 +109,11 @@ bool git_buf_text_is_binary(const git_buf *buf) return ((printable >> 7) < nonprintable); } +bool git_buf_text_contains_nul(const git_buf *buf) +{ + return (strnlen(buf->ptr, buf->size) != buf->size); +} + int git_buf_text_detect_bom(git_bom_t *bom, const git_buf *buf, size_t offset) { const char *ptr; diff --git a/src/buf_text.h b/src/buf_text.h index ae5e6ca30..458ee33c9 100644 --- a/src/buf_text.h +++ b/src/buf_text.h @@ -71,6 +71,14 @@ extern int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strs); extern bool git_buf_text_is_binary(const git_buf *buf); /** + * Check quickly if buffer contains a NUL byte + * + * @param buf Buffer to check + * @return true if buffer contains a NUL byte + */ +extern bool git_buf_text_contains_nul(const git_buf *buf); + +/** * Check if a buffer begins with a UTF BOM * * @param bom Set to the type of BOM detected or GIT_BOM_NONE diff --git a/src/diff_output.c b/src/diff_output.c index d75a7bb94..933d44ee5 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -142,7 +142,12 @@ static int diff_delta_is_binary_by_content( GIT_UNUSED(ctxt); if ((file->flags & KNOWN_BINARY_FLAGS) == 0) { - if (git_buf_text_is_binary(&search)) + /* TODO: provide encoding / binary detection callbacks that can + * be UTF-8 aware, etc. For now, instead of trying to be smart, + * let's just use the simple NUL-byte detection that core git uses. + */ + /* previously was: if (git_buf_text_is_binary(&search)) */ + if (git_buf_text_contains_nul(&search)) file->flags |= GIT_DIFF_FILE_BINARY; else file->flags |= GIT_DIFF_FILE_NOT_BINARY; |