Merge branch 'bw/clone-ref-prefixes'
authorJunio C Hamano <gitster@pobox.com>
Wed, 15 Aug 2018 22:08:23 +0000 (15:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Aug 2018 22:08:23 +0000 (15:08 -0700)
The wire-protocol v2 relies on the client to send "ref prefixes" to
limit the bandwidth spent on the initial ref advertisement. "git
clone" when learned to speak v2 forgot to do so, which has been
corrected.

* bw/clone-ref-prefixes:
clone: send ref-prefixes when using protocol v2

1  2 
builtin/clone.c
diff --combined builtin/clone.c
index 9ebb5acf56c5e03f8acafda4d806d6e3a41ee91f,5c0adbd6d0a360f3cf5825bcd52e8c4e386fed84..26fb0da42dff2124e90999a352c9dc9cdf94d6ac
@@@ -15,7 -15,6 +15,7 @@@
  #include "fetch-pack.h"
  #include "refs.h"
  #include "refspec.h"
 +#include "object-store.h"
  #include "tree.h"
  #include "tree-walk.h"
  #include "unpack-trees.h"
@@@ -696,8 -695,7 +696,8 @@@ static void update_head(const struct re
                        install_branch_config(0, head, option_origin, our->name);
                }
        } else if (our) {
 -              struct commit *c = lookup_commit_reference(&our->old_oid);
 +              struct commit *c = lookup_commit_reference(the_repository,
 +                                                         &our->old_oid);
                /* --branch specifies a non-branch (i.e. tags), detach HEAD */
                update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
                           UPDATE_REFS_DIE_ON_ERR);
@@@ -897,7 -895,8 +897,8 @@@ int cmd_clone(int argc, const char **ar
        int err = 0, complete_refs_before_fetch = 1;
        int submodule_progress;
  
-       struct refspec_item refspec;
+       struct refspec rs = REFSPEC_INIT_FETCH;
+       struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
  
        fetch_if_missing = 0;
  
        if (option_required_reference.nr || option_optional_reference.nr)
                setup_reference();
  
-       refspec_item_init_or_die(&refspec, value.buf, REFSPEC_FETCH);
+       refspec_append(&rs, value.buf);
  
        strbuf_reset(&value);
  
        if (transport->smart_options && !deepen && !filter_options.choice)
                transport->smart_options->check_self_contained_and_connected = 1;
  
-       refs = transport_get_remote_refs(transport, NULL);
+       argv_array_push(&ref_prefixes, "HEAD");
+       refspec_ref_prefixes(&rs, &ref_prefixes);
+       if (option_branch)
+               expand_ref_prefix(&ref_prefixes, option_branch);
+       if (!option_no_tags)
+               argv_array_push(&ref_prefixes, "refs/tags/");
+       refs = transport_get_remote_refs(transport, &ref_prefixes);
  
        if (refs) {
-               mapped_refs = wanted_peer_refs(refs, &refspec);
+               mapped_refs = wanted_peer_refs(refs, &rs.items[0]);
                /*
                 * transport_get_remote_refs() may return refs with null sha-1
                 * in mapped_refs (see struct transport->get_refs_list
                        }
  
                if (!is_local && !complete_refs_before_fetch)
 -                      transport_fetch_refs(transport, mapped_refs);
 +                      transport_fetch_refs(transport, mapped_refs, NULL);
  
                remote_head = find_ref_by_name(refs, "HEAD");
                remote_head_points_at =
        if (is_local)
                clone_local(path, git_dir);
        else if (refs && complete_refs_before_fetch)
 -              transport_fetch_refs(transport, mapped_refs);
 +              transport_fetch_refs(transport, mapped_refs, NULL);
  
        update_remote_refs(refs, mapped_refs, remote_head_points_at,
                           branch_top.buf, reflog_msg.buf, transport,
 -                         !is_local && !filter_options.choice);
 +                         !is_local);
  
        update_head(our_head_points_at, remote_head, reflog_msg.buf);
  
        strbuf_release(&value);
        junk_mode = JUNK_LEAVE_ALL;
  
-       refspec_item_clear(&refspec);
+       refspec_clear(&rs);
+       argv_array_clear(&ref_prefixes);
        return err;
  }