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

* Re: [PATCH] git-log: added --invert-grep option
  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
  2015-01-04  5:27   ` [PATCH] git-log: added --none-match option Christoph Junghans
  0 siblings, 2 replies; 15+ messages in thread
From: Junio C Hamano @ 2014-12-19  6:50 UTC (permalink / raw)
  To: Christoph Junghans; +Cc: git

Christoph Junghans <ottxor@gentoo.org> writes:

> 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.

While I am very sympathetic to those who feel the pain, i.e. the
need for something like this, I do not think this patch takes the
right approach.

The pain is that "git log --grep=..." can express only a limited
subset of what "git grep" can express.  The latter supports a very
rich set of logical operations, with operators like --and and --not,
and grouping, e.g. "git grep \( -e foo --or -e bar \) --and --not -e
baz" (i.e. "has either foo or bar but not baz").  It also can turn
the list of top-level predicates into "all of these predicates must
match somewhere in the entire file" with --all-match option.  None
of this richness is available to "git log --grep=...".

The root cause of the pain comes from the fact that it needs to
share the command line parsing with the revision list commands to
drive the underlying "grep" machinery, so you cannot say

    git log --not --grep=FIXUP

because "--not" is taken as "commits reachable from revs listed after
this point are to be excluded from the result" and not passed to the
underlying grep machinery.

The right way to do this is to somehow find a way to allow you to
express the full "grep" logical operations to the command line
parser that is used by the "log" family of commands.  That would
allow you to express something like "Show only commits that has
either foo or bar and does not have baz".  I am not going to
advocate this exact syntax, but to illustrate the idea, if you had
something like this supported:

    git log --grep-begin \
    	\( -e foo --or -e bar \) --and --not -e baz \
        --grep-end

by stopping the revision.c parser between --grep-{begin,end} and
instead feeding the arguments to the grep expression builder, we may
be able to get the full expressiveness of the logical operations
offered by the grep machinery.

And you shouldn't need to add any new field to grep_opt for that.
All you need is a design of a new syntax and a tweak to the revision
argument parser to understand the new syntax to redirect some
arguments to the grep command line parser.

A new option that allows you to _only_ negate without allowing you
to enable other richer logical operations of the underlying grep
machinery is going in a wrong direction, isn't it?

> 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)

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

* Re: [PATCH] git-log: added --invert-grep option
  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
  1 sibling, 2 replies; 15+ messages in thread
From: Christoph Junghans @ 2014-12-24  3:03 UTC (permalink / raw)
  To: gitster; +Cc: git

Ok, I drafted a first version of the suggest --grep-begin ...
--grep-end syntax.

However, I could not find a good ways to invert the match on a commit
basis instead of the normal line-wise version. Any suggestions?

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

* [PATCH] git-log: added --grep-begin .. --grep-end syntax
  2014-12-24  3:03   ` Christoph Junghans
@ 2014-12-24  3:03     ` Christoph Junghans
  2014-12-29 17:56     ` [PATCH] git-log: added --invert-grep option Junio C Hamano
  1 sibling, 0 replies; 15+ messages in thread
From: Christoph Junghans @ 2014-12-24  3:03 UTC (permalink / raw)
  To: gitster; +Cc: git, Christoph Junghans

This is useful to specify more complicated pattern as with '--grep'.

Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
---
 builtin/grep.c | 73 +++++-----------------------------------------------------
 grep.c         | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 grep.h         | 10 ++++++++
 revision.c     | 56 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 134 insertions(+), 67 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index 4063882..0127fa0 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -551,67 +551,6 @@ static int context_callback(const struct option *opt, const char *arg,
 	return 0;
 }
 
