summaryrefslogtreecommitdiff
path: root/src/config_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 716205851..27b9cc5d7 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -18,6 +18,7 @@
#include "array.h"
#include "config_parse.h"
#include "config_entries.h"
+#include "wildmatch.h"
#include <ctype.h>
#include <sys/types.h>
@@ -697,41 +698,41 @@ static int do_match_gitdir(
int *matches,
const git_repository *repo,
const char *cfg_file,
- const char *value,
+ const char *condition,
bool case_insensitive)
{
- git_buf path = GIT_BUF_INIT;
- int error, fnmatch_flags;
-
- if (value[0] == '.' && git_path_is_dirsep(value[1])) {
- git_path_dirname_r(&path, cfg_file);
- git_buf_joinpath(&path, path.ptr, value + 2);
- } else if (value[0] == '~' && git_path_is_dirsep(value[1]))
- git_sysdir_expand_global_file(&path, value + 1);
- else if (!git_path_is_absolute(value))
- git_buf_joinpath(&path, "**", value);
+ git_buf pattern = GIT_BUF_INIT, gitdir = GIT_BUF_INIT;
+ int error;
+
+ if (condition[0] == '.' && git_path_is_dirsep(condition[1])) {
+ git_path_dirname_r(&pattern, cfg_file);
+ git_buf_joinpath(&pattern, pattern.ptr, condition + 2);
+ } else if (condition[0] == '~' && git_path_is_dirsep(condition[1]))
+ git_sysdir_expand_global_file(&pattern, condition + 1);
+ else if (!git_path_is_absolute(condition))
+ git_buf_joinpath(&pattern, "**", condition);
else
- git_buf_sets(&path, value);
+ git_buf_sets(&pattern, condition);
- if (git_buf_oom(&path)) {
+ if (git_path_is_dirsep(condition[strlen(condition) - 1]))
+ git_buf_puts(&pattern, "**");
+
+ if (git_buf_oom(&pattern)) {
error = -1;
goto out;
}
- if (git_path_is_dirsep(value[strlen(value) - 1]))
- git_buf_puts(&path, "**");
-
- fnmatch_flags = FNM_PATHNAME|FNM_LEADING_DIR;
- if (case_insensitive)
- fnmatch_flags |= FNM_IGNORECASE;
-
- if ((error = p_fnmatch(path.ptr, git_repository_path(repo), fnmatch_flags)) < 0)
+ if ((error = git_repository_item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
goto out;
- *matches = (error == 0);
+ if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1]))
+ git_buf_truncate(&gitdir, gitdir.size - 1);
+ *matches = wildmatch(pattern.ptr, gitdir.ptr,
+ WM_PATHNAME | (case_insensitive ? WM_CASEFOLD : 0)) == WM_MATCH;
out:
- git_buf_dispose(&path);
+ git_buf_dispose(&pattern);
+ git_buf_dispose(&gitdir);
return error;
}