From df7333d8e60dd0ee8f26bdb390e0d52492926e0d Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 9 Jan 2026 13:39:46 +0100 Subject: [PATCH] builtin/fsck: drop `fsck_head_link()` The function `fsck_head_link()` was historically used to perform a couple of consistency checks for refs. (Almost) all of these checks have now been moved into the refs subsystem. There's only a single check remaining that verifies whether `refs_resolve_ref_unsafe()` returns a `NULL` pointer. This may happen in a couple of cases: - When `refs_is_safe()` declares the ref to be unsafe. We already have checks for this as we verify refnames with `check_refname_format()`. - When the ref doesn't exist. A repository without "HEAD" is completely broken though, and we would notice this error ahead of time already. - In case the caller passes `RESOLVE_REF_READING` and the ref is a symref that doesn't resolve. We don't pass this flag though. As such, this check doesn't cover anything anymore that isn't already covered by `refs_fsck()`. Drop it, which also allows us to inline the call to `refs_resolve_ref_unsafe()`. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- builtin/fsck.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 5dda441f45..f104b7af0e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -564,10 +564,6 @@ static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED) return 0; } -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) { struct worktree **worktrees, **p; @@ -583,7 +579,10 @@ static void get_default_heads(void) struct strbuf refname = STRBUF_INIT; strbuf_worktree_ref(wt, &refname, "HEAD"); - fsck_head_link(refname.buf, &head_points_at, &head_oid); + + head_points_at = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), + refname.buf, 0, &head_oid, NULL); + if (head_points_at && !is_null_oid(&head_oid)) { struct reference ref = { .name = refname.buf, @@ -713,25 +712,6 @@ static void fsck_source(struct odb_source *source) stop_progress(&progress); } -static void fsck_head_link(const char *head_ref_name, - const char **head_points_at, - struct object_id *head_oid) -{ - if (verbose) - fprintf_ln(stderr, _("Checking %s link"), head_ref_name); - - *head_points_at = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - head_ref_name, 0, head_oid, - NULL); - if (!*head_points_at) { - errors_found |= ERROR_REFS; - error(_("invalid %s"), head_ref_name); - return; - } - - return; -} - static int fsck_cache_tree(struct cache_tree *it, const char *index_path) { int i;