Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.

Commit 77cd6ab

Browse files
torvaldsgitster
authored andcommitted
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: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 952dfc6 commit 77cd6ab

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

diffcore-delta.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,15 @@ int diffcore_count_changes(struct diff_filespec *src,
201201
while (d->cnt) {
202202
if (d->hashval >= s->hashval)
203203
break;
204+
la += d->cnt;
204205
d++;
205206
}
206207
src_cnt = s->cnt;
207-
dst_cnt = d->hashval == s->hashval ? d->cnt : 0;
208+
dst_cnt = 0;
209+
if (d->cnt && d->hashval == s->hashval) {
210+
dst_cnt = d->cnt;
211+
d++;
212+
}
208213
if (src_cnt < dst_cnt) {
209214
la += dst_cnt - src_cnt;
210215
sc += src_cnt;
@@ -213,6 +218,10 @@ int diffcore_count_changes(struct diff_filespec *src,
213218
sc += dst_cnt;
214219
s++;
215220
}
221+
while (d->cnt) {
222+
la += d->cnt;
223+
d++;
224+
}
216225

217226
if (!src_count_p)
218227
free(src_count);

0 commit comments

Comments
 (0)