diff options
Diffstat (limited to 'builtin/fsck.c')
-rw-r--r-- | builtin/fsck.c | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c index 8aadca160e..6b6f31997c 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -298,7 +298,7 @@ static int fsck_obj(struct object *obj) if (fsck_walk(obj, mark_used, NULL)) objerror(obj, "broken links"); - if (fsck_object(obj, check_strict, fsck_error_func)) + if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func)) return -1; if (obj->type == OBJ_TREE) { @@ -388,7 +388,8 @@ static void fsck_sha1_list(void) unsigned char *sha1 = entry->sha1; sha1_list.entry[i] = NULL; - fsck_sha1(sha1); + if (fsck_sha1(sha1)) + errors_found |= ERROR_OBJECT; free(entry); } sha1_list.nr = 0; @@ -450,40 +451,41 @@ static void fsck_dir(int i, char *path) static int default_refs; -static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1, - const char *email, unsigned long timestamp, int tz, - const char *message, void *cb_data) +static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1) { struct object *obj; - if (verbose) - fprintf(stderr, "Checking reflog %s->%s\n", - sha1_to_hex(osha1), sha1_to_hex(nsha1)); - - if (!is_null_sha1(osha1)) { - obj = lookup_object(osha1); + if (!is_null_sha1(sha1)) { + obj = lookup_object(sha1); if (obj) { obj->used = 1; mark_object_reachable(obj); + } else { + error("%s: invalid reflog entry %s", refname, sha1_to_hex(sha1)); + errors_found |= ERROR_REACHABLE; } } - obj = lookup_object(nsha1); - if (obj) { - obj->used = 1; - mark_object_reachable(obj); - } - return 0; } -static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data) +static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1, + const char *email, unsigned long timestamp, int tz, + const char *message, void *cb_data) { - for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL); + const char *refname = cb_data; + + if (verbose) + fprintf(stderr, "Checking reflog %s->%s\n", + sha1_to_hex(osha1), sha1_to_hex(nsha1)); + + fsck_handle_reflog_sha1(refname, osha1); + fsck_handle_reflog_sha1(refname, nsha1); return 0; } -static int is_branch(const char *refname) +static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data) { - return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/"); + for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname); + return 0; } static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) @@ -493,6 +495,7 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f obj = parse_object(sha1); if (!obj) { error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1)); + errors_found |= ERROR_REACHABLE; /* We'll continue with the rest despite the error.. */ return 0; } @@ -509,7 +512,7 @@ static void get_default_heads(void) { if (head_points_at && !is_null_sha1(head_sha1)) fsck_handle_ref("HEAD", head_sha1, 0, NULL); - for_each_ref(fsck_handle_ref, NULL); + for_each_rawref(fsck_handle_ref, NULL); if (include_reflogs) for_each_reflog(fsck_handle_reflog, NULL); @@ -559,7 +562,7 @@ static int fsck_head_link(void) if (verbose) fprintf(stderr, "Checking HEAD link\n"); - head_points_at = resolve_ref_unsafe("HEAD", head_sha1, 0, &flag); + head_points_at = resolve_ref_unsafe("HEAD", 0, head_sha1, &flag); if (!head_points_at) return error("Invalid HEAD"); if (!strcmp(head_points_at, "HEAD")) @@ -603,7 +606,7 @@ static int fsck_cache_tree(struct cache_tree *it) } static char const * const fsck_usage[] = { - N_("git fsck [options] [<object>...]"), + N_("git fsck [<options>] [<object>...]"), NULL }; |