reachable: per-object progress
The current progress code really just counts commits. This patch makes it count all objects, giving us a "total" count close to what a repack would show. This is nice when using "git gc", which will usually have just repacked the whole repo. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Nov 8, 2011 at 00:37 UTC
0b26abc0f59ce7899257f75d63ce836e1a6566bd
1 file changed
+37
-14
reachable.c
+37
-14
@@ -9,10 +9,23 @@
9
#include "cache-tree.h"
10
#include "progress.h"
11
12
+struct connectivity_progress {
13
+ struct progress *progress;
14
+ unsigned long count;
15
+};
16
+
17
+static void update_progress(struct connectivity_progress *cp)
18
+{
19
+ cp->count++;
20
+ if ((cp->count & 1023) == 0)
21
+ display_progress(cp->progress, cp->count);
22
+}
23
+
24
static void process_blob(struct blob *blob,
25
struct object_array *p,
26
struct name_path *path,
15
- const char *name)
27
+ const char *name,
28
+ struct connectivity_progress *cp)
29
{
30
struct object *obj = &blob->object;
31
@@ -21,6 +34,7 @@ static void process_blob(struct blob *blob,
34
if (obj->flags & SEEN)
35
return;
36
obj->flags |= SEEN;
37
+ update_progress(cp);
38
/* Nothing to do, really .. The blob lookup was the important part */
39
}
40
@@ -35,7 +49,8 @@ static void process_gitlink(const unsigned char *sha1,
49
static void process_tree(struct tree *tree,
50
struct object_array *p,
51
struct name_path *path,
38
- const char *name)
52
+ const char *name,
53
+ struct connectivity_progress *cp)
54
{
55
struct object *obj = &tree->object;
56
struct tree_desc desc;
@@ -47,6 +62,7 @@ static void process_tree(struct tree *tree,
62
if (obj->flags & SEEN)
63
return;
64
obj->flags |= SEEN;
65
+ update_progress(cp);
66
if (parse_tree(tree) < 0)
67
die("bad tree object %s", sha1_to_hex(obj->sha1));
68
add_object(obj, p, path, name);
@@ -58,23 +74,25 @@ static void process_tree(struct tree *tree,
74
75
while (tree_entry(&desc, &entry)) {
76
if (S_ISDIR(entry.mode))
61
- process_tree(lookup_tree(entry.sha1), p, &me, entry.path);
77
+ process_tree(lookup_tree(entry.sha1), p, &me, entry.path, cp);
78
else if (S_ISGITLINK(entry.mode))
79
process_gitlink(entry.sha1, p, &me, entry.path);
80
else
65
- process_blob(lookup_blob(entry.sha1), p, &me, entry.path);
81
+ process_blob(lookup_blob(entry.sha1), p, &me, entry.path, cp);
82
}
83
free(tree->buffer);
84
tree->buffer = NULL;
85
}
86
71
-static void process_tag(struct tag *tag, struct object_array *p, const char *name)
87
+static void process_tag(struct tag *tag, struct object_array *p,
88
+ const char *name, struct connectivity_progress *cp)
89
{
90
struct object *obj = &tag->object;
91
92
if (obj->flags & SEEN)
93
return;
94
obj->flags |= SEEN;
95
+ update_progress(cp);
96
97
if (parse_tag(tag) < 0)
98
die("bad tag object %s", sha1_to_hex(obj->sha1));
@@ -82,17 +100,17 @@ static void process_tag(struct tag *tag, struct object_array *p, const char *nam
100
add_object(tag->tagged, p, NULL, name);
101
}
102
85
-static void walk_commit_list(struct rev_info *revs, struct progress *progress)
103
+static void walk_commit_list(struct rev_info *revs,
104
+ struct connectivity_progress *cp)
105
{
106
int i;
107
struct commit *commit;
108
struct object_array objects = OBJECT_ARRAY_INIT;
90
- uint32_t count = 0;
109
110
/* Walk all commits, process their trees */
111
while ((commit = get_revision(revs)) != NULL) {
94
- process_tree(commit->tree, &objects, NULL, "");
95
- display_progress(progress, ++count);
112
+ process_tree(commit->tree, &objects, NULL, "", cp);
113
+ update_progress(cp);
114
}
115
116
/* Then walk all the pending objects, recursively processing them too */
@@ -100,17 +118,16 @@ static void walk_commit_list(struct rev_info *revs, struct progress *progress)
118
struct object_array_entry *pending = revs->pending.objects + i;
119
struct object *obj = pending->item;
120
const char *name = pending->name;
103
- display_progress(progress, ++count);
121
if (obj->type == OBJ_TAG) {
105
- process_tag((struct tag *) obj, &objects, name);
122
+ process_tag((struct tag *) obj, &objects, name, cp);
123
continue;
124
}
125
if (obj->type == OBJ_TREE) {
109
- process_tree((struct tree *)obj, &objects, NULL, name);
126
+ process_tree((struct tree *)obj, &objects, NULL, name, cp);
127
continue;
128
}
129
if (obj->type == OBJ_BLOB) {
113
- process_blob((struct blob *)obj, &objects, NULL, name);
130
+ process_blob((struct blob *)obj, &objects, NULL, name, cp);
131
continue;
132
}
133
die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
@@ -199,6 +216,8 @@ static void add_cache_refs(struct rev_info *revs)
216
void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
217
struct progress *progress)
218
{
219
+ struct connectivity_progress cp;
220
+
221
/*
222
* Set up revision parsing, and mark us as being interested
223
* in all object types, not just commits.
@@ -217,11 +236,15 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
236
if (mark_reflog)
237
for_each_reflog(add_one_reflog, revs);
238
239
+ cp.progress = progress;
240
+ cp.count = 0;
241
+
242
/*
243
* Set up the revision walk - this will move all commits
244
* from the pending list to the commit walking list.
245
*/
246
if (prepare_revision_walk(revs))
247
die("revision walk setup failed");
226
- walk_commit_list(revs, progress);
248
+ walk_commit_list(revs, &cp);
249
+ display_progress(cp.progress, cp.count);
250
}