summaryrefslogtreecommitdiff
path: root/builtin-fsck.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-12-11 00:36:31 -0800
committerJunio C Hamano <gitster@pobox.com>2008-12-11 00:36:31 -0800
commitde0db422782ddaf7754ac5b03fdc6dc5de1a9ae4 (patch)
tree643c6f8be7804462cc1e21f95cd33bd8dfb27f5f /builtin-fsck.c
parent07e62b733fad4236371a8cd6abc32409fb1fb87d (diff)
parent04d39759373e5de017e7c17ef4b762ac5ad3afcc (diff)
downloadgit-de0db422782ddaf7754ac5b03fdc6dc5de1a9ae4.tar.gz
Merge branch 'maint'
* maint: fsck: reduce stack footprint make sure packs to be replaced are closed beforehand
Diffstat (limited to 'builtin-fsck.c')
-rw-r--r--builtin-fsck.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/builtin-fsck.c b/builtin-fsck.c
index afded5e68d..297b2c41c6 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -64,11 +64,11 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)
return (type == FSCK_WARN) ? 0 : 1;
}
+static struct object_array pending;
+
static int mark_object(struct object *obj, int type, void *data)
{
- struct tree *tree = NULL;
struct object *parent = data;
- int result;
if (!obj) {
printf("broken link from %7s %s\n",
@@ -96,6 +96,20 @@ static int mark_object(struct object *obj, int type, void *data)
return 1;
}
+ add_object_array(obj, (void *) parent, &pending);
+ return 0;
+}
+
+static void mark_object_reachable(struct object *obj)
+{
+ mark_object(obj, OBJ_ANY, 0);
+}
+
+static int traverse_one_object(struct object *obj, struct object *parent)
+{
+ int result;
+ struct tree *tree = NULL;
+
if (obj->type == OBJ_TREE) {
obj->parsed = 0;
tree = (struct tree *)obj;
@@ -107,15 +121,22 @@ static int mark_object(struct object *obj, int type, void *data)
free(tree->buffer);
tree->buffer = NULL;
}
- if (result < 0)
- result = 1;
-
return result;
}
-static void mark_object_reachable(struct object *obj)
+static int traverse_reachable(void)
{
- mark_object(obj, OBJ_ANY, 0);
+ int result = 0;
+ while (pending.nr) {
+ struct object_array_entry *entry;
+ struct object *obj, *parent;
+
+ entry = pending.objects + --pending.nr;
+ obj = entry->item;
+ parent = (struct object *) entry->name;
+ result |= traverse_one_object(obj, parent);
+ }
+ return !!result;
}
static int mark_used(struct object *obj, int type, void *data)
@@ -237,6 +258,9 @@ static void check_connectivity(void)
{
int i, max;
+ /* Traverse the pending reachable objects */
+ traverse_reachable();
+
/* Look up all the requirements, warn about missing objects.. */
max = get_max_object_index();
if (verbose)