commit 91554d234c633881db3ad62e68994adab1d3a9eb from: Stefan Sperling via: Thomas Adam date: Sun Jun 25 17:34:21 2023 UTC fix cleanup progress reporting output commit - e8f803b5e0a1ec1775733d64e72d9e9e9b5a9026 commit + 91554d234c633881db3ad62e68994adab1d3a9eb blob - 05bbf129c161a7987a5dd3be1b38fa9ba12aa0a1 blob + 59f059736b78e75cd6e362a808245d5b01ad8a9a --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -1165,6 +1165,9 @@ cleanup_progress(void *arg, int nloose, int ncommits, a->last_npurged = npurged; } if (a->last_nredundant != nredundant) { + print_loose = 1; + print_commits = 1; + print_purged = 1; print_redundant = 1; a->last_nredundant = nredundant; } @@ -1179,21 +1182,21 @@ cleanup_progress(void *arg, int nloose, int ncommits, if (print_commits) printf("; %d commit%s scanned", ncommits, ncommits == 1 ? "" : "s"); - if (print_purged) { + if (print_purged || print_redundant) { if (a->dry_run) { - printf("; %d object%s could be purged", npurged, + printf("; could purge %d object%s", npurged, npurged == 1 ? "" : "s"); } else { - printf("; %d object%s purged", npurged, + printf("; purged %d object%s", npurged, npurged == 1 ? "" : "s"); } } if (print_redundant) { if (a->dry_run) { - printf("%d pack file%s could be purged", nredundant, + printf(", %d pack file%s", nredundant, nredundant == 1 ? "" : "s"); } else { - printf("%d pack file%s purged", nredundant, + printf(", %d pack file%s", nredundant, nredundant == 1 ? "" : "s"); } } @@ -1233,7 +1236,8 @@ cmd_cleanup(int argc, char *argv[]) const struct got_error *error = NULL; char *repo_path = NULL; struct got_repository *repo = NULL; - int ch, dry_run = 0, npacked = 0, verbosity = 0; + 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; @@ -1328,26 +1332,23 @@ cmd_cleanup(int argc, char *argv[]) cpa.verbosity = verbosity; error = got_repo_purge_unreferenced_loose_objects(repo, - &loose_before, &loose_after, &npacked, dry_run, ignore_mtime, + &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, cleanup_progress, &cpa, check_cancelled, NULL); if (cpa.printed_something) printf("\n"); if (error) goto done; - cpa.printed_something = 0; - cpa.last_ncommits = -1; - cpa.last_npurged = -1; - cpa.last_nloose = -1; - cpa.last_nredundant = -1; - error = got_repo_purge_redundant_packfiles(repo, &pack_before, - &pack_after, dry_run, cleanup_progress, &cpa, - check_cancelled, NULL); - if (error) - goto done; - if (cpa.printed_something) - printf("\n"); - total_size = (loose_before - loose_after) + (pack_before - pack_after); if (cpa.printed_something) { blob - 67ccceea225850c691fd8c0b8c3c4a6e397498dd blob + ea8cf37270d81a00cc006814c1e95430045f8277 --- include/got_repository_admin.h +++ include/got_repository_admin.h @@ -98,13 +98,15 @@ typedef const struct got_error *(*got_cleanup_progress */ const struct got_error * got_repo_purge_unreferenced_loose_objects(struct got_repository *repo, - off_t *size_before, off_t *size_after, int *npacked, int dry_run, - int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg, + off_t *size_before, off_t *size_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); 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); blob - dbfbfe97283f4b857964b519acf28b8bd6aef752 blob + 8d07805c20549afd334e001151748c6ec86fd1f1 --- lib/repository_admin.c +++ lib/repository_admin.c @@ -1156,15 +1156,16 @@ done: const struct got_error * got_repo_purge_unreferenced_loose_objects(struct got_repository *repo, - off_t *size_before, off_t *size_after, int *npacked, int dry_run, - int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg, + off_t *size_before, off_t *size_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) { const struct got_error *err; struct got_object_idset *loose_ids; struct got_object_idset *traversed_ids; struct got_object_id **referenced_ids; - int i, nreferenced, nloose, ncommits = 0; + int i, nreferenced; struct got_reflist_head refs; struct got_reflist_entry *re; struct purge_loose_object_arg arg; @@ -1182,8 +1183,8 @@ got_repo_purge_unreferenced_loose_objects(struct got_r progress_cb, progress_arg, &rl, repo); if (err) return err; - nloose = got_object_idset_num_elements(loose_ids); - if (nloose == 0) { + *nloose = got_object_idset_num_elements(loose_ids); + if (*nloose == 0) { got_object_idset_free(loose_ids); if (progress_cb) { err = progress_cb(progress_arg, 0, 0, 0, -1); @@ -1224,9 +1225,9 @@ got_repo_purge_unreferenced_loose_objects(struct got_r for (i = 0; i < nreferenced; i++) { struct got_object_id *id = referenced_ids[i]; - err = load_commit_or_tag(loose_ids, &ncommits, npacked, + err = load_commit_or_tag(loose_ids, ncommits, npacked, traversed_ids, id, repo, progress_cb, progress_arg, &rl, - nloose, cancel_cb, cancel_arg); + *nloose, cancel_cb, cancel_arg); if (err) goto done; } @@ -1236,10 +1237,10 @@ got_repo_purge_unreferenced_loose_objects(struct got_r arg.progress_arg = progress_arg; arg.progress_cb = progress_cb; arg.rl = &rl; - arg.nloose = nloose; + arg.nloose = *nloose; arg.npurged = 0; arg.size_purged = 0; - arg.ncommits = ncommits; + arg.ncommits = *ncommits; arg.dry_run = dry_run; arg.max_mtime = max_mtime; arg.ignore_mtime = ignore_mtime; @@ -1250,7 +1251,7 @@ got_repo_purge_unreferenced_loose_objects(struct got_r /* Produce a final progress report. */ if (progress_cb) { - err = progress_cb(progress_arg, nloose, ncommits, arg.npurged, + err = progress_cb(progress_arg, *nloose, *ncommits, arg.npurged, -1); if (err) goto done; @@ -1379,6 +1380,7 @@ pack_info_cmp(const void *a, const void *b) const struct got_error * got_repo_purge_redundant_packfiles(struct got_repository *repo, off_t *size_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) { @@ -1438,13 +1440,21 @@ got_repo_purge_redundant_packfiles(struct got_reposito goto done; if (!remove) continue; - err = progress_cb(progress_arg, -1, -1, -1, - ++redundant_packs); + if (progress_cb) { + err = progress_cb(progress_arg, nloose, ncommits, + npurged, ++redundant_packs); + if (err) + goto done; + } + } + + /* Produce a final progress report. */ + if (progress_cb) { + err = progress_cb(progress_arg, nloose, ncommits, npurged, + redundant_packs); if (err) goto done; } - - err = progress_cb(progress_arg, -1, -1, -1, redundant_packs); done: free(sorted); if (idset)