From: "Michał Kiedrowicz" <michal.kiedrowicz@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Martin Langhoff" <martin.langhoff@gmail.com>,
"Michał Kiedrowicz" <michal.kiedrowicz@gmail.com>
Subject: [PATCH V2 3/5] grep: Put calls to fixmatch() and regmatch() into patmatch()
Date: Thu, 5 May 2011 00:00:19 +0200 [thread overview]
Message-ID: <1304546421-25439-4-git-send-email-michal.kiedrowicz@gmail.com> (raw)
In-Reply-To: <1304546421-25439-1-git-send-email-michal.kiedrowicz@gmail.com>
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>
---
grep.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/grep.c b/grep.c
index 63c4280..d67baf9 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)
--
1.7.3.4
next prev parent reply other threads:[~2011-05-04 22:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-04 22:00 [PATCH V2 0/5] Add PCRE support to git-grep Michał Kiedrowicz
2011-05-04 22:00 ` [PATCH V2 1/5] Documentation: Add --line-number to git-grep synopsis Michał Kiedrowicz
2011-05-04 22:00 ` [PATCH V2 2/5] contrib/completion: --line-number to git grep Michał Kiedrowicz
2011-05-04 22:00 ` Michał Kiedrowicz [this message]
2011-05-04 22:00 ` [PATCH V2 4/5] git-grep: Learn PCRE Michał Kiedrowicz
2011-05-05 1:09 ` Junio C Hamano
2011-05-05 5:47 ` Bert Wesarg
2011-05-05 16:55 ` Junio C Hamano
2011-05-05 6:19 ` Johannes Sixt
2011-05-05 7:41 ` Michal Kiedrowicz
2011-05-05 7:49 ` Johannes Sixt
2011-05-05 8:38 ` Michal Kiedrowicz
2011-05-05 6:28 ` Johannes Sixt
2011-05-05 7:43 ` Michal Kiedrowicz
2011-05-05 7:43 ` Alex Riesen
2011-05-04 22:00 ` [PATCH V2 5/5] configure: Check for libpcre Michał Kiedrowicz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304546421-25439-4-git-send-email-michal.kiedrowicz@gmail.com \
--to=michal.kiedrowicz@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=martin.langhoff@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).