Re: [PATCH v5 3/8] packed-backend: check whether the "packed-refs" is regular file
On Mon, Feb 17, 2025 at 11:27:42PM +0800, shejialuo wrote:
Show 35 quoted lines
> diff --git a/refs/packed-backend.c b/refs/packed-backend.c
> index a7b6f74b6e..8140a31d07 100644
> --- a/refs/packed-backend.c
> +++ b/refs/packed-backend.c
> @@ -1748,15 +1749,43 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s
> return empty_ref_iterator_begin();
> }
>
> -static int packed_fsck(struct ref_store *ref_store UNUSED,
> - struct fsck_options *o UNUSED,
> +static int packed_fsck(struct ref_store *ref_store,
> + struct fsck_options *o,
> struct worktree *wt)
> {
> + struct packed_ref_store *refs = packed_downcast(ref_store,
> + REF_STORE_READ, "fsck");
> + struct stat st;
> + int ret = 0;
>
> if (!is_main_worktree(wt))
> - return 0;
> + goto cleanup;
>
> - return 0;
> + if (o->verbose)
> + fprintf_ln(stderr, "Checking packed-refs file %s", refs->path);
> +
> + if (lstat(refs->path, &st) < 0) {
> + /*
> + * If the packed-refs file doesn't exist, there's nothing
> + * to check.
> + */
> + if (errno == ENOENT)
> + goto cleanup;
> + ret = error_errno(_("unable to stat %s"), refs->path);Nit: We should quote the file name: "unable to stat '%s'".
Patrick