]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-objects: add GIT_TEST_NAME_HASH_VERSION
authorDerrick Stolee <stolee@gmail.com>
Mon, 27 Jan 2025 19:02:31 +0000 (19:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Jan 2025 21:21:43 +0000 (13:21 -0800)
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>
builtin/pack-objects.c
t/README
t/t5300-pack-object.sh
t/t5310-pack-bitmaps.sh
t/t5333-pseudo-merge-bitmaps.sh
t/t5510-fetch.sh
t/t6020-bundle-misc.sh
t/t7406-submodule-update.sh
t/t7700-repack.sh

index d0c717e9d09024f170982580597fadcaad42343e..8ae77deb92912ad61c74f14fb2edbcfa8cd430d6 100644 (file)
@@ -266,7 +266,7 @@ struct configured_exclusion {
 static struct oidmap configured_exclusions;
 
 static struct oidset excluded_by_config;
-static int name_hash_version = 1;
+static int name_hash_version = -1;
 
 /**
  * Check whether the name_hash_version chosen by user input is appropriate,
@@ -4616,6 +4616,9 @@ int cmd_pack_objects(int argc,
        if (pack_to_stdout || !rev_list_all)
                write_bitmap_index = 0;
 
+       if (name_hash_version < 0)
+               name_hash_version = (int)git_env_ulong("GIT_TEST_NAME_HASH_VERSION", 1);
+
        validate_name_hash_version();
 
        if (use_delta_islands)
index 8c0319b58e5c8333a13f4d07a47519fa8f137709..e63d236085263bfb4e66f6bbc8a6486afd4d1438 100644 (file)
--- a/t/README
+++ b/t/README
@@ -492,6 +492,10 @@ a test and then fails then the whole test run will abort. This can help to make
 sure the expected tests are executed and not silently skipped when their
 dependency breaks or is simply not present in a new environment.
 
+GIT_TEST_NAME_HASH_VERSION=<int>, when set, causes 'git pack-objects' to
+assume '--name-hash-version=<n>'.
+
+
 Naming Tests
 ------------
 
index 4270eabe8b7c345f8be42fcded9a256df79b3e4c..97fe9e561c6bb8aee095585f22194ba550741bb4 100755 (executable)
@@ -675,15 +675,18 @@ do
 done
 
 test_expect_success 'valid and invalid --name-hash-versions' '
+       sane_unset GIT_TEST_NAME_HASH_VERSION &&
+
        # Valid values are hard to verify other than "do not fail".
        # Performance tests will be more valuable to validate these versions.
-       for value in 1 2
+       # Negative values are converted to version 1.
+       for value in -1 1 2
        do
                git pack-objects base --all --name-hash-version=$value || return 1
        done &&
 
        # Invalid values have clear post-conditions.
-       for value in -1 0 3
+       for value in 0 3
        do
                test_must_fail git pack-objects base --all --name-hash-version=$value 2>err &&
                test_grep "invalid --name-hash-version option" err || return 1
index 7044c7d7c6d0bc804fb8baff48c8d3718945c018..c30522b57fd74da561c6e1dfa24053bd7c08fbaa 100755 (executable)
@@ -420,7 +420,10 @@ test_bitmap_cases () {
                        cat >expect <<-\EOF &&
                        error: missing value for '\''pack.preferbitmaptips'\''
                        EOF
-                       git repack -adb 2>actual &&
+
+                       # Disable name hash version adjustment due to stderr comparison.
+                       GIT_TEST_NAME_HASH_VERSION=1 \
+                               git repack -adb 2>actual &&
                        test_cmp expect actual
                )
        '
index eca4a1eb8c6e56a935bb336a9cdb3272d216d4ca..971f9d2d4ee1cbaf56866413cc8aa3fb028fe433 100755 (executable)
@@ -209,7 +209,8 @@ test_expect_success 'bitmapPseudoMerge.stableThreshold creates stable groups' '
 '
 
 test_expect_success 'out of order thresholds are rejected' '
-       test_must_fail git \
+       # Disable the test var to remove a stderr message.
+       test_must_fail env GIT_TEST_NAME_HASH_VERSION=1 git \
                -c bitmapPseudoMerge.test.pattern="refs/*" \
                -c bitmapPseudoMerge.test.threshold=1.month.ago \
                -c bitmapPseudoMerge.test.stableThreshold=1.week.ago \
index 0890b9f61c56cc4b936fe1206c0378a8d5b15585..1699c3a3bb8206aecbbdeb23fddb212aefa61ce5 100755 (executable)
@@ -1062,7 +1062,12 @@ test_expect_success 'all boundary commits are excluded' '
        test_tick &&
        git merge otherside &&
        ad=$(git log --no-walk --format=%ad HEAD) &&
-       git bundle create twoside-boundary.bdl main --since="$ad" &&
+
+       # If the a different name hash function is used here, then no delta
+       # pair is found and the bundle does not expand to three objects
+       # when fixing the thin object.
+       GIT_TEST_NAME_HASH_VERSION=1 \
+               git bundle create twoside-boundary.bdl main --since="$ad" &&
        test_bundle_object_count --thin twoside-boundary.bdl 3
 '
 
index 34b5cd62c201d98bddbce451b707da2734f07bb2..a1f18ae71f17a676ace0eb185a0ebdba37979e94 100755 (executable)
@@ -247,7 +247,11 @@ test_expect_success 'create bundle with --since option' '
        EOF
        test_cmp expect actual &&
 
-       git bundle create since.bdl \
+       # If a different name hash function is used, then one fewer
+       # delta base is found and this counts a different number
+       # of objects after performing --fix-thin.
+       GIT_TEST_NAME_HASH_VERSION=1 \
+               git bundle create since.bdl \
                --since "Thu Apr 7 15:27:00 2005 -0700" \
                --all &&
 
index 0f0c86f9cb20cefb4c33ff01750a5d30790fbaf9..ebd9941075a87fef10604702220988d43454a73f 100755 (executable)
@@ -1094,7 +1094,9 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
        ) &&
        git clone super4 super5 &&
        (cd super5 &&
-        git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
+        # This test var can mess with the stderr output checked in this test.
+        GIT_TEST_NAME_HASH_VERSION=1 \
+               git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
         test_must_be_empty out &&
         test_must_be_empty err
        ) &&
index b9a5759e01d57b05d5387f7f082bb9f9ed2cf46a..16861f80c9cfb42d4d7e12e2cceafe466c8eb679 100755 (executable)
@@ -309,7 +309,10 @@ test_expect_success 'no bitmaps created if .keep files present' '
        keep=${pack%.pack}.keep &&
        test_when_finished "rm -f \"\$keep\"" &&
        >"$keep" &&
-       git -C bare.git repack -ad 2>stderr &&
+
+       # Disable --name-hash-version test due to stderr comparison.
+       GIT_TEST_NAME_HASH_VERSION=1 \
+               git -C bare.git repack -ad 2>stderr &&
        test_must_be_empty stderr &&
        find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
        test_must_be_empty actual
@@ -320,7 +323,10 @@ test_expect_success 'auto-bitmaps do not complain if unavailable' '
        blob=$(test-tool genrandom big $((1024*1024)) |
               git -C bare.git hash-object -w --stdin) &&
        git -C bare.git update-ref refs/tags/big $blob &&
-       git -C bare.git repack -ad 2>stderr &&
+
+       # Disable --name-hash-version test due to stderr comparison.
+       GIT_TEST_NAME_HASH_VERSION=1 \
+               git -C bare.git repack -ad 2>stderr &&
        test_must_be_empty stderr &&
        find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
        test_must_be_empty actual