@@ -510,44 +510,42 @@ static int git_attr_system(void)
510
510
511
511
static GIT_PATH_FUNC (git_path_info_attributes , INFOATTRIBUTES_FILE )
512
512
513
+ static void push_stack (struct attr_stack * * attr_stack_p ,
514
+ struct attr_stack * elem , char * origin , size_t originlen )
515
+ {
516
+ if (elem ) {
517
+ elem -> origin = origin ;
518
+ if (origin )
519
+ elem -> originlen = originlen ;
520
+ elem -> prev = * attr_stack_p ;
521
+ * attr_stack_p = elem ;
522
+ }
523
+ }
524
+
513
525
static void bootstrap_attr_stack (void )
514
526
{
515
527
struct attr_stack * elem ;
516
528
517
529
if (attr_stack )
518
530
return ;
519
531
520
- elem = read_attr_from_array (builtin_attr );
521
- elem -> origin = NULL ;
522
- elem -> prev = attr_stack ;
523
- attr_stack = elem ;
524
-
525
- if (git_attr_system ()) {
526
- elem = read_attr_from_file (git_etc_gitattributes (), 1 );
527
- if (elem ) {
528
- elem -> origin = NULL ;
529
- elem -> prev = attr_stack ;
530
- attr_stack = elem ;
531
- }
532
- }
532
+ push_stack (& attr_stack , read_attr_from_array (builtin_attr ), NULL , 0 );
533
+
534
+ if (git_attr_system ())
535
+ push_stack (& attr_stack ,
536
+ read_attr_from_file (git_etc_gitattributes (), 1 ),
537
+ NULL , 0 );
533
538
534
539
if (!git_attributes_file )
535
540
git_attributes_file = xdg_config_home ("attributes" );
536
- if (git_attributes_file ) {
537
- elem = read_attr_from_file (git_attributes_file , 1 );
538
- if (elem ) {
539
- elem -> origin = NULL ;
540
- elem -> prev = attr_stack ;
541
- attr_stack = elem ;
542
- }
543
- }
541
+ if (git_attributes_file )
542
+ push_stack (& attr_stack ,
543
+ read_attr_from_file (git_attributes_file , 1 ),
544
+ NULL , 0 );
544
545
545
546
if (!is_bare_repository () || direction == GIT_ATTR_INDEX ) {
546
547
elem = read_attr (GITATTRIBUTES_FILE , 1 );
547
- elem -> origin = xstrdup ("" );
548
- elem -> originlen = 0 ;
549
- elem -> prev = attr_stack ;
550
- attr_stack = elem ;
548
+ push_stack (& attr_stack , elem , xstrdup ("" ), 0 );
551
549
debug_push (elem );
552
550
}
553
551
@@ -558,15 +556,12 @@ static void bootstrap_attr_stack(void)
558
556
559
557
if (!elem )
560
558
elem = xcalloc (1 , sizeof (* elem ));
561
- elem -> origin = NULL ;
562
- elem -> prev = attr_stack ;
563
- attr_stack = elem ;
559
+ push_stack (& attr_stack , elem , NULL , 0 );
564
560
}
565
561
566
562
static void prepare_attr_stack (const char * path , int dirlen )
567
563
{
568
564
struct attr_stack * elem , * info ;
569
- int len ;
570
565
const char * cp ;
571
566
572
567
/*
@@ -626,20 +621,21 @@ static void prepare_attr_stack(const char *path, int dirlen)
626
621
627
622
assert (attr_stack -> origin );
628
623
while (1 ) {
629
- len = strlen (attr_stack -> origin );
624
+ size_t len = strlen (attr_stack -> origin );
625
+ char * origin ;
626
+
630
627
if (dirlen <= len )
631
628
break ;
632
629
cp = memchr (path + len + 1 , '/' , dirlen - len - 1 );
633
630
if (!cp )
634
631
cp = path + dirlen ;
635
- strbuf_add (& pathbuf , path , cp - path );
636
- strbuf_addch ( & pathbuf , '/' );
637
- strbuf_addstr ( & pathbuf , GITATTRIBUTES_FILE );
632
+ strbuf_addf (& pathbuf ,
633
+ "%.*s/%s" , ( int )( cp - path ), path ,
634
+ GITATTRIBUTES_FILE );
638
635
elem = read_attr (pathbuf .buf , 0 );
639
636
strbuf_setlen (& pathbuf , cp - path );
640
- elem -> origin = strbuf_detach (& pathbuf , & elem -> originlen );
641
- elem -> prev = attr_stack ;
642
- attr_stack = elem ;
637
+ origin = strbuf_detach (& pathbuf , & len );
638
+ push_stack (& attr_stack , elem , origin , len );
643
639
debug_push (elem );
644
640
}
645
641
@@ -649,8 +645,7 @@ static void prepare_attr_stack(const char *path, int dirlen)
649
645
/*
650
646
* Finally push the "info" one at the top of the stack.
651
647
*/
652
- info -> prev = attr_stack ;
653
- attr_stack = info ;
648
+ push_stack (& attr_stack , info , NULL , 0 );
654
649
}
655
650
656
651
static int path_matches (const char * pathname , int pathlen ,
0 commit comments