Skip to content

Commit 03eb25b

Browse files
committed
Merge branch 'ib/diff-S-G-with-longhand' into seen
The commands in the "diff" family learned longhands for "-S" and "-G" options. The core part looked mostly good. * ib/diff-S-G-with-longhand: diff: docs: Use --patch-{grep,modifies} over -G/-S diff: --pickaxe-{all,regex} help: Add --patch-{grep,modifies} diff: test: Use --patch-{grep,modifies} over -G/-S completion: Support --patch-{grep,modifies} diff: --patch-{grep,modifies} arg names for -G and -S docs: gitdiffcore: -G and -S: Use regex/string placeholders diff: short help: Add -G and --pickaxe-grep diff: short help: Correct -S description diff: -G description: Correct copy/paste error t/t4209-log-pickaxe: Naming typo: -G takes a regex
2 parents c99ffb9 + ffdfcab commit 03eb25b

File tree

8 files changed

+155
-92
lines changed

8 files changed

+155
-92
lines changed

Documentation/diff-options.adoc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -650,35 +650,37 @@ 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.
656657
+
657658
It is useful when you're looking for an exact block of code (like a
658659
struct), and want to know the history of that block since it first
659660
came into being: use the feature iteratively to feed the interesting
660-
block in the preimage back into `-S`, and keep going until you get the
661-
very first version of the block.
661+
block in the preimage back into `--patch-modifies`, and keep going until
662+
you get the very first version of the block.
662663
+
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
+
669-
To illustrate the difference between `-S<regex>` `--pickaxe-regex` and
670-
`-G<regex>`, consider a commit with the following diff in the same
671-
file:
671+
To illustrate the difference between `--patch-modifies=<regex>
672+
--pickaxe-regex` and `--patch-grep=<regex>`, consider a commit with the
673+
following diff in the same file:
672674
+
673675
----
674676
+ return frotz(nitfol, two->ptr, 1, 0);
675677
...
676678
- hit = frotz(nitfol, mf2.ptr, 1, 0);
677679
----
678680
+
679-
While `git log -G"frotz\(nitfol"` will show this commit, `git log
680-
-S"frotz\(nitfol" --pickaxe-regex` will not (because the number of
681-
occurrences of that string did not change).
681+
While `git log --patch-grep="frotz\(nitfol"` will show this commit, `git
682+
log --patch-modifies="frotz\(nitfol" --pickaxe-regex` will not (because the
683+
number of occurrences of that string did not change).
682684
+
683685
Unless `--text` is supplied patches of binary files without a textconv
684686
filter will be ignored.
@@ -687,22 +689,22 @@ See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
687689
information.
688690
689691
`--find-object=<object-id>`::
690-
Look for differences that change the number of occurrences of
691-
the specified object. Similar to `-S`, just the argument is different
692-
in that it doesn't search for a specific string but for a specific
693-
object id.
692+
Look for differences that change the number of occurrences of the
693+
specified object. Similar to `--patch-modifies`, just the argument
694+
is different in that it doesn't search for a specific string but
695+
for a specific object id.
694696
+
695697
The object can be a blob or a submodule commit. It implies the `-t` option in
696698
`git-log` to also find trees.
697699

698700
`--pickaxe-all`::
699-
When `-S` or `-G` finds a change, show all the changes in that
700-
changeset, not just the files that contain the change
701-
in _<string>_.
701+
When `--patch-modifies` or `--patch-grep` finds a change, show all
702+
the changes in that changeset, not just the files that contain the
703+
change in _<string>_.
702704

703705
`--pickaxe-regex`::
704-
Treat the _<string>_ given to `-S` as an extended POSIX regular
705-
expression to match.
706+
Treat the _<string>_ given to `--patch-modifies` as an extended
707+
POSIX regular expression to match.
706708

707709
endif::git-format-patch[]
708710

Documentation/git-blame.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ a text string in the diff. A small example of the pickaxe interface
4141
that searches for `blame_usage`:
4242

