diffcore-rename: similarity estimator fix.
The "similarity" logic was giving added material way too much negative weight. What we wanted to see was how similar the post-change image was compared to the pre-change image, so the natural definition of similarity is how much common things are there, relative to the post-change image's size. This simplifies things a lot. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 2, 2006 at 22:11 UTC
1706306a54cfb5f1bf65f2b054aab2a5a7dba8e7
1 file changed
+8
-12
diffcore-rename.c
+8
-12
@@ -170,19 +170,15 @@ static int estimate_similarity(struct diff_filespec *src,
170
&src_copied, &literal_added))
171
return 0;
172
173
- /* Extent of damage */
174
- if (src->size + literal_added < src_copied)
175
- delta_size = 0;
176
- else
177
- delta_size = (src->size - src_copied) + literal_added;
178
-
179
- /*
180
- * Now we will give some score to it. 100% edit gets 0 points
181
- * and 0% edit gets MAX_SCORE points.
173
+ /* How similar are they?
174
+ * what percentage of material in dst are from source?
175
*/
183
- score = MAX_SCORE - (MAX_SCORE * delta_size / base_size);
184
- if (score < 0) return 0;
185
- if (MAX_SCORE < score) return MAX_SCORE;
176
+ if (dst->size < src_copied)
177
+ score = MAX_SCORE;
178
+ else if (!dst->size)
179
+ score = 0; /* should not happen */
180
+ else
181
+ score = src_copied * MAX_SCORE / dst->size;
182
return score;
183
}
184