struct ref_to_prune *refs_to_prune = NULL;
struct strbuf err = STRBUF_INIT;
- packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR);
+ packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err);
iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, 0);
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
}
}
- if (packed_refs_lock(refs->packed_ref_store, 0)) {
- strbuf_addf(err, "unable to lock packed-refs file: %s",
- strerror(errno));
+ if (packed_refs_lock(refs->packed_ref_store, 0, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
}
return 0;
}
-int packed_refs_lock(struct ref_store *ref_store, int flags)
+int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
{
struct packed_ref_store *refs =
packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
if (hold_lock_file_for_update_timeout(
&refs->lock,
refs->path,
- flags, timeout_value) < 0 ||
- close_lock_file(&refs->lock))
+ flags, timeout_value) < 0) {
+ unable_to_lock_message(refs->path, errno, err);
+ return -1;
+ }
+
+ if (close_lock_file(&refs->lock)) {
+ strbuf_addf(err, "unable to close %s: %s", refs->path, strerror(errno));
return -1;
+ }
/*
* Now that we hold the `packed-refs` lock, make sure that our
if (!needs_repacking)
return 0; /* no refname exists in packed refs */
- if (packed_refs_lock(&refs->base, 0)) {
- unable_to_lock_message(refs->path, errno, err);
+ if (packed_refs_lock(&refs->base, 0, err))
return -1;
- }
+
packed = get_packed_refs(refs);
/* Remove refnames from the cache */
/*
* Lock the packed-refs file for writing. Flags is passed to
- * hold_lock_file_for_update(). Return 0 on success. On errors, set
- * errno appropriately and return a nonzero value.
+ * hold_lock_file_for_update(). Return 0 on success. On errors, write
+ * an error message to `err` and return a nonzero value.
*/
-int packed_refs_lock(struct ref_store *ref_store, int flags);
+int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err);
void add_packed_ref(struct ref_store *ref_store,
const char *refname, const struct object_id *oid);