git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/5] refs.c: return error instead of dying when locking fails during transaction

From
Ronnie Sahlberg <sahlberg@google.com>
Date
Jul 30, 2014, 21:52 UTC
Message-ID
<1406757168-3729-3-git-send-email-sahlberg@google.com>
In-Reply-To
<1406757168-3729-1-git-send-email-sahlberg@google.com>

Change lock_ref_sha1_basic to return an error instead of dying when we fail to lock a file during a transaction. This function is only called from transaction_commit() and it knows how to handle these failures.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
 refs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/refs.c b/refs.c
index 41cb51d..35f6db1 100644
--- a/refs.c
+++ b/refs.c
@@ -2206,6 +2206,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 
 	lock->lock_fd = hold_lock_file_for_update(lock->lk, ref_file, lflags);
 	if (lock->lock_fd < 0) {
+		last_errno = errno;
 		if (errno == ENOENT && --attempts_remaining > 0)
 			/*
 			 * Maybe somebody just deleted one of the
@@ -2213,8 +2214,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 			 * again:
 			 */
 			goto retry;
-		else
-			unable_to_lock_index_die(ref_file, errno);
+		else {
+			unable_to_lock_error(ref_file, errno);
+			goto error_return;
+		}
 	}
 	if (bad_ref)
 		return lock;
-- 
2.0.1.523.g0041e8a
Previous: Ronnie SahlbergNext: Ronnie Sahlberg
Message 3 of 6 in “ref-transactions-rename”
  1. 0/5 ref-transactions-renameRonnie Sahlberg, Jul 30, 2014
  2. 1/5 refs.c: allow passing raw git_committer_info as email to _update_reflogRonnie Sahlberg, Jul 30, 2014
  3. 2/5 refs.c: return error instead of dying when locking fails during transactionRonnie Sahlberg, Jul 30, 2014
  4. 3/5 refs.c: use packed refs when deleting refs during a transactionRonnie Sahlberg, Jul 30, 2014
  5. 4/5 refs.c: update rename_ref to use a transactionRonnie Sahlberg, Jul 30, 2014
  6. 5/5 refs.c: rollback the lockfile before we die() in repack_without_refsRonnie Sahlberg, Jul 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.