1
0
mirror of https://github.com/git/git.git synced 2025-03-15 16:32:26 +00:00

use wildmatch() directly without fnmatch() wrapper

Make it clear that we don't use fnmatch() anymore.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2014-02-15 09:01:46 +07:00 committed by Junio C Hamano
parent 5f95c9f850
commit eb07894fe0
14 changed files with 20 additions and 17 deletions

View File

@ -4152,7 +4152,7 @@ static int use_patch(struct patch *p)
/* See if it matches any of exclude/include rule */ /* See if it matches any of exclude/include rule */
for (i = 0; i < limit_by_name.nr; i++) { for (i = 0; i < limit_by_name.nr; i++) {
struct string_list_item *it = &limit_by_name.items[i]; struct string_list_item *it = &limit_by_name.items[i];
if (!fnmatch(it->string, pathname, 0)) if (!wildmatch(it->string, pathname, 0, NULL))
return (it->util != NULL); return (it->util != NULL);
} }

View File

@ -315,7 +315,7 @@ static int match_patterns(const char **pattern, const char *refname)
if (!*pattern) if (!*pattern)
return 1; /* no pattern always matches */ return 1; /* no pattern always matches */
while (*pattern) { while (*pattern) {
if (!fnmatch(*pattern, refname, 0)) if (!wildmatch(*pattern, refname, 0, NULL))
return 1; return 1;
pattern++; pattern++;
} }

View File

@ -150,7 +150,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
return 0; return 0;
/* Accept only tags that match the pattern, if given */ /* Accept only tags that match the pattern, if given */
if (pattern && (!is_tag || fnmatch(pattern, path + 10, 0))) if (pattern && (!is_tag || wildmatch(pattern, path + 10, 0, NULL)))
return 0; return 0;
/* Is it annotated? */ /* Is it annotated? */

View File

@ -864,7 +864,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
refname[plen] == '/' || refname[plen] == '/' ||
p[plen-1] == '/')) p[plen-1] == '/'))
break; break;
if (!fnmatch(p, refname, FNM_PATHNAME)) if (!wildmatch(p, refname, WM_PATHNAME, NULL))
break; break;
} }
if (!*pattern) if (!*pattern)

View File

@ -22,7 +22,7 @@ static int tail_match(const char **pattern, const char *path)
if (snprintf(pathbuf, sizeof(pathbuf), "/%s", path) > sizeof(pathbuf)) if (snprintf(pathbuf, sizeof(pathbuf), "/%s", path) > sizeof(pathbuf))
return error("insanely long ref %.*s...", 20, path); return error("insanely long ref %.*s...", 20, path);
while ((p = *(pattern++)) != NULL) { while ((p = *(pattern++)) != NULL) {
if (!fnmatch(p, pathbuf, 0)) if (!wildmatch(p, pathbuf, 0, NULL))
return 1; return 1;
} }
return 0; return 0;

View File

