diff: Only count lines in show_shortstats
Do not mix byte and line counts. Binary files have byte counts; skip them when accumulating line insertions/deletions. The regression was introduced in e18872b. Signed-off-by: Alexander Strasser <eclipse7@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alexander Strasser committed
Jun 15, 2012 at 23:50 UTC
de9658b511377e9eaa2c58a8c3885a1a01b94be8
2 files changed
+13
-1
diff.c
+1
-1
@@ -1668,7 +1668,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
1668
continue;
1669
if (!data->files[i]->is_renamed && (added + deleted == 0)) {
1670
total_files--;
1671
- } else {
1671
+ } else if (!data->files[i]->is_binary) { /* don't count bytes */
1672
adds += added;
1673
dels += deleted;
1674
}
t/t4012-diff-binary.sh
+12
@@ -36,6 +36,18 @@ test_expect_success '"apply --stat" output for binary file change' '
36
test_i18ncmp expected current
37
'
38
39
+test_expect_success 'diff --shortstat output for binary file change' '
40
+ echo " 4 files changed, 2 insertions(+), 2 deletions(-)" >expected &&
41
+ git diff --shortstat >current &&
42
+ test_i18ncmp expected current
43
+'
44
+
45
+test_expect_success 'diff --shortstat output for binary file change only' '
46
+ echo " 1 file changed, 0 insertions(+), 0 deletions(-)" >expected &&
47
+ git diff --shortstat -- b >current &&
48
+ test_i18ncmp expected current
49
+'
50
+
51
test_expect_success 'apply --numstat notices binary file change' '
52
git diff >diff &&
53
git apply --numstat <diff >current &&