Re: [PATCHv2] Add directory pattern matching to attributes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Jean-Noël AVILA" <avila.jn@xxxxxxxxx> 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@xxxxxxx>
> ---
>  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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]