Skip to content

Commit 6a95708

Browse files
committed
pack-objects: add GIT_TEST_NAME_HASH_VERSION
Add a new environment variable to opt-in to differen 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 two tests in t5616-partial-clone.sh that I believe are actually broken scenarios. While the client is set up to clone the 'promisor-server' repo via a treeless partial clone filter (tree:0), that filter does not translate to the 'server' repo. Thus, fetching from these repos causes the server to think that the client has all reachable trees and blobs from the commits advertised as 'haves'. This leads the server to providing a thin pack assuming those objects as delta bases. Changing the name-hash algorithm presents new delta bases and thus breaks the expectations of these tests. An alternative could be to set up 'server' as a promisor server with the correct filter enabled. This may also point out more issues with partial clone being set up as a remote-based filtering mechanism and not a repository-wide setting. For now, do the minimal change to make the test work by disabling the test variable. Third, 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 <[email protected]>
1 parent 1947d1b commit 6a95708

10 files changed

+67
-11
lines changed

builtin/pack-objects.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct configured_exclusion {
266266
static struct oidmap configured_exclusions;
267267

268268
static struct oidset excluded_by_config;
269-
static int name_hash_version = 1;
269+
static int name_hash_version = -1;
270270

271271
static void validate_name_hash_version(void)
272272
{
@@ -4609,6 +4609,9 @@ int cmd_pack_objects(int argc,
46094609
if (pack_to_stdout || !rev_list_all)
46104610
write_bitmap_index = 0;
46114611

4612+
if (name_hash_version < 0)
4613+
name_hash_version = (int)git_env_ulong("GIT_TEST_NAME_HASH_VERSION", 1);
4614+
46124615
validate_name_hash_version();
46134616
if (write_bitmap_index && name_hash_version != 1) {
46144617
warning(_("currently, --write-bitmap-index requires --name-hash-version=1"));

t/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ a test and then fails then the whole test run will abort. This can help to make
492492
sure the expected tests are executed and not silently skipped when their
493493
dependency breaks or is simply not present in a new environment.
494494

495+
GIT_TEST_NAME_HASH_VERSION=<int>, when set, causes 'git pack-objects' to
496+
assume '--name-hash-version=<n>'.
497+
498+
495499
Naming Tests
496500
------------
497501

t/t5300-pack-object.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,18 @@ do
675675
done
676676

677677
test_expect_success 'valid and invalid --name-hash-versions' '
678+
sane_unset GIT_TEST_NAME_HASH_VERSION &&
679+
678680
# Valid values are hard to verify other than "do not fail".
679681
# 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
681684
do
682685
git pack-objects base --all --name-hash-version=$value || return 1
683686
done &&
684687
685688
# Invalid values have clear post-conditions.
686-
for value in -1 0 3
689+
for value in 0 3
687690
do
688691
test_must_fail git pack-objects base --all --name-hash-version=$value 2>err &&
689692
test_grep "invalid --name-hash-version option" err || return 1

t/t5310-pack-bitmaps.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ test_bitmap_cases () {
420420
cat >expect <<-\EOF &&
421421
error: missing value for '\''pack.preferbitmaptips'\''
422422
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 &&
424427
test_cmp expect actual
425428
)
426429
'

t/t5333-pseudo-merge-bitmaps.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ test_expect_success 'bitmapPseudoMerge.stableThreshold creates stable groups' '
209209
'
210210

211211
test_expect_success 'out of order thresholds are rejected' '
212+
# Disable this option to avoid stderr message
213+
GIT_TEST_NAME_HASH_VERSION=1 &&
214+
export GIT_TEST_NAME_HASH_VERSION &&
215+
212216
test_must_fail git \
213217
-c bitmapPseudoMerge.test.pattern="refs/*" \
214218
-c bitmapPseudoMerge.test.threshold=1.month.ago \

t/t5510-fetch.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,12 @@ test_expect_success 'all boundary commits are excluded' '
10621062
test_tick &&
10631063
git merge otherside &&
10641064
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" &&
10661071
test_bundle_object_count --thin twoside-boundary.bdl 3
10671072
'
10681073

t/t5616-partial-clone.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,18 @@ test_expect_success 'fetch lazy-fetches only to resolve deltas' '
516516
# Exercise to make sure it works. Git will not fetch anything from the
517517
# promisor remote other than for the big tree (because it needs to
518518
# resolve the delta).
519-
GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
519+
#
520+
# TODO: the --full-name-hash option is disabled here, since this test
521+
# is fundamentally broken! When GIT_TEST_NAME_HASH_VERSION=2, the server
522+
# recognizes delta bases in a different way and then sends a _blob_ to
523+
# the client with a delta base that the client does not have! This is
524+
# because the client is cloned from "promisor-server" with tree:0 but
525+
# is now fetching from "server" without any filter. This is violating the
526+
# promise to the server that all reachable objects exist and could be
527+
# used as delta bases!
528+
GIT_TRACE_PACKET="$(pwd)/trace" \
529+
GIT_TEST_NAME_HASH_VERSION=1 \
530+
git -C client \
520531
fetch "file://$(pwd)/server" main &&
521532
522533
# Verify the assumption that the client needed to fetch the delta base
@@ -535,7 +546,18 @@ test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
535546
# Exercise to make sure it works. Git will not fetch anything from the
536547
# promisor remote other than for the big blob (because it needs to
537548
# resolve the delta).
538-
GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
549+
#
550+
# TODO: the --full-name-hash option is disabled here, since this test
551+
# is fundamentally broken! When GIT_TEST_NAME_HASH_VERSION=2, the server
552+
# recognizes delta bases in a different way and then sends a _blob_ to
553+
# the client with a delta base that the client does not have! This is
554+
# because the client is cloned from "promisor-server" with tree:0 but
555+
# is now fetching from "server" without any filter. This is violating the
556+
# promise to the server that all reachable objects exist and could be
557+
# used as delta bases!
558+
GIT_TRACE_PACKET="$(pwd)/trace" \
559+
GIT_TEST_NAME_HASH_VERSION=1 \
560+
git -C client \
539561
fetch "file://$(pwd)/server" main &&
540562
541563
# Verify that protocol version 2 was used.

t/t6020-bundle-misc.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,11 @@ test_expect_success 'create bundle with --since option' '
247247
EOF
248248
test_cmp expect actual &&
249249
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 \
251255
--since "Thu Apr 7 15:27:00 2005 -0700" \
252256
--all &&
253257

t/t7406-submodule-update.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,9 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
10941094
) &&
10951095
git clone super4 super5 &&
10961096
(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 &&
10981100
test_must_be_empty out &&
10991101
test_must_be_empty err
11001102
) &&

t/t7700-repack.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ test_expect_success 'no bitmaps created if .keep files present' '
309309
keep=${pack%.pack}.keep &&
310310
test_when_finished "rm -f \"\$keep\"" &&
311311
>"$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 &&
313316
test_must_be_empty stderr &&
314317
find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
315318
test_must_be_empty actual
@@ -320,7 +323,10 @@ test_expect_success 'auto-bitmaps do not complain if unavailable' '
320323
blob=$(test-tool genrandom big $((1024*1024)) |
321324
git -C bare.git hash-object -w --stdin) &&
322325
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 &&
324330
test_must_be_empty stderr &&
325331
find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
326332
test_must_be_empty actual

0 commit comments

Comments
 (0)