Skip to content

Commit 885c716

Browse files
dotdashgitster
authored andcommitted
Rename detection: Avoid repeated filespec population
In diffcore_rename, we assume that the blob contents in the filespec aren't required anymore after estimate_similarity has been called and thus we free it. But estimate_similarity might return early when the file sizes differ too much. In that case, cnt_data is never set and the next call to estimate_similarity will populate the filespec again, eventually rereading the same blob over and over again. To fix that, we first get the blob sizes and only when the blob contents are actually required, and when cnt_data will be set, the full filespec is populated, once. Signed-off-by: Björn Steinbrink <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3aed2fd commit 885c716

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

diffcore-rename.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ static int estimate_similarity(struct diff_filespec *src,
153153
* is a possible size - we really should have a flag to
154154
* say whether the size is valid or not!)
155155
*/
156-
if (!src->cnt_data && diff_populate_filespec(src, 0))
156+
if (!src->cnt_data && diff_populate_filespec(src, 1))
157157
return 0;
158-
if (!dst->cnt_data && diff_populate_filespec(dst, 0))
158+
if (!dst->cnt_data && diff_populate_filespec(dst, 1))
159159
return 0;
160160

161161
max_size = ((src->size > dst->size) ? src->size : dst->size);
@@ -173,6 +173,11 @@ static int estimate_similarity(struct diff_filespec *src,
173173
if (base_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE)
174174
return 0;
175175

176+
if (!src->cnt_data && diff_populate_filespec(src, 0))
177+
return 0;
178+
if (!dst->cnt_data && diff_populate_filespec(dst, 0))
179+
return 0;
180+
176181
delta_limit = (unsigned long)
177182
(base_size * (MAX_SCORE-minimum_score) / MAX_SCORE);
178183
if (diffcore_count_changes(src, dst,

0 commit comments

Comments
 (0)