Skip to content

Commit 9ed06f5

Browse files
committed
clone: unbundle the advertised bundles
A previous change introduced the transport methods to acquire a bundle list from the 'bundle-uri' protocol v2 command, when advertised _and_ when the client has chosen to enable the feature. Teach Git to download and unbundle the data advertised by those bundles during 'git clone'. Also, since the --bundle-uri option exists, we do not want to mix the advertised bundles with the user-specified bundles. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 72ca6f4 commit 9ed06f5

File tree

3 files changed

+98
-7
lines changed

3 files changed

+98
-7
lines changed

builtin/clone.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,11 +1266,26 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12661266
if (refs)
12671267
mapped_refs = wanted_peer_refs(refs, &remote->fetch);
12681268

1269-
/*
1270-
* Populate transport->got_remote_bundle_uri and
1271-
* transport->bundle_uri. We might get nothing.
1272-
*/
1273-
transport_get_remote_bundle_uri(transport);
1269+
if (!bundle_uri) {
1270+
/*
1271+
* Populate transport->got_remote_bundle_uri and
1272+
* transport->bundle_uri. We might get nothing.
1273+
*/
1274+
transport_get_remote_bundle_uri(transport);
1275+
1276+
if (transport->bundles &&
1277+
hashmap_get_size(&transport->bundles->bundles)) {
1278+
/* At this point, we need the_repository to match the cloned repo. */
1279+
if (repo_init(the_repository, git_dir, work_tree))
1280+
warning(_("failed to initialize the repo, skipping bundle URI"));
1281+
else if (fetch_bundle_list(the_repository,
1282+
transport->bundles))
1283+
warning(_("failed to fetch advertised bundles"));
1284+
} else {
1285+
clear_bundle_list(transport->bundles);
1286+
FREE_AND_NULL(transport->bundles);
1287+
}
1288+
}
12741289

12751290
if (mapped_refs) {
12761291
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));

t/lib-bundle-uri-protocol.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: hav
8585
'
8686

8787
test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: request bundle-uris" '
88-
test_when_finished "rm -rf log cloned cloned2" &&
88+
test_when_finished "rm -rf log* cloned*" &&
8989
9090
GIT_TRACE_PACKET="$PWD/log" \
9191
git \
@@ -117,7 +117,24 @@ test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: reque
117117
grep "< bundle-uri" log &&
118118
119119
# Client issued bundle-uri command
120-
grep "> command=bundle-uri" log
120+
grep "> command=bundle-uri" log &&
121+
122+
GIT_TRACE_PACKET="$PWD/log3" \
123+
git \
124+
-c transfer.bundleURI=true \
125+
-c protocol.version=2 \
126+
clone --bundle-uri="$BUNDLE_URI_BUNDLE_URI" \
127+
"$BUNDLE_URI_REPO_URI" cloned3 \
128+
>actual 2>err &&
129+
130+
# Server responded using protocol v2
131+
grep "< version 2" log3 &&
132+
133+
# Server advertised bundle-uri capability
134+
grep "< bundle-uri" log3 &&
135+
136+
# Client did not issue bundle-uri command (--bundle-uri override)
137+
! grep "> command=bundle-uri" log3
121138
'
122139

123140
# The remaining tests will all assume transfer.bundleURI=true

t/t5601-clone.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,65 @@ test_expect_success 'reject cloning shallow repository using HTTP' '
795795
git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo
796796
'
797797

798+
test_expect_success 'auto-discover bundle URI from HTTP clone' '
799+
test_when_finished rm -rf trace.txt repo2 "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
800+
git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/everything.bundle" --all &&
801+
git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
802+
803+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
804+
uploadpack.advertiseBundleURIs true &&
805+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
806+
bundle.version 1 &&
807+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
808+
bundle.mode all &&
809+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
810+
bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
811+
812+
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
813+
git -c protocol.version=2 \
814+
-c transfer.bundleURI=true clone \
815+
$HTTPD_URL/smart/repo2.git repo2 &&
816+
cat >pattern <<-EOF &&
817+
"event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
818+
EOF
819+
grep -f pattern trace.txt
820+
'
821+
822+
test_expect_success 'auto-discover multiple bundles from HTTP clone' '
823+
test_when_finished rm -rf trace.txt repo3 "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
824+
825+
test_commit -C src new &&
826+
git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/new.bundle" HEAD~1..HEAD &&
827+
git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
828+
829+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
830+
uploadpack.advertiseBundleURIs true &&
831+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
832+
bundle.version 1 &&
833+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
834+
bundle.mode all &&
835+
836+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
837+
bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
838+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
839+
bundle.new.uri "$HTTPD_URL/new.bundle" &&
840+
841+
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
842+
git -c protocol.version=2 \
843+
-c transfer.bundleURI=true clone \
844+
$HTTPD_URL/smart/repo3.git repo3 &&
845+
846+
# We should fetch _both_ bundles
847+
cat >pattern <<-EOF &&
848+
"event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
849+
EOF
850+
grep -f pattern trace.txt &&
851+
cat >pattern <<-EOF &&
852+
"event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/new.bundle"\]
853+
EOF
854+
grep -f pattern trace.txt
855+
'
856+
798857
# DO NOT add non-httpd-specific tests here, because the last part of this
799858
# test script is only executed when httpd is available and enabled.
800859

0 commit comments

Comments
 (0)