Skip to content

Commit 5463eea

Browse files
ilya-bobyrgitster
authored andcommitted
diff: --patch-{grep,modifies} arg names for -G and -S
Most arguments have both short and long versions. Long versions are easier to read, especially in scripts and command history. This change mostly keeps existing uses of -G and -S as is in the tests, documentation and help output. Tests that check just the option parsing are duplicated to check both short and long argument options. Signed-off-by: Illia Bobyr <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e23443 commit 5463eea

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

Documentation/diff-options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ Note that not all diffs can feature all types. For instance, copied and
650650
renamed entries cannot appear if detection for those types is disabled.
651651

652652
`-S<string>`::
653+
`--patch-modifies=<string>`::
653654
Look for differences that change the number of occurrences of
654655
the specified _<string>_ (i.e. addition/deletion) in a file.
655656
Intended for the scripter's use.
@@ -663,6 +664,7 @@ very first version of the block.
663664
Binary files are searched as well.
664665

665666
`-G<regex>`::
667+
`--patch-grep=<regex>`::
666668
Look for differences whose patch text contains added/removed
667669
lines that match _<regex>_.
668670
+

Documentation/gitdiffcore.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String
245245

246246
This transformation limits the set of filepairs to those that change
247247
specified strings between the preimage and the postimage in a certain
248-
way. `-S<string>` and `-G<regex>` options are used to specify
248+
way. `--patch-modifies=<string>` (`-S<string>` for short) and
249+
`--patch-grep=<regex>` (`-G<regex>` for short) are used to specify
249250
different ways these strings are sought.
250251

251252
`-S<string>` detects filepairs whose preimage and postimage

diff.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options)
48774877

48784878
if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK))
48794879
die(_("options '%s', '%s', and '%s' cannot be used together"),
4880-
"-G", "-S", "--find-object");
4880+
"-G/--patch-grep", "-S/--patch-modifies", "--find-object");
48814881

48824882
if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_G_REGEX_MASK))
48834883
die(_("options '%s' and '%s' cannot be used together, use '%s' with '%s'"),
4884-
"-G", "--pickaxe-regex", "--pickaxe-regex", "-S");
4884+
"-G/--patch-grep", "--pickaxe-regex",
4885+
"--pickaxe-regex", "-S/--patch-modifies");
48854886

48864887
if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK))
48874888
die(_("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'"),
4888-
"--pickaxe-all", "--find-object", "--pickaxe-all", "-G", "-S");
4889+
"--pickaxe-all", "--find-object",
4890+
"--pickaxe-all", "-G/--patch-grep", "-S/--patch-modifies");
48894891

