Skip to content

Commit 8dfe077

Browse files
inosmeetgitster
authored andcommitted
refs: add a generic 'optimize' API
The existing `pack-refs` API is conceptually tied to the 'files' backend, but its behavior is generic (e.g., it triggers compaction for reftable). This naming is confusing. Introduce a new generic refs_optimize() API that dispatches to a backend-specific implementation via a new 'optimize' vtable method. This lays the architectural groundwork for different reference backends (like 'files' and 'reftable') to provide their own storage optimization logic, which will be called from a single, generic entry point. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: shejialuo <[email protected]> Signed-off-by: Meet Soni <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f814da6 commit 8dfe077

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

refs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,11 @@ int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)
22822282
return refs->be->pack_refs(refs, opts);
22832283
}
22842284

2285+
int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)
2286+
{
2287+
return refs->be->optimize(refs, opts);
2288+
}
2289+
22852290
int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled)
22862291
{
22872292
if (current_ref_iter &&

refs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ struct pack_refs_opts {
480480
*/
481481
int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);
482482

483+
/*
484+
* Optimize the ref store. The exact behavior is up to the backend.
485+
* For the files backend, this is equivalent to packing refs.
486+
*/
487+
int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts);
488+
483489
/*
484490
* Setup reflog before using. Fill in err and return -1 on failure.
485491
*/

refs/refs-internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
447447

448448
typedef int pack_refs_fn(struct ref_store *ref_store,
449449
struct pack_refs_opts *opts);
450+
typedef int optimize_fn(struct ref_store *ref_store,
451+
struct pack_refs_opts *opts);
450452
typedef int rename_ref_fn(struct ref_store *ref_store,
451453
const char *oldref, const char *newref,
452454
const char *logmsg);
@@ -572,6 +574,7 @@ struct ref_storage_be {
572574
ref_transaction_abort_fn *transaction_abort;
573575

574576
pack_refs_fn *pack_refs;
577+
optimize_fn *optimize;
575578
rename_ref_fn *rename_ref;
576579
copy_ref_fn *copy_ref;
577580

0 commit comments

Comments
 (0)