git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: sahlberg@google.com, jrnieder@gmail.com, gitster@pobox.com,
	git@vger.kernel.org
Subject: [PATCH 3/4] lock_ref_sha1_basic: simplify error code path
Date: Tue, 18 Nov 2014 20:37:40 -0500	[thread overview]
Message-ID: <20141119013739.GC2135@peff.net> (raw)
In-Reply-To: <20141119013532.GA861@peff.net>

For most errors, we jump to a goto label that unlocks the
ref and returns NULL. However, in none of these error paths
would we ever have actually locked the ref. By the time we
actually take the lock, we follow a different path that does
not ever hit this goto (we rely on verify_lock to unlock if
it finds an error).

We can just drop the goto completely and return NULL as
appropriate.

Signed-off-by: Jeff King <peff@peff.net>
---
 refs.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/refs.c b/refs.c
index 169a46d..fafae7e 100644
--- a/refs.c
+++ b/refs.c
@@ -2260,7 +2260,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 		ref_file = git_path("%s", orig_refname);
 		if (remove_empty_directories(ref_file)) {
 			error("there are still refs under '%s'", orig_refname);
-			goto error_return;
+			return NULL;
 		}
 		refname = resolve_ref_unsafe(orig_refname, resolve_flags,
 					     lock->old_sha1, &type);
@@ -2270,7 +2270,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 	if (!refname) {
 		error("unable to resolve reference %s: %s",
 			orig_refname, strerror(errno));
-		goto error_return;
+		return NULL;
 	}
 	missing = is_null_sha1(lock->old_sha1);
 	/* When the ref did not exist and we are creating it,
@@ -2281,7 +2281,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 	if (missing &&
 	     !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) {
 		errno = ENOTDIR;
-		goto error_return;
+		return NULL;
 	}
 
 	lock->lk = xcalloc(1, sizeof(struct lock_file));
@@ -2309,7 +2309,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 		/* fall through */
 	default:
 		error("unable to create directory for %s", ref_file);
-		goto error_return;
+		return NULL;
 	}
 
 	lock->lock_fd = hold_lock_file_for_update(lock->lk, ref_file, lflags);
@@ -2325,10 +2325,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 			unable_to_lock_die(ref_file, errno);
 	}
 	return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
-
- error_return:
-	unlock_ref(lock);
-	return NULL;
 }
 
 struct ref_lock *lock_any_ref_for_update(const char *refname,
-- 
2.1.2.596.g7379948

  parent reply	other threads:[~2014-11-19  1:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18 23:17 [PATCH] refs.c: handle locking failure during transaction better Stefan Beller
2014-11-18 23:34 ` Stefan Beller
2014-11-19  1:13   ` Stefan Beller
2014-11-19  1:35     ` [PATCH 0/4] error cleanups in lock_ref_sha1_basic Jeff King
2014-11-19  1:37       ` [PATCH 1/4] error: save and restore errno Jeff King
2014-11-19  1:41         ` Stefan Beller
2014-11-19  1:43         ` Jonathan Nieder
2014-11-19  1:47           ` Jeff King
2014-11-19 18:14             ` Junio C Hamano
2014-11-19 18:28               ` Jeff King
2014-11-19  1:37       ` [PATCH 2/4] lock_ref_sha1_basic: simplify errno handling Jeff King
2014-11-19  1:54         ` Jonathan Nieder
2014-11-21  9:25         ` Michael Haggerty
2014-11-19  1:37       ` Jeff King [this message]
2014-11-19  2:00         ` [PATCH 3/4] lock_ref_sha1_basic: simplify error code path Jonathan Nieder
2014-11-19  2:04           ` Jeff King
2014-11-19  2:07             ` Jonathan Nieder
2014-11-19 21:41               ` Junio C Hamano
2014-11-19 22:28               ` Jeff King
2014-11-19 22:34                 ` Junio C Hamano
2014-11-19 22:36                   ` Jeff King
2014-11-20  1:07                 ` Jonathan Nieder
2014-11-19  1:41       ` [PATCH 4/4] lock_ref_sha1_basic: do not die on locking errors Jeff King
2014-11-19  2:05         ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141119013739.GC2135@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=sahlberg@google.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).