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

Re: [PATCHv2 3/6] t7810-grep: test multiple --author with --all-match

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 13, 2012, 20:47 UTC
Message-ID
<7vmx0t7iq0.fsf@alter.siamese.dyndns.org>
In-Reply-To
<8fd93bb87098298677426735dd354fa4f64abc17.1347544259.git.git@drmicha.warpmail.net>
Michael J Gruber <git@drmicha.warpmail.net> writes:
> --all-match is ignored for author matching on purpose.
>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---

What the added test expects is correct, but I do not think the above description is correct. "all-match" is implicitly turned on when you use header match.

When you say
	git log --grep=Linus --grep=Junio
you will get
    (or
     pattern_body<body>Junio
     pattern_body<body>Linus
    )
but when you say
	git log --author=Linus --author=Junio
you will get
    [all-match]
    (or
     (or
      pattern_head<head 0>Linus
      pattern_head<head 0>Junio
     )
     true
    )

instead. Notice that there is one extra level of "OR" node, so that two OR nodes on the top-level backbone (think of these as cons cells with car and cdr) are "author is either Linus or junio" and "True". Because "all-match" is about rejecting a document as non-matching unless all the OR nodes on the top-level backbone have fired, this allows commit that is authored either by Linus or by Junio to match, and "on purpose" part in your message is correct.

But
	git log --author=Linus --author=Junio --grep=commit
will be parsed to
    [all-match]
    (or
     pattern_body<body>commit
     (or
      (or
       pattern_head<head 0>Linus
       pattern_head<head 0>Junio
      )
      true
     )
    )

to have three OR nodes on the backbone: "the log message must have commit", "authored by either Linus or Junio", and "true". All three must match somewhere in the "git cat-file commit" output for the commit to be considered a match (but obviously they do not have to match on the same line).

So what is giving commits made by Linus, even though it is not authored by Junio, with "--author=Linus --author=Junio" is not the lack of --all-match. In fact, --all-match is implicitly set for other things, so that the last example finds commits that mention "commit" authored by one of these two people. Commits that do mention "commit" but are done by other people are excluded. Commits that do not mention "commit" are excluded even if they were done by Linus or Junio.

	git log --committer=Linus --author=Junio
turns into
    [all-match]
    (or
     pattern_head<head 1>Linus
     (or
      pattern_head<head 0>Junio
      true
     )
    )

which has "committed by Linus", "authored by Junio" on the top-level backbone, so both has to be true for a commit to match.

Adding --grep=commit makes it
    [all-match]
    (or
     pattern_body<body>commit
     (or
      pattern_head<head 1>Linus
      (or
       pattern_head<head 0>Junio
       true
      )
     )
    )

which has "committed by Linus", "authored by Junio", "mentions commit" on the top-level, and all three has to be true.

	git log --committer=Linus --author=Junio --grep=commit --grep=tag

groups the "mentions commit" and "mentions tag" under a new top-level OR node, i.e.

    [all-match]
    (or
     (or
      pattern_body<body>commit
      pattern_body<body>tag
     )
     (or
      pattern_head<head 1>Linus
      (or
       pattern_head<head 0>Junio
       true
      )
     )
    )
so the top-level backbone "all-match" works on becomes
 - Mentions either commit or tag,
 - Committed by Linus,
 - Authored by Junio

One possible improvement we can make is to parse the command line in the last example with "--all-match" to

    [all-match]
    (or
     pattern_body<body>commit
     (or
      pattern_body<body>tag
      (or
       pattern_head<head 1>Linus
       (or
        pattern_head<head 0>Junio
        true
       )
      )
     )
    )
so that the backbone becomes
 - Mentions commit,
 - Mentions tag,
 - Committed by Linus,
 - Authored by Junio
