rename_ref(): extract function rename_tmp_log()
It's about to become a bit more complex. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
863808cd1a
commit
fa59ae7971
52
refs.c
52
refs.c
@ -2528,6 +2528,35 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
|
|||||||
*/
|
*/
|
||||||
#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
|
#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
|
||||||
|
|
||||||
|
static int rename_tmp_log(const char *newrefname)
|
||||||
|
{
|
||||||
|
if (safe_create_leading_directories(git_path("logs/%s", newrefname))) {
|
||||||
|
error("unable to create directory for %s", newrefname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
retry:
|
||||||
|
if (rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
|
||||||
|
if (errno==EISDIR || errno==ENOTDIR) {
|
||||||
|
/*
|
||||||
|
* rename(a, b) when b is an existing
|
||||||
|
* directory ought to result in ISDIR, but
|
||||||
|
* Solaris 5.8 gives ENOTDIR. Sheesh.
|
||||||
|
*/
|
||||||
|
if (remove_empty_directories(git_path("logs/%s", newrefname))) {
|
||||||
|
error("Directory not empty: logs/%s", newrefname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
goto retry;
|
||||||
|
} else {
|
||||||
|
error("unable to move logfile "TMP_RENAMED_LOG" to logs/%s: %s",
|
||||||
|
newrefname, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
|
int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20], orig_sha1[20];
|
unsigned char sha1[20], orig_sha1[20];
|
||||||
@ -2575,30 +2604,9 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log && safe_create_leading_directories(git_path("logs/%s", newrefname))) {
|
if (log && rename_tmp_log(newrefname))
|
||||||
error("unable to create directory for %s", newrefname);
|
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
|
||||||
|
|
||||||
retry:
|
|
||||||
if (log && rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
|
|
||||||
if (errno==EISDIR || errno==ENOTDIR) {
|
|
||||||
/*
|
|
||||||
* rename(a, b) when b is an existing
|
|
||||||
* directory ought to result in ISDIR, but
|
|
||||||
* Solaris 5.8 gives ENOTDIR. Sheesh.
|
|
||||||
*/
|
|
||||||
if (remove_empty_directories(git_path("logs/%s", newrefname))) {
|
|
||||||
error("Directory not empty: logs/%s", newrefname);
|
|
||||||
goto rollback;
|
|
||||||
}
|
|
||||||
goto retry;
|
|
||||||
} else {
|
|
||||||
error("unable to move logfile "TMP_RENAMED_LOG" to logs/%s: %s",
|
|
||||||
newrefname, strerror(errno));
|
|
||||||
goto rollback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logmoved = log;
|
logmoved = log;
|
||||||
|
|
||||||
lock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);
|
lock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user