@@ -278,6 +278,9 @@ struct match_attr {
278
278
279
279
static const char blank [] = " \t\r\n" ;
280
280
281
+ /* Flags usable in read_attr() and parse_attr_line() family of functions. */
282
+ #define READ_ATTR_MACRO_OK (1<<0)
283
+
281
284
/*
282
285
* Parse a whitespace-delimited attribute state (i.e., "attr",
283
286
* "-attr", "!attr", or "attr=value") from the string starting at src.
@@ -331,7 +334,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
331
334
}
332
335
333
336
static struct match_attr * parse_attr_line (const char * line , const char * src ,
334
- int lineno , int macro_ok )
337
+ int lineno , unsigned flags )
335
338
{
336
339
int namelen ;
337
340
int num_attr , i ;
@@ -355,7 +358,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
355
358
356
359
if (strlen (ATTRIBUTE_MACRO_PREFIX ) < namelen &&
357
360
starts_with (name , ATTRIBUTE_MACRO_PREFIX )) {
358
- if (!macro_ok ) {
361
+ if (!( flags & READ_ATTR_MACRO_OK ) ) {
359
362
fprintf_ln (stderr , _ ("%s not allowed: %s:%d" ),
360
363
name , src , lineno );
361
364
goto fail_return ;
@@ -653,11 +656,11 @@ static void handle_attr_line(struct attr_stack *res,
653
656
const char * line ,
654
657
const char * src ,
655
658
int lineno ,
656
- int macro_ok )
659
+ unsigned flags )
657
660
{
658
661
struct match_attr * a ;
659
662
660
- a = parse_attr_line (line , src , lineno , macro_ok );
663
+ a = parse_attr_line (line , src , lineno , flags );
661
664
if (!a )
662
665
return ;
663
666
ALLOC_GROW (res -> attrs , res -> num_matches + 1 , res -> alloc );
@@ -672,7 +675,8 @@ static struct attr_stack *read_attr_from_array(const char **list)
672
675
673
676
res = xcalloc (1 , sizeof (* res ));
674
677
while ((line = * (list ++ )) != NULL )
675
- handle_attr_line (res , line , "[builtin]" , ++ lineno , 1 );
678
+ handle_attr_line (res , line , "[builtin]" , ++ lineno ,
679
+ READ_ATTR_MACRO_OK );
676
680
return res ;
677
681
}
678
682
@@ -698,7 +702,7 @@ void git_attr_set_direction(enum git_attr_direction new_direction)
698
702
direction = new_direction ;
699
703
}
700
704
701
- static struct attr_stack * read_attr_from_file (const char * path , int macro_ok )
705
+ static struct attr_stack * read_attr_from_file (const char * path , unsigned flags )
702
706
{
703
707
FILE * fp = fopen_or_warn (path , "r" );
704
708
struct attr_stack * res ;
@@ -712,15 +716,15 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
712
716
char * bufp = buf ;
713
717
if (!lineno )
714
718
skip_utf8_bom (& bufp , strlen (bufp ));
715
- handle_attr_line (res , bufp , path , ++ lineno , macro_ok );
719
+ handle_attr_line (res , bufp , path , ++ lineno , flags );
716
720
}
717
721
fclose (fp );
718
722
return res ;
719
723
}
720
724
721
725
static struct attr_stack * read_attr_from_index (const struct index_state * istate ,
722
726
const char * path ,
723
- int macro_ok )
727
+ unsigned flags )
724
728
{
725
729
struct attr_stack * res ;
726
730
char * buf , * sp ;
@@ -741,35 +745,35 @@ static struct attr_stack *read_attr_from_index(const struct index_state *istate,
741
745
ep = strchrnul (sp , '\n' );
742
746
more = (* ep == '\n' );
743
747
* ep = '\0' ;
744
- handle_attr_line (res , sp , path , ++ lineno , macro_ok );
748
+ handle_attr_line (res , sp , path , ++ lineno , flags );
745
749
sp = ep + more ;
746
750
}
747
751
free (buf );
748
752
return res ;
749
753
}
750
754
751
755
static struct attr_stack * read_attr (const struct index_state * istate ,
752
- const char * path , int macro_ok )
756
+ const char * path , unsigned flags )
753
757
{
754
758
struct attr_stack * res = NULL ;
755
759
756
760
if (direction == GIT_ATTR_INDEX ) {
757
- res = read_attr_from_index (istate , path , macro_ok );
761
+ res = read_attr_from_index (istate , path , flags );
758
762
} else if (!is_bare_repository ()) {
759
763
if (direction == GIT_ATTR_CHECKOUT ) {
760
- res = read_attr_from_index (istate , path , macro_ok );
764
+ res = read_attr_from_index (istate , path , flags );
761
765
if (!res )
762
- res = read_attr_from_file (path , macro_ok );
766
+ res = read_attr_from_file (path , flags );
763
767
} else if (direction == GIT_ATTR_CHECKIN ) {
764
- res = read_attr_from_file (path , macro_ok );
768
+ res = read_attr_from_file (path , flags );
765
769
if (!res )
766
770
/*
767
771
* There is no checked out .gitattributes file
768
772
* there, but we might have it in the index.
769
773
* We allow operation in a sparsely checked out
770
774
* work tree, so read from it.
771
775
*/
772
- res = read_attr_from_index (istate , path , macro_ok );
776
+ res = read_attr_from_index (istate , path , flags );
773
777
}
774
778
}
775
779
@@ -844,6 +848,7 @@ static void bootstrap_attr_stack(const struct index_state *istate,
844
848
struct attr_stack * * stack )
845
849
{
846
850
struct attr_stack * e ;
851
+ unsigned flags = READ_ATTR_MACRO_OK ;
847
852
848
853
if (* stack )
849
854
return ;
@@ -854,23 +859,23 @@ static void bootstrap_attr_stack(const struct index_state *istate,
854
859
855
860
/* system-wide frame */
856
861
if (git_attr_system ()) {
857
- e = read_attr_from_file (git_etc_gitattributes (), 1 );
862
+ e = read_attr_from_file (git_etc_gitattributes (), flags );
858
863
push_stack (stack , e , NULL , 0 );
859
864
}
860
865
861
866
/* home directory */
862
867
if (get_home_gitattributes ()) {
863
- e = read_attr_from_file (get_home_gitattributes (), 1 );
868
+ e = read_attr_from_file (get_home_gitattributes (), flags );
864
869
push_stack (stack , e , NULL , 0 );
865
870
}
866
871
867
872
/* root directory */
868
- e = read_attr (istate , GITATTRIBUTES_FILE , 1 );
873
+ e = read_attr (istate , GITATTRIBUTES_FILE , flags );
869
874
push_stack (stack , e , xstrdup ("" ), 0 );
870
875
871
876
/* info frame */
872
877
if (startup_info -> have_repository )
873
- e = read_attr_from_file (git_path_info_attributes (), 1 );
878
+ e = read_attr_from_file (git_path_info_attributes (), flags );
874
879
else
875
880
e = NULL ;
876
881
if (!e )
0 commit comments