Skip to content

Commit 1ba6e86

Browse files
committed
Merge branch 'cj/log-invert-grep'
"git log --invert-grep --grep=WIP" will show only commits that do not have the string "WIP" in their messages. * cj/log-invert-grep: log: teach --invert-grep option
2 parents b19aab5 + 22dfa8a commit 1ba6e86

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

Documentation/rev-list-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ if it is part of the log message.
6666
Limit the commits output to ones that match all given `--grep`,
6767
instead of ones that match at least one.
6868

69+
--invert-grep::
70+
Limit the commits output to ones with log message that do not
71+
match the pattern specified with `--grep=<pattern>`.
72+
6973
-i::
7074
--regexp-ignore-case::
7175
Match the regular expression limiting patterns without regard to letter

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ __git_log_gitk_options="
14251425
# Options that go well for log and shortlog (not gitk)
14261426
__git_log_shortlog_options="
14271427
--author= --committer= --grep=
1428-
--all-match
1428+
--all-match --invert-grep
14291429
"
14301430

14311431
__git_log_pretty_formats="oneline short medium full fuller email raw format:"

revision.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
20172017
grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
20182018
} else if (!strcmp(arg, "--all-match")) {
20192019
revs->grep_filter.all_match = 1;
2020+
} else if (!strcmp(arg, "--invert-grep")) {
2021+
revs->invert_grep = 1;
20202022
} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
20212023
if (strcmp(optarg, "none"))
20222024
git_log_output_encoding = xstrdup(optarg);
@@ -2915,7 +2917,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
29152917
(char *)message, strlen(message));
29162918
strbuf_release(&buf);
29172919
unuse_commit_buffer(commit, message);
2918-
return retval;
2920+
return opt->invert_grep ? !retval : retval;
29192921
}
29202922

29212923
static inline int want_ancestry(const struct rev_info *revs)

revision.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ struct rev_info {
169169

170170
/* Filter by commit log message */
171171
struct grep_opt grep_filter;
172+
/* Negate the match of grep_filter */
173+
int invert_grep;
172174

173175
/* Display history graph */
174176
struct git_graph *graph;

t/t4202-log.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ test_expect_success 'log --grep' '
212212
test_cmp expect actual
213213
'
214214

215+
cat > expect << EOF
216+
second
217+
initial
218+
EOF
219+
test_expect_success 'log --invert-grep --grep' '
220+
git log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
221+
test_cmp expect actual
222+
'
223+
224+
test_expect_success 'log --invert-grep --grep -i' '
225+
echo initial >expect &&
226+
git log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
227+
test_cmp expect actual
228+
'
229+
215230
test_expect_success 'log --grep option parsing' '
216231
echo second >expect &&
217232
git log -1 --pretty="tformat:%s" --grep sec >actual &&

0 commit comments

Comments
 (0)