Skip to content

Commit 37ab515

Browse files
lilyballgitster
authored andcommitted
diff: add synonyms for -M, -C, -B
Add new long-form options --detect-renames[=<n>], --detect-copies[=<n>], and --break-rewrites[=[<n>][/<m>]] as synonyms for the -M, -C, and -B options (respectively). Signed-off-by: Kevin Ballard <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10ae752 commit 37ab515

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Documentation/diff-options.txt

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

209209
-B::
210+
--break-rewrites[=[<n>][/<m>]]::
210211
Break complete rewrite changes into pairs of delete and create.
211212

212213
-M::
214+
--detect-renames[=<n>]::
213215
ifndef::git-log[]
214216
Detect renames.
215217
endif::git-log[]
@@ -220,6 +222,7 @@ ifdef::git-log[]
220222
endif::git-log[]
221223

222224
-C::
225+
--detect-copies[=<n>]::
223226
Detect copies as well as renames. See also `--find-copies-harder`.
224227

225228
ifndef::git-format-patch[]

diff.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,16 +3059,19 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
30593059
}
30603060

30613061
/* renames options */
3062-
else if (!prefixcmp(arg, "-B")) {
3062+
else if (!prefixcmp(arg, "-B") || !prefixcmp(arg, "--break-rewrites=") ||
3063+
!strcmp(arg, "--break-rewrites")) {
30633064
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
30643065
return -1;
30653066
}
3066-
else if (!prefixcmp(arg, "-M")) {
3067+
else if (!prefixcmp(arg, "-M") || !prefixcmp(arg, "--detect-renames=") ||
3068+
!strcmp(arg, "--detect-renames")) {
30673069
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
30683070
return -1;
30693071
options->detect_rename = DIFF_DETECT_RENAME;
30703072
}
3071-
else if (!prefixcmp(arg, "-C")) {
3073+
else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--detect-copies=") ||
3074+
!strcmp(arg, "--detect-copies")) {
30723075
if (options->detect_rename == DIFF_DETECT_COPY)
30733076
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
30743077
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
@@ -3262,6 +3265,22 @@ static int diff_scoreopt_parse(const char *opt)
32623265
if (*opt++ != '-')
32633266
return -1;
32643267
cmd = *opt++;
3268+
if (cmd == '-') {
3269+
/* convert the long-form arguments into short-form versions */
3270+
if (!prefixcmp(opt, "break-rewrites")) {
3271+
opt += strlen("break-rewrites");
3272+
if (*opt == 0 || *opt++ == '=')
3273+
cmd = 'B';
3274+
} else if (!prefixcmp(opt, "detect-copies")) {
3275+
opt += strlen("detect-copies");
3276+
if (*opt == 0 || *opt++ == '=')
3277+
cmd = 'C';
3278+
} else if (!prefixcmp(opt, "detect-renames")) {
3279+
opt += strlen("detect-renames");
3280+
if (*opt == 0 || *opt++ == '=')
3281+
cmd = 'M';
3282+
}
3283+
}
32653284
if (cmd != 'M' && cmd != 'C' && cmd != 'B')
32663285
return -1; /* that is not a -M, -C nor -B option */
32673286

0 commit comments

Comments
 (0)