@@ -253,6 +253,7 @@ static int write_entry(struct cache_entry *ce,
253
253
char * path , const struct checkout * state , int to_tempfile )
254
254
{
255
255
unsigned int ce_mode_s_ifmt = ce -> ce_mode & S_IFMT ;
256
+ struct delayed_checkout * dco = state -> delayed_checkout ;
256
257
int fd , ret , fstat_done = 0 ;
257
258
char * new ;
258
259
struct strbuf buf = STRBUF_INIT ;
@@ -273,55 +274,65 @@ static int write_entry(struct cache_entry *ce,
273
274
}
274
275
275
276
switch (ce_mode_s_ifmt ) {
276
- case S_IFREG :
277
277
case S_IFLNK :
278
278
new = read_blob_entry (ce , & size );
279
279
if (!new )
280
280
return error ("unable to read sha1 file of %s (%s)" ,
281
- path , oid_to_hex (& ce -> oid ));
281
+ path , oid_to_hex (& ce -> oid ));
282
282
283
- if (ce_mode_s_ifmt == S_IFLNK && has_symlinks && !to_tempfile ) {
284
- ret = symlink (new , path );
285
- free (new );
286
- if (ret )
287
- return error_errno ("unable to create symlink %s" ,
288
- path );
289
- break ;
283
+ /*
284
+ * We can't make a real symlink; write out a regular file entry
285
+ * with the symlink destination as its contents.
286
+ */
287
+ if (!has_symlinks || to_tempfile )
288
+ goto write_file_entry ;
289
+
290
+ ret = symlink (new , path );
291
+ free (new );
292
+ if (ret )
293
+ return error_errno ("unable to create symlink %s" , path );
294
+ break ;
295
+
296
+ case S_IFREG :
297
+ /*
298
+ * We do not send the blob in case of a retry, so do not
299
+ * bother reading it at all.
300
+ */
301
+ if (dco && dco -> state == CE_RETRY ) {
302
+ new = NULL ;
303
+ size = 0 ;
304
+ } else {
305
+ new = read_blob_entry (ce , & size );
306
+ if (!new )
307
+ return error ("unable to read sha1 file of %s (%s)" ,
308
+ path , oid_to_hex (& ce -> oid ));
290
309
}
291
310
292
311
/*
293
312
* Convert from git internal format to working tree format
294
313
*/
295
- if (ce_mode_s_ifmt == S_IFREG ) {
296
- struct delayed_checkout * dco = state -> delayed_checkout ;
297
- if (dco && dco -> state != CE_NO_DELAY ) {
298
- /* Do not send the blob in case of a retry. */
299
- if (dco -> state == CE_RETRY ) {
300
- new = NULL ;
301
- size = 0 ;
302
- }
303
- ret = async_convert_to_working_tree (
304
- ce -> name , new , size , & buf , dco );
305
- if (ret && string_list_has_string (& dco -> paths , ce -> name )) {
306
- free (new );
307
- goto finish ;
308
- }
309
- } else
310
- ret = convert_to_working_tree (
311
- ce -> name , new , size , & buf );
312
-
313
- if (ret ) {
314
+ if (dco && dco -> state != CE_NO_DELAY ) {
315
+ ret = async_convert_to_working_tree (ce -> name , new ,
316
+ size , & buf , dco );
317
+ if (ret && string_list_has_string (& dco -> paths , ce -> name )) {
314
318
free (new );
315
- new = strbuf_detach (& buf , & newsize );
316
- size = newsize ;
319
+ goto delayed ;
317
320
}
318
- /*
319
- * No "else" here as errors from convert are OK at this
320
- * point. If the error would have been fatal (e.g.
321
- * filter is required), then we would have died already.
322
- */
321
+ } else
322
+ ret = convert_to_working_tree (ce -> name , new , size , & buf );
323
+
324
+ if (ret ) {
325
+ free (new );
326
+ new = strbuf_detach (& buf , & newsize );
327
+ size = newsize ;
323
328
}
329
+ /*
330
+ * No "else" here as errors from convert are OK at this
331
+ * point. If the error would have been fatal (e.g.
332
+ * filter is required), then we would have died already.
333
+ */
324
334
335
+ write_file_entry :
325
336
fd = open_output_fd (path , ce , to_tempfile );
326
337
if (fd < 0 ) {
327
338
free (new );
@@ -336,6 +347,7 @@ static int write_entry(struct cache_entry *ce,
336
347
if (wrote < 0 )
337
348
return error ("unable to write file %s" , path );
338
349
break ;
350
+
339
351
case S_IFGITLINK :
340
352
if (to_tempfile )
341
353
return error ("cannot create temporary submodule %s" , path );
@@ -347,6 +359,7 @@ static int write_entry(struct cache_entry *ce,
347
359
NULL , oid_to_hex (& ce -> oid ),
348
360
state -> force ? SUBMODULE_MOVE_HEAD_FORCE : 0 );
349
361
break ;
362
+
350
363
default :
351
364
return error ("unknown file mode for %s in index" , path );
352
365
}
@@ -355,11 +368,14 @@ static int write_entry(struct cache_entry *ce,
355
368
if (state -> refresh_cache ) {
356
369
assert (state -> istate );
357
370
if (!fstat_done )
358
- lstat (ce -> name , & st );
371
+ if (lstat (ce -> name , & st ) < 0 )
372
+ return error_errno ("unable to stat just-written file %s" ,
373
+ ce -> name );
359
374
fill_stat_cache_info (ce , & st );
360
375
ce -> ce_flags |= CE_UPDATE_IN_BASE ;
361
376
state -> istate -> cache_changed |= CE_ENTRY_CHANGED ;
362
377
}
378
+ delayed :
363
379
return 0 ;
364
380
}
365
381
0 commit comments