aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-04-07 09:10:11 -0700
committerJunio C Hamano <gitster@pobox.com>2013-04-07 13:17:50 -0700
commit6466fbbeef67ec398f6f5d5b5da5d6f107a647b2 (patch)
treedba6d1e8ddb52107c61ada62c14158ba40a33b03
parent3a3101c62ecfbde184934f590bab5d84d7ae64a0 (diff)
parent2137ce01f83d254e4917c107901a5a04f61e8c16 (diff)
downloadgit-6466fbbeef67ec398f6f5d5b5da5d6f107a647b2.tar.gz
git-6466fbbeef67ec398f6f5d5b5da5d6f107a647b2.tar.xz
Sync with 1.8.1.6
-rw-r--r--Documentation/RelNotes/1.8.1.6.txt5
-rw-r--r--Documentation/git.txt3
-rw-r--r--attr.c25
-rwxr-xr-xcontrib/remote-helpers/test-hg.sh2
-rw-r--r--dir.c58
-rwxr-xr-xt/t5002-archive-attr-pattern.sh27
6 files changed, 99 insertions, 21 deletions
diff --git a/Documentation/RelNotes/1.8.1.6.txt b/Documentation/RelNotes/1.8.1.6.txt
index d9de63908..c15cf2e80 100644
--- a/Documentation/RelNotes/1.8.1.6.txt
+++ b/Documentation/RelNotes/1.8.1.6.txt
@@ -4,6 +4,11 @@ Git 1.8.1.6 Release Notes
Fixes since v1.8.1.5
--------------------
+ * An earlier change to the attribute system introduced at v1.8.1.2 by
+ mistake stopped a pattern "dir" (without trailing slash) from
+ matching a directory "dir" (it only wanted to allow pattern "dir/"
+ to also match).
+
* The code to keep track of what directory names are known to Git on
platforms with case insensitive filesystems can get confused upon a
hash collision between these pathnames and looped forever.
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 4307d62bd..5a6178820 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -48,9 +48,10 @@ Documentation for older releases are available here:
* release notes for
link:RelNotes/1.8.2.txt[1.8.2].
-* link:v1.8.1.5/git.html[documentation for release 1.8.1.5]
+* link:v1.8.1.6/git.html[documentation for release 1.8.1.6]
* release notes for
+ link:RelNotes/1.8.1.6.txt[1.8.1.6],
link:RelNotes/1.8.1.5.txt[1.8.1.5],
link:RelNotes/1.8.1.4.txt[1.8.1.4],
link:RelNotes/1.8.1.3.txt[1.8.1.3],
diff --git a/attr.c b/attr.c
index e2f937789..689bc2a89 100644
--- a/attr.c
+++ b/attr.c
@@ -657,24 +657,24 @@ static void prepare_attr_stack(const char *path, int dirlen)
}
static int path_matches(const char *pathname, int pathlen,
- const char *basename,
+ int basename_offset,
const struct pattern *pat,
const char *base, int baselen)
{
const char *pattern = pat->pattern;
int prefix = pat->nowildcardlen;
+ int isdir = (pathlen && pathname[pathlen - 1] == '/');
- if ((pat->flags & EXC_FLAG_MUSTBEDIR) &&
- ((!pathlen) || (pathname[pathlen-1] != '/')))
+ if ((pat->flags & EXC_FLAG_MUSTBEDIR) && !isdir)
return 0;
if (pat->flags & EXC_FLAG_NODIR) {
- return match_basename(basename,
- pathlen - (basename - pathname),
+ return match_basename(pathname + basename_offset,
+ pathlen - basename_offset - isdir,
pattern, prefix,
pat->patternlen, pat->flags);
}
- return match_pathname(pathname, pathlen,
+ return match_pathname(pathname, pathlen - isdir,
base, baselen,
pattern, prefix, pat->patternlen, pat->flags);
}
@@ -703,7 +703,7 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
return rem;
}
-static int fill(const char *path, int pathlen, const char *basename,
+static int fill(const char *path, int pathlen, int basename_offset,
struct attr_stack *stk, int rem)
{
int i;
@@ -713,7 +713,7 @@ static int fill(const char *path, int pathlen, const char *basename,
struct match_attr *a = stk->attrs[i];
if (a->is_macro)
continue;
- if (path_matches(path, pathlen, basename,
+ if (path_matches(path, pathlen, basename_offset,
&a->u.pat, base, stk->originlen))
rem = fill_one("fill", a, rem);
}
@@ -752,7 +752,8 @@ static void collect_all_attrs(const char *path)
{
struct attr_stack *stk;
int i, pathlen, rem, dirlen;
- const char *basename, *cp, *last_slash = NULL;
+ const char *cp, *last_slash = NULL;
+ int basename_offset;
for (cp = path; *cp; cp++) {
if (*cp == '/' && cp[1])
@@ -760,10 +761,10 @@ static void collect_all_attrs(const char *path)
}
pathlen = cp - path;
if (last_slash) {
- basename = last_slash + 1;
+ basename_offset = last_slash + 1 - path;
dirlen = last_slash - path;
} else {
- basename = path;
+ basename_offset = 0;
dirlen = 0;
}
@@ -773,7 +774,7 @@ static void collect_all_attrs(const char *path)
rem = attr_nr;
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
- rem = fill(path, pathlen, basename, stk, rem);
+ rem = fill(path, pathlen, basename_offset, stk, rem);
}
int git_check_attr(const char *path, int num, struct git_attr_check *check)
diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh
index 5f81dfae6..7bb81f2f8 100755
--- a/contrib/remote-helpers/test-hg.sh
+++ b/contrib/remote-helpers/test-hg.sh
@@ -115,7 +115,7 @@ test_expect_success 'update bookmark' '
git push
) &&
- hg -R hgrepo bookmarks | grep "devel\s\+3:"
+ hg -R hgrepo bookmarks | egrep "devel[ ]+3:"
'
test_done
diff --git a/dir.c b/dir.c
index 57394e452..1e42b2b15 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;
}
/*
diff --git a/t/t5002-archive-attr-pattern.sh b/t/t5002-archive-attr-pattern.sh
index 0c847fb45..6667d159a 100755
--- a/t/t5002-archive-attr-pattern.sh
+++ b/t/t5002-archive-attr-pattern.sh
@@ -27,6 +27,25 @@ test_expect_success 'setup' '
echo ignored-only-if-dir/ export-ignore >>.git/info/attributes &&
git add ignored-only-if-dir &&
+ mkdir -p ignored-without-slash &&
+ echo "ignored without slash" >ignored-without-slash/foo &&
+ git add ignored-without-slash/foo &&
+ echo "ignored-without-slash export-ignore" >>.git/info/attributes &&
+
+ mkdir -p wildcard-without-slash &&
+ echo "ignored without slash" >wildcard-without-slash/foo &&
+ git add wildcard-without-slash/foo &&
+ echo "wild*-without-slash export-ignore" >>.git/info/attributes &&
+
+ mkdir -p deep/and/slashless &&
+ echo "ignored without slash" >deep/and/slashless/foo &&
+ git add deep/and/slashless/foo &&
+ echo "deep/and/slashless export-ignore" >>.git/info/attributes &&
+
+ mkdir -p deep/with/wildcard &&
+ echo "ignored without slash" >deep/with/wildcard/foo &&
+ git add deep/with/wildcard/foo &&
+ echo "deep/*t*/wildcard export-ignore" >>.git/info/attributes &&
mkdir -p one-level-lower/two-levels-lower/ignored-only-if-dir &&
echo ignored by ignored dir >one-level-lower/two-levels-lower/ignored-only-if-dir/ignored-by-ignored-dir &&
@@ -49,6 +68,14 @@ test_expect_exists archive/not-ignored-dir/ignored-only-if-dir
test_expect_exists archive/not-ignored-dir/
test_expect_missing archive/ignored-only-if-dir/
test_expect_missing archive/ignored-ony-if-dir/ignored-by-ignored-dir
+test_expect_missing archive/ignored-without-slash/ &&
+test_expect_missing archive/ignored-without-slash/foo &&
+test_expect_missing archive/wildcard-without-slash/
+test_expect_missing archive/wildcard-without-slash/foo &&
+test_expect_missing archive/deep/and/slashless/ &&
+test_expect_missing archive/deep/and/slashless/foo &&
+test_expect_missing archive/deep/with/wildcard/ &&
+test_expect_missing archive/deep/with/wildcard/foo &&
test_expect_exists archive/one-level-lower/
test_expect_missing archive/one-level-lower/two-levels-lower/ignored-only-if-dir/
test_expect_missing archive/one-level-lower/two-levels-lower/ignored-ony-if-dir/ignored-by-ignored-dir