git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.
Previous: Jean-Noël AVILA
Message 2 of 2 in “[PATCHv2] Add directory pattern matching to attributes”
  1. Jean-Noël AVILADec 8, 2012
  2. Junio C HamanoDec 13, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.