Merge branch 'ma/lockfile-cleanup'
Code clean-up to adjust to a more recent lockfile API convention that allows lockfile instances kept on the stack. * ma/lockfile-cleanup: lock_file: move static locks into functions lock_file: make function-local locks non-static refs.c: do not die if locking fails in `delete_pseudoref()` refs.c: do not die if locking fails in `write_pseudoref()` t/helper/test-write-cache: clean up lock-handling
This commit is contained in:
16
refs.c
16
refs.c
@ -660,7 +660,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
|
||||
{
|
||||
const char *filename;
|
||||
int fd;
|
||||
static struct lock_file lock;
|
||||
struct lock_file lock = LOCK_INIT;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
int ret = -1;
|
||||
|
||||
@ -670,8 +670,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
|
||||
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
|
||||
|
||||
filename = git_path("%s", pseudoref);
|
||||
fd = hold_lock_file_for_update_timeout(&lock, filename,
|
||||
LOCK_DIE_ON_ERROR,
|
||||
fd = hold_lock_file_for_update_timeout(&lock, filename, 0,
|
||||
get_files_ref_lock_timeout_ms());
|
||||
if (fd < 0) {
|
||||
strbuf_addf(err, "could not open '%s' for writing: %s",
|
||||
@ -706,20 +705,23 @@ done:
|
||||
|
||||
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)) {
|
||||
struct lock_file lock = LOCK_INIT;
|
||||
int fd;
|
||||
struct object_id actual_old_oid;
|
||||
|
||||
fd = hold_lock_file_for_update_timeout(
|
||||
&lock, filename, LOCK_DIE_ON_ERROR,
|
||||
&lock, filename, 0,
|
||||
get_files_ref_lock_timeout_ms());
|
||||
if (fd < 0)
|
||||
die_errno(_("Could not open '%s' for writing"), filename);
|
||||
if (fd < 0) {
|
||||
error_errno(_("could not open '%s' for writing"),
|
||||
filename);
|
||||
return -1;
|
||||
}
|
||||
if (read_ref(pseudoref, &actual_old_oid))
|
||||
die("could not read ref '%s'", pseudoref);
|
||||
if (oidcmp(&actual_old_oid, old_oid)) {
|
||||
|
Reference in New Issue
Block a user