revision traversal: --author, --committer, and --grep.
This adds three options to setup_revisions(), which lets you filter resulting commits by the author name, the committer name and the log message with regexp. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 17, 2006 at 17:23 UTC
bd95fcd34543d7d98bff033c00054341165bc9ce
2 files changed
+86
-1
Documentation/git-rev-list.txt
+11
@@ -20,6 +20,7 @@ SYNOPSIS
20
[ \--stdin ]
21
[ \--topo-order ]
22
[ \--parents ]
23
+ [ \--(author|committer|grep)=<pattern> ]
24
[ [\--objects | \--objects-edge] [ \--unpacked ] ]
25
[ \--pretty | \--header ]
26
[ \--bisect ]
@@ -154,6 +155,16 @@ limiting may be applied.
155
156
Limit the commits output to specified time range.
157
158
+--author='pattern', --committer='pattern'::
159
+
160
+ Limit the commits output to ones with author/committer
161
+ header lines that match the specified pattern.
162
+
163
+--grep='pattern'::
164
+
165
+ Limit the commits output to ones with log message that
166
+ matches the specified pattern.
167
+
168
--remove-empty::
169
170
Stop when a given path disappears from the tree.
revision.c
+75
-1
@@ -674,6 +674,40 @@ 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)
678
+{
679
+ char *pat;
680
+ int patlen, fldlen;
681
+
682
+ if (!revs->header_filter) {
683
+ struct grep_opt *opt = xcalloc(1, sizeof(*opt));
684
+ opt->status_only = 1;
685
+ opt->pattern_tail = &(opt->pattern_list);
686
+ opt->regflags = REG_NEWLINE;
687
+ revs->header_filter = opt;
688
+ }
689
+
690
+ fldlen = strlen(field);
691
+ patlen = strlen(pattern);
692
+ pat = xmalloc(patlen + fldlen + 3);
693
+ sprintf(pat, "^%s %s", field, pattern);
694
+ append_grep_pattern(revs->header_filter, pat,
695
+ "command line", 0, GREP_PATTERN);
696
+}
697
+
698
+static void add_message_grep(struct rev_info *revs, const char *pattern)
699
+{
700
+ if (!revs->message_filter) {
701
+ struct grep_opt *opt = xcalloc(1, sizeof(*opt));
702
+ opt->status_only = 1;
703
+ opt->pattern_tail = &(opt->pattern_list);
704
+ opt->regflags = REG_NEWLINE;
705
+ revs->message_filter = opt;
706
+ }
707
+ append_grep_pattern(revs->message_filter, pattern,
708
+ "command line", 0, GREP_PATTERN);
709
+}
710
+
711
static void add_ignore_packed(struct rev_info *revs, const char *name)
712
{
713
int num = ++revs->num_ignore_packed;
@@ -915,6 +949,18 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
949
revs->relative_date = 1;
950
continue;
951
}
952
+ if (!strncmp(arg, "--author=", 9)) {
953
+ add_header_grep(revs, "author", arg+9);
954
+ continue;
955
+ }
956
+ if (!strncmp(arg, "--committer=", 12)) {
957
+ add_header_grep(revs, "committer", arg+12);
958
+ continue;
959
+ }
960
+ if (!strncmp(arg, "--grep=", 7)) {
961
+ add_message_grep(revs, arg+7);
962
+ continue;
963
+ }
964
opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
965
if (opts > 0) {
966
revs->diff = 1;
@@ -975,6 +1021,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1021
if (diff_setup_done(&revs->diffopt) < 0)
1022
die("diff_setup_done failed");
1023
1024
+ if (revs->header_filter)
1025
+ compile_grep_patterns(revs->header_filter);
1026
+ if (revs->message_filter)
1027
+ compile_grep_patterns(revs->message_filter);
1028
+
1029
return left;
1030
}
1031
@@ -1049,10 +1100,33 @@ static void mark_boundary_to_show(struct commit *commit)
1100
1101
static int commit_match(struct commit *commit, struct rev_info *opt)
1102
{
1103
+ char *header, *message;
1104
+ unsigned long header_len, message_len;
1105
+
1106
if (!opt->header_filter && !opt->message_filter)
1107
return 1;
1108
1055
- /* match it here */
1109
+ header = commit->buffer;
1110
+ message = strstr(header, "\n\n");
1111
+ if (message) {
1112
+ message += 2;
1113
+ header_len = message - header - 1;
1114
+ message_len = strlen(message);
1115
+ }
1116
+ else {
1117
+ header_len = strlen(header);
1118
+ message = header;
1119
+ message_len = 0;
1120
+ }
1121
+
1122
+ if (opt->header_filter &&
1123
+ !grep_buffer(opt->header_filter, NULL, header, header_len))
1124
+ return 0;
1125
+
1126
+ if (opt->message_filter &&
1127
+ !grep_buffer(opt->message_filter, NULL, message, message_len))
1128
+ return 0;
1129
+
1130
return 1;
1131
}
1132