Merge branch 'jt/fetch-pack-v2'
authorJunio C Hamano <gitster@pobox.com>
Tue, 29 Jan 2019 20:47:54 +0000 (12:47 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Jan 2019 20:47:54 +0000 (12:47 -0800)
"git fetch-pack" now can talk the version 2 protocol.

* jt/fetch-pack-v2:
fetch-pack: support protocol version 2

1  2 
builtin/fetch-pack.c
t/t5500-fetch-pack.sh
diff --combined builtin/fetch-pack.c
index 63e69a58011a4d3c774cd3c81ae9f10e3a96efe6,2cea218fed570cc25a67397dcab2cf081004357d..f6a513495ea77e4350aa6ec5282c3ab2969ee027
@@@ -16,14 -16,13 +16,14 @@@ static void add_sought_entry(struct re
  {
        struct ref *ref;
        struct object_id oid;
 +      const char *p;
  
 -      if (!get_oid_hex(name, &oid)) {
 -              if (name[GIT_SHA1_HEXSZ] == ' ') {
 -                      /* <sha1> <ref>, find refname */
 -                      name += GIT_SHA1_HEXSZ + 1;
 -              } else if (name[GIT_SHA1_HEXSZ] == '\0') {
 -                      ; /* <sha1>, leave sha1 as name */
 +      if (!parse_oid_hex(name, &oid, &p)) {
 +              if (*p == ' ') {
 +                      /* <oid> <ref>, find refname */
 +                      name = p + 1;
 +              } else if (*p == '\0') {
 +                      ; /* <oid>, leave oid as name */
                } else {
                        /* <ref>, clear cruft from oid */
                        oidclr(&oid);
@@@ -55,6 -54,7 +55,7 @@@ int cmd_fetch_pack(int argc, const cha
        struct oid_array shallow = OID_ARRAY_INIT;
        struct string_list deepen_not = STRING_LIST_INIT_DUP;
        struct packet_reader reader;
+       enum protocol_version version;
  
        fetch_if_missing = 0;
  
                           PACKET_READ_CHOMP_NEWLINE |
                           PACKET_READ_GENTLE_ON_EOF);
  
-       switch (discover_version(&reader)) {
+       version = discover_version(&reader);
+       switch (version) {
        case protocol_v2:
-               die("support for protocol v2 not implemented yet");
+               get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL);
+               break;
        case protocol_v1:
        case protocol_v0:
                get_remote_heads(&reader, &ref, 0, NULL, &shallow);
        }
  
        ref = fetch_pack(&args, fd, conn, ref, dest, sought, nr_sought,
-                        &shallow, pack_lockfile_ptr, protocol_v0);
+                        &shallow, pack_lockfile_ptr, version);
        if (pack_lockfile) {
                printf("lock %s\n", pack_lockfile);
                fflush(stdout);
diff --combined t/t5500-fetch-pack.sh
index 086f2c40f68ffaf666a09d88b86709133559fc91,71b0de12aacd0e73d795889acc6f7e7bc503dbe3..49c540b1e1dbd5fc7d9a7baa36ee93a2ed3fc3c3
@@@ -50,11 -50,8 +50,11 @@@ pull_to_client () 
                        case "$heads" in *B*)
                            git update-ref refs/heads/B "$BTIP";;
                        esac &&
 -                      git symbolic-ref HEAD refs/heads/$(echo $heads \
 -                              | sed -e "s/^\(.\).*$/\1/") &&
 +
 +                      git symbolic-ref HEAD refs/heads/$(
 +                              echo $heads |
 +                              sed -e "s/^\(.\).*$/\1/"
 +                      ) &&
  
                        git fsck --full &&
  
@@@ -439,15 -436,23 +439,23 @@@ test_expect_success 'setup tests for th
        ) >input.dup
  '
  
- test_expect_success 'fetch refs from cmdline' '
-       (
-               cd client &&
-               git fetch-pack --no-progress .. $(cat ../input)
-       ) >output &&
-       cut -d " " -f 2 <output | sort >actual &&
-       test_cmp expect actual
+ test_expect_success 'setup fetch refs from cmdline v[12]' '
+       cp -r client client1 &&
+       cp -r client client2
  '
  
+ for version in '' 1 2
+ do
+       test_expect_success "protocol.version=$version fetch refs from cmdline" "
+               (
+                       cd client$version &&
+                       GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
+               ) >output &&
+               cut -d ' ' -f 2 <output | sort >actual &&
+               test_cmp expect actual
+       "
+ done
  test_expect_success 'fetch refs from stdin' '
        (
                cd client &&