Skip to content

Commit

Permalink
diffcore-break: save cnt_data for other phases
Browse files Browse the repository at this point in the history
The "break" phase works by counting changes between two
blobs with the same path. We do this by splitting the file
into chunks (or lines for text oriented files) and then
keeping a count of chunk hashes.

The "rename" phase counts changes between blobs at two
different paths. However, it uses the exact same set of
chunk hashes (which are immutable for a given sha1).

The rename phase can therefore use the same hash data as
break. Unfortunately, we were throwing this data away after
computing it in the break phase. This patch instead attaches
it to the filespec and lets it live through the rename
phase, working under the assumption that most of the time
that breaks are being computed, renames will be too.

We only do this optimization for files which have actually
been broken, as those ones will be candidates for rename
detection (and it is a time-space tradeoff, so we don't want
to waste space keeping useless data).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Nov 16, 2009
1 parent f4f19fb commit 8282de9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions diffcore-break.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static int should_break(struct diff_filespec *src,
return 0; /* we do not break too small filepair */

if (diffcore_count_changes(src, dst,
NULL, NULL,
&src->cnt_data, &dst->cnt_data,
0,
&src_copied, &literal_added))
return 0;
Expand Down Expand Up @@ -204,8 +204,8 @@ void diffcore_break(int break_score)
dp->score = score;
dp->broken_pair = 1;

diff_free_filespec_data(p->one);
diff_free_filespec_data(p->two);
diff_free_filespec_blob(p->one);
diff_free_filespec_blob(p->two);
free(p); /* not diff_free_filepair(), we are
* reusing one and two here.
*/
Expand Down

0 comments on commit 8282de9

Please sign in to comment.