read-cache: force split index mode with GIT_TEST_SPLIT_INDEX

This could be used to run the whole test suite with split indexes. Index splitting is carried out at random. "git read-tree" also resets the index and forces splitting at the next update. I had a lot of headaches with the test suite, which proves it exercises split index pretty good. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 13, 2014 at 19:19 UTC d6e3c181bc94e3f540c403eef0515c5eed74fc16
1 file changed +9 -1
read-cache.c
+9 -1
@@ -1885,8 +1885,11 @@ static int do_write_index(struct index_state *istate, int newfd,
1885 }
1886 }
1887
1888 - if (!istate->version)
1888 + if (!istate->version) {
1889 istate->version = get_index_format_default();
1890 + if (getenv("GIT_TEST_SPLIT_INDEX"))
1891 + init_split_index(istate);
1892 + }
1893
1894 /* demote version 3 to version 2 when the latter suffices */
1895 if (istate->version == 3 || istate->version == 2)
@@ -2077,6 +2080,11 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2080 return do_write_locked_index(istate, lock, flags);
2081 }
2082
2083 + if (getenv("GIT_TEST_SPLIT_INDEX")) {
2084 + int v = si->base_sha1[0];
2085 + if ((v & 15) < 6)
2086 + istate->cache_changed |= SPLIT_INDEX_ORDERED;
2087 + }
2088 if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
2089 int ret = write_shared_index(istate, lock, flags);
2090 if (ret)