prune: show progress while marking reachable objects

prune already shows progress meter while pruning. The marking part may take a few seconds or more, depending on repository size. Show progress meter during this time too. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 5, 2011 at 19:00 UTC dc347195ccfbc87b6e445f5c31a5500e1df6c9b5
4 files changed +18 -7
builtin/prune.c
+5 -1
@@ -5,6 +5,7 @@
5 #include "builtin.h"
6 #include "reachable.h"
7 #include "parse-options.h"
8 +#include "progress.h"
9 #include "dir.h"
10
11 static const char * const prune_usage[] = {
@@ -124,6 +125,7 @@ static void remove_temporary_files(const char *path)
125 int cmd_prune(int argc, const char **argv, const char *prefix)
126 {
127 struct rev_info revs;
128 + struct progress *progress;
129 const struct option options[] = {
130 OPT__DRY_RUN(&show_only, "do not remove, show only"),
131 OPT__VERBOSE(&verbose, "report pruned objects"),
@@ -152,7 +154,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
154 else
155 die("unrecognized argument: %s", name);
156 }
155 - mark_reachable_objects(&revs, 1);
157 + progress = start_progress_delay("Checking connectivity", 0, 0, 2);
158 + mark_reachable_objects(&revs, 1, progress);
159 + stop_progress(&progress);
160 prune_object_dir(get_object_directory());
161
162 prune_packed_objects(show_only);
builtin/reflog.c
+1 -1
@@ -647,7 +647,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
647 init_revisions(&cb.revs, prefix);
648 if (cb.verbose)
649 printf("Marking reachable objects...");
650 - mark_reachable_objects(&cb.revs, 0);
650 + mark_reachable_objects(&cb.revs, 0, NULL);
651 if (cb.verbose)
652 putchar('\n');
653 }
reachable.c
+10 -4
@@ -7,6 +7,7 @@
7 #include "revision.h"
8 #include "reachable.h"
9 #include "cache-tree.h"
10 +#include "progress.h"
11
12 static void process_blob(struct blob *blob,
13 struct object_array *p,
@@ -81,21 +82,25 @@ static void process_tag(struct tag *tag, struct object_array *p, const char *nam
82 add_object(tag->tagged, p, NULL, name);
83 }
84
84 -static void walk_commit_list(struct rev_info *revs)
85 +static void walk_commit_list(struct rev_info *revs, struct progress *progress)
86 {
87 int i;
88 struct commit *commit;
89 struct object_array objects = OBJECT_ARRAY_INIT;
90 + uint32_t count = 0;
91
92 /* Walk all commits, process their trees */
91 - while ((commit = get_revision(revs)) != NULL)
93 + while ((commit = get_revision(revs)) != NULL) {
94 process_tree(commit->tree, &objects, NULL, "");
95 + display_progress(progress, ++count);
96 + }
97
98 /* Then walk all the pending objects, recursively processing them too */
99 for (i = 0; i < revs->pending.nr; i++) {
100 struct object_array_entry *pending = revs->pending.objects + i;
101 struct object *obj = pending->item;
102 const char *name = pending->name;
103 + display_progress(progress, ++count);
104 if (obj->type == OBJ_TAG) {
105 process_tag((struct tag *) obj, &objects, name);
106 continue;
@@ -191,7 +196,8 @@ static void add_cache_refs(struct rev_info *revs)
196 add_cache_tree(active_cache_tree, revs);
197 }
198
194 -void mark_reachable_objects(struct rev_info *revs, int mark_reflog)
199 +void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
200 + struct progress *progress)
201 {
202 /*
203 * Set up revision parsing, and mark us as being interested
@@ -217,5 +223,5 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog)
223 */
224 if (prepare_revision_walk(revs))
225 die("revision walk setup failed");
220 - walk_commit_list(revs);
226 + walk_commit_list(revs, progress);
227 }
reachable.h
+2 -1
@@ -1,6 +1,7 @@
1 #ifndef REACHEABLE_H
2 #define REACHEABLE_H
3
4 -extern void mark_reachable_objects(struct rev_info *revs, int mark_reflog);
4 +struct progress;
5 +extern void mark_reachable_objects(struct rev_info *revs, int mark_reflog, struct progress *);
6
7 #endif