Skip to content

Commit 5b05795

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent acede2e commit 5b05795

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

builtin/clone.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -813,28 +813,28 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
813813
}
814814

815815
refs = transport_get_remote_refs(transport);
816-
mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
817816

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+
}
833834

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);
836837

837-
if (refs) {
838838
remote_head = find_ref_by_name(refs, "HEAD");
839839
remote_head_points_at =
840840
guess_remote_head(remote_head, mapped_refs, 0);
@@ -852,6 +852,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
852852
}
853853
else {
854854
warning(_("You appear to have cloned an empty repository."));
855+
mapped_refs = NULL;
855856
our_head_points_at = NULL;
856857
remote_head_points_at = NULL;
857858
remote_head = NULL;

0 commit comments

Comments
 (0)