@matheusbsbs / matheus-bagliano / commits / 4d0f39cecf
Fork 0

diffcore-break: similarity estimator fix.

This is a companion patch to the previous fix to diffcore-rename. The merging-back process should use a logic similar to what is used there. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 4, 2006 at 01:03 UTC 4d0f39cecf93222401a81216e5cf2528e8abc6ae
2 files changed +28 -21
diffcore-break.c
+26 -19
@@ -45,8 +45,8 @@ static int should_break(struct diff_filespec *src,
45 * The value we return is 1 if we want the pair to be broken,
46 * or 0 if we do not.
47 */
48 - unsigned long delta_size, base_size, src_copied, literal_added;
49 - int to_break = 0;
48 + unsigned long delta_size, base_size, src_copied, literal_added,
49 + src_removed;
50
51 *merge_score_p = 0; /* assume no deletion --- "do not break"
52 * is the default.
@@ -72,33 +72,40 @@ static int should_break(struct diff_filespec *src,
72 &src_copied, &literal_added))
73 return 0;
74
75 + /* sanity */
76 + if (src->size < src_copied)
77 + src_copied = src->size;
78 + if (dst->size < literal_added + src_copied) {
79 + if (src_copied < dst->size)
80 + literal_added = dst->size - src_copied;
81 + else
82 + literal_added = 0;
83 + }
84 + src_removed = src->size - src_copied;
85 +
86 /* Compute merge-score, which is "how much is removed
87 * from the source material". The clean-up stage will
88 * merge the surviving pair together if the score is
89 * less than the minimum, after rename/copy runs.
90 */
80 - if (src->size <= src_copied)
81 - ; /* all copied, nothing removed */
82 - else {
83 - delta_size = src->size - src_copied;
84 - *merge_score_p = delta_size * MAX_SCORE / src->size;
85 - }
86 -
91 + *merge_score_p = src_removed * MAX_SCORE / src->size;
92 +
93 /* Extent of damage, which counts both inserts and
94 * deletes.
95 */
90 - if (src->size + literal_added <= src_copied)
91 - delta_size = 0; /* avoid wrapping around */
92 - else
93 - delta_size = (src->size - src_copied) + literal_added;
94 -
95 - /* We break if the edit exceeds the minimum.
96 - * i.e. (break_score / MAX_SCORE < delta_size / base_size)
96 + delta_size = src_removed + literal_added;
97 + if (delta_size * MAX_SCORE / base_size < break_score)
98 + return 0;
99 +
100 + /* If you removed a lot without adding new material, that is
101 + * not really a rewrite.
102 */
98 - if (break_score * base_size < delta_size * MAX_SCORE)
99 - to_break = 1;
103 + if ((src->size * break_score < src_removed * MAX_SCORE) &&
104 + (literal_added * 20 < src_removed) &&
105 + (literal_added * 20 < src_copied))
106 + return 0;
107
101 - return to_break;
108 + return 1;
109 }
110
111 void diffcore_break(int break_score)
diffcore.h
+2 -2
@@ -17,8 +17,8 @@
17 */
18 #define MAX_SCORE 60000.0
19 #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
20 -#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%)*/
21 -#define DEFAULT_MERGE_SCORE 48000 /* maximum for break-merge to happen (80%)*/
20 +#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
21 +#define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen 60%) */
22
23 #define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
24