Skip to content

Commit 4316ff3

Browse files
jonathantanmygitster
authored andcommitted
fetch-pack: support protocol version 2
When the scaffolding for protocol version 2 was initially added in 8f6982b ("protocol: introduce enum protocol_version value protocol_v2", 2018-03-14). As seen in: git log -p -G'support for protocol v2 not implemented yet' --full-diff --reverse v2.17.0..v2.20.0 Many of those scaffolding "die" placeholders were removed, but we hadn't gotten around to fetch-pack yet. The test here for "fetch refs from cmdline" is very minimal. There's much better coverage when running the entire test suite under the WIP GIT_TEST_PROTOCOL_VERSION=2 mode[1], we should ideally have better coverage without needing to invoke a special test mode. 1. https://public-inbox.org/git/20181213155817.27666-1-avarab@gmail.com/ Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 98cdfbb commit 4316ff3

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

builtin/fetch-pack.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
5454
struct oid_array shallow = OID_ARRAY_INIT;
5555
struct string_list deepen_not = STRING_LIST_INIT_DUP;
5656
struct packet_reader reader;
57+
enum protocol_version version;
5758

5859
fetch_if_missing = 0;
5960

@@ -218,9 +219,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
218219
PACKET_READ_CHOMP_NEWLINE |
219220
PACKET_READ_GENTLE_ON_EOF);
220221

221-
switch (discover_version(&reader)) {
222+
version = discover_version(&reader);
223+
switch (version) {
222224
case protocol_v2:
223-
die("support for protocol v2 not implemented yet");
225+
get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL);
226+
break;
224227
case protocol_v1:
225228
case protocol_v0:
226229
get_remote_heads(&reader, &ref, 0, NULL, &shallow);
@@ -230,7 +233,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
230233
}
231234

232235
ref = fetch_pack(&args, fd, conn, ref, dest, sought, nr_sought,
233-
&shallow, pack_lockfile_ptr, protocol_v0);
236+
&shallow, pack_lockfile_ptr, version);
234237
if (pack_lockfile) {
235238
printf("lock %s\n", pack_lockfile);
236239
fflush(stdout);

t/t5500-fetch-pack.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,23 @@ test_expect_success 'setup tests for the --stdin parameter' '
436436
) >input.dup
437437
'
438438

439-
test_expect_success 'fetch refs from cmdline' '
440-
(
441-
cd client &&
442-
git fetch-pack --no-progress .. $(cat ../input)
443-
) >output &&
444-
cut -d " " -f 2 <output | sort >actual &&
445-
test_cmp expect actual
439+
test_expect_success 'setup fetch refs from cmdline v[12]' '
440+
cp -r client client1 &&
441+
cp -r client client2
446442
'
447443

444+
for version in '' 1 2
445+
do
446+
test_expect_success "protocol.version=$version fetch refs from cmdline" "
447+
(
448+
cd client$version &&
449+
GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
450+
) >output &&
451+
cut -d ' ' -f 2 <output | sort >actual &&
452+
test_cmp expect actual
453+
"
454+
done
455+
448456
test_expect_success 'fetch refs from stdin' '
449457
(
450458
cd client &&

0 commit comments

Comments
 (0)