Skip to content

Commit 329351f

Browse files
committed
Merge branch 'kb/merge-recursive-rename-threshold'
* kb/merge-recursive-rename-threshold: diff: add synonyms for -M, -C, -B merge-recursive: option to specify rename threshold Conflicts: Documentation/diff-options.txt Documentation/merge-strategies.txt
2 parents 9b1054d + 37ab515 commit 329351f

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

Documentation/diff-options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ endif::git-format-patch[]
207207
digits can be specified with `--abbrev=<n>`.
208208

209209
-B[<n>][/<m>]::
210+
--break-rewrites[=[<n>][/<m>]]::
210211
Break complete rewrite changes into pairs of delete and
211212
create. This serves two purposes:
212213
+
@@ -229,6 +230,7 @@ eligible for being picked up as a possible source of a rename to
229230
another file.
230231

231232
-M[<n>]::
233+
--detect-renames[=<n>]::
232234
ifndef::git-log[]
233235
Detect renames.
234236
endif::git-log[]
@@ -244,6 +246,7 @@ endif::git-log[]
244246
hasn't changed.
245247

246248
-C[<n>]::
249+
--detect-copies[=<n>]::
247250
Detect copies as well as renames. See also `--find-copies-harder`.
248251
If `n` is specified, it has the same meaning as for `-M<n>`.
249252

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: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,16 +3140,19 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
31403140
return stat_opt(options, av);
31413141

31423142
/* renames options */
3143-
else if (!prefixcmp(arg, "-B")) {
3143+
else if (!prefixcmp(arg, "-B") || !prefixcmp(arg, "--break-rewrites=") ||
3144+
!strcmp(arg, "--break-rewrites")) {
31443145
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
31453146
return -1;
31463147
}
3147-
else if (!prefixcmp(arg, "-M")) {
3148+
else if (!prefixcmp(arg, "-M") || !prefixcmp(arg, "--detect-renames=") ||
3149+
!strcmp(arg, "--detect-renames")) {
31483150
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
31493151
return -1;
31503152
options->detect_rename = DIFF_DETECT_RENAME;
31513153
}
3152-
else if (!prefixcmp(arg, "-C")) {
3154+
else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--detect-copies=") ||
3155+
!strcmp(arg, "--detect-copies")) {
31533156
if (options->detect_rename == DIFF_DETECT_COPY)
31543157
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
31553158
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
@@ -3323,7 +3326,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
33233326
return 1;
33243327
}
33253328

3326-
static int parse_num(const char **cp_p)
3329+
int parse_rename_score(const char **cp_p)
33273330
{
33283331
unsigned long num, scale;
33293332
int ch, dot;
@@ -3366,10 +3369,26 @@ static int diff_scoreopt_parse(const char *opt)
33663369
if (*opt++ != '-')
33673370
return -1;
33683371
cmd = *opt++;
3372+
if (cmd == '-') {
3373+
/* convert the long-form arguments into short-form versions */
3374+
if (!prefixcmp(opt, "break-rewrites")) {
3375+
opt += strlen("break-rewrites");
3376+
if (*opt == 0 || *opt++ == '=')
3377+
cmd = 'B';
3378+
} else if (!prefixcmp(opt, "detect-copies")) {
3379+
opt += strlen("detect-copies");
3380+
if (*opt == 0 || *opt++ == '=')
3381+
cmd = 'C';
3382+
} else if (!prefixcmp(opt, "detect-renames")) {
3383+
opt += strlen("detect-renames");
3384+
if (*opt == 0 || *opt++ == '=')
3385+
cmd = 'M';
3386+
}
3387+
}
33693388
if (cmd != 'M' && cmd != 'C' && cmd != 'B')
33703389
return -1; /* that is not a -M, -C nor -B option */
33713390

3372-
opt1 = parse_num(&opt);
3391+
opt1 = parse_rename_score(&opt);
33733392
if (cmd != 'B')
33743393
opt2 = 0;
33753394
else {
@@ -3379,7 +3398,7 @@ static int diff_scoreopt_parse(const char *opt)
33793398
return -1; /* we expect -B80/99 or -B80 */
33803399
else {
33813400
opt++;
3382-
opt2 = parse_num(&opt);
3401+
opt2 = parse_rename_score(&opt);
33833402
}
33843403
}
33853404
if (*opt != 0)

diff.h

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

316316
extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
317317

318+
extern int parse_rename_score(const char **cp_p);
319+
318320
#endif /* DIFF_H */

merge-recursive.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ static struct string_list *get_renames(struct merge_options *o,
334334
opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
335335
o->diff_rename_limit >= 0 ? o->diff_rename_limit :
336336
500;
337+
opts.rename_score = o->rename_score;
337338
opts.warn_on_too_large_rename = 1;
338339
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
339340
if (diff_setup_done(&opts) < 0)
@@ -1576,6 +1577,11 @@ int parse_merge_opt(struct merge_options *o, const char *s)
15761577
o->renormalize = 1;
15771578
else if (!strcmp(s, "no-renormalize"))
15781579
o->renormalize = 0;
1580+
else if (!prefixcmp(s, "rename-threshold=")) {
1581+
const char *score = s + strlen("rename-threshold=");
1582+
if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
1583+
return -1;
1584+
}
15791585
else
15801586
return -1;
15811587
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)