diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-06-13 19:16:32 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-06-15 09:34:21 +0200 |
commit | 5811e3ba490ed57dd73714ff4cf26cfa355c19f4 (patch) | |
tree | 4c33c5e9a2ef1477e1da6ee27424fb718085d57c /src/config_file.c | |
parent | cf1a114ba029f57c3c42bd4e8c30565cac48ba90 (diff) | |
download | libgit2-5811e3ba490ed57dd73714ff4cf26cfa355c19f4.tar.gz |
config_file: use `wildmatch` to evaluate conditionals
We currently use `p_fnmatch` to compute whether a given "gitdir:"
or "gitdir/i:" conditional matches the current configuration file
path. As git.git has moved to use `wildmatch` instead of
`p_fnmatch` throughout its complete codebase, we evaluate
conditionals inconsistently with git.git in some special cases.
Convert `p_fnmatch` to use `wildmatch`. The `FNM_LEADINGDIR` flag
cannot be translated to `wildmatch`, but in fact git.git doesn't
use it here either. And in fact, dropping it while we go
increases compatibility with git.git.
Diffstat (limited to 'src/config_file.c')
-rw-r--r-- | src/config_file.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/config_file.c b/src/config_file.c index 4fb832776..27b9cc5d7 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -18,7 +18,7 @@ #include "array.h" #include "config_parse.h" #include "config_entries.h" -#include "fnmatch.h" +#include "wildmatch.h" #include <ctype.h> #include <sys/types.h> @@ -702,7 +702,7 @@ static int do_match_gitdir( bool case_insensitive) { git_buf pattern = GIT_BUF_INIT, gitdir = GIT_BUF_INIT; - int error, fnmatch_flags; + int error; if (condition[0] == '.' && git_path_is_dirsep(condition[1])) { git_path_dirname_r(&pattern, cfg_file); @@ -728,15 +728,8 @@ static int do_match_gitdir( if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1])) git_buf_truncate(&gitdir, gitdir.size - 1); - fnmatch_flags = FNM_PATHNAME|FNM_LEADING_DIR; - if (case_insensitive) - fnmatch_flags |= FNM_IGNORECASE; - - if ((error = p_fnmatch(pattern.ptr, gitdir.ptr, fnmatch_flags)) < 0) - goto out; - - *matches = (error == 0); - + *matches = wildmatch(pattern.ptr, gitdir.ptr, + WM_PATHNAME | (case_insensitive ? WM_CASEFOLD : 0)) == WM_MATCH; out: git_buf_dispose(&pattern); git_buf_dispose(&gitdir); |