-static int file_callback(const struct option *opt, const char *arg, int unset)
-{
-	struct grep_opt *grep_opt = opt->value;
-	int from_stdin = !strcmp(arg, "-");
-	FILE *patterns;
-	int lno = 0;
-	struct strbuf sb = STRBUF_INIT;
-
-	patterns = from_stdin ? stdin : fopen(arg, "r");
-	if (!patterns)
-		die_errno(_("cannot open '%s'"), arg);
-	while (strbuf_getline(&sb, patterns, '\n') == 0) {
-		/* ignore empty line like grep does */
-		if (sb.len == 0)
-			continue;
-
-		append_grep_pat(grep_opt, sb.buf, sb.len, arg, ++lno,
-				GREP_PATTERN);
-	}
-	if (!from_stdin)
-		fclose(patterns);
-	strbuf_release(&sb);
-	return 0;
-}
-
-static int not_callback(const struct option *opt, const char *arg, int unset)
-{
-	struct grep_opt *grep_opt = opt->value;
-	append_grep_pattern(grep_opt, "--not", "command line", 0, GREP_NOT);
-	return 0;
-}
-
-static int and_callback(const struct option *opt, const char *arg, int unset)
-{
-	struct grep_opt *grep_opt = opt->value;
-	append_grep_pattern(grep_opt, "--and", "command line", 0, GREP_AND);
-	return 0;
-}
-
-static int open_callback(const struct option *opt, const char *arg, int unset)
-{
-	struct grep_opt *grep_opt = opt->value;
-	append_grep_pattern(grep_opt, "(", "command line", 0, GREP_OPEN_PAREN);
-	return 0;
-}
-
-static int close_callback(const struct option *opt, const char *arg, int unset)
-{
-	struct grep_opt *grep_opt = opt->value;
-	append_grep_pattern(grep_opt, ")", "command line", 0, GREP_CLOSE_PAREN);
-	return 0;
-}
-
-static int pattern_callback(const struct option *opt, const char *arg,
-			    int unset)
-{
-	struct grep_opt *grep_opt = opt->value;
-	append_grep_pattern(grep_opt, arg, "-e option", 0, GREP_PATTERN);
-	return 0;
-}
-
 static int help_callback(const struct option *opt, const char *arg, int unset)
 {
 	return -1;
@@ -710,21 +649,21 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			N_("show the surrounding function")),
 		OPT_GROUP(""),
 		OPT_CALLBACK('f', NULL, &opt, N_("file"),
-			N_("read patterns from file"), file_callback),
+			N_("read patterns from file"), grep_file_callback),
 		{ OPTION_CALLBACK, 'e', NULL, &opt, N_("pattern"),
-			N_("match <pattern>"), PARSE_OPT_NONEG, pattern_callback },
+			N_("match <pattern>"), PARSE_OPT_NONEG, grep_pattern_callback },
 		{ OPTION_CALLBACK, 0, "and", &opt, NULL,
 		  N_("combine patterns specified with -e"),
-		  PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback },
+		  PARSE_OPT_NOARG | PARSE_OPT_NONEG, grep_and_callback },
 		OPT_BOOL(0, "or", &dummy, ""),
 		{ OPTION_CALLBACK, 0, "not", &opt, NULL, "",
-		  PARSE_OPT_NOARG | PARSE_OPT_NONEG, not_callback },
+		  PARSE_OPT_NOARG | PARSE_OPT_NONEG, grep_not_callback },
 		{ OPTION_CALLBACK, '(', NULL, &opt, NULL, "",
 		  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH,
-		  open_callback },
+		  grep_open_callback },
 		{ OPTION_CALLBACK, ')', NULL, &opt, NULL, "",
 		  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH,
-		  close_callback },
+		  grep_close_callback },
 		OPT__QUIET(&opt.status_only,
 			   N_("indicate hit with exit status without output")),
 		OPT_BOOL(0, "all-match", &opt.all_match,
diff --git a/grep.c b/grep.c
index 6e085f8..0c9a977 100644
--- a/grep.c
+++ b/grep.c
@@ -1796,3 +1796,65 @@ static int grep_source_is_binary(struct grep_source *gs)
 
 	return 0;
 }
+
+int grep_file_callback(const struct option *opt, const char *arg, int unset)
+{
+	struct grep_opt *grep_opt = opt->value;
+	int from_stdin = !strcmp(arg, "-");
+	FILE *patterns;
+	int lno = 0;
+	struct strbuf sb = STRBUF_INIT;
+
+	patterns = from_stdin ? stdin : fopen(arg, "r");
+	if (!patterns)
+		die_errno(_("cannot open '%s'"), arg);
+	while (strbuf_getline(&sb, patterns, '\n') == 0) {
+		/* ignore empty line like grep does */
+		if (sb.len == 0)
+			continue;
+
+		append_grep_pat(grep_opt, sb.buf, sb.len, arg, ++lno,
+				GREP_PATTERN);
+	}
+	if (!from_stdin)
+		fclose(patterns);
+	strbuf_release(&sb);
+	return 0;
+}
+
+int grep_not_callback(const struct option *opt, const char *arg, int unset)
+{
+	struct grep_opt *grep_opt = opt->value;
+	append_grep_pattern(grep_opt, "--not", "command line", 0, GREP_NOT);
+	return 0;
+}
+
+int grep_and_callback(const struct option *opt, const char *arg, int unset)
+{
+	struct grep_opt *grep_opt = opt->value;
+	append_grep_pattern(grep_opt, "--and", "command line", 0, GREP_AND);
+	return 0;
+}
+
+int grep_open_callback(const struct option *opt, const char *arg, int unset)
+{
+	struct grep_opt *grep_opt = opt->value;
+	append_grep_pattern(grep_opt, "(", "command line", 0, GREP_OPEN_PAREN);
+	return 0;
+}
+
+int grep_close_callback(const struct option *opt, const char *arg, int unset)
+{
+	struct grep_opt *grep_opt = opt->value;
+	append_grep_pattern(grep_opt, ")", "command line", 0, GREP_CLOSE_PAREN);
+	return 0;
+}
+
+int grep_pattern_callback(const struct option *opt, const char *arg,
+			    int unset)
+{
+	struct grep_opt *grep_opt = opt->value;
+	append_grep_pattern(grep_opt, arg, "-e option", 0, GREP_PATTERN);
+	return 0;
+}
+
diff --git a/grep.h b/grep.h
index 95f197a..d85fdb4 100644
--- a/grep.h
+++ b/grep.h
@@ -10,6 +10,7 @@ typedef int pcre_extra;
 #include "kwset.h"
 #include "thread-utils.h"
 #include "userdiff.h"
