diff options
| author | Patrick Steinhardt <ps@pks.im> | 2026-01-12 10:03:04 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-12 06:55:41 -0800 |
| commit | 46d611cadab500ca2b458b2fda7008c41b174011 (patch) | |
| tree | 700e25707d347981e83938f5f6fbc5495728f143 /builtin/fsck.c | |
| parent | 06d6ead762ba525c5837812e7f509406253cdacd (diff) | |
| download | git-46d611cadab500ca2b458b2fda7008c41b174011.tar.xz | |
builtin/fsck: move generic object ID checks into `refs_fsck()`
While most of the logic that verifies the consistency of refs is
driven by `refs_fsck()`, we still have a small handful of checks in
`fsck_head_link()`. These checks don't use the git-fsck(1) reporting
infrastructure, and as such it's impossible to for example disable
some of those checks.
One such check detects refs that point to the all-zeroes object ID.
Extract this check into the generic `refs_fsck_ref()` function that is
used by both the "files" and "reftable" backends.
Note that this will cause us to not return an error code from
`fsck_head_link()` anymore in case this error was detected. This is fine
though: the only caller of this function does not check the error code
anyway. To demonstrate this, adapt the function to drop its return value
altogether. The function will be removed in a subsequent commit anyway.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fsck.c')
| -rw-r--r-- | builtin/fsck.c | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c index 4979bc795e..4dd4d74d1e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -564,9 +564,9 @@ static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED) return 0; } -static int fsck_head_link(const char *head_ref_name, - const char **head_points_at, - struct object_id *head_oid); +static void fsck_head_link(const char *head_ref_name, + const char **head_points_at, + struct object_id *head_oid); static void get_default_heads(void) { @@ -713,12 +713,10 @@ static void fsck_source(struct odb_source *source) stop_progress(&progress); } -static int fsck_head_link(const char *head_ref_name, - const char **head_points_at, - struct object_id *head_oid) +static void fsck_head_link(const char *head_ref_name, + const char **head_points_at, + struct object_id *head_oid) { - int null_is_error = 0; - if (verbose) fprintf_ln(stderr, _("Checking %s link"), head_ref_name); @@ -727,27 +725,18 @@ static int fsck_head_link(const char *head_ref_name, NULL); if (!*head_points_at) { errors_found |= ERROR_REFS; - return error(_("invalid %s"), head_ref_name); + error(_("invalid %s"), head_ref_name); + return; } - if (!strcmp(*head_points_at, head_ref_name)) - /* detached HEAD */ - null_is_error = 1; - else if (!starts_with(*head_points_at, "refs/heads/")) { + if (strcmp(*head_points_at, head_ref_name) && + !starts_with(*head_points_at, "refs/heads/")) { errors_found |= ERROR_REFS; - return error(_("%s points to something strange (%s)"), - head_ref_name, *head_points_at); - } - if (is_null_oid(head_oid)) { - if (null_is_error) { - errors_found |= ERROR_REFS; - return error(_("%s: detached HEAD points at nothing"), - head_ref_name); - } - fprintf_ln(stderr, - _("notice: %s points to an unborn branch (%s)"), - head_ref_name, *head_points_at + 11); + error(_("%s points to something strange (%s)"), + head_ref_name, *head_points_at); + return; } - return 0; + + return; } static int fsck_cache_tree(struct cache_tree *it, const char *index_path) |
