diff mbox series

[20/25] grep.h: make patmatch() a public function

Message ID 20210203032811.14979-21-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series grep: PCREv2 fixes, remove kwset.[ch] | expand

Commit Message

Ævar Arnfjörð Bjarmason Feb. 3, 2021, 3:28 a.m. UTC
I'd like to use the PCRE & ERE etc. code in grep.c for more things in
git, starting with diffcore-pickaxe.c.

The current API just exposes grep_{source,buffer}() for that
purpose. I could use those, but they're very fat entry points into the
entire set of bells and whistles that grep.c supports for "git
grep". I just want the equivalent of a light regexec() wrapper for my
compiled patterns.

So let's expose patmatch() for that purpose. It's not perfect, in
particular it's a bit ugly that we need to pop a pattern off the
opt->pattern_list if all we've got is the "grep_opt" wrapper struct,
but it'll do for now.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 grep.c | 4 ++--
 grep.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/grep.c b/grep.c
index 636ac48bf0..8d84313d6e 100644
--- a/grep.c
+++ b/grep.c
@@ -906,8 +906,8 @@  static void show_name(struct grep_opt *opt, const char *name)
 	opt->output(opt, opt->null_following_name ? "\0" : "\n", 1);
-static int patmatch(struct grep_pat *p, char *line, char *eol,
-		    regmatch_t *match, int eflags)
+int patmatch(struct grep_pat *p, char *line, char *eol,
+	     regmatch_t *match, int eflags)
 	int hit;
diff --git a/grep.h b/grep.h
index 72f82b1e30..66e2ee37f3 100644
--- a/grep.h
+++ b/grep.h
@@ -205,6 +205,8 @@  void grep_source_load_driver(struct grep_source *gs,
 int grep_source(struct grep_opt *opt, struct grep_source *gs);
+int patmatch(struct grep_pat *p, char *line, char *eol,
+	     regmatch_t *match, int eflags);
 struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
 int grep_threads_ok(const struct grep_opt *opt);