diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-06-13 15:27:22 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-06-15 09:34:21 +0200 |
| commit | de70bb46ae4ea91c26f6afdc210f37b8980b7a76 (patch) | |
| tree | 6f650a4b546924ef65dd9c8f9ef6302658312930 /src/pathspec.c | |
| parent | 451df7930db432e7b251bbd0fe2862fe96424ae9 (diff) | |
| download | libgit2-de70bb46ae4ea91c26f6afdc210f37b8980b7a76.tar.gz | |
global: convert trivial `fnmatch` users to use `wildcard`
Upstream git.git has converted its codebase to use wildcard in
favor of fnmatch in commit 70a8fc999d (stop using fnmatch (either
native or compat), 2014-02-15). To keep our own regex-matching in
line with what git does, convert all trivial instances of
`fnmatch` usage to use `wildcard`, instead. Trivial usage is
defined to be use of `fnmatch` with either no flags or flags that
have a 1:1 equivalent in wildmatch (PATHNAME, IGNORECASE).
Diffstat (limited to 'src/pathspec.c')
| -rw-r--r-- | src/pathspec.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/pathspec.c b/src/pathspec.c index 80144c741..0cd3fc4cc 100644 --- a/src/pathspec.c +++ b/src/pathspec.c @@ -16,7 +16,7 @@ #include "index.h" #include "bitvec.h" #include "diff.h" -#include "fnmatch.h" +#include "wildmatch.h" /* what is the common non-wildcard prefix for all items in the pathspec */ char *git_pathspec_prefix(const git_strarray *pathspec) @@ -111,7 +111,7 @@ void git_pathspec__vfree(git_vector *vspec) } struct pathspec_match_context { - int fnmatch_flags; + int wildmatch_flags; int (*strcomp)(const char *, const char *); int (*strncomp)(const char *, const char *, size_t); }; @@ -122,11 +122,11 @@ static void pathspec_match_context_init( bool casefold) { if (disable_fnmatch) - ctxt->fnmatch_flags = -1; + ctxt->wildmatch_flags = -1; else if (casefold) - ctxt->fnmatch_flags = FNM_CASEFOLD; + ctxt->wildmatch_flags = WM_CASEFOLD; else - ctxt->fnmatch_flags = 0; + ctxt->wildmatch_flags = 0; if (casefold) { ctxt->strcomp = git__strcasecmp; @@ -142,16 +142,16 @@ static int pathspec_match_one( struct pathspec_match_context *ctxt, const char *path) { - int result = (match->flags & GIT_ATTR_FNMATCH_MATCH_ALL) ? 0 : FNM_NOMATCH; + int result = (match->flags & GIT_ATTR_FNMATCH_MATCH_ALL) ? 0 : WM_NOMATCH; - if (result == FNM_NOMATCH) - result = ctxt->strcomp(match->pattern, path) ? FNM_NOMATCH : 0; + if (result == WM_NOMATCH) + result = ctxt->strcomp(match->pattern, path) ? WM_NOMATCH : 0; - if (ctxt->fnmatch_flags >= 0 && result == FNM_NOMATCH) - result = p_fnmatch(match->pattern, path, ctxt->fnmatch_flags); + if (ctxt->wildmatch_flags >= 0 && result == WM_NOMATCH) + result = wildmatch(match->pattern, path, ctxt->wildmatch_flags); /* if we didn't match, look for exact dirname prefix match */ - if (result == FNM_NOMATCH && + if (result == WM_NOMATCH && (match->flags & GIT_ATTR_FNMATCH_HASWILD) == 0 && ctxt->strncomp(path, match->pattern, match->length) == 0 && path[match->length] == '/') @@ -160,7 +160,7 @@ static int pathspec_match_one( /* if we didn't match and this is a negative match, check for exact * match of filename with leading '!' */ - if (result == FNM_NOMATCH && + if (result == WM_NOMATCH && (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) != 0 && *path == '!' && ctxt->strncomp(path + 1, match->pattern, match->length) == 0 && |
