@matheusbsbs / matheus-bagliano / commits / 2c3fa66f35
Fork 0

diff: honor binariness specified in attributes

The code shuffling mistakenly lost binariness specified with the attribute mecahnism and made it always guess from the data. Noticed by Johannes, with two test cases to t4020. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 7, 2007 at 12:25 UTC 2c3fa66f3577d1305fb0fac5a181261fb2597859
2 files changed +21 -5
diff.c
+9 -5
@@ -1162,6 +1162,7 @@ static void setup_diff_attr_check(struct git_attr_check *check)
1162 static void diff_filespec_check_attr(struct diff_filespec *one)
1163 {
1164 struct git_attr_check attr_diff_check;
1165 + int check_from_data = 0;
1166
1167 if (one->checked_attr)
1168 return;
@@ -1179,6 +1180,8 @@ static void diff_filespec_check_attr(struct diff_filespec *one)
1180 ;
1181 else if (ATTR_FALSE(value))
1182 one->is_binary = 1;
1183 + else
1184 + check_from_data = 1;
1185
1186 /* funcname pattern ident */
1187 if (ATTR_TRUE(value) || ATTR_FALSE(value) || ATTR_UNSET(value))
@@ -1187,12 +1190,13 @@ static void diff_filespec_check_attr(struct diff_filespec *one)
1190 one->funcname_pattern_ident = value;
1191 }
1192
1190 - if (!one->data && DIFF_FILE_VALID(one))
1191 - diff_populate_filespec(one, 0);
1192 -
1193 - if (one->data)
1194 - one->is_binary = buffer_is_binary(one->data, one->size);
1193 + if (check_from_data) {
1194 + if (!one->data && DIFF_FILE_VALID(one))
1195 + diff_populate_filespec(one, 0);
1196
1197 + if (one->data)
1198 + one->is_binary = buffer_is_binary(one->data, one->size);
1199 + }
1200 }
1201
1202 int diff_filespec_is_binary(struct diff_filespec *one)
t/t4020-diff-external.sh
+12
@@ -94,4 +94,16 @@ test_expect_success 'diff attribute should apply only to diff' '
94
95 '
96
97 +test_expect_success 'no diff with -diff' '
98 + echo >.gitattributes "file -diff" &&
99 + git diff | grep Binary
100 +'
101 +
102 +echo NULZbetweenZwords | tr Z '\0' > file
103 +
104 +test_expect_success 'force diff with "diff"' '
105 + echo >.gitattributes "file diff" &&
106 + git diff | grep -a second
107 +'
108 +
109 test_done