git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Dotan Cohen <dotancohen@gmail.com>,
	git@vger.kernel.org, Christoph Junghans <ottxor@gentoo.org>
Subject: Re: Git bug: Filter ignored when "--invert-grep" option is used.
Date: Fri, 17 Dec 2021 10:16:00 -0800	[thread overview]
Message-ID: <xmqqbl1f5c7z.fsf@gitster.g> (raw)
In-Reply-To: <e2e7759e-aa97-1117-6df2-f93a12afb094@web.de> ("René Scharfe"'s message of "Fri, 17 Dec 2021 17:48:49 +0100")

René Scharfe <l.s.r@web.de> writes:

> Subject: [PATCH] log: let --invert-grep only invert --grep
>
> The option --invert-grep is documented to filter out commits whose
> messages match the --grep filters.  However, it also affects the
> header matches (--author, --committer), which is not intended.

I re-read the log message that introduced this feature, and I agree
with the "not intended" part.  I do not think the change itself was
even done with awareness that the header matches may also be
affected, and there is no test for it to see the interaction.

> Move the handling of that option to grep.c, as only the code there can
> distinguish between matches in the header from those in the message
> body.  If --invert-grep is given then enable extended expressions (not
> the regex type, we just need git grep's --not to work), negate the body
> patterns and check if any of them match by piggy-backing on the
> collect_hits mechanism of grep_source_1().

Nice.  The original says that --files-without-matches being a
negation of --files-with-matches was what triggered them to have the
bit in the revisions, not in grep_opt, by the way.

> Collecting the matches in struct grep_opt is a bit iffy, but with
> "last_shown" we have a precedent for writing state information to that
> struct.

I think this is perfectly fine.  apply_state, grep_opt,
diff_options, and rev_info are used the same way within their
subsystems to carry in options that affect behaviour, carry around
the state of the machinery, and carry out the result.  The word
"option" does make it sound it is an input-only thing, but others
are not much better ;-).

> diff --git a/grep.c b/grep.c
> index fe847a0111..beef5fe47e 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -699,6 +699,14 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
>  	return compile_pattern_or(list);
>  }
>
> +static struct grep_expr *grep_not_expr(struct grep_expr *expr)
> +{
> +	struct grep_expr *z = xcalloc(1, sizeof(*z));
> +	z->node = GREP_NODE_NOT;
> +	z->u.unary = expr;
> +	return z;
> +}

A bit surprising to see that we already had GREP_NODE_NOT without a
helper to create a node.  Not updating compile_pattern_not() to use
this new helper does make this patch simpler to read by allowing
readers to focus on what matters, which is very much appreciaed.

The rest of the patch looks good to me, too.

      reply	other threads:[~2021-12-17 18:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15  9:50 Git bug: Filter ignored when "--invert-grep" option is used Dotan Cohen
2021-12-15 22:08 ` Junio C Hamano
2021-12-16 14:54   ` Dotan Cohen
2021-12-16 19:42     ` Junio C Hamano
2021-12-17 16:48       ` René Scharfe
2021-12-17 18:16         ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqbl1f5c7z.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=dotancohen@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=ottxor@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).