@@ -594,20 +594,25 @@ static int path_matches(const char *pathname, int pathlen,
594
594
return fnmatch (pattern , pathname + baselen , FNM_PATHNAME ) == 0 ;
595
595
}
596
596
597
+ static int macroexpand_one (int attr_nr , int rem );
598
+
597
599
static int fill_one (const char * what , struct match_attr * a , int rem )
598
600
{
599
601
struct git_attr_check * check = check_all_attr ;
600
602
int i ;
601
603
602
- for (i = 0 ; 0 < rem && i < a -> num_attr ; i ++ ) {
604
+ for (i = a -> num_attr - 1 ; 0 < rem && 0 <= i ; i -- ) {
603
605
struct git_attr * attr = a -> state [i ].attr ;
604
606
const char * * n = & (check [attr -> attr_nr ].value );
605
607
const char * v = a -> state [i ].setto ;
606
608
607
609
if (* n == ATTR__UNKNOWN ) {
608
- debug_set (what , a -> u .pattern , attr , v );
610
+ debug_set (what ,
611
+ a -> is_macro ? a -> u .attr -> name : a -> u .pattern ,
612
+ attr , v );
609
613
* n = v ;
610
614
rem -- ;
615
+ rem = macroexpand_one (attr -> attr_nr , rem );
611
616
}
612
617
}
613
618
return rem ;
@@ -629,19 +634,27 @@ static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
629
634
return rem ;
630
635
}
631
636
632
- static int macroexpand ( struct attr_stack * stk , int rem )
637
+ static int macroexpand_one ( int attr_nr , int rem )
633
638
{
639
+ struct attr_stack * stk ;
640
+ struct match_attr * a = NULL ;
634
641
int i ;
635
- struct git_attr_check * check = check_all_attr ;
636
642
637
- for (i = stk -> num_matches - 1 ; 0 < rem && 0 <= i ; i -- ) {
638
- struct match_attr * a = stk -> attrs [i ];
639
- if (!a -> is_macro )
640
- continue ;
641
- if (check [a -> u .attr -> attr_nr ].value != ATTR__TRUE )
642
- continue ;
643
+ if (check_all_attr [attr_nr ].value != ATTR__TRUE )
644
+ return rem ;
645
+
646
+ for (stk = attr_stack ; !a && stk ; stk = stk -> prev )
647
+ for (i = stk -> num_matches - 1 ; !a && 0 <= i ; i -- ) {
648
+ struct match_attr * ma = stk -> attrs [i ];
649
+ if (!ma -> is_macro )
650
+ continue ;
651
+ if (ma -> u .attr -> attr_nr == attr_nr )
652
+ a = ma ;
653
+ }
654
+
655
+ if (a )
643
656
rem = fill_one ("expand" , a , rem );
644
- }
657
+
645
658
return rem ;
646
659
}
647
660
@@ -666,9 +679,6 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
666
679
for (stk = attr_stack ; 0 < rem && stk ; stk = stk -> prev )
667
680
rem = fill (path , pathlen , stk , rem );
668
681
669
- for (stk = attr_stack ; 0 < rem && stk ; stk = stk -> prev )
670
- rem = macroexpand (stk , rem );
671
-
672
682
for (i = 0 ; i < num ; i ++ ) {
673
683
const char * value = check_all_attr [check [i ].attr -> attr_nr ].value ;
674
684
if (value == ATTR__UNKNOWN )
0 commit comments