Skip to content

Commit 9b25cf1

Browse files
committed
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 parent 0a88c83 commit 9b25cf1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/refdb_fs.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,22 +1100,27 @@ static int packed_write(refdb_fs_backend *backend)
11001100
static int packed_delete(refdb_fs_backend *backend, const char *ref_name)
11011101
{
11021102
size_t pack_pos;
1103-
int error;
1103+
int error, found = 0;
11041104

11051105
if ((error = packed_reload(backend)) < 0)
11061106
goto cleanup;
11071107

1108-
/* If a packed reference exists, remove it from the packfile and repack */
11091108
if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
11101109
goto cleanup;
11111110

1112-
if (!(error = git_sortedcache_lookup_index(
1113-
&pack_pos, backend->refcache, ref_name)))
1111+
/* If a packed reference exists, remove it from the packfile and repack if necessary */
1112+
error = git_sortedcache_lookup_index(&pack_pos, backend->refcache, ref_name);
1113+
if (error == 0) {
11141114
error = git_sortedcache_remove(backend->refcache, pack_pos);
1115+
found = 1;
1116+
}
1117+
if (error == GIT_ENOTFOUND)
1118+
error = 0;
11151119

11161120
git_sortedcache_wunlock(backend->refcache);
11171121

1118-
error = packed_write(backend);
1122+
if (found)
1123+
error = packed_write(backend);
11191124

11201125
cleanup:
11211126
return error;

0 commit comments

Comments
 (0)