git-log: added --invert-grep option
PATCH 1/1 git-log: added --invert-grep option
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.
--- 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(-)
Documentation/rev-list-options.txt +4 -0
@@ -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
contrib/completion/git-completion.bash +1 -1
@@ -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:"
grep.h +2 -1
@@ -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;
revision.c +3 -1
@@ -2011,6 +2011,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arggrep_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)
Signature · 1 line
2.0.4
Quoted 7 lines · 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 asrevs->grep_filter.invertinverts 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-endby 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?
Quoted 72 lines
Signed-off-by Christoph Junghans <[email protected]>--- 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(-)Documentation/rev-list-options.txt +4
-0@@ -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 lettercontrib/completion/git-completion.bash +1
-1@@ -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:"grep.h +2
-1@@ -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;revision.c +3
-1@@ -2011,6 +2011,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arggrep_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)
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?
PATCH 1/1 git-log: added --grep-begin .. --grep-end syntax
This is useful to specify more complicated pattern as with '--grep'.
--- builtin/grep.c | 73 +++++----------------------------------------------------- grep.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ grep.h | 10 ++++++++ revision.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 67 deletions(-)
builtin/grep.c +6 -67
@@ -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,
grep.c +62 -0
65 lines not on this page · raw message
grep.h +10 -0
@@ -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);
revision.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.0.5
Quoted 2 lines · Christoph Junghans
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 ;-).
Quoted 2 lines
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.
PATCH 1/1 git-log: added --none-match option
In reply to Junio C HamanoImplements 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.
--- 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(-)
Documentation/rev-list-options.txt +4 -0
@@ -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
contrib/completion/git-completion.bash +1 -1
@@ -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:"
grep.c +2 -0
@@ -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".
grep.h +1 -0
@@ -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
revision.c +4 -0
@@ -2011,6 +2011,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arggrep_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 sdie ("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; }
Signature · 1 line
2.0.5
Re: [PATCH] git-log: added --none-match option
Quoted 10 lines · 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 asrevs->grep_filter.invertinverts the match line-wise, which cannot work as i.e. empty line always not match the pattern given.Signed-off-by Christoph Junghans <[email protected]>---
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.
builtin/grep.c +6 -2
@@ -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 },
grep.c +8 -4
@@ -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.
grep.h +3 -2
@@ -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
revision.c +2 -4
@@ -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 sdie ("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; }
Re: [PATCH] git-log: added --none-match option
2015-01-06 16:02 GMT-07:00 Junio C Hamano <[email protected]>:
Quoted 13 lines
Quoted 10 lines · 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 asrevs->grep_filter.invertinverts the match line-wise, which cannot work as i.e. empty line always not match the pattern given.Signed-off-by Christoph Junghans <[email protected]>---
Quoted 8 lines
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_matchtoall_or_noneand 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.
Quoted 100 lines
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.
builtin/grep.c +6
-2@@ -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 },grep.c +8
-4@@ -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. grep.h +3
-2@@ -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 1revision.c +2
-4@@ -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 sdie ("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; }
Signature · 2 lines
Christoph Junghans http://dev.gentoo.org/~ottxor/
Re: [PATCH] git-log: added --none-match option
Quoted 2 lines · Christoph Junghans
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.
Re: [PATCH] git-log: added --none-match option
Quoted 11 lines · Junio C Hamano
Quoted 2 lines · Christoph Junghans
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").
---
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(-)
Documentation/rev-list-options.txt +4 -0
@@ -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
contrib/completion/git-completion.bash +1 -1
@@ -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:"
revision.c +3 -1
@@ -1952,6 +1952,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arggrep_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)
revision.h +2 -0
@@ -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;
t/t4202-log.sh +12 -0
@@ -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 &&
PATCH v2 1/1 git-log: added --none-match option
In reply to Junio C HamanoImplements 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.
--- 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(-)
Documentation/rev-list-options.txt +4 -0
@@ -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
builtin/grep.c +3 -2
@@ -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 },
contrib/completion/git-completion.bash +1 -1
@@ -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:"
gitk-git/gitk +1 -0
@@ -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"}}
grep.c +18 -6
@@ -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.
grep.h +3 -1
@@ -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
revision.c +3 -1
@@ -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);
Signature · 1 line
2.0.5
PATCH v2 1/1 log: teach --invert-grep option
In reply to Junio C Hamano"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.
--- 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(-)
Documentation/rev-list-options.txt +4 -0
@@ -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
contrib/completion/git-completion.bash +1 -1
@@ -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:"
gitk-git/gitk +1 -0
@@ -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"}}
revision.c +3 -1
@@ -2011,6 +2011,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arggrep_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)
revision.h +2 -0
@@ -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;
t/t4202-log.sh +15 -0
@@ -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 &&
Signature · 1 line
2.0.5
Re: [PATCH v2] log: teach --invert-grep option
Quoted 11 lines · 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.
Quoted 5 lines
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.
PATCH 1/1 gitk: pass --invert-grep option down to "git log"
In reply to Christoph JunghansFrom: Christoph Junghans <[email protected]>
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.
---
* Split from Christoph's original patch ($gmane/262313).
gitk | 1 + 1 file changed, 1 insertion(+)
gitk +1 -0
@@ -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"}}
Paul Mackerras
AppliedRe: [PATCH] gitk: pass --invert-grep option down to "git log"
Quoted 14 lines · Junio C Hamano
From: Christoph Junghans <[email protected]>
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.
Quoted 5 lines
Teach "gitk" to allow users to pass it down to underlying "git log" command by adding it to the
known_view_optionsarray.Signed-off-by Christoph Junghans <[email protected]>Signed-off-by Junio C Hamano <[email protected]>
Thanks, applied.
Paul.