summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fa0c87c)
raw | patch | inline | side by side (parent: fa0c87c)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Tue, 5 Jun 2007 02:36:11 +0000 (03:36 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 16 Jun 2007 06:27:23 +0000 (23:27 -0700) |
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>
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>
diff.c | patch | blob | history | |
grep.c | patch | blob | history | |
xdiff-interface.c | patch | blob | history | |
xdiff-interface.h | patch | blob | history |
index af282ddd8818aacdc516ff6f9dff4d84097cbab0..dc6da5e253c4a64440a2da9e2f785f3ea06bea61 100644 (file)
--- a/diff.c
+++ b/diff.c
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);
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,
index fcc676230282e4c5bda4f9f97c5ae65c1a6beb30..f67d6716ea5f42c3384a7a4cb2eb973b02785fba 100644 (file)
--- a/grep.c
+++ b/grep.c
#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)
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);
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 10816e95a07c23dda7554c102c306d7e9beca606..963bb89b08e64188ba278587f63f380653b019c6 100644 (file)
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
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);
+}
+
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 1918808081c00daf20a16a1592c0ed9be6d79be4..536f4e4d9784e0e5ffdc108a5be4bf758d1578ba 100644 (file)
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
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