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>
Michael Haggerty committed
Jun 23, 2017 at 09:01 UTC
c8bed835c2a37056aa8f61769c6d8cc7f57bc4d3
3 files changed
+16
-13
refs/files-backend.c
+2
-4
@@ -1096,7 +1096,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
1096
struct ref_to_prune *refs_to_prune = NULL;
1097
struct strbuf err = STRBUF_INIT;
1098
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);
1100
1101
iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, 0);
1102
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
@@ -2679,9 +2679,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
2679
}
2680
}
2681
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)) {
2683
ret = TRANSACTION_GENERIC_ERROR;
2684
goto cleanup;
2685
}
refs/packed-backend.c
+11
-6
@@ -515,7 +515,7 @@ static int write_packed_entry(FILE *fh, const char *refname,
515
return 0;
516
}
517
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)
519
{
520
struct packed_ref_store *refs =
521
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)
537
if (hold_lock_file_for_update_timeout(
538
&refs->lock,
539
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));
547
return -1;
548
+ }
549
550
/*
551
* 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,
704
if (!needs_repacking)
705
return 0; /* no refname exists in packed refs */
706
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))
708
return -1;
704
- }
709
+
710
packed = get_packed_refs(refs);
711
712
/* Remove refnames from the cache */
refs/packed-backend.h
+3
-3
@@ -6,10 +6,10 @@ struct ref_store *packed_ref_store_create(const char *path,
6
7
/*
8
* 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.
11
*/
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);
13
14
void add_packed_ref(struct ref_store *ref_store,
15
const char *refname, const struct object_id *oid);