log --grep-reflog: reject the option without -g

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 29, 2012 at 11:59 UTC baa6378ff2106738c74213280904507d0ed8129c
5 files changed +20 -4
Documentation/rev-list-options.txt
+2 -2
@@ -56,8 +56,8 @@ endif::git-rev-list[]
56 Limit the commits output to ones with reflog entries that
57 match the specified pattern (regular expression). With
58 more than one `--grep-reflog`, commits whose reflog message
59 - matches any of the given patterns are chosen. Ignored unless
60 - `--walk-reflogs` is given.
59 + matches any of the given patterns are chosen. It is an
60 + error to use this option unless `--walk-reflogs` is in use.
61
62 --grep=<pattern>::
63
grep.c
+2
@@ -64,6 +64,8 @@ void append_header_grep_pattern(struct grep_opt *opt,
64 {
65 struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
66 GREP_PATTERN_HEAD, field);
67 + if (field == GREP_HEADER_REFLOG)
68 + opt->use_reflog_filter = 1;
69 do_append_grep_pat(&opt->header_tail, p);
70 }
71
grep.h
+1
@@ -107,6 +107,7 @@ struct grep_opt {
107 #define GREP_BINARY_TEXT 2
108 int binary;
109 int extended;
110 + int use_reflog_filter;
111 int pcre;
112 int relative;
113 int pathname;
revision.c
+11 -2
@@ -1908,6 +1908,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
1908
1909 if (revs->reflog_info && revs->graph)
1910 die("cannot combine --walk-reflogs with --graph");
1911 + if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)
1912 + die("cannot use --grep-reflog without --walk-reflogs");
1913
1914 return left;
1915 }
@@ -2217,12 +2219,19 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
2219 struct strbuf buf = STRBUF_INIT;
2220 if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list)
2221 return 1;
2220 - if (opt->reflog_info) {
2222 +
2223 + /* Prepend "fake" headers as needed */
2224 + if (opt->grep_filter.use_reflog_filter) {
2225 strbuf_addstr(&buf, "reflog ");
2226 get_reflog_message(&buf, opt->reflog_info);
2227 strbuf_addch(&buf, '\n');
2224 - strbuf_addstr(&buf, commit->buffer);
2228 }
2229 +
2230 + /* Copy the commit to temporary if we are using "fake" headers */
2231 + if (buf.len)
2232 + strbuf_addstr(&buf, commit->buffer);
2233 +
2234 + /* Find either in the commit object, or in the temporary */
2235 if (buf.len)
2236 retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
2237 else
t/t7810-grep.sh
+4
@@ -572,6 +572,10 @@ test_expect_success 'log grep (9)' '
572 test_cmp expect actual
573 '
574
575 +test_expect_success 'log --grep-reflog can only be used under -g' '
576 + test_must_fail git log --grep-reflog="commit: third"
577 +'
578 +
579 test_expect_success 'log with multiple --grep uses union' '
580 git log --grep=i --grep=r --format=%s >actual &&
581 {