+#include "parse-options.h"
 
 enum grep_pat_token {
 	GREP_PATTERN,
@@ -181,6 +182,15 @@ void grep_source_load_driver(struct grep_source *gs);
 
 int grep_source(struct grep_opt *opt, struct grep_source *gs);
 
+
+int grep_file_callback(const struct option *opt, const char *arg, int unset);
+int grep_not_callback(const struct option *opt, const char *arg, int unset);
+int grep_and_callback(const struct option *opt, const char *arg, int unset);
+int grep_open_callback(const struct option *opt, const char *arg, int unset);
+int grep_close_callback(const struct option *opt, const char *arg, int unset);
+int grep_pattern_callback(const struct option *opt, const char *arg, int unset);
+
+
 extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
 extern int grep_threads_ok(const struct grep_opt *opt);
 
diff --git a/revision.c b/revision.c
index 75dda92..4fe9085 100644
--- a/revision.c
+++ b/revision.c
@@ -1998,6 +1998,62 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		return argcount;
 	} else if (!strcmp(arg, "--grep-debug")) {
 		revs->grep_filter.debug = 1;
+	} else if (!strcmp(arg, "--grep-begin")) {
+		if (argc <= 1)
+			return error("--grep-begin requires an argument");
+		int dummy;
+		struct option options[] = {
+			OPT_CALLBACK('f', NULL, &revs->grep_filter, N_("file"),
+				N_("read patterns from file"), grep_file_callback),
+			{ OPTION_CALLBACK, 'e', NULL, &revs->grep_filter, N_("pattern"),
+				N_("match <pattern>"), PARSE_OPT_NONEG, grep_pattern_callback },
+			{ OPTION_CALLBACK, 0, "and", &revs->grep_filter, NULL,
+			  N_("combine patterns specified with -e"),
+			  PARSE_OPT_NOARG | PARSE_OPT_NONEG, grep_and_callback },
+			OPT_BOOL(0, "or", &dummy, ""),
+			{ OPTION_CALLBACK, 0, "not", &revs->grep_filter, NULL, "",
+			  PARSE_OPT_NOARG | PARSE_OPT_NONEG, grep_not_callback },
+			{ OPTION_CALLBACK, '(', NULL, &revs->grep_filter, NULL, "",
+			  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH,
+			  grep_open_callback },
+			{ OPTION_CALLBACK, ')', NULL, &revs->grep_filter, NULL, "",
+			  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH,
+			  grep_close_callback },
+			OPT_END()
+		};
+		char const * const grep_usage[] = {
+			N_("git log [log-options] --begin-grep [grep-options] --end-grep ..."), 
+			NULL 
+		};
+		struct parse_opt_ctx_t ctx;
+
+		parse_options_start(&ctx, argc, argv, revs->prefix, options,
+				PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP);
+		if (parse_options_step(&ctx, options, grep_usage) != PARSE_OPT_UNKNOWN) {
+			error("--grep-end expected");
+			usage_with_options(grep_usage, options);
+		}
+		if(strcmp(ctx.argv[0], "--grep-end")) {
+			if (ctx.argv[0][1] == '-') {
+			error("unknown option `%s'", ctx.argv[0] + 2);
+			} else if (isascii(*ctx.opt)) {
+				error("unknown switch `%c'", *ctx.opt);
+			} else {
+			error("unknown non-ascii option in string: `%s'",
+			      ctx.argv[0]);
+			}	
+			usage_with_options(grep_usage, options);
+		}
+
+		precompose_argv(argc, argv);
+		argcount = argc + 1 - parse_options_end(&ctx);
+		if (argcount == 2 ) {
+			return error("There should be options between --grep-begin and --grep-end ;-)");
+		}
+
+		grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED, &revs->grep_filter);
+
+		return argcount;
 	} else if (!strcmp(arg, "--basic-regexp")) {
 		grep_set_pattern_type_option(GREP_PATTERN_TYPE_BRE, &revs->grep_filter);
 	} else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
-- 
2.0.5

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

