Add two grep config options
PATCH 1/1 Add two grep config options
grep.extended-regexp: Enabling this boolean option has the same effect as adding "-E" to all "git grep " instantiations. This can be disabled by specifying "--no-extended-regexp" on a particular call.
grep.line-numbers: Enabling this boolean option has the same effect as adding "-n" to all "git grep " instantiations.
--- Documentation/config.txt | 6 ++++++ Documentation/git-grep.txt | 9 +++++++++ builtin/grep.c | 10 ++++++++++ 3 files changed, 25 insertions(+), 0 deletions(-)
Documentation/config.txt +6 -0
@@ -1101,6 +1101,12 @@ All gitcvs variables except for 'gitcvs.usecrlfattr' and is one of "ext" and "pserver") to make them apply only for the given access method. +grep.line-numbers:: + If set to true, enable '-n' option by default. + +grep.extended-regexp:: + If set to true, enable '--extended-regexp' option by default. + gui.commitmsgwidth:: Defines how wide the commit message window is in the linkgit:git-gui[1]. "75" is the default.
Documentation/git-grep.txt +9 -0
@@ -31,6 +31,15 @@ Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. +CONFIGURATION +------------- + +grep.line-numbers:: + If set to true, enable '-n' option by default. + +grep.extended-regexp:: + If set to true, enable '--extended-regexp' option by default. + OPTIONS ------- --cached::
builtin/grep.c +10 -0
@@ -303,6 +303,16 @@ static int grep_config(const char *var, const char *value, void *cb)default :return 0 ; } +if (!strcmp (var,"grep.extended-regexp" )) { + opt->regflags =git_config_bool (var, value); +return 0 ; + } + +if (!strcmp (var,"grep.line-numbers" )) { + opt->linenum =git_config_bool (var, value); +return 0 ; + } +if (!strcmp (var,"color.grep" )) opt->color =git_config_colorbool (var, value,-1 );else if (!strcmp (var,"color.grep.context" ))
Signature · 1 line
1.7.4.1.4.g0ea33
Quoted 8 lines · Joe Ratterman
grep.extended-regexp: Enabling this boolean option has the same effect as adding "-E" to all "git grep " instantiations. This can be disabled by specifying "--no-extended-regexp" on a particular call.
grep.line-numbers: Enabling this boolean option has the same effect as adding "-n" to all "git grep " instantiations.
Signed-off-by Joe Ratterman <[email protected]>
Thanks.
Things to consider:
- Apply this patch on top of "master",run "git shortlog v1.7.4..HEAD", store the output somewhere, and imagine reading that 2 months from now. Does a single line in the output about this patch sufficiently tell you what it was about?
- Configuration variables are spelled without hyphens between words (you can see "gui.commitmsgwidth" in the context of the patch you sent and notice that it is not "gui.commit-msg-width").
- This will break scripts people have written, knowing that they can rely on "grep" they wrote without giving "-E" from their command line will use BRE, and force them to update the script with --no-extended-regexp for no good reason. Worse yet, there isn't even --no-line-numbers supported to defeat grep.linenumbers configuration to protect such scripts.
I understand that some people would feel that the convenience would outweigh the risk of script breakage in this particular case, and I am sympathetic to the cause, but I still have to point it out. Is there anything we can do to mitigate the risk somehow?
Junio C Hamano venit, vidit, dixit 26.03.2011 00:25:
Quoted 31 lines
Quoted 8 lines · Joe Ratterman
grep.extended-regexp: Enabling this boolean option has the same effect as adding "-E" to all "git grep " instantiations. This can be disabled by specifying "--no-extended-regexp" on a particular call.
grep.line-numbers: Enabling this boolean option has the same effect as adding "-n" to all "git grep " instantiations.
Signed-off-by Joe Ratterman <[email protected]>Thanks.
Things to consider:
- Apply this patch on top of "master",run "git shortlog v1.7.4..HEAD", store the output somewhere, and imagine reading that 2 months from now. Does a single line in the output about this patch sufficiently tell you what it was about?
- Configuration variables are spelled without hyphens between words (you can see "gui.commitmsgwidth" in the context of the patch you sent and notice that it is not "gui.commit-msg-width").
- This will break scripts people have written, knowing that they can rely on "grep" they wrote without giving "-E" from their command line will use BRE, and force them to update the script with --no-extended-regexp for no good reason. Worse yet, there isn't even --no-line-numbers supported to defeat grep.linenumbers configuration to protect such scripts.
Quoted 4 lines
I understand that some people would feel that the convenience would outweigh the risk of script breakage in this particular case, and I am sympathetic to the cause, but I still have to point it out. Is there anything we can do to mitigate the risk somehow?
This comes up again and again, and I feel that rather than adding config options one by one, we should either allow aliases for standard commands and/or setting default options depending on the mode (ui use vs. scripting use), so to say a companion to "git -c n=v" which allows
git config ui.grep "-E -n"
I.e. just like "git -c n=v <cmd>" sets up pseudo config before running cmd, our wrapper could augment argv from "ui.<cmd>".
We could safeguard scripts from this by
- checking istty and
- checking env for GIT_PLUMBING
and setting the latter in git-sh-setup.sh. After a long migration phase, we could skip the first (fragile) check.
Michael
Quoted 22 lines · Michael J Gruber
Quoted 11 lines
- This will break scripts people have written, knowing that they can rely on "grep" they wrote without giving "-E" from their command line will use BRE, and force them to update the script with --no-extended-regexp for no good reason. Worse yet, there isn't even --no-line-numbers supported to defeat grep.linenumbers configuration to protect such scripts.
I understand that some people would feel that the convenience would outweigh the risk of script breakage in this particular case, and I am sympathetic to the cause, but I still have to point it out. Is there anything we can do to mitigate the risk somehow?
This comes up again and again, and I feel that rather than adding config options one by one, we should either allow aliases for standard commands and/or setting default options depending on the mode (ui use vs. scripting use), so to say a companion to "git -c n=v" which allows
git config ui.grep "-E -n"
I.e. just like "git -c n=v <cmd>" sets up pseudo config before running cmd, our wrapper could augment argv from "ui.<cmd>".
Quoted 7 lines
We could safeguard scripts from this by
- checking istty and
- checking env forGIT_PLUMBINGand setting the latter in
git-sh-setup.sh. After a long migration phase, we could skip the first (fragile) check.
I like the idea of a GIT_PLUMBING variable. It is something that has come up as a solution to similar problems many times in the past, but it never ends up getting implemented, because it never solves the problem at hand. It is something that we would introduce now, and would solve problems several versions down the road, after people adjusted their scripts. So nobody ends up doing it.
And probably we would want something like --no-plumbing to switch back to porcelain mode for a specific command. Because often scripts do a bunch of work, and then want to show the user their output in their favorite format. Something like:
. git-sh-setup ;# or manually GIT_PLUMBING=1 # get list of "interesting" files containing some pattern files=`git grep -le "$1"` # and then show them git --no-plumbing log $files
One shortcoming of such a scheme, though, is that it is an all-or-nothing proposal; a script has no way to say "it's OK to take the user's default for _this_ option, but not for others". For example, in the script above, it would make sense for the grep call to respect the user's choice of "-E". So it is tempting to use --no-plumbing there, too. But we don't necessarily want to respect whatever cruft the user put into ui.grep, because we care what the output looks like (something like "-O" would not be helpful).
So what we really want is to let the script "allow" certain options from the user's preferences. This could be done easily with individual config options, like:
git --allow=grep.extended grep ...
where the config code would respect a variable if GIT_PLUMBING is unset, or if the key is in the allowed list. You could probably also adapt it to something like:
git --allow="-E --foo" grep ...
which would allow "-E" and "--foo" in ui.grep, but nothing else.
Now, obviously my script is a toy (it's not a real script I use). In particular, "-O" would probably be suppressed by the lack of a tty, anyway. But:
1. I used a toy to have something readable. Look at something more complex, like "git pull". It calls "git merge". Should it be respecting "-n" and "--log" from the user's config? Probably. Should it respect "--no-ff" or "-s"? I'm not sure. And there are lots more examples just in the git.git scripts.
2. It's not just about safeguarding versus the current set of grep options. It's about safeguarding the script against any _future_ options that don't exist yet.
3. This might be overengineering a little bit. Most invocations probably do fall into either the "run command to get its output" category (where you want pure plumbing) or the "run command to show things to the user" category (where you will take whatever options the user wants). But because the deployment of whatever scheme is chosen is going to be so annoying (because it will take many versions before we're clear to assume that people are setting GIT_PLUMBING), I would rather over-engineer than find out 2 years into the process that the flexibility we provide is not sufficient and have to start again.
Quoted 4 lines
We could safeguard scripts from this by
- checking istty and
- checking env forGIT_PLUMBING
I'm not sure isatty is a good check. In the example above, grep's output was not going to a tty, but I did want to respect the user's choice of "-E".
-Peff
Jeff King venit, vidit, dixit 28.03.2011 13:54:
Quoted 98 lines · Michael J Gruber
Quoted 23 lines
Quoted 8 lines
- This will break scripts people have written, knowing that they can rely on "grep" they wrote without giving "-E" from their command line will use BRE, and force them to update the script with --no-extended-regexp for no good reason. Worse yet, there isn't even --no-line-numbers supported to defeat grep.linenumbers configuration to protect such scripts.
Quoted 4 lines
I understand that some people would feel that the convenience would outweigh the risk of script breakage in this particular case, and I am sympathetic to the cause, but I still have to point it out. Is there anything we can do to mitigate the risk somehow?
This comes up again and again, and I feel that rather than adding config options one by one, we should either allow aliases for standard commands and/or setting default options depending on the mode (ui use vs. scripting use), so to say a companion to "git -c n=v" which allows
git config ui.grep "-E -n"
I.e. just like "git -c n=v <cmd>" sets up pseudo config before running cmd, our wrapper could augment argv from "ui.<cmd>".
Quoted 7 lines
We could safeguard scripts from this by
- checking istty and
- checking env forGIT_PLUMBINGand setting the latter in
git-sh-setup.sh. After a long migration phase, we could skip the first (fragile) check.I like the idea of a
GIT_PLUMBINGvariable. It is something that has come up as a solution to similar problems many times in the past, but it never ends up getting implemented, because it never solves the problem at hand. It is something that we would introduce now, and would solve problems several versions down the road, after people adjusted their scripts. So nobody ends up doing it.And probably we would want something like --no-plumbing to switch back to porcelain mode for a specific command. Because often scripts do a bunch of work, and then want to show the user their output in their favorite format. Something like:
. git-sh-setup ;# or manually GIT_PLUMBING=1 # get list of "interesting" files containing some pattern files=`git grep -le "$1"` # and then show them git --no-plumbing log $filesOne shortcoming of such a scheme, though, is that it is an all-or-nothing proposal; a script has no way to say "it's OK to take the user's default for _this_ option, but not for others". For example, in the script above, it would make sense for the grep call to respect the user's choice of "-E". So it is tempting to use --no-plumbing there, too. But we don't necessarily want to respect whatever cruft the user put into ui.grep, because we care what the output looks like (something like "-O" would not be helpful).
So what we really want is to let the script "allow" certain options from the user's preferences. This could be done easily with individual config options, like:
git --allow=grep.extended grep ...
where the config code would respect a variable if
GIT_PLUMBINGis unset, or if the key is in the allowed list. You could probably also adapt it to something like:git --allow="-E --foo" grep ...
which would allow "-E" and "--foo" in ui.grep, but nothing else.
Now, obviously my script is a toy (it's not a real script I use). In particular, "-O" would probably be suppressed by the lack of a tty, anyway. But:
1. I used a toy to have something readable. Look at something more complex, like "git pull". It calls "git merge". Should it be respecting "-n" and "--log" from the user's config? Probably. Should it respect "--no-ff" or "-s"? I'm not sure. And there are lots more examples just in the git.git scripts.
2. It's not just about safeguarding versus the current set of grep options. It's about safeguarding the script against any _future_ options that don't exist yet.
3. This might be overengineering a little bit. Most invocations probably do fall into either the "run command to get its output" category (where you want pure plumbing) or the "run command to show things to the user" category (where you will take whatever options the user wants). But because the deployment of whatever scheme is chosen is going to be so annoying (because it will take many versions before we're clear to assume that people are setting
GIT_PLUMBING), I would rather over-engineer than find out 2 years into the process that the flexibility we provide is not sufficient and have to start again.
Quoted 8 lines
Quoted 4 lines
We could safeguard scripts from this by
- checking istty and
- checking env forGIT_PLUMBINGI'm not sure isatty is a good check. In the example above, grep's output was not going to a tty, but I did want to respect the user's choice of "-E".
I'm not saying it's good either, but it is something that a new git (i.e. between the time we introduce ui.* and GIT_PLUMBING/--no-plum and the time we rely on the latter) could do to make use of (and promote) the new ui.* options.
Michael
Quoted 5 lines · Michael J Gruber
Quoted 5 lines
Quoted 4 lines
We could safeguard scripts from this by
- checking istty and
- checking env forGIT_PLUMBING
Quoted 8 lines
Quoted 3 lines
I'm not sure isatty is a good check. In the example above, grep's output was not going to a tty, but I did want to respect the user's choice of "-E".
I'm not saying it's good either, but it is something that a new git (i.e. between the time we introduce ui.* and GIT_PLUMBING/--no-plum and the time we rely on the latter) could do to make use of (and promote) the new ui.* options.
The example I gave was a false negative (we could have used the user's preference but the isatty check said no). Which is OK for a transitional period, because we err on the side of being conservative. But I wonder if there are false positives (i.e., cases where the isatty check says it's OK, but we are breaking a script). Maybe something where the script prepares a BRE to hand to git-grep, but we want to show the user the output in their usual way.
That seems pretty contrived, though. Maybe it is a non-issue.
-Peff
Quoted 2 lines · Jeff King
One shortcoming of such a scheme, though, is that it is an all-or-nothing proposal...
I fully agree with this assessment, and I think that was the primary reason that we rejected --plumbing / GIT_PLUMB (i.e. as too naive to be useful).
Quoted 5 lines
So what we really want is to let the script "allow" certain options from the user's preferences. This could be done easily with individual config options, like:
git --allow=grep.extended grep ...
I think this is probably the right thing to do _if_ we wanted to add such a configuration variable and give a way to let script writers protect themselves.
But would any user go all that trouble, just not to say "-nE" from the command line (or use an alias that was designed not to crash with scripts)?
Quoted 13 lines · Junio C Hamano
Quoted 2 lines · Jeff King
One shortcoming of such a scheme, though, is that it is an all-or-nothing proposal...
I fully agree with this assessment, and I think that was the primary reason that we rejected --plumbing /
GIT_PLUMB(i.e. as too naive to be useful).Quoted 4 lines
So what we really want is to let the script "allow" certain options from the user's preferences. This could be done easily with individual config options, like:
Quoted 5 lines
Quoted 1 line
git --allow=grep.extended grep ...
I think this is probably the right thing to do _if_ we wanted to add such a configuration variable and give a way to let script writers protect themselves.
Note that "git --allow=grep.extended" is not useful without GIT_PLUMBING=1. Otherwise, users at the command line would have to individually allow each config option, which makes them pointless.
Probably you already figured that out, but I wasn't sure from what you wrote.
Quoted 3 lines
But would any user go all that trouble, just not to say "-nE" from the command line (or use an alias that was designed not to crash with scripts)?
I dunno. I generally prefer to use extended regexps when I can, but I don't remember ever having been annoyed that they are not the default with git grep. Perhaps because 99% of my greps are for literal symbol names (whereas in my editor, I am often doing substitutions, and I am continually annoyed at having to use backslash to make my parentheses magical).
-Peff
Quoted 6 lines · Jeff King
I dunno. I generally prefer to use extended regexps when I can, but I don't remember ever having been annoyed that they are not the default with git grep. Perhaps because 99% of my greps are for literal symbol names (whereas in my editor, I am often doing substitutions, and I am continually annoyed at having to use backslash to make my parentheses magical).
I do not think I've ever been annoyed that "GNU grep" needs -E to enable extended regexps, either.
As much as I hate GREP_OPTIONS and GREP_COLORS environment variables that force us to write a "sane_grep" wrapper to run "grep" while disabling these, I have to admit that the approach to use these environment variables is far easier to disable than having a set of configuration variables that cover many commands we have, which is harder to disable selectively.
Having discussed all this, with an addition of --[no-]line-number synonym to the existing -n option, I don't think this particular incompatibility is a huge issue. At the worst, we might want to wait until a version bump like 1.8.0, but I personally think a prominent notice in the release notes in 1.7.5 would be sufficient.
Quoted 4 lines · Junio C Hamano
But would any user go all that trouble, just not to say "-nE" from the command line (or use an alias that was designed not to crash with scripts)?
I use the $GREP_OPTIONS environment variable to add -n and -P (pcre) to my grep commands by default. Coming from a strong Perl background, I don't know the *exact* difference between basic and extended, so I do not usually realize I need -E until it gets a little too complicated. I generally forget line numbers until I want to start editing the file, making me run the grep command a second time. For me, it is much easier to have them in the environment/config-file, since I never want to avoid them.
Joe
Quoted 3 lines · Michael J Gruber
We could safeguard scripts from this by
- checking istty and
That should consider running under the pager too.
I had proposed this scheme last year to TopGit as a way to differentiate between ui and plumbing. But as Jeff pointed out, this is probably not enough.
Bert
Quoted 2 lines
- checking env for
GIT_PLUMBING
Quoted 7 lines · Bert Wesarg
Quoted 3 lines · Michael J Gruber
We could safeguard scripts from this by
- checking istty and
Quoted 10 lines
That should consider running under the pager too.
I had proposed this scheme last year to TopGit as a way to differentiate between ui and plumbing. But as Jeff pointed out, this is probably not enough.
Bert
Quoted 2 lines
- checking env for
GIT_PLUMBING
Thanks for looking over this and taking the time to comment. I had not considered the importance of the first line, nor had I noticed the lack of hyphens in the other options--I copied the name of grep.extended-regexp from the --extended-regexp grep option. I can change those things if the general idea is accepted. I like the idea of a single option config key have takes a list of command-line flags, but I'm not 100% sure I know enough about git code internals to implement it. I'll look.
With regard to disabling the line numbering, GNU grep supports both -n and --line-number. Adding the latter option to git grep allows for the long form --no-line-number. Another option would be to use -N for the negative, like -h and -H. GNU grep doesn't support either of those.
Thanks,
Joe Ratterman
Quoted 3 lines · Joe Ratterman
With regard to disabling the line numbering, GNU grep supports both -n and --line-number. Adding the latter option to git grep allows for the long form --no-line-number.
Yes, that is something we would probably want regardless of your patch we are discussing in this thread, if only for helping people who are used to the GNU way.
PATCH 1/1 grep: allow -E and -n to be turned on by default via configuration
In reply to Junio C HamanoFrom: Joe Ratterman <[email protected]>
Add two configration variables grep.extendedRegexp and grep.lineNumbers to allow the user to skip typing -E and -n on the command line, respectively.
Scripts that are meant to be used by random users and/or in random repositories now have use -G and/or --no-line-number options as appropriately to override the settings in the repository or user's ~/.gitconfig settings. Just because the script didn't say "git grep -n" no longer guarantees that the output from the command will not have line numbers.
---
* Having discussed the b/c issue to death, here is an updated version of your patch to be applied on top of your --[no-]line-number patch.
I addressed both the title for shortlog and names of the variables, but two more important fixes are not to overwrite the whole regflags and not to assume that the value of REG_EXTENDED is 01.
I did not add tests, but we do need one perhaps at the end of t7810 to move things forward.
Documentation/config.txt | 6 ++++++ Documentation/git-grep.txt | 10 ++++++++++ builtin/grep.c | 10 ++++++++++ 3 files changed, 26 insertions(+), 0 deletions(-)
Documentation/config.txt +6 -0
@@ -1098,6 +1098,12 @@ All gitcvs variables except for 'gitcvs.usecrlfattr' and is one of "ext" and "pserver") to make them apply only for the given access method. +grep.lineNumbers:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. + gui.commitmsgwidth:: Defines how wide the commit message window is in the linkgit:git-gui[1]. "75" is the default.
Documentation/git-grep.txt +10 -0
@@ -31,6 +31,16 @@ Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. +CONFIGURATION +------------- + +grep.lineNumbers:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. + + OPTIONS ------- --cached::
builtin/grep.c +10 -0
@@ -302,6 +302,16 @@ static int grep_config(const char *var, const char *value, void *cb)default :return 0 ; } +if (!strcmp (var,"grep.extendedregexp" )) { + opt->regflags |=git_config_bool (var, value) ?REG_EXTENDED :0 ; +return 0 ; + } + +if (!strcmp (var,"grep.linenumbers" )) { + opt->linenum =git_config_bool (var, value); +return 0 ; + } +if (!strcmp (var,"color.grep" )) opt->color =git_config_colorbool (var, value,-1 );else if (!strcmp (var,"color.grep.context" ))
Signature · 1 line
1.7.4.2.412.g61e8a
Re: [PATCH] grep: allow -E and -n to be turned on by default via configuration
builtin/grep.c static int grep_config(const char *var, const char *value, void *cb) · line 308
Quoted 4 lines · Junio C Hamano
builtin/grep.c +4
-0+if (!strcmp (var,"grep.extendedregexp" )) { + opt->regflags |=git_config_bool (var, value) ?REG_EXTENDED :0 ; +return 0 ; + }
Heh, I am an idiot. This should be more like
if (git_config_bool(var, value))
opt->regflags |= REG_EXTENDED;
else
opt->regflags &= ~REG_EXTENDED;
return 0;Re: [PATCH] grep: allow -E and -n to be turned on by default via configuration
In reply to Junio C HamanoQuoted 2 lines · Junio C Hamano
I did not add tests, but we do need one perhaps at the end of t7810 to move things forward.
What sort of tests would be appropriate? I cannot find anything that tests -E/--extended-regexp. I copied the first test that used "git grep -n" and changed it to these:
1) git -c grep.linenumber=false grep -n # Expected to have line numbers 2) git -c grep.linenumber=true grep # Expected to have line numbers 3) git -c grep.linenumber=true grep --no-line-number # Expected to
have no line numbers
Joe
PATCH v3 1/1 grep: allow -E and -n to be turned on by default via configuration
Add two configration variables grep.extendedRegexp and grep.lineNumbers to allow the user to skip typing -E and -n on the command line, respectively.
Scripts that are meant to be used by random users and/or in random repositories now have use -G and/or --no-line-number options as appropriately to override the settings in the repository or user's ~/.gitconfig settings. Just because the script didn't say "git grep -n" no longer guarantees that the output from the command will not have line numbers.
---
This adds 3 tests to t7810-grep.sh:
1) git -c grep.linenumber=false grep -n # Expected to have line numbers 2) git -c grep.linenumber=true grep # Expected to have line numbers 3) git -c grep.linenumber=true grep --no-line-number # Expected to
have no line numbers
Documentation/config.txt | 6 ++++++ Documentation/git-grep.txt | 10 ++++++++++ builtin/grep.c | 13 +++++++++++++ t/t7810-grep.sh | 24 +++++++++++++++++++++++- 4 files changed, 52 insertions(+), 1 deletions(-)
Documentation/config.txt +6 -0
@@ -1092,6 +1092,12 @@ All gitcvs variables except for 'gitcvs.usecrlfattr' and is one of "ext" and "pserver") to make them apply only for the given access method. +grep.lineNumber:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. + gui.commitmsgwidth:: Defines how wide the commit message window is in the linkgit:git-gui[1]. "75" is the default.
Documentation/git-grep.txt +10 -0
@@ -31,6 +31,16 @@ Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. +CONFIGURATION +------------- + +grep.lineNumber:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. + + OPTIONS ------- --cached::
builtin/grep.c +13 -0
@@ -302,6 +302,19 @@ static int grep_config(const char *var, const char *value, void *cb)default :return 0 ; } +if (!strcmp (var,"grep.extendedregexp" )) { +if (git_config_bool (var, value)) + opt->regflags |=REG_EXTENDED ; +else + opt->regflags &= ~REG_EXTENDED ; +return 0 ; + } + +if (!strcmp (var,"grep.linenumber" )) { + opt->linenum =git_config_bool (var, value); +return 0 ; + } +if (!strcmp (var,"color.grep" )) opt->color =git_config_colorbool (var, value,-1 );else if (!strcmp (var,"color.grep.context" ))
t/t7810-grep.sh +23 -1
@@ -59,7 +59,29 @@ do echo ${HC}file:4:foo mmap bar_mmap echo ${HC}file:5:foo_mmap bar mmap baz } >expected && - git grep -n -w -e mmap $H >actual && + git -c grep.linenumber=false grep -n -w -e mmap $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep -w $L" ' + { + echo ${HC}file:1:foo mmap bar + echo ${HC}file:3:foo_mmap bar mmap + echo ${HC}file:4:foo mmap bar_mmap + echo ${HC}file:5:foo_mmap bar mmap baz + } >expected && + git -c grep.linenumber=true grep -w -e mmap $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep -w $L" ' + { + echo ${HC}file:foo mmap bar + echo ${HC}file:foo_mmap bar mmap + echo ${HC}file:foo mmap bar_mmap + echo ${HC}file:foo_mmap bar mmap baz + } >expected && + git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual && test_cmp expected actual '
Signature · 1 line
1.7.4.1.4.g0ea33
Re: [PATCH] grep: allow -E and -n to be turned on by default via configuration
In reply to Junio C HamanoDocumentation/config.txt All gitcvs variables except for 'gitcvs.usecrlfattr' and · line 1106
Quoted 6 lines · Junio C Hamano
Documentation/config.txt +6
-0+grep.lineNumbers:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. +
I know my original patch was plural, but I since noticed that the GNU grep --line-number option is singular. I used the same thing in my patch to add that option to git grep. Should this one be singular?
Quoted 7 lines
Documentation/git-grep.txt +7
-0+grep.lineNumbers:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. + +
...
Quoted 7 lines
+ if (!strcmp(var, "grep.extendedregexp")) {
+opt->regflags|=git_config_bool(var, value)?REG_EXTENDED: 0;
+ return 0;
+ }
+
+ if (!strcmp(var, "grep.linenumbers")) {
+opt->linenum=git_config_bool(var, value);
We need to match the case between the docs and the code or use strcasecmp(). Most config options I could find used all lower-case.
Joe
Re: [PATCH] grep: allow -E and -n to be turned on by default via configuration
Quoted 11 lines · Joe Ratterman
Documentation/config.txt All gitcvs variables except for 'gitcvs.usecrlfattr' and · line 1106
Quoted 6 lines · Junio C Hamano
Documentation/config.txt +6
-0+grep.lineNumbers:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. +I know my original patch was plural, but I since noticed that the GNU grep --line-number option is singular. I used the same thing in my patch to add that option to git grep. Should this one be singular?
Good eyes.
We should match what we are trying to mimic, and we need to be internally consistent. So --[no-]line-number should be singular to mimic GNU (which is how your othr patch is done---I don't have to amend what I already queued). And we should match the variable by naming it "grep.lineNumber" to the command line option.
Quoted 5 lines
Quoted 2 lines
+ if (!strcmp(var, "grep.linenumbers")) {
+opt->linenum=git_config_bool(var, value);We need to match the case between the docs and the code or use
strcasecmp().
In git_config() callback functions, the variable name is supposed to be already downcased by the caller, except for the second-level name in three-level names, like "branch.Foo.merge" where the second-level name is case sensitive. Feeding var we got from the caller and lowercased variable name we expect to strcmp() is the right way to write them when you are dealing with configuration variable names.
Some places might unnecessarily and incorrectly use strcasecmp() but if so, we should be fixing them instead. We shouldn't mimic bad code.
In documentation we customary write them in camelCase only for readability.