Skip to content

Commit 6466fbb

Browse files
committed
Sync with 1.8.1.6
2 parents 3a3101c + 2137ce0 commit 6466fbb

File tree

6 files changed

+99
-21
lines changed

6 files changed

+99
-21
lines changed

Documentation/RelNotes/1.8.1.6.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Git 1.8.1.6 Release Notes
44
Fixes since v1.8.1.5
55
--------------------
66

7+
* An earlier change to the attribute system introduced at v1.8.1.2 by
8+
mistake stopped a pattern "dir" (without trailing slash) from
9+
matching a directory "dir" (it only wanted to allow pattern "dir/"
10+
to also match).
11+
712
* The code to keep track of what directory names are known to Git on
813
platforms with case insensitive filesystems can get confused upon a
914
hash collision between these pathnames and looped forever.

Documentation/git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ Documentation for older releases are available here:
4848
* release notes for
4949
link:RelNotes/1.8.2.txt[1.8.2].
5050

51-
* link:v1.8.1.5/git.html[documentation for release 1.8.1.5]
51+
* link:v1.8.1.6/git.html[documentation for release 1.8.1.6]
5252

5353
* release notes for
54+
link:RelNotes/1.8.1.6.txt[1.8.1.6],
5455
link:RelNotes/1.8.1.5.txt[1.8.1.5],
5556
link:RelNotes/1.8.1.4.txt[1.8.1.4],
5657
link:RelNotes/1.8.1.3.txt[1.8.1.3],

attr.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -657,24 +657,24 @@ static void prepare_attr_stack(const char *path, int dirlen)
657657
}
658658