* Re: [PATCH] git-log: added --invert-grep option
  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     ` Junio C Hamano
  1 sibling, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2014-12-29 17:56 UTC (permalink / raw)
  To: Christoph Junghans; +Cc: git

Christoph Junghans <ottxor@gentoo.org> writes:

> Ok, I drafted a first version of the suggest --grep-begin ...
> --grep-end syntax.

I am somewhat surprised that it was doable that cleanly.

The syntax, as I already said, is a bit too ugly to live in that
form I suggested, though ;-).

> However, I could not find a good ways to invert the match on a commit
> basis instead of the normal line-wise version.

Good point.

The only interface to tweak the way the individual matches are
turned into file-level match (by default, we say "any one of the
clauses match, we find the file to be interesting") is "--all-match"
("all of the clauses have to trigger at least once for us to find
the file interesting"), which, compared to the richer set of boolean
operations at the line level, is a kludge.

Offhand, short of overhauling that kludge to allow us to express
"The file has to have either 'atomic' or 'all-or-none' appear
somewhere, and also cannot have 'wip' anywhere", I do not think of a
good way, other than adding yet another kludge on top of the
"--all-match" that says "none of the clauses must trigger" to
express what you want to see happen in "git log" to exclude ones
that are marked with "wip", perhaps naming it "--none-match" or
something.

Thanks.

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

* [PATCH] git-log: added --none-match option
  2014-12-19  6:50 ` Junio C Hamano
  2014-12-24  3:03   ` Christoph Junghans
@ 2015-01-04  5:27   ` Christoph Junghans
  2015-01-06 23:02     ` Junio C Hamano
  1 sibling, 1 reply; 15+ messages in thread
From: Christoph Junghans @ 2015-01-04  5:27 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 '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

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

* Re: [PATCH] git-log: added --none-match option
  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
                         ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Junio C Hamano @ 2015-01-06 23:02 UTC (permalink / raw)
  To: Christoph Junghans; +Cc: git

Christoph Junghans <ottxor@gentoo.org> writes:

> 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>
> ---

The patch itself looks like a good start, except that the above
description no longer matches the implementation.

I further suspect it would be better to rename all_match to
all_or_none and then you can lose the "these two are mutually
incompatible" check that is placed together with a wrong existing
comment.  I also notice that you forgot to update the "git grep"
where the original "--all-match" came from.

A partial fix-up may start like this on top of your version.  By
renaming the variable used in the existing code, the compiler will
remind you that there are a few more places that your patch did not
touch that does something special for --all-match, which are a good
candidates you need to think if doing something similarly special
for the --none-match case is necessary.

Thanks.

diff --git a/builtin/grep.c b/builtin/grep.c
index 4063882..9ba4254 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -727,8 +727,12 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		  close_callback },
 		OPT__QUIET(&opt.status_only,
 			   N_("indicate hit with exit status without output")),
-		OPT_BOOL(0, "all-match", &opt.all_match,
-			N_("show only matches from files that match all patterns")),
+		OPT_SET_INT(0, "all-match", &opt.all_or_none,
+			    N_("show only matches from files that match all patterns"),
+			    GREP_ALL_MATCH),
+		OPT_SET_INT(0, "none-match", &opt.all_or_none,
+			    N_("show only matches from files that match no patterns"),
+			    GREP_NONE_MATCH),
 		{ OPTION_SET_INT, 0, "debug", &opt.debug, NULL,
 		  N_("show parse tree for grep expression"),
 		  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },
diff --git a/grep.c b/grep.c
index f486ee5..1ff5dea 100644
--- a/grep.c
+++ b/grep.c
@@ -1622,14 +1622,18 @@ 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".
+	 * buffer-wide "all-match" or "none-match".
 	 */
-	if (!opt->all_match)
+	switch (opt->all_or_none) {
+	case GREP_ALL_MATCH:
 		return grep_source_1(opt, gs, 0);
+	case GREP_NONE_MATCH:
+		return !grep_source_1(opt, gs, 0);
+	default:
+		break;
+	}
 
 	/* Otherwise the toplevel "or" terms hit a bit differently.
 	 * We first clear hit markers from them.
diff --git a/grep.h b/grep.h
index 8e50c95..2cdabf2 100644
--- a/grep.h
+++ b/grep.h
@@ -101,8 +101,9 @@ struct grep_opt {
 	int count;
 	int word_regexp;
 	int fixed;
-	int all_match;
-	int none_match;
+#define GREP_ALL_MATCH 1
+#define GREP_NONE_MATCH 2
+	int all_or_none;
 	int debug;
 #define GREP_BINARY_DEFAULT	0
 #define GREP_BINARY_NOMATCH	1
diff --git a/revision.c b/revision.c
index d43779e..b955848 100644
--- a/revision.c
+++ b/revision.c
@@ -2010,9 +2010,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (!strcmp(arg, "--perl-regexp")) {
 		grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
 	} else if (!strcmp(arg, "--all-match")) {
-		revs->grep_filter.all_match = 1;
+		revs->grep_filter.all_or_none = GREP_ALL_MATCH;
 	} else if (!strcmp(arg, "--none-match")) {
-		revs->grep_filter.none_match = 1;
+		revs->grep_filter.all_or_none = GREP_NONE_MATCH;
 	} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
 		if (strcmp(optarg, "none"))
 			git_log_output_encoding = xstrdup(optarg);
@@ -2335,8 +2335,6 @@ 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;
 }

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

* Re: [PATCH] git-log: added --none-match option
  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  1:39       ` [PATCH v2] " Christoph Junghans
  2015-01-13  1:33       ` [PATCH v2] log: teach --invert-grep option Christoph Junghans
  2 siblings, 1 reply; 15+ messages in thread
From: Christoph Junghans @ 2015-01-09 22:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

2015-01-06 16:02 GMT-07:00 Junio C Hamano <gitster@pobox.com>:
> Christoph Junghans <ottxor@gentoo.org> writes:
>
>> 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>
>> ---
>
> The patch itself looks like a good start, except that the above
> description no longer matches the implementation.
>
> I further suspect it would be better to rename all_match to
> all_or_none and then you can lose the "these two are mutually
> incompatible" check that is placed together with a wrong existing
> comment.  I also notice that you forgot to update the "git grep"
> where the original "--all-match" came from.
That was on purpose. I am not quite sure what would be the point of
"showing only matches from files that match no patterns" (option
description from your patch below).
If a file matches none of the patterns, what matches are there to show?

The only useful thing I could image is using it in conjunction with
--files-with-matches, but that is what --files-without-match is for.

>
> A partial fix-up may start like this on top of your version.  By
> renaming the variable used in the existing code, the compiler will
> remind you that there are a few more places that your patch did not
> touch that does something special for --all-match, which are a good
> candidates you need to think if doing something similarly special
> for the --none-match case is necessary.
>
> Thanks.
>
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 4063882..9ba4254 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -727,8 +727,12 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>                   close_callback },
>                 OPT__QUIET(&opt.status_only,
>                            N_("indicate hit with exit status without output")),
> -               OPT_BOOL(0, "all-match", &opt.all_match,
> -                       N_("show only matches from files that match all patterns")),
> +               OPT_SET_INT(0, "all-match", &opt.all_or_none,
> +                           N_("show only matches from files that match all patterns"),
> +                           GREP_ALL_MATCH),
> +               OPT_SET_INT(0, "none-match", &opt.all_or_none,
> +                           N_("show only matches from files that match no patterns"),
> +                           GREP_NONE_MATCH),
>                 { OPTION_SET_INT, 0, "debug", &opt.debug, NULL,
>                   N_("show parse tree for grep expression"),
>                   PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },
> diff --git a/grep.c b/grep.c
> index f486ee5..1ff5dea 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1622,14 +1622,18 @@ 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".
> +        * buffer-wide "all-match" or "none-match".
>          */
> -       if (!opt->all_match)
> +       switch (opt->all_or_none) {
> +       case GREP_ALL_MATCH:
>                 return grep_source_1(opt, gs, 0);
> +       case GREP_NONE_MATCH:
> +               return !grep_source_1(opt, gs, 0);
> +       default:
> +               break;
> +       }
>
>         /* Otherwise the toplevel "or" terms hit a bit differently.
>          * We first clear hit markers from them.
> diff --git a/grep.h b/grep.h
> index 8e50c95..2cdabf2 100644
> --- a/grep.h
> +++ b/grep.h
> @@ -101,8 +101,9 @@ struct grep_opt {
>         int count;
>         int word_regexp;
>         int fixed;
> -       int all_match;
> -       int none_match;
> +#define GREP_ALL_MATCH 1
> +#define GREP_NONE_MATCH 2
> +       int all_or_none;
>         int debug;
>  #define GREP_BINARY_DEFAULT    0
>  #define GREP_BINARY_NOMATCH    1
> diff --git a/revision.c b/revision.c
> index d43779e..b955848 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2010,9 +2010,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
>         } else if (!strcmp(arg, "--perl-regexp")) {
>                 grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
>         } else if (!strcmp(arg, "--all-match")) {
> -               revs->grep_filter.all_match = 1;
> +               revs->grep_filter.all_or_none = GREP_ALL_MATCH;
>         } else if (!strcmp(arg, "--none-match")) {
> -               revs->grep_filter.none_match = 1;
> +               revs->grep_filter.all_or_none = GREP_NONE_MATCH;
>         } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
>                 if (strcmp(optarg, "none"))
>                         git_log_output_encoding = xstrdup(optarg);
> @@ -2335,8 +2335,6 @@ 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;
>  }
>
>
>



-- 
Christoph Junghans
http://dev.gentoo.org/~ottxor/

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

* Re: [PATCH] git-log: added --none-match option
  2015-01-09 22:33       ` Christoph Junghans
