commit df608fc203b5a43669fc6d8f886c4ab4a518b6b6 from: Omar Polo date: Mon Jul 10 16:51:01 2023 UTC workz commit - 0d23c640a51b599b99c9fe781c54e1bd371bc433 commit + df608fc203b5a43669fc6d8f886c4ab4a518b6b6 blob - cdaeef909c106875bbbf659a52c64f0eac22d6d1 blob + 89a96527bdeb14c7ad3997dff379e3f0cb4379a1 --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -1251,7 +1251,6 @@ cmd_cleanup(int argc, char *argv[]) int ch, dry_run = 0, verbosity = 0; int ncommits = 0, nloose = 0, npacked = 0; int remove_lonely_packidx = 0, ignore_mtime = 0; - struct got_lockfile *lock = NULL; struct got_cleanup_progress_arg cpa; struct got_lonely_packidx_progress_arg lpa; off_t loose_before, loose_after; @@ -1322,10 +1321,6 @@ cmd_cleanup(int argc, char *argv[]) "this implies that objects must not be deleted"); goto done; } - - error = got_repo_cleanup_prepare(repo, &lock); - if (error) - goto done; if (remove_lonely_packidx) { memset(&lpa, 0, sizeof(lpa)); @@ -1343,18 +1338,8 @@ cmd_cleanup(int argc, char *argv[]) cpa.dry_run = dry_run; cpa.verbosity = verbosity; - error = got_repo_purge_unreferenced_loose_objects(repo, - &loose_before, &loose_after, &ncommits, &nloose, &npacked, - dry_run, ignore_mtime, cleanup_progress, &cpa, - check_cancelled, NULL); - if (error) { - if (cpa.printed_something) - printf("\n"); - goto done; - } - - error = got_repo_purge_redundant_packfiles(repo, &pack_before, - &pack_after, dry_run, ncommits, nloose, npacked, + error = got_repo_cleanup(repo, &loose_before, &loose_after, + &pack_before, &pack_after, &npacked, dry_run, ignore_mtime, cleanup_progress, &cpa, check_cancelled, NULL); if (cpa.printed_something) printf("\n"); @@ -1398,7 +1383,6 @@ cmd_cleanup(int argc, char *argv[]) } done: - got_repo_cleanup_complete(repo, lock); if (repo) got_repo_close(repo); if (pack_fds) { blob - ea8cf37270d81a00cc006814c1e95430045f8277 blob + 5c8a41b06b8735767c2fb5b22ea03d83779a6495 --- include/got_repository_admin.h +++ include/got_repository_admin.h @@ -14,8 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -struct got_lockfile; - /* A callback function which gets invoked with progress information to print. */ typedef const struct got_error *(*got_pack_progress_cb)(void *arg, int ncolored, int nfound, int ntrees, off_t packfile_size, int ncommits, @@ -70,18 +68,6 @@ got_repo_list_pack(FILE *packfile, struct got_object_i struct got_repository *repo, got_pack_list_cb list_cb, void *list_arg, got_cancel_cb cancel_cb, void *cancel_arg); -/* - * Prepare for removing loose objects or redundant packfiles. - * - * These functions do the necessary locking in order to avoid - * concurrent operation to irremediably damage the repository. - */ -const struct got_error * -got_repo_cleanup_prepare(struct got_repository *, struct got_lockfile **); - -const struct got_error * -got_repo_cleanup_complete(struct got_repository *, struct got_lockfile *); - /* A callback function which gets invoked with cleanup information to print. */ typedef const struct got_error *(*got_cleanup_progress_cb)(void *arg, int nloose, int ncommits, int npurged, int nredundant); @@ -94,22 +80,17 @@ typedef const struct got_error *(*got_cleanup_progress * implementation-defined timestamp threshold, unless ignore_mtime is set. * Return the disk space size occupied by loose objects before and after * the operation. + * Remove pack file which are redundant because all their objects are + * unreachable or already provided by other packs. * Return the number of loose objects which are also stored in a pack file. */ const struct got_error * -got_repo_purge_unreferenced_loose_objects(struct got_repository *repo, - off_t *size_before, off_t *size_after, int *ncommits, int *nloose, - int *npacked, int dry_run, int ignore_mtime, +got_repo_cleanup(struct got_repository *repo, off_t *loose_before, + off_t *loose_after, off_t *pack_before, off_t *pack_after, + int dry_run, int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg, got_cancel_cb cancel_cb, void *cancel_arg); -const struct got_error * -got_repo_purge_redundant_packfiles(struct got_repository *repo, - off_t *before, off_t *size_after, int dry_run, - int nloose, int ncommits, int npurged, - got_cleanup_progress_cb progress_cb, void *progress_arg, - got_cancel_cb cancel_cb, void *cancel_arg); - /* A callback function which gets invoked with cleanup information to print. */ typedef const struct got_error *(*got_lonely_packidx_progress_cb)(void *arg, const char *path); blob - 19d5908c4cf536ad152ec319e3493ffdd5a1183d blob + 064041ebe0672364e61cfda87818e3da74455499 --- lib/repository_admin.c +++ lib/repository_admin.c @@ -613,9 +613,8 @@ done: return err; } -const struct got_error * -got_repo_cleanup_prepare(struct got_repository *repo, - struct got_lockfile **lk) +static const struct got_error * +cleanup_lock(struct got_repository *repo, struct got_lockfile **lk) { const struct got_error *err; char myname[_POSIX_HOST_NAME_MAX + 1]; @@ -640,8 +639,7 @@ got_repo_cleanup_prepare(struct got_repository *repo, } const struct got_error * -got_repo_cleanup_complete(struct got_repository *repo, - struct got_lockfile *lk) +cleanup_unlock(struct got_repository *repo, struct got_lockfile *lk) { if (lk == NULL) return NULL; @@ -1159,8 +1157,10 @@ done: } const struct got_error * -got_repo_purge_unreferenced_loose_objects(struct got_repository *repo, - off_t *size_before, off_t *size_after, int *ncommits, int *nloose, +got_repo_cleanup(struct got_repository *repo, + off_t *loose_before, off_t *loose_after, + off_t *pack_before, off_t *pack_after, + int *ncommits, int *nloose, int *npacked, int dry_run, int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg, got_cancel_cb cancel_cb, void *cancel_arg) @@ -1179,11 +1179,11 @@ got_repo_purge_unreferenced_loose_objects(struct got_r TAILQ_INIT(&refs); got_ratelimit_init(&rl, 0, 500); - *size_before = 0; - *size_after = 0; + *loose_before = 0; + *loose_after = 0; *npacked = 0; - err = get_loose_object_ids(&loose_ids, size_before, + err = get_loose_object_ids(&loose_ids, loose_before, progress_cb, progress_arg, &rl, repo); if (err) return err; @@ -1251,7 +1251,7 @@ got_repo_purge_unreferenced_loose_objects(struct got_r err = got_object_idset_for_each(loose_ids, purge_loose_object, &arg); if (err) goto done; - *size_after = *size_before - arg.size_purged; + *loose_after = *loose_before - arg.size_purged; /* Produce a final progress report. */ if (progress_cb) {