static int check_strict;
static int keep_cache_objects;
static unsigned char head_sha1[20];
+static int errors_found;
+#define ERROR_OBJECT 01
+#define ERROR_REACHABLE 02
#ifdef NO_D_INO_IN_DIRENT
#define SORT_DIRENT 0
{
va_list params;
va_start(params, err);
+ errors_found |= ERROR_OBJECT;
objreport(obj, "error", err, params);
va_end(params);
return -1;
* do a full fsck
*/
if (!obj->parsed) {
- if (has_sha1_file(obj->sha1))
+ if (has_sha1_pack(obj->sha1, NULL))
return; /* it is in pack - forget about it */
printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
+ errors_found |= ERROR_REACHABLE;
return;
}
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;
}
}
}
static int fsck_sha1(unsigned char *sha1)
{
struct object *obj = parse_object(sha1);
- if (!obj)
- return error("%s: object corrupt or missing", sha1_to_hex(sha1));
+ if (!obj) {
+ errors_found |= ERROR_OBJECT;
+ return error("%s: object corrupt or missing",
+ sha1_to_hex(sha1));
+ }
if (obj->flags & SEEN)
return 0;
obj->flags |= SEEN;
return fsck_commit((struct commit *) obj);
if (obj->type == OBJ_TAG)
return fsck_tag((struct tag *) obj);
+
/* By now, parse_object() would've returned NULL instead. */
- return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type);
+ return objerror(obj, "unknown type '%d' (internal fsck error)",
+ obj->type);
}
/*
if (!head_points_at || !(flag & REF_ISSYMREF))
return error("HEAD is not a symbolic ref");
- if (strncmp(head_points_at, "refs/heads/", 11))
+ if (prefixcmp(head_points_at, "refs/heads/"))
return error("HEAD points to something strange (%s)",
head_points_at);
if (is_null_sha1(sha1))
return err;
}
+static const char fsck_usage[] =
+"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
+"[--strict] <head-sha1>*]";
+
int cmd_fsck(int argc, char **argv, const char *prefix)
{
int i, heads;
track_object_refs = 1;
+ errors_found = 0;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
continue;
}
if (*arg == '-')
- usage("git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] [--strict] <head-sha1>*]");
+ usage(fsck_usage);
}
fsck_head_link();
verify_pack(p, 0);
for (p = packed_git; p; p = p->next) {
- int num = num_packed_objects(p);
+ uint32_t i, num = num_packed_objects(p);
for (i = 0; i < num; i++) {
unsigned char sha1[20];
nth_packed_object_sha1(p, i, sha1);
}
check_connectivity();
- return 0;
+ return errors_found;
}