git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-log: added --none-match option

From
Christoph Junghans <ottxor@gentoo.org>
Date
Jan 4, 2015, 05:27 UTC
Message-ID
<1420349268-13479-1-git-send-email-ottxor@gentoo.org>
In-Reply-To
<xmqqwq5o5e1j.fsf@gitster.dls.corp.google.com>

Implements a inverted match for "git log", like in the case of "git grep -v", which is useful from time to time to e.g. filter FIXUP message out of "git log".

Internally, a new bol 'none_match' has been introduces as revs->grep_filter.invert inverts the match line-wise, which cannot work as i.e. empty line always not match the pattern given.

Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
---
 Documentation/rev-list-options.txt     | 4 ++++
 contrib/completion/git-completion.bash | 2 +-
 grep.c                                 | 2 ++
 grep.h                                 | 1 +
 revision.c                             | 4 ++++
 5 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index afccfdc..08e4ed8 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.
 
+--none-match::
+	Limit the commits output to ones that do not match any of the 
+	given `--grep`, instead of ones that match at least one.
+
 -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 23988ec..b0720e9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1425,7 +1425,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 --none-match
 "
 
 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
diff --git a/grep.c b/grep.c
index 6e085f8..eadf8d9 100644
--- a/grep.c
+++ b/grep.c
@@ -1622,6 +1622,8 @@ static int chk_hit_marker(struct grep_expr *x)
 
 int grep_source(struct grep_opt *opt, struct grep_source *gs)
 {
+  	if(opt->none_match)
+		return !grep_source_1(opt, gs, 0);	
 	/*
 	 * we do not have to do the two-pass grep when we do not check
 	 * buffer-wide "all-match".
diff --git a/grep.h b/grep.h
index 95f197a..8e50c95 100644
--- a/grep.h
+++ b/grep.h
@@ -102,6 +102,7 @@ struct grep_opt {
 	int word_regexp;
 	int fixed;
 	int all_match;
+	int none_match;
 	int debug;
 #define GREP_BINARY_DEFAULT	0
 #define GREP_BINARY_NOMATCH	1
diff --git a/revision.c b/revision.c
index 75dda92..d43779e 100644
--- a/revision.c
+++ b/revision.c
@@ -2011,6 +2011,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, "--none-match")) {
+		revs->grep_filter.none_match = 1;
 	} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
 		if (strcmp(optarg, "none"))
 			git_log_output_encoding = xstrdup(optarg);
@@ -2333,6 +2335,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		die("cannot combine --walk-reflogs with --graph");
 	if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)
 		die("cannot use --grep-reflog without --walk-reflogs");
+	if (revs->grep_filter.all_match && revs->grep_filter.none_match)
+		die("cannot combine --all-match with --none-match");
 
 	return left;
 }
-- 
2.0.5
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 15 in “git-log: added --invert-grep option”
  1. git-log: added --invert-grep optionChristoph Junghans, Dec 19, 2014
  2. Junio C HamanoDec 19, 2014
  3. Christoph JunghansDec 24, 2014
  4. git-log: added --grep-begin .. --grep-end syntaxChristoph Junghans, Dec 24, 2014
  5. Junio C HamanoDec 29, 2014
  6. git-log: added --none-match optionChristoph Junghans, Jan 4, 2015
  7. Junio C HamanoJan 6, 2015
  8. Christoph JunghansJan 9, 2015
  9. Junio C HamanoJan 9, 2015
  10. Junio C HamanoJan 12, 2015
  11. git-log: added --none-match optionChristoph Junghans, Jan 12, 2015
  12. log: teach --invert-grep optionChristoph Junghans, Jan 13, 2015
  13. Junio C HamanoJan 13, 2015
  14. gitk: pass --invert-grep option down to "git log"Junio C Hamano, Feb 16, 2015
  15. Paul MackerrasMar 22, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.