Commit 7aacf027 by Patrick Steinhardt

global: convert all users of POSIX regex to use our new regexp API

The old POSIX regex API has been superseded by our new regexp API.
Convert all users to make use of the new one.
parent d77378eb
...@@ -7,13 +7,15 @@ ...@@ -7,13 +7,15 @@
#include "config.h" #include "config.h"
#include "sysdir.h"
#include "git2/config.h" #include "git2/config.h"
#include "git2/sys/config.h" #include "git2/sys/config.h"
#include "vector.h"
#include "buf_text.h" #include "buf_text.h"
#include "config_backend.h" #include "config_backend.h"
#include "regexp.h"
#include "sysdir.h"
#include "transaction.h" #include "transaction.h"
#include "vector.h"
#if GIT_WIN32 #if GIT_WIN32
# include <windows.h> # include <windows.h>
#endif #endif
...@@ -345,7 +347,7 @@ typedef struct { ...@@ -345,7 +347,7 @@ typedef struct {
git_config_iterator parent; git_config_iterator parent;
git_config_iterator *current; git_config_iterator *current;
const git_config *cfg; const git_config *cfg;
p_regex_t regex; git_regexp regex;
size_t i; size_t i;
} all_iter; } all_iter;
...@@ -423,7 +425,7 @@ static int all_iter_glob_next(git_config_entry **entry, git_config_iterator *_it ...@@ -423,7 +425,7 @@ static int all_iter_glob_next(git_config_entry **entry, git_config_iterator *_it
*/ */
while ((error = all_iter_next(entry, _iter)) == 0) { while ((error = all_iter_next(entry, _iter)) == 0) {
/* skip non-matching keys if regexp was provided */ /* skip non-matching keys if regexp was provided */
if (p_regexec(&iter->regex, (*entry)->name, 0, NULL, 0) != 0) if (git_regexp_match(&iter->regex, (*entry)->name) != 0)
continue; continue;
/* and simply return if we like the entry's name */ /* and simply return if we like the entry's name */
...@@ -447,7 +449,7 @@ static void all_iter_glob_free(git_config_iterator *_iter) ...@@ -447,7 +449,7 @@ static void all_iter_glob_free(git_config_iterator *_iter)
{ {
all_iter *iter = (all_iter *) _iter; all_iter *iter = (all_iter *) _iter;
p_regfree(&iter->regex); git_regexp_dispose(&iter->regex);
all_iter_free(_iter); all_iter_free(_iter);
} }
...@@ -480,8 +482,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf ...@@ -480,8 +482,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf
iter = git__calloc(1, sizeof(all_iter)); iter = git__calloc(1, sizeof(all_iter));
GIT_ERROR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
if ((result = p_regcomp(&iter->regex, regexp, P_REG_EXTENDED)) != 0) { if ((result = git_regexp_compile(&iter->regex, regexp, 0)) < 0) {
git_error_set_regex(&iter->regex, result);
git__free(iter); git__free(iter);
return -1; return -1;
} }
...@@ -510,18 +511,13 @@ int git_config_backend_foreach_match( ...@@ -510,18 +511,13 @@ int git_config_backend_foreach_match(
{ {
git_config_entry *entry; git_config_entry *entry;
git_config_iterator* iter; git_config_iterator* iter;
p_regex_t regex; git_regexp regex;
int error = 0; int error = 0;
assert(backend && cb); assert(backend && cb);
if (regexp != NULL) { if (regexp && git_regexp_compile(&regex, regexp, 0) < 0)
if ((error = p_regcomp(&regex, regexp, P_REG_EXTENDED)) != 0) { return -1;
git_error_set_regex(&regex, error);
p_regfree(&regex);
return -1;
}
}
if ((error = backend->iterator(&iter, backend)) < 0) { if ((error = backend->iterator(&iter, backend)) < 0) {
iter = NULL; iter = NULL;
...@@ -530,7 +526,7 @@ int git_config_backend_foreach_match( ...@@ -530,7 +526,7 @@ int git_config_backend_foreach_match(
while (!(iter->next(&entry, iter) < 0)) { while (!(iter->next(&entry, iter) < 0)) {
/* skip non-matching keys if regexp was provided */ /* skip non-matching keys if regexp was provided */
if (regexp && p_regexec(&regex, entry->name, 0, NULL, 0) != 0) if (regexp && git_regexp_match(&regex, entry->name) != 0)
continue; continue;
/* abort iterator on non-zero return value */ /* abort iterator on non-zero return value */
...@@ -541,7 +537,7 @@ int git_config_backend_foreach_match( ...@@ -541,7 +537,7 @@ int git_config_backend_foreach_match(
} }
if (regexp != NULL) if (regexp != NULL)
p_regfree(&regex); git_regexp_dispose(&regex);
iter->free(iter); iter->free(iter);
...@@ -981,7 +977,7 @@ typedef struct { ...@@ -981,7 +977,7 @@ typedef struct {
git_config_iterator parent; git_config_iterator parent;
git_config_iterator *iter; git_config_iterator *iter;
char *name; char *name;
p_regex_t regex; git_regexp regex;
int have_regex; int have_regex;
} multivar_iter; } multivar_iter;
...@@ -997,7 +993,7 @@ static int multivar_iter_next(git_config_entry **entry, git_config_iterator *_it ...@@ -997,7 +993,7 @@ static int multivar_iter_next(git_config_entry **entry, git_config_iterator *_it
if (!iter->have_regex) if (!iter->have_regex)
return 0; return 0;
if (p_regexec(&iter->regex, (*entry)->value, 0, NULL, 0) == 0) if (git_regexp_match(&iter->regex, (*entry)->value) == 0)
return 0; return 0;
} }
...@@ -1012,7 +1008,7 @@ void multivar_iter_free(git_config_iterator *_iter) ...@@ -1012,7 +1008,7 @@ void multivar_iter_free(git_config_iterator *_iter)
git__free(iter->name); git__free(iter->name);
if (iter->have_regex) if (iter->have_regex)
p_regfree(&iter->regex); git_regexp_dispose(&iter->regex);
git__free(iter); git__free(iter);
} }
...@@ -1032,13 +1028,8 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config ...@@ -1032,13 +1028,8 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config
goto on_error; goto on_error;
if (regexp != NULL) { if (regexp != NULL) {
error = p_regcomp(&iter->regex, regexp, P_REG_EXTENDED); if ((error = git_regexp_compile(&iter->regex, regexp, 0)) < 0)
if (error != 0) {
git_error_set_regex(&iter->regex, error);
error = -1;
p_regfree(&iter->regex);
goto on_error; goto on_error;
}
iter->have_regex = 1; iter->have_regex = 1;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "config_entries.h" #include "config_entries.h"
#include "config_parse.h" #include "config_parse.h"
#include "filebuf.h" #include "filebuf.h"
#include "regexp.h"
#include "strmap.h" #include "strmap.h"
#include "sysdir.h" #include "sysdir.h"
#include "wildmatch.h" #include "wildmatch.h"
...@@ -61,7 +62,7 @@ typedef struct { ...@@ -61,7 +62,7 @@ typedef struct {
static int config_read(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth); static int config_read(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth);
static int config_read_buffer(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth, const char *buf, size_t buflen); static int config_read_buffer(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth, const char *buf, size_t buflen);
static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const p_regex_t *preg, const char *value); static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char *value);
static char *escape_value(const char *ptr); static char *escape_value(const char *ptr);
/** /**
...@@ -350,21 +351,17 @@ static int config_set_multivar( ...@@ -350,21 +351,17 @@ static int config_set_multivar(
git_config_backend *cfg, const char *name, const char *regexp, const char *value) git_config_backend *cfg, const char *name, const char *regexp, const char *value)
{ {
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
char *key; git_regexp preg;
p_regex_t preg;
int result; int result;
char *key;
assert(regexp); assert(regexp);
if ((result = git_config__normalize_name(name, &key)) < 0) if ((result = git_config__normalize_name(name, &key)) < 0)
return result; return result;
result = p_regcomp(&preg, regexp, P_REG_EXTENDED); if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
if (result != 0) {
git_error_set_regex(&preg, result);
result = -1;
goto out; goto out;
}
/* If we do have it, set call config_write() and reload */ /* If we do have it, set call config_write() and reload */
if ((result = config_write(b, name, key, &preg, value)) < 0) if ((result = config_write(b, name, key, &preg, value)) < 0)
...@@ -372,7 +369,7 @@ static int config_set_multivar( ...@@ -372,7 +369,7 @@ static int config_set_multivar(
out: out:
git__free(key); git__free(key);
p_regfree(&preg); git_regexp_dispose(&preg);
return result; return result;
} }
...@@ -412,7 +409,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -412,7 +409,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries = NULL; git_config_entries *entries = NULL;
git_config_entry *entry = NULL; git_config_entry *entry = NULL;
p_regex_t preg = { 0 }; git_regexp preg = GIT_REGEX_INIT;
char *key = NULL; char *key = NULL;
int result; int result;
...@@ -430,11 +427,8 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -430,11 +427,8 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
goto out; goto out;
} }
if ((result = p_regcomp(&preg, regexp, P_REG_EXTENDED)) != 0) { if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
git_error_set_regex(&preg, result);
result = -1;
goto out; goto out;
}
if ((result = config_write(b, name, key, &preg, NULL)) < 0) if ((result = config_write(b, name, key, &preg, NULL)) < 0)
goto out; goto out;
...@@ -442,7 +436,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -442,7 +436,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
out: out:
git_config_entries_free(entries); git_config_entries_free(entries);
git__free(key); git__free(key);
p_regfree(&preg); git_regexp_dispose(&preg);
return result; return result;
} }
...@@ -928,7 +922,7 @@ struct write_data { ...@@ -928,7 +922,7 @@ struct write_data {
const char *section; const char *section;
const char *orig_name; const char *orig_name;
const char *name; const char *name;
const p_regex_t *preg; const git_regexp *preg;
const char *value; const char *value;
}; };
...@@ -1033,7 +1027,7 @@ static int write_on_variable( ...@@ -1033,7 +1027,7 @@ static int write_on_variable(
/* If we have a regex to match the value, see if it matches */ /* If we have a regex to match the value, see if it matches */
if (has_matched && write_data->preg != NULL) if (has_matched && write_data->preg != NULL)
has_matched = (p_regexec(write_data->preg, var_value, 0, NULL, 0) == 0); has_matched = (git_regexp_match(write_data->preg, var_value) == 0);
/* If this isn't the name/value we're looking for, simply dump the /* If this isn't the name/value we're looking for, simply dump the
* existing data back out and continue on. * existing data back out and continue on.
...@@ -1094,7 +1088,8 @@ static int write_on_eof( ...@@ -1094,7 +1088,8 @@ static int write_on_eof(
/* /*
* This is pretty much the parsing, except we write out anything we don't have * This is pretty much the parsing, except we write out anything we don't have
*/ */
static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const p_regex_t *preg, const char* value) static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char* value)
{ {
char *orig_section = NULL, *section = NULL, *orig_name, *name, *ldot; char *orig_section = NULL, *section = NULL, *orig_name, *name, *ldot;
git_buf buf = GIT_BUF_INIT, contents = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT, contents = GIT_BUF_INIT;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "map.h" #include "map.h"
#include "buf_text.h" #include "buf_text.h"
#include "config.h" #include "config.h"
#include "regexp.h"
#include "repository.h" #include "repository.h"
typedef enum { typedef enum {
...@@ -25,7 +26,7 @@ typedef enum { ...@@ -25,7 +26,7 @@ typedef enum {
} git_diff_driver_t; } git_diff_driver_t;
typedef struct { typedef struct {
p_regex_t re; git_regexp re;
int flags; int flags;
} git_diff_driver_pattern; } git_diff_driver_pattern;
...@@ -39,7 +40,7 @@ struct git_diff_driver { ...@@ -39,7 +40,7 @@ struct git_diff_driver {
uint32_t binary_flags; uint32_t binary_flags;
uint32_t other_flags; uint32_t other_flags;
git_array_t(git_diff_driver_pattern) fn_patterns; git_array_t(git_diff_driver_pattern) fn_patterns;
p_regex_t word_pattern; git_regexp word_pattern;
char name[GIT_FLEX_ARRAY]; char name[GIT_FLEX_ARRAY];
}; };
...@@ -113,7 +114,7 @@ static int diff_driver_add_patterns( ...@@ -113,7 +114,7 @@ static int diff_driver_add_patterns(
if (error < 0) if (error < 0)
break; break;
if ((error = p_regcomp(&pat->re, buf.ptr, regex_flags)) != 0) { if ((error = git_regexp_compile(&pat->re, buf.ptr, regex_flags)) != 0) {
/* /*
* TODO: issue a warning * TODO: issue a warning
*/ */
...@@ -130,7 +131,7 @@ static int diff_driver_add_patterns( ...@@ -130,7 +131,7 @@ static int diff_driver_add_patterns(
static int diff_driver_xfuncname(const git_config_entry *entry, void *payload) static int diff_driver_xfuncname(const git_config_entry *entry, void *payload)
{ {
return diff_driver_add_patterns(payload, entry->value, P_REG_EXTENDED); return diff_driver_add_patterns(payload, entry->value, 0);
} }
static int diff_driver_funcname(const git_config_entry *entry, void *payload) static int diff_driver_funcname(const git_config_entry *entry, void *payload)
...@@ -205,16 +206,12 @@ static int git_diff_driver_builtin( ...@@ -205,16 +206,12 @@ static int git_diff_driver_builtin(
if (ddef->fns && if (ddef->fns &&
(error = diff_driver_add_patterns( (error = diff_driver_add_patterns(
drv, ddef->fns, ddef->flags | P_REG_EXTENDED)) < 0) drv, ddef->fns, ddef->flags)) < 0)
goto done; goto done;
if (ddef->words && if (ddef->words &&
(error = p_regcomp( (error = git_regexp_compile(&drv->word_pattern, ddef->words, ddef->flags)) < 0)
&drv->word_pattern, ddef->words, ddef->flags | P_REG_EXTENDED)))
{
error = git_error_set_regex(&drv->word_pattern, error);
goto done; goto done;
}
if ((error = git_strmap_set(reg->drivers, drv->name, drv)) < 0) if ((error = git_strmap_set(reg->drivers, drv->name, drv)) < 0)
goto done; goto done;
...@@ -316,11 +313,10 @@ static int git_diff_driver_load( ...@@ -316,11 +313,10 @@ static int git_diff_driver_load(
goto done; goto done;
if (!ce || !ce->value) if (!ce || !ce->value)
/* no diff.<driver>.wordregex, so just continue */; /* no diff.<driver>.wordregex, so just continue */;
else if (!(error = p_regcomp(&drv->word_pattern, ce->value, P_REG_EXTENDED))) else if (!(error = git_regexp_compile(&drv->word_pattern, ce->value, 0)))
found_driver = true; found_driver = true;
else { else {
/* TODO: warn about bad regex instead of failure */ /* TODO: warn about bad regex instead of failure */
error = git_error_set_regex(&drv->word_pattern, error);
goto done; goto done;
} }
...@@ -400,10 +396,10 @@ void git_diff_driver_free(git_diff_driver *driver) ...@@ -400,10 +396,10 @@ void git_diff_driver_free(git_diff_driver *driver)
return; return;
for (i = 0; i < git_array_size(driver->fn_patterns); ++i) for (i = 0; i < git_array_size(driver->fn_patterns); ++i)
p_regfree(& git_array_get(driver->fn_patterns, i)->re); git_regexp_dispose(& git_array_get(driver->fn_patterns, i)->re);
git_array_clear(driver->fn_patterns); git_array_clear(driver->fn_patterns);
p_regfree(&driver->word_pattern); git_regexp_dispose(&driver->word_pattern);
git__free(driver); git__free(driver);
} }
...@@ -451,19 +447,19 @@ static int diff_context_line__pattern_match( ...@@ -451,19 +447,19 @@ static int diff_context_line__pattern_match(
git_diff_driver *driver, git_buf *line) git_diff_driver *driver, git_buf *line)
{ {
size_t i, maxi = git_array_size(driver->fn_patterns); size_t i, maxi = git_array_size(driver->fn_patterns);
p_regmatch_t pmatch[2]; git_regmatch pmatch[2];
for (i = 0; i < maxi; ++i) { for (i = 0; i < maxi; ++i) {
git_diff_driver_pattern *pat = git_array_get(driver->fn_patterns, i); git_diff_driver_pattern *pat = git_array_get(driver->fn_patterns, i);
if (!p_regexec(&pat->re, line->ptr, 2, pmatch, 0)) { if (!git_regexp_search(&pat->re, line->ptr, 2, pmatch)) {
if (pat->flags & REG_NEGATE) if (pat->flags & REG_NEGATE)
return false; return false;
/* use pmatch data to trim line data */ /* use pmatch data to trim line data */
i = (pmatch[1].rm_so >= 0) ? 1 : 0; i = (pmatch[1].start >= 0) ? 1 : 0;
git_buf_consume(line, git_buf_cstr(line) + pmatch[i].rm_so); git_buf_consume(line, git_buf_cstr(line) + pmatch[i].start);
git_buf_truncate(line, pmatch[i].rm_eo - pmatch[i].rm_so); git_buf_truncate(line, pmatch[i].end - pmatch[i].start);
git_buf_rtrim(line); git_buf_rtrim(line);
return true; return true;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "buffer.h" #include "buffer.h"
#include "tree.h" #include "tree.h"
#include "refdb.h" #include "refdb.h"
#include "regexp.h"
#include "git2.h" #include "git2.h"
...@@ -42,7 +43,7 @@ static int maybe_abbrev(git_object** out, git_repository *repo, const char *spec ...@@ -42,7 +43,7 @@ static int maybe_abbrev(git_object** out, git_repository *repo, const char *spec
return maybe_sha_or_abbrev(out, repo, spec, speclen); return maybe_sha_or_abbrev(out, repo, spec, speclen);
} }
static int build_regex(p_regex_t *regex, const char *pattern) static int build_regex(git_regexp *regex, const char *pattern)
{ {
int error; int error;
...@@ -51,13 +52,11 @@ static int build_regex(p_regex_t *regex, const char *pattern) ...@@ -51,13 +52,11 @@ static int build_regex(p_regex_t *regex, const char *pattern)
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
} }
error = p_regcomp(regex, pattern, P_REG_EXTENDED); error = git_regexp_compile(regex, pattern, 0);
if (!error) if (!error)
return 0; return 0;
error = git_error_set_regex(regex, error); git_regexp_dispose(regex);
p_regfree(regex);
return error; return error;
} }
...@@ -66,7 +65,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe ...@@ -66,7 +65,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
{ {
const char *substr; const char *substr;
int error; int error;
p_regex_t regex; git_regexp regex;
substr = strstr(spec, "-g"); substr = strstr(spec, "-g");
...@@ -76,8 +75,8 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe ...@@ -76,8 +75,8 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0) if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0)
return -1; return -1;
error = p_regexec(&regex, spec, 0, NULL, 0); error = git_regexp_match(&regex, spec);
p_regfree(&regex); git_regexp_dispose(&regex);
if (error) if (error)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
...@@ -143,12 +142,11 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -143,12 +142,11 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
{ {
git_reference *ref = NULL; git_reference *ref = NULL;
git_reflog *reflog = NULL; git_reflog *reflog = NULL;
p_regex_t preg; git_regexp preg;
int error = -1; int error = -1;
size_t i, numentries, cur; size_t i, numentries, cur;
const git_reflog_entry *entry; const git_reflog_entry *entry;
const char *msg; const char *msg;
p_regmatch_t regexmatches[2];
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
cur = position; cur = position;
...@@ -168,12 +166,14 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -168,12 +166,14 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
numentries = git_reflog_entrycount(reflog); numentries = git_reflog_entrycount(reflog);
for (i = 0; i < numentries; i++) { for (i = 0; i < numentries; i++) {
git_regmatch regexmatches[2];
entry = git_reflog_entry_byindex(reflog, i); entry = git_reflog_entry_byindex(reflog, i);
msg = git_reflog_entry_message(entry); msg = git_reflog_entry_message(entry);
if (!msg) if (!msg)
continue; continue;
if (p_regexec(&preg, msg, 2, regexmatches, 0)) if (git_regexp_search(&preg, msg, 2, regexmatches) < 0)
continue; continue;
cur--; cur--;
...@@ -181,7 +181,8 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -181,7 +181,8 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
if (cur > 0) if (cur > 0)
continue; continue;
git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so); if ((git_buf_put(&buf, msg+regexmatches[1].start, regexmatches[1].end - regexmatches[1].start)) < 0)
goto cleanup;
if ((error = git_reference_dwim(base_ref, repo, git_buf_cstr(&buf))) == 0) if ((error = git_reference_dwim(base_ref, repo, git_buf_cstr(&buf))) == 0)
goto cleanup; goto cleanup;
...@@ -199,7 +200,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -199,7 +200,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
cleanup: cleanup:
git_reference_free(ref); git_reference_free(ref);
git_buf_dispose(&buf); git_buf_dispose(&buf);
p_regfree(&preg); git_regexp_dispose(&preg);
git_reflog_free(reflog); git_reflog_free(reflog);
return error; return error;
} }
...@@ -448,7 +449,7 @@ cleanup: ...@@ -448,7 +449,7 @@ cleanup:
return error; return error;
} }
static int walk_and_search(git_object **out, git_revwalk *walk, p_regex_t *regex) static int walk_and_search(git_object **out, git_revwalk *walk, git_regexp *regex)
{ {
int error; int error;
git_oid oid; git_oid oid;
...@@ -460,7 +461,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, p_regex_t *regex ...@@ -460,7 +461,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, p_regex_t *regex
if ((error < 0) && (error != GIT_ENOTFOUND)) if ((error < 0) && (error != GIT_ENOTFOUND))
return -1; return -1;
if (!p_regexec(regex, git_commit_message((git_commit*)obj), 0, NULL, 0)) { if (!git_regexp_match(regex, git_commit_message((git_commit*)obj))) {
*out = obj; *out = obj;
return 0; return 0;
} }
...@@ -476,7 +477,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, p_regex_t *regex ...@@ -476,7 +477,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, p_regex_t *regex
static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern) static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern)
{ {
p_regex_t preg; git_regexp preg;
git_revwalk *walk = NULL; git_revwalk *walk = NULL;
int error; int error;
...@@ -497,7 +498,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_ ...@@ -497,7 +498,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_
error = walk_and_search(out, walk, &preg); error = walk_and_search(out, walk, &preg);
cleanup: cleanup:
p_regfree(&preg); git_regexp_dispose(&preg);
git_revwalk_free(walk); git_revwalk_free(walk);
return error; return error;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifndef INCLUDE_userdiff_h__ #ifndef INCLUDE_userdiff_h__
#define INCLUDE_userdiff_h__ #define INCLUDE_userdiff_h__
#include "regexp.h"
/* /*
* This file isolates the built in diff driver function name patterns. * This file isolates the built in diff driver function name patterns.
* Most of these patterns are taken from Git (with permission from the * Most of these patterns are taken from Git (with permission from the
...@@ -29,7 +31,7 @@ typedef struct { ...@@ -29,7 +31,7 @@ typedef struct {
#define PATTERNS(NAME, FN_PATS, WORD_PAT) \ #define PATTERNS(NAME, FN_PATS, WORD_PAT) \
{ NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 } { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 }
#define IPATTERN(NAME, FN_PATS, WORD_PAT) \ #define IPATTERN(NAME, FN_PATS, WORD_PAT) \
{ NAME, FN_PATS, WORD_PAT WORD_DEFAULT, P_REG_ICASE } { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, GIT_REGEXP_ICASE }
/* /*
* The table of diff driver patterns * The table of diff driver patterns
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment