]> git.ipfire.org Git - thirdparty/git.git/commit
grep: make the behavior for NUL-byte in patterns sane
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 1 Jul 2019 21:20:57 +0000 (23:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Jul 2019 21:33:14 +0000 (14:33 -0700)
commit25754125cef278c7e9492fbd6dc4a28319b01f18
tree2c2c2967cc00ac8aeaac6472aaf7ff3c927860ec
parentd316af059d67273f381048cdf538d2e0667b6485
grep: make the behavior for NUL-byte in patterns sane

The behavior of "grep" when patterns contained a NUL-byte has always
been haphazard, and has served the vagaries of the implementation more
than anything else. A pattern containing a NUL-byte can only be
provided via "-f <file>". Since pickaxe (log search) has no such flag
the NUL-byte in patterns has only ever been supported by "grep" (and
not "log --grep").

Since 9eceddeec6 ("Use kwset in grep", 2011-08-21) patterns containing
"\0" were considered fixed. In 966be95549 ("grep: add tests to fix
blind spots with \0 patterns", 2017-05-20) I added tests for this
behavior.

Change the behavior to do the obvious thing, i.e. don't silently
discard a regex pattern and make it implicitly fixed just because they
contain a NUL-byte. Instead die if the backend in question can't
handle them, e.g. --basic-regexp is combined with such a pattern.

This is desired because from a user's point of view it's the obvious
thing to do. Whether we support BRE/ERE/Perl syntax is different from
whether our implementation is limited by C-strings. These patterns are
obscure enough that I think this behavior change is OK, especially
since we never documented the old behavior.

Doing this also makes it easier to replace the kwset backend with
something else, since we'll no longer strictly need it for anything we
can't easily use another fixed-string backend for.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-grep.txt
grep.c
t/t7816-grep-binary-pattern.sh