multi-pack-index: define GIT_TEST_MULTI_PACK_INDEX
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 12 Oct 2018 17:34:20 +0000 (10:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Oct 2018 01:42:46 +0000 (10:42 +0900)
The multi-pack-index feature is tested in isolation by
t5319-multi-pack-index.sh, but there are many more interesting
scenarios in the test suite surrounding pack-file data shapes
and interactions. Since the multi-pack-index is an optional
data structure, it does not make sense to include it by default
in those tests.

Instead, add a new GIT_TEST_MULTI_PACK_INDEX environment variable
that enables core.multiPackIndex and writes a multi-pack-index
after each 'git repack' command. This adds extra test coverage
when needed.

There are a few spots in the test suite that need to react to this
change:

* t5319-multi-pack-index.sh: there is a test that checks that
'git repack' deletes the multi-pack-index. Disable the environment
variable to ensure this still happens.

* t5310-pack-bitmaps.sh: One test moves a pack-file from the object
directory to an alternate. This breaks the multi-pack-index, so
delete the multi-pack-index at this point, if it exists.

* t9300-fast-import.sh: One test verifies the number of files in
the .git/objects/pack directory is exactly 8. Exclude the
multi-pack-index from this count so it is still 8 in all cases.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/repack.c
midx.c
midx.h
t/README
t/t5310-pack-bitmaps.sh
t/t5319-multi-pack-index.sh
t/t9300-fast-import.sh
index 44965cbaa3ef3a142a89fd72403b46a9fbbc26eb..26dcccdafc5b8054f903a838d379a3a23dbc8b39 100644 (file)
@@ -553,6 +553,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        if (!no_update_server_info)
                update_server_info(0);
        remove_temporary_files();
+
+       if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
+               write_midx_file(get_object_directory());
+
        string_list_clear(&names, 0);
        string_list_clear(&rollback, 0);
        string_list_clear(&existing_packs, 0);
diff --git a/midx.c b/midx.c
index 2243c912fc8206e663614bda8acee113e9a89d8d..1a6fa96cdaab5a61a0a93742bc11f553f4f564b9 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -338,9 +338,14 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
        struct multi_pack_index *m;
        struct multi_pack_index *m_search;
        int config_value;
+       static int env_value = -1;
 
-       if (repo_config_get_bool(r, "core.multipackindex", &config_value) ||
-           !config_value)
+       if (env_value < 0)
+               env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);
+
+       if (!env_value &&
+           (repo_config_get_bool(r, "core.multipackindex", &config_value) ||
+           !config_value))
                return 0;
 
        for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
diff --git a/midx.h b/midx.h
index 7e60907596373e9ce2b9113e3ae5fed454aad0e7..228016088e7886b0118209c10c5db0a2a9b68ce6 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -3,6 +3,8 @@
 
 #include "repository.h"
 
+#define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
+
 struct multi_pack_index {
        struct multi_pack_index *next;
 
index 3ea6c854606056e1a7d9431dd59518d817768527..9d0277c338e931a1e35e70803118114b1599e929 100644 (file)
--- a/t/README
+++ b/t/README
@@ -327,6 +327,10 @@ GIT_TEST_COMMIT_GRAPH=<boolean>, when true, forces the commit-graph to
 be written after every 'git commit' command, and overrides the
 'core.commitGraph' setting to true.
 
+GIT_TEST_MULTI_PACK_INDEX=<boolean>, when true, forces the multi-pack-
+index to be written after every 'git repack' command, and overrides the
+'core.multiPackIndex' setting to true.
+
 Naming Tests
 ------------
 
index 1be3459c5b8aa331a646e3ead24f7422110cdc08..82d7f7f6a5bbdc5609e0b76c97a3ae14f6a53a92 100755 (executable)
@@ -191,6 +191,7 @@ test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pa
 
 test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
        mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
+       rm -f .git/objects/pack/multi-pack-index &&
        test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
        echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
        git index-pack 3b.pack &&
index 6f56b38674fd62085e757cbc685436107a6bb9fe..4024ff9a399edd2113fedb0f7a7bc19fbd40621f 100755 (executable)
@@ -152,7 +152,7 @@ compare_results_with_midx "twelve packs"
 
 test_expect_success 'repack removes multi-pack-index' '
        test_path_is_file $objdir/pack/multi-pack-index &&
-       git repack -adf &&
+       GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
        test_path_is_missing $objdir/pack/multi-pack-index
 '
 
index 40fe7e49767ac4e0bbe5686413ff2b667171747a..59a13b6a779b437fa377b30b2e0856f285f806b6 100755 (executable)
@@ -1558,7 +1558,7 @@ test_expect_success 'O: blank lines not necessary after other commands' '
        INPUT_END
 
        git fast-import <input &&
-       test 8 = $(find .git/objects/pack -type f | wc -l) &&
+       test 8 = $(find .git/objects/pack -type f | grep -v multi-pack-index | wc -l) &&
        test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
        git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
        test_cmp expect actual