Commit Diff


commit - ce3526e665af1bf37976bad5db91e63a4892b685
commit + 900499fd0de2c868694828487244f097de63289e
blob - 2b43e7ed974e7ba95556eac4c0b718e3c5706bb3
blob + 5551b60b73215eb11a82c034e1d2601ed9a15c31
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -1166,6 +1166,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;
 	}
@@ -1180,21 +1183,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");
 		}
 	}
@@ -1234,7 +1237,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;
@@ -1329,26 +1333,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 - bb314c3843f03978714c781199f72d807aeb3881
blob + 6fa4671fb9daa18d8e83c5e0144be2fd6b847e90
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -1159,15 +1159,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;
@@ -1185,8 +1186,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);
@@ -1227,9 +1228,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;
 	}
@@ -1239,10 +1240,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;
@@ -1253,7 +1254,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;
@@ -1382,6 +1383,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)
 {
@@ -1441,13 +1443,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)