read-cache: force split index mode with GIT_TEST_SPLIT_INDEX
[gitweb.git] / read-cache.c
index 8ecb9599e58d3e08e6cf84f3d5403eae59d1e997..12335a362b035340118dd8e0b202a95ad16d9b00 100644 (file)
@@ -1885,8 +1885,11 @@ static int do_write_index(struct index_state *istate, int newfd,
                }
        }
 
-       if (!istate->version)
+       if (!istate->version) {
                istate->version = get_index_format_default();
+               if (getenv("GIT_TEST_SPLIT_INDEX"))
+                       init_split_index(istate);
+       }
 
        /* demote version 3 to version 2 when the latter suffices */
        if (istate->version == 3 || istate->version == 2)
@@ -2030,14 +2033,21 @@ static void remove_temporary_sharedindex_on_signal(int signo)
        raise(signo);
 }
 
-static int write_shared_index(struct index_state *istate)
+static int write_shared_index(struct index_state *istate,
+                             struct lock_file *lock, unsigned flags)
 {
        struct split_index *si = istate->split_index;
        static int installed_handler;
        int fd, ret;
 
        temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
-       fd = xmkstemp(temporary_sharedindex);
+       fd = mkstemp(temporary_sharedindex);
+       if (fd < 0) {
+               free(temporary_sharedindex);
+               temporary_sharedindex = NULL;
+               hashclr(si->base_sha1);
+               return do_write_locked_index(istate, lock, flags);
+       }
        if (!installed_handler) {
                atexit(remove_temporary_sharedindex);
                sigchain_push_common(remove_temporary_sharedindex_on_signal);
@@ -2063,14 +2073,20 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
 {
        struct split_index *si = istate->split_index;
 
-       if (!si || (istate->cache_changed & ~EXTMASK)) {
+       if (!si || alternate_index_output ||
+           (istate->cache_changed & ~EXTMASK)) {
                if (si)
                        hashclr(si->base_sha1);
                return do_write_locked_index(istate, lock, flags);
        }
 
+       if (getenv("GIT_TEST_SPLIT_INDEX")) {
+               int v = si->base_sha1[0];
+               if ((v & 15) < 6)
+                       istate->cache_changed |= SPLIT_INDEX_ORDERED;
+       }
        if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
-               int ret = write_shared_index(istate);
+               int ret = write_shared_index(istate, lock, flags);
                if (ret)
                        return ret;
        }