git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: git@vger.kernel.org
Cc: David Turner <novalis@novalis.org>
Subject: [PATCH 3/5] refs.c: drop dead code checking lock status in `delete_pseudoref()`
Date: Sun,  6 May 2018 16:10:29 +0200	[thread overview]
Message-ID: <20180506141031.30204-4-martin.agren@gmail.com> (raw)

After taking the lock we check whether we got it and die otherwise. But
since we take the lock using `LOCK_DIE_ON_ERROR`, we would already have
died.

Unlike in the previous patch, this function is not prepared for
indicating errors via a `strbuf err`, so let's just drop the dead code.
Any improved error-handling can be added later.

While at it, make the lock non-static and reduce its scope.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 refs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/refs.c b/refs.c
index 8c50b8b139..7abd30dfe1 100644
--- a/refs.c
+++ b/refs.c
@@ -689,20 +689,17 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
 
 static int delete_pseudoref(const char *pseudoref, const struct object_id *old_oid)
 {
-	static struct lock_file lock;
 	const char *filename;
 
 	filename = git_path("%s", pseudoref);
 
 	if (old_oid && !is_null_oid(old_oid)) {
-		int fd;
+		struct lock_file lock = LOCK_INIT;
 		struct object_id actual_old_oid;
 
-		fd = hold_lock_file_for_update_timeout(
+		hold_lock_file_for_update_timeout(
 				&lock, filename, LOCK_DIE_ON_ERROR,
 				get_files_ref_lock_timeout_ms());
-		if (fd < 0)
-			die_errno(_("Could not open '%s' for writing"), filename);
 		if (read_ref(pseudoref, &actual_old_oid))
 			die("could not read ref '%s'", pseudoref);
 		if (oidcmp(&actual_old_oid, old_oid)) {
-- 
2.17.0.411.g9fd64c8e46


             reply	other threads:[~2018-05-06 14:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-06 14:10 Martin Ågren [this message]
2018-05-06 15:54 ` [PATCH 3/5] refs.c: drop dead code checking lock status in `delete_pseudoref()` David Turner
2018-05-08 18:10 ` Jeff King
2018-05-09  4:23   ` Martin Ågren

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20180506141031.30204-4-martin.agren@gmail.com \
    --to=martin.agren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=novalis@novalis.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).