aboutsummaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-04-07 08:45:03 -0700
committerJunio C Hamano <gitster@pobox.com>2013-04-07 08:45:03 -0700
commit4bbb830a35c5134b612a990f04ee16678ec0c674 (patch)
tree5857a31360481265078ae10c2989471137596cd7 /attr.c
parent0e9b327227fb8f7c1e3a5bbaef19e25b4dfd6764 (diff)
parentefa5f82540ac0ea75ac185324a78fa230befa050 (diff)
downloadgit-4bbb830a35c5134b612a990f04ee16678ec0c674.tar.gz
git-4bbb830a35c5134b612a990f04ee16678ec0c674.tar.xz
Merge branch 'jc/directory-attrs-regression-fix' into maint-1.8.1
A pattern "dir" (without trailing slash) in the attributes file stopped matching a directory "dir" by mistake with an earlier change that wanted to allow pattern "dir/" to also match. * 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 'attr.c')
-rw-r--r--attr.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/attr.c b/attr.c
index d181d98b0..23be4abf4 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)