From c8bed835c2a37056aa8f61769c6d8cc7f57bc4d3 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 23 Jun 2017 09:01:42 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- refs/packed-backend.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'refs/packed-backend.c') diff --git a/refs/packed-backend.c b/refs/packed-backend.c index cd214e07a1..78e877a9e3 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -515,7 +515,7 @@ static int write_packed_entry(FILE *fh, const char *refname, 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, @@ -537,9 +537,15 @@ int packed_refs_lock(struct ref_store *ref_store, int flags) 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 @@ -698,10 +704,9 @@ int repack_without_refs(struct ref_store *ref_store, 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 */ -- cgit v1.2.3