clone: factor out remote ref writing

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 16, 2012 at 16:46 UTC 960b7d1c62bb8010954890b090546382161ae731
1 file changed +25 -14
builtin/clone.c
+25 -14
@@ -486,6 +486,29 @@ static void write_followtags(const struct ref *refs, const char *msg)
486 }
487 }
488
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 +
512 static void update_head(const struct ref *our, const struct ref *remote,
513 const char *msg)
514 {
@@ -782,12 +805,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
805 }
806
807 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 -
808 remote_head = find_ref_by_name(refs, "HEAD");
809 remote_head_points_at =
810 guess_remote_head(remote_head, mapped_refs, 0);
@@ -821,14 +838,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
838 "refs/heads/master");
839 }
840
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);
843
844 update_head(our_head_points_at, remote_head, reflog_msg.buf);
845