refdb: fix packed_delete clobbering some errors In the case of a failed lookup, we'd paper over that by writing back the packed-refs successfully.
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
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index aab1103..2236027 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1100,22 +1100,27 @@ fail:
static int packed_delete(refdb_fs_backend *backend, const char *ref_name)
{
size_t pack_pos;
- int error;
+ int error, found = 0;
if ((error = packed_reload(backend)) < 0)
goto cleanup;
- /* If a packed reference exists, remove it from the packfile and repack */
if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
goto cleanup;
- if (!(error = git_sortedcache_lookup_index(
- &pack_pos, backend->refcache, ref_name)))
+ /* If a packed reference exists, remove it from the packfile and repack if necessary */
+ error = git_sortedcache_lookup_index(&pack_pos, backend->refcache, ref_name);
+ if (error == 0) {
error = git_sortedcache_remove(backend->refcache, pack_pos);
+ found = 1;
+ }
+ if (error == GIT_ENOTFOUND)
+ error = 0;
git_sortedcache_wunlock(backend->refcache);
- error = packed_write(backend);
+ if (found)
+ error = packed_write(backend);
cleanup:
return error;