Skip to contentSkip to conversation

Improve diffcore-pickaxe documentation

PATCH In review Ramkumar Ramachandra 2 participants 5 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v4 cover Improve diffcore-pickaxe documentation

Junio had some suggestions in the previous round. The inter-diff follows.

Yeah, word-diff is a bit messy. Which brings me to: is it possible to turn on word-diff only where heuristically appropriate? word-diff applied on the rewrite of the first paragraph of gitdiffcore.txt is a disaster, but okay everywhere else.

Documentation/diff-options.txt +0 -0
index efb5dfe..a85288f 100644
@@ -387,11 +387,11 @@ ifndef::git-format-patch[]

the specified string (i.e. addition/deletion) in a file. Intended for the scripter's use.
+
It is[-especially-] useful when you're looking for an exact block of code (like a struct), and want to know the history of that block since it first came into being: use the feature iteratively to feed the interesting block in the preimage back into -S, and keep going until you get the very first version of the block.

-G<regex>::
Look for differences whose patch text contains added/removed

Documentation/gitdiffcore.txt +0 -0
index ef4c04a..c8b3e51 100644
@@ -222,25 +222,27 @@ version prefixed with '+'.

diffcore-pickaxe: For Detecting Addition/Deletion of Specified String
---------------------------------------------------------------------

[-There are two kinds of pickaxe:-]{+This transformation limits+} the [-S kind (corresponding-]{+set of filepairs+} to [-'git log-] [--S')-]{+those that change+}
{+specified strings between the preimage+} and the [-G kind (mnemonic: grep; corresponding-]{+postimage in a certain+} {+way. -S<block of text> and -G<regular expression> options are used+} to
[-'git log -G').-]{+specify different ways these strings are sought.+}

"-S<block of text>" detects filepairs whose preimage and postimage
have different number of occurrences of the specified block of text.
By definition, it will not detect in-file moves. Also, when a
changeset moves a file wholesale without affecting the interesting
string, [-rename detection-]{+diffcore-rename+} kicks in as usual, and -S omits the filepair (since the number of occurrences of that string didn't change in that
rename-detected filepair).[-The implementation essentially-]
[-runs a count, and is significantly cheaper than the G kind.-] When used with --pickaxe-regex, treat the <block of text> as an extended POSIX regular expression to match,
instead of a literal string.

"-G<regular expression>" {+(mnemonic: grep)+} detects filepairs whose textual diff has an added or a deleted line that matches the given regular expression. This means that it [-can-]{+will+} detect in-file (or what rename-detection considers the same file) [-moves.-]{+moves, which is noise.+} The implementation runs diff twice and greps, and this can be quite expensive.

When -S or -G are used without --pickaxe-all, only filepairs that match their respective criterion are kept in the output. When

Ramkumar Ramachandra (2):
diffcore-pickaxe: make error messages more consistent diffcore-pickaxe doc: document -S and -G properly

 Documentation/diff-options.txt | 38 +++++++++++++++++++++++++++--------
 Documentation/gitdiffcore.txt  | 45 +++++++++++++++++++++++++-----------------
 diffcore-pickaxe.c             |  4 ++--
 3 files changed, 59 insertions(+), 28 deletions(-)
Signature · 1 line
1.8.3.114.gcd03571
#1 lore raw

PATCH v4 1/2 diffcore-pickaxe: make error messages more consistent

Currently, diffcore-pickaxe reports two distinct errors for the same user error:

    $ git log --pickaxe-regex -S'\1'
    fatal: invalid pickaxe regex: Invalid back reference
    $ git log -G'\1' # --pickaxe-regex is implied
    fatal: invalid log-grep regex: Invalid back reference

Since the error has nothing to do with "log-grep", change the -G and -S error messages to say "invalid regex".

---
 diffcore-pickaxe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diffcore-pickaxe.c +2 -2
index 63722f8..c97ac9b 100644
@@ -122,7 +122,7 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
 		char errbuf[1024];
 		regerror(err, &regex, errbuf, 1024);
 		regfree(&regex);
-		die("invalid log-grep regex: %s", errbuf);
+		die("invalid regex: %s", errbuf);
 	}
 
 	pickaxe(&diff_queued_diff, o, &regex, NULL, diff_grep);
@@ -246,7 +246,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
 			char errbuf[1024];
 			regerror(err, &regex, errbuf, 1024);
 			regfree(&regex);
