aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-04-21 17:38:00 -0700
committerJunio C Hamano <junkio@cox.net>2007-04-21 17:38:00 -0700
commita2d7c6c62080b542007f9787342aa1e57b95f50c (patch)
tree22348e2f38132cd45dcf74cf0c02475d95dbce5b /diff.c
parentafb5b6a24bd333d298d10acac731f1c127bbb82d (diff)
parent5e635e396020cc08bc21a3e67c20c5294d6d13fd (diff)
downloadgit-a2d7c6c62080b542007f9787342aa1e57b95f50c.tar.gz
git-a2d7c6c62080b542007f9787342aa1e57b95f50c.tar.xz
Merge branch 'jc/attr'
* 'jc/attr': (28 commits) lockfile: record the primary process. convert.c: restructure the attribute checking part. Fix bogus linked-list management for user defined merge drivers. Simplify calling of CR/LF conversion routines Document gitattributes(5) Update 'crlf' attribute semantics. Documentation: support manual section (5) - file formats. Simplify code to find recursive merge driver. Counto-fix in merge-recursive Fix funny types used in attribute value representation Allow low-level driver to specify different behaviour during internal merge. Custom low-level merge driver: change the configuration scheme. Allow the default low-level merge driver to be configured. Custom low-level merge driver support. Add a demonstration/test of customized merge. Allow specifying specialized merge-backend per path. merge-recursive: separate out xdl_merge() interface. Allow more than true/false to attributes. Document git-check-attr Change attribute negation marker from '!' to '-'. ...
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/diff.c b/diff.c
index 1e8e689be..f51666496 100644
--- a/diff.c
+++ b/diff.c
@@ -8,6 +8,7 @@
#include "delta.h"
#include "xdiff-interface.h"
#include "color.h"
+#include "attr.h"
#ifdef NO_FAST_WORKING_DIRECTORY
#define FAST_WORKING_DIRECTORY 0
@@ -1051,13 +1052,44 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
emit_binary_diff_body(two, one);
}
+static void setup_diff_attr_check(struct git_attr_check *check)
+{
+ static struct git_attr *attr_diff;
+
+ if (!attr_diff)
+ attr_diff = git_attr("diff", 4);
+ check->attr = attr_diff;
+}
+
#define FIRST_FEW_BYTES 8000
-static int mmfile_is_binary(mmfile_t *mf)
+static int file_is_binary(struct diff_filespec *one)
{
- long sz = mf->size;
+ unsigned long sz;
+ struct git_attr_check attr_diff_check;
+
+ setup_diff_attr_check(&attr_diff_check);
+ if (!git_checkattr(one->path, 1, &attr_diff_check)) {
+ const char *value = attr_diff_check.value;
+ if (ATTR_TRUE(value))
+ return 0;
+ else if (ATTR_FALSE(value))
+ return 1;
+ else if (ATTR_UNSET(value))
+ ;
+ else
+ die("unknown value %s given to 'diff' attribute",
+ value);
+ }
+
+ if (!one->data) {
+ if (!DIFF_FILE_VALID(one))
+ return 0;
+ diff_populate_filespec(one, 0);
+ }
+ sz = one->size;
if (FIRST_FEW_BYTES < sz)
sz = FIRST_FEW_BYTES;
- return !!memchr(mf->ptr, 0, sz);
+ return !!memchr(one->data, 0, sz);
}
static void builtin_diff(const char *name_a,
@@ -1114,7 +1146,7 @@ static void builtin_diff(const char *name_a,
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
die("unable to read files to diff");
- if (!o->text && (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))) {
+ if (!o->text && (file_is_binary(one) || file_is_binary(two))) {
/* Quite common confusing case */
if (mf1.size == mf2.size &&
!memcmp(mf1.ptr, mf2.ptr, mf1.size))
@@ -1190,7 +1222,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
die("unable to read files to diff");
- if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) {
+ if (file_is_binary(one) || file_is_binary(two)) {
data->is_binary = 1;
data->added = mf2.size;
data->deleted = mf1.size;
@@ -1228,7 +1260,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
die("unable to read files to diff");
- if (mmfile_is_binary(&mf2))
+ if (file_is_binary(two))
return;
else {
/* Crazy xdl interfaces.. */
@@ -1481,9 +1513,9 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
/*
* Convert from working tree format to canonical git format
*/
- buf = s->data;
size = s->size;
- if (convert_to_git(s->path, &buf, &size)) {
+ buf = convert_to_git(s->path, s->data, &size);
+ if (buf) {
munmap(s->data, s->size);
s->should_munmap = 0;
s->data = buf;
@@ -1825,8 +1857,8 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
if (o->binary) {
mmfile_t mf;
- if ((!fill_mmfile(&mf, one) && mmfile_is_binary(&mf)) ||
- (!fill_mmfile(&mf, two) && mmfile_is_binary(&mf)))
+ if ((!fill_mmfile(&mf, one) && file_is_binary(one)) ||
+ (!fill_mmfile(&mf, two) && file_is_binary(two)))
abbrev = 40;
}
len += snprintf(msg + len, sizeof(msg) - len,
@@ -2721,7 +2753,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
return error("unable to read files to diff");
/* Maybe hash p->two? into the patch id? */
- if (mmfile_is_binary(&mf2))
+ if (file_is_binary(p->two))
continue;
len1 = remove_space(p->one->path, strlen(p->one->path));