Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH 3/6] lock_ref_sha1(): do not sometimes error() and sometimes die().
Date: Sat, 30 Sep 2006 15:30:34 -0700	[thread overview]
Message-ID: <7vlko19ed1.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: 7v1wptc7ou.fsf@assigned-by-dhcp.cox.net

This cleans up the error path in the function so it does not
die() itself sometimes while signalling an error with NULL some
other times which was inconsistent and confusing.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 refs.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/refs.c b/refs.c
index 6ee5f96..157de43 100644
--- a/refs.c
+++ b/refs.c
@@ -561,6 +561,7 @@ static struct ref_lock *lock_ref_sha1_ba
 	const char *orig_ref = ref;
 	struct ref_lock *lock;
 	struct stat st;
+	int last_errno = 0;
 	int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
 
 	lock = xcalloc(1, sizeof(struct ref_lock));
@@ -574,17 +575,18 @@ static struct ref_lock *lock_ref_sha1_ba
 		 * to remain.
 		 */
 		ref_file = git_path("%s", orig_ref);
-		if (remove_empty_directories(ref_file))
-			die("there are still refs under '%s'", orig_ref);
+		if (remove_empty_directories(ref_file)) {
+			last_errno = errno;
+			error("there are still refs under '%s'", orig_ref);
+			goto error_return;
+		}
 		ref = resolve_ref(orig_ref, lock->old_sha1, mustexist, NULL);
 	}
 	if (!ref) {
-		int last_errno = errno;
+		last_errno = errno;
 		error("unable to resolve reference %s: %s",
 			orig_ref, strerror(errno));
-		unlock_ref(lock);
-		errno = last_errno;
-		return NULL;
+		goto error_return;
 	}
 	lock->lk = xcalloc(1, sizeof(struct lock_file));
 
@@ -593,11 +595,19 @@ static struct ref_lock *lock_ref_sha1_ba
 	ref_file = git_path("%s", ref);
 	lock->force_write = lstat(ref_file, &st) && errno == ENOENT;
 
-	if (safe_create_leading_directories(ref_file))
-		die("unable to create directory for %s", ref_file);
+	if (safe_create_leading_directories(ref_file)) {
+		last_errno = errno;
+		error("unable to create directory for %s", ref_file);
+		goto error_return;
+	}
 	lock->lock_fd = hold_lock_file_for_update(lock->lk, ref_file, 1);
 
 	return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
+
+ error_return:
+	unlock_ref(lock);
+	errno = last_errno;
+	return NULL;
 }
 
 struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
-- 
1.4.2.1.g5a98f

  parent reply	other threads:[~2006-09-30 22:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-30 20:01 [PATCH 1/2] Move code resolving packed refs into its own function Christian Couder
2006-09-30 20:33 ` Junio C Hamano
2006-09-30 22:26   ` [PATCH 0/6] ref deletion and D/F conflict avoidance with packed-refs Junio C Hamano
2006-09-30 22:29     ` [PATCH 1/6] ref locking: allow 'foo' when 'foo/bar' used to exist but not anymore Junio C Hamano
2006-09-30 22:30     ` [PATCH 2/6] refs: minor restructuring of cached refs data Junio C Hamano
2006-09-30 22:30     ` Junio C Hamano [this message]
2006-09-30 22:30     ` [PATCH 4/6] lock_ref_sha1(): check D/F conflict with packed ref when creating Junio C Hamano
2006-09-30 22:30     ` [PATCH 5/6] delete_ref(): delete packed ref Junio C Hamano
2006-09-30 22:30     ` [PATCH 6/6] git-branch: remove D/F check done by hand Junio C Hamano
2006-09-30 22:36     ` [PATCH 0/6] ref deletion and D/F conflict avoidance with packed-refs Jeff King
2006-10-01  4:06   ` [PATCH 1/2] Move code resolving packed refs into its own function Christian Couder
2006-10-01  9:58     ` Junio C Hamano
2006-10-03 12:10       ` Jakub Narebski
2006-10-03 17:39         ` Junio C Hamano

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=7vlko19ed1.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    /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