diffcore-rename: don't change similarity index based on basename equality
This implements a suggestion from Johannes. It uses a separate field in struct diff_score to keep the result of the file name comparison in the rename detection logic. This reverts the value of the similarity index to be a function of file contents, only, and basename comparison is only used to decide between files with equal amounts of content changes. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 25, 2007 at 00:23 UTC
cfc0aef1ffb8a9fe2792667597a05bbf3b6b1258
1 file changed
+7
-4
diffcore-rename.c
+7
-4
@@ -138,6 +138,7 @@ struct diff_score {
138
int src; /* index in rename_src */
139
int dst; /* index in rename_dst */
140
int score;
141
+ int name_score;
142
};
143
144
static int estimate_similarity(struct diff_filespec *src,
@@ -201,11 +202,8 @@ static int estimate_similarity(struct diff_filespec *src,
202
*/
203
if (!dst->size)
204
score = 0; /* should not happen */
204
- else {
205
+ else
206
score = (int)(src_copied * MAX_SCORE / max_size);
206
- if (basename_same(src, dst))
207
- score++;
208
- }
207
return score;
208
}
209
@@ -242,6 +240,10 @@ static void record_rename_pair(int dst_index, int src_index, int score)
240
static int score_compare(const void *a_, const void *b_)
241
{
242
const struct diff_score *a = a_, *b = b_;
243
+
244
+ if (a->score == b->score)
245
+ return b->name_score - a->name_score;
246
+
247
return b->score - a->score;
248
}
249
@@ -360,6 +362,7 @@ void diffcore_rename(struct diff_options *options)
362
m->dst = i;
363
m->score = estimate_similarity(one, two,
364
minimum_score);
365
+ m->name_score = basename_same(one, two);
366
diff_free_filespec_data(one);
367
}
368
/* We do not need the text anymore */