X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=attr.c;h=17f6a4dca521d9690377f2e93a0192d8a874d2ad;hb=35fb0e8633217f602360a9987af51c4b960e7850;hp=64b77b16636482d3448027d7823e5dc07861faa5;hpb=f1a8cc635455a65567d040349327b9ea4adb479b;p=git.git diff --git a/attr.c b/attr.c index 64b77b166..17f6a4dca 100644 --- a/attr.c +++ b/attr.c @@ -438,11 +438,13 @@ static void bootstrap_attr_stack(void) elem->prev = attr_stack; attr_stack = elem; - elem = read_attr(GITATTRIBUTES_FILE, 1); - elem->origin = strdup(""); - elem->prev = attr_stack; - attr_stack = elem; - debug_push(elem); + if (!is_bare_repository()) { + elem = read_attr(GITATTRIBUTES_FILE, 1); + elem->origin = strdup(""); + elem->prev = attr_stack; + attr_stack = elem; + debug_push(elem); + } elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1); if (!elem) @@ -457,7 +459,9 @@ static void prepare_attr_stack(const char *path, int dirlen) { struct attr_stack *elem, *info; int len; - char pathbuf[PATH_MAX]; + struct strbuf pathbuf; + + strbuf_init(&pathbuf, dirlen+2+strlen(GITATTRIBUTES_FILE)); /* * At the bottom of the attribute stack is the built-in @@ -501,22 +505,25 @@ static void prepare_attr_stack(const char *path, int dirlen) /* * Read from parent directories and push them down */ - while (1) { - char *cp; - - len = strlen(attr_stack->origin); - if (dirlen <= len) - break; - memcpy(pathbuf, path, dirlen); - memcpy(pathbuf + dirlen, "/", 2); - cp = strchr(pathbuf + len + 1, '/'); - strcpy(cp + 1, GITATTRIBUTES_FILE); - elem = read_attr(pathbuf, 0); - *cp = '\0'; - elem->origin = strdup(pathbuf); - elem->prev = attr_stack; - attr_stack = elem; - debug_push(elem); + if (!is_bare_repository()) { + while (1) { + char *cp; + + len = strlen(attr_stack->origin); + if (dirlen <= len) + break; + strbuf_reset(&pathbuf); + strbuf_add(&pathbuf, path, dirlen); + strbuf_addch(&pathbuf, '/'); + cp = strchr(pathbuf.buf + len + 1, '/'); + strcpy(cp + 1, GITATTRIBUTES_FILE); + elem = read_attr(pathbuf.buf, 0); + *cp = '\0'; + elem->origin = strdup(pathbuf.buf); + elem->prev = attr_stack; + attr_stack = elem; + debug_push(elem); + } } /* @@ -546,7 +553,9 @@ static int path_matches(const char *pathname, int pathlen, (baselen && pathname[baselen] != '/') || strncmp(pathname, base, baselen)) return 0; - return fnmatch(pattern, pathname + baselen + 1, FNM_PATHNAME) == 0; + if (baselen != 0) + baselen++; + return fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0; } static int fill_one(const char *what, struct match_attr *a, int rem)