Skip to content

Commit b422d99

Browse files
committed
Merge branch 'jc/grep-commandline-vs-configuration'
"git -c grep.patternType=extended log --basic-regexp" misbehaved because the internal API to access the grep machinery was not designed well. * jc/grep-commandline-vs-configuration: grep: further simplify setting the pattern type
2 parents 1e9a485 + 8465541 commit b422d99

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

grep.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)
163163
color_set(opt->color_sep, def->color_sep);
164164
}
165165

166-
void grep_commit_pattern_type(enum grep_pattern_type pattern_type, struct grep_opt *opt)
167-
{
168-
if (pattern_type != GREP_PATTERN_TYPE_UNSPECIFIED)
169-
grep_set_pattern_type_option(pattern_type, opt);
170-
else if (opt->pattern_type_option != GREP_PATTERN_TYPE_UNSPECIFIED)
171-
grep_set_pattern_type_option(opt->pattern_type_option, opt);
172-
else if (opt->extended_regexp_option)
173-
grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE, opt);
174-
}
175-
176-
void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, struct grep_opt *opt)
166+
static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, struct grep_opt *opt)
177167
{
178168
switch (pattern_type) {
179169
case GREP_PATTERN_TYPE_UNSPECIFIED:
@@ -205,6 +195,16 @@ void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, struct gr
205195
}
206196
}
207197

198+
void grep_commit_pattern_type(enum grep_pattern_type pattern_type, struct grep_opt *opt)
199+
{
200+
if (pattern_type != GREP_PATTERN_TYPE_UNSPECIFIED)
201+
grep_set_pattern_type_option(pattern_type, opt);
202+
else if (opt->pattern_type_option != GREP_PATTERN_TYPE_UNSPECIFIED)
203+
grep_set_pattern_type_option(opt->pattern_type_option, opt);
204+
else if (opt->extended_regexp_option)
205+
grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE, opt);
206+
}
207+
208208
static struct grep_pat *create_grep_pat(const char *pat, size_t patlen,
209209
const char *origin, int no,
210210
enum grep_pat_token t,

grep.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ struct grep_opt {
145145
extern void init_grep_defaults(void);
146146
extern int grep_config(const char *var, const char *value, void *);
147147
extern void grep_init(struct grep_opt *, const char *prefix);
148-
void grep_set_pattern_type_option(enum grep_pattern_type, struct grep_opt *opt);
149148
void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt);
150149

151150
extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);

revision.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,16 +1973,16 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19731973
} else if (!strcmp(arg, "--grep-debug")) {
19741974
revs->grep_filter.debug = 1;
19751975
} else if (!strcmp(arg, "--basic-regexp")) {
1976-
grep_set_pattern_type_option(GREP_PATTERN_TYPE_BRE, &revs->grep_filter);
1976+
revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_BRE;
19771977
} else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
1978-
grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE, &revs->grep_filter);
1978+
revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_ERE;
19791979
} else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
19801980
revs->grep_filter.regflags |= REG_ICASE;
19811981
DIFF_OPT_SET(&revs->diffopt, PICKAXE_IGNORE_CASE);
19821982
} else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
1983-
grep_set_pattern_type_option(GREP_PATTERN_TYPE_FIXED, &revs->grep_filter);
1983+
revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED;
19841984
} else if (!strcmp(arg, "--perl-regexp")) {
1985-
grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
1985+
revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;
19861986
} else if (!strcmp(arg, "--all-match")) {
19871987
revs->grep_filter.all_match = 1;
19881988
} else if (!strcmp(arg, "--invert-grep")) {

t/t4202-log.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@ test_expect_success 'log -F -E --grep=<ere> uses ere' '
255255
test_cmp expect actual
256256
'
257257

258+
test_expect_success 'log with grep.patternType configuration' '
259+
>expect &&
260+
git -c grep.patterntype=fixed \
261+
log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
262+
test_cmp expect actual
263+
'
264+
265+
test_expect_success 'log with grep.patternType configuration and command line' '
266+
echo second >expect &&
267+
git -c grep.patterntype=fixed \
268+
log -1 --pretty=tformat:%s --basic-regexp --grep=s.c.nd >actual &&
269+
test_cmp expect actual
270+
'
271+
258272
cat > expect <<EOF
259273
* Second
260274
* sixth

0 commit comments

Comments
 (0)