diff options
-rw-r--r-- | Documentation/rev-list-options.txt | 4 | ||||
-rw-r--r-- | contrib/completion/git-completion.bash | 2 | ||||
-rw-r--r-- | revision.c | 4 | ||||
-rw-r--r-- | revision.h | 2 | ||||
-rwxr-xr-x | t/t4202-log.sh | 15 |
5 files changed, 25 insertions, 2 deletions
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index deb8cca917..05aa997fd1 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -66,6 +66,10 @@ if it is part of the log message. Limit the commits output to ones that match all given `--grep`, instead of ones that match at least one. +--invert-grep:: + Limit the commits output to ones with log message that do not + match the pattern specified with `--grep=<pattern>`. + -i:: --regexp-ignore-case:: Match the regular expression limiting patterns without regard to letter diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 06bf262087..53857f0bbf 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1428,7 +1428,7 @@ __git_log_gitk_options=" # Options that go well for log and shortlog (not gitk) __git_log_shortlog_options=" --author= --committer= --grep= - --all-match + --all-match --invert-grep " __git_log_pretty_formats="oneline short medium full fuller email raw format:" diff --git a/revision.c b/revision.c index 615535c984..84b33a33ca 100644 --- a/revision.c +++ b/revision.c @@ -1952,6 +1952,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter); } else if (!strcmp(arg, "--all-match")) { revs->grep_filter.all_match = 1; + } else if (!strcmp(arg, "--invert-grep")) { + revs->invert_grep = 1; } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { if (strcmp(optarg, "none")) git_log_output_encoding = xstrdup(optarg); @@ -2848,7 +2850,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt) (char *)message, strlen(message)); strbuf_release(&buf); unuse_commit_buffer(commit, message); - return retval; + return opt->invert_grep ? !retval : retval; } static inline int want_ancestry(const struct rev_info *revs) diff --git a/revision.h b/revision.h index a6205307cf..b0b82e766e 100644 --- a/revision.h +++ b/revision.h @@ -168,6 +168,8 @@ struct rev_info { /* Filter by commit log message */ struct grep_opt grep_filter; + /* Negate the match of grep_filter */ + int invert_grep; /* Display history graph */ struct git_graph *graph; diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 99ab7ca21f..5f2b290d2b 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -212,6 +212,21 @@ test_expect_success 'log --grep' ' test_cmp expect actual ' +cat > expect << EOF +second +initial +EOF +test_expect_success 'log --invert-grep --grep' ' + git log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual && + test_cmp expect actual +' + +test_expect_success 'log --invert-grep --grep -i' ' + echo initial >expect && + git log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual && + test_cmp expect actual +' + test_expect_success 'log --grep option parsing' ' echo second >expect && git log -1 --pretty="tformat:%s" --grep sec >actual && |