log --grep-reflog: reject the option without -g
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
72fd13f71c
commit
baa6378ff2
@ -56,8 +56,8 @@ endif::git-rev-list[]
|
|||||||
Limit the commits output to ones with reflog entries that
|
Limit the commits output to ones with reflog entries that
|
||||||
match the specified pattern (regular expression). With
|
match the specified pattern (regular expression). With
|
||||||
more than one `--grep-reflog`, commits whose reflog message
|
more than one `--grep-reflog`, commits whose reflog message
|
||||||
matches any of the given patterns are chosen. Ignored unless
|
matches any of the given patterns are chosen. It is an
|
||||||
`--walk-reflogs` is given.
|
error to use this option unless `--walk-reflogs` is in use.
|
||||||
|
|
||||||
--grep=<pattern>::
|
--grep=<pattern>::
|
||||||
|
|
||||||
|
2
grep.c
2
grep.c
@ -64,6 +64,8 @@ void append_header_grep_pattern(struct grep_opt *opt,
|
|||||||
{
|
{
|
||||||
struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
|
struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
|
||||||
GREP_PATTERN_HEAD, field);
|
GREP_PATTERN_HEAD, field);
|
||||||
|
if (field == GREP_HEADER_REFLOG)
|
||||||
|
opt->use_reflog_filter = 1;
|
||||||
do_append_grep_pat(&opt->header_tail, p);
|
do_append_grep_pat(&opt->header_tail, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
grep.h
1
grep.h
@ -107,6 +107,7 @@ struct grep_opt {
|
|||||||
#define GREP_BINARY_TEXT 2
|
#define GREP_BINARY_TEXT 2
|
||||||
int binary;
|
int binary;
|
||||||
int extended;
|
int extended;
|
||||||
|
int use_reflog_filter;
|
||||||
int pcre;
|
int pcre;
|
||||||
int relative;
|
int relative;
|
||||||
int pathname;
|
int pathname;
|
||||||
|
13
revision.c
13
revision.c
@ -1908,6 +1908,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
|
|||||||
|
|
||||||
if (revs->reflog_info && revs->graph)
|
if (revs->reflog_info && revs->graph)
|
||||||
die("cannot combine --walk-reflogs with --graph");
|
die("cannot combine --walk-reflogs with --graph");
|
||||||
|
if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)
|
||||||
|
die("cannot use --grep-reflog without --walk-reflogs");
|
||||||
|
|
||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
@ -2217,12 +2219,19 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
|
|||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list)
|
if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list)
|
||||||
return 1;
|
return 1;
|
||||||
if (opt->reflog_info) {
|
|
||||||
|
/* Prepend "fake" headers as needed */
|
||||||
|
if (opt->grep_filter.use_reflog_filter) {
|
||||||
strbuf_addstr(&buf, "reflog ");
|
strbuf_addstr(&buf, "reflog ");
|
||||||
get_reflog_message(&buf, opt->reflog_info);
|
get_reflog_message(&buf, opt->reflog_info);
|
||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
strbuf_addstr(&buf, commit->buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy the commit to temporary if we are using "fake" headers */
|
||||||
|
if (buf.len)
|
||||||
|
strbuf_addstr(&buf, commit->buffer);
|
||||||
|
|
||||||
|
/* Find either in the commit object, or in the temporary */
|
||||||
if (buf.len)
|
if (buf.len)
|
||||||
retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
|
retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
|
||||||
else
|
else
|
||||||
|
@ -572,6 +572,10 @@ test_expect_success 'log grep (9)' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'log --grep-reflog can only be used under -g' '
|
||||||
|
test_must_fail git log --grep-reflog="commit: third"
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'log with multiple --grep uses union' '
|
test_expect_success 'log with multiple --grep uses union' '
|
||||||
git log --grep=i --grep=r --format=%s >actual &&
|
git log --grep=i --grep=r --format=%s >actual &&
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user