@@ -297,6 +297,19 @@ static char *get_symlink(const struct object_id *oid, const char *path)
297
297
return data ;
298
298
}
299
299
300
+ static int checkout_path (unsigned mode , struct object_id * oid ,
301
+ const char * path , const struct checkout * state )
302
+ {
303
+ struct cache_entry * ce ;
304
+ int ret ;
305
+
306
+ ce = make_cache_entry (mode , oid -> hash , path , 0 , 0 );
307
+ ret = checkout_entry (ce , state , NULL );
308
+
309
+ free (ce );
310
+ return ret ;
311
+ }
312
+
300
313
static int run_dir_diff (const char * extcmd , int symlinks , const char * prefix ,
301
314
int argc , const char * * argv )
302
315
{
@@ -305,8 +318,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
305
318
struct strbuf rpath = STRBUF_INIT , buf = STRBUF_INIT ;
306
319
struct strbuf ldir = STRBUF_INIT , rdir = STRBUF_INIT ;
307
320
struct strbuf wtdir = STRBUF_INIT ;
321
+ char * lbase_dir , * rbase_dir ;
308
322
size_t ldir_len , rdir_len , wtdir_len ;
309
- struct cache_entry * ce = xcalloc (1 , sizeof (ce ) + PATH_MAX + 1 );
310
323
const char * workdir , * tmp ;
311
324
int ret = 0 , i ;
312
325
FILE * fp ;
@@ -339,11 +352,11 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
339
352
memset (& wtindex , 0 , sizeof (wtindex ));
340
353
341
354
memset (& lstate , 0 , sizeof (lstate ));
342
- lstate .base_dir = ldir .buf ;
355
+ lstate .base_dir = lbase_dir = xstrdup ( ldir .buf ) ;
343
356
lstate .base_dir_len = ldir .len ;
344
357
lstate .force = 1 ;
345
358
memset (& rstate , 0 , sizeof (rstate ));
346
- rstate .base_dir = rdir .buf ;
359
+ rstate .base_dir = rbase_dir = xstrdup ( rdir .buf ) ;
347
360
rstate .base_dir_len = rdir .len ;
348
361
rstate .force = 1 ;
349
362
@@ -377,7 +390,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
377
390
struct object_id loid , roid ;
378
391
char status ;
379
392
const char * src_path , * dst_path ;
380
- size_t src_path_len , dst_path_len ;
381
393
382
394
if (starts_with (info .buf , "::" ))
383
395
die (N_ ("combined diff formats('-c' and '--cc') are "
@@ -390,17 +402,14 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
390
402
if (strbuf_getline_nul (& lpath , fp ))
391
403
break ;
392
404
src_path = lpath .buf ;
393
- src_path_len = lpath .len ;
394
405
395
406
i ++ ;
396
407
if (status != 'C' && status != 'R' ) {
397
408
dst_path = src_path ;
398
- dst_path_len = src_path_len ;
399
409
} else {
400
410
if (strbuf_getline_nul (& rpath , fp ))
401
411
break ;
402
412
dst_path = rpath .buf ;
403
- dst_path_len = rpath .len ;
404
413
}
405
414
406
415
if (S_ISGITLINK (lmode ) || S_ISGITLINK (rmode )) {
@@ -430,11 +439,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
430
439
}
431
440
432
441
if (lmode && status != 'C' ) {
433
- ce -> ce_mode = lmode ;
434
- oidcpy (& ce -> oid , & loid );
435
- strcpy (ce -> name , src_path );
436
- ce -> ce_namelen = src_path_len ;
437
- if (checkout_entry (ce , & lstate , NULL ))
442
+ if (checkout_path (lmode , & loid , src_path , & lstate ))
438
443
return error ("could not write '%s'" , src_path );
439
444
}
440
445
@@ -451,11 +456,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
451
456
hashmap_add (& working_tree_dups , entry );
452
457
453
458
if (!use_wt_file (workdir , dst_path , & roid )) {
454
- ce -> ce_mode = rmode ;
455
- oidcpy (& ce -> oid , & roid );
456
- strcpy (ce -> name , dst_path );
457
- ce -> ce_namelen = dst_path_len ;
458
- if (checkout_entry (ce , & rstate , NULL ))
459
+ if (checkout_path (rmode , & roid , dst_path , & rstate ))
459
460
return error ("could not write '%s'" ,
460
461
dst_path );
461
462
} else if (!is_null_oid (& roid )) {
@@ -625,7 +626,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
625
626
exit_cleanup (tmpdir , rc );
626
627
627
628
finish :
628
- free (ce );
629
+ free (lbase_dir );
630
+ free (rbase_dir );
629
631
strbuf_release (& ldir );
630
632
strbuf_release (& rdir );
631
633
strbuf_release (& wtdir );
0 commit comments