Skip to content

Commit

Permalink
grep: change internal *pcre* variable & function names to be *pcre1*
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
avar authored and gitster committed May 26, 2017
1 parent 3485bea commit 6d4b574
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
52 changes: 26 additions & 26 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,23 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st

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

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

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

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

#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;
int erroffset;
int options = PCRE_MULTILINE;

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

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

p->pcre_extra_info = pcre_study(p->pcre_regexp, 0, &error);
if (!p->pcre_extra_info && error)
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, 0, &error);
if (!p->pcre1_extra_info && 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)
{
int ovector[30], ret, flags = 0;

if (eflags & REG_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));
if (ret < 0 && ret != PCRE_ERROR_NOMATCH)
die("pcre_exec failed with error code %d", ret);
Expand All @@ -379,25 +379,25 @@ static int pcrematch(struct grep_pat *p, const char *line, const char *eol,
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->pcre_extra_info);
pcre_free((void *)p->pcre_tables);
pcre_free(p->pcre1_regexp);
pcre_free(p->pcre1_extra_info);
pcre_free((void *)p->pcre1_tables);
}
#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");
}

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)
{
return 1;
}

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

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

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

if (p->fixed)
hit = !fixmatch(p, line, eol, match);
else if (p->pcre_regexp)
hit = !pcrematch(p, line, eol, match, eflags);
else if (p->pcre1_regexp)
hit = !pcre1match(p, line, eol, match, eflags);
else
hit = !regexec_buf(&p->regexp, line, eol - line, 1, match,
eflags);
Expand Down
8 changes: 4 additions & 4 deletions grep.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ struct grep_pat {
size_t patternlen;
enum grep_header_field field;
regex_t regexp;
pcre *pcre_regexp;
pcre_extra *pcre_extra_info;
const unsigned char *pcre_tables;
pcre *pcre1_regexp;
pcre_extra *pcre1_extra_info;
const unsigned char *pcre1_tables;
kwset_t kws;
unsigned fixed:1;
unsigned ignore_case:1;
Expand Down Expand Up @@ -111,7 +111,7 @@ struct grep_opt {
int allow_textconv;
int extended;
int use_reflog_filter;
int pcre;
int pcre1;
int relative;
int pathname;
int null_following_name;
Expand Down

0 comments on commit 6d4b574

Please sign in to comment.