@@ -933,8 +933,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
933
933
*/
934
934
int get_sha1 (const char * name , unsigned char * sha1 )
935
935
{
936
- unsigned unused ;
937
- return get_sha1_with_mode (name , sha1 , & unused );
936
+ struct object_context unused ;
937
+ return get_sha1_with_context (name , sha1 , & unused );
938
938
}
939
939
940
940
/* Must be called only when object_name:filename doesn't exist. */
@@ -1031,12 +1031,24 @@ static void diagnose_invalid_index_path(int stage,
1031
1031
1032
1032
1033
1033
int get_sha1_with_mode_1 (const char * name , unsigned char * sha1 , unsigned * mode , int gently , const char * prefix )
1034
+ {
1035
+ struct object_context oc ;
1036
+ int ret ;
1037
+ ret = get_sha1_with_context_1 (name , sha1 , & oc , gently , prefix );
1038
+ * mode = oc .mode ;
1039
+ return ret ;
1040
+ }
1041
+
1042
+ int get_sha1_with_context_1 (const char * name , unsigned char * sha1 ,
1043
+ struct object_context * oc ,
1044
+ int gently , const char * prefix )
1034
1045
{
1035
1046
int ret , bracket_depth ;
1036
1047
int namelen = strlen (name );
1037
1048
const char * cp ;
1038
1049
1039
- * mode = S_IFINVALID ;
1050
+ memset (oc , 0 , sizeof (* oc ));
1051
+ oc -> mode = S_IFINVALID ;
1040
1052
ret = get_sha1_1 (name , namelen , sha1 );
1041
1053
if (!ret )
1042
1054
return ret ;
@@ -1059,6 +1071,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1059
1071
cp = name + 3 ;
1060
1072
}
1061
1073
namelen = namelen - (cp - name );
1074
+
1075
+ strncpy (oc -> path , cp ,
1076
+ sizeof (oc -> path ));
1077
+ oc -> path [sizeof (oc -> path )- 1 ] = '\0' ;
1078
+
1062
1079
if (!active_cache )
1063
1080
read_cache ();
1064
1081
pos = cache_name_pos (cp , namelen );
@@ -1071,7 +1088,6 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1071
1088
break ;
1072
1089
if (ce_stage (ce ) == stage ) {
1073
1090
hashcpy (sha1 , ce -> sha1 );
1074
- * mode = ce -> ce_mode ;
1075
1091
return 0 ;
1076
1092
}
1077
1093
pos ++ ;
@@ -1098,12 +1114,17 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1098
1114
}
1099
1115
if (!get_sha1_1 (name , cp - name , tree_sha1 )) {
1100
1116
const char * filename = cp + 1 ;
1101
- ret = get_tree_entry (tree_sha1 , filename , sha1 , mode );
1117
+ ret = get_tree_entry (tree_sha1 , filename , sha1 , & oc -> mode );
1102
1118
if (!gently ) {
1103
1119
diagnose_invalid_sha1_path (prefix , filename ,
1104
1120
tree_sha1 , object_name );
1105
1121
free (object_name );
1106
1122
}
1123
+ hashcpy (oc -> tree , tree_sha1 );
1124
+ strncpy (oc -> path , filename ,
1125
+ sizeof (oc -> path ));
1126
+ oc -> path [sizeof (oc -> path )- 1 ] = '\0' ;
1127
+
1107
1128
return ret ;
1108
1129
} else {
1109
1130
if (!gently )
0 commit comments