attr.c: clarify the logic to pop attr_stack
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 10, 2012 at 12:28 UTC
c432ef996e28a2f02369c505b841f86ec30c85fb
1 file changed
+10
-1
attr.c
+10
-1
@@ -567,7 +567,9 @@ static void prepare_attr_stack(const char *path, int dirlen)
567
568
/*
569
* 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.
573
*/
574
while (attr_stack->origin) {
575
int namelen = strlen(attr_stack->origin);
@@ -587,6 +589,13 @@ static void prepare_attr_stack(const char *path, int dirlen)
589
* Read from parent directories and push them down
590
*/
591
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);
599
while (1) {
600
char *cp;
601