summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorMichał Kiedrowicz <michal.kiedrowicz@gmail.com>2011-05-05 00:00:19 +0200
committerJunio C Hamano <gitster@pobox.com>2011-05-05 08:38:12 -0700
commit97e777842260a5339bb5272a35ebeaeaae554937 (patch)
tree22961e850ded32de96f2dfe1fd108cef6c82e15d /grep.c
parent5a69eaf5541b8449ede74f148d395abd0acbf20f (diff)
downloadgit-97e777842260a5339bb5272a35ebeaeaae554937.tar.gz
grep: Put calls to fixmatch() and regmatch() into patmatch()
Both match_one_pattern() and look_ahead() use fixmatch() and regmatch() in the same way. They really want to match a pattern againt a string, but now they need to know if the pattern is fixed or regexp. This change cleans this up by introducing patmatch() (from "pattern match") and also simplifies inserting other ways of matching a string. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/grep.c b/grep.c
index 63c4280cac..d67baf9566 100644
--- a/grep.c
+++ b/grep.c
@@ -412,6 +412,19 @@ static int regmatch(const regex_t *preg, char *line, char *eol,
return regexec(preg, line, 1, match, eflags);
}
+static int patmatch(struct grep_pat *p, char *line, char *eol,
+ regmatch_t *match, int eflags)
+{
+ int hit;
+
+ if (p->fixed)
+ hit = !fixmatch(p, line, eol, match);
+ else
+ hit = !regmatch(&p->regexp, line, eol, match, eflags);
+
+ return hit;
+}
+
static int strip_timestamp(char *bol, char **eol_p)
{
char *eol = *eol_p;
@@ -461,10 +474,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
}
again:
- if (p->fixed)
- hit = !fixmatch(p, bol, eol, pmatch);
- else
- hit = !regmatch(&p->regexp, bol, eol, pmatch, eflags);
+ hit = patmatch(p, bol, eol, pmatch, eflags);
if (hit && p->word_regexp) {
if ((pmatch[0].rm_so < 0) ||
@@ -791,10 +801,7 @@ static int look_ahead(struct grep_opt *opt,
int hit;
regmatch_t m;
- if (p->fixed)
- hit = !fixmatch(p, bol, bol + *left_p, &m);
- else
- hit = !regmatch(&p->regexp, bol, bol + *left_p, &m, 0);
+ hit = patmatch(p, bol, bol + *left_p, &m, 0);
if (!hit || m.rm_so < 0 || m.rm_eo < 0)
continue;
if (earliest < 0 || m.rm_so < earliest)