All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-log: added --invert-grep option
@ 2014-12-19  2:14 Christoph Junghans
  2014-12-19  6:50 ` Junio C Hamano
  0 siblings, 1 reply; 15+ messages in thread
From: Christoph Junghans @ 2014-12-19  2:14 UTC (permalink / raw)
  To: gitster; +Cc: git, Christoph Junghans

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 'global_invert' 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.h                                 | 3 ++-
 revision.c                             | 4 +++-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index afccfdc..6d4671f 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 2fece98..914c317 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 --invert-grep
 "
 
 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
diff --git a/grep.h b/grep.h
index 95f197a..c137103 100644
--- a/grep.h
+++ b/grep.h
@@ -93,7 +93,8 @@ struct grep_opt {
 	int prefix_length;
 	regex_t regexp;
 	int linenum;
-	int invert;
+	int invert; /** line-wise invert match */
+	int global_invert; /** final global invert match */
 	int ignore_case;
 	int status_only;
 	int name_only;
diff --git a/revision.c b/revision.c
index 75dda92..c8d4c49 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, "--invert-grep")) {
+		revs->grep_filter.global_invert = 1;
 	} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
 		if (strcmp(optarg, "none"))
 			git_log_output_encoding = xstrdup(optarg);
@@ -2909,7 +2911,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->grep_filter.global_invert ? !retval : retval;
 }
 
 static inline int want_ancestry(const struct rev_info *revs)
-- 
2.0.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-03-22  3:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19  2:14 [PATCH] git-log: added --invert-grep option Christoph Junghans
2014-12-19  6:50 ` Junio C Hamano
2014-12-24  3:03   ` Christoph Junghans
2014-12-24  3:03     ` [PATCH] git-log: added --grep-begin .. --grep-end syntax Christoph Junghans
2014-12-29 17:56     ` [PATCH] git-log: added --invert-grep option Junio C Hamano
2015-01-04  5:27   ` [PATCH] git-log: added --none-match option Christoph Junghans
2015-01-06 23:02     ` Junio C Hamano
2015-01-09 22:33       ` Christoph Junghans
2015-01-09 22:55         ` Junio C Hamano
2015-01-12 20:51           ` Junio C Hamano
2015-01-12  1:39       ` [PATCH v2] " Christoph Junghans
2015-01-13  1:33       ` [PATCH v2] log: teach --invert-grep option Christoph Junghans
2015-01-13 18:25         ` Junio C Hamano
2015-02-16  7:29         ` [PATCH] gitk: pass --invert-grep option down to "git log" Junio C Hamano
2015-03-22  3:39           ` Paul Mackerras

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.