@ -87,7 +87,7 @@ static int subpath_matches(const char *path, const char *filter)
const char *subpath = path; const char *subpath = path;
while (subpath) { while (subpath) {
if (!fnmatch(filter, subpath, 0)) if (!wildmatch(filter, subpath, 0, NULL))
return subpath - path; return subpath - path;
subpath = strchr(subpath, '/'); subpath = strchr(subpath, '/');
if (subpath) if (subpath)

View File

@ -561,7 +561,7 @@ static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, c
return; /* both given explicitly -- nothing to tweak */ return; /* both given explicitly -- nothing to tweak */
for (ent = reflog_expire_cfg; ent; ent = ent->next) { for (ent = reflog_expire_cfg; ent; ent = ent->next) {
if (!fnmatch(ent->pattern, ref, 0)) { if (!wildmatch(ent->pattern, ref, 0, NULL)) {
if (!(slot & EXPIRE_TOTAL)) if (!(slot & EXPIRE_TOTAL))
cb->expire_total = ent->expire_total; cb->expire_total = ent->expire_total;
if (!(slot & EXPIRE_UNREACH)) if (!(slot & EXPIRE_UNREACH))

View File

@ -36,7 +36,7 @@ static int show_reference(const char *refname, const unsigned char *sha1,
{ {
struct show_data *data = cb_data; struct show_data *data = cb_data;
if (!fnmatch(data->pattern, refname, 0)) { if (!wildmatch(data->pattern, refname, 0, NULL)) {
if (data->format == REPLACE_FORMAT_SHORT) if (data->format == REPLACE_FORMAT_SHORT)
printf("%s\n", refname); printf("%s\n", refname);
else if (data->format == REPLACE_FORMAT_MEDIUM) else if (data->format == REPLACE_FORMAT_MEDIUM)

View File

@ -450,7 +450,7 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
slash--; slash--;
if (!*tail) if (!*tail)
return 0; return 0;
if (fnmatch(match_ref_pattern, tail, 0)) if (wildmatch(match_ref_pattern, tail, 0, NULL))
return 0; return 0;
if (starts_with(refname, "refs/heads/")) if (starts_with(refname, "refs/heads/"))
return append_head_ref(refname, sha1, flag, cb_data); return append_head_ref(refname, sha1, flag, cb_data);

View File

@ -42,7 +42,7 @@ static int match_pattern(const char **patterns, const char *ref)
if (!*patterns) if (!*patterns)
return 1; return 1;
for (; *patterns; patterns++) for (; *patterns; patterns++)
if (!fnmatch(*patterns, ref, 0)) if (!wildmatch(*patterns, ref, 0, NULL))
return 1; return 1;
return 0; return 0;
} }

View File

@ -73,7 +73,7 @@ static int match_order(const char *path)
strbuf_addstr(&p, path); strbuf_addstr(&p, path);
while (p.buf[0]) { while (p.buf[0]) {
char *cp; char *cp;
if (!fnmatch(order[i], p.buf, 0)) if (!wildmatch(order[i], p.buf, 0, NULL))
return i; return i;
cp = strrchr(p.buf, '/'); cp = strrchr(p.buf, '/');
if (!cp) if (!cp)

11
dir.c
View File

@ -49,7 +49,9 @@ int strncmp_icase(const char *a, const char *b, size_t count)
int fnmatch_icase(const char *pattern, const char *string, int flags) int fnmatch_icase(const char *pattern, const char *string, int flags)
{ {
return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0)); return wildmatch(pattern, string,
flags | (ignore_case ? WM_CASEFOLD : 0),
NULL);
} }
inline int git_fnmatch(const struct pathspec_item *item, inline int git_fnmatch(const struct pathspec_item *item,
@ -58,7 +60,7 @@ inline int git_fnmatch(const struct pathspec_item *item,
{ {
if (prefix > 0) { if (prefix > 0) {
if (ps_strncmp(item, pattern, string, prefix)) if (ps_strncmp(item, pattern, string, prefix))
return FNM_NOMATCH; return WM_NOMATCH;
pattern += prefix; pattern += prefix;
string += prefix; string += prefix;
} }
@ -76,8 +78,9 @@ inline int git_fnmatch(const struct pathspec_item *item,
NULL); NULL);
else else
/* wildmatch has not learned no FNM_PATHNAME mode yet */ /* wildmatch has not learned no FNM_PATHNAME mode yet */
return fnmatch(pattern, string, return wildmatch(pattern, string,
item->magic & PATHSPEC_ICASE ? FNM_CASEFOLD : 0); item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0,
NULL);
} }
static int fnmatch_icase_mem(const char *pattern, int patternlen, static int fnmatch_icase_mem(const char *pattern, int patternlen,

2
refs.c
View File

@ -1477,7 +1477,7 @@ static int filter_refs(const char *refname, const unsigned char *sha1, int flags
void *data) void *data)
{ {
struct ref_filter *filter = (struct ref_filter *)data; struct ref_filter *filter = (struct ref_filter *)data;
if (fnmatch(filter->pattern, refname, 0)) if (wildmatch(filter->pattern, refname, 0, NULL))
return 0; return 0;
return filter->fn(refname, sha1, flags, filter->cb_data); return filter->fn(refname, sha1, flags, filter->cb_data);
} }

View File

@ -1191,7 +1191,7 @@ int ref_excluded(struct string_list *ref_excludes, const char *path)
if (!ref_excludes) if (!ref_excludes)
return 0; return 0;
for_each_string_list_item(item, ref_excludes) { for_each_string_list_item(item, ref_excludes) {
if (!fnmatch(item->string, path, 0)) if (!wildmatch(item->string, path, 0, NULL))
return 1; return 1;
} }
return 0; return 0;