659659
static int path_matches(const char *pathname, int pathlen,
660-
const char *basename,
660+
int basename_offset,
661661
const struct pattern *pat,
662662
const char *base, int baselen)
663663
{
664664
const char *pattern = pat->pattern;
665665
int prefix = pat->nowildcardlen;
666+
int isdir = (pathlen && pathname[pathlen - 1] == '/');
666667

667-
if ((pat->flags & EXC_FLAG_MUSTBEDIR) &&
668-
((!pathlen) || (pathname[pathlen-1] != '/')))
668+
if ((pat->flags & EXC_FLAG_MUSTBEDIR) && !isdir)
669669
return 0;
670670

671671
if (pat->flags & EXC_FLAG_NODIR) {
672-
return match_basename(basename,
673-
pathlen - (basename - pathname),
672+
return match_basename(pathname + basename_offset,
673+
pathlen - basename_offset - isdir,
674674
pattern, prefix,
675675
pat->patternlen, pat->flags);
676676
}
677-
return match_pathname(pathname, pathlen,
677+
return match_pathname(pathname, pathlen - isdir,
678678
base, baselen,
679679
pattern, prefix, pat->patternlen, pat->flags);
680680
}
@@ -703,7 +703,7 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
703703
return rem;
704704
}
705705

706-
static int fill(const char *path, int pathlen, const char *basename,
706+
static int fill(const char *path, int pathlen, int basename_offset,
707707
struct attr_stack *stk, int rem)
708708
{
709709
int i;
@@ -713,7 +713,7 @@ static int fill(const char *path, int pathlen, const char *basename,
713713
struct match_attr *a = stk->attrs[i];
714714
if (a->is_macro)
715715
continue;
716-
if (path_matches(path, pathlen, basename,
716+
if (path_matches(path, pathlen, basename_offset,
717717
&a->u.pat, base, stk->originlen))
718718
rem = fill_one("fill", a, rem);
719719
}
@@ -752,18 +752,19 @@ static void collect_all_attrs(const char *path)
752752
{
753753
struct attr_stack *stk;
754754
int i, pathlen, rem, dirlen;
755-
const char *basename, *cp, *last_slash = NULL;
755+
const char *cp, *last_slash = NULL;
756+
int basename_offset;
756757

757758
for (cp = path; *cp; cp++) {
758759
if (*cp == '/' && cp[1])
759760
last_slash = cp;
760761
}
761762
pathlen = cp - path;
762763
if (last_slash) {
763-
basename = last_slash + 1;
764+
basename_offset = last_slash + 1 - path;
764765
dirlen = last_slash - path;
765766
} else {
766-
basename = path;
767+
basename_offset = 0;
767768
dirlen = 0;
768769
}
769770

@@ -773,7 +774,7 @@ static void collect_all_attrs(const char *path)
773774

774775
rem = attr_nr;
775776
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
776-
rem = fill(path, pathlen, basename, stk, rem);
777+
rem = fill(path, pathlen, basename_offset, stk, rem);
777778
}
778779

779780
int git_check_attr(const char *path, int num, struct git_attr_check *check)

contrib/remote-helpers/test-hg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test_expect_success 'update bookmark' '
115115
git push
116116
) &&
117117
118-
hg -R hgrepo bookmarks | grep "devel\s\+3:"
118+
hg -R hgrepo bookmarks | egrep "devel[ ]+3:"
119119
'
120120

121121
test_done

dir.c

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ inline int git_fnmatch(const char *pattern, const char *string,
5959
return fnmatch(pattern, string, fnm_flags);
6060
}
6161

62+
static int fnmatch_icase_mem(const char *pattern, int patternlen,
63+
const char *string, int stringlen,
64+
int flags)
65+
{
66+
int match_status;
67+
struct strbuf pat_buf = STRBUF_INIT;
68+
struct strbuf str_buf = STRBUF_INIT;
69+
const char *use_pat = pattern;
70+
const char *use_str = string;
71+
72+
if (pattern[patternlen]) {
73+
strbuf_add(&pat_buf, pattern, patternlen);
74+
use_pat = pat_buf.buf;
75+
}
76+
if (string[stringlen]) {
77+
strbuf_add(&str_buf, string, stringlen);
78+
use_str = str_buf.buf;
79+
}
80+
81+
if (ignore_case)
82+
flags |= WM_CASEFOLD;
83+
match_status = wildmatch(use_pat, use_str, flags, NULL);
84+
85+
strbuf_release(&pat_buf);
86+
strbuf_release(&str_buf);
87+
88+
return match_status;
89+
}
90+
6291
static size_t common_prefix_len(const char **pathspec)
6392
{
6493
const char *n, *first;
@@ -626,15 +655,20 @@ int match_basename(const char *basename, int basenamelen,
626655
int flags)
627656
{
628657
if (prefix == patternlen) {
629-
if (!strcmp_icase(pattern, basename))
658+
if (patternlen == basenamelen &&
659+
!strncmp_icase(pattern, basename, basenamelen))
630660
return 1;
631661
} else if (flags & EXC_FLAG_ENDSWITH) {
662+
/* "*literal" matching against "fooliteral" */
632663
if (patternlen - 1 <= basenamelen &&
633-
!strcmp_icase(pattern + 1,
634-
basename + basenamelen - patternlen + 1))
664+
!strncmp_icase(pattern + 1,
665+
basename + basenamelen - (patternlen - 1),
666+
patternlen - 1))
635667
return 1;
636668
} else {
637-
if (fnmatch_icase(pattern, basename, 0) == 0)
669+
if (fnmatch_icase_mem(pattern, patternlen,
670+
basename, basenamelen,
671+
0) == 0)
638672
return 1;
639673
}
640674
return 0;
@@ -654,6 +688,7 @@ int match_pathname(const char *pathname, int pathlen,
654688
*/
655689
if (*pattern == '/') {
656690
pattern++;
691+
patternlen--;
657692
prefix--;
658693
}
659694

@@ -680,13 +715,22 @@ int match_pathname(const char *pathname, int pathlen,
680715
if (strncmp_icase(pattern, name, prefix))
681716
return 0;
682717
pattern += prefix;
718+
patternlen -= prefix;
683719
name += prefix;
684720
namelen -= prefix;
721+
722+
/*
723+
* If the whole pattern did not have a wildcard,
724+
* then our prefix match is all we need; we
725+
* do not need to call fnmatch at all.
726+
*/
727+
if (!patternlen && !namelen)
728+
return 1;
685729
}
686730

687-
return wildmatch(pattern, name,
688-
WM_PATHNAME | (ignore_case ? WM_CASEFOLD : 0),
689-
NULL) == 0;
731+
return fnmatch_icase_mem(pattern, patternlen,
732+
name, namelen,
733+
WM_PATHNAME) == 0;
690734
}
691735

692736
/*

t/t5002-archive-attr-pattern.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ test_expect_success 'setup' '
2727
echo ignored-only-if-dir/ export-ignore >>.git/info/attributes &&
2828
git add ignored-only-if-dir &&
2929
30+
mkdir -p ignored-without-slash &&
31+
echo "ignored without slash" >ignored-without-slash/foo &&
32+
git add ignored-without-slash/foo &&
33+
echo "ignored-without-slash export-ignore" >>.git/info/attributes &&
34+
35+
mkdir -p wildcard-without-slash &&
36+
echo "ignored without slash" >wildcard-without-slash/foo &&
37+
git add wildcard-without-slash/foo &&
38+
echo "wild*-without-slash export-ignore" >>.git/info/attributes &&
39+
40+
mkdir -p deep/and/slashless &&
41+
echo "ignored without slash" >deep/and/slashless/foo &&
42+
git add deep/and/slashless/foo &&
43+
echo "deep/and/slashless export-ignore" >>.git/info/attributes &&
44+
45+
mkdir -p deep/with/wildcard &&
46+
echo "ignored without slash" >deep/with/wildcard/foo &&
47+
git add deep/with/wildcard/foo &&
48+
echo "deep/*t*/wildcard export-ignore" >>.git/info/attributes &&
3049
3150
mkdir -p one-level-lower/two-levels-lower/ignored-only-if-dir &&
3251
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
4968
test_expect_exists archive/not-ignored-dir/
5069
test_expect_missing archive/ignored-only-if-dir/
5170
test_expect_missing archive/ignored-ony-if-dir/ignored-by-ignored-dir
71+
test_expect_missing archive/ignored-without-slash/ &&
72+
test_expect_missing archive/ignored-without-slash/foo &&
73+
test_expect_missing archive/wildcard-without-slash/
74+
test_expect_missing archive/wildcard-without-slash/foo &&
75+
test_expect_missing archive/deep/and/slashless/ &&
76+
test_expect_missing archive/deep/and/slashless/foo &&
77+
test_expect_missing archive/deep/with/wildcard/ &&
78+
test_expect_missing archive/deep/with/wildcard/foo &&
5279
test_expect_exists archive/one-level-lower/
5380
test_expect_missing archive/one-level-lower/two-levels-lower/ignored-only-if-dir/
5481
test_expect_missing archive/one-level-lower/two-levels-lower/ignored-ony-if-dir/ignored-by-ignored-dir

0 commit comments

Comments
 (0)