Skip to content

Commit c8bed83

Browse files
mhaggergitster
authored andcommitted
packed_refs_lock(): report errors via a struct strbuf *err
That way the callers don't have to come up with error messages themselves. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b7de57d commit c8bed83

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

refs/files-backend.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
10961096
struct ref_to_prune *refs_to_prune = NULL;
10971097
struct strbuf err = STRBUF_INIT;
10981098

1099-
packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR);
1099+
packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err);
11001100

11011101
iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, 0);
11021102
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
@@ -2679,9 +2679,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
26792679
}
26802680
}
26812681

2682-
if (packed_refs_lock(refs->packed_ref_store, 0)) {
2683-
strbuf_addf(err, "unable to lock packed-refs file: %s",
2684-
strerror(errno));
2682+
if (packed_refs_lock(refs->packed_ref_store, 0, err)) {
26852683
ret = TRANSACTION_GENERIC_ERROR;
26862684
goto cleanup;
26872685
}

refs/packed-backend.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static int write_packed_entry(FILE *fh, const char *refname,
515515
return 0;
516516
}
517517

518-
int packed_refs_lock(struct ref_store *ref_store, int flags)
518+
int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
519519
{
520520
struct packed_ref_store *refs =
521521
packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
@@ -537,9 +537,15 @@ int packed_refs_lock(struct ref_store *ref_store, int flags)
537537
if (hold_lock_file_for_update_timeout(
538538
&refs->lock,
539539
refs->path,
540-
flags, timeout_value) < 0 ||
541-
close_lock_file(&refs->lock))
540+
flags, timeout_value) < 0) {
541+
unable_to_lock_message(refs->path, errno, err);
542+
return -1;
543+
}
544+
545+
if (close_lock_file(&refs->lock)) {
546+
strbuf_addf(err, "unable to close %s: %s", refs->path, strerror(errno));
542547
return -1;
548+
}
543549

544550
/*
545551
* Now that we hold the `packed-refs` lock, make sure that our
@@ -698,10 +704,9 @@ int repack_without_refs(struct ref_store *ref_store,
698704
if (!needs_repacking)
699705
return 0; /* no refname exists in packed refs */
700706

701-
if (packed_refs_lock(&refs->base, 0)) {
702-
unable_to_lock_message(refs->path, errno, err);
707+
if (packed_refs_lock(&refs->base, 0, err))
703708
return -1;
704-
}
709+
705710
packed = get_packed_refs(refs);
706711

707712
/* Remove refnames from the cache */

refs/packed-backend.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ struct ref_store *packed_ref_store_create(const char *path,
66

77
/*
88
* Lock the packed-refs file for writing. Flags is passed to
9-
* hold_lock_file_for_update(). Return 0 on success. On errors, set
10-
* errno appropriately and return a nonzero value.
9+
* hold_lock_file_for_update(). Return 0 on success. On errors, write
10+
* an error message to `err` and return a nonzero value.
1111
*/
12-
int packed_refs_lock(struct ref_store *ref_store, int flags);
12+
int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err);
1313

1414
void add_packed_ref(struct ref_store *ref_store,
1515
const char *refname, const struct object_id *oid);

0 commit comments

Comments
 (0)