]> git.ipfire.org Git - thirdparty/git.git/commit - grep.c
log --grep/--author: honor --all-match honored for multiple --grep patterns
authorJunio C Hamano <gitster@pobox.com>
Thu, 13 Sep 2012 23:26:57 +0000 (16:26 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Sep 2012 17:12:56 +0000 (10:12 -0700)
commit13e4fc7e0197ca752cf46674392bf6ef6249e614
tree8237199ff4ec448d341329d637a08f1da48b5a4d
parent208f5aa42615671bae1e55de20a58d9ba046d3e8
log --grep/--author: honor --all-match honored for multiple --grep patterns

When we have both header expression (which has to be an OR node by
construction) and a pattern expression (which could be anything), we
create a new top-level OR node to bind them together, and the
resulting expression structure looks like this:

             OR
        /          \
       /            \
   pattern            OR
     / \           /     \
    .....    committer    OR
                         /   \
                     author   TRUE

The three elements on the top-level backbone that are inspected by
the "all-match" logic are "pattern", "committer" and "author".  When
there are more than one elements in the "pattern", the top-level
node of the "pattern" part of the subtree is an OR, and that node is
inspected by "all-match".

The result ends up ignoring the "--all-match" given from the command
line.  A match on either side of the pattern is considered a match,
hence:

        git log --grep=A --grep=B --author=C --all-match

shows the same "authored by C and has either A or B" that is correct
only when run without "--all-match".

Fix this by turning the resulting expression around when "--all-match"
is in effect, like this:

              OR
          /        \
         /          \
        /              OR
    committer        /    \
                 author    \
                           pattern

The set of nodes on the top-level backbone in the resulting
expression becomes "committer", "author", and the nodes that are on
the top-level backbone of the "pattern" subexpression.  This makes
the "all-match" logic inspect the same nodes in "pattern" as the
case without the author and/or the committer restriction, and makes
the earlier "log" example to show "authored by C and has A and has
B", which is what the command line expects.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c