git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 21/29] grep: factor test for \0 in grep patterns into a function

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 15, 2017, 18:07 UTC
Message-ID
<CACBZZX7DbZh0jYG5SAFvFiOHvowyG=_bdbPbQj7Cr+zw-jOXJg@mail.gmail.com>
In-Reply-To
<xmqqo9uuvdra.fsf@gitster.mtv.corp.google.com>
On Mon, May 15, 2017 at 8:24 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> Factor the test for \0 in grep patterns into a function. Since commit
>> 9eceddeec6 ("Use kwset in grep", 2011-08-21) any pattern containing a
>> \0 is considered fixed as regcomp() can't handle it.
>>
>> This limitation was never documented, and other some regular
>> expression engines are capable of compiling a pattern containing a
>> \0. Factoring this out makes a subsequent change which does that
>> smaller.
>
> The latter half of the first sentence of this paragraph does not
> parse well, around "and other some".  "never documented" makes
> readers expect "... so let's document it", but I think you are
> driving in a different direction, something like...
I'll try to reword it.
Show 13 quoted lines
>         Since some other regular expression engines are capable of a
>         pattern to match a string with NUL in it, it would be nice
>         if we can use such an engine and match against NUL; as this
>         "patterns with NUL always use --fixed match" is not documented,
>         let's hope that nobody depend on that current behaviour.
>         This step does not yet change the behaviour yet, but it
>         makes it easier to do so in later steps.
>
> perhaps?  I tend to agree that it is OK to break users who depended
> on that "patterns with NULL match with --fixed" (partly because it
> is so unintuitive and not useful behaviour, and partly because it is
> easy for them to explicitly say -F), but let's make sure we clearly
> say that we will be knowingly breaking them.

I think there's a few different things going on here, which I'll address accordingly.

 * Yes, if someone is relying on the undocumented behavior of a \0
pattern implying -F if and when I change that their stuff will break.
I'm going to actually just drop this whole discussion from this
commit, we can have an explanation for that when and if I actually
change it in a later series.
* I'm making things more confusing by saying "engines" here, but it's
important to note that git has never in its docs promised to use the C
library implementation of POSIX regexes, it's just advertised that it
uses POSIX regular *expressions*, which are a different thing.
Implementation != syntax.

E.g. GNU grep uses POSIX regex syntax, but its engine does not have the same limitation as ours:

    $ (command cd /tmp && printf "æ\0ð\n" >a && printf "æ\n" >> a;
printf "æ\0[öð]" >f; grep -a -f f a; echo $?)
    æð
    0

I went down this particular rabbit hole because I was genuinely surprised that this didn't work with git-grep, until I realized that of course the implementation detail of using C strings for this under the hood was bleeding through.

Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 31 of 42 in “Easy to review grep & pre-PCRE changes”
  1. 00/29 Easy to review grep & pre-PCRE changesÆvar Arnfjörð Bjarmason, May 13, 2017
  2. 01/29 Makefile & configure: reword inaccurate comment about PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  3. 02/29 grep & rev-list doc: stop promising libpcre for --perl-regexpÆvar Arnfjörð Bjarmason, May 13, 2017
  4. 04/29 log: add exhaustive tests for pattern style options & configÆvar Arnfjörð Bjarmason, May 13, 2017
  5. Junio C HamanoMay 15, 2017
  6. Ævar Arnfjörð BjarmasonMay 15, 2017
  7. Junio C HamanoMay 16, 2017
  8. 05/29 grep: add a test asserting that --perl-regexp dies when !PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  9. 03/29 test-lib: rename the LIBPCRE prerequisite to PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  10. 06/29 grep: add a test for backreferences in PCRE patternsÆvar Arnfjörð Bjarmason, May 13, 2017
  11. 07/29 grep: change non-ASCII -i test to stop using --debugÆvar Arnfjörð Bjarmason, May 13, 2017
  12. 08/29 grep: add tests for --threads=N and grep.threadsÆvar Arnfjörð Bjarmason, May 13, 2017
  13. 09/29 grep: amend submodule recursion test for regex engine testingÆvar Arnfjörð Bjarmason, May 13, 2017
  14. 10/29 grep: add tests for grep pattern types being passed to submodulesÆvar Arnfjörð Bjarmason, May 13, 2017
  15. 11/29 grep: add a test helper function for less verbose -f \0 testsÆvar Arnfjörð Bjarmason, May 13, 2017
  16. 12/29 grep: prepare for testing binary regexes containing rx metacharactersÆvar Arnfjörð Bjarmason, May 13, 2017
  17. 13/29 grep: add tests to fix blind spots with \0 patternsÆvar Arnfjörð Bjarmason, May 13, 2017
  18. 14/29 perf: add a GIT_PERF_MAKE_COMMAND for when *_MAKE_OPTS won't doÆvar Arnfjörð Bjarmason, May 13, 2017
  19. 15/29 perf: emit progress output when unpacking & buildingÆvar Arnfjörð Bjarmason, May 13, 2017
  20. 16/29 perf: add a performance comparison test of grep -G, -E and -PÆvar Arnfjörð Bjarmason, May 13, 2017
  21. 18/29 grep: catch a missing enum in switch statementÆvar Arnfjörð Bjarmason, May 13, 2017
  22. Junio C HamanoMay 15, 2017
  23. Ævar Arnfjörð BjarmasonMay 15, 2017
  24. 17/29 perf: add a performance comparison of fixed-string grepÆvar Arnfjörð Bjarmason, May 13, 2017
  25. 20/29 grep: remove redundant `regflags &= ~REG_EXTENDED` assignmentsÆvar Arnfjörð Bjarmason, May 13, 2017
  26. Junio C HamanoMay 15, 2017
  27. Ævar Arnfjörð BjarmasonMay 15, 2017
  28. 19/29 grep: remove redundant regflags assignment under PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  29. 21/29 grep: factor test for \0 in grep patterns into a functionÆvar Arnfjörð Bjarmason, May 13, 2017
  30. Junio C HamanoMay 15, 2017
  31. Ævar Arnfjörð BjarmasonMay 15, 2017
  32. 22/29 grep: change the internal PCRE macro names to be PCRE1Ævar Arnfjörð Bjarmason, May 13, 2017
  33. 23/29 grep: change internal *pcre* variable & function names to be *pcre1*Ævar Arnfjörð Bjarmason, May 13, 2017
  34. 25/29 test-lib: add a PTHREADS prerequisiteÆvar Arnfjörð Bjarmason, May 13, 2017
  35. 26/29 pack-objects & index-pack: add test for --threads warningÆvar Arnfjörð Bjarmason, May 13, 2017
  36. 24/29 grep: move is_fixed() earlier to avoid forward declarationÆvar Arnfjörð Bjarmason, May 13, 2017
  37. 27/29 pack-objects: fix buggy warning about threadsÆvar Arnfjörð Bjarmason, May 13, 2017
  38. Junio C HamanoMay 15, 2017
  39. Ævar Arnfjörð BjarmasonMay 15, 2017
  40. 28/29 grep: given --threads with NO_PTHREADS=YesPlease, warnÆvar Arnfjörð Bjarmason, May 13, 2017
  41. 29/29 grep: assert that threading is enabled when calling grep_{lock,unlock}Ævar Arnfjörð Bjarmason, May 13, 2017
  42. Junio C HamanoMay 15, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.