Skip to content

Commit b966427

Browse files
committed
Merge branch 'jr/grep-en-config'
* jr/grep-en-config: grep: allow -E and -n to be turned on by default via configuration
2 parents 6c80cd2 + b22520a commit b966427

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,12 @@ All gitcvs variables except for 'gitcvs.usecrlfattr' and
10981098
is one of "ext" and "pserver") to make them apply only for the given
10991099
access method.
11001100

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+
11011107
gui.commitmsgwidth::
11021108
Defines how wide the commit message window is in the
11031109
linkgit:git-gui[1]. "75" is the default.

Documentation/git-grep.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ Look for specified patterns in the tracked files in the work tree, blobs
3131
registered in the index file, or blobs in given tree objects.
3232

3333

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+
3444
OPTIONS
3545
-------
3646
--cached::

builtin/grep.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,19 @@ static int grep_config(const char *var, const char *value, void *cb)
302302
default: return 0;
303303
}
304304

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+
305318
if (!strcmp(var, "color.grep"))
306319
opt->color = git_config_colorbool(var, value, -1);
307320
else if (!strcmp(var, "color.grep.context"))

t/t7810-grep.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,29 @@ do
5959
echo ${HC}file:4:foo mmap bar_mmap
6060
echo ${HC}file:5:foo_mmap bar mmap baz
6161
} >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 &&
6385
test_cmp expected actual
6486
'
6587

0 commit comments

Comments
 (0)