]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: add a generic 'optimize' API
authorMeet Soni <meetsoni3017@gmail.com>
Fri, 19 Sep 2025 08:26:39 +0000 (13:56 +0530)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2025 17:02:55 +0000 (10:02 -0700)
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 <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index 4ff55cf24f68ee90e73de04f823c36bf536882bd..191b95b4a301310f5a28a2ce270edae7602b1401 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2282,6 +2282,11 @@ int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)
        return refs->be->pack_refs(refs, opts);
 }
 
+int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)
+{
+       return refs->be->optimize(refs, opts);
+}
+
 int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled)
 {
        if (current_ref_iter &&
diff --git a/refs.h b/refs.h
index f29e486e332f6d8245966af58e7c8b0927628857..d28c4ef0afd080ef631eed3ead2f12f0947bc6f1 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -480,6 +480,12 @@ struct pack_refs_opts {
  */
 int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);
 
+/*
+ * Optimize the ref store. The exact behavior is up to the backend.
+ * For the files backend, this is equivalent to packing refs.
+ */
+int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts);
+
 /*
  * Setup reflog before using. Fill in err and return -1 on failure.
  */
index 54c2079c1264e8b757cf5c44552c0ef46405375a..4ef3bd75c6ae55e0e33beec4c73f986fe18c0cce 100644 (file)
@@ -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;