Add directory pattern matching to attributes
PATCH v2 1/1 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.
---
This patch was not reviewed when I submitted it for the second time. Is there any pending work which prevents it from being merged?
archive.c | 3 ++- attr.c | 32 ++++++++++++++++------ t/t5002-archive-attr-pattern.sh | 57 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 t/t5002-archive-attr-pattern.sh
archive.c +2 -1
@@ -120,6 +120,8 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,strbuf_add (&path, args->base, args->baselen);strbuf_add (&path, base, baselen);strbuf_addstr (&path, filename); +if (S_ISDIR (mode) ||S_ISGITLINK (mode)) +strbuf_addch (&path,'/' ); path_without_prefix = path.buf + args->baselen;setup_archive_check (check);
@@ -130,7 +132,6 @@ static int write_archive_entry(const unsigned char *sha1, const char *base, }if (S_ISDIR (mode) ||S_ISGITLINK (mode)) { -strbuf_addch (&path,'/' );if (args->verbose)fprintf (stderr,"%.*s\n" , (int )path.len, path.buf); err =write_entry (args, sha1, path.buf, path.len, mode);
attr.c +24 -8
@@ -564,17 +564,31 @@ static void bootstrap_attr_stack(void) attr_stack = elem; } +static const char *find_basename (const char *path) +{ +char pathbuf[PATH_MAX ]; +int pathlen; +const char *cp; + + pathlen =strlen (path); +if (path[pathlen-1 ] !='/' ) { + cp =strrchr (path,'/' ); +return cp ? cp +1 : path; + }else { +strncpy (pathbuf, path, pathlen); + pathbuf[pathlen-1 ] ='\0' ; + cp =strrchr (pathbuf,'/' ); +return cp ? path + (cp - pathbuf) +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 +682,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 +776,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)
t/t5002-archive-attr-pattern.sh new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 1 line · Jean-Noël AVILA
This patch was not reviewed when I submitted it for the second time.
Did you miss this?
http://thread.gmane.org/gmane.comp.version-control.git/211214/focus=211470
Le mercredi 19 décembre 2012 22:44:59, vous avez écrit :
Quoted 6 lines
Quoted 1 line · Jean-Noël AVILA
This patch was not reviewed when I submitted it for the second time.
Did you miss this?
Grml, I did. Sorry for the noise.
Quoted 8 lines · Jean-Noël AVILA
Le mercredi 19 décembre 2012 22:44:59, vous avez écrit :
Quoted 5 lines
Quoted 1 line · Jean-Noël AVILA
This patch was not reviewed when I submitted it for the second time.
Did you miss this?
Grml, I did. Sorry for the noise.
That's OK. Your previous one, with the update suggested in the thread, has already been queued in 'next' and will be cooking there throughout the pre-release feature freeze.