clone.c: move more code into the "if (refs)" conditional
The bahavior of a bunch of code before the "if (refs)" statement also depends on whether refs is set, so make the logic clearer by shifting this code into the if statement. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Feb 11, 2012 at 07:20 UTC
5b05795c4cdf39348c18e40c12e70bd00a7192e5
1 file changed
+20
-19
builtin/clone.c
+20
-19
@@ -813,28 +813,28 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
813
}
814
815
refs = transport_get_remote_refs(transport);
816
- mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
816
818
- /*
819
- * transport_get_remote_refs() may return refs with null sha-1
820
- * in mapped_refs (see struct transport->get_refs_list
821
- * comment). In that case we need fetch it early because
822
- * remote_head code below relies on it.
823
- *
824
- * for normal clones, transport_get_remote_refs() should
825
- * return reliable ref set, we can delay cloning until after
826
- * remote HEAD check.
827
- */
828
- for (ref = refs; ref; ref = ref->next)
829
- if (is_null_sha1(ref->old_sha1)) {
830
- complete_refs_before_fetch = 0;
831
- break;
832
- }
817
+ if (refs) {
818
+ mapped_refs = wanted_peer_refs(refs, refspec);
819
+ /*
820
+ * transport_get_remote_refs() may return refs with null sha-1
821
+ * in mapped_refs (see struct transport->get_refs_list
822
+ * comment). In that case we need fetch it early because
823
+ * remote_head code below relies on it.
824
+ *
825
+ * for normal clones, transport_get_remote_refs() should
826
+ * return reliable ref set, we can delay cloning until after
827
+ * remote HEAD check.
828
+ */
829
+ for (ref = refs; ref; ref = ref->next)
830
+ if (is_null_sha1(ref->old_sha1)) {
831
+ complete_refs_before_fetch = 0;
832
+ break;
833
+ }
834
834
- if (!is_local && !complete_refs_before_fetch && refs)
835
- transport_fetch_refs(transport, mapped_refs);
835
+ if (!is_local && !complete_refs_before_fetch)
836
+ transport_fetch_refs(transport, mapped_refs);
837
837
- if (refs) {
838
remote_head = find_ref_by_name(refs, "HEAD");
839
remote_head_points_at =
840
guess_remote_head(remote_head, mapped_refs, 0);
@@ -852,6 +852,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
852
}
853
else {
854
warning(_("You appear to have cloned an empty repository."));
855
+ mapped_refs = NULL;
856
our_head_points_at = NULL;
857
remote_head_points_at = NULL;
858
remote_head = NULL;