Skip to content

Commit 4efd165

Browse files
committed
Merge branch 'rr/diffcore-pickaxe-doc' into maint
* rr/diffcore-pickaxe-doc: diffcore-pickaxe doc: document -S and -G properly diffcore-pickaxe: make error messages more consistent
2 parents 213d256 + 5bc3f0b commit 4efd165

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

Documentation/diff-options.txt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,23 +383,45 @@ ifndef::git-format-patch[]
383383
that matches other criteria, nothing is selected.
384384

385385
-S<string>::
386-
Look for differences that introduce or remove an instance of
387-
<string>. Note that this is different than the string simply
388-
appearing in diff output; see the 'pickaxe' entry in
389-
linkgit:gitdiffcore[7] for more details.
386+
Look for differences that change the number of occurrences of
387+
the specified string (i.e. addition/deletion) in a file.
388+
Intended for the scripter's use.
389+
+
390+
It is useful when you're looking for an exact block of code (like a
391+
struct), and want to know the history of that block since it first
392+
came into being: use the feature iteratively to feed the interesting
393+
block in the preimage back into `-S`, and keep going until you get the
394+
very first version of the block.
390395

391396
-G<regex>::
392-
Look for differences whose added or removed line matches
393-
the given <regex>.
397+
Look for differences whose patch text contains added/removed
398+
lines that match <regex>.
399+
+
400+
To illustrate the difference between `-S<regex> --pickaxe-regex` and
401+
`-G<regex>`, consider a commit with the following diff in the same
402+
file:
403+
+
404+
----
405+
+ return !regexec(regexp, two->ptr, 1, &regmatch, 0);
406+
...
407+
- hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
408+
----
409+
+
410+
While `git log -G"regexec\(regexp"` will show this commit, `git log
411+
-S"regexec\(regexp" --pickaxe-regex` will not (because the number of
412+
occurrences of that string did not change).
413+
+
414+
See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
415+
information.
394416

395417
--pickaxe-all::
396418
When `-S` or `-G` finds a change, show all the changes in that
397419
changeset, not just the files that contain the change
398420
in <string>.
399421

400422
--pickaxe-regex::
401-
Make the <string> not a plain string but an extended POSIX
402-
regex to match.
423+
Treat the <string> given to `-S` as an extended POSIX regular
424+
expression to match.
403425
endif::git-format-patch[]
404426

405427
-O<orderfile>::

Documentation/gitdiffcore.txt

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,35 @@ version prefixed with '+'.
222222
diffcore-pickaxe: For Detecting Addition/Deletion of Specified String
223223
---------------------------------------------------------------------
224224

225-
This transformation is used to find filepairs that represent
226-
changes that touch a specified string, and is controlled by the
227-
-S option and the `--pickaxe-all` option to the 'git diff-*'
228-
commands.
229-
230-
When diffcore-pickaxe is in use, it checks if there are
231-
filepairs whose "result" side and whose "origin" side have
232-
different number of specified string. Such a filepair represents
233-
"the string appeared in this changeset". It also checks for the
234-
opposite case that loses the specified string.
235-
236-
When `--pickaxe-all` is not in effect, diffcore-pickaxe leaves
237-
only such filepairs that touch the specified string in its
238-
output. When `--pickaxe-all` is used, diffcore-pickaxe leaves all
239-
filepairs intact if there is such a filepair, or makes the
240-
output empty otherwise. The latter behaviour is designed to
241-
make reviewing of the changes in the context of the whole
225+
This transformation limits the set of filepairs to those that change
226+
specified strings between the preimage and the postimage in a certain
227+
way. -S<block of text> and -G<regular expression> options are used to
228+
specify different ways these strings are sought.
229+
230+
"-S<block of text>" detects filepairs whose preimage and postimage
231+
have different number of occurrences of the specified block of text.
232+
By definition, it will not detect in-file moves. Also, when a
233+
changeset moves a file wholesale without affecting the interesting
234+
string, diffcore-rename kicks in as usual, and `-S` omits the filepair
235+
(since the number of occurrences of that string didn't change in that
236+
rename-detected filepair). When used with `--pickaxe-regex`, treat
237+
the <block of text> as an extended POSIX regular expression to match,
238+
instead of a literal string.
239+
240+
"-G<regular expression>" (mnemonic: grep) detects filepairs whose
241+
textual diff has an added or a deleted line that matches the given
242+
regular expression. This means that it will detect in-file (or what
243+
rename-detection considers the same file) moves, which is noise. The
244+
implementation runs diff twice and greps, and this can be quite
245+
expensive.
246+
247+
When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
248+
that match their respective criterion are kept in the output. When
249+
`--pickaxe-all` is used, if even one filepair matches their respective
250+
criterion in a changeset, the entire changeset is kept. This behavior
251+
is designed to make reviewing changes in the context of the whole
242252
changeset easier.
243253

244-
245254
diffcore-order: For Sorting the Output Based on Filenames
246255
---------------------------------------------------------
247256

diffcore-pickaxe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
122122
char errbuf[1024];
123123
regerror(err, &regex, errbuf, 1024);
124124
regfree(&regex);
125-
die("invalid log-grep regex: %s", errbuf);
125+
die("invalid regex: %s", errbuf);
126126
}
127127

128128
pickaxe(&diff_queued_diff, o, &regex, NULL, diff_grep);
@@ -246,7 +246,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
246246
char errbuf[1024];
247247
regerror(err, &regex, errbuf, 1024);
248248
regfree(&regex);
249-
die("invalid pickaxe regex: %s", errbuf);
249+
die("invalid regex: %s", errbuf);
250250
}
251251
regexp = &regex;
252252
} else {

0 commit comments

Comments
 (0)