]> git.ipfire.org Git - thirdparty/git.git/commit - grep.c
grep: remove regflags from the public grep_opt API
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 29 Jun 2017 22:22:21 +0000 (22:22 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 30 Jun 2017 17:06:24 +0000 (10:06 -0700)
commit07a3d4117390841ed6884a9eac836918491df0a9
tree533b2a85560776d713114c41dd693848c41593f6
parentb07ed4e532fa9492a53b7b510c45efd671f468a8
grep: remove regflags from the public grep_opt API

Refactor calls to the grep machinery to always pass opt.ignore_case &
opt.extended_regexp_option instead of setting the equivalent regflags
bits.

The bug fixed when making -i work with -P in commit 9e3cbc59d5 ("log:
make --regexp-ignore-case work with --perl-regexp", 2017-05-20) was
really just plastering over the code smell which this change fixes.

The reason for adding the extensive commentary here is that I
discovered some subtle complexity in implementing this that really
should be called out explicitly to future readers.

Before this change we'd rely on the difference between
`extended_regexp_option` and `regflags` to serve as a membrane between
our preliminary parsing of grep.extendedRegexp and grep.patternType,
and what we decided to do internally.

Now that those two are the same thing, it's necessary to unset
`extended_regexp_option` just before we commit in cases where both of
those config variables are set. See 84befcd0a4 ("grep: add a
grep.patternType configuration setting", 2012-08-03) for the code and
documentation related to that.

The explanation of why the if/else branches in
grep_commit_pattern_type() are ordered the way they are exists in that
commit message, but I think it's worth calling this subtlety out
explicitly with a comment for future readers.

Even though grep_commit_pattern_type() is the only caller of
grep_set_pattern_type_option() it's simpler to reset the
extended_regexp_option flag in the latter, since 2/3 branches in the
former would otherwise need to reset it, this way we can do it in one
place.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
grep.c
grep.h
revision.c