public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: shejialuo <shejialuo@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>
Subject: Re: [PATCH 16/17] builtin/fsck: move generic HEAD check into `refs_fsck()`
Date: Sat, 10 Jan 2026 21:31:07 +0800	[thread overview]
Message-ID: <aWJUm-hrPquegbdf@ArchLinux> (raw)
In-Reply-To: <20260109-pks-refs-verify-fixes-v1-16-3587dba18294@pks.im>

On Fri, Jan 09, 2026 at 01:39:45PM +0100, Patrick Steinhardt wrote:
> Move the check that detects "HEAD" refs that do not point at a branch
> into `refs_fsck()`. This follows the same motivation as the preceding
> commit.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  Documentation/fsck-msgids.adoc |  3 +++
>  builtin/fsck.c                 |  7 -------
>  fsck.h                         |  1 +
>  refs.c                         | 12 +++++++++++-
>  t/t0602-reffiles-fsck.sh       |  8 ++++----
>  t/t1450-fsck.sh                |  4 ++--
>  6 files changed, 21 insertions(+), 14 deletions(-)
> 
> diff --git a/Documentation/fsck-msgids.adoc b/Documentation/fsck-msgids.adoc
> index 76609321f6..6a4db3a991 100644
> --- a/Documentation/fsck-msgids.adoc
> +++ b/Documentation/fsck-msgids.adoc
> @@ -13,6 +13,9 @@
>  `badGpgsig`::
>  	(ERROR) A tag contains a bad (truncated) signature (e.g., `gpgsig`) header.
>  
> +`badHeadTarget`::
> +	(ERROR) The `HEAD` ref is a symref that does not refer to a branch.
> +
>  `badHeaderContinuation`::
>  	(ERROR) A continuation header (such as for `gpgsig`) is unexpectedly truncated.
>  
> diff --git a/builtin/fsck.c b/builtin/fsck.c
> index 4dd4d74d1e..5dda441f45 100644
> --- a/builtin/fsck.c
> +++ b/builtin/fsck.c
> @@ -728,13 +728,6 @@ static void fsck_head_link(const char *head_ref_name,
>  		error(_("invalid %s"), head_ref_name);
>  		return;
>  	}
> -	if (strcmp(*head_points_at, head_ref_name) &&
> -	    !starts_with(*head_points_at, "refs/heads/")) {
> -		errors_found |= ERROR_REFS;
> -		error(_("%s points to something strange (%s)"),
> -		      head_ref_name, *head_points_at);
> -		return;
> -	}
>  
>  	return;
>  }
> diff --git a/fsck.h b/fsck.h
> index 1f472b7daa..65ecbb7fe1 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -30,6 +30,7 @@ enum fsck_msg_type {
>  	FUNC(BAD_DATE_OVERFLOW, ERROR) \
>  	FUNC(BAD_EMAIL, ERROR) \
>  	FUNC(BAD_GPGSIG, ERROR) \
> +	FUNC(BAD_HEAD_TARGET, ERROR) \
>  	FUNC(BAD_NAME, ERROR) \
>  	FUNC(BAD_OBJECT_SHA1, ERROR) \
>  	FUNC(BAD_PACKED_REF_ENTRY, ERROR) \
> diff --git a/refs.c b/refs.c
> index c3528862c6..a772d371cd 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -334,8 +334,18 @@ int refs_fsck_ref(struct ref_store *refs UNUSED, struct fsck_options *o,
>  
>  int refs_fsck_symref(struct ref_store *refs UNUSED, struct fsck_options *o,
>  		     struct fsck_ref_report *report,
> -		     const char *refname UNUSED, const char *target)
> +		     const char *refname, const char *target)
>  {
> +	const char *stripped_refname;
> +
> +	parse_worktree_ref(refname, NULL, NULL, &stripped_refname);
> +
> +	if (!strcmp(stripped_refname, "HEAD") &&
> +	    !starts_with(target, "refs/heads/") &&

We would first check whether the current ref is `HEAD`. And I am
wondering whether we have some common APIs. And I find the similar logic
in `reglog.c::is_head` like the following shows:

    static int is_head(const char *refname)
    {
            const char *stripped_refname;
            parse_worktree_ref(refname, NULL, NULL, &stripped_refname);
            return !strcmp(stripped_refname, "HEAD");
    }

I think we might just extract this common logic to avoid introducing
repetition.

Thanks,
Jialuo

  reply	other threads:[~2026-01-10 13:31 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09 12:39 [PATCH 00/17] Fixes and improvements for ref consistency checks Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 01/17] refs/files: simplify iterating through root refs Patrick Steinhardt
2026-01-10 12:28   ` shejialuo
2026-01-09 12:39 ` [PATCH 02/17] refs/files: move fsck functions into global scope Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 03/17] refs/files: remove `refs_check_dir` parameter Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 04/17] refs/files: remove useless indirection Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 05/17] refs/files: extract function to check single ref Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 06/17] refs/files: improve error handling when verifying symrefs Patrick Steinhardt
2026-01-10 12:34   ` shejialuo
2026-01-09 12:39 ` [PATCH 07/17] refs/files: perform consistency checks for root refs Patrick Steinhardt
2026-01-10 12:47   ` shejialuo
2026-01-12  8:17     ` Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 08/17] fsck: drop unused fields from `struct fsck_ref_report` Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 09/17] refs/files: extract generic symref target checks Patrick Steinhardt
2026-01-10 12:59   ` shejialuo
2026-01-12  8:17     ` Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 10/17] refs/files: introduce function to perform normal ref checks Patrick Steinhardt
2026-01-10 13:12   ` shejialuo
2026-01-12  8:17     ` Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 11/17] refs/reftable: adapt includes to become consistent Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 12/17] refs/reftable: extract function to retrieve backend for worktree Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 13/17] refs/reftable: fix consistency checks with worktrees Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 14/17] refs/reftable: introduce generic checks for refs Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 15/17] builtin/fsck: move generic object ID checks into `refs_fsck()` Patrick Steinhardt
2026-01-09 12:39 ` [PATCH 16/17] builtin/fsck: move generic HEAD check " Patrick Steinhardt
2026-01-10 13:31   ` shejialuo [this message]
2026-01-12  8:18     ` Patrick Steinhardt
2026-01-15 12:52       ` shejialuo
2026-01-09 12:39 ` [PATCH 17/17] builtin/fsck: drop `fsck_head_link()` Patrick Steinhardt
2026-01-10 13:37 ` [PATCH 00/17] Fixes and improvements for ref consistency checks shejialuo
2026-01-12  8:18   ` Patrick Steinhardt
2026-01-12  9:02 ` [PATCH v2 " Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 01/17] refs/files: simplify iterating through root refs Patrick Steinhardt
2026-01-12  9:56     ` Karthik Nayak
2026-01-12  9:02   ` [PATCH v2 02/17] refs/files: move fsck functions into global scope Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 03/17] refs/files: remove `refs_check_dir` parameter Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 04/17] refs/files: remove useless indirection Patrick Steinhardt
2026-01-12 10:01     ` Karthik Nayak
2026-01-12  9:02   ` [PATCH v2 05/17] refs/files: extract function to check single ref Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 06/17] refs/files: improve error handling when verifying symrefs Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 07/17] refs/files: perform consistency checks for root refs Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 08/17] fsck: drop unused fields from `struct fsck_ref_report` Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 09/17] refs/files: extract generic symref target checks Patrick Steinhardt
2026-01-12  9:02   ` [PATCH v2 10/17] refs/files: introduce function to perform normal ref checks Patrick Steinhardt
2026-01-12 11:42     ` Karthik Nayak
2026-01-12 13:08       ` Patrick Steinhardt
2026-01-12 14:19         ` Junio C Hamano
2026-01-12 14:37           ` Junio C Hamano
2026-01-12 15:02             ` Patrick Steinhardt
2026-01-12  9:03   ` [PATCH v2 11/17] refs/reftable: adapt includes to become consistent Patrick Steinhardt
2026-01-12  9:03   ` [PATCH v2 12/17] refs/reftable: extract function to retrieve backend for worktree Patrick Steinhardt
2026-01-12  9:03   ` [PATCH v2 13/17] refs/reftable: fix consistency checks with worktrees Patrick Steinhardt
2026-01-12 11:45     ` Karthik Nayak
2026-01-12  9:03   ` [PATCH v2 14/17] refs/reftable: introduce generic checks for refs Patrick Steinhardt
2026-01-12  9:03   ` [PATCH v2 15/17] builtin/fsck: move generic object ID checks into `refs_fsck()` Patrick Steinhardt
2026-01-12  9:03   ` [PATCH v2 16/17] builtin/fsck: move generic HEAD check " Patrick Steinhardt
2026-01-12  9:03   ` [PATCH v2 17/17] builtin/fsck: drop `fsck_head_link()` Patrick Steinhardt
2026-01-12 11:50   ` [PATCH v2 00/17] Fixes and improvements for ref consistency checks Karthik Nayak
2026-01-12 13:09     ` Patrick Steinhardt
2026-01-15 12:56   ` shejialuo
2026-01-16  6:48     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aWJUm-hrPquegbdf@ArchLinux \
    --to=shejialuo@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox