[PATCHv2 2/2] diff: add synonyms for -M, -C, -B
From: Kevin Ballard <hidden>
Date: 2016-06-15 22:49:38
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
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 <redacted> --- After thinking about it, I decided that --rename-threshold doesn't make sense as a long-form option because it doesn't make its meaning obvious when you don't specify the optional argument. I also figured it doesn't need to match exactly with the rename-threshold merge strategy option as merge-recursive already turns on rename detection and the option just controls the threshold. However, the option to git-diff actually turns on rename detection instead of just controlling the threshold. Documentation/diff-options.txt | 3 +++ diff.c | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index f77a0f8..a511529 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt@@ -207,6 +207,7 @@ endif::git-format-patch[] digits can be specified with `--abbrev=<n>`. -B[<n>][/<m>]:: +--break-rewrites[=[<n>][/<m>]]:: Break complete rewrite changes into pairs of delete and create. This serves two purposes: +
@@ -229,6 +230,7 @@ eligible for being picked up as a possible source of a rename to another file. -M[<n>]:: +--detect-renames[=<n>]:: ifndef::git-log[] Detect renames. endif::git-log[]
@@ -244,6 +246,7 @@ endif::git-log[] hasn't changed. -C[<n>]:: +--detect-copies[=<n>]:: Detect copies as well as renames. See also `--find-copies-harder`. If `n` is specified, it has the same meaning as for `-M<n>`.
diff --git a/diff.c b/diff.c
index d862234..d8fcf06 100644
--- a/diff.c
+++ b/diff.c@@ -3140,16 +3140,19 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) return stat_opt(options, av); /* renames options */ - else if (!prefixcmp(arg, "-B")) { + else if (!prefixcmp(arg, "-B") || !prefixcmp(arg, "--break-rewrites=") || + !strcmp(arg, "--break-rewrites")) { if ((options->break_opt = diff_scoreopt_parse(arg)) == -1) return -1; } - else if (!prefixcmp(arg, "-M")) { + else if (!prefixcmp(arg, "-M") || !prefixcmp(arg, "--detect-renames=") || + !strcmp(arg, "--detect-renames")) { if ((options->rename_score = diff_scoreopt_parse(arg)) == -1) return -1; options->detect_rename = DIFF_DETECT_RENAME; } - else if (!prefixcmp(arg, "-C")) { + else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--detect-copies=") || + !strcmp(arg, "--detect-copies")) { if (options->detect_rename == DIFF_DETECT_COPY) DIFF_OPT_SET(options, FIND_COPIES_HARDER); if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
@@ -3366,6 +3369,22 @@ static int diff_scoreopt_parse(const char *opt) if (*opt++ != '-') return -1; cmd = *opt++; + if (cmd == '-') { + /* convert the long-form arguments into short-form versions */ + if (!prefixcmp(opt, "break-rewrites")) { + opt += strlen("break-rewrites"); + if (*opt == 0 || *opt++ == '=') + cmd = 'B'; + } else if (!prefixcmp(opt, "detect-copies")) { + opt += strlen("detect-copies"); + if (*opt == 0 || *opt++ == '=') + cmd = 'C'; + } else if (!prefixcmp(opt, "detect-renames")) { + opt += strlen("detect-renames"); + if (*opt == 0 || *opt++ == '=') + cmd = 'M'; + } + } if (cmd != 'M' && cmd != 'C' && cmd != 'B') return -1; /* that is not a -M, -C nor -B option */
--
1.7.3.72.g8af0.dirty