This is the 3rd attempt to add PCRE support to git-grep.
Changes from v2:
* Replaced NO_LIBPCRE with USE_LIBPCRE. This makes libpcre support
optional. I also considered WITH_LIBPCRE but I see most #defines start
with USE_.
* Renamed 'pcre_extra *extra' with 'pcre_extra *pcre_extra_info'. Now
this variable is more descriptive.
* Reworded description of USE_LIBPCRE in Makefile and configure.ac
* I _didn't_ change the die() message to contain only "Perl-compatible
regexes not supported", but left "cannot use Perl-compatible regexes
when not compiled with USE_LIBPCRE". In my opinion this is more
informative to the user. However, it's OK for me to change that if more
people prefer shorter version.
* Removed die() from pcrematch() and free_pcre_regexp(), because die()
is first called from compile_pcre_regexp(). I left die() there and not
moved it to option parsing because I'd like to keep as few '#ifdef
USE_LIBPCRE' as possible.
* Added compile_regexp_failed() which handles both regcomp() and
pcre_compile() failures.
* Added basic testcases. I'm not sure if I should repeat all
git-grep tests with -P enabled, this seems to be officiousness. Beyond
testing -P/--perl-regexp and their interaction with -i and -w, I also
check if `git grep -F -P` and `git grep -E -P` was called, but do not
protect from `git grep -G -P` nor `git grep -E -G -P`. Fixing this
would require changing the way -G -E are parsed (currently they
set/unset REG_EXTENDED bit in opts.regflags). Personally, if I were
fixing this, I'd remove regflags completely from grep_opt and use it
only in functions which call regcomp()/regexec() directly. That would
make code more general. But it's also possible to just convert option
parsing code to properly detect used flags. That said, I don't think the
end result is worth the effort.
I'd like to thank for all comments!
Michał Kiedrowicz (6):
grep: Fix a typo in a comment
grep: Extract compile_regexp_failed() from compile_regexp()
git-grep: Learn PCRE
configure: Check for libpcre
grep: Add basic tests
git-grep: Bail out when -P is used with -F or -E
Documentation/git-grep.txt | 6 ++
Makefile | 15 +++++
builtin/grep.c | 6 ++-
config.mak.in | 1 +
configure.ac | 40 ++++++++++++
contrib/completion/git-completion.bash | 1 +
grep.c | 102 ++++++++++++++++++++++++++++----
grep.h | 9 +++
t/README | 5 ++
t/t7810-grep.sh | 54 +++++++++++++++++
t/test-lib.sh | 1 +
11 files changed, 228 insertions(+), 12 deletions(-)