@@ -305,7 +305,6 @@ static void refresh_cache_or_die(int refresh_flags)
305305static char * prepare_index (int argc , const char * * argv , const char * prefix ,
306306 const struct commit * current_head , int is_status )
307307{
308- int fd ;
309308 struct string_list partial ;
310309 struct pathspec pathspec ;
311310 int refresh_flags = REFRESH_QUIET ;
@@ -321,12 +320,11 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
321320
322321 if (interactive ) {
323322 char * old_index_env = NULL ;
324- fd = hold_locked_index (& index_lock , 1 );
323+ hold_locked_index (& index_lock , 1 );
325324
326325 refresh_cache_or_die (refresh_flags );
327326
328- if (write_cache (fd , active_cache , active_nr ) ||
329- close_lock_file (& index_lock ))
327+ if (write_locked_index (& the_index , & index_lock , CLOSE_LOCK ))
330328 die (_ ("unable to create temporary index" ));
331329
332330 old_index_env = getenv (INDEX_ENVIRONMENT );
@@ -360,12 +358,11 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
360358 * (B) on failure, rollback the real index.
361359 */
362360 if (all || (also && pathspec .nr )) {
363- fd = hold_locked_index (& index_lock , 1 );
361+ hold_locked_index (& index_lock , 1 );
364362 add_files_to_cache (also ? prefix : NULL , & pathspec , 0 );
365363 refresh_cache_or_die (refresh_flags );
366364 update_main_cache_tree (WRITE_TREE_SILENT );
367- if (write_cache (fd , active_cache , active_nr ) ||
368- close_lock_file (& index_lock ))
365+ if (write_locked_index (& the_index , & index_lock , CLOSE_LOCK ))
369366 die (_ ("unable to write new_index file" ));
370367 commit_style = COMMIT_NORMAL ;
371368 return index_lock .filename ;
@@ -381,12 +378,12 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
381378 * We still need to refresh the index here.
382379 */
383380 if (!only && !pathspec .nr ) {
384- fd = hold_locked_index (& index_lock , 1 );
381+ hold_locked_index (& index_lock , 1 );
385382 refresh_cache_or_die (refresh_flags );
386383 if (active_cache_changed ) {
387384 update_main_cache_tree (WRITE_TREE_SILENT );
388- if (write_cache ( fd , active_cache , active_nr ) ||
389- commit_locked_index ( & index_lock ))
385+ if (write_locked_index ( & the_index , & index_lock ,
386+ COMMIT_LOCK ))
390387 die (_ ("unable to write new_index file" ));
391388 } else {
392389 rollback_lock_file (& index_lock );
@@ -432,24 +429,22 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
432429 if (read_cache () < 0 )
433430 die (_ ("cannot read the index" ));
434431
435- fd = hold_locked_index (& index_lock , 1 );
432+ hold_locked_index (& index_lock , 1 );
436433 add_remove_files (& partial );
437434 refresh_cache (REFRESH_QUIET );
438- if (write_cache (fd , active_cache , active_nr ) ||
439- close_lock_file (& index_lock ))
435+ if (write_locked_index (& the_index , & index_lock , CLOSE_LOCK ))
440436 die (_ ("unable to write new_index file" ));
441437
442- fd = hold_lock_file_for_update (& false_lock ,
443- git_path ("next-index-%" PRIuMAX ,
444- (uintmax_t ) getpid ()),
445- LOCK_DIE_ON_ERROR );
438+ hold_lock_file_for_update (& false_lock ,
439+ git_path ("next-index-%" PRIuMAX ,
440+ (uintmax_t ) getpid ()),
441+ LOCK_DIE_ON_ERROR );
446442
447443 create_base_index (current_head );
448444 add_remove_files (& partial );
449445 refresh_cache (REFRESH_QUIET );
450446
451- if (write_cache (fd , active_cache , active_nr ) ||
452- close_lock_file (& false_lock ))
447+ if (write_locked_index (& the_index , & false_lock , CLOSE_LOCK ))
453448 die (_ ("unable to write temporary index file" ));
454449
455450 discard_cache ();
0 commit comments