From: Junio C Hamano <gitster@pobox.com>
To: "Jean-Noël AVILA" <avila.jn@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCHv2] Add directory pattern matching to attributes
Date: Thu, 13 Dec 2012 12:08:57 -0800 [thread overview]
Message-ID: <7vfw39yasm.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <201212082104.39411.avila.jn@gmail.com> ("Jean-Noël AVILA"'s message of "Sat, 8 Dec 2012 21:04:39 +0100")
"Jean-Noël AVILA" <avila.jn@gmail.com> writes:
> 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.
> 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.
prev parent reply other threads:[~2012-12-13 20:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-08 20:04 [PATCHv2] Add directory pattern matching to attributes Jean-Noël AVILA
2012-12-13 20:08 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vfw39yasm.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=avila.jn@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).