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>
Michael Haggerty committed
Jan 18, 2014 at 23:48 UTC
fa59ae7971498157370d935adbb2bfc28012aa9f
1 file changed
+30
-22
refs.c
+30
-22
@@ -2528,6 +2528,35 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
2528
*/
2529
#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
2530
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
+
2560
int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
2561
{
2562
unsigned char sha1[20], orig_sha1[20];
@@ -2575,30 +2604,9 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
2604
}
2605
}
2606
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))
2608
goto rollback;
2581
- }
2609
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
- }
2610
logmoved = log;
2611
2612
lock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);