grep: change internal *pcre* variable & function names to be *pcre1*

Change the internal PCRE variable & function names to have a "1"
suffix. This is for preparation for libpcre2 support, where having
non-versioned names would be confusing.

An earlier change in this series ("grep: change the internal PCRE
macro names to be PCRE1", 2017-04-07) elaborates on the motivations
behind this change.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Ævar Arnfjörð Bjarmason 2017-05-25 19:45:29 +00:00 committed by Junio C Hamano
parent 3485bea157
commit 6d4b5747f0
2 changed files with 30 additions and 30 deletions

52
grep.c
View File

@ -178,23 +178,23 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st


case GREP_PATTERN_TYPE_BRE: case GREP_PATTERN_TYPE_BRE:
opt->fixed = 0; opt->fixed = 0;
opt->pcre = 0; opt->pcre1 = 0;
break; break;


case GREP_PATTERN_TYPE_ERE: case GREP_PATTERN_TYPE_ERE:
opt->fixed = 0; opt->fixed = 0;
opt->pcre = 0; opt->pcre1 = 0;
opt->regflags |= REG_EXTENDED; opt->regflags |= REG_EXTENDED;
break; break;


case GREP_PATTERN_TYPE_FIXED: case GREP_PATTERN_TYPE_FIXED:
opt->fixed = 1; opt->fixed = 1;
opt->pcre = 0; opt->pcre1 = 0;
break; break;


case GREP_PATTERN_TYPE_PCRE: case GREP_PATTERN_TYPE_PCRE:
opt->fixed = 0; opt->fixed = 0;
opt->pcre = 1; opt->pcre1 = 1;
break; break;
} }
} }
@ -334,7 +334,7 @@ static int has_null(const char *s, size_t len)
} }


#ifdef USE_LIBPCRE1 #ifdef USE_LIBPCRE1
static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt) static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
{ {
const char *error; const char *error;
int erroffset; int erroffset;
@ -342,23 +342,23 @@ static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)


if (opt->ignore_case) { if (opt->ignore_case) {
if (has_non_ascii(p->pattern)) if (has_non_ascii(p->pattern))
p->pcre_tables = pcre_maketables(); p->pcre1_tables = pcre_maketables();
options |= PCRE_CASELESS; options |= PCRE_CASELESS;
} }
if (is_utf8_locale() && has_non_ascii(p->pattern)) if (is_utf8_locale() && has_non_ascii(p->pattern))
options |= PCRE_UTF8; options |= PCRE_UTF8;


p->pcre_regexp = pcre_compile(p->pattern, options, &error, &erroffset, p->pcre1_regexp = pcre_compile(p->pattern, options, &error, &erroffset,
p->pcre_tables); p->pcre1_tables);
if (!p->pcre_regexp) if (!p->pcre1_regexp)
compile_regexp_failed(p, error); compile_regexp_failed(p, error);


p->pcre_extra_info = pcre_study(p->pcre_regexp, 0, &error); p->pcre1_extra_info = pcre_study(p->pcre1_regexp, 0, &error);
if (!p->pcre_extra_info && error) if (!p->pcre1_extra_info && error)
die("%s", error); die("%s", error);
} }


static int pcrematch(struct grep_pat *p, const char *line, const char *eol, static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
regmatch_t *match, int eflags) regmatch_t *match, int eflags)
{ {
int ovector[30], ret, flags = 0; int ovector[30], ret, flags = 0;
@ -366,7 +366,7 @@ static int pcrematch(struct grep_pat *p, const char *line, const char *eol,
if (eflags & REG_NOTBOL) if (eflags & REG_NOTBOL)
flags |= PCRE_NOTBOL; flags |= PCRE_NOTBOL;


ret = pcre_exec(p->pcre_regexp, p->pcre_extra_info, line, eol - line, ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line, eol - line,
0, flags, ovector, ARRAY_SIZE(ovector)); 0, flags, ovector, ARRAY_SIZE(ovector));
if (ret < 0 && ret != PCRE_ERROR_NOMATCH) if (ret < 0 && ret != PCRE_ERROR_NOMATCH)
die("pcre_exec failed with error code %d", ret); die("pcre_exec failed with error code %d", ret);
@ -379,25 +379,25 @@ static int pcrematch(struct grep_pat *p, const char *line, const char *eol,
return ret; return ret;
} }


static void free_pcre_regexp(struct grep_pat *p) static void free_pcre1_regexp(struct grep_pat *p)
{ {
pcre_free(p->pcre_regexp); pcre_free(p->pcre1_regexp);
pcre_free(p->pcre_extra_info); pcre_free(p->pcre1_extra_info);
pcre_free((void *)p->pcre_tables); pcre_free((void *)p->pcre1_tables);
} }
#else /* !USE_LIBPCRE1 */ #else /* !USE_LIBPCRE1 */
static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt) static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
{ {
die("cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE"); die("cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE");
} }


static int pcrematch(struct grep_pat *p, const char *line, const char *eol, static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
regmatch_t *match, int eflags) regmatch_t *match, int eflags)
{ {
return 1; return 1;
} }


static void free_pcre_regexp(struct grep_pat *p) static void free_pcre1_regexp(struct grep_pat *p)
{ {
} }
#endif /* !USE_LIBPCRE1 */ #endif /* !USE_LIBPCRE1 */
@ -479,8 +479,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
return; return;
} }


if (opt->pcre) { if (opt->pcre1) {
compile_pcre_regexp(p, opt); compile_pcre1_regexp(p, opt);
return; return;
} }


@ -836,8 +836,8 @@ void free_grep_patterns(struct grep_opt *opt)
case GREP_PATTERN_BODY: case GREP_PATTERN_BODY:
if (p->kws) if (p->kws)
kwsfree(p->kws); kwsfree(p->kws);
else if (p->pcre_regexp) else if (p->pcre1_regexp)
free_pcre_regexp(p); free_pcre1_regexp(p);
else else
regfree(&p->regexp); regfree(&p->regexp);
free(p->pattern); free(p->pattern);
@ -916,8 +916,8 @@ static int patmatch(struct grep_pat *p, char *line, char *eol,


if (p->fixed) if (p->fixed)
hit = !fixmatch(p, line, eol, match); hit = !fixmatch(p, line, eol, match);
else if (p->pcre_regexp) else if (p->pcre1_regexp)
hit = !pcrematch(p, line, eol, match, eflags); hit = !pcre1match(p, line, eol, match, eflags);
else else
hit = !regexec_buf(&p->regexp, line, eol - line, 1, match, hit = !regexec_buf(&p->regexp, line, eol - line, 1, match,
eflags); eflags);

8
grep.h
View File

@ -46,9 +46,9 @@ struct grep_pat {
size_t patternlen; size_t patternlen;
enum grep_header_field field; enum grep_header_field field;
regex_t regexp; regex_t regexp;
pcre *pcre_regexp; pcre *pcre1_regexp;
pcre_extra *pcre_extra_info; pcre_extra *pcre1_extra_info;
const unsigned char *pcre_tables; const unsigned char *pcre1_tables;
kwset_t kws; kwset_t kws;
unsigned fixed:1; unsigned fixed:1;
unsigned ignore_case:1; unsigned ignore_case:1;
@ -111,7 +111,7 @@ struct grep_opt {
int allow_textconv; int allow_textconv;
int extended; int extended;
int use_reflog_filter; int use_reflog_filter;
int pcre; int pcre1;
int relative; int relative;
int pathname; int pathname;
int null_following_name; int null_following_name;