@ 2015-01-09 22:55         ` Junio C Hamano
  2015-01-12 20:51           ` Junio C Hamano
  0 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2015-01-09 22:55 UTC (permalink / raw)
  To: Christoph Junghans; +Cc: git

Christoph Junghans <ottxor@gentoo.org> writes:

> The only useful thing I could image is using it in conjunction with
> --files-with-matches, but that is what --files-without-match is for.

Yes, "-l" was exactly what I had in mind and I was hoping that "git
grep -l --no-match -e WIP -e TODO -e FIXME -e NEEDSWORK" may be a
way to find perfect files without needing any work.

You can say "git grep -L -e WIP -e TODO -e FIXME -e NEEDSWORK"
instead.  I missed that "-L" option.

Thanks.

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

* [PATCH v2] git-log: added --none-match option
  2015-01-06 23:02     ` Junio C Hamano
  2015-01-09 22:33       ` Christoph Junghans
@ 2015-01-12  1:39       ` Christoph Junghans
  2015-01-13  1:33       ` [PATCH v2] log: teach --invert-grep option Christoph Junghans
  2 siblings, 0 replies; 15+ messages in thread
From: Christoph Junghans @ 2015-01-12  1:39 UTC (permalink / raw)
  To: gitster; +Cc: git, Christoph Junghans

Implements a none match for git log, which is useful from time to
time to e.g. filter FIXUP message out of git log.

Internally, the bol 'all_match' was changed to an int 'all_or_none'
taken the values 0, GREP_ALL_MATCH or GREP_NONE_MATCH.

