refs: add a optimize_required field to struct ref_storage_be

To allow users of the refs namespace to check if the reference backend
requires optimization, add a new field `optimize_required` field to
`struct ref_storage_be`. This field is of type `optimize_required_fn`
which is also introduced in this commit.

Modify the debug, files, packed and reftable backend to implement this
field. A following commit will expose this via 'git pack-refs' and 'git
refs optimize'.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karthik Nayak
2025-11-08 22:51:55 +01:00
committed by Junio C Hamano
parent e35155588a
commit f6c5ca387a
7 changed files with 82 additions and 0 deletions

View File

@@ -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 refs_optimize_opts *opts UNUSED,
bool *required)
{
/*
* Packed refs are already optimized.
*/
*required = false;
return 0;
}
static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_store UNUSED)
{
return empty_ref_iterator_begin();
@@ -2130,6 +2141,8 @@ struct ref_storage_be refs_be_packed = {
.transaction_abort = packed_transaction_abort,
.optimize = packed_optimize,
.optimize_required = packed_optimize_required,
.rename_ref = NULL,
.copy_ref = NULL,