]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: move to using the '.optimize' functions
authorKarthik Nayak <karthik.188@gmail.com>
Mon, 20 Oct 2025 08:18:29 +0000 (10:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2025 15:35:12 +0000 (07:35 -0800)
The `struct ref_store` variable exposes two ways to optimize a reftable
backend:

  1. pack_refs
  2. optimize

The former was specific to the 'files' + 'packed' refs backend. The
latter is more generic and covers all backends. While the naming is
different, both of these functions perform the same functionality.

Consolidate this code to only maintain the 'optimize' functions. Do this
by modifying the backends so that they exclusively implement the
`optimize` callback, only. All users of the refs subsystem already use
the 'optimize' function so there is no changes needed on the callee
side. Finally, cleanup all references to the 'pack_refs' field of the
structure and code around it.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h
refs/debug.c
refs/files-backend.c
refs/packed-backend.c
refs/refs-internal.h
refs/reftable-backend.c

diff --git a/refs.c b/refs.c
index a41a94ae55bb43444015949e0871aeed42001694..b9a4a606462d71c21396aa3377d57001dc9407d5 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2313,12 +2313,6 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,
        refs->gitdir = xstrdup(path);
 }
 
-/* backend functions */
-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);
diff --git a/refs.h b/refs.h
index 2dd7ac1a16aee9b72b83c4f9eb322dd725de4b11..8ff591ea95c7d9f775769103acc57e6f4a52b4f6 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -514,12 +514,6 @@ struct pack_refs_opts {
        struct string_list *includes;
 };
 
-/*
- * Write a packed-refs file for the current repository.
- * flags: Combination of the above PACK_REFS_* flags.
- */
-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.
index 01499b9033ca3ce47250fcd311bbabbea912a72a..40cd1d9c1540c6d0e6d8172e3459a386a70176fb 100644 (file)
@@ -116,11 +116,11 @@ static int debug_transaction_abort(struct ref_store *refs,
        return res;
 }
 
-static int debug_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *opts)
+static int debug_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts)
 {
        struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
-       int res = drefs->refs->be->pack_refs(drefs->refs, opts);
-       trace_printf_key(&trace_refs, "pack_refs: %d\n", res);
+       int res = drefs->refs->be->optimize(drefs->refs, opts);
+       trace_printf_key(&trace_refs, "optimize: %d\n", res);
        return res;
 }
 
@@ -430,7 +430,7 @@ struct ref_storage_be refs_be_debug = {
        .transaction_finish = debug_transaction_finish,
        .transaction_abort = debug_transaction_abort,
 
-       .pack_refs = debug_pack_refs,
+       .optimize = debug_optimize,
        .rename_ref = debug_rename_ref,
        .copy_ref = debug_copy_ref,
 
index 5aeb454fb47684d890db1579cb3cc0089c09d8e4..d13b87e056cf5e8c8ff06272fb1f2828d27167a5 100644 (file)
@@ -1444,8 +1444,8 @@ static int should_pack_refs(struct files_ref_store *refs,
        return 0;
 }
 
-static int files_pack_refs(struct ref_store *ref_store,
-                          struct pack_refs_opts *opts)
+static int files_optimize(struct ref_store *ref_store,
+                         struct pack_refs_opts *opts)
 {
        struct files_ref_store *refs =
                files_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB,
@@ -1512,15 +1512,6 @@ 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.
@@ -3975,7 +3966,6 @@ struct ref_storage_be refs_be_files = {
        .transaction_finish = files_transaction_finish,
        .transaction_abort = files_transaction_abort,
 
-       .pack_refs = files_pack_refs,
        .optimize = files_optimize,
        .rename_ref = files_rename_ref,
        .copy_ref = files_copy_ref,
index 1ab0c5039301647d133b9672898a8262aa8a1568..20cf9fab18e2e9cd042244eb500318b555024cf2 100644 (file)
@@ -1773,8 +1773,8 @@ cleanup:
        return ret;
 }
 
-static int packed_pack_refs(struct ref_store *ref_store UNUSED,
-                           struct pack_refs_opts *pack_opts UNUSED)
+static int packed_optimize(struct ref_store *ref_store UNUSED,
+                          struct pack_refs_opts *pack_opts UNUSED)
 {
        /*
         * Packed refs are already packed. It might be that loose refs
@@ -2129,7 +2129,7 @@ struct ref_storage_be refs_be_packed = {
        .transaction_finish = packed_transaction_finish,
        .transaction_abort = packed_transaction_abort,
 
-       .pack_refs = packed_pack_refs,
+       .optimize = packed_optimize,
        .rename_ref = NULL,
        .copy_ref = NULL,
 
index 4671517dade968fa673c04235c0e1d87552c368e..fc5149df5b3c5c0f135ef6a7b1cf337e81c59a7f 100644 (file)
@@ -422,8 +422,6 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
                                      struct ref_transaction *transaction,
                                      struct strbuf *err);
 
-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,
@@ -550,7 +548,6 @@ struct ref_storage_be {
        ref_transaction_finish_fn *transaction_finish;
        ref_transaction_abort_fn *transaction_abort;
 
-       pack_refs_fn *pack_refs;
        optimize_fn *optimize;
        rename_ref_fn *rename_ref;
        copy_ref_fn *copy_ref;
index 6bbfd5618dac16693c735994d29550da73403bf7..43cc66a48e91431e675cce60b4c0bb0c75a5b045 100644 (file)
@@ -1700,11 +1700,11 @@ done:
        return ret;
 }
 
-static int reftable_be_pack_refs(struct ref_store *ref_store,
-                                struct pack_refs_opts *opts)
+static int reftable_be_optimize(struct ref_store *ref_store,
+                               struct pack_refs_opts *opts)
 {
        struct reftable_ref_store *refs =
-               reftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, "pack_refs");
+               reftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, "optimize_refs");
        struct reftable_stack *stack;
        int ret;
 
@@ -1733,12 +1733,6 @@ 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;
@@ -2761,7 +2755,6 @@ struct ref_storage_be refs_be_reftable = {
        .transaction_finish = reftable_be_transaction_finish,
        .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,