Skip to content

Commit de9658b

Browse files
beastdgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e18872b commit de9658b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
16681668
continue;
16691669
if (!data->files[i]->is_renamed && (added + deleted == 0)) {
16701670
total_files--;
1671-
} else {
1671+
} else if (!data->files[i]->is_binary) { /* don't count bytes */
16721672
adds += added;
16731673
dels += deleted;
16741674
}

t/t4012-diff-binary.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ test_expect_success '"apply --stat" output for binary file change' '
3636
test_i18ncmp expected current
3737
'
3838

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+
3951
test_expect_success 'apply --numstat notices binary file change' '
4052
git diff >diff &&
4153
git apply --numstat <diff >current &&

0 commit comments

Comments
 (0)