summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 355885d)
raw | patch | inline | side by side (parent: 355885d)
author | Martin Koegler <mkoegler@auto.tuwien.ac.at> | |
Mon, 25 Feb 2008 21:46:05 +0000 (22:46 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 26 Feb 2008 07:57:34 +0000 (23:57 -0800) |
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-fsck.c | patch | blob | history |
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 2a6e94deaf6b27f27ad7655ebf6072a05b25017c..7321ab236b6925ef12f9e169b130eb53428d81a5 100644 (file)
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
#include "pack.h"
#include "cache-tree.h"
#include "tree-walk.h"
+#include "fsck.h"
#include "parse-options.h"
#define REACHABLE 0x0001
return -1;
}
+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",
+ typename(parent->type), sha1_to_hex(parent->sha1));
+ printf("broken link from %7s %s\n",
+ (type == OBJ_ANY ? "unknown" : typename(type)), "unknown");
+ errors_found |= ERROR_REACHABLE;
+ return 1;
+ }
+
+ if (type != OBJ_ANY && obj->type != type)
+ objerror(parent, "wrong object type in link");
+
+ if (obj->flags & REACHABLE)
+ return 0;
+ obj->flags |= REACHABLE;
+ if (!obj->parsed) {
+ if (parent && !has_sha1_file(obj->sha1)) {
+ printf("broken link from %7s %s\n",
+ typename(parent->type), sha1_to_hex(parent->sha1));
+ printf(" to %7s %s\n",
+ typename(obj->type), sha1_to_hex(obj->sha1));
+ errors_found |= ERROR_REACHABLE;
+ }
+ return 1;
+ }
+
+ if (obj->type == OBJ_TREE) {
+ obj->parsed = 0;
+ tree = (struct tree *)obj;
+ if (parse_tree(tree) < 0)
+ return 1; /* error already displayed */
+ }
+ result = fsck_walk(obj, mark_object, obj);
+ if (tree) {
+ free(tree->buffer);
+ tree->buffer = NULL;
+ }
+ if (result < 0)
+ result = 1;
+
+ return result;
+}
+
+static void mark_object_reachable(struct object *obj)
+{
+ mark_object(obj, OBJ_ANY, 0);
+}
+
+static int mark_used(struct object *obj, int type, void *data)
+{
+ if (!obj)
+ return 1;
+ obj->used = 1;
+ return 0;
+}
+
/*
* Check a single reachable object
*/
static void check_reachable_object(struct object *obj)
{
- const struct object_refs *refs;
-
/*
* We obviously want the object to be parsed,
* except if it was in a pack-file and we didn't
errors_found |= ERROR_REACHABLE;
return;
}
-
- /*
- * Check that everything that we try to reference is also good.
- */
- refs = lookup_object_refs(obj);
- if (refs) {
- unsigned j;
- for (j = 0; j < refs->count; j++) {
- struct object *ref = refs->ref[j];
- if (ref->parsed ||
- (has_sha1_file(ref->sha1)))
- continue;
- printf("broken link from %7s %s\n",
- typename(obj->type), sha1_to_hex(obj->sha1));
- printf(" to %7s %s\n",
- typename(ref->type), sha1_to_hex(ref->sha1));
- errors_found |= ERROR_REACHABLE;
- }
- }
}
/*
if (obj->flags & SEEN)
return 0;
obj->flags |= SEEN;
+ if (fsck_walk(obj, mark_used, 0))
+ objerror(obj, "broken links");
if (obj->type == OBJ_BLOB)
return 0;
if (obj->type == OBJ_TREE)
obj = lookup_object(osha1);
if (obj) {
obj->used = 1;
- mark_reachable(obj, REACHABLE);
+ mark_object_reachable(obj);
}
}
obj = lookup_object(nsha1);
if (obj) {
obj->used = 1;
- mark_reachable(obj, REACHABLE);
+ mark_object_reachable(obj);
}
return 0;
}
@@ -574,7 +618,7 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
error("%s: not a commit", refname);
default_refs++;
obj->used = 1;
- mark_reachable(obj, REACHABLE);
+ mark_object_reachable(obj);
return 0;
}
sha1_to_hex(it->sha1));
return 1;
}
- mark_reachable(obj, REACHABLE);
+ mark_object_reachable(obj);
obj->used = 1;
if (obj->type != OBJ_TREE)
err |= objerror(obj, "non-tree in cache-tree");
{
int i, heads;
- track_object_refs = 1;
errors_found = 0;
argc = parse_options(argc, argv, fsck_opts, fsck_usage, 0);
continue;
obj->used = 1;
- mark_reachable(obj, REACHABLE);
+ mark_object_reachable(obj);
heads++;
continue;
}
continue;
obj = &blob->object;
obj->used = 1;
- mark_reachable(obj, REACHABLE);
+ mark_object_reachable(obj);
}
if (active_cache_tree)
fsck_cache_tree(active_cache_tree);