]>
Commit | Line | Data |
---|---|---|
42cc7485 JT |
1 | #!/bin/sh |
2 | ||
3 | test_description='test skipping fetch negotiator' | |
4 | . ./test-lib.sh | |
5 | ||
258902ce ÆAB |
6 | test_expect_success 'fetch.negotiationalgorithm config' ' |
7 | test_when_finished "rm -rf repo" && | |
8 | git init repo && | |
9 | cat >repo/.git/config <<-\EOF && | |
10 | [fetch] | |
11 | negotiationAlgorithm | |
12 | EOF | |
13 | cat >expect <<-\EOF && | |
14 | error: missing value for '\''fetch.negotiationalgorithm'\'' | |
15 | fatal: bad config variable '\''fetch.negotiationalgorithm'\'' in file '\''.git/config'\'' at line 2 | |
16 | EOF | |
17 | test_expect_code 128 git -C repo fetch >out 2>actual && | |
18 | test_must_be_empty out && | |
19 | test_cmp expect actual | |
20 | ' | |
21 | ||
42cc7485 JT |
22 | have_sent () { |
23 | while test "$#" -ne 0 | |
24 | do | |
25 | grep "fetch> have $(git -C client rev-parse $1)" trace | |
26 | if test $? -ne 0 | |
27 | then | |
28 | echo "No have $(git -C client rev-parse $1) ($1)" | |
29 | return 1 | |
30 | fi | |
31 | shift | |
32 | done | |
33 | } | |
34 | ||
35 | have_not_sent () { | |
36 | while test "$#" -ne 0 | |
37 | do | |
38 | grep "fetch> have $(git -C client rev-parse $1)" trace | |
39 | if test $? -eq 0 | |
40 | then | |
41 | return 1 | |
42 | fi | |
43 | shift | |
44 | done | |
45 | } | |
46 | ||
b6e7fc4f JK |
47 | # trace_fetch <client_dir> <server_dir> [args] |
48 | # | |
49 | # Trace the packet output of fetch, but make sure we disable the variable | |
50 | # in the child upload-pack, so we don't combine the results in the same file. | |
51 | trace_fetch () { | |
52 | client=$1; shift | |
53 | server=$1; shift | |
54 | GIT_TRACE_PACKET="$(pwd)/trace" \ | |
55 | git -C "$client" fetch \ | |
56 | --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \ | |
57 | "$server" "$@" | |
58 | } | |
59 | ||
42cc7485 JT |
60 | test_expect_success 'commits with no parents are sent regardless of skip distance' ' |
61 | git init server && | |
62 | test_commit -C server to_fetch && | |
63 | ||
64 | git init client && | |
b2fa7a23 | 65 | for i in $(test_seq 7) |
42cc7485 | 66 | do |
d0fd9931 | 67 | test_commit -C client c$i || return 1 |
42cc7485 JT |
68 | done && |
69 | ||
70 | # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since | |
71 | # "c1" has no parent, it is still sent as "have" even though it would | |
72 | # normally be skipped. | |
73 | test_config -C client fetch.negotiationalgorithm skipping && | |
b6e7fc4f | 74 | trace_fetch client "$(pwd)/server" && |
42cc7485 JT |
75 | have_sent c7 c5 c2 c1 && |
76 | have_not_sent c6 c4 c3 | |
77 | ' | |
78 | ||
79 | test_expect_success 'when two skips collide, favor the larger one' ' | |
80 | rm -rf server client trace && | |
81 | git init server && | |
82 | test_commit -C server to_fetch && | |
83 | ||
84 | git init client && | |
b2fa7a23 | 85 | for i in $(test_seq 11) |
42cc7485 | 86 | do |
d0fd9931 | 87 | test_commit -C client c$i || return 1 |
42cc7485 JT |
88 | done && |
89 | git -C client checkout c5 && | |
90 | test_commit -C client c5side && | |
91 | ||
92 | # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9" | |
93 | # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so | |
94 | # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4" | |
95 | # (from "c5side" skip 1). | |
96 | test_config -C client fetch.negotiationalgorithm skipping && | |
b6e7fc4f | 97 | trace_fetch client "$(pwd)/server" && |
42cc7485 JT |
98 | have_sent c5side c11 c9 c6 c1 && |
99 | have_not_sent c10 c8 c7 c5 c4 c3 c2 | |
100 | ' | |
101 | ||
102 | test_expect_success 'use ref advertisement to filter out commits' ' | |
103 | rm -rf server client trace && | |
104 | git init server && | |
105 | test_commit -C server c1 && | |
106 | test_commit -C server c2 && | |
107 | test_commit -C server c3 && | |
108 | git -C server tag -d c1 c2 c3 && | |
109 | ||
110 | git clone server client && | |
111 | test_commit -C client c4 && | |
112 | test_commit -C client c5 && | |
113 | git -C client checkout c4^^ && | |
114 | test_commit -C client c2side && | |
115 | ||
116 | git -C server checkout --orphan anotherbranch && | |
117 | test_commit -C server to_fetch && | |
118 | ||
028cb644 | 119 | # The server advertising "c3" (as "refs/heads/main") means that we do |
42cc7485 JT |
120 | # not need to send any ancestors of "c3", but we still need to send "c3" |
121 | # itself. | |
122 | test_config -C client fetch.negotiationalgorithm skipping && | |
010834a8 JT |
123 | |
124 | # The ref advertisement itself is filtered when protocol v2 is used, so | |
125 | # use v0. | |
c7973f24 | 126 | ( |
8a1b0978 | 127 | GIT_TEST_PROTOCOL_VERSION=0 && |
c7973f24 JN |
128 | export GIT_TEST_PROTOCOL_VERSION && |
129 | trace_fetch client origin to_fetch | |
130 | ) && | |
42cc7485 JT |
131 | have_sent c5 c4^ c2side && |
132 | have_not_sent c4 c4^^ c4^^^ | |
133 | ' | |
134 | ||
135 | test_expect_success 'handle clock skew' ' | |
136 | rm -rf server client trace && | |
137 | git init server && | |
138 | test_commit -C server to_fetch && | |
139 | ||
140 | git init client && | |
141 | ||
142 | # 2 regular commits | |
143 | test_tick=2000000000 && | |
144 | test_commit -C client c1 && | |
145 | test_commit -C client c2 && | |
146 | ||
147 | # 4 old commits | |
148 | test_tick=1000000000 && | |
149 | git -C client checkout c1 && | |
150 | test_commit -C client old1 && | |
151 | test_commit -C client old2 && | |
152 | test_commit -C client old3 && | |
153 | test_commit -C client old4 && | |
154 | ||
155 | # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would | |
156 | # normally be skipped, but is treated as a commit without a parent here | |
157 | # and sent, because (due to clock skew) its only parent has already been | |
158 | # popped off the priority queue. | |
159 | test_config -C client fetch.negotiationalgorithm skipping && | |
b6e7fc4f | 160 | trace_fetch client "$(pwd)/server" && |
42cc7485 JT |
161 | have_sent c2 c1 old4 old2 old1 && |
162 | have_not_sent old3 | |
163 | ' | |
164 | ||
165 | test_expect_success 'do not send "have" with ancestors of commits that server ACKed' ' | |
166 | rm -rf server client trace && | |
167 | git init server && | |
168 | test_commit -C server to_fetch && | |
169 | ||
170 | git init client && | |
b2fa7a23 | 171 | for i in $(test_seq 8) |
42cc7485 JT |
172 | do |
173 | git -C client checkout --orphan b$i && | |
d0fd9931 | 174 | test_commit -C client b$i.c0 || return 1 |
42cc7485 | 175 | done && |
b2fa7a23 | 176 | for j in $(test_seq 19) |
42cc7485 | 177 | do |
b2fa7a23 | 178 | for i in $(test_seq 8) |
42cc7485 JT |
179 | do |
180 | git -C client checkout b$i && | |
d0fd9931 | 181 | test_commit -C client b$i.c$j || return 1 |
42cc7485 JT |
182 | done |
183 | done && | |
184 | ||
185 | # Copy this branch over to the server and add a commit on it so that it | |
186 | # is reachable but not advertised. | |
187 | git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 && | |
188 | git -C server checkout b1 && | |
189 | test_commit -C server commit-on-b1 && | |
190 | ||
191 | test_config -C client fetch.negotiationalgorithm skipping && | |
d6509da6 JN |
192 | |
193 | # NEEDSWORK: The number of "have"s sent depends on whether the transport | |
194 | # is stateful. If the overspecification of the result were reduced, this | |
195 | # test could be used for both stateful and stateless transports. | |
196 | ( | |
197 | # Force protocol v0, in which local transport is stateful (in | |
198 | # protocol v2 it is stateless). | |
199 | GIT_TEST_PROTOCOL_VERSION=0 && | |
200 | export GIT_TEST_PROTOCOL_VERSION && | |
201 | trace_fetch client "$(pwd)/server" to_fetch | |
202 | ) && | |
42cc7485 JT |
203 | grep " fetch" trace && |
204 | ||
205 | # fetch-pack sends 2 requests each containing 16 "have" lines before | |
206 | # processing the first response. In these 2 requests, 4 commits from | |
207 | # each branch are sent. Just check the first branch. | |
208 | have_sent b1.c19 b1.c17 b1.c14 b1.c9 && | |
209 | have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 && | |
210 | ||
211 | # While fetch-pack is processing the first response, it should read that | |
212 | # the server ACKs b1.c19 and b1.c17. | |
213 | grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace && | |
214 | grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace && | |
215 | ||
216 | # fetch-pack should thus not send any more commits in the b1 branch, but | |
217 | # should still send the others (in this test, just check b2). | |
b2fa7a23 | 218 | for i in $(test_seq 0 8) |
42cc7485 | 219 | do |
d0fd9931 | 220 | have_not_sent b1.c$i || return 1 |
42cc7485 JT |
221 | done && |
222 | have_sent b2.c1 b2.c0 | |
223 | ' | |
224 | ||
225 | test_done |