clone-pack: use create_symref() instead of raw symlink.
This was the last instance of symlink() in coreish part. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 5, 2005 at 15:29 UTC
4cfc63db1daa0ebdb284ae6972928e41a317a0c8
1 file changed
+16
-8
clone-pack.c
+16
-8
@@ -51,6 +51,7 @@ static void write_refs(struct ref *ref)
51
struct ref *head = NULL, *head_ptr, *master_ref;
52
char *head_path;
53
54
+ /* Upload-pack must report HEAD first */
55
if (!strcmp(ref->name, "HEAD")) {
56
head = ref;
57
ref = ref->next;
@@ -60,17 +61,21 @@ static void write_refs(struct ref *ref)
61
while (ref) {
62
if (is_master(ref))
63
master_ref = ref;
63
- if (head && !memcmp(ref->old_sha1, head->old_sha1, 20)) {
64
- if (!head_ptr || ref == master_ref)
65
- head_ptr = ref;
66
- }
64
+ if (head &&
65
+ !memcmp(ref->old_sha1, head->old_sha1, 20) &&
66
+ !strncmp(ref->name, "refs/heads/",11) &&
67
+ (!head_ptr || ref == master_ref))
68
+ head_ptr = ref;
69
+
70
write_one_ref(ref);
71
ref = ref->next;
72
}
70
- if (!head)
73
+ if (!head) {
74
+ fprintf(stderr, "No HEAD in remote.\n");
75
return;
76
+ }
77
73
- head_path = git_path("HEAD");
78
+ head_path = strdup(git_path("HEAD"));
79
if (!head_ptr) {
80
/*
81
* If we had a master ref, and it wasn't HEAD, we need to undo the
@@ -82,6 +87,7 @@ static void write_refs(struct ref *ref)
87
unlink(head_path);
88
}
89
write_one_ref(head);
90
+ free(head_path);
91
return;
92
}
93
@@ -89,13 +95,15 @@ static void write_refs(struct ref *ref)
95
if (master_ref)
96
return;
97
98
+ fprintf(stderr, "Setting HEAD to %s\n", head_ptr->name);
99
+
100
/*
101
* Uhhuh. Other end didn't have master. We start HEAD off with
102
* the first branch with the same value.
103
*/
96
- unlink(head_path);
97
- if (symlink(head_ptr->name, head_path) < 0)
104
+ if (create_symref(head_path, head_ptr->name) < 0)
105
die("unable to link HEAD to %s", head_ptr->name);
106
+ free(head_path);
107
}
108
109
static int clone_pack(int fd[2], int nr_match, char **match)