Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCHv2] Add directory pattern matching to attributes

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:55:31

"Jean-Noël AVILA" [off-list ref] 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 <redacted>
---
 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.
quoted hunk
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help