t / t5552-skipping-fetch-negotiator.shon commit t5310: increase the number of bitmapped commits (1ac96cd)
   1#!/bin/sh
   2
   3test_description='test skipping fetch negotiator'
   4. ./test-lib.sh
   5
   6have_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
  14                fi
  15                shift
  16        done
  17}
  18
  19have_not_sent () {
  20        while test "$#" -ne 0
  21        do
  22                grep "fetch> have $(git -C client rev-parse $1)" trace
  23                if test $? -eq 0
  24                then
  25                        return 1
  26                fi
  27                shift
  28        done
  29}
  30
  31# trace_fetch <client_dir> <server_dir> [args]
  32#
  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.
  35trace_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" "$@"
  42}
  43
  44test_expect_success 'commits with no parents are sent regardless of skip distance' '
  45        git init server &&
  46        test_commit -C server to_fetch &&
  47
  48        git init client &&
  49        for i in $(test_seq 7)
  50        do
  51                test_commit -C client c$i
  52        done &&
  53
  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
  61'
  62
  63test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
  64        rm -rf server client trace &&
  65        git init server &&
  66        test_commit -C server to_fetch &&
  67
  68        git init client &&
  69        test_commit -C client on_client &&
  70        git -C client checkout on_client &&
  71
  72        test_config -C client fetch.negotiationAlgorithm invalid &&
  73        test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
  74        test_i18ngrep "unknown fetch negotiation algorithm" err &&
  75
  76        # Explicit "default" value
  77        test_config -C client fetch.negotiationAlgorithm default &&
  78        git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
  79
  80        # Implementation detail: If there is nothing to fetch, we will not error out
  81        test_config -C client fetch.negotiationAlgorithm invalid &&
  82        git -C client fetch "$(pwd)/server" 2>err &&
  83        test_i18ngrep ! "unknown fetch negotiation algorithm" err
  84'
  85
  86test_expect_success 'when two skips collide, favor the larger one' '
  87        rm -rf server client trace &&
  88        git init server &&
  89        test_commit -C server to_fetch &&
  90
  91        git init client &&
  92        for i in $(test_seq 11)
  93        do
  94                test_commit -C client c$i
  95        done &&
  96        git -C client checkout c5 &&
  97        test_commit -C client c5side &&
  98
  99        # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
 100        # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
 101        # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
 102        # (from "c5side" skip 1).
 103        test_config -C client fetch.negotiationalgorithm skipping &&
 104        trace_fetch client "$(pwd)/server" &&
 105        have_sent c5side c11 c9 c6 c1 &&
 106        have_not_sent c10 c8 c7 c5 c4 c3 c2
 107'
 108
 109test_expect_success 'use ref advertisement to filter out commits' '
 110        rm -rf server client trace &&
 111        git init server &&
 112        test_commit -C server c1 &&
 113        test_commit -C server c2 &&
 114        test_commit -C server c3 &&
 115        git -C server tag -d c1 c2 c3 &&
 116
 117        git clone server client &&
 118        test_commit -C client c4 &&
 119        test_commit -C client c5 &&
 120        git -C client checkout c4^^ &&
 121        test_commit -C client c2side &&
 122
 123        git -C server checkout --orphan anotherbranch &&
 124        test_commit -C server to_fetch &&
 125
 126        # The server advertising "c3" (as "refs/heads/master") means that we do
 127        # not need to send any ancestors of "c3", but we still need to send "c3"
 128        # itself.
 129        test_config -C client fetch.negotiationalgorithm skipping &&
 130
 131        # The ref advertisement itself is filtered when protocol v2 is used, so
 132        # use v0.
 133        GIT_TEST_PROTOCOL_VERSION= trace_fetch client origin to_fetch &&
 134        have_sent c5 c4^ c2side &&
 135        have_not_sent c4 c4^^ c4^^^
 136'
 137
 138test_expect_success 'handle clock skew' '
 139        rm -rf server client trace &&
 140        git init server &&
 141        test_commit -C server to_fetch &&
 142
 143        git init client &&
 144
 145        # 2 regular commits
 146        test_tick=2000000000 &&
 147        test_commit -C client c1 &&
 148        test_commit -C client c2 &&
 149
 150        # 4 old commits
 151        test_tick=1000000000 &&
 152        git -C client checkout c1 &&
 153        test_commit -C client old1 &&
 154        test_commit -C client old2 &&
 155        test_commit -C client old3 &&
 156        test_commit -C client old4 &&
 157
 158        # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
 159        # normally be skipped, but is treated as a commit without a parent here
 160        # and sent, because (due to clock skew) its only parent has already been
 161        # popped off the priority queue.
 162        test_config -C client fetch.negotiationalgorithm skipping &&
 163        trace_fetch client "$(pwd)/server" &&
 164        have_sent c2 c1 old4 old2 old1 &&
 165        have_not_sent old3
 166'
 167
 168test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
 169        rm -rf server client trace &&
 170        git init server &&
 171        test_commit -C server to_fetch &&
 172
 173        git init client &&
 174        for i in $(test_seq 8)
 175        do
 176                git -C client checkout --orphan b$i &&
 177                test_commit -C client b$i.c0
 178        done &&
 179        for j in $(test_seq 19)
 180        do
 181                for i in $(test_seq 8)
 182                do
 183                        git -C client checkout b$i &&
 184                        test_commit -C client b$i.c$j
 185                done
 186        done &&
 187
 188        # Copy this branch over to the server and add a commit on it so that it
 189        # is reachable but not advertised.
 190        git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
 191        git -C server checkout b1 &&
 192        test_commit -C server commit-on-b1 &&
 193
 194        test_config -C client fetch.negotiationalgorithm skipping &&
 195        trace_fetch client "$(pwd)/server" to_fetch &&
 196        grep "  fetch" trace &&
 197
 198        # fetch-pack sends 2 requests each containing 16 "have" lines before
 199        # processing the first response. In these 2 requests, 4 commits from
 200        # each branch are sent. Just check the first branch.
 201        have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
 202        have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
 203
 204        # While fetch-pack is processing the first response, it should read that
 205        # the server ACKs b1.c19 and b1.c17.
 206        grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
 207        grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
 208
 209        # fetch-pack should thus not send any more commits in the b1 branch, but
 210        # should still send the others (in this test, just check b2).
 211        for i in $(test_seq 0 8)
 212        do
 213                have_not_sent b1.c$i
 214        done &&
 215        have_sent b2.c1 b2.c0
 216'
 217
 218test_done