Skip to content

Commit c432ef9

Browse files
committed
attr.c: clarify the logic to pop attr_stack
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 909ca7b commit c432ef9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

attr.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,9 @@ static void prepare_attr_stack(const char *path, int dirlen)
567567

568568
/*
569569
* Pop the ones from directories that are not the prefix of
570-
* the path we are checking.
570+
* the path we are checking. Break out of the loop when we see
571+
* the root one (whose origin is an empty string "") or the builtin
572+
* one (whose origin is NULL) without popping it.
571573
*/
572574
while (attr_stack->origin) {
573575
int namelen = strlen(attr_stack->origin);
@@ -587,6 +589,13 @@ static void prepare_attr_stack(const char *path, int dirlen)
587589
* Read from parent directories and push them down
588590
*/
589591
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
592+
/*
593+
* bootstrap_attr_stack() should have added, and the
594+
* above loop should have stopped before popping, the
595+
* root element whose attr_stack->origin is set to an
596+
* empty string.
597+
*/
598+
assert(attr_stack->origin);
590599
while (1) {
591600
char *cp;
592601

0 commit comments

Comments
 (0)