Long names for `git log -S` and `git log -G`
Hello,
I would like to add long names for the -S and -G options for git log. It seems that most options have long versions, though there are some exceptions.
I was wondering if there could be any objections.
And also, what would be a good name for each.
Both are provided by the diff-pickaxe functionality.-S is already affected by --pickaxe-regex and both -G and -S are affected by --pickaxe-all.
Also,diffcore docs says:
Quoted 1 line
"-G<regular-expression>" (mnemonic: grep)
I was thinking of --pickaxe for -S and --grep for -G.
And it would probably make sense to discuss this before I try submitting a patch.
--pickaxe-grep for -G seems like a reasonable alternative name for -G. Not sure what would be a reasonably short alternative for -S. --pickaxe-occurance-change seems too long, and might not be as clear. --pickaxe-occurance-count-change is just way too long.
Thank you,
Illia Bobyr
Quoted 5 lines · Illia Bobyr
Also,
diffcoredocs says:Quoted 1 line
"-G<regular-expression>" (mnemonic: grep)
I was thinking of
--pickaxefor-Sand--grepfor-G.
In the context of "git diff", calling "-G" "--grep" would be OK, but in the context of "git log", there is "--grep" already, so that won't fly.
Quoted 1 line
--pickaxe-grepfor-Gseems like a reasonable alternative name for-G.
That is probably OK (even though "-G" is not exactly what the pickaxe machinery wants to do; "--grep-in-patch" might be closer to the intent).
Quoted 3 lines
Not sure what would be a reasonably short alternative for
-S.--pickaxe-occurance-changeseems too long, and might not be as clear.--pickaxe-occurance-count-changeis just way too long.
Giving a tool a meaningful name is an excellent idea. If the meaningful name guides users to the right way to use the tool, it would be ideal. Which means that to name it right, you'd need to know what it exactly is for.
The -S feature was written to become one of the building blocks of Linus's "clearly superior algorithm", described in [1]. Linus talks about "where did this _line_ come from?", but the algorithm is more generally about a block of code. The expected use case is for -S to be fed sufficiently unique block of text so that we can efficiently detect the transition of occurence count from 1 (because wee start from sufficiently unique block of code) down to 0 (which is the boundary in history where the block of code was first introduced in its current form). It detects any occurence count change, but its primary focus is to find a transition from 1 to 0 (when going backwards in history). Its spirit is more about "finding where it appeared in its current shape".
[Footnote]
Quoted 6 lines · Junio C Hamano
Quoted 2 lines
--pickaxe-grepfor-Gseems like a reasonable alternative name for-G.That is probably OK (even though "-G" is not exactly what the pickaxe machinery wants to do; "--grep-in-patch" might be closer to the intent).
FWIW, I like --grep-in-patch. Saying just "--pickaxe-grep" does not highlight that it is about looking in the patch. I.e., it is not clear from the name that is different from "-Sfoo --pickaxe-regex".
Quoted 4 lines
The -S feature was written to become one of the building blocks of Linus's "clearly superior algorithm", described in [1]. Linus talks about "where did this _line_ come from?", but the algorithm is more generally about a block of code. The expected use case is for -S to
Quoted 8 lines
be fed sufficiently unique block of text so that we can efficiently detect the transition of occurence count from 1 (because wee start from sufficiently unique block of code) down to 0 (which is the boundary in history where the block of code was first introduced in its current form). It detects any occurence count change, but its primary focus is to find a transition from 1 to 0 (when going backwards in history). Its spirit is more about "finding where it appeared in its current shape".
Heh. I do not disagree that was the original focus, but I find that I use "-S" most frequently to find mentions of a particular function or other token across the code base. E.g., understanding the historical uses of a function, or why it has no callers anymore, and so on. So I am often looking for many appearances or disappearances (though of course they may or may not happen in a single file).
-Peff
Quoted 4 lines · Junio C Hamano
Quoted 1 line
--pickaxe-grepfor-Gseems like a reasonable alternative name for-G.That is probably OK (even though "-G" is not exactly what the pickaxe machinery wants to do; "--grep-in-patch" might be closer to the intent).
Imagining, that I am starting from scratch for this functionality, I think I would also consider "patch". Though, as we have 4 related argument names, I wonder if using it as a prefix would create a more consistent UX.
Something like:
"--patch-grep" for "-G"
"--patch-modifies" for "-S" "--patch-search-show-all"/"--patch-show-all" for "--pickaxe-all" "--patch-search-regex"/"--patch-regex" for "--pickaxe-regex"
I'm not too sure about the later two, and also they already have long names. But it seems quite easy to understand what this command would do:
git log --patch-grep sometext ...
Or this
git log --patch-modifies function_call --patch-search-regex ...
Quoted 7 lines
Quoted 3 lines
Not sure what would be a reasonably short alternative for
-S.--pickaxe-occurance-changeseems too long, and might not be as clear.--pickaxe-occurance-count-changeis just way too long.Giving a tool a meaningful name is an excellent idea. If the meaningful name guides users to the right way to use the tool, it would be ideal. Which means that to name it right, you'd need to know what it exactly is for.
Glad we are on the same page here :)
I would really appreciate yours and Jeff input.
I wrote a simple patch to see how much work is it to add long names [1]. But I would change it based on whatever names are agreed upon.
[1]: https://lore.kernel.org/git/[email protected]/
Quoted 14 lines
The -S feature was written to become one of the building blocks of Linus's "clearly superior algorithm", described in [1]. Linus talks about "where did this _line_ come from?", but the algorithm is more generally about a block of code. The expected use case is for -S to be fed sufficiently unique block of text so that we can efficiently detect the transition of occurence count from 1 (because wee start from sufficiently unique block of code) down to 0 (which is the boundary in history where the block of code was first introduced in its current form). It detects any occurence count change, but its primary focus is to find a transition from 1 to 0 (when going backwards in history). Its spirit is more about "finding where it appeared in its current shape".
Quoted 3 lines
[Footnote]
This is pretty interesting. Thank you for pointing it out. I guess, it means that the "counting" in the porposed long name of "-S" arguments is more of an implementation detail than the actually intended functionality. Do you think there is a word that better reflects the intent here? "--patch-modifies" is probably also not really hitting it 100%.
Quoted 8 lines · Jeff King
Quoted 4 lines · Junio C Hamano
Quoted 1 line
--pickaxe-grepfor-Gseems like a reasonable alternative name for-G.That is probably OK (even though "-G" is not exactly what the pickaxe machinery wants to do; "--grep-in-patch" might be closer to the intent).
FWIW, I like --grep-in-patch. Saying just "--pickaxe-grep" does not highlight that it is about looking in the patch. I.e., it is not clear from the name that is different from "-Sfoo --pickaxe-regex".
I agree. Do you think "--patch-grep" is a better name? Or do you think that the grep and the occurrence counting functionality should not share a common prefix, as they are somewhat different in nature?
"git log" docs talk about both "-S" and "-G" as if they are pretty close. There is a note in "git diffcore" doc, "diff-pickaxe" section that says that grep is actually quite different. I wonder if this is important for the users to think about. I often use "-G" followed by "-S" or the other way around, just to see which view is better for my particular problem.
Quoted 5 lines · Illia Bobyr
Quoted 4 lines · Junio C Hamano
Quoted 1 line
--pickaxe-grepfor-Gseems like a reasonable alternative name for-G.That is probably OK (even though "-G" is not exactly what the pickaxe machinery wants to do; "--grep-in-patch" might be closer to the intent).
Quoted 8 lines
Imagining, that I am starting from scratch for this functionality, I think I would also consider "patch". Though, as we have 4 related argument names, I wonder if using it as a prefix would create a more consistent UX.
Something like:
"--patch-grep" for "-G"
"--patch-modifies" for "-S"
Ahh, "modifies" is a great verb. It sounds quite logical, but "-S" does not have to genereate a patch internally for it to work, so "--patch-modifies" is a bit of white lie.
Quoted 2 lines
"--patch-search-show-all"/"--patch-show-all" for "--pickaxe-all" "--patch-search-regex"/"--patch-regex" for "--pickaxe-regex"
These already have their own established long names, so it is outside the scope of this topic, and I doubt it is worth giving these additional aliases (as you seem to agree).
v2 cover Long names for `git log -S` and `git log -G`
Sorry, I dropped the ball on this.
I still think it would be good to get it done.
Quoted 9 lines · Junio C Hamano
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
--pickaxe-grepfor-Gseems like a reasonable alternative name for-G.That is probably OK (even though "-G" is not exactly what the pickaxe machinery wants to do; "--grep-in-patch" might be closer to the intent).
Imagining, that I am starting from scratch for this functionality, I think I would also consider "patch". Though, as we have 4 related argument names, I wonder if using it as a prefix would create a more consistent UX.
Quoted 8 lines
Quoted 4 lines
Something like:
"--patch-grep" for "-G"
"--patch-modifies" for "-S"Ahh, "modifies" is a great verb. It sounds quite logical, but "-S" does not have to generate a patch internally for it to work, so "--patch-modifies" is a bit of white lie.
Used "--patch-modifies" for the second version of the patch.
I think most people (certainly me) think about patches first, when they look at these commands. They are unlikely to realize right away that generating a patch is more expensive than counting the string/regex occurrences in the pre- and post- images. So, if you consider the "it behaves as if" point of view rather than "this is how it works" point of view, it is not even a lie :)
Quoted 6 lines
Quoted 2 lines
"--patch-search-show-all"/"--patch-show-all" for "--pickaxe-all" "--patch-search-regex"/"--patch-regex" for "--pickaxe-regex"
These already have their own established long names, so it is outside the scope of this topic, and I doubt it is worth giving these additional aliases (as you seem to agree).
I do not have a strong feeling on this one. If "-S" and/or "-G" would get names that do not start with a "--pickaxe" it might be a bit confusing that the flags that affect their behavior do have the "--pickaxe" prefix. If this is a valid concern, I could probably create a separate patch to add alternative names.
---
I've updated the patch with the following names:
"--patch-grep" for "-G"
"--patch-modifies" for "-S"
Quoted 3 lines · Jeff King
FWIW, I like --grep-in-patch. Saying just "--pickaxe-grep" does not highlight that it is about looking in the patch. I.e., it is not clear from the name that is different from "-Sfoo --pickaxe-regex".
Is "--patch-grep" a good alternative? I think, using the same prefix for a functionality that looks quite similar from the user standpoint ("-G" and "-S") seems nice. Using "--grep-in-patch" for "-G", "--patch-modifies" for "-S" and "--pickaxe-regex"/"--pickaxe-all" all at the same time seems less consistent, but I can change it if you insist.
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 +++- gitk-git/gitk | 10 +++- t/t4062-diff-pickaxe.sh | 8 +-- t/t4209-log-pickaxe.sh | 106 +++++++++++++++++++++++---------- 8 files changed, 151 insertions(+), 88 deletions(-)
Signature · 1 line
2.45.2
PATCH v2 1/1 diff: --patch{-modifies,grep} arg names for -S and -G
In reply to Junio C HamanoMost 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 +++- gitk-git/gitk | 10 +++- t/t4062-diff-pickaxe.sh | 8 +-- t/t4209-log-pickaxe.sh | 106 +++++++++++++++++++++++---------- 8 files changed, 151 insertions(+), 88 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);
gitk-git/gitk +9 -1
@@ -228,7 +228,15 @@ proc parseviewargs {n arglist} { "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" - "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" - "--remove-empty" - "--first-parent" - "--cherry-pick" - - "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" - + "-S*" - "--patch-modifies=*" - + "--patch-modifies" { + set nextisval 1 + } + "-G*" - "--patch-grep=*" - + "--patch-grep" { + set nextisval 1 + } + "--pickaxe-all" - "--pickaxe-regex" - "--simplify-by-decoration" { # These mean that we get a subset of the commits set filtered 1
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 v2 1/1] diff: --patch{-modifies,grep} arg names for -S and -G
Am 05.02.25 um 03:24 schrieb Illia Bobyr:
gitk-git/gitk
Quoted 4 lines
gitk-git/gitk +0
-0
Please exclude this part related to gitk from this submission and send a follow-up patch with only this part. The subject line should then start with "gitk:".
-- Hannes