X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=attr.c;h=55bdb7cdebea7f7ea551231fe7801f272d128d69;hb=bb99190e27c455867bb364059f9a44c0571fc914;hp=43259e5b01f7c8368e5b5d53d8ed4af9dba593ee;hpb=87d2062b3984af5347519c38877b99bce06e6e8d;p=git.git diff --git a/attr.c b/attr.c index 43259e5b0..55bdb7cde 100644 --- a/attr.c +++ b/attr.c @@ -35,8 +35,7 @@ static struct git_attr *(git_attr_hash[HASHSIZE]); static unsigned hash_name(const char *name, int namelen) { - unsigned val = 0; - unsigned char c; + unsigned val = 0, c; while (namelen--) { c = *name++; @@ -224,7 +223,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src, if (is_macro) res->u.attr = git_attr(name, namelen); else { - res->u.pattern = (char*)&(res->state[num_attr]); + res->u.pattern = (char *)&(res->state[num_attr]); memcpy(res->u.pattern, name, namelen); res->u.pattern[namelen] = 0; } @@ -275,7 +274,7 @@ static void free_attr_elem(struct attr_stack *e) setto == ATTR__UNKNOWN) ; else - free((char*) setto); + free((char *) setto); } free(a); } @@ -405,7 +404,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok) if (!res) res = read_attr_from_file(path, macro_ok); } - else { + else if (direction == GIT_ATTR_CHECKIN) { res = read_attr_from_file(path, macro_ok); if (!res) /* @@ -415,6 +414,8 @@ static struct attr_stack *read_attr(const char *path, int macro_ok) */ res = read_attr_from_index(path, macro_ok); } + else + res = read_attr_from_index(path, macro_ok); if (!res) res = xcalloc(1, sizeof(*res)); return res; @@ -466,7 +467,7 @@ static void bootstrap_attr_stack(void) elem->prev = attr_stack; attr_stack = elem; - if (!is_bare_repository()) { + if (!is_bare_repository() || direction == GIT_ATTR_INDEX) { elem = read_attr(GITATTRIBUTES_FILE, 1); elem->origin = strdup(""); elem->prev = attr_stack; @@ -533,7 +534,7 @@ static void prepare_attr_stack(const char *path, int dirlen) /* * Read from parent directories and push them down */ - if (!is_bare_repository()) { + if (!is_bare_repository() || direction == GIT_ATTR_INDEX) { while (1) { char *cp; @@ -554,6 +555,8 @@ static void prepare_attr_stack(const char *path, int dirlen) } } + strbuf_release(&pathbuf); + /* * Finally push the "info" one at the top of the stack. */ @@ -674,6 +677,10 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check) void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate) { enum git_attr_direction old = direction; + + if (is_bare_repository() && new != GIT_ATTR_INDEX) + die("BUG: non-INDEX attr direction in a bare repo"); + direction = new; if (new != old) drop_attr_stack();