]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/fsck: drop `fsck_head_link()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 12 Jan 2026 09:03:06 +0000 (10:03 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jan 2026 14:55:41 +0000 (06:55 -0800)
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>
builtin/fsck.c

index 5dda441f45f3f55bba01160438466e559386ba7f..f104b7af0e15f3a42cc4c3cd8fa5893c39ec9d97 100644 (file)
@@ -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;