refdb: bubble up errors We can get useful information like GIT_ELOCKED out of this instead of just -1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index f978038..6faf6cc 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -944,41 +944,42 @@ static int packed_write(refdb_fs_backend *backend)
{
git_sortedcache *refcache = backend->refcache;
git_filebuf pack_file = GIT_FILEBUF_INIT;
+ int error;
size_t i;
/* lock the cache to updates while we do this */
- if (git_sortedcache_wlock(refcache) < 0)
- return -1;
+ if ((error = git_sortedcache_wlock(refcache)) < 0)
+ return error;
/* Open the file! */
- if (git_filebuf_open(&pack_file, git_sortedcache_path(refcache), 0, GIT_PACKEDREFS_FILE_MODE) < 0)
+ if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), 0, GIT_PACKEDREFS_FILE_MODE)) < 0)
goto fail;
/* Packfiles have a header... apparently
* This is in fact not required, but we might as well print it
* just for kicks */
- if (git_filebuf_printf(&pack_file, "%s\n", GIT_PACKEDREFS_HEADER) < 0)
+ if ((error = git_filebuf_printf(&pack_file, "%s\n", GIT_PACKEDREFS_HEADER)) < 0)
goto fail;
for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) {
struct packref *ref = git_sortedcache_entry(refcache, i);
assert(ref);
- if (packed_find_peel(backend, ref) < 0)
+ if ((error = packed_find_peel(backend, ref)) < 0)
goto fail;
- if (packed_write_ref(ref, &pack_file) < 0)
+ if ((error = packed_write_ref(ref, &pack_file)) < 0)
goto fail;
}
/* if we've written all the references properly, we can commit
* the packfile to make the changes effective */
- if (git_filebuf_commit(&pack_file) < 0)
+ if ((error = git_filebuf_commit(&pack_file)) < 0)
goto fail;
/* when and only when the packfile has been properly written,
* we can go ahead and remove the loose refs */
- if (packed_remove_loose(backend) < 0)
+ if ((error = packed_remove_loose(backend)) < 0)
goto fail;
git_sortedcache_updated(refcache);
@@ -991,7 +992,7 @@ fail:
git_filebuf_cleanup(&pack_file);
git_sortedcache_wunlock(refcache);
- return -1;
+ return error;
}
static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *author, const char *message);