Re: [PATCHv2] Add directory pattern matching to attributes
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 13, 2012, 20:08 UTC
- Message-ID
- <7vfw39yasm.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <201212082104.39411.avila.jn@gmail.com>
"Jean-Noël AVILA" <avila.jn@gmail.com> writes:
Show 14 quoted lines
> 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> > --- > 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
Looks nicely done.
Show 25 quoted lines
> diff --git a/attr.c b/attr.c
> index 097ae87..cdba88a 100644
> --- a/attr.c
> +++ b/attr.c
> @@ -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;
> + }
> +}Let's do this function like this instead; shorter and equally easy to understand.
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;
}Thanks; will queue.