From 8dfe077fb68eb952464ce59deaa4dfdd52891457 Mon Sep 17 00:00:00 2001 From: Meet Soni Date: Fri, 19 Sep 2025 13:56:39 +0530 Subject: 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 Mentored-by: shejialuo Signed-off-by: Meet Soni Signed-off-by: Junio C Hamano --- refs/refs-internal.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'refs') diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 54c2079c12..4ef3bd75c6 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -447,6 +447,8 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs, typedef int pack_refs_fn(struct ref_store *ref_store, struct pack_refs_opts *opts); +typedef int optimize_fn(struct ref_store *ref_store, + struct pack_refs_opts *opts); typedef int rename_ref_fn(struct ref_store *ref_store, const char *oldref, const char *newref, const char *logmsg); @@ -572,6 +574,7 @@ struct ref_storage_be { ref_transaction_abort_fn *transaction_abort; pack_refs_fn *pack_refs; + optimize_fn *optimize; rename_ref_fn *rename_ref; copy_ref_fn *copy_ref; -- cgit v1.3 From 1fd6067181703e9e65f602e6da27b9b1d8b783a2 Mon Sep 17 00:00:00 2001 From: Meet Soni Date: Fri, 19 Sep 2025 13:56:40 +0530 Subject: files-backend: implement 'optimize' action With the generic `refs_optimize()` API now in place, provide the first implementation for the 'files' reference backend. This makes the new API functional for existing repositories and serves as the foundation for migrating user-facing commands to the new architecture. The implementation simply calls the existing `files_pack_refs()` function, as 'packing' is the method used to optimize the files-based reference store. Wire up the new `files_optimize()` function to the `optimize` slot in the files backend's virtual table. Mentored-by: Patrick Steinhardt Mentored-by: shejialuo Signed-off-by: Meet Soni Signed-off-by: Junio C Hamano --- refs/files-backend.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'refs') diff --git a/refs/files-backend.c b/refs/files-backend.c index dfc8e9bc50..1428d3a6f1 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1473,6 +1473,15 @@ static int files_pack_refs(struct ref_store *ref_store, return 0; } +static int files_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts) +{ + /* + * For the "files" backend, "optimizing" is the same as "packing". + * So, we just call the existing worker function for packing. + */ + return files_pack_refs(ref_store, opts); +} + /* * People using contrib's git-new-workdir have .git/logs/refs -> * /some/other/path/.git/logs/refs, and that may live on another device. @@ -3909,6 +3918,7 @@ struct ref_storage_be refs_be_files = { .transaction_abort = files_transaction_abort, .pack_refs = files_pack_refs, + .optimize = files_optimize, .rename_ref = files_rename_ref, .copy_ref = files_copy_ref, -- cgit v1.3 From da0849a71e08ad072700b7cd1a0cb8b6fb89c50a Mon Sep 17 00:00:00 2001 From: Meet Soni Date: Fri, 19 Sep 2025 13:56:41 +0530 Subject: reftable-backend: implement 'optimize' action To make the new generic `optimize` API fully functional, provide an implementation for the 'reftable' reference backend. For the reftable backend, the 'optimize' action is to compact its tables. The existing `reftable_be_pack_refs()` function already provides this logic, so the new `reftable_be_optimize()` function simply calls it. Wire up the new function to the `optimize` slot in the reftable backend's virtual table. Mentored-by: Patrick Steinhardt Mentored-by: shejialuo Signed-off-by: Meet Soni Signed-off-by: Junio C Hamano --- refs/reftable-backend.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'refs') diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 570463da41..5dff1e08e5 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1721,6 +1721,12 @@ out: return ret; } +static int reftable_be_optimize(struct ref_store *ref_store, + struct pack_refs_opts *opts) +{ + return reftable_be_pack_refs(ref_store, opts); +} + struct write_create_symref_arg { struct reftable_ref_store *refs; struct reftable_stack *stack; @@ -2702,6 +2708,7 @@ struct ref_storage_be refs_be_reftable = { .transaction_abort = reftable_be_transaction_abort, .pack_refs = reftable_be_pack_refs, + .optimize = reftable_be_optimize, .rename_ref = reftable_be_rename_ref, .copy_ref = reftable_be_copy_ref, -- cgit v1.3