@@ -592,7 +592,7 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
592592 return it ;
593593}
594594
595- int write_cache_as_tree (unsigned char * sha1 , int flags , const char * prefix )
595+ int write_index_as_tree (unsigned char * sha1 , struct index_state * index_state , const char * index_path , int flags , const char * prefix )
596596{
597597 int entries , was_valid , newfd ;
598598 struct lock_file * lock_file ;
@@ -603,23 +603,23 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
603603 */
604604 lock_file = xcalloc (1 , sizeof (struct lock_file ));
605605
606- newfd = hold_locked_index (lock_file , 1 );
606+ newfd = hold_lock_file_for_update (lock_file , index_path , LOCK_DIE_ON_ERROR );
607607
608- entries = read_cache ( );
608+ entries = read_index_from ( index_state , index_path );
609609 if (entries < 0 )
610610 return WRITE_TREE_UNREADABLE_INDEX ;
611611 if (flags & WRITE_TREE_IGNORE_CACHE_TREE )
612- cache_tree_free (& ( active_cache_tree ) );
612+ cache_tree_free (& index_state -> cache_tree );
613613
614- if (!active_cache_tree )
615- active_cache_tree = cache_tree ();
614+ if (!index_state -> cache_tree )
615+ index_state -> cache_tree = cache_tree ();
616616
617- was_valid = cache_tree_fully_valid (active_cache_tree );
617+ was_valid = cache_tree_fully_valid (index_state -> cache_tree );
618618 if (!was_valid ) {
619- if (cache_tree_update (& the_index , flags ) < 0 )
619+ if (cache_tree_update (index_state , flags ) < 0 )
620620 return WRITE_TREE_UNMERGED_INDEX ;
621621 if (0 <= newfd ) {
622- if (!write_locked_index (& the_index , lock_file , COMMIT_LOCK ))
622+ if (!write_locked_index (index_state , lock_file , COMMIT_LOCK ))
623623 newfd = -1 ;
624624 }
625625 /* Not being able to write is fine -- we are only interested
@@ -631,21 +631,26 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
631631 }
632632
633633 if (prefix ) {
634- struct cache_tree * subtree =
635- cache_tree_find (active_cache_tree , prefix );
634+ struct cache_tree * subtree ;
635+ subtree = cache_tree_find (index_state -> cache_tree , prefix );
636636 if (!subtree )
637637 return WRITE_TREE_PREFIX_ERROR ;
638638 hashcpy (sha1 , subtree -> sha1 );
639639 }
640640 else
641- hashcpy (sha1 , active_cache_tree -> sha1 );
641+ hashcpy (sha1 , index_state -> cache_tree -> sha1 );
642642
643643 if (0 <= newfd )
644644 rollback_lock_file (lock_file );
645645
646646 return 0 ;
647647}
648648
649+ int write_cache_as_tree (unsigned char * sha1 , int flags , const char * prefix )
650+ {
651+ return write_index_as_tree (sha1 , & the_index , get_index_file (), flags , prefix );
652+ }
653+
649654static void prime_cache_tree_rec (struct cache_tree * it , struct tree * tree )
650655{
651656 struct tree_desc desc ;
0 commit comments