Skip to content

Commit 960b7d1

Browse files
pcloudsgitster
authored andcommitted
clone: factor out remote ref writing
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f034d35 commit 960b7d1

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

builtin/clone.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,29 @@ static void write_followtags(const struct ref *refs, const char *msg)
486486
}
487487
}
488488

489+
static void update_remote_refs(const struct ref *refs,
490+
const struct ref *mapped_refs,
491+
const struct ref *remote_head_points_at,
492+
const char *branch_top,
493+
const char *msg)
494+
{
495+
if (refs) {
496+
clear_extra_refs();
497+
write_remote_refs(mapped_refs);
498+
if (option_single_branch)
499+
write_followtags(refs, msg);
500+
}
501+
502+
if (remote_head_points_at && !option_bare) {
503+
struct strbuf head_ref = STRBUF_INIT;
504+
strbuf_addstr(&head_ref, branch_top);
505+
strbuf_addstr(&head_ref, "HEAD");
506+
create_symref(head_ref.buf,
507+
remote_head_points_at->peer_ref->name,
508+
msg);
509+
}
510+
}
511+
489512
static void update_head(const struct ref *our, const struct ref *remote,
490513
const char *msg)
491514
{
@@ -782,12 +805,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
782805
}
783806

784807
if (refs) {
785-
clear_extra_refs();
786-
787-
write_remote_refs(mapped_refs);
788-
if (option_single_branch)
789-
write_followtags(refs, reflog_msg.buf);
790-
791808
remote_head = find_ref_by_name(refs, "HEAD");
792809
remote_head_points_at =
793810
guess_remote_head(remote_head, mapped_refs, 0);
@@ -821,14 +838,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
821838
"refs/heads/master");
822839
}
823840

824-
if (remote_head_points_at && !option_bare) {
825-
struct strbuf head_ref = STRBUF_INIT;
826-
strbuf_addstr(&head_ref, branch_top.buf);
827-
strbuf_addstr(&head_ref, "HEAD");
828-
create_symref(head_ref.buf,
829-
remote_head_points_at->peer_ref->name,
830-
reflog_msg.buf);
831-
}
841+
update_remote_refs(refs, mapped_refs, remote_head_points_at,
842+
branch_top.buf, reflog_msg.buf);
832843

833844
update_head(our_head_points_at, remote_head, reflog_msg.buf);
834845

0 commit comments

Comments
 (0)