summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-06-13 19:16:32 +0200
committerPatrick Steinhardt <ps@pks.im>2019-06-15 09:34:21 +0200
commit5811e3ba490ed57dd73714ff4cf26cfa355c19f4 (patch)
tree4c33c5e9a2ef1477e1da6ee27424fb718085d57c
parentcf1a114ba029f57c3c42bd4e8c30565cac48ba90 (diff)
downloadlibgit2-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.
-rw-r--r--src/config_file.c15
-rw-r--r--tests/config/conditionals.c3
2 files changed, 7 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);
diff --git a/tests/config/conditionals.c b/tests/config/conditionals.c
index 4c2572846..8b9c0e6df 100644
--- a/tests/config/conditionals.c
+++ b/tests/config/conditionals.c
@@ -68,6 +68,7 @@ void test_config_conditionals__gitdir(void)
assert_condition_includes("gitdir", "empty_stand*/", true);
assert_condition_includes("gitdir", "empty_stand*/.git", true);
assert_condition_includes("gitdir", "empty_stand*/.git/", false);
+ assert_condition_includes("gitdir", "empty_standard_repo", false);
assert_condition_includes("gitdir", "empty_standard_repo/", true);
assert_condition_includes("gitdir", "empty_standard_repo/.git", true);
assert_condition_includes("gitdir", "empty_standard_repo/.git/", false);
@@ -79,8 +80,10 @@ void test_config_conditionals__gitdir(void)
assert_condition_includes("gitdir", "~/empty_standard_repo", false);
assert_condition_includes("gitdir", sandbox_path(&path, "/"), true);
+ assert_condition_includes("gitdir", sandbox_path(&path, "/*"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "/**"), true);
+ assert_condition_includes("gitdir", sandbox_path(&path, "empty_standard_repo"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo"), false);