4343
-----------------------------------------------------------------------------
44-
$ git log --pretty=oneline -S'blame_usage'
44+
$ git log --pretty=oneline --patch-modifies='blame_usage'
4545
5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
4646
ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
4747
-----------------------------------------------------------------------------

Documentation/gitdiffcore.adoc

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,34 @@ 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<block-of-text> and -G<regular-expression> options are used to
249-
specify different ways these strings are sought.
250-
251-
"-S<block-of-text>" detects filepairs whose preimage and postimage
252-
have different number of occurrences of the specified block of text.
253-
By definition, it will not detect in-file moves. Also, when a
254-
changeset moves a file wholesale without affecting the interesting
255-
string, diffcore-rename kicks in as usual, and `-S` omits the filepair
256-
(since the number of occurrences of that string didn't change in that
257-
rename-detected filepair). When used with `--pickaxe-regex`, treat
258-
the <block-of-text> as an extended POSIX regular expression to match,
259-
instead of a literal string.
260-
261-
"-G<regular-expression>" (mnemonic: grep) detects filepairs whose
262-
textual diff has an added or a deleted line that matches the given
263-
regular expression. This means that it will detect in-file (or what
264-
rename-detection considers the same file) moves, which is noise. The
265-
implementation runs diff twice and greps, and this can be quite
266-
expensive. To speed things up, binary files without textconv filters
267-
will be ignored.
268-
269-
When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
270-
that match their respective criterion are kept in the output. When
271-
`--pickaxe-all` is used, if even one filepair matches their respective
272-
criterion in a changeset, the entire changeset is kept. This behavior
273-
is designed to make reviewing changes in the context of the whole
274-
changeset easier.
248+
way. `--patch-modifies=<string>` and `--patch-grep=<regex>` are used
249+
to specify different ways these strings are sought.
250+
251+
`--patch-modifies=<string>` (`-S<string>` for short) detects filepairs
252+
whose preimage and postimage have different number of occurrences of
253+
the specified _<string>_. By definition, it will not detect in-file
254+
moves. Also, when a changeset moves a file wholesale without
255+
affecting the interesting string, diffcore-rename kicks in as usual,
256+
and `--patch-modifies` omits the filepair (since the number of
257+
occurrences of that string didn't change in that rename-detected
258+
filepair). When used with `--pickaxe-regex`, treat the _<string>_ as
259+
an extended POSIX regular expression to match, instead of a literal
260+
string.
261+
262+
`--patch-grep=<regex>` (`-G<regex>` for short, mnemonic: grep) detects
263+
filepairs whose textual diff has an added or a deleted line that
264+
matches the given regular expression. This means that it will detect
265+
in-file (or what rename-detection considers the same file) moves,
266+
which is noise. The implementation runs diff twice and greps, and
267+
this can be quite expensive. To speed things up, binary files without
268+
textconv filters will be ignored.
269+
270+
When `--patch-modifies` or `--patch-grep` are used without
271+
`--pickaxe-all`, only filepairs that match their respective criterion
272+
are kept in the output. When `--pickaxe-all` is used, if even one
273+
filepair matches their respective criterion in a changeset, the entire
274+
changeset is kept. This behavior is designed to make reviewing
275+
changes in the context of the whole changeset easier.
275276

276277
diffcore-order: For Sorting the Output Based on Filenames
277278
---------------------------------------------------------

contrib/completion/git-completion.bash

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
19001900
--output= --output-indicator-context=
19011901
--output-indicator-new= --output-indicator-old=
19021902
--ws-error-highlight=
1903+
--patch-grep= --patch-modifies=
19031904
--pickaxe-all --pickaxe-regex --patch-with-raw
19041905
"
19051906

