Subject: Re: [GSoC][PATCH v14 11/11] fsck: add ref name check for files backend

From: Patrick Steinhardt <[email-masked]>
Date: Mon, 5 Aug 2024 14:58:42 +0200

On Thu, Aug 01, 2024 at 11:15:24PM +0800, shejialuo wrote:
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 5574e78656..1186b6cbb1 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -3419,6 +3419,37 @@ typedef int (*files_fsck_refs_fn)(struct fsck_options *o,
>  				  const char *refs_check_dir,
>  				  struct dir_iterator *iter);
>  
> +static int files_fsck_refs_name(struct fsck_options *o,
> +				const char *gitdir UNUSED,
> +				const char *refs_check_dir,
> +				struct dir_iterator *iter)
> +{
> +	struct strbuf sb = STRBUF_INIT;
> +	size_t len = 0;
> +	int ret = 0;
> +
> +	/*
> +	 * Ignore the files ending with ".lock" as they may be lock files
> +	 * However, do not allow bare ".lock" files.
> +	 */
> +	if (strip_suffix(iter->basename, ".lock", &len) && (len != 0))
> +		goto clean;

Better:

    if (ends_with(iter->basename, ".lock))
            goto cleanup;

Patrick