diff options
author | Jean-Noël AVILA <avila.jn@gmail.com> | 2012-12-08 21:04:39 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-12-17 22:07:23 -0800 |
commit | 94bc671a1f2e8610de475c2494d2763355a99f65 (patch) | |
tree | ee7215f3ca5209152ba36b82955d8e12160fb425 /attr.c | |
parent | 24a62db7bbcbd8083bd0070ecd434205489629ed (diff) | |
download | git-94bc671a1f2e8610de475c2494d2763355a99f65.tar.gz |
Add directory pattern matching to attributes
The manpage of gitattributes says: "The rules how the pattern
matches paths are the same as in .gitignore files" and the gitignore
pattern matching has a pattern ending with / for directory matching.
This rule is specifically relevant for the 'export-ignore' rule used
for git archive.
Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'attr.c')
-rw-r--r-- | attr.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -564,17 +564,24 @@ static void bootstrap_attr_stack(void) attr_stack = elem; } +static const char *find_basename(const char *path) +{ + const char *cp, *last_slash = NULL; + + for (cp = path; *cp; cp++) { + if (*cp == '/' && cp[1]) + last_slash = cp; + } + return last_slash ? last_slash + 1 : path; +} + static void prepare_attr_stack(const char *path) { struct attr_stack *elem, *info; int dirlen, len; const char *cp; - cp = strrchr(path, '/'); - if (!cp) - dirlen = 0; - else - dirlen = cp - path; + dirlen = find_basename(path) - path; /* * At the bottom of the attribute stack is the built-in @@ -668,6 +675,10 @@ static int path_matches(const char *pathname, int pathlen, const char *pattern = pat->pattern; int prefix = pat->nowildcardlen; + if ((pat->flags & EXC_FLAG_MUSTBEDIR) && + ((!pathlen) || (pathname[pathlen-1] != '/'))) + return 0; + if (pat->flags & EXC_FLAG_NODIR) { return match_basename(basename, pathlen - (basename - pathname), @@ -758,9 +769,7 @@ static void collect_all_attrs(const char *path) for (i = 0; i < attr_nr; i++) check_all_attr[i].value = ATTR__UNKNOWN; - basename = strrchr(path, '/'); - basename = basename ? basename + 1 : path; - + basename = find_basename(path); pathlen = strlen(path); rem = attr_nr; for (stk = attr_stack; 0 < rem && stk; stk = stk->prev) |