summaryrefslogtreecommitdiff
path: root/diffcore-rename.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-05-24 19:09:32 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-25 00:47:05 (GMT)
commit85976974581060716311d6807b03a671cb71cbde (patch)
tree3e10a2cd51b3f118abea32bfbcf5873337bfe2ef /diffcore-rename.c
parentbba0f401eea22ddc345df8aa32ac0ccb2c73dc15 (diff)
downloadgit-85976974581060716311d6807b03a671cb71cbde.zip
git-85976974581060716311d6807b03a671cb71cbde.tar.gz
git-85976974581060716311d6807b03a671cb71cbde.tar.bz2
[PATCH] Update rename/copy similarity estimator.
The second round similarity estimator simply used the size of the xdelta itself to estimate the extent of damage. This patch keeps that logic to detect big insertions to terminate the check early, but otherwise looks at the generated delta in order to estimate the extent of edit more accurately. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'diffcore-rename.c')
-rw-r--r--diffcore-rename.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 34e83da..07782f4 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -5,6 +5,7 @@
#include "diff.h"
#include "diffcore.h"
#include "delta.h"
+#include "count-delta.h"
/* Table of rename/copy destinations */
@@ -158,13 +159,18 @@ static int estimate_similarity(struct diff_filespec *src,
delta = diff_delta(src->data, src->size,
dst->data, dst->size,
&delta_size);
- /*
- * We currently punt here, but we may later end up parsing the
- * delta to really assess the extent of damage. A big consecutive
- * remove would produce small delta_size that affects quite a
- * big portion of the file.
+
+ /* A delta that has a lot of literal additions would have
+ * big delta_size no matter what else it does.
*/
+ if (minimum_score < MAX_SCORE * delta_size / base_size)
+ return 0;
+
+ /* Estimate the edit size by interpreting delta. */
+ delta_size = count_delta(delta, delta_size);
free(delta);
+ if (delta_size == UINT_MAX)
+ return 0;
/*
* Now we will give some score to it. 100% edit gets 0 points