Skip to content

Commit 10ae752

Browse files
lilyballgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4e5dd04 commit 10ae752

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

Documentation/merge-strategies.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ no-renormalize;;
7474
Disables the `renormalize` option. This overrides the
7575
`merge.renormalize` configuration variable.
7676

77+
rename-threshold=<n>;;
78+
Controls the similarity threshold used for rename detection.
79+
See also linkgit:git-diff[1] `-M`.
80+
7781
subtree[=path];;
7882
This option is a more advanced form of 'subtree' strategy, where
7983
the strategy makes a guess on how two trees must be shifted to

diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
32193219
return 1;
32203220
}
32213221

3222-
static int parse_num(const char **cp_p)
3222+
int parse_rename_score(const char **cp_p)
32233223
{
32243224
unsigned long num, scale;
32253225
int ch, dot;
@@ -3265,7 +3265,7 @@ static int diff_scoreopt_parse(const char *opt)
32653265
if (cmd != 'M' && cmd != 'C' && cmd != 'B')
32663266
return -1; /* that is not a -M, -C nor -B option */
32673267

3268-
opt1 = parse_num(&opt);
3268+
opt1 = parse_rename_score(&opt);
32693269
if (cmd != 'B')
32703270
opt2 = 0;
32713271
else {
@@ -3275,7 +3275,7 @@ static int diff_scoreopt_parse(const char *opt)
32753275
return -1; /* we expect -B80/99 or -B80 */
32763276
else {
32773277
opt++;
3278-
opt2 = parse_num(&opt);
3278+
opt2 = parse_rename_score(&opt);
32793279
}
32803280
}
32813281
if (*opt != 0)

diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,6 @@ extern size_t fill_textconv(struct userdiff_driver *driver,
301301

302302
extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
303303

304+
extern int parse_rename_score(const char **cp_p);
305+
304306
#endif /* DIFF_H */

merge-recursive.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ static struct string_list *get_renames(struct merge_options *o,
339339
opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
340340
o->diff_rename_limit >= 0 ? o->diff_rename_limit :
341341
500;
342+
opts.rename_score = o->rename_score;
342343
opts.warn_on_too_large_rename = 1;
343344
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
344345
if (diff_setup_done(&opts) < 0)
@@ -1525,6 +1526,11 @@ int parse_merge_opt(struct merge_options *o, const char *s)
15251526
o->renormalize = 1;
15261527
else if (!strcmp(s, "no-renormalize"))
15271528
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+
}
15281534
else
15291535
return -1;
15301536
return 0;

merge-recursive.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct merge_options {
1919
int verbosity;
2020
int diff_rename_limit;
2121
int merge_rename_limit;
22+
int rename_score;
2223
int call_depth;
2324
struct strbuf obuf;
2425
struct string_list current_file_set;

0 commit comments

Comments
 (0)