pack-objects: create GIT_TEST_PACK_SPARSE

Create a test variable GIT_TEST_PACK_SPARSE to enable the sparse object walk algorithm by default during the test suite. Enabling this variable ensures coverage in many interesting cases, such as shallow clones, partial clones, and missing objects. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 16, 2019 at 10:26 UTC 99dbbfa8ddbba2b620965d026d4ec199b8837a6f
3 files changed +7 -2
builtin/pack-objects.c
+1
@@ -3331,6 +3331,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3331
3332 read_replace_refs = 0;
3333
3334 + sparse = git_env_bool("GIT_TEST_PACK_SPARSE", 0);
3335 reset_pack_idx_option(&pack_idx_opts);
3336 git_config(git_pack_config, NULL);
3337
t/README
+4
@@ -342,6 +342,10 @@ GIT_TEST_INDEX_VERSION=<n> exercises the index read/write code path
342 for the index version specified. Can be set to any valid version
343 (currently 2, 3, or 4).
344
345 +GIT_TEST_PACK_SPARSE=<boolean> if enabled will default the pack-objects
346 +builtin to use the sparse object walk. This can still be overridden by
347 +the --no-sparse command-line argument.
348 +
349 GIT_TEST_PRELOAD_INDEX=<boolean> exercises the preload-index code path
350 by overriding the minimum number of cache entries required per thread.
351
t/t5322-pack-objects-sparse.sh
+2 -2
@@ -36,7 +36,7 @@ test_expect_success 'setup repo' '
36 '
37
38 test_expect_success 'non-sparse pack-objects' '
39 - git pack-objects --stdout --revs <packinput.txt >nonsparse.pack &&
39 + git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
40 git index-pack -o nonsparse.idx nonsparse.pack &&
41 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
42 test_cmp expect_objects.txt nonsparse_objects.txt
@@ -64,7 +64,7 @@ test_expect_success 'duplicate a folder from f3 and commit to topic1' '
64 '
65
66 test_expect_success 'non-sparse pack-objects' '
67 - git pack-objects --stdout --revs <packinput.txt >nonsparse.pack &&
67 + git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
68 git index-pack -o nonsparse.idx nonsparse.pack &&
69 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
70 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&