summaryrefslogtreecommitdiff
path: root/grep.h
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2018-07-09 15:33:47 -0500
committerJunio C Hamano <gitster@pobox.com>2018-07-09 14:15:28 -0700
commit9d8db06eb4a5d5577db559a0059a377914c1ce5a (patch)
treea0ef841c1f6cd361d25b5c9f0e25337eb4a1c38d /grep.h
parentc707ded332375a5b51c1acf9b7ce1c29cbd4536d (diff)
downloadgit-9d8db06eb4a5d5577db559a0059a377914c1ce5a.tar.gz
grep.c: teach 'git grep --only-matching'
Teach 'git grep --only-matching', a new option to only print the matching part(s) of a line. For instance, a line containing the following (taken from README.md:27): (`man gitcvs-migration` or `git help cvs-migration` if git is Is printed as follows: $ git grep --line-number --column --only-matching -e git -- \ README.md | grep ":27" README.md:27:7:git README.md:27:16:git README.md:27:38:git The patch works mostly as one would expect, with the exception of a few considerations that are worth mentioning here. Like GNU grep, this patch ignores --only-matching when --invert (-v) is given. There is a sensible answer here, but parity with the behavior of other tools is preferred. Because a line might contain more than one match, there are special considerations pertaining to when to print line headers, newlines, and how to increment the match column offset. The line header and newlines are handled as a special case within the main loop to avoid polluting the surrounding code with conditionals that have large blocks. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.h')
-rw-r--r--grep.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/grep.h b/grep.h
index 08a0b391c5..4d474d8ec4 100644
--- a/grep.h
+++ b/grep.h
@@ -150,6 +150,7 @@ struct grep_opt {
int relative;
int pathname;
int null_following_name;
+ int only_matching;
int color;
int max_depth;
int funcname;