Code

prune: show progress while marking reachable objects
[git.git] / reachable.c
index b515fa2de332cc570a8a32861bd8d6491b61133e..293d37d22481561b46cb8fbf747205a6ba73a420 100644 (file)
@@ -7,6 +7,7 @@
 #include "revision.h"
 #include "reachable.h"
 #include "cache-tree.h"
+#include "progress.h"
 
 static void process_blob(struct blob *blob,
                         struct object_array *p,
@@ -70,37 +71,36 @@ static void process_tree(struct tree *tree,
 static void process_tag(struct tag *tag, struct object_array *p, const char *name)
 {
        struct object *obj = &tag->object;
-       struct name_path me;
 
        if (obj->flags & SEEN)
                return;
        obj->flags |= SEEN;
 
-       me.up = NULL;
-       me.elem = "tag:/";
-       me.elem_len = 5;
-
        if (parse_tag(tag) < 0)
                die("bad tag object %s", sha1_to_hex(obj->sha1));
        if (tag->tagged)
                add_object(tag->tagged, p, NULL, name);
 }
 
-static void walk_commit_list(struct rev_info *revs)
+static void walk_commit_list(struct rev_info *revs, struct progress *progress)
 {
        int i;
        struct commit *commit;
-       struct object_array objects = { 0, 0, NULL };
+       struct object_array objects = OBJECT_ARRAY_INIT;
+       uint32_t count = 0;
 
        /* Walk all commits, process their trees */
-       while ((commit = get_revision(revs)) != NULL)
+       while ((commit = get_revision(revs)) != NULL) {
                process_tree(commit->tree, &objects, NULL, "");
+               display_progress(progress, ++count);
+       }
 
        /* Then walk all the pending objects, recursively processing them too */
        for (i = 0; i < revs->pending.nr; i++) {
                struct object_array_entry *pending = revs->pending.objects + i;
                struct object *obj = pending->item;
                const char *name = pending->name;
+               display_progress(progress, ++count);
                if (obj->type == OBJ_TAG) {
                        process_tag((struct tag *) obj, &objects, name);
                        continue;
@@ -196,7 +196,8 @@ static void add_cache_refs(struct rev_info *revs)
                add_cache_tree(active_cache_tree, revs);
 }
 
-void mark_reachable_objects(struct rev_info *revs, int mark_reflog)
+void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
+                           struct progress *progress)
 {
        /*
         * Set up revision parsing, and mark us as being interested
@@ -222,5 +223,5 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog)
         */
        if (prepare_revision_walk(revs))
                die("revision walk setup failed");
-       walk_commit_list(revs);
+       walk_commit_list(revs, progress);
 }