revision: add --grep-reflog to filter commits by reflog messages
Similar to --author/--committer which filters commits by author and committer header fields. --grep-reflog adds a fake "reflog" header to commit and a grep filter to search on that line. All rules to --author/--committer apply except no timestamp stripping. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
ad4813b3c2
commit
72fd13f71c
|
@ -51,6 +51,14 @@ endif::git-rev-list[]
|
||||||
commits whose author matches any of the given patterns are
|
commits whose author matches any of the given patterns are
|
||||||
chosen (similarly for multiple `--committer=<pattern>`).
|
chosen (similarly for multiple `--committer=<pattern>`).
|
||||||
|
|
||||||
|
--grep-reflog=<pattern>::
|
||||||
|
|
||||||
|
Limit the commits output to ones with reflog entries that
|
||||||
|
match the specified pattern (regular expression). With
|
||||||
|
more than one `--grep-reflog`, commits whose reflog message
|
||||||
|
matches any of the given patterns are chosen. Ignored unless
|
||||||
|
`--walk-reflogs` is given.
|
||||||
|
|
||||||
--grep=<pattern>::
|
--grep=<pattern>::
|
||||||
|
|
||||||
Limit the commits output to ones with log message that
|
Limit the commits output to ones with log message that
|
||||||
|
|
1
grep.c
1
grep.c
|
@ -697,6 +697,7 @@ static struct {
|
||||||
} header_field[] = {
|
} header_field[] = {
|
||||||
{ "author ", 7 },
|
{ "author ", 7 },
|
||||||
{ "committer ", 10 },
|
{ "committer ", 10 },
|
||||||
|
{ "reflog ", 7 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
|
static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
|
||||||
|
|
1
grep.h
1
grep.h
|
@ -30,6 +30,7 @@ enum grep_context {
|
||||||
enum grep_header_field {
|
enum grep_header_field {
|
||||||
GREP_HEADER_AUTHOR = 0,
|
GREP_HEADER_AUTHOR = 0,
|
||||||
GREP_HEADER_COMMITTER,
|
GREP_HEADER_COMMITTER,
|
||||||
|
GREP_HEADER_REFLOG,
|
||||||
|
|
||||||
/* Must be at the end of the enum */
|
/* Must be at the end of the enum */
|
||||||
GREP_HEADER_FIELD_MAX
|
GREP_HEADER_FIELD_MAX
|
||||||
|
|
20
revision.c
20
revision.c
|
@ -1595,6 +1595,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
|
||||||
} else if ((argcount = parse_long_opt("committer", argv, &optarg))) {
|
} else if ((argcount = parse_long_opt("committer", argv, &optarg))) {
|
||||||
add_header_grep(revs, GREP_HEADER_COMMITTER, optarg);
|
add_header_grep(revs, GREP_HEADER_COMMITTER, optarg);
|
||||||
return argcount;
|
return argcount;
|
||||||
|
} else if ((argcount = parse_long_opt("grep-reflog", argv, &optarg))) {
|
||||||
|
add_header_grep(revs, GREP_HEADER_REFLOG, optarg);
|
||||||
|
return argcount;
|
||||||
} else if ((argcount = parse_long_opt("grep", argv, &optarg))) {
|
} else if ((argcount = parse_long_opt("grep", argv, &optarg))) {
|
||||||
add_message_grep(revs, optarg);
|
add_message_grep(revs, optarg);
|
||||||
return argcount;
|
return argcount;
|
||||||
|
@ -2210,10 +2213,23 @@ static int rewrite_parents(struct rev_info *revs, struct commit *commit)
|
||||||
|
|
||||||
static int commit_match(struct commit *commit, struct rev_info *opt)
|
static int commit_match(struct commit *commit, struct rev_info *opt)
|
||||||
{
|
{
|
||||||
|
int retval;
|
||||||
|
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;
|
||||||
return grep_buffer(&opt->grep_filter,
|
if (opt->reflog_info) {
|
||||||
commit->buffer, strlen(commit->buffer));
|
strbuf_addstr(&buf, "reflog ");
|
||||||
|
get_reflog_message(&buf, opt->reflog_info);
|
||||||
|
strbuf_addch(&buf, '\n');
|
||||||
|
strbuf_addstr(&buf, commit->buffer);
|
||||||
|
}
|
||||||
|
if (buf.len)
|
||||||
|
retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
|
||||||
|
else
|
||||||
|
retval = grep_buffer(&opt->grep_filter,
|
||||||
|
commit->buffer, strlen(commit->buffer));
|
||||||
|
strbuf_release(&buf);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int want_ancestry(struct rev_info *revs)
|
static inline int want_ancestry(struct rev_info *revs)
|
||||||
|
|
|
@ -546,6 +546,32 @@ test_expect_success 'log grep (6)' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'log grep (7)' '
|
||||||
|
git log -g --grep-reflog="commit: third" --pretty=tformat:%s >actual &&
|
||||||
|
echo third >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'log grep (8)' '
|
||||||
|
git log -g --grep-reflog="commit: third" --grep-reflog="commit: second" --pretty=tformat:%s >actual &&
|
||||||
|
{
|
||||||
|
echo third && echo second
|
||||||
|
} >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'log grep (9)' '
|
||||||
|
git log -g --grep-reflog="commit: third" --author="Thor" --pretty=tformat:%s >actual &&
|
||||||
|
echo third >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'log grep (9)' '
|
||||||
|
git log -g --grep-reflog="commit: third" --author="non-existant" --pretty=tformat:%s >actual &&
|
||||||
|
: >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
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