to require that both commit and tag are mentioned in the message.
Show 22 quoted lines
>  t/t7810-grep.sh | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> index 1db3dcb..9bc63a3 100755
> --- a/t/t7810-grep.sh
> +++ b/t/t7810-grep.sh
> @@ -580,6 +580,14 @@ test_expect_success 'log with multiple --author uses union' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'log --all-match with multiple --author still uses union' '
> +	git log --all-match --author="Thor" --author="Aster" --format=%s >actual &&
> +	{
> +	    echo third && echo second && echo initial
> +	} >expect &&
> +	test_cmp expect actual
> +'
> +
>  test_expect_success 'log with --grep and multiple --author uses all-match' '
>  	git log --author="Thor" --author="Night" --grep=i --format=%s >actual &&
>  	{
Previous: Michael J GruberNext: Junio C Hamano
Message 11 of 43 in “rev-list/log: document logic with several limiting options”
  1. rev-list/log: document logic with several limiting optionsMichael J Gruber, Sep 11, 2012
  2. Junio C HamanoSep 11, 2012
  3. Michael J GruberSep 12, 2012
  4. Junio C HamanoSep 12, 2012
  5. Junio C HamanoSep 12, 2012
  6. 0/6 rev-list/log: document logic with several limiting optionsMichael J Gruber, Sep 13, 2012
  7. Junio C HamanoSep 13, 2012
  8. 1/6 t7810-grep: bring log --grep tests in common formMichael J Gruber, Sep 13, 2012
  9. 2/6 t7810-grep: test multiple --grep with and without --all-matchMichael J Gruber, Sep 13, 2012
  10. 3/6 t7810-grep: test multiple --author with --all-matchMichael J Gruber, Sep 13, 2012
  11. Junio C HamanoSep 13, 2012
  12. Junio C HamanoSep 13, 2012
  13. Michael J GruberSep 14, 2012
  14. Junio C HamanoSep 14, 2012
  15. 4/6 t7810-grep: test interaction of multiple --grep and --author optionsMichael J Gruber, Sep 13, 2012
  16. 5/6 t7810-grep: test --all-match with multiple --grep and --author optionsMichael J Gruber, Sep 13, 2012
  17. 6/6 rev-list/log: document logic with several limiting optionsMichael J Gruber, Sep 13, 2012
  18. Junio C HamanoSep 13, 2012
  19. Junio C HamanoSep 14, 2012
  20. Junio C HamanoSep 14, 2012
  21. 00/11 rev-list/log: document logic with several limiting optionsMichael J Gruber, Sep 14, 2012
  22. Junio C HamanoSep 14, 2012
  23. 01/11 grep: teach --debug option to dump the parse treeMichael J Gruber, Sep 14, 2012
  24. Junio C HamanoSep 14, 2012
  25. 02/11 log: name --debug-grep option like in the commit messageMichael J Gruber, Sep 14, 2012
  26. 03/11 grep: show --debug output only onceMichael J Gruber, Sep 14, 2012
  27. Junio C HamanoSep 14, 2012
  28. 04/11 log --grep/--author: honor --all-match honored for multiple --grep patternsMichael J Gruber, Sep 14, 2012
  29. 05/11 log: document use of multiple commit limiting optionsMichael J Gruber, Sep 14, 2012
  30. 06/11 fixup! log: document use of multiple commit limiting optionsMichael J Gruber, Sep 14, 2012
  31. Junio C HamanoSep 14, 2012
  32. 07/11 t7810-grep: bring log --grep tests in common formMichael J Gruber, Sep 14, 2012
  33. 08/11 t7810-grep: test multiple --grep with and without --all-matchMichael J Gruber, Sep 14, 2012
  34. 09/11 t7810-grep: test multiple --author with --all-matchMichael J Gruber, Sep 14, 2012
  35. Junio C HamanoSep 14, 2012
  36. 10/11 t7810-grep: test interaction of multiple --grep and --author optionsMichael J Gruber, Sep 14, 2012
  37. 11/11 t7810-grep: test --all-match with multiple --grep and --author optionsMichael J Gruber, Sep 14, 2012
  38. Junio C HamanoSep 14, 2012
  39. Michael J GruberSep 13, 2012
  40. Junio C HamanoSep 13, 2012
  41. Michael J GruberSep 14, 2012
  42. Junio C HamanoSep 14, 2012
  43. Michael J GruberSep 14, 2012

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.