From 3f566c4e695a6df8237c34b7c1f34f0832b7e575 Mon Sep 17 00:00:00 2001 From: Hamza Mahfooz Date: Wed, 29 Sep 2021 07:57:15 -0400 Subject: grep: refactor next_match() and match_one_pattern() for external use These changes are made in preparation of, the colorization support for the "git log" subcommands that, rely on regex functionality (i.e. "--author", "--committer" and "--grep"). These changes are necessary primarily because match_one_pattern() expects header lines to be prefixed, however, in pretty, the prefixes are stripped from the lines because the name-email pairs need to go through additional parsing, before they can be printed and because next_match() doesn't handle the case of "ctx == GREP_CONTEXT_HEAD" at all. So, teach next_match() how to handle the new case and move match_one_pattern()'s core logic to headerless_match_one_pattern() while preserving match_one_pattern()'s uses that depend on the additional processing. Signed-off-by: Hamza Mahfooz Signed-off-by: Junio C Hamano --- grep.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'grep.h') diff --git a/grep.h b/grep.h index 3cb8a83ae8..808ad76f0c 100644 --- a/grep.h +++ b/grep.h @@ -191,6 +191,15 @@ void compile_grep_patterns(struct grep_opt *opt); void free_grep_patterns(struct grep_opt *opt); int grep_buffer(struct grep_opt *opt, const char *buf, unsigned long size); +/* The field parameter is only used to filter header patterns + * (where appropriate). If filtering isn't desirable + * GREP_HEADER_FIELD_MAX should be supplied. + */ +int grep_next_match(struct grep_opt *opt, + const char *bol, const char *eol, + enum grep_context ctx, regmatch_t *pmatch, + enum grep_header_field field, int eflags); + struct grep_source { char *name; -- cgit v1.2.3