@@ -592,7 +592,7 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
592
592
return it ;
593
593
}
594
594
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 )
596
596
{
597
597
int entries , was_valid , newfd ;
598
598
struct lock_file * lock_file ;
@@ -603,23 +603,23 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
603
603
*/
604
604
lock_file = xcalloc (1 , sizeof (struct lock_file ));
605
605
606
- newfd = hold_locked_index (lock_file , 1 );
606
+ newfd = hold_lock_file_for_update (lock_file , index_path , LOCK_DIE_ON_ERROR );
607
607
608
- entries = read_cache ( );
608
+ entries = read_index_from ( index_state , index_path );
609
609
if (entries < 0 )
610
610
return WRITE_TREE_UNREADABLE_INDEX ;
611
611
if (flags & WRITE_TREE_IGNORE_CACHE_TREE )
612
- cache_tree_free (& ( active_cache_tree ) );
612
+ cache_tree_free (& index_state -> cache_tree );
613
613
614
- if (!active_cache_tree )
615
- active_cache_tree = cache_tree ();
614
+ if (!index_state -> cache_tree )
615
+ index_state -> cache_tree = cache_tree ();
616
616
617
- was_valid = cache_tree_fully_valid (active_cache_tree );
617
+ was_valid = cache_tree_fully_valid (index_state -> cache_tree );
618
618
if (!was_valid ) {
619
- if (cache_tree_update (& the_index , flags ) < 0 )
619
+ if (cache_tree_update (index_state , flags ) < 0 )
620
620
return WRITE_TREE_UNMERGED_INDEX ;
621
621
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 ))
623
623
newfd = -1 ;
624
624
}
625
625
/* 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)
631
631
}
632
632
633
633
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 );
636
636
if (!subtree )
637
637
return WRITE_TREE_PREFIX_ERROR ;
638
638
hashcpy (sha1 , subtree -> sha1 );
639
639
}
640
640
else
641
- hashcpy (sha1 , active_cache_tree -> sha1 );
641
+ hashcpy (sha1 , index_state -> cache_tree -> sha1 );
642
642
643
643
if (0 <= newfd )
644
644
rollback_lock_file (lock_file );
645
645
646
646
return 0 ;
647
647
}
648
648
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
+
649
654
static void prime_cache_tree_rec (struct cache_tree * it , struct tree * tree )
650
655
{
651
656
struct tree_desc desc ;
0 commit comments