@matheusbsbs / matheus-bagliano / commits / 6bfce93e04
Fork 0

Move buffer_is_binary() to xdiff-interface.h

We already have two instances where we want to determine if a buffer contains binary data as opposed to text. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 5, 2007 at 03:36 UTC 6bfce93e04d13ecb42008a3cf214cc892f480f0c
4 files changed +11 -17
diff.c
+1 -6
@@ -1107,10 +1107,8 @@ static void setup_diff_attr_check(struct git_attr_check *check)
1107 check->attr = attr_diff;
1108 }
1109
1110 -#define FIRST_FEW_BYTES 8000
1110 static int file_is_binary(struct diff_filespec *one)
1111 {
1113 - unsigned long sz;
1112 struct git_attr_check attr_diff_check;
1113
1114 setup_diff_attr_check(&attr_diff_check);
@@ -1127,10 +1125,7 @@ static int file_is_binary(struct diff_filespec *one)
1125 return 0;
1126 diff_populate_filespec(one, 0);
1127 }
1130 - sz = one->size;
1131 - if (FIRST_FEW_BYTES < sz)
1132 - sz = FIRST_FEW_BYTES;
1133 - return !!memchr(one->data, 0, sz);
1128 + return buffer_is_binary(one->data, one->size);
1129 }
1130
1131 static void builtin_diff(const char *name_a,
grep.c
+1 -11
@@ -1,5 +1,6 @@
1 #include "cache.h"
2 #include "grep.h"
3 +#include "xdiff-interface.h"
4
5 void append_grep_pattern(struct grep_opt *opt, const char *pat,
6 const char *origin, int no, enum grep_pat_token t)
@@ -232,17 +233,6 @@ static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
233 printf("%.*s\n", (int)(eol-bol), bol);
234 }
235
235 -/*
236 - * NEEDSWORK: share code with diff.c
237 - */
238 -#define FIRST_FEW_BYTES 8000
239 -static int buffer_is_binary(const char *ptr, unsigned long size)
240 -{
241 - if (FIRST_FEW_BYTES < size)
242 - size = FIRST_FEW_BYTES;
243 - return !!memchr(ptr, 0, size);
244 -}
245 -
236 static int fixmatch(const char *pattern, char *line, regmatch_t *match)
237 {
238 char *hit = strstr(line, pattern);
xdiff-interface.c
+8
@@ -122,4 +122,12 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
122 return 0;
123 }
124
125 +#define FIRST_FEW_BYTES 8000
126 +int buffer_is_binary(const char *ptr, unsigned long size)
127 +{
128 + if (FIRST_FEW_BYTES < size)
129 + size = FIRST_FEW_BYTES;
130 + return !!memchr(ptr, 0, size);
131 +}
132 +
133
xdiff-interface.h
+1
@@ -18,5 +18,6 @@ int parse_hunk_header(char *line, int len,
18 int *ob, int *on,
19 int *nb, int *nn);
20 int read_mmfile(mmfile_t *ptr, const char *filename);
21 +int buffer_is_binary(const char *ptr, unsigned long size);
22
23 #endif