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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 12, 2026 at 10:03 UTC 8947da018387f146a90e64055b4caf2ab79e39a7
1 file changed +4 -24
builtin/fsck.c
+4 -24
@@ -564,10 +564,6 @@ static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
564 return 0;
565 }
566
567 -static void fsck_head_link(const char *head_ref_name,
568 - const char **head_points_at,
569 - struct object_id *head_oid);
570 -
567 static void get_default_heads(void)
568 {
569 struct worktree **worktrees, **p;
@@ -583,7 +579,10 @@ static void get_default_heads(void)
579 struct strbuf refname = STRBUF_INIT;
580
581 strbuf_worktree_ref(wt, &refname, "HEAD");
586 - fsck_head_link(refname.buf, &head_points_at, &head_oid);
582 +
583 + head_points_at = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
584 + refname.buf, 0, &head_oid, NULL);
585 +
586 if (head_points_at && !is_null_oid(&head_oid)) {
587 struct reference ref = {
588 .name = refname.buf,
@@ -713,25 +712,6 @@ static void fsck_source(struct odb_source *source)
712 stop_progress(&progress);
713 }
714
716 -static void fsck_head_link(const char *head_ref_name,
717 - const char **head_points_at,
718 - struct object_id *head_oid)
719 -{
720 - if (verbose)
721 - fprintf_ln(stderr, _("Checking %s link"), head_ref_name);
722 -
723 - *head_points_at = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
724 - head_ref_name, 0, head_oid,
725 - NULL);
726 - if (!*head_points_at) {
727 - errors_found |= ERROR_REFS;
728 - error(_("invalid %s"), head_ref_name);
729 - return;
730 - }
731 -
732 - return;
733 -}
734 -
715 static int fsck_cache_tree(struct cache_tree *it, const char *index_path)
716 {
717 int i;