Skip to content

Commit 0a3f07d

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 33dfb9f commit 0a3f07d

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

refs/files-backend.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,23 +2585,34 @@ static int files_rename_ref(struct ref_store *ref_store,
25852585
struct stat loginfo;
25862586
int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
25872587
struct strbuf err = STRBUF_INIT;
2588+
int ret;
25882589

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+
}
25912594

25922595
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+
}
25952600

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+
}
26012610

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+
}
26052616

26062617
if (delete_ref(logmsg, oldrefname, orig_sha1, REF_NODEREF)) {
26072618
error("unable to delete old %s", oldrefname);
@@ -2657,7 +2668,8 @@ static int files_rename_ref(struct ref_store *ref_store,
26572668
goto rollback;
26582669
}
26592670

2660-
return 0;
2671+
ret = 0;
2672+
goto out;
26612673

26622674
rollback:
26632675
lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
@@ -2686,7 +2698,9 @@ static int files_rename_ref(struct ref_store *ref_store,
26862698
error("unable to restore logfile %s from "TMP_RENAMED_LOG": %s",
26872699
oldrefname, strerror(errno));
26882700

2689-
return 1;
2701+
ret = 1;
2702+
out:
2703+
return ret;
26902704
}
26912705

26922706
static int close_ref(struct ref_lock *lock)

0 commit comments

Comments
 (0)