Long names for `git log -S` and `git log -G`
v3 cover Long names for `git log -S` and `git log -G`
Same as PATCH v2[1], but removed gitk changes, as suggested by Johannes Sixt.
I'll send a separate patch for gitk, should this patch be accepted. Or, I could include gitk changes into this chain, but just as a separate patch?
[1]: https://lore.kernel.org/git/[email protected]/
Illia Bobyr (1):
diff: --patch-{modifies,grep} arg names for -S and -G
Documentation/diff-options.txt | 36 +++++------ Documentation/git-blame.txt | 2 +- Documentation/gitdiffcore.txt | 48 ++++++++------- diff.c | 18 +++--- diff.h | 11 +++- t/t4062-diff-pickaxe.sh | 8 +-- t/t4209-log-pickaxe.sh | 106 +++++++++++++++++++++++---------- 7 files changed, 142 insertions(+), 87 deletions(-)
Signature · 1 line
2.45.2
PATCH v3 1/1 diff: --patch-{modifies,grep} arg names for -S and -G
Most arguments have both short and long versions. Long versions are easier to read, especially in scripts and command history.
Tests that check just the option parsing are duplicated to check both short and long argument options. But more complex tests are updated to use the long argument in order to improve the test readability. Assuming that the usage tests have already verified that both arguments invoke the same underlying functionality.
--- Documentation/diff-options.txt | 36 +++++------ Documentation/git-blame.txt | 2 +- Documentation/gitdiffcore.txt | 48 ++++++++------- diff.c | 18 +++--- diff.h | 11 +++- t/t4062-diff-pickaxe.sh | 8 +-- t/t4209-log-pickaxe.sh | 106 +++++++++++++++++++++++---------- 7 files changed, 142 insertions(+), 87 deletions(-)
Documentation/diff-options.txt +19 -17
@@ -650,6 +650,7 @@ Note that not all diffs can feature all types. For instance, copied and renamed entries cannot appear if detection for those types is disabled. `-S<string>`:: +`--patch-modifies=<string>`:: 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.
@@ -657,18 +658,19 @@ renamed entries cannot appear if detection for those types is disabled. 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. +block in the preimage back into `--patch-modifies`, and keep going until +you get the very first version of the block. + Binary files are searched as well. `-G<regex>`:: +`--patch-grep=<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: +To illustrate the difference between `--patch-modifies=<regex> +--pickaxe-regex` and `--patch-grep=<regex>`, consider a commit with the +following diff in the same file: + ---- + return frotz(nitfol, two->ptr, 1, 0);
@@ -676,9 +678,9 @@ file: - hit = frotz(nitfol, mf2.ptr, 1, 0); ---- + -While `git log -G"frotz\(nitfol"` will show this commit, `git log --S"frotz\(nitfol" --pickaxe-regex` will not (because the number of -occurrences of that string did not change). +While `git log --patch-grep="frotz\(nitfol"` will show this commit, `git +log --patch-modifies="frotz\(nitfol" --pickaxe-regex` will not (because the +number of occurrences of that string did not change). + Unless `--text` is supplied patches of binary files without a textconv filter will be ignored.
@@ -687,22 +689,22 @@ See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more information. `--find-object=<object-id>`:: - Look for differences that change the number of occurrences of - the specified object. Similar to `-S`, just the argument is different - in that it doesn't search for a specific string but for a specific - object id. + Look for differences that change the number of occurrences of the + specified object. Similar to `--patch-modifies`, just the argument + is different in that it doesn't search for a specific string but + for a specific object id. + The object can be a blob or a submodule commit. It implies the `-t` option in `git-log` to also find trees. `--pickaxe-all`:: - When `-S` or `-G` finds a change, show all the changes in that - changeset, not just the files that contain the change - in _<string>_. + When `--patch-modifies` or `--patch-grep` finds a change, show all + the changes in that changeset, not just the files that contain the + change in _<string>_. `--pickaxe-regex`:: - Treat the _<string>_ given to `-S` as an extended POSIX regular - expression to match. + Treat the _<string>_ given to `--patch-modifies` as an extended + POSIX regular expression to match. endif::git-format-patch[]
Documentation/git-blame.txt +1 -1
@@ -41,7 +41,7 @@ a text string in the diff. A small example of the pickaxe interface that searches for `blame_usage`: ----------------------------------------------------------------------------- -$ git log --pretty=oneline -S'blame_usage' +$ git log --pretty=oneline --patch-modifies='blame_usage' 5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file> ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output -----------------------------------------------------------------------------
Documentation/gitdiffcore.txt +25 -23
58 lines not on this page · raw message
diff.c +10 -8
@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options)if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_MASK ))die (_ ("options '%s', '%s', and '%s' cannot be used together" ), -"-G" ,"-S" ,"--find-object" ); +"-G/--patch-grep" ,"-S/--patch-modifies" ,"--find-object" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_G_REGEX_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s'" ), -"-G" ,"--pickaxe-regex" ,"--pickaxe-regex" ,"-S" ); +"-G/--patch-grep" ,"--pickaxe-regex" , +"--pickaxe-regex" ,"-S/--patch-modifies" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'" ), -"--pickaxe-all" ,"--find-object" ,"--pickaxe-all" ,"-G" ,"-S" ); +"--pickaxe-all" ,"--find-object" , +"--pickaxe-all" ,"-G/--patch-grep" ,"-S/--patch-modifies" );/* * Most of the time we can say "there are changes"
@@ -5862,17 +5864,17 @@ struct option *add_diff_options(const struct option *opts,OPT_SET_INT_F (0 ,"ita-visible-in-index" , &options->ita_invisible_in_index,N_ ("treat 'git add -N' entries as real in the index" ),0 ,PARSE_OPT_NONEG ), -OPT_CALLBACK_F ('S' ,NULL , options,N_ ("<string>" ), +OPT_CALLBACK_F ('S' ,"patch-modifies" , options,N_ ("<string>" ),N_ ("look for differences that change the number of occurrences of the specified string" ),0 , diff_opt_pickaxe_string), -OPT_CALLBACK_F ('G' ,NULL , options,N_ ("<regex>" ), -N_ ("look for differences that change the number of occurrences of the specified regex" ), +OPT_CALLBACK_F ('G' ,"patch-grep" , options,N_ ("<regex>" ), +N_ ("look for differences where a patch contains the specified regex" ),0 , diff_opt_pickaxe_regex),OPT_BIT_F (0 ,"pickaxe-all" , &options->pickaxe_opts, -N_ ("show all changes in the changeset with -S or -G" ), +N_ ("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep" ),DIFF_PICKAXE_ALL ,PARSE_OPT_NONEG ),OPT_BIT_F (0 ,"pickaxe-regex" , &options->pickaxe_opts, -N_ ("treat <string> in -S as extended POSIX regular expression" ), +N_ ("treat <string> in -S/--patch-modifies as extended POSIX regular expression" ),DIFF_PICKAXE_REGEX ,PARSE_OPT_NONEG ),OPT_FILENAME ('O' ,NULL , &options->orderfile, N_("control the order in which files appear in the output")),
diff.h +9 -2
@@ -598,9 +598,16 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ -" -S<string> find filepair whose only one side contains the string.\n" \ +" -G<regex>\n" \ +" --patch-grep=<regex>\n" \ +" find differences whose patch contains the regex.\n" \ +" -S<string>\n" \ +" --patch-modifies=<string>\n" \ +" find filepair who differ in the number of occurrences of string.\n" \ +" --pickaxe-grep\n" \ +" treat <string> as regex in the -S/--patch-modifies argument.\n" \" --pickaxe-all\n" \ -" show all files diff when -S is used and hit is found.\n" \ +" show all files diff for -G/--patch-grep and -S/--patch-modifies.\n" \" -a --text treat all files as text.\n" int diff_queue_is_empty(struct diff_options *o);
t/t4062-diff-pickaxe.sh +4 -4
@@ -16,13 +16,13 @@ test_expect_success setup ' ' # OpenBSD only supports up to 255 repetitions, so repeat twice for 64*64=4096. -test_expect_success '-G matches' ' - git diff --name-only -G "^(0{64}){64}$" HEAD^ >out && +test_expect_success '--patch-grep matches' ' + git diff --name-only --patch-grep "^(0{64}){64}$" HEAD^ >out && test 4096-zeroes.txt = "$(cat out)" ' -test_expect_success '-S --pickaxe-regex' ' - git diff --name-only -S0 --pickaxe-regex HEAD^ >out && +test_expect_success '--patch-modifies --pickaxe-regex' ' + git diff --name-only --patch-modifies 0 --pickaxe-regex HEAD^ >out && test 4096-zeroes.txt = "$(cat out)" '
t/t4209-log-pickaxe.sh +74 -32
225 lines not on this page · raw message
Signature · 1 line
2.45.2
Re: [PATCH v3 1/1] diff: --patch-{modifies,grep} arg names for -S and -G
Quoted 6 lines · Illia Bobyr
Most arguments have both short and long versions. Long versions are easier to read, especially in scripts and command history.
Tests that check just the option parsing are duplicated to check both short and long argument options. But more complex tests are updated to use the long argument in order to improve the test readability.
While checking both may be a prudent thing to do, because the "-S" option and the "-G" option have been there with us almost since the beginning of time, the swapping all existing use of them with the longhand is rather unwelcome and needless churn, I would have to say.
Quoted 2 lines
-S<string>::
+--patch-modifies=<string>::
Good. I am looking at 'git-commit.txt' as an example, and we seem to give shorthand first and then longhand, which matches what we see here.
Documentation/diff-options.txt renamed entries cannot appear if detection for those types is disabled. · line 662
Quoted 8 lines
Documentation/diff-options.txt +2
-2@@ -657,18 +658,19 @@ renamed entries cannot appear if detection for those types is disabled. 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. +block in the preimage back into `--patch-modifies`, and keep going until +you get the very first version of the block.
If this paragraph _were_ written with the longhand from the beginning, I would not have minded too much, but I personally find it unnecessary to churn the existing document like this.
Documentation/diff-options.txt renamed entries cannot appear if detection for those types is disabled. · line 667
Quoted 2 lines
Documentation/diff-options.txt +1
-0`-G<regex>`:: +`--patch-grep=<regex>`::
Same two paragraphs from the above apply here, and ...
Documentation/diff-options.txt See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more · line 705
Quoted 3 lines
Documentation/diff-options.txt +0
-0`--find-object=<object-id>`:: `--pickaxe-all`:: `--pickaxe-regex`::
... all of the above.
Documentation/git-blame.txt
Quoted 1 line
Documentation/git-blame.txt +0
-0
Ditto.
Documentation/gitdiffcore.txt diffcore-pickaxe: For Detecting Addition/Deletion of Specified String · line 250
Quoted 12 lines
Documentation/gitdiffcore.txt +3
-1@@ -245,33 +245,35 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String This transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain -way. -S<block-of-text> and -G<regular-expression> options are used to +way. --patch-modifies=<block-of-text> and +--patch-grep=<regular-expression> options are used to specify +different ways these strings are sought.
This is worse. Here is the first part that describes the pickaxe, so mentioning both may be more appropriate; showing only the longhand nobody is familiar with (yet) does not make any sense.
... certain way. `--patch-modifies=<block-of-text>`
(`-S<block-of-text>` for short) and `--patch-grep=<regular-expression>`
(`-G<regular-expression>` for short) are used to ...Once establishing the equivalence between the longhand and the shorthand for these two options, we do not have to churn the existing text at all.
Quoted 12 lines
diff.c +1
-1@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options)if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_MASK ))die (_ ("options '%s', '%s', and '%s' cannot be used together" ), -"-G" ,"-S" ,"--find-object" ); +"-G/--patch-grep" ,"-S/--patch-modifies" ,"--find-object" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_G_REGEX_MASK ))
diff.c void diff_setup_done(struct diff_options *options) · line 4890
Quoted 10 lines
diff.c +4
-2die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s'" ), -"-G" ,"--pickaxe-regex" ,"--pickaxe-regex" ,"-S" ); +"-G/--patch-grep" ,"--pickaxe-regex" , +"--pickaxe-regex" ,"-S/--patch-modifies" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'" ), -"--pickaxe-all" ,"--find-object" ,"--pickaxe-all" ,"-G" ,"-S" ); +"--pickaxe-all" ,"--find-object" , +"--pickaxe-all" ,"-G/--patch-grep" ,"-S/--patch-modifies" );
The message change looks fine; the indentation is broken.
.git/rebase-apply/patch:184: indent with spaces.
"--pickaxe-regex", "-S/--patch-modifies");
.git/rebase-apply/patch:190: indent with spaces.
"--pickaxe-all", "-G/--patch-grep", "-S/--patch-modifies");warning: 2 lines applied after fixing whitespace errors.
Applying: diff: --patch-{modifies,grep} arg names for -S and -G
These alone do not require a new iteration, as "git am --whitespace=fix" already corrected them.
diff.c struct option *add_diff_options(const struct option *opts, · line 5870
Quoted 4 lines
diff.c +2
-2- OPT_CALLBACK_F('S', NULL, options, N_("<string>"), + OPT_CALLBACK_F('S', "patch-modifies", options, N_("<string>"), - OPT_CALLBACK_F('G', NULL, options, N_("<regex>"), + OPT_CALLBACK_F('G', "patch-grep", options, N_("<regex>"),
OK. NOte that this says <regex>. We may want to have a separate clean-up patch so that Documentation/gitdifcore.txt that used <regular-expression> and the placeholder used here match.
diff.c struct option *add_diff_options(const struct option *opts, · line 5871
Quoted 2 lines
diff.c +1
-1- N_("look for differences that change the number of occurrences of the specified regex"), + N_("look for differences where a patch contains the specified regex"),
This is an unrelated change that should not be in this patch. If you want to modify it, please do it in a separate clean-up patch, just like the above <regex> vs <regular-expression> change.
diff.c struct option *add_diff_options(const struct option *opts, · line 5874
Quoted 2 lines
diff.c +1
-1- N_("show all changes in the changeset with -S or -G"), + N_("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep"),
This line is meant to be shown when the user requests list of options and their meanings. Growing the message from 47 columns or so to 78 columns would make it wider than terminals when these messages are indented. Because earlier entries in this array have already established the equivalence between the shorthand and the longhand, I do not think the output is understandable without this change.
diff.c struct option *add_diff_options(const struct option *opts, · line 5877
Quoted 3 lines
diff.c +1
-1OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts, - N_("treat <string> in -S as extended POSIX regular expression"), + N_("treat <string> in -S/--patch-modifies as extended POSIX regular expression"),
Ditto.
Thanks.
Re: [PATCH v3 1/1] diff: --patch-{modifies,grep} arg names for -S and -G
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Illia Bobyr
Most arguments have both short and long versions. Long versions are easier to read, especially in scripts and command history.
Tests that check just the option parsing are duplicated to check both short and long argument options. But more complex tests are updated to use the long argument in order to improve the test readability.
Quoted 5 lines
While checking both may be a prudent thing to do, because the "-S" option and the "-G" option have been there with us almost since the beginning of time, the swapping all existing use of them with the longhand is rather unwelcome and needless churn, I would have to say.
My thinking is that as long version names improve readability, it also applies to the test code. When I see a short option, I often have to check the manual to remember what exactly does it do. Even for "-S"/"-G" I find myself sometimes confused as to which of the two does what exactly. While the "grep" mnemonic helps, I do not always remember it.
But, I think, I understand your point of view as well.
In v5, patch 5 contains a relatively minimum amount of changes that add long alternatives for "-S" and "-G" just to the command line parsing.
I do not have your experience with assessing the churn, but if my argument about the readability changes your mind, I've moved the rest of the updates into separate patches, at the end of the chain. Patches 8 through 10. Making it easier to discuss them in smaller chunks, if you wish so. But also, I assume, it should be easy for you to ignore those, if you do not want to include them?
Quoted 19 lines
[...]
Documentation/gitdiffcore.txt diffcore-pickaxe: For Detecting Addition/Deletion of Specified String · line 250
Quoted 12 lines
Documentation/gitdiffcore.txt +0
-0@@ -245,33 +245,35 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified StringThis transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain
Documentation/gitdiffcore.txt +3
-1-way. -S<block-of-text> and -G<regular-expression> options are used to +way. --patch-modifies=<block-of-text> and +--patch-grep=<regular-expression> options are used to specify +different ways these strings are sought.This is worse. Here is the first part that describes the pickaxe, so mentioning both may be more appropriate; showing only the longhand nobody is familiar with (yet) does not make any sense.
Quoted 7 lines
... certain way.
--patch-modifies=<block-of-text>(-S<block-of-text>for short) and--patch-grep=<regular-expression>(-G<regular-expression>for short) are used to ...Once establishing the equivalence between the longhand and the shorthand for these two options, we do not have to churn the existing text at all.
Applied your suggestion.
I guess one difference in the way you look at it, is that you default to the short version when you can. While I default to the long one, as I assume it is easier to understand. Someone not that intimately familiar with git might need to go to the previous paragraph to recall what "-S" and "-G" are, while if they are spelled as "--patch-modifies" and "--patch-grep", it might be less necessary. So, the argument is that while we are reducing the diff, we might also be reducing the improvement in readability.
Being the author, I could also be biased when assessing how much more readable "--patch-modifies" and "--patch-grep" are compared to "-S" and "-G".
Quoted 32 lines
Quoted 12 lines
diff.c +1
-1@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options) if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK)) die(_("options '%s', '%s', and '%s' cannot be used together"), - "-G", "-S", "--find-object"); + "-G/--patch-grep", "-S/--patch-modifies", "--find-object"); if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_G_REGEX_MASK))diff.c void diff_setup_done(struct diff_options *options) · line 4890
Quoted 10 lines
diff.c +4
-2die(_("options '%s' and '%s' cannot be used together, use '%s' with '%s'"), - "-G", "--pickaxe-regex", "--pickaxe-regex", "-S"); + "-G/--patch-grep", "--pickaxe-regex", + "--pickaxe-regex", "-S/--patch-modifies"); if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK)) die(_("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'"), - "--pickaxe-all", "--find-object", "--pickaxe-all", "-G", "-S"); + "--pickaxe-all", "--find-object", + "--pickaxe-all", "-G/--patch-grep", "-S/--patch-modifies");The message change looks fine; the indentation is broken.
.git/rebase-apply/patch:184: indent with spaces.
"--pickaxe-regex", "-S/--patch-modifies"); .git/rebase-apply/patch:190: indent with spaces.
"--pickaxe-all", "-G/--patch-grep", "-S/--patch-modifies");
warning: 2 lines applied after fixing whitespace errors.
Applying: diff: --patch-{modifies,grep} arg names for -S and -G
Quoted 2 lines
These alone do not require a new iteration, as "git am --whitespace=fix" already corrected them.
Sorry about this. I did check the indentation manually, but did not use a tool. Reconfigured my editor to use tabs now.
Quoted 8 lines
diff.c struct option *add_diff_options(const struct option *opts, · line 5870
Quoted 4 lines
diff.c +2
-2- OPT_CALLBACK_F('S', NULL, options, N_("<string>"), + OPT_CALLBACK_F('S', "patch-modifies", options, N_("<string>"), - OPT_CALLBACK_F('G', NULL, options, N_("<regex>"), + OPT_CALLBACK_F('G', "patch-grep", options, N_("<regex>"),OK. NOte that this says <regex>. We may want to have a separate clean-up patch so that
Documentation/gitdifcore.txtthat used <regular-expression> and the placeholder used here match.
Makes sense.
I've added this fix as patch 5 in v5.
I've reformatted paragraphs in gitdifcore.adoc that were affected. Let me know if you do not want me to reformat it, and just keep shorter lines as is.
Quoted 6 lines
diff.c struct option *add_diff_options(const struct option *opts, · line 5871
Quoted 2 lines
diff.c +1
-1- N_("look for differences that change the number of occurrences of the specified regex"), + N_("look for differences where a patch contains the specified regex"),This is an unrelated change that should not be in this patch. If you want to modify it, please do it in a separate clean-up patch, just like the above <regex> vs <regular-expression> change.
Split it into patch 2 in v5.
Quoted 10 lines
Quoted 2 lines
-
N_("show all changes in the changeset with -S or -G"),
+N_("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep"),This line is meant to be shown when the user requests list of options and their meanings. Growing the message from 47 columns or so to 78 columns would make it wider than terminals when these messages are indented. Because earlier entries in this array have already established the equivalence between the shorthand and the longhand, I do not think the output is understandable without this change.
A description for "-S" is already 81 characters long:
N_("look for differences that change the number of occurrences of the specified regex"),
So I was assuming if I grow another description to 77 characters, it is still OK. While one can find the correspondence between "-S" and "--patch-modifies" by reading the "-S" description, in my mind, the same argument applies as to the test readability - it just makes it a bit easier for the reader.
This change is now part of a much smaller patch 9 in v5, which is only about adding longer alternatives to the CLI help messages that currently contain only "-G" and "-S". This way you can decide if you want it or not as a complete unit. Or if you want me to change it in some way, we can discuss it separately from the rest of the changes.
By the way, I must admit I can not find a way to look at a help message generated from these strings. Running git diff -h shows a message from
diff.h and running git diff --help shows the man page.
Thank you.
Re: [PATCH v3 1/1] diff: --patch-{modifies,grep} arg names for -S and -G
Quoted 5 lines · Illia Bobyr
My thinking is that as long version names improve readability, it also applies
to the test code. When I see a short option, I often have to check the manual
to remember what exactly does it do.
But by now due to enough exposure, you have committed them in your memory, no? ;-)
Quoted 1 line
But, I think, I understand your point of view as well.
Yup, if the options were introduced with long and short forms at the same time and the tests were written at the same time or shortly after their introduction, I'd agree that using longer form more may be beneficial, since there is nobody who is already familier with either of the forms. But at this point after 20 years, swapping one for the other is mostly unnecessary churn, I would have to say (and I do not particularly want to having to repeat saying the same thing again).
Quoted 7 lines
Quoted 1 line
OK. NOte that this says <regex>. We may want to have a separate
clean-up
Quoted 2 lines
patch so that
Documentation/gitdifcore.txtthat used <regular-expression> and the placeholder used here match.Makes sense.
I've added this fix as patch 5 in v5.
I'd rather see these "fixes to existing anomalies" done totally outside of this series. IOW, I'd prefer to either (1) get the series done with the minimally necessary changes first and then after the dust settles from merging that to 'master', see these "oh we noticed these issues while working on the other series that has now completed" issues addressed, or (2) do the clean-up of existing anomalies first as a separate series, and then after the dust settles for the clean-up, do the proposed addition of longform as a separate series. I have slight preference to (1), simply because nobody complained on these small anomalies for the past 20 years ;-) but I can also go with "preliminary clean-up first" route.
Quoted 5 lines
Quoted 3 lines
This is an unrelated change that should not be in this patch. If you want to modify it, please do it in a separate clean-up patch, just like the above <regex> vs <regular-expression> change.
Split it into patch 2 in v5.
Again, when I said "unrelated", I meant that I want them to be treated as unrelated changes, addressed outside of this series, either in a preliminary clean-up, or after-the-dust-settles clean-up.
Thanks.
Quoted 4 lines · Illia Bobyr
Same as PATCH v2[1], but removed gitk changes, as suggested by Johannes Sixt.
I'll send a separate patch for gitk, should this patch be accepted. Or, I could include gitk changes into this chain, but just as a separate patch?
They are technically separate codebases so the changes to the core would become prerequisite for the same changes to gitk, so from that point of view the former may be more kosher, but I would expect that the latter is fine in practice.
v4 cover Long names for `git log -S` and `git log -G`
In reply to Illia BobyrI've split the big change from v3 [1] into multiple, mostly independent patches to make it easier to review and merge each one separately.
[1] https://lore.kernel.org/git/[email protected]/
Patches 1 through 4 are fixing minor bugs and inconsistencies.
Patch 5 contains updates gitdiffcore to use same placeholder names as the rest of the code.
Patch 6 contains a minimum change to add long versions of -S and -G.
Patch 7 adds bash completion support.
Patches 8 through 10 increase usage of the long argument versions in tests, CLI help and docs respectively.
Please, let me know if you prefer it split in a different way, or reorder the changes.
---
I was not sure if I should include a reference to the previous version of the patch into the next reroll. It seems that Documentation/MyFirstContribution.adoc suggests so. But it creates very long threads. And I've noticed that not everyone is doing it.
---
Reply to review notes from Junio C Hamano:
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Illia Bobyr
Most arguments have both short and long versions. Long versions are easier to read, especially in scripts and command history.
Tests that check just the option parsing are duplicated to check both short and long argument options. But more complex tests are updated to use the long argument in order to improve the test readability.
Quoted 5 lines
While checking both may be a prudent thing to do, because the "-S" option and the "-G" option have been there with us almost since the beginning of time, the swapping all existing use of them with the longhand is rather unwelcome and needless churn, I would have to say.
My thinking is that as long version names improve readability, it also applies to the test code. When I see a short option I often have to check the manual to remember what exactly does it do. Even for "-S"/"-G" I find myself sometimes confused as to which of the two does what exactly. While the "grep" mnemonic helps, I do not always remember it.
But, I think, I understand your point of view as well.
In v4 patch 5 contains a relatively minimum amount of changes that add long alternatives for "-S" and "-G" just to the command line parsing.
I do not have your experience with assessing the churn, but if my argument about the readability changes your mind, I've moved the rest of the updates into separate patches, at the end of the chain. Patches 8 through 10. Making it easier to discuss them in smaller chunks, if you wish so. But also, I assume, it should be easy for you to ignore those, if you do not want to include them?
Quoted 46 lines
[...]
Review renamed entries cannot appear if detection for those types is disabled. · line 662
Quoted 8 lines
(quoted diff) +2
-2@@ -657,18 +658,19 @@ renamed entries cannot appear if detection for those types is disabled. 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. +block in the preimage back into `--patch-modifies`, and keep going until +you get the very first version of the block.If this paragraph _were_ written with the longhand from the beginning, I would not have minded too much, but I personally find it unnecessary to churn the existing document like this.
Review renamed entries cannot appear if detection for those types is disabled. · line 664
Quoted 2 lines
(quoted diff) +1
-0`-G<regex>`:: +`--patch-grep=<regex>`::Same two paragraphs from the above apply here, and ...
Review renamed entries cannot appear if detection for those types is disabled. · line 667
Quoted 3 lines
(quoted diff) +0
-0`--find-object=<object-id>`:: `--pickaxe-all`:: `--pickaxe-regex`::... all of the above.
Documentation/git-blame.txt
Quoted 1 line
Documentation/git-blame.txt +0
-0Ditto.
Documentation/gitdiffcore.txt diffcore-pickaxe: For Detecting Addition/Deletion of Specified String · line 250
Quoted 12 lines
Documentation/gitdiffcore.txt +3
-1@@ -245,33 +245,35 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String This transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain -way. -S<block-of-text> and -G<regular-expression> options are used to +way. --patch-modifies=<block-of-text> and +--patch-grep=<regular-expression> options are used to specify +different ways these strings are sought.This is worse. Here is the first part that describes the pickaxe, so mentioning both may be more appropriate; showing only the longhand nobody is familiar with (yet) does not make any sense.
Quoted 7 lines
... certain way. `--patch-modifies=<block-of-text>` (`-S<block-of-text>` for short) and `--patch-grep=<regular-expression>` (`-G<regular-expression>` for short) are used to ...Once establishing the equivalence between the longhand and the shorthand for these two options, we do not have to churn the existing text at all.
Applied your suggestion.
I guess one difference in the way you look at it, is that you default to the short version when you can. While I default to the long one, as I assume it is easier to understand. Someone not that intimately familiar with git might need to go to the previous paragraph to recall what "-S" and "-G" are, while if they are spelled as "--patch-modifies" and "--patch-grep", it might be less necessary. So, the argument is that while we are reducing the diff, we might also be reducing the improvement in readability.
Being the author, I could also be biased when assessing how much more readable "--patch-modifies" and "--patch-grep" are compared to "-S" and "-G".
Quoted 26 lines
Quoted 12 lines
diff.c +1
-1@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options)if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_MASK ))die (_ ("options '%s', '%s', and '%s' cannot be used together" ), -"-G" ,"-S" ,"--find-object" ); +"-G/--patch-grep" ,"-S/--patch-modifies" ,"--find-object" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_G_REGEX_MASK ))diff.c void diff_setup_done(struct diff_options *options) · line 4890
Quoted 10 lines
diff.c +4
-2die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s'" ), -"-G" ,"--pickaxe-regex" ,"--pickaxe-regex" ,"-S" ); +"-G/--patch-grep" ,"--pickaxe-regex" , +"--pickaxe-regex" ,"-S/--patch-modifies" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'" ), -"--pickaxe-all" ,"--find-object" ,"--pickaxe-all" ,"-G" ,"-S" ); +"--pickaxe-all" ,"--find-object" , +"--pickaxe-all" ,"-G/--patch-grep" ,"-S/--patch-modifies" );The message change looks fine; the indentation is broken.
.git/rebase-apply/patch:184: indent with spaces.
Quoted 8 lines
"--pickaxe-regex", "-S/--patch-modifies"); .git/rebase-apply/patch:190: indent with spaces. "--pickaxe-all", "-G/--patch-grep", "-S/--patch-modifies");warning: 2 lines applied after fixing whitespace errors.
Applying: diff: --patch-{modifies,grep} arg names for -S and -GThese alone do not require a new iteration, as "git am --whitespace=fix" already corrected them.
Sorry about this. I did check the indentation manually, but did not use a tool. Reconfigured my editor to use tabs now.
Quoted 8 lines
diff.c void diff_setup_done(struct diff_options *options) · line 4892
Quoted 4 lines
diff.c +2
-2- OPT_CALLBACK_F('S', NULL, options, N_("<string>"), + OPT_CALLBACK_F('S', "patch-modifies", options, N_("<string>"), - OPT_CALLBACK_F('G', NULL, options, N_("<regex>"), + OPT_CALLBACK_F('G', "patch-grep", options, N_("<regex>"),OK. NOte that this says <regex>. We may want to have a separate clean-up patch so that
Documentation/gitdifcore.txtthat used <regular-expression> and the placeholder used here match.
Makes sense.
I've added this fix as patch 5.
I've reformatted paragraphs in gitdifcore.adoc that were affected. Let me know if you do not want me to reformat it, and just keep shorter lines as is.
Quoted 6 lines
diff.c void diff_setup_done(struct diff_options *options) · line 4893
Quoted 2 lines
diff.c +1
-1- N_("look for differences that change the number of occurrences of the specified regex"), + N_("look for differences where a patch contains the specified regex"),This is an unrelated change that should not be in this patch. If you want to modify it, please do it in a separate clean-up patch, just like the above <regex> vs <regular-expression> change.
Split it into patch 2.
Quoted 10 lines
diff.c
Quoted 2 lines
diff.c +1
-1- N_("show all changes in the changeset with -S or -G"), + N_("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep"),This line is meant to be shown when the user requests list of options and their meanings. Growing the message from 47 columns or so to 78 columns would make it wider than terminals when these messages are indented. Because earlier entries in this array have already established the equivalence between the shorthand and the longhand, I do not think the output is understandable without this change.
A description for "-S" is already 81 characters long:
N_("look for differences that change the number of occurrences of the specified regex"),
So I was assuming if I grow another description to 77 characters it is still OK. While one can find the correspondence between "-S" and "--patch-modifies" by reading the "-S" description, in my mind, the same argument applies as to the test readability - it just makes it a bit easier for the reader.
This change is now part of a much smaller patch 9, which is only about adding longer alternatives to the CLI help messages that currently contain only "-G" and "-S". This way you can decide if you want it or not as a complete unit. Or if you want me to change it in some way, we can discuss it separately from the rest of the changes.
By the way, I must admit I can not find a way to look at a help message generated from these strings. Running git diff -h shows a message from diff.h and running git diff --help shows the man page.
---
Illia Bobyr (10):
t/t4209-log-pickaxe: Naming typo: -G takes a regex
diff: -G description: Correct copy/paste error
diff: short help: Correct -S description
diff: short help: Add -G and --pickaxe-grep
docs: gitdiffcore: -G and -S: Use regex/string placeholders
diff: --patch-{grep,modifies} arg names for -G and -S
completion: Support --patch-{grep,modifies}
diff: test: Use --patch-{grep,modifies} over -G/-S
diff: --pickaxe-{all,regex} help: Add --patch-{grep,modifies}
diff: docs: Use --patch-{grep,modifies} over -G/-S
Documentation/diff-options.adoc | 36 +++++---- Documentation/git-blame.adoc | 2 +- Documentation/gitdiffcore.adoc | 55 ++++++------- contrib/completion/git-completion.bash | 11 ++- diff.c | 18 +++-- diff.h | 11 ++- t/t4062-diff-pickaxe.sh | 8 +- t/t4209-log-pickaxe.sh | 106 +++++++++++++++++-------- 8 files changed, 155 insertions(+), 92 deletions(-)
Signature · 1 line
2.45.2
Quoted 12 lines · Illia Bobyr
I've split the big change from v3 [1] into multiple, mostly independent patches to make it easier to review and merge each one separately.
[1] https://lore.kernel.org/git/[email protected]/
Patches 1 through 4 are fixing minor bugs and inconsistencies.
Patch 5 contains updates gitdiffcore to use same placeholder names as the rest of the code.
Patch 6 contains a minimum change to add long versions of -S and -G.
Quoted 7 lines
Patch 7 adds bash completion support.
Patches 8 through 10 increase usage of the long argument versions in tests, CLI help and docs respectively.
Please, let me know if you prefer it split in a different way, or reorder the changes.
When you base your patch on a different base than 'master' (or if the previous iteration of the topic has already been queued in my tree, then the commit used as the base to queue the topic), please make sure you state it clearly.
This iteration seems to apply on none of bc204b74 (The seventh batch, 2025-02-03), on top of which the previous round dcc02caba2 (ib/diff-S-G-with-longhand) has been queued, or any of the recent tips of 'master', like 388218fa (The ninth batch, 2025-02-10) or 9520f7d9 (The eighth batch, 2025-02-06), so I cannot look at it.
Quoted 4 lines
I was not sure if I should include a reference to the previous version of the patch into the next reroll. It seems that
Documentation/MyFirstContribution.adocsuggests so. But it creates very long threads. And I've noticed that not everyone is doing it.
Almost everybody does so, actually.
Taking a topic that has 5 iterations, each about ~20 patches, as an example:
https://lore.kernel.org/git/20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im/
it is perfectly clear and easy to nagivate from the list of messages what discussions we had in previous iterations.
Quoted 1 line
Reply to review notes ...
It is more customary to Reply-all directly to review messages, instead of sending new round of patches. When the cover letter of a new iteration is sent as a response to the cover letter of the previous iteration, readers can find the previous discussion messages.
Thanks.
Quoted 27 lines · Junio C Hamano
Quoted 12 lines · Illia Bobyr
I've split the big change from v3 [1] into multiple, mostly independent patches to make it easier to review and merge each one separately.
[1] https://lore.kernel.org/git/[email protected]/
Patches 1 through 4 are fixing minor bugs and inconsistencies.
Patch 5 contains updates gitdiffcore to use same placeholder names as the rest of the code.
Patch 6 contains a minimum change to add long versions of -S and -G.
Quoted 7 lines
Patch 7 adds bash completion support.
Patches 8 through 10 increase usage of the long argument versions in tests, CLI help and docs respectively.
Please, let me know if you prefer it split in a different way, or reorder the changes.
When you base your patch on a different base than 'master' (or if the previous iteration of the topic has already been queued in my tree, then the commit used as the base to queue the topic), please make sure you state it clearly.
Quoted 5 lines
This iteration seems to apply on none of
bc204b74(The seventh batch, 2025-02-03), on top of which the previous rounddcc02caba2(ib/diff-S-G-with-longhand) has been queued, or any of the recent tips of 'master', like388218fa(The ninth batch, 2025-02-10) or9520f7d9(The eighth batch, 2025-02-06), so I cannot look at it.
Sorry for the confusion. I randomly decided to check if my changes have any conflicts with next and rebased on top of it.
Did not realize it would affect the patches.
I've rebased back on top of master and published as v5.
Quoted 7 lines
Quoted 4 lines
I was not sure if I should include a reference to the previous version of the patch into the next reroll. It seems that
Documentation/MyFirstContribution.adocsuggests so. But it creates very long threads. And I've noticed that not everyone is doing it.Almost everybody does so, actually.
Quoted 7 lines
Taking a topic that has 5 iterations, each about ~20 patches, as an example:
https://lore.kernel.org/git/20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im/
it is perfectly clear and easy to nagivate from the list of messages what discussions we had in previous iterations.
Thank you for the explanation and for sharing an example link. I'll use v3 cover letter as a reference point for v5, as I have already interrupted the reference chain in v3.
Quoted 7 lines
Quoted 1 line
Reply to review notes ...
It is more customary to Reply-all directly to review messages, instead of sending new round of patches. When the cover letter of a new iteration is sent as a response to the cover letter of the previous iteration, readers can find the previous discussion messages.
Got it. Thank you. I have replied to your review email, so that we can continue the conversation there.
PATCH v4 1/10 t/t4209-log-pickaxe: Naming typo: -G takes a regex
In reply to Illia BobyrNot effect on the test logic, but as "-G" argument is a regex it is more accurate to use "regex" as a dummy argument value rather than "string". In all the other case when "-G" is passed a dummy value it is spelled as "regex" rather than as "string".
--- t/t4209-log-pickaxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t4209-log-pickaxe.sh +1 -1
@@ -89,7 +89,7 @@ test_expect_success 'usage: --no-pickaxe-regex' ' test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual && test_cmp expect actual && - test_expect_code 128 git log -Gstring --no-pickaxe-regex 2>err && + test_expect_code 128 git log -Gregex --no-pickaxe-regex 2>err && test_cmp expect actual '
Signature · 1 line
2.45.2
PATCH v4 2/10 diff: -G description: Correct copy/paste error
In reply to Illia BobyrCurrent description for -G is incorrect, seems like it was copied from the description for -S.
--- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff.c +1 -1
@@ -5866,7 +5866,7 @@ struct option *add_diff_options(const struct option *opts, N_("look for differences that change the number of occurrences of the specified string"), 0, diff_opt_pickaxe_string),OPT_CALLBACK_F ('G' ,NULL , options,N_ ("<regex>" ), -N_ ("look for differences that change the number of occurrences of the specified regex" ), +N_ ("look for differences where a patch contains the specified regex" ),0 , diff_opt_pickaxe_regex), OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts, N_("show all changes in the changeset with -S or -G"),
Signature · 1 line
2.45.2
PATCH v4 3/10 diff: short help: Correct -S description
In reply to Illia Bobyr-S shows changes that modify the number of occurrences of the specified string, rather than only those that either completely remove it or add it for the first time.
--- diff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff.h +1 -1
@@ -606,7 +606,7 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ -" -S<string> find filepair whose only one side contains the string.\n" \ +" -S<string> find filepair who differ in the number of occurrences of string.\n" \" --pickaxe-all\n" \" show all files diff when -S is used and hit is found.\n" \" -a --text treat all files as text.\n"
Signature · 1 line
2.45.2
PATCH v4 4/10 diff: short help: Add -G and --pickaxe-grep
In reply to Illia Bobyr-G and --pickaxe-grep seems to be on par with -S and --pickaxe-all that are already mentioned.
--- diff.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff.h +4 -1
@@ -606,9 +606,12 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ +" -G<regex> find differences where patch contains the specified regex.\n" \" -S<string> find filepair who differ in the number of occurrences of string.\n" \ +" --pickaxe-grep\n" \ +" treat <string> as a regex in the -S argument.\n" \" --pickaxe-all\n" \ -" show all files diff when -S is used and hit is found.\n" \ +" show all files diff when -G or -S is used and hit is found.\n" \" -a --text treat all files as text.\n" int diff_queue_is_empty(struct diff_options *o);
Signature · 1 line
2.45.2
PATCH v4 5/10 docs: gitdiffcore: -G and -S: Use regex/string placeholders
In reply to Illia BobyrIn the rest of the documentation (and in the code) we use regex and string as -G and -S argument placeholders. While regular-expression and block-of-text are a bit easier to read, it is a bit consistent.
And we could assume that everyone who uses git should be able to understand that a "string" and a "block-of-text", as well as a "regex" and "regular-expression" are the same thing. So, using a shorter version is also more consistent.
--- Documentation/gitdiffcore.adoc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
Documentation/gitdiffcore.adoc +11 -12
@@ -245,26 +245,25 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String This transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain -way. -S<block-of-text> and -G<regular-expression> options are used to -specify different ways these strings are sought. +way. `-S<string>` and `-G<regex>` options are used to 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. +`-S<string>` detects filepairs whose preimage and postimage +have different number of occurrences of the specified _<string>_. By definition, it will not detect in-file moves. Also, when a changeset moves a file wholesale without affecting the interesting string, 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). When used with `--pickaxe-regex`, treat -the <block-of-text> as an extended POSIX regular expression to match, +the _<string>_ 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 will detect in-file (or what -rename-detection considers the same file) moves, which is noise. The -implementation runs diff twice and greps, and this can be quite -expensive. To speed things up, binary files without textconv filters -will be ignored. +`-G<regex>` (mnemonic: grep) detects filepairs whose textual diff has +an added or a deleted line that matches the given _<regex>_. This +means that it will detect in-file (or what rename-detection considers +the same file) moves, which is noise. The implementation runs diff +twice and greps, and this can be quite expensive. To speed things up, +binary files without textconv filters will be ignored. When `-S` or `-G` are used without `--pickaxe-all`, only filepairs that match their respective criterion are kept in the output. When
Signature · 1 line
2.45.2
PATCH v4 6/10 diff: --patch-{grep,modifies} arg names for -G and -S
In reply to Illia BobyrMost 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.
--- Documentation/diff-options.adoc | 2 ++ Documentation/gitdiffcore.adoc | 3 ++- diff.c | 12 ++++++---- diff.h | 8 +++++-- t/t4209-log-pickaxe.sh | 42 +++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-)
Documentation/diff-options.adoc +2 -0
@@ -650,6 +650,7 @@ Note that not all diffs can feature all types. For instance, copied and renamed entries cannot appear if detection for those types is disabled. `-S<string>`:: +`--patch-modifies=<string>`:: 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.
@@ -663,6 +664,7 @@ very first version of the block. Binary files are searched as well. `-G<regex>`:: +`--patch-grep=<regex>`:: Look for differences whose patch text contains added/removed lines that match _<regex>_. +
Documentation/gitdiffcore.adoc +2 -1
@@ -245,7 +245,8 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String This transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain -way. `-S<string>` and `-G<regex>` options are used to specify +way. `--patch-modifies=<string>` (`-S<string>` for short) and +`--patch-grep=<regex>` (`-G<regex>` for short) are used to specify different ways these strings are sought. `-S<string>` detects filepairs whose preimage and postimage
diff.c +7 -5
@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options)if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_MASK ))die (_ ("options '%s', '%s', and '%s' cannot be used together" ), -"-G" ,"-S" ,"--find-object" ); +"-G/--patch-grep" ,"-S/--patch-modifies" ,"--find-object" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_G_REGEX_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s'" ), -"-G" ,"--pickaxe-regex" ,"--pickaxe-regex" ,"-S" ); +"-G/--patch-grep" ,"--pickaxe-regex" , +"--pickaxe-regex" ,"-S/--patch-modifies" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'" ), -"--pickaxe-all" ,"--find-object" ,"--pickaxe-all" ,"-G" ,"-S" ); +"--pickaxe-all" ,"--find-object" , +"--pickaxe-all" ,"-G/--patch-grep" ,"-S/--patch-modifies" );/* * Most of the time we can say "there are changes"
@@ -5862,10 +5864,10 @@ struct option *add_diff_options(const struct option *opts,OPT_SET_INT_F (0 ,"ita-visible-in-index" , &options->ita_invisible_in_index,N_ ("treat 'git add -N' entries as real in the index" ),0 ,PARSE_OPT_NONEG ), -OPT_CALLBACK_F ('S' ,NULL , options,N_ ("<string>" ), +OPT_CALLBACK_F ('S' ,"patch-modifies" , options,N_ ("<string>" ),N_ ("look for differences that change the number of occurrences of the specified string" ),0 , diff_opt_pickaxe_string), -OPT_CALLBACK_F ('G' ,NULL , options,N_ ("<regex>" ), +OPT_CALLBACK_F ('G' ,"patch-grep" , options,N_ ("<regex>" ),N_ ("look for differences where a patch contains the specified regex" ),0 , diff_opt_pickaxe_regex), OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts,
diff.h +6 -2
@@ -606,8 +606,12 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ -" -G<regex> find differences where patch contains the specified regex.\n" \ -" -S<string> find filepair who differ in the number of occurrences of string.\n" \ +" -G<regex>\n" \ +" --patch-grep=<regex>\n" \ +" find differences where patch contains the regex.\n" \ +" -S<string>\n" \ +" --patch-modifies=<string>\n" \ +" find filepair who differ in the number of occurrences of string.\n" \" --pickaxe-grep\n" \" treat <string> as a regex in the -S argument.\n" \" --pickaxe-all\n" \
t/t4209-log-pickaxe.sh +42 -0
96 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v4 7/10 completion: Support --patch-{grep,modifies}
In reply to Illia Bobyr--- contrib/completion/git-completion.bash | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
contrib/completion/git-completion.bash +10 -1
@@ -1900,6 +1900,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary --output= --output-indicator-context= --output-indicator-new= --output-indicator-old= --ws-error-highlight= + --patch-grep= --patch-modifies= --pickaxe-all --pickaxe-regex --patch-with-raw "
@@ -2216,7 +2217,7 @@ __git_complete_log_opts () __git_complete_symbol --cur="${cur#:}" --sfx=":" return ;; - -G,*|-S,*) + -G,*|--patch-grep,*|-S,*|--patch-modifies,*) __git_complete_symbol return ;;
@@ -2239,6 +2240,14 @@ __git_complete_log_opts () __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" return ;; + --patch-grep=*) + __git_complete_symbol --pfx="--patch-grep=" --cur="${cur#--patch-grep=}" + return + ;; + --patch-modifies=*) + __git_complete_symbol --pfx="--patch-modifies=" --cur="${cur#--patch-modifies=}" + return + ;; --submodule=*) __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" return
Signature · 1 line
2.45.2
PATCH v4 8/10 diff: test: Use --patch-{grep,modifies} over -G/-S
In reply to Illia BobyrLong argument names are easier to read, compared to short ones. So while short arguments are great when you want to type a command quickly, tests are more readable if we use long argument names.
There are still test that verify that both short and long arguments work interchangeably when parsing the arguments.
Tests where the focus is not on the argument names are updated to use long argument names.
--- t/t4062-diff-pickaxe.sh | 8 +++--- t/t4209-log-pickaxe.sh | 62 ++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 35 deletions(-)
t/t4062-diff-pickaxe.sh +4 -4
@@ -16,13 +16,13 @@ test_expect_success setup ' ' # OpenBSD only supports up to 255 repetitions, so repeat twice for 64*64=4096. -test_expect_success '-G matches' ' - git diff --name-only -G "^(0{64}){64}$" HEAD^ >out && +test_expect_success '--patch-grep matches' ' + git diff --name-only --patch-grep "^(0{64}){64}$" HEAD^ >out && test 4096-zeroes.txt = "$(cat out)" ' -test_expect_success '-S --pickaxe-regex' ' - git diff --name-only -S0 --pickaxe-regex HEAD^ >out && +test_expect_success '--patch-modifies --pickaxe-regex' ' + git diff --name-only --patch-modifies 0 --pickaxe-regex HEAD^ >out && test 4096-zeroes.txt = "$(cat out)" '
t/t4209-log-pickaxe.sh +31 -31
139 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v4 9/10 diff: --pickaxe-{all,regex} help: Add --patch-{grep,modifies}
In reply to Illia BobyrFor less experienced users --patch-{grep,modifies} should be easier to understand than just -S or -G. By mentioning the long argument names in the help messages we save those users from having to search the list of options for an explanation of what -S or -G stand for.
--- diff.c | 4 ++-- diff.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
diff.c +2 -2
@@ -5871,10 +5871,10 @@ struct option *add_diff_options(const struct option *opts, N_("look for differences where a patch contains the specified regex"), 0, diff_opt_pickaxe_regex),OPT_BIT_F (0 ,"pickaxe-all" , &options->pickaxe_opts, -N_ ("show all changes in the changeset with -S or -G" ), +N_ ("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep" ),DIFF_PICKAXE_ALL ,PARSE_OPT_NONEG ),OPT_BIT_F (0 ,"pickaxe-regex" , &options->pickaxe_opts, -N_ ("treat <string> in -S as extended POSIX regular expression" ), +N_ ("treat <string> in -S/--patch-modifies as extended POSIX regular expression" ),DIFF_PICKAXE_REGEX ,PARSE_OPT_NONEG ),OPT_FILENAME ('O' ,NULL , &options->orderfile, N_("control the order in which files appear in the output")),
diff.h +2 -2
@@ -613,9 +613,9 @@ void diffcore_fix_diff_index(void);" --patch-modifies=<string>\n" \" find filepair who differ in the number of occurrences of string.\n" \" --pickaxe-grep\n" \ -" treat <string> as a regex in the -S argument.\n" \ +" treat <string> as a regex in the -S/--patch-modifies argument.\n" \" --pickaxe-all\n" \ -" show all files diff when -G or -S is used and hit is found.\n" \ +" show all files diff for -G/--patch-grep and -S/--patch-modifies.\n" \" -a --text treat all files as text.\n" int diff_queue_is_empty(struct diff_options *o);
Signature · 1 line
2.45.2
PATCH v4 10/10 diff: docs: Use --patch-{grep,modifies} over -G/-S
In reply to Illia BobyrLong argument names are easier to read, compared to short ones. So while short arguments are great when you want to type a command quickly, the documentation readability is improved if we use long argument names.
Note for reviewers: All changes are just a replacement of -G with --patch-grep and -S with --patch-modifies. But as the text was reformatted to fit the same width in a few places it might look like there are more changes, if the diff is only line-wise and not word-wise.
The only an exception are changes in gitdiffcore.adoc, where I did rephrase a sentence. I've moved introduction of the short versions of the --patch-{grep,modifies} into a subsequent paragraph. The reason is that I wanted to keep a note on the -G mnemonic, and it was awkward if I would repeat the short definition twice over a span of two paragraphs.
--- Documentation/diff-options.adoc | 34 ++++++++++---------- Documentation/git-blame.adoc | 2 +- Documentation/gitdiffcore.adoc | 55 +++++++++++++++++---------------- 3 files changed, 46 insertions(+), 45 deletions(-)
Documentation/diff-options.adoc +17 -17
@@ -658,8 +658,8 @@ renamed entries cannot appear if detection for those types is disabled. 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. +block in the preimage back into `--patch-modifies`, and keep going until +you get the very first version of the block. + Binary files are searched as well.
@@ -668,9 +668,9 @@ Binary files are searched as well. 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: +To illustrate the difference between `--patch-modifies=<regex> +--pickaxe-regex` and `--patch-grep=<regex>`, consider a commit with the +following diff in the same file: + ---- + return frotz(nitfol, two->ptr, 1, 0);
@@ -678,9 +678,9 @@ file: - hit = frotz(nitfol, mf2.ptr, 1, 0); ---- + -While `git log -G"frotz\(nitfol"` will show this commit, `git log --S"frotz\(nitfol" --pickaxe-regex` will not (because the number of -occurrences of that string did not change). +While `git log --patch-grep="frotz\(nitfol"` will show this commit, `git +log --patch-modifies="frotz\(nitfol" --pickaxe-regex` will not (because the +number of occurrences of that string did not change). + Unless `--text` is supplied patches of binary files without a textconv filter will be ignored.
@@ -689,22 +689,22 @@ See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more information. `--find-object=<object-id>`:: - Look for differences that change the number of occurrences of - the specified object. Similar to `-S`, just the argument is different - in that it doesn't search for a specific string but for a specific - object id. + Look for differences that change the number of occurrences of the + specified object. Similar to `--patch-modifies`, just the argument + is different in that it doesn't search for a specific string but + for a specific object id. + The object can be a blob or a submodule commit. It implies the `-t` option in `git-log` to also find trees. `--pickaxe-all`:: - When `-S` or `-G` finds a change, show all the changes in that - changeset, not just the files that contain the change - in _<string>_. + When `--patch-modifies` or `--patch-grep` finds a change, show all + the changes in that changeset, not just the files that contain the + change in _<string>_. `--pickaxe-regex`:: - Treat the _<string>_ given to `-S` as an extended POSIX regular - expression to match. + Treat the _<string>_ given to `--patch-modifies` as an extended + POSIX regular expression to match. endif::git-format-patch[]
Documentation/git-blame.adoc +1 -1
@@ -41,7 +41,7 @@ a text string in the diff. A small example of the pickaxe interface that searches for `blame_usage`: ----------------------------------------------------------------------------- -$ git log --pretty=oneline -S'blame_usage' +$ git log --pretty=oneline --patch-modifies='blame_usage' 5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file> ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output -----------------------------------------------------------------------------
Documentation/gitdiffcore.adoc +28 -27
61 lines not on this page · raw message
Signature · 1 line
2.45.2
v5 cover Long names for `git log -S` and `git log -G`
In reply to Illia BobyrRebased v4 [1] on top of master.
I've accidentally published v4 based on next.
[1] https://lore.kernel.org/git/[email protected]/
Other than the rebase, it is identical to v4, details below.
Split the big change from v3 [1] into multiple, mostly independent patches, to make it easier to review and merge each one separately.
Patches 1 through 4 are fixing minor bugs and inconsistencies.
Patch 5 contains updates gitdiffcore to use same placeholder names as the rest of the code.
Patch 6 contains a minimum change to add long versions of -S and -G.
Patch 7 adds bash completion support.
Patches 8 through 10 increase usage of the long argument versions in tests, CLI help and docs respectively.
Please, let me know if you prefer it split in a different way, or reorder the changes.
Illia Bobyr (10):
t/t4209-log-pickaxe: Naming typo: -G takes a regex
diff: -G description: Correct copy/paste error
diff: short help: Correct -S description
diff: short help: Add -G and --pickaxe-grep
docs: gitdiffcore: -G and -S: Use regex/string placeholders
diff: --patch-{grep,modifies} arg names for -G and -S
completion: Support --patch-{grep,modifies}
diff: test: Use --patch-{grep,modifies} over -G/-S
diff: --pickaxe-{all,regex} help: Add --patch-{grep,modifies}
diff: docs: Use --patch-{grep,modifies} over -G/-S
Documentation/diff-options.txt | 36 +++++---- Documentation/git-blame.txt | 2 +- Documentation/gitdiffcore.txt | 55 ++++++------- contrib/completion/git-completion.bash | 11 ++- diff.c | 18 +++-- diff.h | 11 ++- t/t4062-diff-pickaxe.sh | 8 +- t/t4209-log-pickaxe.sh | 106 +++++++++++++++++-------- 8 files changed, 155 insertions(+), 92 deletions(-)
Signature · 1 line
2.45.2
PATCH v5 1/10 t/t4209-log-pickaxe: Naming typo: -G takes a regex
Not effect on the test logic, but as "-G" argument is a regex it is more accurate to use "regex" as a dummy argument value rather than "string". In all the other case when "-G" is passed a dummy value it is spelled as "regex" rather than as "string".
--- t/t4209-log-pickaxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t4209-log-pickaxe.sh +1 -1
@@ -89,7 +89,7 @@ test_expect_success 'usage: --no-pickaxe-regex' ' test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual && test_cmp expect actual && - test_expect_code 128 git log -Gstring --no-pickaxe-regex 2>err && + test_expect_code 128 git log -Gregex --no-pickaxe-regex 2>err && test_cmp expect actual '
Signature · 1 line
2.45.2
Re: [PATCH v5 01/10] t/t4209-log-pickaxe: Naming typo: -G takes a regex
Quoted 1 line · Illia Bobyr
Subject: Re: [PATCH v5 01/10] t/t4209-log-pickaxe: Naming typo: -G takes a regex
"Naming" -> "naming". It is even more preferable if you can avoid introducing the second colon. E.g.
Subject: t/t4209: call the value given to -G <regex>, not <string>
This applies to the titles of all the patches in the series, I suspect?
Quoted 4 lines
Not effect on the test logic, but as "-G" argument is a regex it is more accurate to use "regex" as a dummy argument value rather than "string". In all the other case when "-G" is passed a dummy value it is spelled as "regex" rather than as "string".
I guess the -G tests are copied-and-pasted from existing tests for the -S option when the -G option was introduced much later. This makes me wonder if we try to see what happens when a malformed regular expression is fed to the -G option (I didn't check---if we have no test for it, we might want to add one).
Quoted 1 line
---
Missing sign-off.
Having said all that, I'd prefer to see the changes in one topic focused only to give --patch-grep and --patch-modifies synonyms to the existing option and do nothing else. Certainly a change like this is a distraction we do not have to discuss at the same time.
If you can group all these "preliminary clean-up" changes together into a separate series, without including any change to add the longhand to -S/-G, that is also a viable alternative approach. Once such a series graduates to 'master', then you'd do the longhand on top.
What we do not want is to see changes that are not directly necessary to add the longhand intermixed in the same series.
Quoted 8 lines
t/t4209-log-pickaxe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t4209-log-pickaxe.sh +0
-0
t/t4209-log-pickaxe.sh test_expect_success 'usage: --no-pickaxe-regex' ' · line 94
Quoted 7 lines
t/t4209-log-pickaxe.sh +1
-1@@ -89,7 +89,7 @@ test_expect_success 'usage: --no-pickaxe-regex' ' test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual && test_cmp expect actual && - test_expect_code 128 git log -Gstring --no-pickaxe-regex 2>err && + test_expect_code 128 git log -Gregex --no-pickaxe-regex 2>err && test_cmp expect actual '
Thanks.
PATCH v5 2/10 diff: -G description: Correct copy/paste error
In reply to Illia BobyrCurrent description for -G is incorrect, seems like it was copied from the description for -S.
--- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff.c +1 -1
@@ -5866,7 +5866,7 @@ struct option *add_diff_options(const struct option *opts, N_("look for differences that change the number of occurrences of the specified string"), 0, diff_opt_pickaxe_string),OPT_CALLBACK_F ('G' ,NULL , options,N_ ("<regex>" ), -N_ ("look for differences that change the number of occurrences of the specified regex" ), +N_ ("look for differences where a patch contains the specified regex" ),0 , diff_opt_pickaxe_regex), OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts, N_("show all changes in the changeset with -S or -G"),
Signature · 1 line
2.45.2
Re: [PATCH v5 02/10] diff: -G description: Correct copy/paste error
Quoted 5 lines · Illia Bobyr
Current description for -G is incorrect, seems like it was copied from the description for -S.
--- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[jc: I won't point out about the title and sign-off, which are the same issues [1/10] had and maybe shared with the later patches]
diff.c struct option *add_diff_options(const struct option *opts, · line 5869
Quoted 11 lines
diff.c +1
-1@@ -5866,7 +5866,7 @@ struct option *add_diff_options(const struct option *opts, N_("look for differences that change the number of occurrences of the specified string"), 0, diff_opt_pickaxe_string), OPT_CALLBACK_F('G', NULL, options, N_("<regex>"), - N_("look for differences that change the number of occurrences of the specified regex"), + N_("look for differences where a patch contains the specified regex"),
Yeah, but the updated one is not all that great, either. -S looks for string, so either "occurences" or "contains" would work, but a patch that "contains" the regular expression would not necessarily match with -G ;-)
"a patch contains a line that matches" is closer but not correct.
What the option looks for is if there is a changed line in the patch that matches the given regular expression. If a context line shared between the preimage and the postimage matches the regular expression that does not count as a "hit".
N_("find differences with changed lines that match the given regex").
perhaps?
Again, this is "preliminary clean-up" (or "after-the-dust-settles") material and shouldn't be part of the main series.
Thanks.
PATCH v5 3/10 diff: short help: Correct -S description
In reply to Illia Bobyr-S shows changes that modify the number of occurrences of the specified string, rather than only those that either completely remove it or add it for the first time.
--- diff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff.h +1 -1
@@ -606,7 +606,7 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ -" -S<string> find filepair whose only one side contains the string.\n" \ +" -S<string> find filepair who differ in the number of occurrences of string.\n" \" --pickaxe-all\n" \" show all files diff when -S is used and hit is found.\n" \" -a --text treat all files as text.\n"
Signature · 1 line
2.45.2
Re: [PATCH v5 03/10] diff: short help: Correct -S description
Quoted 4 lines · Illia Bobyr
-Sshows changes that modify the number of occurrences of the specified string, rather than only those that either completely remove it or add it for the first time.
---
[jc: title, sign-off, and this should be done outside the main topic are shared with other patches, so I won't repeat them]
diff.h void diffcore_fix_diff_index(void); · line 609
Quoted 13 lines
diff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)diff.h +1
-1@@ -606,7 +606,7 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ -" -S<string> find filepair whose only one side contains the string.\n" \ +" -S<string> find filepair who differ in the number of occurrences of string.\n" \
Given that the initial motivation of -S<block-of-text> was to find "before it wasn't there in that shape, now there it is" [*1*] (and <block-of-text> wasn meant to be something unique in the codebase), the original conveys the intent better, but the updated text describes the actual behaviour more correctly (in other words, the behaviour of the option when a not-so-unique string that may produce multiple hits is given is whatever it happens to do---which is "see the number of occurrences are different").
So this is a good change.
[Foornote]
*1* The original motivation of "-S<block-of-text>" was to be a
building block for the tool Linus dreamed in his message
https://lore.kernel.org/git/[email protected]
that explained why recording renames at the commit time is a bad idea.
Quoted 3 lines
diff.h +0
-0" --pickaxe-all\n" \" show all files diff when -S is used and hit is found.\n" \" -a --text treat all files as text.\n"
PATCH v5 4/10 diff: short help: Add -G and --pickaxe-grep
In reply to Illia Bobyr-G and --pickaxe-grep seems to be on par with -S and --pickaxe-all that are already mentioned.
--- diff.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff.h +4 -1
@@ -606,9 +606,12 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ +" -G<regex> find differences where patch contains the specified regex.\n" \" -S<string> find filepair who differ in the number of occurrences of string.\n" \ +" --pickaxe-grep\n" \ +" treat <string> as a regex in the -S argument.\n" \" --pickaxe-all\n" \ -" show all files diff when -S is used and hit is found.\n" \ +" show all files diff when -G or -S is used and hit is found.\n" \" -a --text treat all files as text.\n" int diff_queue_is_empty(struct diff_options *o);
Signature · 1 line
2.45.2
PATCH v5 5/10 docs: gitdiffcore: -G and -S: Use regex/string placeholders
In reply to Illia BobyrIn the rest of the documentation (and in the code) we use regex and string as -G and -S argument placeholders. While regular-expression and block-of-text are a bit easier to read, it is a bit consistent.
And we could assume that everyone who uses git should be able to understand that a "string" and a "block-of-text", as well as a "regex" and "regular-expression" are the same thing. So, using a shorter version is also more consistent.
--- Documentation/gitdiffcore.txt | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
Documentation/gitdiffcore.txt +11 -12
@@ -245,26 +245,25 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String This transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain -way. -S<block-of-text> and -G<regular-expression> options are used to -specify different ways these strings are sought. +way. `-S<string>` and `-G<regex>` options are used to 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. +`-S<string>` detects filepairs whose preimage and postimage +have different number of occurrences of the specified _<string>_. By definition, it will not detect in-file moves. Also, when a changeset moves a file wholesale without affecting the interesting string, 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). When used with `--pickaxe-regex`, treat -the <block-of-text> as an extended POSIX regular expression to match, +the _<string>_ 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 will detect in-file (or what -rename-detection considers the same file) moves, which is noise. The -implementation runs diff twice and greps, and this can be quite -expensive. To speed things up, binary files without textconv filters -will be ignored. +`-G<regex>` (mnemonic: grep) detects filepairs whose textual diff has +an added or a deleted line that matches the given _<regex>_. This +means that it will detect in-file (or what rename-detection considers +the same file) moves, which is noise. The implementation runs diff +twice and greps, and this can be quite expensive. To speed things up, +binary files without textconv filters will be ignored. When `-S` or `-G` are used without `--pickaxe-all`, only filepairs that match their respective criterion are kept in the output. When
Signature · 1 line
2.45.2
Re: [PATCH v5 05/10] docs: gitdiffcore: -G and -S: Use regex/string placeholders
Quoted 5 lines · Illia Bobyr
In the rest of the documentation (and in the code) we use
regexandstringas-Gand-Sargument placeholders. Whileregular-expressionandblock-of-textare a bit easier to read, it is a bit consistent.
Quoted 7 lines
And we could assume that everyone who uses git should be able to understand that a "string" and a "block-of-text", as well as a "regex" and "regular-expression" are the same thing. So, using a shorter version is also more consistent.
--- Documentation/gitdiffcore.txt | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
I am with one reservation. <block-of-text> was written to stress the fact that most of the time the string is expected to be a multi-line block of text (like a function body) [*1*] that is unique within the codebase. I do not think replacing a short-and-sweet <string> with <block-of-text> is a good idea, but if we are to go this route, we should mention that to compensate for the diminished stress on that block-ness of the text, as <string> would imply something quite short and would fit on a single line.
[Footnote]
*1* Go back to Linus's message I cited earlier;
https://lore.kernel.org/git/[email protected]/
PATCH v5 6/10 diff: --patch-{grep,modifies} arg names for -G and -S
In reply to Illia BobyrMost 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.
--- Documentation/diff-options.txt | 2 ++ Documentation/gitdiffcore.txt | 3 ++- diff.c | 12 ++++++---- diff.h | 8 +++++-- t/t4209-log-pickaxe.sh | 42 ++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-)
Documentation/diff-options.txt +2 -0
@@ -650,6 +650,7 @@ Note that not all diffs can feature all types. For instance, copied and renamed entries cannot appear if detection for those types is disabled. `-S<string>`:: +`--patch-modifies=<string>`:: 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.
@@ -663,6 +664,7 @@ very first version of the block. Binary files are searched as well. `-G<regex>`:: +`--patch-grep=<regex>`:: Look for differences whose patch text contains added/removed lines that match _<regex>_. +
Documentation/gitdiffcore.txt +2 -1
@@ -245,7 +245,8 @@ diffcore-pickaxe: For Detecting Addition/Deletion of Specified String This transformation limits the set of filepairs to those that change specified strings between the preimage and the postimage in a certain -way. `-S<string>` and `-G<regex>` options are used to specify +way. `--patch-modifies=<string>` (`-S<string>` for short) and +`--patch-grep=<regex>` (`-G<regex>` for short) are used to specify different ways these strings are sought. `-S<string>` detects filepairs whose preimage and postimage
diff.c +7 -5
@@ -4877,15 +4877,17 @@ void diff_setup_done(struct diff_options *options)if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_MASK ))die (_ ("options '%s', '%s', and '%s' cannot be used together" ), -"-G" ,"-S" ,"--find-object" ); +"-G/--patch-grep" ,"-S/--patch-modifies" ,"--find-object" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_G_REGEX_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s'" ), -"-G" ,"--pickaxe-regex" ,"--pickaxe-regex" ,"-S" ); +"-G/--patch-grep" ,"--pickaxe-regex" , +"--pickaxe-regex" ,"-S/--patch-modifies" );if (HAS_MULTI_BITS (options->pickaxe_opts &DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK ))die (_ ("options '%s' and '%s' cannot be used together, use '%s' with '%s' and '%s'" ), -"--pickaxe-all" ,"--find-object" ,"--pickaxe-all" ,"-G" ,"-S" ); +"--pickaxe-all" ,"--find-object" , +"--pickaxe-all" ,"-G/--patch-grep" ,"-S/--patch-modifies" );/* * Most of the time we can say "there are changes"
@@ -5862,10 +5864,10 @@ struct option *add_diff_options(const struct option *opts,OPT_SET_INT_F (0 ,"ita-visible-in-index" , &options->ita_invisible_in_index,N_ ("treat 'git add -N' entries as real in the index" ),0 ,PARSE_OPT_NONEG ), -OPT_CALLBACK_F ('S' ,NULL , options,N_ ("<string>" ), +OPT_CALLBACK_F ('S' ,"patch-modifies" , options,N_ ("<string>" ),N_ ("look for differences that change the number of occurrences of the specified string" ),0 , diff_opt_pickaxe_string), -OPT_CALLBACK_F ('G' ,NULL , options,N_ ("<regex>" ), +OPT_CALLBACK_F ('G' ,"patch-grep" , options,N_ ("<regex>" ),N_ ("look for differences where a patch contains the specified regex" ),0 , diff_opt_pickaxe_regex), OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts,
diff.h +6 -2
@@ -606,8 +606,12 @@ void diffcore_fix_diff_index(void);" try unchanged files as candidate for copy detection.\n" \" -l<n> limit rename attempts up to <n> paths.\n" \" -O<file> reorder diffs according to the <file>.\n" \ -" -G<regex> find differences where patch contains the specified regex.\n" \ -" -S<string> find filepair who differ in the number of occurrences of string.\n" \ +" -G<regex>\n" \ +" --patch-grep=<regex>\n" \ +" find differences where patch contains the regex.\n" \ +" -S<string>\n" \ +" --patch-modifies=<string>\n" \ +" find filepair who differ in the number of occurrences of string.\n" \" --pickaxe-grep\n" \" treat <string> as a regex in the -S argument.\n" \" --pickaxe-all\n" \
t/t4209-log-pickaxe.sh +42 -0
96 lines not on this page · raw message
Signature · 1 line
2.45.2
Re: [PATCH v5 06/10] diff: --patch-{grep,modifies} arg names for -G and -S
Quoted 11 lines · Illia Bobyr
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]>---
This step looks mostly good, but the option descriptions for existing "-S" and "-G" have been touched by clean-up changes earlier, so they cannot be separated out.
We can treat [01-05/10] as a separate 5-patch "preliminary clean-up" series and discard this and later steps until the earlier half lands.
Unlike other earlier steps, this one has a decent title and it has your sign-off, both of which are good. And of course it is very much on topic.
PATCH v5 7/10 completion: Support --patch-{grep,modifies}
In reply to Illia Bobyr--- contrib/completion/git-completion.bash | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
contrib/completion/git-completion.bash +10 -1
@@ -1900,6 +1900,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary --output= --output-indicator-context= --output-indicator-new= --output-indicator-old= --ws-error-highlight= + --patch-grep= --patch-modifies= --pickaxe-all --pickaxe-regex --patch-with-raw "
@@ -2216,7 +2217,7 @@ __git_complete_log_opts () __git_complete_symbol --cur="${cur#:}" --sfx=":" return ;; - -G,*|-S,*) + -G,*|--patch-grep,*|-S,*|--patch-modifies,*) __git_complete_symbol return ;;
@@ -2239,6 +2240,14 @@ __git_complete_log_opts () __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" return ;; + --patch-grep=*) + __git_complete_symbol --pfx="--patch-grep=" --cur="${cur#--patch-grep=}" + return + ;; + --patch-modifies=*) + __git_complete_symbol --pfx="--patch-modifies=" --cur="${cur#--patch-modifies=}" + return + ;; --submodule=*) __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" return
Signature · 1 line
2.45.2
Re: [PATCH v5 07/10] completion: Support --patch-{grep,modifies}
Quoted 1 line · Illia Bobyr
Subject: Re: [PATCH v5 07/10] completion: Support --patch-{grep,modifies}
"Support" -> "support".
Quoted 3 lines
--- contrib/completion/git-completion.bash | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Missing sign-off.
Other than that, this is a great material to be part of the main topic to add the longhands to these two options.
Thanks.
Quoted 36 lines
contrib/completion/git-completion.bash +10
-1@@ -1900,6 +1900,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary --output= --output-indicator-context= --output-indicator-new= --output-indicator-old= --ws-error-highlight= + --patch-grep= --patch-modifies= --pickaxe-all --pickaxe-regex --patch-with-raw "@@ -2216,7 +2217,7 @@ __git_complete_log_opts () __git_complete_symbol --cur="${cur#:}" --sfx=":" return ;; - -G,*|-S,*) + -G,*|--patch-grep,*|-S,*|--patch-modifies,*) __git_complete_symbol return ;;@@ -2239,6 +2240,14 @@ __git_complete_log_opts () __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" return ;; + --patch-grep=*) + __git_complete_symbol --pfx="--patch-grep=" --cur="${cur#--patch-grep=}" + return + ;; + --patch-modifies=*) + __git_complete_symbol --pfx="--patch-modifies=" --cur="${cur#--patch-modifies=}" + return + ;; --submodule=*) __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" return
PATCH v5 8/10 diff: test: Use --patch-{grep,modifies} over -G/-S
In reply to Illia BobyrLong argument names are easier to read, compared to short ones. So while short arguments are great when you want to type a command quickly, tests are more readable if we use long argument names.
There are still test that verify that both short and long arguments work interchangeably when parsing the arguments.
Tests where the focus is not on the argument names are updated to use long argument names.
--- t/t4062-diff-pickaxe.sh | 8 +++--- t/t4209-log-pickaxe.sh | 62 ++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 35 deletions(-)
t/t4062-diff-pickaxe.sh +4 -4
@@ -16,13 +16,13 @@ test_expect_success setup ' ' # OpenBSD only supports up to 255 repetitions, so repeat twice for 64*64=4096. -test_expect_success '-G matches' ' - git diff --name-only -G "^(0{64}){64}$" HEAD^ >out && +test_expect_success '--patch-grep matches' ' + git diff --name-only --patch-grep "^(0{64}){64}$" HEAD^ >out && test 4096-zeroes.txt = "$(cat out)" ' -test_expect_success '-S --pickaxe-regex' ' - git diff --name-only -S0 --pickaxe-regex HEAD^ >out && +test_expect_success '--patch-modifies --pickaxe-regex' ' + git diff --name-only --patch-modifies 0 --pickaxe-regex HEAD^ >out && test 4096-zeroes.txt = "$(cat out)" '
t/t4209-log-pickaxe.sh +31 -31
139 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v5 9/10 diff: --pickaxe-{all,regex} help: Add --patch-{grep,modifies}
In reply to Illia BobyrFor less experienced users --patch-{grep,modifies} should be easier to understand than just -S or -G. By mentioning the long argument names in the help messages we save those users from having to search the list of options for an explanation of what -S or -G stand for.
--- diff.c | 4 ++-- diff.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
diff.c +2 -2
@@ -5871,10 +5871,10 @@ struct option *add_diff_options(const struct option *opts, N_("look for differences where a patch contains the specified regex"), 0, diff_opt_pickaxe_regex),OPT_BIT_F (0 ,"pickaxe-all" , &options->pickaxe_opts, -N_ ("show all changes in the changeset with -S or -G" ), +N_ ("show all changes in the changeset with -S/--patch-modifies or -G/--patch-grep" ),DIFF_PICKAXE_ALL ,PARSE_OPT_NONEG ),OPT_BIT_F (0 ,"pickaxe-regex" , &options->pickaxe_opts, -N_ ("treat <string> in -S as extended POSIX regular expression" ), +N_ ("treat <string> in -S/--patch-modifies as extended POSIX regular expression" ),DIFF_PICKAXE_REGEX ,PARSE_OPT_NONEG ),OPT_FILENAME ('O' ,NULL , &options->orderfile, N_("control the order in which files appear in the output")),
diff.h +2 -2
@@ -613,9 +613,9 @@ void diffcore_fix_diff_index(void);" --patch-modifies=<string>\n" \" find filepair who differ in the number of occurrences of string.\n" \" --pickaxe-grep\n" \ -" treat <string> as a regex in the -S argument.\n" \ +" treat <string> as a regex in the -S/--patch-modifies argument.\n" \" --pickaxe-all\n" \ -" show all files diff when -G or -S is used and hit is found.\n" \ +" show all files diff for -G/--patch-grep and -S/--patch-modifies.\n" \" -a --text treat all files as text.\n" int diff_queue_is_empty(struct diff_options *o);
Signature · 1 line
2.45.2
PATCH v5 10/10 diff: docs: Use --patch-{grep,modifies} over -G/-S
In reply to Illia BobyrLong argument names are easier to read, compared to short ones. So while short arguments are great when you want to type a command quickly, the documentation readability is improved if we use long argument names.
Note for reviewers: All changes are just a replacement of -G with --patch-grep and -S with --patch-modifies. But as the text was reformatted to fit the same width in a few places it might look like there are more changes, if the diff is only line-wise and not word-wise.
The only an exception are changes in gitdiffcore.adoc, where I did rephrase a sentence. I've moved introduction of the short versions of the --patch-{grep,modifies} into a subsequent paragraph. The reason is that I wanted to keep a note on the -G mnemonic, and it was awkward if I would repeat the short definition twice over a span of two paragraphs.
--- Documentation/diff-options.txt | 34 ++++++++++----------- Documentation/git-blame.txt | 2 +- Documentation/gitdiffcore.txt | 55 +++++++++++++++++----------------- 3 files changed, 46 insertions(+), 45 deletions(-)
Documentation/diff-options.txt +17 -17
@@ -658,8 +658,8 @@ renamed entries cannot appear if detection for those types is disabled. 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. +block in the preimage back into `--patch-modifies`, and keep going until +you get the very first version of the block. + Binary files are searched as well.
@@ -668,9 +668,9 @@ Binary files are searched as well. 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: +To illustrate the difference between `--patch-modifies=<regex> +--pickaxe-regex` and `--patch-grep=<regex>`, consider a commit with the +following diff in the same file: + ---- + return frotz(nitfol, two->ptr, 1, 0);
@@ -678,9 +678,9 @@ file: - hit = frotz(nitfol, mf2.ptr, 1, 0); ---- + -While `git log -G"frotz\(nitfol"` will show this commit, `git log --S"frotz\(nitfol" --pickaxe-regex` will not (because the number of -occurrences of that string did not change). +While `git log --patch-grep="frotz\(nitfol"` will show this commit, `git +log --patch-modifies="frotz\(nitfol" --pickaxe-regex` will not (because the +number of occurrences of that string did not change). + Unless `--text` is supplied patches of binary files without a textconv filter will be ignored.
@@ -689,22 +689,22 @@ See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more information. `--find-object=<object-id>`:: - Look for differences that change the number of occurrences of - the specified object. Similar to `-S`, just the argument is different - in that it doesn't search for a specific string but for a specific - object id. + Look for differences that change the number of occurrences of the + specified object. Similar to `--patch-modifies`, just the argument + is different in that it doesn't search for a specific string but + for a specific object id. + The object can be a blob or a submodule commit. It implies the `-t` option in `git-log` to also find trees. `--pickaxe-all`:: - When `-S` or `-G` finds a change, show all the changes in that - changeset, not just the files that contain the change - in _<string>_. + When `--patch-modifies` or `--patch-grep` finds a change, show all + the changes in that changeset, not just the files that contain the + change in _<string>_. `--pickaxe-regex`:: - Treat the _<string>_ given to `-S` as an extended POSIX regular - expression to match. + Treat the _<string>_ given to `--patch-modifies` as an extended + POSIX regular expression to match. endif::git-format-patch[]
Documentation/git-blame.txt +1 -1
@@ -41,7 +41,7 @@ a text string in the diff. A small example of the pickaxe interface that searches for `blame_usage`: ----------------------------------------------------------------------------- -$ git log --pretty=oneline -S'blame_usage' +$ git log --pretty=oneline --patch-modifies='blame_usage' 5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file> ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output -----------------------------------------------------------------------------
Documentation/gitdiffcore.txt +28 -27
61 lines not on this page · raw message
Signature · 1 line
2.45.2