]> git.ipfire.org Git - thirdparty/git.git/commit - grep.c
grep.c: expose {,inverted} match column in match_line()
authorTaylor Blau <me@ttaylorr.com>
Fri, 22 Jun 2018 15:49:35 +0000 (10:49 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Jun 2018 19:59:02 +0000 (12:59 -0700)
commit68d686e6af0fc192fce1788f67bbe0c21a5419ab
tree65fb8399de80ad79e25e51bfb808606ea9551991
parentf8a0c6e799b98f6b502eadfadcf6acc103d6f7c6
grep.c: expose {,inverted} match column in match_line()

When calling match_line(), callers presently cannot determine the
relative offset of the match because match_line() discards the
'regmatch_t' that contains this information.

Instead, teach match_line() to take in two 'ssize_t's. Fill the first
with the offset of the match produced by the given expression. If
extended, fill the later with the offset of the match produced as if
--invert were given.

For instance, matching "--not -e x" on this line produces a columnar
offset of 0, (i.e., the whole line does not contain an x), but "--invert
--not -e -x" will fill the later ssize_t of the column containing an
"x", because this expression is semantically equivalent to "-e x".

To determine the column for the inverted and non-inverted case, do the
following:

  - If matching an atom, the non-inverted column is as given from
    match_one_pattern(), and the inverted column is unset.

  - If matching a --not, the inverted column and non-inverted column
    swap.

  - If matching an --and, or --or, the non-inverted column is the
    minimum of the two children.

Presently, the existing short-circuiting logic for AND and OR applies as
before. This will change in the following commit when we add options to
configure the --column flag. Taken together, this and the forthcoming
change will always yield the earlier column on a given line.

This patch will become useful when we later pick between the two new
results in order to display the column number of the first match on a
line with --column.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c