fetch-pack.c: rename some parameters from "path" to "refname"
[gitweb.git] / builtin / clone.c
index 72eebca5350c740e39c07737685204acfb9f8c80..279fdf0d252618b6fec648036f87141c61c03466 100644 (file)
@@ -472,11 +472,10 @@ static void write_remote_refs(const struct ref *local_refs)
        for (r = local_refs; r; r = r->next) {
                if (!r->peer_ref)
                        continue;
-               add_extra_ref(r->peer_ref->name, r->old_sha1, 0);
+               add_packed_ref(r->peer_ref->name, r->old_sha1);
        }
 
        pack_refs(PACK_REFS_ALL);
-       clear_extra_refs();
 }
 
 static void write_followtags(const struct ref *refs, const char *msg)
@@ -631,12 +630,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        const struct ref *remote_head_points_at;
        const struct ref *our_head_points_at;
        struct ref *mapped_refs;
+       const struct ref *ref;
        struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
        struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
        struct transport *transport = NULL;
        const char *src_ref_prefix = "refs/heads/";
        struct remote *remote;
-       int err = 0;
+       int err = 0, complete_refs_before_fetch = 1;
 
        struct refspec *refspec;
        const char *fetch_pattern;
@@ -813,21 +813,28 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        }
 
        refs = transport_get_remote_refs(transport);
-       mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
-
-       /*
-        * mapped_refs may be updated if transport-helper is used so
-        * we need fetch it early because remote_head code below
-        * relies on it.
-        *
-        * for normal clones, transport_get_remote_refs() should
-        * return reliable ref set, we can delay cloning until after
-        * remote HEAD check.
-        */
-       if (!is_local && remote->foreign_vcs && refs)
-               transport_fetch_refs(transport, mapped_refs);
 
        if (refs) {
+               mapped_refs = wanted_peer_refs(refs, refspec);
+               /*
+                * transport_get_remote_refs() may return refs with null sha-1
+                * in mapped_refs (see struct transport->get_refs_list
+                * comment). In that case we need fetch it early because
+                * remote_head code below relies on it.
+                *
+                * for normal clones, transport_get_remote_refs() should
+                * return reliable ref set, we can delay cloning until after
+                * remote HEAD check.
+                */
+               for (ref = refs; ref; ref = ref->next)
+                       if (is_null_sha1(ref->old_sha1)) {
+                               complete_refs_before_fetch = 0;
+                               break;
+                       }
+
+               if (!is_local && !complete_refs_before_fetch)
+                       transport_fetch_refs(transport, mapped_refs);
+
                remote_head = find_ref_by_name(refs, "HEAD");
                remote_head_points_at =
                        guess_remote_head(remote_head, mapped_refs, 0);
@@ -845,6 +852,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        }
        else {
                warning(_("You appear to have cloned an empty repository."));
+               mapped_refs = NULL;
                our_head_points_at = NULL;
                remote_head_points_at = NULL;
                remote_head = NULL;
@@ -856,7 +864,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
        if (is_local)
                clone_local(path, git_dir);
-       else if (refs && !remote->foreign_vcs)
+       else if (refs && complete_refs_before_fetch)
                transport_fetch_refs(transport, mapped_refs);
 
        update_remote_refs(refs, mapped_refs, remote_head_points_at,