For git grep a similar functionality can achieved by the existing
--files-without-match option.

Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
---
 Documentation/rev-list-options.txt     |  4 ++++
 builtin/grep.c                         |  5 +++--
 contrib/completion/git-completion.bash |  2 +-
 gitk-git/gitk                          |  1 +
 grep.c                                 | 24 ++++++++++++++++++------
 grep.h                                 |  4 +++-
 revision.c                             |  4 +++-
 7 files changed, 33 insertions(+), 11 deletions(-)

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/builtin/grep.c b/builtin/grep.c
index 4063882..1ec8ce1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -727,8 +727,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		  close_callback },
 		OPT__QUIET(&opt.status_only,
 			   N_("indicate hit with exit status without output")),
-		OPT_BOOL(0, "all-match", &opt.all_match,
-			N_("show only matches from files that match all patterns")),
+		OPT_SET_INT(0, "all-match", &opt.all_or_none,
+			    N_("show only matches from files that match all patterns"),
+			    GREP_ALL_MATCH),
 		{ OPTION_SET_INT, 0, "debug", &opt.debug, NULL,
 		  N_("show parse tree for grep expression"),
 		  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index cd76579..47ed970 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/gitk-git/gitk b/gitk-git/gitk
index 78358a7..c67674f 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -3977,6 +3977,7 @@ set known_view_options {
     {committer t15  .  "--committer=*"  {mc "Committer:"}}
     {loginfo   t15  .. "--grep=*"       {mc "Commit Message:"}}
     {allmatch  b    .. "--all-match"    {mc "Matches all Commit Info criteria"}}
+    {nonematch b    .. "--none-match"   {mc "Matches none Commit Info criteria"}}
     {changes_l l    +  {}               {mc "Changes to Files:"}}
     {pickaxe_s r0   .  {}               {mc "Fixed String"}}
     {pickaxe_t r1   .  "--pickaxe-regex"  {mc "Regular Expression"}}
diff --git a/grep.c b/grep.c
index 6e085f8..f6eb044 100644
--- a/grep.c
+++ b/grep.c
@@ -609,8 +609,14 @@ static void dump_grep_expression(struct grep_opt *opt)
 {
 	struct grep_expr *x = opt->pattern_expression;
 
-	if (opt->all_match)
+	switch (opt->all_or_none) {
+	case GREP_ALL_MATCH:
 		fprintf(stderr, "[all-match]\n");
+	case GREP_NONE_MATCH:
+		fprintf(stderr, "[none-match]\n");
+	default:
+		break;
+	}
 	dump_grep_expression_1(x, 0);
 	fflush(NULL);
 }
@@ -713,7 +719,7 @@ static void compile_grep_patterns_real(struct grep_opt *opt)
 		}
 	}
 
-	if (opt->all_match || header_expr)
+	if ((opt->all_or_none == GREP_ALL_MATCH) || header_expr)
 		opt->extended = 1;
 	else if (!opt->extended && !opt->debug)
 		return;
@@ -729,13 +735,13 @@ static void compile_grep_patterns_real(struct grep_opt *opt)
 
 	if (!opt->pattern_expression)
 		opt->pattern_expression = header_expr;
-	else if (opt->all_match)
+	else if (opt->all_or_none == GREP_ALL_MATCH)
 		opt->pattern_expression = grep_splice_or(header_expr,
 							 opt->pattern_expression);
 	else
 		opt->pattern_expression = grep_or_expr(opt->pattern_expression,
 						       header_expr);
-	opt->all_match = 1;
+	opt->all_or_none = GREP_ALL_MATCH;
 }
 
 void compile_grep_patterns(struct grep_opt *opt)
