Subject: Re: [PATCH v2 21/22] pickaxe -G: terminate early on matching lines

From: Junio C Hamano <[email-masked]>
Date: Tue, 30 Mar 2021 17:11:51 -0700

Ævar Arnfjörð Bjarmason  <[email-masked]> writes:

> Solve a long-standing item for "git log -Grx" of us e.g. finding "+
> str" in the diff context and noting that we had a "hit", but xdiff
> diligently continuing to generate and spew the rest of the diff at us.
>

Nice.  "git log -Gpattern" without "-p" has no reason to do the full
diff once it finds out that pattern would have existed if "-p" were
given in the output.

It actually is a bit of shame that "git log -Gpattern -p" still
needs to run two diffs (instead of taking advantage of the diff that
it needs to generate anyway (to show to the user of the "log") and
pattern match in it).

>  	if (data->hit)
> +		BUG("Already matched in diffgrep_consume! Broken xdiff_emit_line_fn?");

Hmph, an obvious alternative would be to silently return -1 here,
which probably would not hurt, either.  I do not mind the check to
be stricter, though.

> +	if (!regexec_buf(data->regexp, line + 1, len - 1, 1,
> +			 &regmatch, 0)) {
> +		data->hit = 1;
> +		return -1;
> +	}
>  	return 0;
>  }