Skip to content

Commit 0108451

Browse files
Martin Ågrengitster
authored andcommitted
refs.c: do not die if locking fails in write_pseudoref()
If we could not take the lock, we add an error to the `strbuf err` and return. However, this code is dead. The reason is that we take the lock using `LOCK_DIE_ON_ERROR`. Drop the flag to allow our more gentle error-handling to actually kick in. We could instead just drop the dead code and die here. But everything is prepared for gently propagating the error, so let's do that instead. There is similar dead code in `delete_pseudoref()`, but let's save that for the next patch. While at it, make the lock non-static. (Placing `struct lock_file`s on the stack used to be a bad idea, because the temp- and lockfile-machinery would keep a pointer into the struct. But after 076aa2c (tempfile: auto-allocate tempfiles on heap, 2017-09-05), we can safely have lockfiles on the stack.) Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75d9a25 commit 0108451

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

refs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
644644
{
645645
const char *filename;
646646
int fd;
647-
static struct lock_file lock;
647+
struct lock_file lock = LOCK_INIT;
648648
struct strbuf buf = STRBUF_INIT;
649649
int ret = -1;
650650

@@ -654,8 +654,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
654654
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
655655

656656
filename = git_path("%s", pseudoref);
657-
fd = hold_lock_file_for_update_timeout(&lock, filename,
658-
LOCK_DIE_ON_ERROR,
657+
fd = hold_lock_file_for_update_timeout(&lock, filename, 0,
659658
get_files_ref_lock_timeout_ms());
660659
if (fd < 0) {
661660
strbuf_addf(err, "could not open '%s' for writing: %s",

0 commit comments

Comments
 (0)