diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-03-05 09:30:17 -0800 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-05 09:30:17 -0800 |
commit | c4c4bc1fd83a6682c72702cc8d25b784c9ba3cbb (patch) | |
tree | 9a41021df02a0f130d17ccabf7255d0787e709c3 /src/diff_output.c | |
parent | 28b486b2e2376f11cb86f6116763421c2fed7218 (diff) | |
download | libgit2-c4c4bc1fd83a6682c72702cc8d25b784c9ba3cbb.tar.gz |
Convert from strnlen to git_text_is_binary
Since strnlen is not supported on all platforms and since we
now have the shiny new git_text_is_binary in the filtering
code, let's convert diff binary detection to use the new stuff.
Diffstat (limited to 'src/diff_output.c')
-rw-r--r-- | src/diff_output.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/diff_output.c b/src/diff_output.c index 684de0cc4..2c6bacc81 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -13,6 +13,7 @@ #include "diff.h" #include "map.h" #include "fileops.h" +#include "filter.h" typedef struct { git_diff_list *diff; @@ -161,19 +162,30 @@ static int file_is_binary_by_content( git_map *old_data, git_map *new_data) { + git_buf search; + git_text_stats stats; + GIT_UNUSED(diff); if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) { - size_t search_len = min(old_data->len, 4000); - if (strnlen(old_data->data, search_len) != search_len) + search.ptr = old_data->data; + search.size = min(old_data->len, 4000); + + git_text_gather_stats(&stats, &search); + + if (git_text_is_binary(&stats)) delta->old_file.flags |= GIT_DIFF_FILE_BINARY; else delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY; } if ((delta->new_file.flags & BINARY_DIFF_FLAGS) == 0) { - size_t search_len = min(new_data->len, 4000); - if (strnlen(new_data->data, search_len) != search_len) + search.ptr = new_data->data; + search.size = min(new_data->len, 4000); + + git_text_gather_stats(&stats, &search); + + if (git_text_is_binary(&stats)) delta->new_file.flags |= GIT_DIFF_FILE_BINARY; else delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY; |