summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2017-03-26 02:42:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-27 17:23:39 (GMT)
commit0a3f07d6c0ce8ee3fb315d582a0eaaba56fb7873 (patch)
tree9b3a95c5397f4571e4f0a89d97d0fe25f4787297 /refs
parent33dfb9f3f2aa6b7cc3fcba84ad8ac1485272e003 (diff)
downloadgit-0a3f07d6c0ce8ee3fb315d582a0eaaba56fb7873.zip
git-0a3f07d6c0ce8ee3fb315d582a0eaaba56fb7873.tar.gz
git-0a3f07d6c0ce8ee3fb315d582a0eaaba56fb7873.tar.bz2
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>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index f17dadd..6d0fcc8 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2585,23 +2585,34 @@ static int files_rename_ref(struct ref_store *ref_store,
struct stat loginfo;
int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
struct strbuf err = STRBUF_INIT;
+ int ret;
- if (log && S_ISLNK(loginfo.st_mode))
- return error("reflog for %s is a symlink", oldrefname);
+ if (log && S_ISLNK(loginfo.st_mode)) {
+ ret = error("reflog for %s is a symlink", oldrefname);
+ goto out;
+ }
if (!resolve_ref_unsafe(oldrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
- orig_sha1, &flag))
- return error("refname %s not found", oldrefname);
+ orig_sha1, &flag)) {
+ ret = error("refname %s not found", oldrefname);
+ goto out;
+ }
- if (flag & REF_ISSYMREF)
- return error("refname %s is a symbolic ref, renaming it is not supported",
- oldrefname);
- if (!rename_ref_available(oldrefname, newrefname))
- return 1;
+ if (flag & REF_ISSYMREF) {
+ ret = error("refname %s is a symbolic ref, renaming it is not supported",
+ oldrefname);
+ goto out;
+ }
+ if (!rename_ref_available(oldrefname, newrefname)) {
+ ret = 1;
+ goto out;
+ }
- if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))
- return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
- oldrefname, strerror(errno));
+ if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG))) {
+ ret = error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
+ oldrefname, strerror(errno));
+ goto out;
+ }
if (delete_ref(logmsg, oldrefname, orig_sha1, REF_NODEREF)) {
error("unable to delete old %s", oldrefname);
@@ -2657,7 +2668,8 @@ static int files_rename_ref(struct ref_store *ref_store,
goto rollback;
}
- return 0;
+ ret = 0;
+ goto out;
rollback:
lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
@@ -2686,7 +2698,9 @@ static int files_rename_ref(struct ref_store *ref_store,
error("unable to restore logfile %s from "TMP_RENAMED_LOG": %s",
oldrefname, strerror(errno));
- return 1;
+ ret = 1;
+ out:
+ return ret;
}
static int close_ref(struct ref_lock *lock)