]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: allow specifying compatibility hash
authorbrian m. carlson <sandals@crustytoothpaste.net>
Thu, 2 Oct 2025 22:38:54 +0000 (22:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Oct 2025 16:58:54 +0000 (09:58 -0700)
We want to specify a compatibility hash for testing interactions for
SHA-256 repositories where we have SHA-1 compatibility enabled.  Allow
the user to specify this scenario in the test suite by setting
GIT_TEST_DEFAULT_HASH to "sha256:sha1".

Note that this will get passed into GIT_DEFAULT_HASH, which Git itself
does not presently support.  However, we will support this in a future
commit.

Since we'll now want to know the value for a specific version, let's add
the ability to specify either the storage hash (in this case, SHA-256)
or the compatibility hash (SHA-1).  We use a different value for the
compatibility hash that will be enabled for all repositories
(test_repo_compat_hash_algo) versus the one that is used individually in
some tests (test_compat_hash_algo), since we want to still run those
individual tests without requiring that the testsuite be run fully in a
compatibility mode.

In some cases, we'll need to adjust our test suite to work in a proper
way with a compatibility hash.  For example, in such a case, we'll only
use pack index v3, since v1 and v2 lack support for multiple algorithms.
Since we won't want to write those older formats, we'll need to skip
tests that do so.  Let's add a COMPAT_HASH prerequisite for this
purpose.

Finally, in this scenario, we can no longer rely on having broken
objects work since we lack compatibility mappings to rewrite objects in
the repository.  Add a prerequisite, BROKEN_OBJECTS, that we define in
terms of COMPAT_HASH and checks to see if creating deliberately broken
objects is possible, so that we can disable these tests if not.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib-functions.sh
t/test-lib.sh

index a28de7b19bc001b0ae4494b243f7afda82037a32..52d7759bf5762d03b2f6125c6b54297cb742520f 100644 (file)
@@ -1708,11 +1708,16 @@ test_set_hash () {
 # Detect the hash algorithm in use.
 test_detect_hash () {
        case "${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}" in
-       "sha256")
+       *:*)
+           test_hash_algo="${GIT_TEST_DEFAULT_HASH%%:*}"
+           test_compat_hash_algo="${GIT_TEST_DEFAULT_HASH##*:}"
+           test_repo_compat_hash_algo="$test_compat_hash_algo"
+           ;;
+       sha256)
            test_hash_algo=sha256
            test_compat_hash_algo=sha1
            ;;
-       *)
+       sha1)
            test_hash_algo=sha1
            test_compat_hash_algo=sha256
            ;;
index 621cd31ae1dc5143979f3563fb407ff7b943bae6..9eb79324eee6f1667d2d48c8a8e00b547fdfe6d6 100644 (file)
@@ -1917,6 +1917,19 @@ test_lazy_prereq DEFAULT_HASH_ALGORITHM '
 test_lazy_prereq DEFAULT_REPO_FORMAT '
        test_have_prereq SHA1,REFFILES
 '
+# BROKEN_OBJECTS is a test whether we can write deliberately broken objects and
+# expect them to work.  When running using SHA-256 mode with SHA-1
+# compatibility, we cannot write such objects because there's no SHA-1
+# compatibility value for a nonexistent object.
+test_lazy_prereq BROKEN_OBJECTS '
+       ! test_have_prereq COMPAT_HASH
+'
+
+# COMPAT_HASH is a test if we're operating in a repository with SHA-256 with
+# SHA-1 compatibility.
+test_lazy_prereq COMPAT_HASH '
+       test -n "$test_repo_compat_hash_algo"
+'
 
 # Ensure that no test accidentally triggers a Git command
 # that runs the actual maintenance scheduler, affecting a user's