@@ -1603,7 +1603,7 @@ int hold_locked_index(struct lock_file *lk, int lock_flags)
16031603
16041604int read_index (struct index_state * istate )
16051605{
1606- return read_index_from (istate , get_index_file ());
1606+ return read_index_from (istate , get_index_file (), get_git_dir () );
16071607}
16081608
16091609static struct cache_entry * cache_entry_from_ondisk (struct ondisk_cache_entry * ondisk ,
@@ -1863,20 +1863,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
18631863 * This way, shared index can be removed if they have not been used
18641864 * for some time.
18651865 */
1866- static void freshen_shared_index (char * base_sha1_hex , int warn )
1866+ static void freshen_shared_index (const char * shared_index , int warn )
18671867{
1868- char * shared_index = git_pathdup ("sharedindex.%s" , base_sha1_hex );
18691868 if (!check_and_freshen_file (shared_index , 1 ) && warn )
18701869 warning ("could not freshen shared index '%s'" , shared_index );
1871- free (shared_index );
18721870}
18731871
1874- int read_index_from (struct index_state * istate , const char * path )
1872+ int read_index_from (struct index_state * istate , const char * path ,
1873+ const char * gitdir )
18751874{
18761875 struct split_index * split_index ;
18771876 int ret ;
18781877 char * base_sha1_hex ;
1879- const char * base_path ;
1878+ char * base_path ;
18801879
18811880 /* istate->initialized covers both .git/index and .git/sharedindex.xxx */
18821881 if (istate -> initialized )
@@ -1896,16 +1895,17 @@ int read_index_from(struct index_state *istate, const char *path)
18961895 split_index -> base = xcalloc (1 , sizeof (* split_index -> base ));
18971896
18981897 base_sha1_hex = sha1_to_hex (split_index -> base_sha1 );
1899- base_path = git_path ( " sharedindex.%s" , base_sha1_hex );
1898+ base_path = xstrfmt ( "%s/ sharedindex.%s", gitdir , base_sha1_hex );
19001899 ret = do_read_index (split_index -> base , base_path , 1 );
19011900 if (hashcmp (split_index -> base_sha1 , split_index -> base -> sha1 ))
19021901 die ("broken index, expect %s in %s, got %s" ,
19031902 base_sha1_hex , base_path ,
19041903 sha1_to_hex (split_index -> base -> sha1 ));
19051904
1906- freshen_shared_index (base_sha1_hex , 0 );
1905+ freshen_shared_index (base_path , 0 );
19071906 merge_base_index (istate );
19081907 post_read_index_from (istate );
1908+ free (base_path );
19091909 return ret ;
19101910}
19111911
@@ -2243,7 +2243,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
22432243 struct stat st ;
22442244 struct ondisk_cache_entry_extended ondisk ;
22452245 struct strbuf previous_name_buf = STRBUF_INIT , * previous_name ;
2246- int drop_cache_tree = 0 ;
2246+ int drop_cache_tree = istate -> drop_cache_tree ;
22472247
22482248 for (i = removed = extended = 0 ; i < entries ; i ++ ) {
22492249 if (cache [i ]-> ce_flags & CE_REMOVE )
@@ -2573,8 +2573,11 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
25732573 ret = write_split_index (istate , lock , flags );
25742574
25752575 /* Freshen the shared index only if the split-index was written */
2576- if (!ret && !new_shared_index )
2577- freshen_shared_index (sha1_to_hex (si -> base_sha1 ), 1 );
2576+ if (!ret && !new_shared_index ) {
2577+ const char * shared_index = git_path ("sharedindex.%s" ,
2578+ sha1_to_hex (si -> base_sha1 ));
2579+ freshen_shared_index (shared_index , 1 );
2580+ }
25782581
25792582out :
25802583 if (flags & COMMIT_LOCK )
0 commit comments