Skip to content

Commit b5f11b4

Browse files
committed
Merge branch 'ib/diff-S-G-with-longhand' into seen
* ib/diff-S-G-with-longhand: diff: --patch-{modifies,grep} arg names for -S and -G
2 parents 66c0533 + dcc02ca commit b5f11b4

File tree

7 files changed

+142
-87
lines changed

7 files changed

+142
-87
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: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,35 @@ 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
248+
way. --patch-modifies=<block-of-text> and
249+
--patch-grep=<regular-expression> options are used to specify
250+
different ways these strings are sought.
251+
252+
"-S<block-of-text>", or "--patch-modifies=<block-of-text>" detects
253+
filepairs whose preimage and postimage have different number of
254+
occurrences of the specified block of text. By definition, it will
255+
not detect in-file moves. Also, when a changeset moves a file
256+
wholesale without affecting the interesting string, diffcore-rename
257+
kicks in as usual, and `--patch-modifies` omits the filepair (since
258+
the number of occurrences of that string didn't change in that
257259
rename-detected filepair). When used with `--pickaxe-regex`, treat
258260
the <block-of-text> as an extended POSIX regular expression to match,
259261
instead of a literal string.
260262

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.
263+
"-G<regular-expression>", or "--patch-grep=<regular-expression>"
264+
(mnemonic: grep) detects filepairs whose textual diff has an added or
265+
a deleted line that matches the given regular expression. This means
266+
that it will detect in-file (or what rename-detection considers the
267+
same file) moves, which is noise. The implementation runs diff twice
268+
and greps, and this can be quite expensive. To speed things up,
269+
binary files without textconv filters will be ignored.
270+
271+
When `--patch-modifies` or `--patch-grep` are used without
272+
`--pickaxe-all`, only filepairs that match their respective criterion
273+
are kept in the output. When `--pickaxe-all` is used, if even one
274+
filepair matches their respective criterion in a changeset, the entire
275+
changeset is kept. This behavior is designed to make reviewing
276+
changes in the context of the whole changeset easier.
275277

276278
diffcore-order: For Sorting the Output Based on Filenames
277279
---------------------------------------------------------

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"
@@ -5862,17 +5864,17 @@ 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>"),
5869-
N_("look for differences that change the number of occurrences of the specified regex"),
5870+
OPT_CALLBACK_F('G', "patch-grep", options, N_("<regex>"),
5871+
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,
5872-
N_("show all changes in the changeset with -S or -G"),
5874+
N_("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep"),
58735875
DIFF_PICKAXE_ALL, PARSE_OPT_NONEG),
58745876
OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
5875-
N_("treat <string> in -S as extended POSIX regular expression"),
5877+
N_("treat <string> in -S/--patch-modifies as extended POSIX regular expression"),
58765878
DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
58775879
OPT_FILENAME('O', NULL, &options->orderfile,
58785880
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 whose 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 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)