revs->commit_format = CMIT_FMT_DEFAULT;
+ revs->grep_filter.status_only = 1;
+ revs->grep_filter.pattern_tail = &(revs->grep_filter.pattern_list);
+ revs->grep_filter.regflags = REG_NEWLINE;
+
diff_setup(&revs->diffopt);
if (prefix && !revs->diffopt.prefix) {
revs->diffopt.prefix = prefix;
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
{
- if (!revs->grep_filter) {
- struct grep_opt *opt = xcalloc(1, sizeof(*opt));
- opt->status_only = 1;
- opt->pattern_tail = &(opt->pattern_list);
- opt->regflags = REG_NEWLINE;
- revs->grep_filter = opt;
- }
- append_grep_pattern(revs->grep_filter, ptn,
- "command line", 0, what);
+ append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what);
}
-static void add_header_grep(struct rev_info *revs, const char *field, const char *pattern)
+static void add_header_grep(struct rev_info *revs, enum grep_header_field field, const char *pattern)
{
- char *pat;
- const char *prefix;
- int patlen, fldlen;
-
- fldlen = strlen(field);
- patlen = strlen(pattern);
- pat = xmalloc(patlen + fldlen + 10);
- prefix = ".*";
- if (*pattern == '^') {
- prefix = "";
- pattern++;
- }
- sprintf(pat, "^%s %s%s", field, prefix, pattern);
- add_grep(revs, pat, GREP_PATTERN_HEAD);
+ append_header_grep_pattern(&revs->grep_filter, field, pattern);
}
static void add_message_grep(struct rev_info *revs, const char *pattern)
int num = ++revs->num_ignore_packed;
revs->ignore_packed = xrealloc(revs->ignore_packed,
- sizeof(const char **) * (num + 1));
+ sizeof(const char *) * (num + 1));
revs->ignore_packed[num-1] = name;
revs->ignore_packed[num] = NULL;
}
* Grepping the commit log
*/
else if (!prefixcmp(arg, "--author=")) {
- add_header_grep(revs, "author", arg+9);
+ add_header_grep(revs, GREP_HEADER_AUTHOR, arg+9);
} else if (!prefixcmp(arg, "--committer=")) {
- add_header_grep(revs, "committer", arg+12);
+ add_header_grep(revs, GREP_HEADER_COMMITTER, arg+12);
} else if (!prefixcmp(arg, "--grep=")) {
add_message_grep(revs, arg+7);
} else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
- if (revs->grep_filter)
- revs->grep_filter->regflags |= REG_EXTENDED;
+ revs->grep_filter.regflags |= REG_EXTENDED;
} else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
- if (revs->grep_filter)
- revs->grep_filter->regflags |= REG_ICASE;
+ revs->grep_filter.regflags |= REG_ICASE;
} else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
- if (revs->grep_filter)
- revs->grep_filter->fixed = 1;
+ revs->grep_filter.fixed = 1;
} else if (!strcmp(arg, "--all-match")) {
- if (revs->grep_filter)
- revs->grep_filter->all_match = 1;
+ revs->grep_filter.all_match = 1;
} else if (!prefixcmp(arg, "--encoding=")) {
arg += 11;
if (strcmp(arg, "none"))
if (diff_setup_done(&revs->diffopt) < 0)
die("diff_setup_done failed");
- if (revs->grep_filter) {
- compile_grep_patterns(revs->grep_filter);
- }
+ compile_grep_patterns(&revs->grep_filter);
if (revs->reverse && revs->reflog_info)
die("cannot combine --reverse with --walk-reflogs");
static int commit_match(struct commit *commit, struct rev_info *opt)
{
- if (!opt->grep_filter)
+ if (!opt->grep_filter.pattern_list)
return 1;
- return grep_buffer(opt->grep_filter,
+ return grep_buffer(&opt->grep_filter,
NULL, /* we say nothing, not even filename */
commit->buffer, strlen(commit->buffer));
}