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