reflog --fix-stale: do not check the same trees and commits repeatedly.
Since we use the reachability tracking machinery now, we should keep the already checked trees and commits whose completeness is known, to avoid checking the same thing over and over again. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 6, 2007 at 22:32 UTC
cd1f9c36beeafd3dea4672494a98e1ed39ae63f1
1 file changed
+54
-23
builtin-reflog.c
+54
-23
@@ -34,35 +34,51 @@ struct expire_reflog_cb {
34
struct cmd_reflog_expire_cb *cmd;
35
};
36
37
+#define INCOMPLETE (1u<<10)
38
+#define STUDYING (1u<<11)
39
+
40
static int tree_is_complete(const unsigned char *sha1)
41
{
42
struct tree_desc desc;
40
- void *buf;
41
- char type[20];
43
+ struct name_entry entry;
44
+ int complete;
45
+ struct tree *tree;
46
43
- buf = read_sha1_file(sha1, type, &desc.size);
44
- if (!buf)
47
+ tree = lookup_tree(sha1);
48
+ if (!tree)
49
+ return 0;
50
+ if (tree->object.flags & SEEN)
51
+ return 1;
52
+ if (tree->object.flags & INCOMPLETE)
53
return 0;
46
- desc.buf = buf;
47
- while (desc.size) {
48
- const unsigned char *elem;
49
- const char *name;
50
- unsigned mode;
51
-
52
- elem = tree_entry_extract(&desc, &name, &mode);
53
- if (!has_sha1_file(elem) ||
54
- (S_ISDIR(mode) && !tree_is_complete(elem))) {
55
- free(buf);
54
+
55
+ desc.buf = tree->buffer;
56
+ desc.size = tree->size;
57
+ if (!desc.buf) {
58
+ char type[20];
59
+ void *data = read_sha1_file(sha1, type, &desc.size);
60
+ if (!data) {
61
+ tree->object.flags |= INCOMPLETE;
62
return 0;
63
}
58
- update_tree_entry(&desc);
64
+ desc.buf = data;
65
+ tree->buffer = data;
66
}
60
- free(buf);
61
- return 1;
62
-}
67
+ complete = 1;
68
+ while (tree_entry(&desc, &entry)) {
69
+ if (!has_sha1_file(entry.sha1) ||
70
+ (S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) {
71
+ tree->object.flags |= INCOMPLETE;
72
+ complete = 0;
73
+ }
74
+ }
75
+ free(tree->buffer);
76
+ tree->buffer = NULL;
77
64
-#define INCOMPLETE (1u<<10)
65
-#define STUDYING (1u<<11)
78
+ if (complete)
79
+ tree->object.flags |= SEEN;
80
+ return complete;
81
+}
82
83
static int commit_is_complete(struct commit *commit)
84
{
@@ -112,14 +128,17 @@ static int commit_is_complete(struct commit *commit)
128
}
129
}
130
if (!is_incomplete) {
115
- /* make sure all commits in found have all the
131
+ /*
132
+ * make sure all commits in "found" array have all the
133
* necessary objects.
134
*/
118
- for (i = 0; !is_incomplete && i < found.nr; i++) {
135
+ for (i = 0; i < found.nr; i++) {
136
struct commit *c =
137
(struct commit *)found.objects[i].item;
121
- if (!tree_is_complete(c->tree->object.sha1))
138
+ if (!tree_is_complete(c->tree->object.sha1)) {
139
is_incomplete = 1;
140
+ c->object.flags |= INCOMPLETE;
141
+ }
142
}
143
if (!is_incomplete) {
144
/* mark all found commits as complete, iow SEEN */
@@ -132,6 +151,18 @@ static int commit_is_complete(struct commit *commit)
151
found.objects[i].item->flags &= ~STUDYING;
152
if (is_incomplete)
153
commit->object.flags |= INCOMPLETE;
154
+ else {
155
+ /*
156
+ * If we come here, we have (1) traversed the ancestry chain
157
+ * from the "commit" until we reach SEEN commits (which are
158
+ * known to be complete), and (2) made sure that the commits
159
+ * encountered during the above traversal refer to trees that
160
+ * are complete. Which means that we know *all* the commits
161
+ * we have seen during this process are complete.
162
+ */
163
+ for (i = 0; i < found.nr; i++)
164
+ found.objects[i].item->flags |= SEEN;
165
+ }
166
/* free object arrays */
167
free(study.objects);
168
free(found.objects);