Skip to content

Commit fa59ae7

Browse files
mhaggergitster
authored andcommitted
rename_ref(): extract function rename_tmp_log()
It's about to become a bit more complex. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 863808c commit fa59ae7

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

refs.c

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,35 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
25282528
*/
25292529
#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
25302530

2531+
static int rename_tmp_log(const char *newrefname)
2532+
{
2533+
if (safe_create_leading_directories(git_path("logs/%s", newrefname))) {
2534+
error("unable to create directory for %s", newrefname);
2535+
return -1;
2536+
}
2537+
2538+
retry:
2539+
if (rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
2540+
if (errno==EISDIR || errno==ENOTDIR) {
2541+
/*
2542+
* rename(a, b) when b is an existing
2543+
* directory ought to result in ISDIR, but
2544+
* Solaris 5.8 gives ENOTDIR. Sheesh.
2545+
*/
2546+
if (remove_empty_directories(git_path("logs/%s", newrefname))) {
2547+
error("Directory not empty: logs/%s", newrefname);
2548+
return -1;
2549+
}
2550+
goto retry;
2551+
} else {
2552+
error("unable to move logfile "TMP_RENAMED_LOG" to logs/%s: %s",
2553+
newrefname, strerror(errno));
2554+
return -1;
2555+
}
2556+
}
2557+
return 0;
2558+
}
2559+
25312560
int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
25322561
{
25332562
unsigned char sha1[20], orig_sha1[20];
@@ -2575,30 +2604,9 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
25752604
}
25762605
}
25772606

2578-
if (log && safe_create_leading_directories(git_path("logs/%s", newrefname))) {
2579-
error("unable to create directory for %s", newrefname);
2607+
if (log && rename_tmp_log(newrefname))
25802608
goto rollback;
2581-
}
25822609

2583-
retry:
2584-
if (log && rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
2585-
if (errno==EISDIR || errno==ENOTDIR) {
2586-
/*
2587-
* rename(a, b) when b is an existing
2588-
* directory ought to result in ISDIR, but
2589-
* Solaris 5.8 gives ENOTDIR. Sheesh.
2590-
*/
2591-
if (remove_empty_directories(git_path("logs/%s", newrefname))) {
2592-
error("Directory not empty: logs/%s", newrefname);
2593-
goto rollback;
2594-
}
2595-
goto retry;
2596-
} else {
2597-
error("unable to move logfile "TMP_RENAMED_LOG" to logs/%s: %s",
2598-
newrefname, strerror(errno));
2599-
goto rollback;
2600-
}
2601-
}
26022610
logmoved = log;
26032611

26042612
lock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);

0 commit comments

Comments
 (0)