summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-04-03 09:34:04 -0700
committerJunio C Hamano <gitster@pobox.com>2013-04-03 09:34:09 -0700
commitf30366b27a91dbc18328bccf3067cdfad4f0cfbc (patch)
tree14712f06445837c105ed70a611830f4d8415c025 /dir.c
parent97fefaf6d32d3e8dbb78778f62fcdd980dcf46c7 (diff)
parentefa5f82540ac0ea75ac185324a78fa230befa050 (diff)
downloadgit-f30366b27a91dbc18328bccf3067cdfad4f0cfbc.tar.gz
Merge branch 'jc/directory-attrs-regression-fix'
Fix 1.8.1.x regression that stopped matching "dir" (without trailing slash) to a directory "dir". * jc/directory-attrs-regression-fix: t: check that a pattern without trailing slash matches a directory dir.c::match_pathname(): pay attention to the length of string parameters dir.c::match_pathname(): adjust patternlen when shifting pattern dir.c::match_basename(): pay attention to the length of string parameters attr.c::path_matches(): special case paths that end with a slash attr.c::path_matches(): the basename is part of the pathname
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c58
1 files changed, 51 insertions, 7 deletions
diff --git a/dir.c b/dir.c
index 57394e452e..1e42b2b150 100644
--- a/dir.c
+++ b/dir.c
@@ -59,6 +59,35 @@ inline int git_fnmatch(const char *pattern, const char *string,
return fnmatch(pattern, string, fnm_flags);
}
+static int fnmatch_icase_mem(const char *pattern, int patternlen,
+ const char *string, int stringlen,
+ int flags)
+{
+ int match_status;
+ struct strbuf pat_buf = STRBUF_INIT;
+ struct strbuf str_buf = STRBUF_INIT;
+ const char *use_pat = pattern;
+ const char *use_str = string;
+
+ if (pattern[patternlen]) {
+ strbuf_add(&pat_buf, pattern, patternlen);
+ use_pat = pat_buf.buf;
+ }
+ if (string[stringlen]) {
+ strbuf_add(&str_buf, string, stringlen);
+ use_str = str_buf.buf;
+ }
+
+ if (ignore_case)
+ flags |= WM_CASEFOLD;
+ match_status = wildmatch(use_pat, use_str, flags, NULL);
+
+ strbuf_release(&pat_buf);
+ strbuf_release(&str_buf);
+
+ return match_status;
+}
+
static size_t common_prefix_len(const char **pathspec)
{
const char *n, *first;
@@ -626,15 +655,20 @@ int match_basename(const char *basename, int basenamelen,
int flags)
{
if (prefix == patternlen) {
- if (!strcmp_icase(pattern, basename))
+ if (patternlen == basenamelen &&
+ !strncmp_icase(pattern, basename, basenamelen))
return 1;
} else if (flags & EXC_FLAG_ENDSWITH) {
+ /* "*literal" matching against "fooliteral" */
if (patternlen - 1 <= basenamelen &&
- !strcmp_icase(pattern + 1,
- basename + basenamelen - patternlen + 1))
+ !strncmp_icase(pattern + 1,
+ basename + basenamelen - (patternlen - 1),
+ patternlen - 1))
return 1;
} else {
- if (fnmatch_icase(pattern, basename, 0) == 0)
+ if (fnmatch_icase_mem(pattern, patternlen,
+ basename, basenamelen,
+ 0) == 0)
return 1;
}
return 0;
@@ -654,6 +688,7 @@ int match_pathname(const char *pathname, int pathlen,
*/
if (*pattern == '/') {
pattern++;
+ patternlen--;
prefix--;
}
@@ -680,13 +715,22 @@ int match_pathname(const char *pathname, int pathlen,
if (strncmp_icase(pattern, name, prefix))
return 0;
pattern += prefix;
+ patternlen -= prefix;
name += prefix;
namelen -= prefix;
+
+ /*
+ * If the whole pattern did not have a wildcard,
+ * then our prefix match is all we need; we
+ * do not need to call fnmatch at all.
+ */
+ if (!patternlen && !namelen)
+ return 1;
}
- return wildmatch(pattern, name,
- WM_PATHNAME | (ignore_case ? WM_CASEFOLD : 0),
- NULL) == 0;
+ return fnmatch_icase_mem(pattern, patternlen,
+ name, namelen,
+ WM_PATHNAME) == 0;
}
/*