avoid searching the pack index twice in 'gotadmin cleanup'
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 65 66 67 68 69 70 71 72 73 74 75
diff --git a/lib/repository_admin.c b/lib/repository_admin.c
index 7461d26..391b44a 100644
--- a/lib/repository_admin.c
+++ b/lib/repository_admin.c
@@ -721,55 +721,31 @@ done:
}
static const struct got_error *
-search_packidx(int *found, struct got_object_id *id,
- struct got_repository *repo)
-{
- const struct got_error *err = NULL;
- struct got_packidx *packidx = NULL;
- int idx;
-
- *found = 0;
-
- err = got_repo_search_packidx(&packidx, &idx, repo, id);
- if (err == NULL)
- *found = 1; /* object is already packed */
- else if (err->code == GOT_ERR_NO_OBJ)
- err = NULL;
- return err;
-}
-
-static const struct got_error *
preserve_loose_object(struct got_object_idset *loose_ids,
struct got_object_id *id, struct got_repository *repo, int *npacked)
{
const struct got_error *err = NULL;
- int is_packed;
+ struct got_object *obj;
if (!got_object_idset_contains(loose_ids, id))
return NULL;
- err = search_packidx(&is_packed, id, repo);
- if (err)
- return err;
- if (is_packed) {
- struct got_object *obj;
-
+ /*
+ * Try to open this object from a pack file. This ensures that
+ * we do in fact have a valid packed copy of the object. Otherwise
+ * we should not delete the loose representation of this object.
+ */
+ err = got_object_open_packed(&obj, id, repo);
+ if (err == NULL) {
+ got_object_close(obj);
/*
- * Sanity check: Open the packed object to prevent a
- * corrupt pack index from misleading us.
+ * The object is referenced and packed.
+ * We can purge the redundantly stored loose object.
*/
- err = got_object_open_packed(&obj, id, repo);
- if (err == NULL) {
- got_object_close(obj);
- /*
- * The object is referenced and packed.
- * We can purge the redundantly stored loose object.
- */
- (*npacked)++;
- return NULL;
- } else if (err->code != GOT_ERR_NO_OBJ)
- return err;
- }
+ (*npacked)++;
+ return NULL;
+ } else if (err->code != GOT_ERR_NO_OBJ)
+ return err;
/*
* This object is referenced and not packed.