pack-objects: add GIT_TEST_NAME_HASH_VERSION

Add a new environment variable to opt-in to different values of the --name-hash-version=<n> option in 'git pack-objects'. This allows for extra testing of the feature without repeating all of the test scenarios. Unlike many GIT_TEST_* variables, we are choosing to not add this to the linux-TEST-vars CI build as that test run is already overloaded. The behavior exposed by this test variable is of low risk and should be sufficient to allow manual testing when an issue arises. But this option isn't free. There are a few tests that change behavior with the variable enabled. First, there are a few tests that are very sensitive to certain delta bases being picked. These are both involving the generation of thin bundles and then counting their objects via 'git index-pack --fix-thin' which pulls the delta base into the new packfile. For these tests, disable the option as a decent long-term option. Second, there are some tests that compare the exact output of a 'git pack-objects' process when using bitmaps. The warning that ignores the --name-hash-version=2 and forces version 1 causes these tests to fail. Disable the environment variable to get around this issue. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 27, 2025 at 19:02 UTC ce961135ccf5bc008b8160404cc7c995789b942e
9 files changed +41 -10
builtin/pack-objects.c
+4 -1
@@ -266,7 +266,7 @@ struct configured_exclusion {
266 static struct oidmap configured_exclusions;
267
268 static struct oidset excluded_by_config;
269 -static int name_hash_version = 1;
269 +static int name_hash_version = -1;
270
271 /**
272 * Check whether the name_hash_version chosen by user input is appropriate,
@@ -4616,6 +4616,9 @@ int cmd_pack_objects(int argc,
4616 if (pack_to_stdout || !rev_list_all)
4617 write_bitmap_index = 0;
4618
4619 + if (name_hash_version < 0)
4620 + name_hash_version = (int)git_env_ulong("GIT_TEST_NAME_HASH_VERSION", 1);
4621 +
4622 validate_name_hash_version();
4623
4624 if (use_delta_islands)
t/README
+4
@@ -492,6 +492,10 @@ a test and then fails then the whole test run will abort. This can help to make
492 sure the expected tests are executed and not silently skipped when their
493 dependency breaks or is simply not present in a new environment.
494
495 +GIT_TEST_NAME_HASH_VERSION=<int>, when set, causes 'git pack-objects' to
496 +assume '--name-hash-version=<n>'.
497 +
498 +
499 Naming Tests
500 ------------
501
t/t5300-pack-object.sh
+5 -2
@@ -675,15 +675,18 @@ do
675 done
676
677 test_expect_success 'valid and invalid --name-hash-versions' '
678 + sane_unset GIT_TEST_NAME_HASH_VERSION &&
679 +
680 # Valid values are hard to verify other than "do not fail".
681 # Performance tests will be more valuable to validate these versions.
680 - for value in 1 2
682 + # Negative values are converted to version 1.
683 + for value in -1 1 2
684 do
685 git pack-objects base --all --name-hash-version=$value || return 1
686 done &&
687
688 # Invalid values have clear post-conditions.
686 - for value in -1 0 3
689 + for value in 0 3
690 do
691 test_must_fail git pack-objects base --all --name-hash-version=$value 2>err &&
692 test_grep "invalid --name-hash-version option" err || return 1
t/t5310-pack-bitmaps.sh
+4 -1
@@ -420,7 +420,10 @@ test_bitmap_cases () {
420 cat >expect <<-\EOF &&
421 error: missing value for '\''pack.preferbitmaptips'\''
422 EOF
423 - git repack -adb 2>actual &&
423 +
424 + # Disable name hash version adjustment due to stderr comparison.
425 + GIT_TEST_NAME_HASH_VERSION=1 \
426 + git repack -adb 2>actual &&
427 test_cmp expect actual
428 )
429 '
t/t5333-pseudo-merge-bitmaps.sh
+2 -1
@@ -209,7 +209,8 @@ test_expect_success 'bitmapPseudoMerge.stableThreshold creates stable groups' '
209 '
210
211 test_expect_success 'out of order thresholds are rejected' '
212 - test_must_fail git \
212 + # Disable the test var to remove a stderr message.
213 + test_must_fail env GIT_TEST_NAME_HASH_VERSION=1 git \
214 -c bitmapPseudoMerge.test.pattern="refs/*" \
215 -c bitmapPseudoMerge.test.threshold=1.month.ago \
216 -c bitmapPseudoMerge.test.stableThreshold=1.week.ago \
t/t5510-fetch.sh
+6 -1
@@ -1062,7 +1062,12 @@ test_expect_success 'all boundary commits are excluded' '
1062 test_tick &&
1063 git merge otherside &&
1064 ad=$(git log --no-walk --format=%ad HEAD) &&
1065 - git bundle create twoside-boundary.bdl main --since="$ad" &&
1065 +
1066 + # If the a different name hash function is used here, then no delta
1067 + # pair is found and the bundle does not expand to three objects
1068 + # when fixing the thin object.
1069 + GIT_TEST_NAME_HASH_VERSION=1 \
1070 + git bundle create twoside-boundary.bdl main --since="$ad" &&
1071 test_bundle_object_count --thin twoside-boundary.bdl 3
1072 '
1073
t/t6020-bundle-misc.sh
+5 -1
@@ -247,7 +247,11 @@ test_expect_success 'create bundle with --since option' '
247 EOF
248 test_cmp expect actual &&
249
250 - git bundle create since.bdl \
250 + # If a different name hash function is used, then one fewer
251 + # delta base is found and this counts a different number
252 + # of objects after performing --fix-thin.
253 + GIT_TEST_NAME_HASH_VERSION=1 \
254 + git bundle create since.bdl \
255 --since "Thu Apr 7 15:27:00 2005 -0700" \
256 --all &&
257
t/t7406-submodule-update.sh
+3 -1
@@ -1094,7 +1094,9 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
1094 ) &&
1095 git clone super4 super5 &&
1096 (cd super5 &&
1097 - git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
1097 + # This test var can mess with the stderr output checked in this test.
1098 + GIT_TEST_NAME_HASH_VERSION=1 \
1099 + git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
1100 test_must_be_empty out &&
1101 test_must_be_empty err
1102 ) &&
t/t7700-repack.sh
+8 -2
@@ -309,7 +309,10 @@ test_expect_success 'no bitmaps created if .keep files present' '
309 keep=${pack%.pack}.keep &&
310 test_when_finished "rm -f \"\$keep\"" &&
311 >"$keep" &&
312 - git -C bare.git repack -ad 2>stderr &&
312 +
313 + # Disable --name-hash-version test due to stderr comparison.
314 + GIT_TEST_NAME_HASH_VERSION=1 \
315 + git -C bare.git repack -ad 2>stderr &&
316 test_must_be_empty stderr &&
317 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
318 test_must_be_empty actual
@@ -320,7 +323,10 @@ test_expect_success 'auto-bitmaps do not complain if unavailable' '
323 blob=$(test-tool genrandom big $((1024*1024)) |
324 git -C bare.git hash-object -w --stdin) &&
325 git -C bare.git update-ref refs/tags/big $blob &&
323 - git -C bare.git repack -ad 2>stderr &&
326 +
327 + # Disable --name-hash-version test due to stderr comparison.
328 + GIT_TEST_NAME_HASH_VERSION=1 \
329 + git -C bare.git repack -ad 2>stderr &&
330 test_must_be_empty stderr &&
331 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
332 test_must_be_empty actual