Merge branch 'dd/mailinfo-with-nul'
[git/raj.git] / t / t5552-skipping-fetch-negotiator.sh
blob156c70404083fb789127a0a5540bb6ba5332a3fb
1 #!/bin/sh
3 test_description='test skipping fetch negotiator'
4 . ./test-lib.sh
6 have_sent () {
7 while test "$#" -ne 0
8 do
9 grep "fetch> have $(git -C client rev-parse $1)" trace
10 if test $? -ne 0
11 then
12 echo "No have $(git -C client rev-parse $1) ($1)"
13 return 1
15 shift
16 done
19 have_not_sent () {
20 while test "$#" -ne 0
22 grep "fetch> have $(git -C client rev-parse $1)" trace
23 if test $? -eq 0
24 then
25 return 1
27 shift
28 done
31 # trace_fetch <client_dir> <server_dir> [args]
33 # Trace the packet output of fetch, but make sure we disable the variable
34 # in the child upload-pack, so we don't combine the results in the same file.
35 trace_fetch () {
36 client=$1; shift
37 server=$1; shift
38 GIT_TRACE_PACKET="$(pwd)/trace" \
39 git -C "$client" fetch \
40 --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
41 "$server" "$@"
44 test_expect_success 'commits with no parents are sent regardless of skip distance' '
45 git init server &&
46 test_commit -C server to_fetch &&
48 git init client &&
49 for i in $(test_seq 7)
51 test_commit -C client c$i
52 done &&
54 # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
55 # "c1" has no parent, it is still sent as "have" even though it would
56 # normally be skipped.
57 test_config -C client fetch.negotiationalgorithm skipping &&
58 trace_fetch client "$(pwd)/server" &&
59 have_sent c7 c5 c2 c1 &&
60 have_not_sent c6 c4 c3
63 test_expect_success 'when two skips collide, favor the larger one' '
64 rm -rf server client trace &&
65 git init server &&
66 test_commit -C server to_fetch &&
68 git init client &&
69 for i in $(test_seq 11)
71 test_commit -C client c$i
72 done &&
73 git -C client checkout c5 &&
74 test_commit -C client c5side &&
76 # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
77 # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
78 # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
79 # (from "c5side" skip 1).
80 test_config -C client fetch.negotiationalgorithm skipping &&
81 trace_fetch client "$(pwd)/server" &&
82 have_sent c5side c11 c9 c6 c1 &&
83 have_not_sent c10 c8 c7 c5 c4 c3 c2
86 test_expect_success 'use ref advertisement to filter out commits' '
87 rm -rf server client trace &&
88 git init server &&
89 test_commit -C server c1 &&
90 test_commit -C server c2 &&
91 test_commit -C server c3 &&
92 git -C server tag -d c1 c2 c3 &&
94 git clone server client &&
95 test_commit -C client c4 &&
96 test_commit -C client c5 &&
97 git -C client checkout c4^^ &&
98 test_commit -C client c2side &&
100 git -C server checkout --orphan anotherbranch &&
101 test_commit -C server to_fetch &&
103 # The server advertising "c3" (as "refs/heads/master") means that we do
104 # not need to send any ancestors of "c3", but we still need to send "c3"
105 # itself.
106 test_config -C client fetch.negotiationalgorithm skipping &&
108 # The ref advertisement itself is filtered when protocol v2 is used, so
109 # use v0.
111 GIT_TEST_PROTOCOL_VERSION=0 &&
112 export GIT_TEST_PROTOCOL_VERSION &&
113 trace_fetch client origin to_fetch
114 ) &&
115 have_sent c5 c4^ c2side &&
116 have_not_sent c4 c4^^ c4^^^
119 test_expect_success 'handle clock skew' '
120 rm -rf server client trace &&
121 git init server &&
122 test_commit -C server to_fetch &&
124 git init client &&
126 # 2 regular commits
127 test_tick=2000000000 &&
128 test_commit -C client c1 &&
129 test_commit -C client c2 &&
131 # 4 old commits
132 test_tick=1000000000 &&
133 git -C client checkout c1 &&
134 test_commit -C client old1 &&
135 test_commit -C client old2 &&
136 test_commit -C client old3 &&
137 test_commit -C client old4 &&
139 # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
140 # normally be skipped, but is treated as a commit without a parent here
141 # and sent, because (due to clock skew) its only parent has already been
142 # popped off the priority queue.
143 test_config -C client fetch.negotiationalgorithm skipping &&
144 trace_fetch client "$(pwd)/server" &&
145 have_sent c2 c1 old4 old2 old1 &&
146 have_not_sent old3
149 test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
150 rm -rf server client trace &&
151 git init server &&
152 test_commit -C server to_fetch &&
154 git init client &&
155 for i in $(test_seq 8)
157 git -C client checkout --orphan b$i &&
158 test_commit -C client b$i.c0
159 done &&
160 for j in $(test_seq 19)
162 for i in $(test_seq 8)
164 git -C client checkout b$i &&
165 test_commit -C client b$i.c$j
166 done
167 done &&
169 # Copy this branch over to the server and add a commit on it so that it
170 # is reachable but not advertised.
171 git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
172 git -C server checkout b1 &&
173 test_commit -C server commit-on-b1 &&
175 test_config -C client fetch.negotiationalgorithm skipping &&
177 # NEEDSWORK: The number of "have"s sent depends on whether the transport
178 # is stateful. If the overspecification of the result were reduced, this
179 # test could be used for both stateful and stateless transports.
181 # Force protocol v0, in which local transport is stateful (in
182 # protocol v2 it is stateless).
183 GIT_TEST_PROTOCOL_VERSION=0 &&
184 export GIT_TEST_PROTOCOL_VERSION &&
185 trace_fetch client "$(pwd)/server" to_fetch
186 ) &&
187 grep " fetch" trace &&
189 # fetch-pack sends 2 requests each containing 16 "have" lines before
190 # processing the first response. In these 2 requests, 4 commits from
191 # each branch are sent. Just check the first branch.
192 have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
193 have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
195 # While fetch-pack is processing the first response, it should read that
196 # the server ACKs b1.c19 and b1.c17.
197 grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
198 grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
200 # fetch-pack should thus not send any more commits in the b1 branch, but
201 # should still send the others (in this test, just check b2).
202 for i in $(test_seq 0 8)
204 have_not_sent b1.c$i
205 done &&
206 have_sent b2.c1 b2.c0
209 test_done