X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=builtin-fsck.c;h=7c3b0a535f81a350d11df112a6a5b5a49b139afb;hb=ec771a7084ed9352ac6b14ed6ff437e67aba0f0b;hp=6abf498d2b391c97e9efcdb32da1cf3b5d566397;hpb=99e6ac503b175ef38ca98e88a6ec1e290ad79d69;p=thirdparty%2Fgit.git diff --git a/builtin-fsck.c b/builtin-fsck.c index 6abf498d2b..7c3b0a535f 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -18,6 +18,9 @@ static int check_full; 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 @@ -40,6 +43,7 @@ static int objerror(struct object *obj, const char *err, ...) { va_list params; va_start(params, err); + errors_found |= ERROR_OBJECT; objreport(obj, "error", err, params); va_end(params); return -1; @@ -67,9 +71,10 @@ static void check_reachable_object(struct object *obj) * 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; } @@ -88,6 +93,7 @@ static void check_reachable_object(struct object *obj) 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; } } } @@ -221,8 +227,7 @@ static int fsck_tree(struct tree *item) const char *o_name; const unsigned char *o_sha1; - desc.buf = item->buffer; - desc.size = item->size; + init_tree_desc(&desc, item->buffer, item->size); o_mode = 0; o_name = NULL; @@ -236,7 +241,7 @@ static int fsck_tree(struct tree *item) if (strchr(name, '/')) has_full_path = 1; - has_zero_pad |= *(char *)desc.buf == '0'; + has_zero_pad |= *(char *)desc.buffer == '0'; update_tree_entry(&desc); switch (mode) { @@ -346,8 +351,11 @@ static int fsck_tag(struct tag *tag) 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; @@ -359,8 +367,10 @@ static int fsck_sha1(unsigned char *sha1) 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); } /* @@ -522,7 +532,7 @@ static void get_default_heads(void) * "show_unreachable" flag. */ if (!default_refs) { - error("No default references"); + fprintf(stderr, "notice: No default references\n"); show_unreachable = 0; } } @@ -542,15 +552,23 @@ static int fsck_head_link(void) { unsigned char sha1[20]; int flag; - const char *head_points_at = resolve_ref("HEAD", sha1, 1, &flag); - - if (!head_points_at || !(flag & REF_ISSYMREF)) - return error("HEAD is not a symbolic ref"); - if (prefixcmp(head_points_at, "refs/heads/")) + int null_is_error = 0; + const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag); + + if (!head_points_at) + return error("Invalid HEAD"); + if (!strcmp(head_points_at, "HEAD")) + /* detached HEAD */ + null_is_error = 1; + else if (prefixcmp(head_points_at, "refs/heads/")) return error("HEAD points to something strange (%s)", head_points_at); - if (is_null_sha1(sha1)) - return error("HEAD: not a valid git pointer"); + if (is_null_sha1(sha1)) { + if (null_is_error) + return error("HEAD: detached HEAD points at nothing"); + fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n", + head_points_at + 11); + } return 0; } @@ -576,11 +594,16 @@ static int fsck_cache_tree(struct cache_tree *it) return err; } +static const char fsck_usage[] = +"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] " +"[--strict] *]"; + 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]; @@ -610,7 +633,7 @@ int cmd_fsck(int argc, char **argv, const char *prefix) continue; } if (*arg == '-') - usage("git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] [--strict] *]"); + usage(fsck_usage); } fsck_head_link(); @@ -632,7 +655,7 @@ int cmd_fsck(int argc, char **argv, const char *prefix) 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); @@ -690,5 +713,5 @@ int cmd_fsck(int argc, char **argv, const char *prefix) } check_connectivity(); - return 0; + return errors_found; }