1111#include "cache.h"
1212#include "exec_cmd.h"
1313#include "attr.h"
14+ #include "dir.h"
1415
1516const char git_attr__true [] = "(builtin)true" ;
1617const char git_attr__false [] = "\0(builtin)false" ;
@@ -20,8 +21,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
2021#define ATTR__UNSET NULL
2122#define ATTR__UNKNOWN git_attr__unknown
2223
23- static const char * attributes_file ;
24-
2524/* This is a randomly chosen prime. */
2625#define HASHSIZE 257
2726
@@ -494,14 +493,6 @@ static int git_attr_system(void)
494493 return !git_env_bool ("GIT_ATTR_NOSYSTEM" , 0 );
495494}
496495
497- static int git_attr_config (const char * var , const char * value , void * dummy )
498- {
499- if (!strcmp (var , "core.attributesfile" ))
500- return git_config_pathname (& attributes_file , var , value );
501-
502- return 0 ;
503- }
504-
505496static void bootstrap_attr_stack (void )
506497{
507498 if (!attr_stack ) {
@@ -521,9 +512,8 @@ static void bootstrap_attr_stack(void)
521512 }
522513 }
523514
524- git_config (git_attr_config , NULL );
525- if (attributes_file ) {
526- elem = read_attr_from_file (attributes_file , 1 );
515+ if (git_attributes_file ) {
516+ elem = read_attr_from_file (git_attributes_file , 1 );
527517 if (elem ) {
528518 elem -> origin = NULL ;
529519 elem -> prev = attr_stack ;
@@ -533,7 +523,7 @@ static void bootstrap_attr_stack(void)
533523
534524 if (!is_bare_repository () || direction == GIT_ATTR_INDEX ) {
535525 elem = read_attr (GITATTRIBUTES_FILE , 1 );
536- elem -> origin = strdup ("" );
526+ elem -> origin = xstrdup ("" );
537527 elem -> prev = attr_stack ;
538528 attr_stack = elem ;
539529 debug_push (elem );
@@ -552,7 +542,6 @@ static void prepare_attr_stack(const char *path)
552542{
553543 struct attr_stack * elem , * info ;
554544 int dirlen , len ;
555- struct strbuf pathbuf ;
556545 const char * cp ;
557546
558547 cp = strrchr (path , '/' );
@@ -561,8 +550,6 @@ static void prepare_attr_stack(const char *path)
561550 else
562551 dirlen = cp - path ;
563552
564- strbuf_init (& pathbuf , dirlen + 2 + strlen (GITATTRIBUTES_FILE ));
565-
566553 /*
567554 * At the bottom of the attribute stack is the built-in
568555 * set of attribute definitions, followed by the contents
@@ -607,27 +594,28 @@ static void prepare_attr_stack(const char *path)
607594 * Read from parent directories and push them down
608595 */
609596 if (!is_bare_repository () || direction == GIT_ATTR_INDEX ) {
610- while (1 ) {
611- char * cp ;
597+ struct strbuf pathbuf = STRBUF_INIT ;
612598
599+ while (1 ) {
613600 len = strlen (attr_stack -> origin );
614601 if (dirlen <= len )
615602 break ;
616- strbuf_reset (& pathbuf );
617- strbuf_add (& pathbuf , path , dirlen );
603+ cp = memchr (path + len + 1 , '/' , dirlen - len - 1 );
604+ if (!cp )
605+ cp = path + dirlen ;
606+ strbuf_add (& pathbuf , path , cp - path );
618607 strbuf_addch (& pathbuf , '/' );
619- cp = strchr (pathbuf .buf + len + 1 , '/' );
620- strcpy (cp + 1 , GITATTRIBUTES_FILE );
608+ strbuf_addstr (& pathbuf , GITATTRIBUTES_FILE );
621609 elem = read_attr (pathbuf .buf , 0 );
622- * cp = '\0' ;
623- elem -> origin = strdup ( pathbuf . buf );
610+ strbuf_setlen ( & pathbuf , cp - path ) ;
611+ elem -> origin = strbuf_detach ( & pathbuf , NULL );
624612 elem -> prev = attr_stack ;
625613 attr_stack = elem ;
626614 debug_push (elem );
627615 }
628- }
629616
630- strbuf_release (& pathbuf );
617+ strbuf_release (& pathbuf );
618+ }
631619
632620 /*
633621 * Finally push the "info" one at the top of the stack.
@@ -644,7 +632,7 @@ static int path_matches(const char *pathname, int pathlen,
644632 /* match basename */
645633 const char * basename = strrchr (pathname , '/' );
646634 basename = basename ? basename + 1 : pathname ;
647- return (fnmatch (pattern , basename , 0 ) == 0 );
635+ return (fnmatch_icase (pattern , basename , 0 ) == 0 );
648636 }
649637 /*
650638 * match with FNM_PATHNAME; the pattern has base implicitly
@@ -658,7 +646,7 @@ static int path_matches(const char *pathname, int pathlen,
658646 return 0 ;
659647 if (baselen != 0 )
660648 baselen ++ ;
661- return fnmatch (pattern , pathname + baselen , FNM_PATHNAME ) == 0 ;
649+ return fnmatch_icase (pattern , pathname + baselen , FNM_PATHNAME ) == 0 ;
662650}
663651
664652static int macroexpand_one (int attr_nr , int rem );
0 commit comments