move create_symref() past log_ref_write()
This doesn't change the code at all. It is done to make the next patch more obvious. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
e1dde3d06c
commit
41b625b047
94
refs.c
94
refs.c
@ -309,53 +309,6 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
|
|||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_symref(const char *ref_target, const char *refs_heads_master)
|
|
||||||
{
|
|
||||||
const char *lockpath;
|
|
||||||
char ref[1000];
|
|
||||||
int fd, len, written;
|
|
||||||
const char *git_HEAD = git_path("%s", ref_target);
|
|
||||||
|
|
||||||
#ifndef NO_SYMLINK_HEAD
|
|
||||||
if (prefer_symlink_refs) {
|
|
||||||
unlink(git_HEAD);
|
|
||||||
if (!symlink(refs_heads_master, git_HEAD))
|
|
||||||
return 0;
|
|
||||||
fprintf(stderr, "no symlink - falling back to symbolic ref\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
|
|
||||||
if (sizeof(ref) <= len) {
|
|
||||||
error("refname too long: %s", refs_heads_master);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
lockpath = mkpath("%s.lock", git_HEAD);
|
|
||||||
fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
|
|
||||||
if (fd < 0) {
|
|
||||||
error("Unable to open %s for writing", lockpath);
|
|
||||||
return -5;
|
|
||||||
}
|
|
||||||
written = write_in_full(fd, ref, len);
|
|
||||||
close(fd);
|
|
||||||
if (written != len) {
|
|
||||||
unlink(lockpath);
|
|
||||||
error("Unable to write to %s", lockpath);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
if (rename(lockpath, git_HEAD) < 0) {
|
|
||||||
unlink(lockpath);
|
|
||||||
error("Unable to create %s", git_HEAD);
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
if (adjust_shared_perm(git_HEAD)) {
|
|
||||||
unlink(lockpath);
|
|
||||||
error("Unable to fix permissions on %s", lockpath);
|
|
||||||
return -4;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int read_ref(const char *ref, unsigned char *sha1)
|
int read_ref(const char *ref, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
if (resolve_ref(ref, sha1, 1, NULL))
|
if (resolve_ref(ref, sha1, 1, NULL))
|
||||||
@ -1033,6 +986,53 @@ int write_ref_sha1(struct ref_lock *lock,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int create_symref(const char *ref_target, const char *refs_heads_master)
|
||||||
|
{
|
||||||
|
const char *lockpath;
|
||||||
|
char ref[1000];
|
||||||
|
int fd, len, written;
|
||||||
|
const char *git_HEAD = git_path("%s", ref_target);
|
||||||
|
|
||||||
|
#ifndef NO_SYMLINK_HEAD
|
||||||
|
if (prefer_symlink_refs) {
|
||||||
|
unlink(git_HEAD);
|
||||||
|
if (!symlink(refs_heads_master, git_HEAD))
|
||||||
|
return 0;
|
||||||
|
fprintf(stderr, "no symlink - falling back to symbolic ref\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
|
||||||
|
if (sizeof(ref) <= len) {
|
||||||
|
error("refname too long: %s", refs_heads_master);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
lockpath = mkpath("%s.lock", git_HEAD);
|
||||||
|
fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
|
||||||
|
if (fd < 0) {
|
||||||
|
error("Unable to open %s for writing", lockpath);
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
written = write_in_full(fd, ref, len);
|
||||||
|
close(fd);
|
||||||
|
if (written != len) {
|
||||||
|
unlink(lockpath);
|
||||||
|
error("Unable to write to %s", lockpath);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
if (rename(lockpath, git_HEAD) < 0) {
|
||||||
|
unlink(lockpath);
|
||||||
|
error("Unable to create %s", git_HEAD);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
if (adjust_shared_perm(git_HEAD)) {
|
||||||
|
unlink(lockpath);
|
||||||
|
error("Unable to fix permissions on %s", lockpath);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static char *ref_msg(const char *line, const char *endp)
|
static char *ref_msg(const char *line, const char *endp)
|
||||||
{
|
{
|
||||||
const char *ep;
|
const char *ep;
|
||||||
|
Loading…
Reference in New Issue
Block a user