Commit 77cd6ab6 authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano

Fix diff -B/--dirstat miscounting of newly added contents

What used to happen is that diffcore_count_changes() simply ignored any
hashes in the destination that didn't match hashes in the source. EXCEPT
if the source hash didn't exist at all, in which case it would count _one_
destination hash that happened to have the "next" hash value.  As a
consequence, newly added material was often undercounted, making output
from --dirstat and "complete rewrite" detection used by -B unrelialble.

This changes it so that:

 - whenever it bypasses a destination hash (because it doesn't match a
   source), it counts the bytes associated with that as "literal added"

 - at the end (once we have used up all the source hashes), we do the same
   thing with the remaining destination hashes.

 - when hashes do match, and we use the difference in counts as a value,
   we also use up that destination hash entry (the 'd++').
Signed-off-by: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 952dfc69
......@@ -201,10 +201,15 @@ int diffcore_count_changes(struct diff_filespec *src,
while (d->cnt) {
if (d->hashval >= s->hashval)
la += d->cnt;
src_cnt = s->cnt;
dst_cnt = d->hashval == s->hashval ? d->cnt : 0;
dst_cnt = 0;
if (d->cnt && d->hashval == s->hashval) {
dst_cnt = d->cnt;
if (src_cnt < dst_cnt) {
la += dst_cnt - src_cnt;
sc += src_cnt;
......@@ -213,6 +218,10 @@ int diffcore_count_changes(struct diff_filespec *src,
sc += dst_cnt;
while (d->cnt) {
la += d->cnt;
if (!src_count_p)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment