@@ -1137,7 +1137,8 @@ int get_sha1_blob(const char *name, unsigned char *sha1)
1137
1137
static void diagnose_invalid_sha1_path (const char * prefix ,
1138
1138
const char * filename ,
1139
1139
const unsigned char * tree_sha1 ,
1140
- const char * object_name )
1140
+ const char * object_name ,
1141
+ int object_name_len )
1141
1142
{
1142
1143
struct stat st ;
1143
1144
unsigned char sha1 [20 ];
@@ -1147,8 +1148,8 @@ static void diagnose_invalid_sha1_path(const char *prefix,
1147
1148
prefix = "" ;
1148
1149
1149
1150
if (!lstat (filename , & st ))
1150
- die ("Path '%s' exists on disk, but not in '%s'." ,
1151
- filename , object_name );
1151
+ die ("Path '%s' exists on disk, but not in '%.* s'." ,
1152
+ filename , object_name_len , object_name );
1152
1153
if (errno == ENOENT || errno == ENOTDIR ) {
1153
1154
char * fullname = xmalloc (strlen (filename )
1154
1155
+ strlen (prefix ) + 1 );
@@ -1158,16 +1159,16 @@ static void diagnose_invalid_sha1_path(const char *prefix,
1158
1159
if (!get_tree_entry (tree_sha1 , fullname ,
1159
1160
sha1 , & mode )) {
1160
1161
die ("Path '%s' exists, but not '%s'.\n"
1161
- "Did you mean '%s:%s' aka '%s:./%s'?" ,
1162
+ "Did you mean '%.* s:%s' aka '%.* s:./%s'?" ,
1162
1163
fullname ,
1163
1164
filename ,
1164
- object_name ,
1165
+ object_name_len , object_name ,
1165
1166
fullname ,
1166
- object_name ,
1167
+ object_name_len , object_name ,
1167
1168
filename );
1168
1169
}
1169
- die ("Path '%s' does not exist in '%s'" ,
1170
- filename , object_name );
1170
+ die ("Path '%s' does not exist in '%.* s'" ,
1171
+ filename , object_name_len , object_name );
1171
1172
}
1172
1173
}
1173
1174
@@ -1332,13 +1333,8 @@ static int get_sha1_with_context_1(const char *name,
1332
1333
}
1333
1334
if (* cp == ':' ) {
1334
1335
unsigned char tree_sha1 [20 ];
1335
- char * object_name = NULL ;
1336
- if (only_to_die ) {
1337
- object_name = xmalloc (cp - name + 1 );
1338
- strncpy (object_name , name , cp - name );
1339
- object_name [cp - name ] = '\0' ;
1340
- }
1341
- if (!get_sha1_1 (name , cp - name , tree_sha1 , GET_SHA1_TREEISH )) {
1336
+ int len = cp - name ;
1337
+ if (!get_sha1_1 (name , len , tree_sha1 , GET_SHA1_TREEISH )) {
1342
1338
const char * filename = cp + 1 ;
1343
1339
char * new_filename = NULL ;
1344
1340
@@ -1348,8 +1344,8 @@ static int get_sha1_with_context_1(const char *name,
1348
1344
ret = get_tree_entry (tree_sha1 , filename , sha1 , & oc -> mode );
1349
1345
if (ret && only_to_die ) {
1350
1346
diagnose_invalid_sha1_path (prefix , filename ,
1351
- tree_sha1 , object_name );
1352
- free ( object_name );
1347
+ tree_sha1 ,
1348
+ name , len );
1353
1349
}
1354
1350
hashcpy (oc -> tree , tree_sha1 );
1355
1351
strncpy (oc -> path , filename ,
@@ -1360,7 +1356,7 @@ static int get_sha1_with_context_1(const char *name,
1360
1356
return ret ;
1361
1357
} else {
1362
1358
if (only_to_die )
1363
- die ("Invalid object name '%s'." , object_name );
1359
+ die ("Invalid object name '%.* s'." , len , name );
1364
1360
}
1365
1361
}
1366
1362
return ret ;
0 commit comments