mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
attr: push the bare repo check into read_attr()
Push the bare repository check into the 'read_attr()' function. This avoids needing to have extra logic which creates an empty stack frame when inside a bare repo as a similar bit of logic already exists in the 'read_attr()' function. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
dc81cf377c
commit
0787dafdcc
38
attr.c
38
attr.c
@ -747,25 +747,28 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
|
||||
|
||||
static struct attr_stack *read_attr(const char *path, int macro_ok)
|
||||
{
|
||||
struct attr_stack *res;
|
||||
struct attr_stack *res = NULL;
|
||||
|
||||
if (direction == GIT_ATTR_INDEX) {
|
||||
res = read_attr_from_index(path, macro_ok);
|
||||
} else if (!is_bare_repository()) {
|
||||
if (direction == GIT_ATTR_CHECKOUT) {
|
||||
res = read_attr_from_index(path, macro_ok);
|
||||
if (!res)
|
||||
res = read_attr_from_file(path, macro_ok);
|
||||
}
|
||||
else if (direction == GIT_ATTR_CHECKIN) {
|
||||
} else if (direction == GIT_ATTR_CHECKIN) {
|
||||
res = read_attr_from_file(path, macro_ok);
|
||||
if (!res)
|
||||
/*
|
||||
* There is no checked out .gitattributes file there, but
|
||||
* we might have it in the index. We allow operation in a
|
||||
* sparsely checked out work tree, so read from it.
|
||||
* There is no checked out .gitattributes file
|
||||
* there, but we might have it in the index.
|
||||
* We allow operation in a sparsely checked out
|
||||
* work tree, so read from it.
|
||||
*/
|
||||
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;
|
||||
@ -857,10 +860,7 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
|
||||
}
|
||||
|
||||
/* root directory */
|
||||
if (!is_bare_repository() || direction == GIT_ATTR_INDEX)
|
||||
e = read_attr(GITATTRIBUTES_FILE, 1);
|
||||
else
|
||||
e = xcalloc(1, sizeof(struct attr_stack));
|
||||
push_stack(stack, e, xstrdup(""), 0);
|
||||
|
||||
/* info frame */
|
||||
@ -877,6 +877,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
|
||||
struct attr_stack **stack)
|
||||
{
|
||||
struct attr_stack *info;
|
||||
struct strbuf pathbuf = STRBUF_INIT;
|
||||
|
||||
/*
|
||||
* At the bottom of the attribute stack is the built-in
|
||||
@ -922,19 +923,14 @@ static void prepare_attr_stack(const char *path, int dirlen,
|
||||
attr_stack_free(elem);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from parent directories and push them down
|
||||
*/
|
||||
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
|
||||
/*
|
||||
* bootstrap_attr_stack() should have added, and the
|
||||
* above loop should have stopped before popping, the
|
||||
* root element whose attr_stack->origin is set to an
|
||||
* empty string.
|
||||
*/
|
||||
struct strbuf pathbuf = STRBUF_INIT;
|
||||
|
||||
assert((*stack)->origin);
|
||||
|
||||
strbuf_addstr(&pathbuf, (*stack)->origin);
|
||||
/* Build up to the directory 'path' is in */
|
||||
while (pathbuf.len < dirlen) {
|
||||
@ -951,8 +947,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
|
||||
|
||||
if (pathbuf.len > 0)
|
||||
strbuf_addch(&pathbuf, '/');
|
||||
strbuf_add(&pathbuf, path + pathbuf.len,
|
||||
(len - pathbuf.len));
|
||||
strbuf_add(&pathbuf, path + pathbuf.len, (len - pathbuf.len));
|
||||
strbuf_addf(&pathbuf, "/%s", GITATTRIBUTES_FILE);
|
||||
|
||||
next = read_attr(pathbuf.buf, 0);
|
||||
@ -962,15 +957,14 @@ static void prepare_attr_stack(const char *path, int dirlen,
|
||||
|
||||
origin = xstrdup(pathbuf.buf);
|
||||
push_stack(stack, next, origin, len);
|
||||
|
||||
}
|
||||
strbuf_release(&pathbuf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally push the "info" one at the top of the stack.
|
||||
*/
|
||||
push_stack(stack, info, NULL, 0);
|
||||
|
||||
strbuf_release(&pathbuf);
|
||||
}
|
||||
|
||||
static int path_matches(const char *pathname, int pathlen,
|
||||
|
Loading…
Reference in New Issue
Block a user