files-backend: make sure files_rename_ref() always reach the end

This is a no-op patch. It prepares the function so that we can release resources (to be added later in this function) before we return. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 26, 2017 at 09:42 UTC 0a3f07d6c0ce8ee3fb315d582a0eaaba56fb7873
1 file changed +28 -14
refs/files-backend.c
+28 -14
@@ -2585,23 +2585,34 @@ static int files_rename_ref(struct ref_store *ref_store,
2585 struct stat loginfo;
2586 int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
2587 struct strbuf err = STRBUF_INIT;
2588 + int ret;
2589
2589 - if (log && S_ISLNK(loginfo.st_mode))
2590 - return error("reflog for %s is a symlink", oldrefname);
2590 + if (log && S_ISLNK(loginfo.st_mode)) {
2591 + ret = error("reflog for %s is a symlink", oldrefname);
2592 + goto out;
2593 + }
2594
2595 if (!resolve_ref_unsafe(oldrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
2593 - orig_sha1, &flag))
2594 - return error("refname %s not found", oldrefname);
2596 + orig_sha1, &flag)) {
2597 + ret = error("refname %s not found", oldrefname);
2598 + goto out;
2599 + }
2600
2596 - if (flag & REF_ISSYMREF)
2597 - return error("refname %s is a symbolic ref, renaming it is not supported",
2598 - oldrefname);
2599 - if (!rename_ref_available(oldrefname, newrefname))
2600 - return 1;
2601 + if (flag & REF_ISSYMREF) {
2602 + ret = error("refname %s is a symbolic ref, renaming it is not supported",
2603 + oldrefname);
2604 + goto out;
2605 + }
2606 + if (!rename_ref_available(oldrefname, newrefname)) {
2607 + ret = 1;
2608 + goto out;
2609 + }
2610
2602 - if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))
2603 - return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
2604 - oldrefname, strerror(errno));
2611 + if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG))) {
2612 + ret = error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
2613 + oldrefname, strerror(errno));
2614 + goto out;
2615 + }
2616
2617 if (delete_ref(logmsg, oldrefname, orig_sha1, REF_NODEREF)) {
2618 error("unable to delete old %s", oldrefname);
@@ -2657,7 +2668,8 @@ static int files_rename_ref(struct ref_store *ref_store,
2668 goto rollback;
2669 }
2670
2660 - return 0;
2671 + ret = 0;
2672 + goto out;
2673
2674 rollback:
2675 lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
@@ -2686,7 +2698,9 @@ static int files_rename_ref(struct ref_store *ref_store,
2698 error("unable to restore logfile %s from "TMP_RENAMED_LOG": %s",
2699 oldrefname, strerror(errno));
2700
2689 - return 1;
2701 + ret = 1;
2702 + out:
2703 + return ret;
2704 }
2705
2706 static int close_ref(struct ref_lock *lock)