Skip to content

Commit 634cd48

Browse files
dschogitster
authored andcommitted
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. [jc: cherry-picked 6bfce93 from 'master'] Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa0c87c commit 634cd48

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

diff.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,8 @@ static void setup_diff_attr_check(struct git_attr_check *check)
11071107
check->attr = attr_diff;
11081108
}
11091109

1110-
#define FIRST_FEW_BYTES 8000
11111110
static int file_is_binary(struct diff_filespec *one)
11121111
{
1113-
unsigned long sz;
11141112
struct git_attr_check attr_diff_check;
11151113

11161114
setup_diff_attr_check(&attr_diff_check);
@@ -1127,10 +1125,7 @@ static int file_is_binary(struct diff_filespec *one)
11271125
return 0;
11281126
diff_populate_filespec(one, 0);
11291127
}
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);
11341129
}
11351130

11361131
static void builtin_diff(const char *name_a,

grep.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "grep.h"
3+
#include "xdiff-interface.h"
34

45
void append_grep_pattern(struct grep_opt *opt, const char *pat,
56
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,
232233
printf("%.*s\n", (int)(eol-bol), bol);
233234
}
234235

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-
246236
static int fixmatch(const char *pattern, char *line, regmatch_t *match)
247237
{
248238
char *hit = strstr(line, pattern);

xdiff-interface.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,12 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
122122
return 0;
123123
}
124124

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+
125133

xdiff-interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ int parse_hunk_header(char *line, int len,
1818
int *ob, int *on,
1919
int *nb, int *nn);
2020
int read_mmfile(mmfile_t *ptr, const char *filename);
21+
int buffer_is_binary(const char *ptr, unsigned long size);
2122

2223
#endif

0 commit comments

Comments
 (0)