@@ -1624,10 +1630,16 @@ int grep_source(struct grep_opt *opt, struct grep_source *gs)
 {
 	/*
 	 * we do not have to do the two-pass grep when we do not check
-	 * buffer-wide "all-match".
+	 * buffer-wide "all-match" or check "none-match".
 	 */
-	if (!opt->all_match)
+	switch (opt->all_or_none) {
+	case GREP_NONE_MATCH:
+		return !grep_source_1(opt, gs, 0);
+	case GREP_ALL_MATCH:
+		break;
+	default:
 		return grep_source_1(opt, gs, 0);
+	}
 
 	/* Otherwise the toplevel "or" terms hit a bit differently.
 	 * We first clear hit markers from them.
diff --git a/grep.h b/grep.h
index 95f197a..2cdabf2 100644
--- a/grep.h
+++ b/grep.h
@@ -101,7 +101,9 @@ struct grep_opt {
 	int count;
 	int word_regexp;
 	int fixed;
-	int all_match;
+#define GREP_ALL_MATCH 1
+#define GREP_NONE_MATCH 2
+	int all_or_none;
 	int debug;
 #define GREP_BINARY_DEFAULT	0
 #define GREP_BINARY_NOMATCH	1
diff --git a/revision.c b/revision.c
index 14e0e03..723b495 100644
--- a/revision.c
+++ b/revision.c
@@ -2010,7 +2010,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (!strcmp(arg, "--perl-regexp")) {
 		grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
 	} else if (!strcmp(arg, "--all-match")) {
-		revs->grep_filter.all_match = 1;
+		revs->grep_filter.all_or_none = GREP_ALL_MATCH;
+	} else if (!strcmp(arg, "--none-match")) {
+		revs->grep_filter.all_or_none = GREP_NONE_MATCH;
 	} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
 		if (strcmp(optarg, "none"))
 			git_log_output_encoding = xstrdup(optarg);
-- 
2.0.5

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

* Re: [PATCH] git-log: added --none-match option
  2015-01-09 22:55         ` Junio C Hamano
@ 2015-01-12 20:51           ` Junio C Hamano
  0 siblings, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2015-01-12 20:51 UTC (permalink / raw)
  To: Christoph Junghans; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Christoph Junghans <ottxor@gentoo.org> writes:
>
>> The only useful thing I could image is using it in conjunction with
>> --files-with-matches, but that is what --files-without-match is for.
>
> Yes, "-l" was exactly what I had in mind and I was hoping that "git
> grep -l --no-match -e WIP -e TODO -e FIXME -e NEEDSWORK" may be a
> way to find perfect files without needing any work.
>
> You can say "git grep -L -e WIP -e TODO -e FIXME -e NEEDSWORK"
> instead.  I missed that "-L" option.

Thanks for your patience.  I should have realized that this not only
can be "log-only" but _should_ be "log-only".  As you pointed out,
when we already have "-L", trying to extend it to "grep" does not
make much sense.

Continuing this line of thought, as we determined that it is
pointless to have this at "grep" level and it is needed only in the
"log" family of commands, I would very much prefer the approach
taken by your original "log --invert-grep" patch.  I would further
say that I prefer not to touch grep_opt at all.

The new "global-invert bit" is about "we'd run the usual grep thing
on the log message, and instead of filtering to only show the
commits with matching message, we only show the ones with messages
that do not match".  That logically belongs to the revision struct
that is used to interpret what the underlying grep machinery figured
out, and should not have to affect the way how underlying grep
machinery works.

We would want a few test to make sure that we do not break the
feature in the future changes.  Here is an attempt.  The patch would
apply any commit your original "--invert-grep" option would have
applied.

Thanks again.

-- >8 --
Subject: log: teach --invert-grep option

"git log --grep=<string>" shows only commits with messages that
match the given string, but sometimes it is useful to be able to
show only commits that do *not* have certain messages (e.g. "show me
ones that are not FIXUP commits").

Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 jc: Christoph originally had the invert-grep flag in grep_opt, but
     because "git grep --invert-grep" does not make sense except in
     conjunction with "--files-with-matches", which is already
     covered by "--files-without-matches", I moved it to revisions
     structure.  I think it expresses what the feature is about
     better to have the flag there.

     When the newly inserted two tests run, the history would have
     commits with messages "initial", "second", "third", "fourth",
     "fifth", "sixth" and Second", committed in this order.  The
     first commit that does not match either "th" or "Sec" is
     "second", and "initial" is the one that does not match either
     "th" or "Sec" case insensitively.

 Documentation/rev-list-options.txt     |  4 ++++
 contrib/completion/git-completion.bash |  2 +-
 revision.c                             |  4 +++-
 revision.h                             |  2 ++
 t/t4202-log.sh                         | 12 ++++++++++++
 5 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index deb8cca..05aa997 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 06bf262..53857f0 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 615535c..84b33a3 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 a620530..b0b82e7 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 99ab7ca..1c9934e 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -212,6 +212,18 @@ test_expect_success 'log --grep' '
 	test_cmp expect actual
 '
 
+test_expect_success 'log --invert-grep --grep' '
+	echo second >expect &&
+	git log -1 --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 -1 --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 &&

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

* [PATCH v2] log: teach --invert-grep option
  2015-01-06 23:02     ` Junio C Hamano
  2015-01-09 22:33       ` Christoph Junghans
  2015-01-12  1:39       ` [PATCH v2] " Christoph Junghans
@ 2015-01-13  1:33       ` 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
  2 siblings, 2 replies; 15+ messages in thread
From: Christoph Junghans @ 2015-01-13  1:33 UTC (permalink / raw)
  To: gitster; +Cc: git, Christoph Junghans

"git log --grep=<string>" shows only commits with messages that
match the given string, but sometimes it is useful to be able to
show only commits that do *not* have certain messages (e.g. "show
me ones that are not FIXUP commits").

Originally, we had the invert-grep flag in grep_opt, but because
"git grep --invert-grep" does not make sense except in conjunction
with "--files-with-matches", which is already covered by
"--files-without-matches", it was moved it to revisions structure.
To have the flag there expresses the function to the feature better.

When the newly inserted two tests run, the history would have commits
with messages "initial", "second", "third", "fourth", "fifth", "sixth"
and "Second", committed in this order.  The commits that does not match
either "th" or "Sec" is "second" and "initial". For the case insensitive
case only "initial" matches.

Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
---
 Documentation/rev-list-options.txt     |  4 ++++
 contrib/completion/git-completion.bash |  2 +-
 gitk-git/gitk                          |  1 +
 revision.c                             |  4 +++-
 revision.h                             |  2 ++
 t/t4202-log.sh                         | 15 +++++++++++++++
 6 files changed, 26 insertions(+), 2 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 cd76579..aaeac50 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/gitk-git/gitk b/gitk-git/gitk
index 78358a7..5a78432 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -3977,6 +3977,7 @@ set known_view_options {
     {committer t15  .  "--committer=*"  {mc "Committer:"}}
     {loginfo   t15  .. "--grep=*"       {mc "Commit Message:"}}
     {allmatch  b    .. "--all-match"    {mc "Matches all Commit Info criteria"}}
+    {igrep     b    .. "--invert-grep"  {mc "Matches none Commit Info criteria"}}
     {changes_l l    +  {}               {mc "Changes to Files:"}}
     {pickaxe_s r0   .  {}               {mc "Fixed String"}}
     {pickaxe_t r1   .  "--pickaxe-regex"  {mc "Regular Expression"}}
diff --git a/revision.c b/revision.c
index 14e0e03..4d03338 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->invert_grep = 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->invert_grep ? !retval : retval;
 }
 
 static inline int want_ancestry(const struct rev_info *revs)
diff --git a/revision.h b/revision.h
index 9cb5adc..bc27098 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 99ab7ca..5f2b290 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 &&
-- 
2.0.5

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

* Re: [PATCH v2] log: teach --invert-grep option
  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
  1 sibling, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2015-01-13 18:25 UTC (permalink / raw)
  To: Christoph Junghans; +Cc: git

Christoph Junghans <ottxor@gentoo.org> writes:

> "git log --grep=<string>" shows only commits with messages that
> match the given string, but sometimes it is useful to be able to
> show only commits that do *not* have certain messages (e.g. "show
> me ones that are not FIXUP commits").
>
> Originally, we had the invert-grep flag in grep_opt, but because
> "git grep --invert-grep" does not make sense except in conjunction
> with "--files-with-matches", which is already covered by
> "--files-without-matches", it was moved it to revisions structure.
> To have the flag there expresses the function to the feature better.
>
> When the newly inserted two tests run, the history would have commits
> with messages "initial", "second", "third", "fourth", "fifth", "sixth"
> and "Second", committed in this order.  The commits that does not match
> either "th" or "Sec" is "second" and "initial". For the case insensitive
> case only "initial" matches.

I see you moved the two bits meant only to be useful during the
review to the commit message proper.  The reason why I omitted the
"Originally, ..." part was because those who are reading "git log
-p" output would not know what the earlier draft had.

I do not mind it either way, though, so let's take this version.

However, I'd have to drop gitk-git/ bit; that part of the tree is
maintained separately and comes from Paul's gitk repository.  I'll
forward only that part of the patch to him when this feature
graduates to 'master'.

Thanks.

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

* [PATCH] gitk: pass --invert-grep option down to "git log"
  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         ` Junio C Hamano
  2015-03-22  3:39           ` Paul Mackerras
  1 sibling, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2015-02-16  7:29 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git, Christoph Junghans

From: Christoph Junghans <ottxor@gentoo.org>
Date: Mon, 12 Jan 2015 18:33:32 -0700

"git log --grep=<string>" shows only commits with messages that
match the given string, but sometimes it is useful to be able to
show only commits that do *not* have certain messages (e.g. "show
me ones that are not FIXUP commits").

Now the underlying "git log" learned the "--invert-grep" option.
The option syntactically behaves similar to "--all-match" that
requires that all of the grep strings to match and semantically
behaves the opposite---it requires that none of the grep strings to
match.

Teach "gitk" to allow users to pass it down to underlying "git log"
command by adding it to the known_view_options array.

Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * Split from Christoph's original patch ($gmane/262313).

 gitk | 1 +
 1 file changed, 1 insertion(+)

diff --git b/gitk a/gitk
index 3520bda..a95a93f 100755
--- b/gitk
+++ a/gitk
@@ -4036,6 +4036,7 @@ set known_view_options {
     {committer t15  .  "--committer=*"  {mc "Committer:"}}
     {loginfo   t15  .. "--grep=*"       {mc "Commit Message:"}}
     {allmatch  b    .. "--all-match"    {mc "Matches all Commit Info criteria"}}
+    {igrep     b    .. "--invert-grep"  {mc "Matches none Commit Info criteria"}}
     {changes_l l    +  {}               {mc "Changes to Files:"}}
     {pickaxe_s r0   .  {}               {mc "Fixed String"}}
     {pickaxe_t r1   .  "--pickaxe-regex"  {mc "Regular Expression"}}

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

* Re: [PATCH] gitk: pass --invert-grep option down to "git log"
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Paul Mackerras @ 2015-03-22  3:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Christoph Junghans

On Sun, Feb 15, 2015 at 11:29:10PM -0800, Junio C Hamano wrote:
> From: Christoph Junghans <ottxor@gentoo.org>
> Date: Mon, 12 Jan 2015 18:33:32 -0700
> 
> "git log --grep=<string>" shows only commits with messages that
> match the given string, but sometimes it is useful to be able to
> show only commits that do *not* have certain messages (e.g. "show
> me ones that are not FIXUP commits").
> 
> Now the underlying "git log" learned the "--invert-grep" option.
> The option syntactically behaves similar to "--all-match" that
> requires that all of the grep strings to match and semantically
> behaves the opposite---it requires that none of the grep strings to
> match.
> 
> Teach "gitk" to allow users to pass it down to underlying "git log"
> command by adding it to the known_view_options array.
> 
> Signed-off-by: Christoph Junghans <ottxor@gentoo.org>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thanks, applied.

Paul.

^ permalink raw reply	[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.