git log: Unify header_filter and message_filter into one.
Now we can tell the built-in grep to grep only in head or in body, use that to update --author, --committer, and --grep. Unfortunately, to make --and, --not and other grep boolean expressions useful, as in: # Things written by Junio committed and by Linus and log # does not talk about diff. git log --author=Junio --and --committer=Linus \ --grep-not --grep=diff we will need to do another round of built-in grep core enhancement, because grep boolean expressions are designed to work on one line at a time. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 20, 2006 at 13:21 UTC
2d10c555374df257e32848ba6f77fd73d608645f
3 files changed
+27
-54
builtin-rev-list.c
+1
-3
@@ -269,9 +269,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
269
revs.diff)
270
usage(rev_list_usage);
271
272
- save_commit_buffer = revs.verbose_header ||
273
- revs.header_filter ||
274
- revs.message_filter;
272
+ save_commit_buffer = revs.verbose_header || revs.grep_filter;
273
track_object_refs = 0;
274
if (bisect_list)
275
revs.limited = 1;
revision.c
+25
-49
@@ -674,19 +674,24 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
674
return 0;
675
}
676
677
-static void add_header_grep(struct rev_info *revs, const char *field, const char *pattern)
677
+static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
678
{
679
- char *pat;
680
- const char *prefix;
681
- int patlen, fldlen;
682
-
683
- if (!revs->header_filter) {
679
+ if (!revs->grep_filter) {
680
struct grep_opt *opt = xcalloc(1, sizeof(*opt));
681
opt->status_only = 1;
682
opt->pattern_tail = &(opt->pattern_list);
683
opt->regflags = REG_NEWLINE;
688
- revs->header_filter = opt;
684
+ revs->grep_filter = opt;
685
}
686
+ append_grep_pattern(revs->grep_filter, ptn,
687
+ "command line", 0, what);
688
+}
689
+
690
+static void add_header_grep(struct rev_info *revs, const char *field, const char *pattern)
691
+{
692
+ char *pat;
693
+ const char *prefix;
694
+ int patlen, fldlen;
695
696
fldlen = strlen(field);
697
patlen = strlen(pattern);
@@ -697,21 +702,12 @@ static void add_header_grep(struct rev_info *revs, const char *field, const char
702
pattern++;
703
}
704
sprintf(pat, "^%s %s%s", field, prefix, pattern);
700
- append_grep_pattern(revs->header_filter, pat,
701
- "command line", 0, GREP_PATTERN);
705
+ add_grep(revs, pat, GREP_PATTERN_HEAD);
706
}
707
708
static void add_message_grep(struct rev_info *revs, const char *pattern)
709
{
706
- if (!revs->message_filter) {
707
- struct grep_opt *opt = xcalloc(1, sizeof(*opt));
708
- opt->status_only = 1;
709
- opt->pattern_tail = &(opt->pattern_list);
710
- opt->regflags = REG_NEWLINE;
711
- revs->message_filter = opt;
712
- }
713
- append_grep_pattern(revs->message_filter, pattern,
714
- "command line", 0, GREP_PATTERN);
710
+ add_grep(revs, pattern, GREP_PATTERN_BODY);
711
}
712
713
static void add_ignore_packed(struct rev_info *revs, const char *name)
@@ -955,6 +951,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
951
revs->relative_date = 1;
952
continue;
953
}
954
+
955
+ /*
956
+ * Grepping the commit log
957
+ */
958
if (!strncmp(arg, "--author=", 9)) {
959
add_header_grep(revs, "author", arg+9);
960
continue;
@@ -967,6 +967,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
967
add_message_grep(revs, arg+7);
968
continue;
969
}
970
+
971
opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
972
if (opts > 0) {
973
revs->diff = 1;
@@ -1027,10 +1028,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1028
if (diff_setup_done(&revs->diffopt) < 0)
1029
die("diff_setup_done failed");
1030
1030
- if (revs->header_filter)
1031
- compile_grep_patterns(revs->header_filter);
1032
- if (revs->message_filter)
1033
- compile_grep_patterns(revs->message_filter);
1031
+ if (revs->grep_filter)
1032
+ compile_grep_patterns(revs->grep_filter);
1033
1034
return left;
1035
}
@@ -1106,34 +1105,11 @@ static void mark_boundary_to_show(struct commit *commit)
1105
1106
static int commit_match(struct commit *commit, struct rev_info *opt)
1107
{
1109
- char *header, *message;
1110
- unsigned long header_len, message_len;
1111
-
1112
- if (!opt->header_filter && !opt->message_filter)
1108
+ if (!opt->grep_filter)
1109
return 1;
1114
-
1115
- header = commit->buffer;
1116
- message = strstr(header, "\n\n");
1117
- if (message) {
1118
- message += 2;
1119
- header_len = message - header - 1;
1120
- message_len = strlen(message);
1121
- }
1122
- else {
1123
- header_len = strlen(header);
1124
- message = header;
1125
- message_len = 0;
1126
- }
1127
-
1128
- if (opt->header_filter &&
1129
- !grep_buffer(opt->header_filter, NULL, header, header_len))
1130
- return 0;
1131
-
1132
- if (opt->message_filter &&
1133
- !grep_buffer(opt->message_filter, NULL, message, message_len))
1134
- return 0;
1135
-
1136
- return 1;
1110
+ return grep_buffer(opt->grep_filter,
1111
+ NULL, /* we say nothing, not even filename */
1112
+ commit->buffer, strlen(commit->buffer));
1113
}
1114
1115
struct commit *get_revision(struct rev_info *revs)
revision.h
+1
-2
@@ -72,8 +72,7 @@ struct rev_info {
72
const char *extra_headers;
73
74
/* Filter by commit log message */
75
- struct grep_opt *header_filter;
76
- struct grep_opt *message_filter;
75
+ struct grep_opt *grep_filter;
76
77
/* special limits */
78
int max_count;