@matheusbsbs / matheus-bagliano / commits / 10ae7526be
Fork 0

merge-recursive: option to specify rename threshold

The recursive merge strategy turns on rename detection but leaves the rename threshold at the default. Add a strategy option to allow the user to specify a rename threshold to use. Signed-off-by: Kevin Ballard <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Ballard committed Sep 27, 2010 at 16:58 UTC 10ae7526bebb505ddddba01f76ec97d5f7b5e0e5
5 files changed +16 -3
Documentation/merge-strategies.txt
+4
@@ -74,6 +74,10 @@ no-renormalize;;
74 Disables the `renormalize` option. This overrides the
75 `merge.renormalize` configuration variable.
76
77 +rename-threshold=<n>;;
78 + Controls the similarity threshold used for rename detection.
79 + See also linkgit:git-diff[1] `-M`.
80 +
81 subtree[=path];;
82 This option is a more advanced form of 'subtree' strategy, where
83 the strategy makes a guess on how two trees must be shifted to
diff.c
+3 -3
@@ -3219,7 +3219,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3219 return 1;
3220 }
3221
3222 -static int parse_num(const char **cp_p)
3222 +int parse_rename_score(const char **cp_p)
3223 {
3224 unsigned long num, scale;
3225 int ch, dot;
@@ -3265,7 +3265,7 @@ static int diff_scoreopt_parse(const char *opt)
3265 if (cmd != 'M' && cmd != 'C' && cmd != 'B')
3266 return -1; /* that is not a -M, -C nor -B option */
3267
3268 - opt1 = parse_num(&opt);
3268 + opt1 = parse_rename_score(&opt);
3269 if (cmd != 'B')
3270 opt2 = 0;
3271 else {
@@ -3275,7 +3275,7 @@ static int diff_scoreopt_parse(const char *opt)
3275 return -1; /* we expect -B80/99 or -B80 */
3276 else {
3277 opt++;
3278 - opt2 = parse_num(&opt);
3278 + opt2 = parse_rename_score(&opt);
3279 }
3280 }
3281 if (*opt != 0)
diff.h
+2
@@ -301,4 +301,6 @@ extern size_t fill_textconv(struct userdiff_driver *driver,
301
302 extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
303
304 +extern int parse_rename_score(const char **cp_p);
305 +
306 #endif /* DIFF_H */
merge-recursive.c
+6
@@ -339,6 +339,7 @@ static struct string_list *get_renames(struct merge_options *o,
339 opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
340 o->diff_rename_limit >= 0 ? o->diff_rename_limit :
341 500;
342 + opts.rename_score = o->rename_score;
343 opts.warn_on_too_large_rename = 1;
344 opts.output_format = DIFF_FORMAT_NO_OUTPUT;
345 if (diff_setup_done(&opts) < 0)
@@ -1525,6 +1526,11 @@ int parse_merge_opt(struct merge_options *o, const char *s)
1526 o->renormalize = 1;
1527 else if (!strcmp(s, "no-renormalize"))
1528 o->renormalize = 0;
1529 + else if (!prefixcmp(s, "rename-threshold=")) {
1530 + const char *score = s + strlen("rename-threshold=");
1531 + if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
1532 + return -1;
1533 + }
1534 else
1535 return -1;
1536 return 0;
merge-recursive.h
+1
@@ -19,6 +19,7 @@ struct merge_options {
19 int verbosity;
20 int diff_rename_limit;
21 int merge_rename_limit;
22 + int rename_score;
23 int call_depth;
24 struct strbuf obuf;
25 struct string_list current_file_set;