@@ -2216,7 +2217,7 @@ __git_complete_log_opts ()
22162217
__git_complete_symbol --cur="${cur#:}" --sfx=":"
22172218
return
22182219
;;
2219-
-G,*|-S,*)
2220+
-G,*|--patch-grep,*|-S,*|--patch-modifies,*)
22202221
__git_complete_symbol
22212222
return
22222223
;;
@@ -2239,6 +2240,14 @@ __git_complete_log_opts ()
22392240
__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
22402241
return
22412242
;;
2243+
--patch-grep=*)
2244+
__git_complete_symbol --pfx="--patch-grep=" --cur="${cur#--patch-grep=}"
2245+
return
2246+
;;
2247+
--patch-modifies=*)
2248+
__git_complete_symbol --pfx="--patch-modifies=" --cur="${cur#--patch-modifies=}"
2249+
return
2250+
;;
22422251
--submodule=*)
22432252
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
22442253
return

diff.c

Lines changed: 10 additions & 8 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"
@@ -5866,17 +5868,17 @@ struct option *add_diff_options(const struct option *opts,
58665868
OPT_SET_INT_F(0, "ita-visible-in-index", &options->ita_invisible_in_index,
58675869
N_("treat 'git add -N' entries as real in the index"),
58685870
0, PARSE_OPT_NONEG),
5869-
OPT_CALLBACK_F('S', NULL, options, N_("<string>"),
5871+
OPT_CALLBACK_F('S', "patch-modifies", options, N_("<string>"),
58705872
N_("look for differences that change the number of occurrences of the specified string"),
58715873
0, diff_opt_pickaxe_string),
5872-
OPT_CALLBACK_F('G', NULL, options, N_("<regex>"),
5873-
N_("look for differences that change the number of occurrences of the specified regex"),
5874+
OPT_CALLBACK_F('G', "patch-grep", options, N_("<regex>"),
5875+
N_("look for differences where a patch contains the specified regex"),
58745876
0, diff_opt_pickaxe_regex),
58755877
OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts,
5876-
N_("show all changes in the changeset with -S or -G"),
5878+
N_("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep"),
58775879
DIFF_PICKAXE_ALL, PARSE_OPT_NONEG),
58785880
OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
5879-
N_("treat <string> in -S as extended POSIX regular expression"),
5881+
N_("treat <string> in -S/--patch-modifies as extended POSIX regular expression"),
58805882
DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
58815883
OPT_FILENAME('O', NULL, &options->orderfile,
58825884
N_("control the order in which files appear in the output")),

diff.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,16 @@ 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-
" -S<string> find filepair whose only one side contains the 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" \
615+
" --pickaxe-grep\n" \
616+
" treat <string> as a regex in the -S/--patch-modifies argument.\n" \
610617
" --pickaxe-all\n" \
611-
" show all files diff when -S is used and hit is found.\n" \
618+
" show all files diff for -G/--patch-grep and -S/--patch-modifies.\n" \
612619
" -a --text treat all files as text.\n"
613620

614621
int diff_queue_is_empty(struct diff_options *o);

t/t4062-diff-pickaxe.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ test_expect_success setup '
1616
'
1717

1818
# OpenBSD only supports up to 255 repetitions, so repeat twice for 64*64=4096.
19-
test_expect_success '-G matches' '
20-
git diff --name-only -G "^(0{64}){64}$" HEAD^ >out &&
19+
test_expect_success '--patch-grep matches' '
20+
git diff --name-only --patch-grep "^(0{64}){64}$" HEAD^ >out &&
2121
test 4096-zeroes.txt = "$(cat out)"
2222
'
2323

24-
test_expect_success '-S --pickaxe-regex' '
25-
git diff --name-only -S0 --pickaxe-regex HEAD^ >out &&
24+
test_expect_success '--patch-modifies --pickaxe-regex' '
25+
git diff --name-only --patch-modifies 0 --pickaxe-regex HEAD^ >out &&
2626
test 4096-zeroes.txt = "$(cat out)"
2727
'
2828

0 commit comments

Comments
 (0)