-			die("invalid pickaxe regex: %s", errbuf);
+			die("invalid regex: %s", errbuf);
 		}
 		regexp = &regex;
 	} else {
Signature · 1 line
1.8.3.114.gcd03571
#2 lore raw

Re: [PATCH 1/2] diffcore-pickaxe: make error messages more consistent

Quoted 11 lines · Ramkumar Ramachandra

Currently, diffcore-pickaxe reports two distinct errors for the same user error:

    $ git log --pickaxe-regex -S'\1'
    fatal: invalid pickaxe regex: Invalid back reference
    $ git log -G'\1' # --pickaxe-regex is implied
    fatal: invalid log-grep regex: Invalid back reference

Since the error has nothing to do with "log-grep", change the -G and -S error messages to say "invalid regex".

I'll reword the above somewhat; as I repeatedly explained, -G does *not* imply pickaxe-regex at all.

While -G was being developed, it was internally called log-grep (no relation to "git log --grep=<pattern>"), and that seeped through to the error message. Removing that is a good idea.

Thanks, will queue.

Quoted 28 lines
---
 diffcore-pickaxe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diffcore-pickaxe.c +2 -2
index 63722f8..c97ac9b 100644
@@ -122,7 +122,7 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
 		char errbuf[1024];
 		regerror(err, &regex, errbuf, 1024);
 		regfree(&regex);
-		die("invalid log-grep regex: %s", errbuf);
+		die("invalid regex: %s", errbuf);
 	}
 
 	pickaxe(&diff_queued_diff, o, &regex, NULL, diff_grep);
@@ -246,7 +246,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
 			char errbuf[1024];
 			regerror(err, &regex, errbuf, 1024);
 			regfree(&regex);
-			die("invalid pickaxe regex: %s", errbuf);
+			die("invalid regex: %s", errbuf);
 		}
 		regexp = &regex;
 	} else {
#3 lore raw

PATCH v4 2/2 diffcore-pickaxe doc: document -S and -G properly

In reply to Ramkumar Ramachandra

The documentation of -S and -G is very sketchy. Completely rewrite the sections in Documentation/diff-options.txt and Documentation/gitdiffcore.txt.

References:
52e9578 ([PATCH] Introducing software archaeologist's tool "pickaxe".) f506b8e (git log/diff: add -G<regexp> that greps in the patch text)

Inputs-from: Phil Hord <[email protected]>

---
 Documentation/diff-options.txt | 38 +++++++++++++++++++++++++++--------
 Documentation/gitdiffcore.txt  | 45 +++++++++++++++++++++++++-----------------
 2 files changed, 57 insertions(+), 26 deletions(-)
Documentation/diff-options.txt +30 -8
index b8a9b86..a85288f 100644
@@ -383,14 +383,36 @@ ifndef::git-format-patch[]
 	that matches other criteria, nothing is selected.
 
 -S<string>::
-	Look for differences that introduce or remove an instance of
-	<string>. Note that this is different than the string simply
-	appearing in diff output; see the 'pickaxe' entry in
-	linkgit:gitdiffcore[7] for more details.
+	Look for differences that change the number of occurrences of
+	the specified string (i.e. addition/deletion) in a file.
+	Intended for the scripter's use.
++
+It is useful when you're looking for an exact block of code (like a
+struct), and want to know the history of that block since it first
+came into being: use the feature iteratively to feed the interesting
+block in the preimage back into `-S`, and keep going until you get the
+very first version of the block.
 
 -G<regex>::
-	Look for differences whose added or removed line matches
-	the given <regex>.
+	Look for differences whose patch text contains added/removed
+	lines that match <regex>.
++
+To illustrate the difference between `-S<regex> --pickaxe-regex` and
+`-G<regex>`, consider a commit with the following diff in the same
+file:
++
+----
++    return !regexec(regexp, two->ptr, 1, &regmatch, 0);
+...
+-    hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
+----
++
+While `git log -G"regexec\(regexp"` will show this commit, `git log
+-S"regexec\(regexp" --pickaxe-regex` will not (because the number of
+occurrences of that string did not change).
++
+See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
+information.
 
 --pickaxe-all::
 	When `-S` or `-G` finds a change, show all the changes in that
@@ -398,8 +420,8 @@ ifndef::git-format-patch[]
 	in <string>.
 
 --pickaxe-regex::
-	Make the <string> not a plain string but an extended POSIX
-	regex to match.
+	Treat the <string> given to `-S` as an extended POSIX regular
+	expression to match.
 endif::git-format-patch[]
 
 -O<orderfile>::
Documentation/gitdiffcore.txt +27 -18

53 lines not on this page · raw message

Signature · 1 line
1.8.3.114.gcd03571
#4 lore raw

Re: [PATCH 2/2] diffcore-pickaxe doc: document -S and -G properly

Quoted 3 lines · Ramkumar Ramachandra

The documentation of -S and -G is very sketchy. Completely rewrite the sections in Documentation/diff-options.txt and Documentation/gitdiffcore.txt.

Will queue; thanks.