@@ -708,10 +708,10 @@ static struct attr_stack *read_attr_from_array(const char **list)
708708 * another thread could potentially be calling into the attribute system.
709709 */
710710static enum git_attr_direction direction ;
711- static struct index_state * use_index ;
711+ static const struct index_state * use_index ;
712712
713713void git_attr_set_direction (enum git_attr_direction new_direction ,
714- struct index_state * istate )
714+ const struct index_state * istate )
715715{
716716 if (is_bare_repository () && new_direction != GIT_ATTR_INDEX )
717717 BUG ("non-INDEX attr direction in a bare repo" );
@@ -743,13 +743,24 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
743743 return res ;
744744}
745745
746- static struct attr_stack * read_attr_from_index (const char * path , int macro_ok )
746+ static struct attr_stack * read_attr_from_index (const struct index_state * istate ,
747+ const char * path ,
748+ int macro_ok )
747749{
748750 struct attr_stack * res ;
749751 char * buf , * sp ;
750752 int lineno = 0 ;
753+ const struct index_state * to_read_from ;
751754
752- buf = read_blob_data_from_index (use_index ? use_index : & the_index , path , NULL );
755+ /*
756+ * Temporary workaround for c24f3abace (apply: file commited
757+ * with CRLF should roundtrip diff and apply - 2017-08-19)
758+ */
759+ to_read_from = use_index ? use_index : istate ;
760+ if (!to_read_from )
761+ return NULL ;
762+
763+ buf = read_blob_data_from_index (to_read_from , path , NULL );
753764 if (!buf )
754765 return NULL ;
755766
@@ -768,15 +779,16 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
768779 return res ;
769780}
770781
771- static struct attr_stack * read_attr (const char * path , int macro_ok )
782+ static struct attr_stack * read_attr (const struct index_state * istate ,
783+ const char * path , int macro_ok )
772784{
773785 struct attr_stack * res = NULL ;
774786
775787 if (direction == GIT_ATTR_INDEX ) {
776- res = read_attr_from_index (path , macro_ok );
788+ res = read_attr_from_index (istate , path , macro_ok );
777789 } else if (!is_bare_repository ()) {
778790 if (direction == GIT_ATTR_CHECKOUT ) {
779- res = read_attr_from_index (path , macro_ok );
791+ res = read_attr_from_index (istate , path , macro_ok );
780792 if (!res )
781793 res = read_attr_from_file (path , macro_ok );
782794 } else if (direction == GIT_ATTR_CHECKIN ) {
@@ -788,7 +800,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
788800 * We allow operation in a sparsely checked out
789801 * work tree, so read from it.
790802 */
791- res = read_attr_from_index (path , macro_ok );
803+ res = read_attr_from_index (istate , path , macro_ok );
792804 }
793805 }
794806
@@ -859,7 +871,8 @@ static void push_stack(struct attr_stack **attr_stack_p,
859871 }
860872}
861873
862- static void bootstrap_attr_stack (struct attr_stack * * stack )
874+ static void bootstrap_attr_stack (const struct index_state * istate ,
875+ struct attr_stack * * stack )
863876{
864877 struct attr_stack * e ;
865878
@@ -883,7 +896,7 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
883896 }
884897
885898 /* root directory */
886- e = read_attr (GITATTRIBUTES_FILE , 1 );
899+ e = read_attr (istate , GITATTRIBUTES_FILE , 1 );
887900 push_stack (stack , e , xstrdup ("" ), 0 );
888901
889902 /* info frame */
@@ -896,7 +909,8 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
896909 push_stack (stack , e , NULL , 0 );
897910}
898911
899- static void prepare_attr_stack (const char * path , int dirlen ,
912+ static void prepare_attr_stack (const struct index_state * istate ,
913+ const char * path , int dirlen ,
900914 struct attr_stack * * stack )
901915{
902916 struct attr_stack * info ;
@@ -917,7 +931,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
917931 * .gitattributes in deeper directories to shallower ones,
918932 * and finally use the built-in set as the default.
919933 */
920- bootstrap_attr_stack (stack );
934+ bootstrap_attr_stack (istate , stack );
921935
922936 /*
923937 * Pop the "info" one that is always at the top of the stack.
@@ -973,7 +987,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
973987 strbuf_add (& pathbuf , path + pathbuf .len , (len - pathbuf .len ));
974988 strbuf_addf (& pathbuf , "/%s" , GITATTRIBUTES_FILE );
975989
976- next = read_attr (pathbuf .buf , 0 );
990+ next = read_attr (istate , pathbuf .buf , 0 );
977991
978992 /* reset the pathbuf to not include "/.gitattributes" */
979993 strbuf_setlen (& pathbuf , len );
@@ -1095,7 +1109,9 @@ static void determine_macros(struct all_attrs_item *all_attrs,
10951109 * If check->check_nr is non-zero, only attributes in check[] are collected.
10961110 * Otherwise all attributes are collected.
10971111 */
1098- static void collect_some_attrs (const char * path , struct attr_check * check )
1112+ static void collect_some_attrs (const struct index_state * istate ,
1113+ const char * path ,
1114+ struct attr_check * check )
10991115{
11001116 int i , pathlen , rem , dirlen ;
11011117 const char * cp , * last_slash = NULL ;
@@ -1114,7 +1130,7 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
11141130 dirlen = 0 ;
11151131 }
11161132
1117- prepare_attr_stack (path , dirlen , & check -> stack );
1133+ prepare_attr_stack (istate , path , dirlen , & check -> stack );
11181134 all_attrs_init (& g_attr_hashmap , check );
11191135 determine_macros (check -> all_attrs , check -> stack );
11201136
@@ -1136,11 +1152,13 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
11361152 fill (path , pathlen , basename_offset , check -> stack , check -> all_attrs , rem );
11371153}
11381154
1139- int git_check_attr (const char * path , struct attr_check * check )
1155+ int git_check_attr (const struct index_state * istate ,
1156+ const char * path ,
1157+ struct attr_check * check )
11401158{
11411159 int i ;
11421160
1143- collect_some_attrs (path , check );
1161+ collect_some_attrs (istate , path , check );
11441162
11451163 for (i = 0 ; i < check -> nr ; i ++ ) {
11461164 size_t n = check -> items [i ].attr -> attr_nr ;
@@ -1153,12 +1171,13 @@ int git_check_attr(const char *path, struct attr_check *check)
11531171 return 0 ;
11541172}
11551173
1156- void git_all_attrs (const char * path , struct attr_check * check )
1174+ void git_all_attrs (const struct index_state * istate ,
1175+ const char * path , struct attr_check * check )
11571176{
11581177 int i ;
11591178
11601179 attr_check_reset (check );
1161- collect_some_attrs (path , check );
1180+ collect_some_attrs (istate , path , check );
11621181
11631182 for (i = 0 ; i < check -> all_attrs_nr ; i ++ ) {
11641183 const char * name = check -> all_attrs [i ].attr -> name ;
0 commit comments