From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 8/9] refs: add a `optimize_required` field to `struct ref_storage_be`
Date: Fri, 10 Oct 2025 13:22:47 +0200 [thread overview]
Message-ID: <aOjsh4102DYctgQE@pks.im> (raw)
In-Reply-To: <20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-8-c7962be584fa@gmail.com>
On Fri, Oct 10, 2025 at 12:27:12PM +0200, Karthik Nayak wrote:
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 1c37899006..c262ae1a7b 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -1513,6 +1513,16 @@ static int files_optimize(struct ref_store *ref_store,
> return 0;
> }
>
> +static int files_optimize_required(struct ref_store *ref_store,
> + struct optimize_refs_opts *opts,
> + bool *required)
> +{
> + struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_READ,
> + "optimize_required");
> + *required = should_pack_refs(refs, opts);
> + return 0;
> +}
Okay, this is nice and straight-forward. One might argue that we could
also have the following (uncompiled, so pseudo-code-y) implementation:
static int files_optimize_required(struct ref_store *ref_store,
struct optimize_refs_opts *opts,
bool *required)
{
struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_READ,
"optimize_required");
*required = should_pack_refs(refs, opts) ||
refs_optimize_required(refs->packed_refs, opts);
return 0;
}
But on the other hand we know that they aren't ever repacked, so it's
probably dumb.
> diff --git a/refs/packed-backend.c b/refs/packed-backend.c
> index acaa5a6e57..c94948f618 100644
> --- a/refs/packed-backend.c
> +++ b/refs/packed-backend.c
> @@ -1784,6 +1784,17 @@ static int packed_optimize(struct ref_store *ref_store UNUSED,
> return 0;
> }
>
> +static int packed_optimize_required(struct ref_store *ref_store UNUSED,
> + struct optimize_refs_opts *opts UNUSED,
> + bool *required)
> +{
> + /*
> + * Packed refs are already optimized.
> + */
> + *required = false;
> + return 0;
> +}
Yup.
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index d77714366a..df39fe9b38 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -1732,6 +1732,29 @@ static int reftable_be_optimize(struct ref_store *ref_store,
> return ret;
> }
>
> +static int reftable_be_optimize_required(struct ref_store *ref_store,
> + struct optimize_refs_opts *opts,
> + bool *required)
> +{
> + struct reftable_ref_store *refs = reftable_be_downcast(ref_store, REF_STORE_READ,
> + "optimize_refs_required");
> + struct reftable_stack *stack;
> +
> + if (refs->err)
> + return refs->err;
> +
> + stack = refs->worktree_backend.stack;
> + if (!stack)
> + stack = refs->main_backend.stack;
> +
> + if (opts->flags & OPTIMIZE_REFS_AUTO)
> + return reftable_stack_compaction_required(stack, required);
> + else
> + *required = true;
This doesn't make much sense. We should only indicate that we require
repacking when there are at least two tables in the stack.
Patrick
next prev parent reply other threads:[~2025-10-10 11:22 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-10 10:27 [PATCH 0/9] refs: add a '--required' flag to 'git refs optimize' Karthik Nayak
2025-10-10 10:27 ` [PATCH 1/9] refs: move to using the '.optimize' functions Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 8:18 ` Karthik Nayak
2025-10-10 10:27 ` [PATCH 2/9] refs: cleanup code around optimization Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 8:22 ` Karthik Nayak
2025-10-10 10:27 ` [PATCH 3/9] refs: rename 'pack_refs_opts' to 'optimize_refs_opts' Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 8:52 ` Karthik Nayak
2025-10-10 10:27 ` [PATCH 4/9] t/pack-refs-tests: move the 'test_done' to callees Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 8:54 ` Karthik Nayak
2025-10-10 10:27 ` [PATCH 5/9] t/t0450: split whitespace consistency check per subcommand Karthik Nayak
2025-10-10 10:27 ` [PATCH 6/9] reftable/stack: return stack segments directly Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 9:01 ` Karthik Nayak
2025-10-13 11:10 ` Patrick Steinhardt
2025-10-10 10:27 ` [PATCH 7/9] reftable/stack: add function to check if optimization is required Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 9:04 ` Karthik Nayak
2025-10-10 10:27 ` [PATCH 8/9] refs: add a `optimize_required` field to `struct ref_storage_be` Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt [this message]
2025-10-13 9:46 ` Karthik Nayak
2025-10-10 10:27 ` [PATCH 9/9] refs: add a '--required' flag to 'git refs optimize' Karthik Nayak
2025-10-10 11:22 ` Patrick Steinhardt
2025-10-13 12:37 ` Karthik Nayak
2025-10-13 13:40 ` Junio C Hamano
2025-10-13 14:37 ` Junio C Hamano
2025-10-14 15:08 ` Karthik Nayak
2025-10-14 17:46 ` Junio C Hamano
2025-10-15 7:50 ` Srivastava, Nitin
2025-10-15 8:19 ` Karthik Nayak
2025-10-15 9:29 ` Karthik Nayak
2025-10-15 12:14 ` Patrick Steinhardt
2025-10-15 20:17 ` Junio C Hamano
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=aOjsh4102DYctgQE@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).