summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2012-01-16 16:46:11 +0700
committerJunio C Hamano <gitster@pobox.com>2012-01-16 16:26:25 -0800
commit960b7d1c62bb8010954890b090546382161ae731 (patch)
treee2370bec20c55e62ecd1e73663abb45f3d0d6b54
parentf034d3549fa34e65ca09ee9ce721dcf43faefd1d (diff)
downloadgit-960b7d1c62bb8010954890b090546382161ae731.tar.gz
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>
-rw-r--r--builtin/clone.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 3b68014998..2733fa47ef 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -486,6 +486,29 @@ static void write_followtags(const struct ref *refs, const char *msg)
}
}
+static void update_remote_refs(const struct ref *refs,
+ const struct ref *mapped_refs,
+ const struct ref *remote_head_points_at,
+ const char *branch_top,
+ const char *msg)
+{
+ if (refs) {
+ clear_extra_refs();
+ write_remote_refs(mapped_refs);
+ if (option_single_branch)
+ write_followtags(refs, msg);
+ }
+
+ if (remote_head_points_at && !option_bare) {
+ struct strbuf head_ref = STRBUF_INIT;
+ strbuf_addstr(&head_ref, branch_top);
+ strbuf_addstr(&head_ref, "HEAD");
+ create_symref(head_ref.buf,
+ remote_head_points_at->peer_ref->name,
+ msg);
+ }
+}
+
static void update_head(const struct ref *our, const struct ref *remote,
const char *msg)
{
@@ -782,12 +805,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
}
if (refs) {
- clear_extra_refs();
-
- write_remote_refs(mapped_refs);
- if (option_single_branch)
- write_followtags(refs, reflog_msg.buf);
-
remote_head = find_ref_by_name(refs, "HEAD");
remote_head_points_at =
guess_remote_head(remote_head, mapped_refs, 0);
@@ -821,14 +838,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
"refs/heads/master");
}
- if (remote_head_points_at && !option_bare) {
- struct strbuf head_ref = STRBUF_INIT;
- strbuf_addstr(&head_ref, branch_top.buf);
- strbuf_addstr(&head_ref, "HEAD");
- create_symref(head_ref.buf,
- remote_head_points_at->peer_ref->name,
- reflog_msg.buf);
- }
+ update_remote_refs(refs, mapped_refs, remote_head_points_at,
+ branch_top.buf, reflog_msg.buf);
update_head(our_head_points_at, remote_head, reflog_msg.buf);