48904892
/*
48914893
* Most of the time we can say "there are changes"
@@ -5862,10 +5864,10 @@ struct option *add_diff_options(const struct option *opts,
58625864
OPT_SET_INT_F(0, "ita-visible-in-index", &options->ita_invisible_in_index,
58635865
N_("treat 'git add -N' entries as real in the index"),
58645866
0, PARSE_OPT_NONEG),
5865-
OPT_CALLBACK_F('S', NULL, options, N_("<string>"),
5867+
OPT_CALLBACK_F('S', "patch-modifies", options, N_("<string>"),
58665868
N_("look for differences that change the number of occurrences of the specified string"),
58675869
0, diff_opt_pickaxe_string),
5868-
OPT_CALLBACK_F('G', NULL, options, N_("<regex>"),
5870+
OPT_CALLBACK_F('G', "patch-grep", options, N_("<regex>"),
58695871
N_("look for differences where a patch contains the specified regex"),
58705872
0, diff_opt_pickaxe_regex),
58715873
OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts,

diff.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,12 @@ void diffcore_fix_diff_index(void);
606606
" try unchanged files as candidate for copy detection.\n" \
607607
" -l<n> limit rename attempts up to <n> paths.\n" \
608608
" -O<file> reorder diffs according to the <file>.\n" \
609-
" -G<regex> find differences where patch contains the specified regex.\n" \
610-
" -S<string> find filepair who differ in the number of occurrences of string.\n" \
609+
" -G<regex>\n" \
610+
" --patch-grep=<regex>\n" \
611+
" find differences where patch contains the regex.\n" \
612+
" -S<string>\n" \
613+
" --patch-modifies=<string>\n" \
614+
" find filepair who differ in the number of occurrences of string.\n" \
611615
" --pickaxe-grep\n" \
612616
" treat <string> as a regex in the -S argument.\n" \
613617
" --pickaxe-all\n" \

t/t4209-log-pickaxe.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,48 @@ test_expect_success 'usage' '
6060
test_expect_code 129 git log -S 2>err &&
6161
test_grep "switch.*requires a value" err &&
6262
63+
test_expect_code 129 git log --patch-modifies 2>err &&
64+
test_grep "option.*requires a value" err &&
65+
6366
test_expect_code 129 git log -G 2>err &&
6467
test_grep "switch.*requires a value" err &&
6568
69+
test_expect_code 129 git log --patch-grep 2>err &&
70+
test_grep "option.*requires a value" err &&
71+
6672
test_expect_code 128 git log -Gregex -Sstring 2>err &&
6773
grep "cannot be used together" err &&
6874
75+
test_expect_code 128 git log -Gregex --patch-modifies string 2>err &&
76+
grep "cannot be used together" err &&
77+
78+
test_expect_code 128 git log --patch-grep regex -Sstring 2>err &&
79+
grep "cannot be used together" err &&
80+
81+
test_expect_code 128 git log --patch-grep regex --patch-modifies string 2>err &&
82+
grep "cannot be used together" err &&
83+
6984
test_expect_code 128 git log -Gregex --find-object=HEAD 2>err &&
7085
grep "cannot be used together" err &&
7186
87+
test_expect_code 128 git log --patch-grep regex --find-object=HEAD 2>err &&
88+
grep "cannot be used together" err &&
89+
7290
test_expect_code 128 git log -Sstring --find-object=HEAD 2>err &&
7391
grep "cannot be used together" err &&
7492
93+
test_expect_code 128 git log --patch-modifies string --find-object=HEAD 2>err &&
94+
grep "cannot be used together" err &&
95+
7596
test_expect_code 128 git log --pickaxe-all --find-object=HEAD 2>err &&
7697
grep "cannot be used together" err
7798
'
7899

79100
test_expect_success 'usage: --pickaxe-regex' '
80101
test_expect_code 128 git log -Gregex --pickaxe-regex 2>err &&
102+
grep "cannot be used together" err &&
103+
104+
test_expect_code 128 git log --patch-grep regex --pickaxe-regex 2>err &&
81105
grep "cannot be used together" err
82106
'
83107

@@ -89,7 +113,13 @@ test_expect_success 'usage: --no-pickaxe-regex' '
89113
test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual &&
90114
test_cmp expect actual &&
91115
116+
test_expect_code 128 git log --patch-modifies string --no-pickaxe-regex 2>actual &&
117+
test_cmp expect actual &&
118+
92119
test_expect_code 128 git log -Gregex --no-pickaxe-regex 2>err &&
120+
test_cmp expect actual &&
121+
122+
test_expect_code 128 git log --patch-grep regex --no-pickaxe-regex 2>err &&
93123
test_cmp expect actual
94124
'
95125

@@ -104,9 +134,13 @@ test_log_icase expect_second --author person
104134
test_log_icase expect_nomatch --author spreon
105135

106136
test_log expect_nomatch -G picked
137+
test_log expect_nomatch --patch-grep picked
107138
test_log expect_second -G Picked
139+
test_log expect_second --patch-grep Picked
108140
test_log_icase expect_nomatch -G pickle
141+
test_log_icase expect_nomatch --patch-grep pickle
109142
test_log_icase expect_second -G picked
143+
test_log_icase expect_second --patch-grep picked
110144

111145
test_expect_success 'log -G --textconv (missing textconv tool)' '
112146
echo "* diff=test" >.gitattributes &&
@@ -122,14 +156,22 @@ test_expect_success 'log -G --no-textconv (missing textconv tool)' '
122156
'
123157

124158
test_log expect_nomatch -S picked
159+
test_log expect_nomatch --patch-modifies picked
125160
test_log expect_second -S Picked
161+
test_log expect_second --patch-modifies Picked
126162
test_log_icase expect_second -S picked
163+
test_log_icase expect_second --patch-modifies picked
127164
test_log_icase expect_nomatch -S pickle
165+
test_log_icase expect_nomatch --patch-modifies pickle
128166

129167
test_log expect_nomatch -S p.cked --pickaxe-regex
168+
test_log expect_nomatch --patch-modifies p.cked --pickaxe-regex
130169
test_log expect_second -S P.cked --pickaxe-regex
170+
test_log expect_second --patch-modifies P.cked --pickaxe-regex
131171
test_log_icase expect_second -S p.cked --pickaxe-regex
172+
test_log_icase expect_second --patch-modifies p.cked --pickaxe-regex
132173
test_log_icase expect_nomatch -S p.ckle --pickaxe-regex
174+
test_log_icase expect_nomatch --patch-modifies p.ckle --pickaxe-regex
133175

134176
test_expect_success 'log -S --textconv (missing textconv tool)' '
135177
echo "* diff=test" >.gitattributes &&

0 commit comments

Comments
 (0)