Browse Source

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 6bfce93e from 'master']

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Johannes Schindelin 18 years ago committed by Junio C Hamano
parent
commit
634cd48a8a
  1. 7
      diff.c
  2. 12
      grep.c
  3. 8
      xdiff-interface.c
  4. 1
      xdiff-interface.h

7
diff.c

@ -1107,10 +1107,8 @@ static void setup_diff_attr_check(struct git_attr_check *check) @@ -1107,10 +1107,8 @@ static void setup_diff_attr_check(struct git_attr_check *check)
check->attr = attr_diff;
}

#define FIRST_FEW_BYTES 8000
static int file_is_binary(struct diff_filespec *one)
{
unsigned long sz;
struct git_attr_check attr_diff_check;

setup_diff_attr_check(&attr_diff_check);
@ -1127,10 +1125,7 @@ static int file_is_binary(struct diff_filespec *one) @@ -1127,10 +1125,7 @@ static int file_is_binary(struct diff_filespec *one)
return 0;
diff_populate_filespec(one, 0);
}
sz = one->size;
if (FIRST_FEW_BYTES < sz)
sz = FIRST_FEW_BYTES;
return !!memchr(one->data, 0, sz);
return buffer_is_binary(one->data, one->size);
}

static void builtin_diff(const char *name_a,

12
grep.c

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
#include "cache.h"
#include "grep.h"
#include "xdiff-interface.h"

void append_grep_pattern(struct grep_opt *opt, const char *pat,
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, @@ -232,17 +233,6 @@ static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
printf("%.*s\n", (int)(eol-bol), bol);
}

/*
* NEEDSWORK: share code with diff.c
*/
#define FIRST_FEW_BYTES 8000
static int buffer_is_binary(const char *ptr, unsigned long size)
{
if (FIRST_FEW_BYTES < size)
size = FIRST_FEW_BYTES;
return !!memchr(ptr, 0, size);
}

static int fixmatch(const char *pattern, char *line, regmatch_t *match)
{
char *hit = strstr(line, pattern);

8
xdiff-interface.c

@ -122,4 +122,12 @@ int read_mmfile(mmfile_t *ptr, const char *filename) @@ -122,4 +122,12 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
return 0;
}

#define FIRST_FEW_BYTES 8000
int buffer_is_binary(const char *ptr, unsigned long size)
{
if (FIRST_FEW_BYTES < size)
size = FIRST_FEW_BYTES;
return !!memchr(ptr, 0, size);
}



1
xdiff-interface.h

@ -18,5 +18,6 @@ int parse_hunk_header(char *line, int len, @@ -18,5 +18,6 @@ int parse_hunk_header(char *line, int len,
int *ob, int *on,
int *nb, int *nn);
int read_mmfile(mmfile_t *ptr, const char *filename);
int buffer_is_binary(const char *ptr, unsigned long size);

#endif

Loading…
Cancel
Save