diff options
Diffstat (limited to 'builtin-fsck.c')
-rw-r--r-- | builtin-fsck.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/builtin-fsck.c b/builtin-fsck.c index 21f1f9e..05d98d2 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -14,6 +14,7 @@ static int show_root; static int show_tags; static int show_unreachable; +static int include_reflogs = 1; static int check_full; static int check_strict; static int keep_cache_objects; @@ -348,7 +349,7 @@ static int fsck_tag(struct tag *tag) return 0; } -static int fsck_sha1(unsigned char *sha1) +static int fsck_sha1(const unsigned char *sha1) { struct object *obj = parse_object(sha1); if (!obj) { @@ -517,7 +518,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f static void get_default_heads(void) { for_each_ref(fsck_handle_ref, NULL); - for_each_reflog(fsck_handle_reflog, NULL); + if (include_reflogs) + for_each_reflog(fsck_handle_reflog, NULL); /* * Not having any default heads isn't really fatal, but @@ -532,7 +534,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; } } @@ -552,15 +554,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; } @@ -616,6 +626,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix) keep_cache_objects = 1; continue; } + if (!strcmp(arg, "--no-reflogs")) { + include_reflogs = 0; + continue; + } if (!strcmp(arg, "--full")) { check_full = 1; continue; @@ -648,11 +662,8 @@ int cmd_fsck(int argc, char **argv, const char *prefix) for (p = packed_git; p; p = p->next) { 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); - fsck_sha1(sha1); - } + for (i = 0; i < num; i++) + fsck_sha1(nth_packed_object_sha1(p, i)); } } |