Skip to content

Commit 909ca7b

Browse files
committed
attr.c: make bootstrap_attr_stack() leave early
Thas would de-dent the body of a function that has grown rather large over time, making it a bit easier to read. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77f7f82 commit 909ca7b

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

attr.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -488,48 +488,49 @@ static int git_attr_config(const char *var, const char *value, void *dummy)
488488

489489
static void bootstrap_attr_stack(void)
490490
{
491-
if (!attr_stack) {
492-
struct attr_stack *elem;
491+
struct attr_stack *elem;
493492

494-
elem = read_attr_from_array(builtin_attr);
495-
elem->origin = NULL;
496-
elem->prev = attr_stack;
497-
attr_stack = elem;
493+
if (attr_stack)
494+
return;
498495

499-
if (git_attr_system()) {
500-
elem = read_attr_from_file(git_etc_gitattributes(), 1);
501-
if (elem) {
502-
elem->origin = NULL;
503-
elem->prev = attr_stack;
504-
attr_stack = elem;
505-
}
506-
}
496+
elem = read_attr_from_array(builtin_attr);
497+
elem->origin = NULL;
498+
elem->prev = attr_stack;
499+
attr_stack = elem;
507500

508-
git_config(git_attr_config, NULL);
509-
if (attributes_file) {
510-
elem = read_attr_from_file(attributes_file, 1);
511-
if (elem) {
512-
elem->origin = NULL;
513-
elem->prev = attr_stack;
514-
attr_stack = elem;
515-
}
501+
if (git_attr_system()) {
502+
elem = read_attr_from_file(git_etc_gitattributes(), 1);
503+
if (elem) {
504+
elem->origin = NULL;
505+
elem->prev = attr_stack;
506+
attr_stack = elem;
516507
}
508+
}
517509

518-
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
519-
elem = read_attr(GITATTRIBUTES_FILE, 1);
520-
elem->origin = strdup("");
510+
git_config(git_attr_config, NULL);
511+
if (attributes_file) {
512+
elem = read_attr_from_file(attributes_file, 1);
513+
if (elem) {
514+
elem->origin = NULL;
521515
elem->prev = attr_stack;
522516
attr_stack = elem;
523-
debug_push(elem);
524517
}
518+
}
525519

526-
elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);
527-
if (!elem)
528-
elem = xcalloc(1, sizeof(*elem));
529-
elem->origin = NULL;
520+
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
521+
elem = read_attr(GITATTRIBUTES_FILE, 1);
522+
elem->origin = strdup("");
530523
elem->prev = attr_stack;
531524
attr_stack = elem;
525+
debug_push(elem);
532526
}
527+
528+
elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);
529+
if (!elem)
530+
elem = xcalloc(1, sizeof(*elem));
531+
elem->origin = NULL;
532+
elem->prev = attr_stack;
533+
attr_stack = elem;
533534
}
534535

535536
static void prepare_attr_stack(const char *path, int dirlen)

0 commit comments

Comments
 (0)