summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-08-02 22:30:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-02 22:30:44 (GMT)
commit87ece7ce1133ebc5d339cad5f6f92c02e5fc712d (patch)
tree80a92c51969d8893f56b74a595ab9c260cca1091 /builtin
parent562413eb2938b7a1aa85a2ae157ef162d51e55dc (diff)
parent9d8db06eb4a5d5577db559a0059a377914c1ce5a (diff)
downloadgit-87ece7ce1133ebc5d339cad5f6f92c02e5fc712d.zip
git-87ece7ce1133ebc5d339cad5f6f92c02e5fc712d.tar.gz
git-87ece7ce1133ebc5d339cad5f6f92c02e5fc712d.tar.bz2
Merge branch 'tb/grep-only-matching'
"git grep" learned the "--only-matching" option. * tb/grep-only-matching: grep.c: teach 'git grep --only-matching' grep.c: extract show_line_header()
Diffstat (limited to 'builtin')
-rw-r--r--builtin/grep.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index f9678f1..056161f 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -844,6 +844,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
OPT_BOOL_F('z', "null", &opt.null_following_name,
N_("print NUL after filenames"),
PARSE_OPT_NOCOMPLETE),
+ OPT_BOOL('o', "only-matching", &opt.only_matching,
+ N_("show only matching parts of a line")),
OPT_BOOL('c', "count", &opt.count,
N_("show the number of matches instead of matching lines")),
OPT__COLOR(&opt.color, N_("highlight matches")),
@@ -963,6 +965,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (!opt.pattern_list)
die(_("no pattern given."));
+ /* --only-matching has no effect with --invert. */
+ if (opt.invert)
+ opt.only_matching = 0;
+
/*
* We have to find "--" in a separate pass, because its presence
* influences how we will parse arguments that come before it.