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. Signed-off-by: Joe Ratterman <jratt0@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Joe Ratterman committed
Mar 30, 2011 at 14:31 UTC
b22520a37c8472751f2c4b3da9b5bc4e5aa5a0a3
4 files changed
+52
-1
Documentation/config.txt
+6
@@ -1098,6 +1098,12 @@ All gitcvs variables except for 'gitcvs.usecrlfattr' and
1098
is one of "ext" and "pserver") to make them apply only for the given
1099
access method.
1100
1101
+grep.lineNumber::
1102
+ If set to true, enable '-n' option by default.
1103
+
1104
+grep.extendedRegexp::
1105
+ If set to true, enable '--extended-regexp' option by default.
1106
+
1107
gui.commitmsgwidth::
1108
Defines how wide the commit message window is in the
1109
linkgit:git-gui[1]. "75" is the default.
Documentation/git-grep.txt
+10
@@ -31,6 +31,16 @@ Look for specified patterns in the tracked files in the work tree, blobs
31
registered in the index file, or blobs in given tree objects.
32
33
34
+CONFIGURATION
35
+-------------
36
+
37
+grep.lineNumber::
38
+ If set to true, enable '-n' option by default.
39
+
40
+grep.extendedRegexp::
41
+ If set to true, enable '--extended-regexp' option by default.
42
+
43
+
44
OPTIONS
45
-------
46
--cached::
builtin/grep.c
+13
@@ -302,6 +302,19 @@ static int grep_config(const char *var, const char *value, void *cb)
302
default: return 0;
303
}
304
305
+ if (!strcmp(var, "grep.extendedregexp")) {
306
+ if (git_config_bool(var, value))
307
+ opt->regflags |= REG_EXTENDED;
308
+ else
309
+ opt->regflags &= ~REG_EXTENDED;
310
+ return 0;
311
+ }
312
+
313
+ if (!strcmp(var, "grep.linenumber")) {
314
+ opt->linenum = git_config_bool(var, value);
315
+ return 0;
316
+ }
317
+
318
if (!strcmp(var, "color.grep"))
319
opt->color = git_config_colorbool(var, value, -1);
320
else if (!strcmp(var, "color.grep.context"))
t/t7810-grep.sh
+23
-1
@@ -59,7 +59,29 @@ do
59
echo ${HC}file:4:foo mmap bar_mmap
60
echo ${HC}file:5:foo_mmap bar mmap baz
61
} >expected &&
62
- git grep -n -w -e mmap $H >actual &&
62
+ git -c grep.linenumber=false grep -n -w -e mmap $H >actual &&
63
+ test_cmp expected actual
64
+ '
65
+
66
+ test_expect_success "grep -w $L" '
67
+ {
68
+ echo ${HC}file:1:foo mmap bar
69
+ echo ${HC}file:3:foo_mmap bar mmap
70
+ echo ${HC}file:4:foo mmap bar_mmap
71
+ echo ${HC}file:5:foo_mmap bar mmap baz
72
+ } >expected &&
73
+ git -c grep.linenumber=true grep -w -e mmap $H >actual &&
74
+ test_cmp expected actual
75
+ '
76
+
77
+ test_expect_success "grep -w $L" '
78
+ {
79
+ echo ${HC}file:foo mmap bar
80
+ echo ${HC}file:foo_mmap bar mmap
81
+ echo ${HC}file:foo mmap bar_mmap
82
+ echo ${HC}file:foo_mmap bar mmap baz
83
+ } >expected &&
84
+ git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual &&
85
test_cmp expected actual
86
'
87