Skip to content

Commit baa6378

Browse files
committed
log --grep-reflog: reject the option without -g
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72fd13f commit baa6378

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

Documentation/rev-list-options.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ endif::git-rev-list[]
5656
Limit the commits output to ones with reflog entries that
5757
match the specified pattern (regular expression). With
5858
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.
6161

6262
--grep=<pattern>::
6363

grep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void append_header_grep_pattern(struct grep_opt *opt,
6464
{
6565
struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
6666
GREP_PATTERN_HEAD, field);
67+
if (field == GREP_HEADER_REFLOG)
68+
opt->use_reflog_filter = 1;
6769
do_append_grep_pat(&opt->header_tail, p);
6870
}
6971

grep.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct grep_opt {
107107
#define GREP_BINARY_TEXT 2
108108
int binary;
109109
int extended;
110+
int use_reflog_filter;
110111
int pcre;
111112
int relative;
112113
int pathname;

revision.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
19081908

19091909
if (revs->reflog_info && revs->graph)
19101910
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");
19111913

19121914
return left;
19131915
}
@@ -2217,12 +2219,19 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
22172219
struct strbuf buf = STRBUF_INIT;
22182220
if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list)
22192221
return 1;
2220-
if (opt->reflog_info) {
2222+
2223+
/* Prepend "fake" headers as needed */
2224+
if (opt->grep_filter.use_reflog_filter) {
22212225
strbuf_addstr(&buf, "reflog ");
22222226
get_reflog_message(&buf, opt->reflog_info);
22232227
strbuf_addch(&buf, '\n');
2224-
strbuf_addstr(&buf, commit->buffer);
22252228
}
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 */
22262235
if (buf.len)
22272236
retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
22282237
else

t/t7810-grep.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ test_expect_success 'log grep (9)' '
572572
test_cmp expect actual
573573
'
574574

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+
575579
test_expect_success 'log with multiple --grep uses union' '
576580
git log --grep=i --grep=r --format=%s >actual &&
577581
{

0 commit comments

Comments
 (0)