Skip to content

Commit 810e193

Browse files
jonathantanmygitster
authored andcommitted
t5616: cover case of client having delta base
When fetching into a partial clone, Git first prefetches missing REF_DELTA bases from the promisor remote. (This feature was introduced in [1].) But as can be seen in a recent test coverage report [2], the case in which a REF_DELTA base is already present is not covered by tests. Extend the tests slightly to cover this case. [1] 8a30a1e ("index-pack: prefetch missing REF_DELTA bases", 2019-05-15). [2] https://public-inbox.org/git/[email protected]/ Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5718c53 commit 810e193

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

t/t5616-partial-clone.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,30 +346,37 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
346346
test_config -C "$SERVER" uploadpack.allowfilter 1 &&
347347
test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
348348
349-
# Create a commit with a blob to be used as a delta base.
349+
# Create a commit with 2 blobs to be used as delta bases.
350350
for i in $(test_seq 10)
351351
do
352-
echo "this is a line" >>"$SERVER/foo.txt"
352+
echo "this is a line" >>"$SERVER/foo.txt" &&
353+
echo "this is another line" >>"$SERVER/have.txt"
353354
done &&
354-
git -C "$SERVER" add foo.txt &&
355+
git -C "$SERVER" add foo.txt have.txt &&
355356
git -C "$SERVER" commit -m bar &&
356-
git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase &&
357+
git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing &&
358+
git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have &&
357359
360+
# Clone. The client has deltabase_have but not deltabase_missing.
358361
git -c protocol.version=2 clone --no-checkout \
359362
--filter=blob:none $HTTPD_URL/one_time_sed/server repo &&
363+
git -C repo hash-object -w -- "$SERVER/have.txt" &&
360364
361-
# Sanity check to ensure that the client does not have that blob.
365+
# Sanity check to ensure that the client does not have
366+
# deltabase_missing.
362367
git -C repo rev-list --objects --ignore-missing \
363-
-- $(cat deltabase) >objlist &&
368+
-- $(cat deltabase_missing) >objlist &&
364369
test_line_count = 0 objlist &&
365370
366371
# Another commit. This commit will be fetched by the client.
367372
echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" &&
368-
git -C "$SERVER" add foo.txt &&
373+
echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" &&
374+
git -C "$SERVER" add foo.txt have.txt &&
369375
git -C "$SERVER" commit -m baz &&
370376
371377
# Pack a thin pack containing, among other things, HEAD:foo.txt
372-
# delta-ed against HEAD^:foo.txt.
378+
# delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against
379+
# HEAD^:have.txt.
373380
printf "%s\n--not\n%s\n" \
374381
$(git -C "$SERVER" rev-parse HEAD) \
375382
$(git -C "$SERVER" rev-parse HEAD^) |
@@ -381,8 +388,13 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
381388
# most significant nybble of the first byte is 0b1111 (0b1 to indicate
382389
# that the header continues, and 0b111 to indicate REF_DELTA), followed
383390
# by any 3 nybbles, then the OID of the delta base.
384-
git -C "$SERVER" rev-parse HEAD^:foo.txt >deltabase &&
385-
printf "f.,..%s" $(intersperse "," <deltabase) >want &&
391+
printf "f.,..%s" $(intersperse "," <deltabase_missing) >want &&
392+
hex_unpack <thin.pack | intersperse "," >have &&
393+
grep $(cat want) have &&
394+
395+
# Ensure that the pack contains one delta against HEAD^:have.txt,
396+
# similar to the above.
397+
printf "f.,..%s" $(intersperse "," <deltabase_have) >want &&
386398
hex_unpack <thin.pack | intersperse "," >have &&
387399
grep $(cat want) have &&
388400
@@ -394,7 +406,12 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
394406
395407
# Fetch the thin pack and ensure that index-pack is able to handle the
396408
# REF_DELTA object with a missing promisor delta base.
397-
git -C repo -c protocol.version=2 fetch &&
409+
GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch &&
410+
411+
# Ensure that the missing delta base was directly fetched, but not the
412+
# one that the client has.
413+
grep "want $(cat deltabase_missing)" trace &&
414+
! grep "want $(cat deltabase_have)" trace &&
398415
399416
# Ensure that the one-time-sed script was used.
400417
! test -e "$HTTPD_ROOT_PATH/one-time-sed"

0 commit comments

Comments
 (0)