]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Revert "Merge branch 'kn/refs-optim-cleanup' into next"
authorJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2025 15:31:19 +0000 (07:31 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2025 15:31:19 +0000 (07:31 -0800)
This reverts commit 8c2d7a4413436c0f91af0c0ab978cba8af905696, reversing
changes made to 8ac48a10de61267858d66383c34833e55a5e9d02.

pack-refs.c
refs.c
refs.h
refs/debug.c
refs/files-backend.c
refs/packed-backend.c
refs/refs-internal.h
refs/reftable-backend.c
t/pack-refs-tests.sh
t/t0601-reffiles-pack-refs.sh
t/t1463-refs-optimize.sh

index eb6b2ba2c2c2b50922bdae4104b768a3fb50b2d3..1a5e07d8b888abd9cf128c8058d2ca4cbffd5371 100644 (file)
@@ -14,10 +14,10 @@ int pack_refs_core(int argc,
 {
        struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
        struct string_list included_refs = STRING_LIST_INIT_NODUP;
-       struct refs_optimize_opts optimize_opts = {
+       struct pack_refs_opts pack_refs_opts = {
                .exclusions = &excludes,
                .includes = &included_refs,
-               .flags = REFS_OPTIMIZE_PRUNE,
+               .flags = PACK_REFS_PRUNE,
        };
        struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
        struct string_list_item *item;
@@ -26,9 +26,9 @@ int pack_refs_core(int argc,
 
        struct option opts[] = {
                OPT_BOOL(0, "all",   &pack_all, N_("pack everything")),
-               OPT_BIT(0, "prune", &optimize_opts.flags, N_("prune loose refs (default)"), REFS_OPTIMIZE_PRUNE),
-               OPT_BIT(0, "auto", &optimize_opts.flags, N_("auto-pack refs as needed"), REFS_OPTIMIZE_AUTO),
-               OPT_STRING_LIST(0, "include", optimize_opts.includes, N_("pattern"),
+               OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
+               OPT_BIT(0, "auto", &pack_refs_opts.flags, N_("auto-pack refs as needed"), PACK_REFS_AUTO),
+               OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
                        N_("references to include")),
                OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
                        N_("references to exclude")),
@@ -39,15 +39,15 @@ int pack_refs_core(int argc,
                usage_with_options(usage_opts, opts);
 
        for_each_string_list_item(item, &option_excluded_refs)
-               add_ref_exclusion(optimize_opts.exclusions, item->string);
+               add_ref_exclusion(pack_refs_opts.exclusions, item->string);
 
        if (pack_all)
-               string_list_append(optimize_opts.includes, "*");
+               string_list_append(pack_refs_opts.includes, "*");
 
-       if (!optimize_opts.includes->nr)
-               string_list_append(optimize_opts.includes, "refs/tags/*");
+       if (!pack_refs_opts.includes->nr)
+               string_list_append(pack_refs_opts.includes, "refs/tags/*");
 
-       ret = refs_optimize(get_main_ref_store(repo), &optimize_opts);
+       ret = refs_optimize(get_main_ref_store(repo), &pack_refs_opts);
 
        clear_ref_exclusions(&excludes);
        string_list_clear(&included_refs, 0);
diff --git a/refs.c b/refs.c
index 0d0831f29ba25bccae36170e9dcfef27f623904e..a41a94ae55bb43444015949e0871aeed42001694 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2313,7 +2313,13 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,
        refs->gitdir = xstrdup(path);
 }
 
-int refs_optimize(struct ref_store *refs, struct refs_optimize_opts *opts)
+/* 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 6b05bba527ffca938a75b1e1d98ee0f608d54234..2dd7ac1a16aee9b72b83c4f9eb322dd725de4b11 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -499,26 +499,32 @@ void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,
                                const struct string_list *refnames);
 
 /*
- * Flags for controlling behaviour of refs_optimize()
- * REFS_OPTIMIZE_PRUNE: Prune loose refs after packing
- * REFS_OPTIMIZE_AUTO: Pack refs on a best effort basis. The heuristics and end
- *                     result are decided by the ref backend. Backends may ignore
- *                     this flag and fall back to a normal repack.
+ * Flags for controlling behaviour of pack_refs()
+ * PACK_REFS_PRUNE: Prune loose refs after packing
+ * PACK_REFS_AUTO: Pack refs on a best effort basis. The heuristics and end
+ *                 result are decided by the ref backend. Backends may ignore
+ *                 this flag and fall back to a normal repack.
  */
-#define REFS_OPTIMIZE_PRUNE (1 << 0)
-#define REFS_OPTIMIZE_AUTO  (1 << 1)
+#define PACK_REFS_PRUNE (1 << 0)
+#define PACK_REFS_AUTO  (1 << 1)
 
-struct refs_optimize_opts {
+struct pack_refs_opts {
        unsigned int flags;
        struct ref_exclusions *exclusions;
        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.
  */
-int refs_optimize(struct ref_store *refs, struct refs_optimize_opts *opts);
+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 54f409c249c1dcf47fa93d21c2c4b42e22371068..f38991c02ae8d6f04552ac9305170448efcacafa 100644 (file)
@@ -124,11 +124,11 @@ static int debug_transaction_abort(struct ref_store *refs,
        return res;
 }
 
-static int debug_optimize(struct ref_store *ref_store, struct refs_optimize_opts *opts)
+static int debug_pack_refs(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->optimize(drefs->refs, opts);
-       trace_printf_key(&trace_refs, "optimize: %d\n", res);
+       int res = drefs->refs->be->pack_refs(drefs->refs, opts);
+       trace_printf_key(&trace_refs, "pack_refs: %d\n", res);
        return res;
 }
 
@@ -439,7 +439,7 @@ struct ref_storage_be refs_be_debug = {
        .transaction_finish = debug_transaction_finish,
        .transaction_abort = debug_transaction_abort,
 
-       .optimize = debug_optimize,
+       .pack_refs = debug_pack_refs,
        .rename_ref = debug_rename_ref,
        .copy_ref = debug_copy_ref,
 
index a1e70b1c10dbb81ec48727018b840d7677065f64..f4809edda8a5af6174099e4aa774f83b1c5f9189 100644 (file)
@@ -1355,7 +1355,7 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_
  */
 static int should_pack_ref(struct files_ref_store *refs,
                           const struct reference *ref,
-                          struct refs_optimize_opts *opts)
+                          struct pack_refs_opts *opts)
 {
        struct string_list_item *item;
 
@@ -1383,7 +1383,7 @@ static int should_pack_ref(struct files_ref_store *refs,
 }
 
 static int should_pack_refs(struct files_ref_store *refs,
-                           struct refs_optimize_opts *opts)
+                           struct pack_refs_opts *opts)
 {
        struct ref_iterator *iter;
        size_t packed_size;
@@ -1391,7 +1391,7 @@ static int should_pack_refs(struct files_ref_store *refs,
        size_t limit;
        int ret;
 
-       if (!(opts->flags & REFS_OPTIMIZE_AUTO))
+       if (!(opts->flags & PACK_REFS_AUTO))
                return 1;
 
        ret = packed_refs_size(refs->packed_ref_store, &packed_size);
@@ -1444,8 +1444,8 @@ static int should_pack_refs(struct files_ref_store *refs,
        return 0;
 }
 
-static int files_optimize(struct ref_store *ref_store,
-                         struct refs_optimize_opts *opts)
+static int files_pack_refs(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,
@@ -1488,7 +1488,7 @@ static int files_optimize(struct ref_store *ref_store,
                            iter->ref.name, err.buf);
 
                /* Schedule the loose reference for pruning if requested. */
-               if ((opts->flags & REFS_OPTIMIZE_PRUNE)) {
+               if ((opts->flags & PACK_REFS_PRUNE)) {
                        struct ref_to_prune *n;
                        FLEX_ALLOC_STR(n, name, iter->ref.name);
                        oidcpy(&n->oid, iter->ref.oid);
@@ -1512,6 +1512,15 @@ static int files_optimize(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.
@@ -3981,6 +3990,7 @@ 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 10062fd8b63063795266fb7dc0805ecdf43ac6a4..1ab0c5039301647d133b9672898a8262aa8a1568 100644 (file)
@@ -1773,8 +1773,8 @@ cleanup:
        return ret;
 }
 
-static int packed_optimize(struct ref_store *ref_store UNUSED,
-                          struct refs_optimize_opts *opts UNUSED)
+static int packed_pack_refs(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,
 
-       .optimize = packed_optimize,
+       .pack_refs = packed_pack_refs,
        .rename_ref = NULL,
        .copy_ref = NULL,
 
index dee42f231dbd0a0a445bf9b31fc61a5c3d95cc7e..4671517dade968fa673c04235c0e1d87552c368e 100644 (file)
@@ -422,8 +422,10 @@ 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 refs_optimize_opts *opts);
+                       struct pack_refs_opts *opts);
 typedef int rename_ref_fn(struct ref_store *ref_store,
                          const char *oldref, const char *newref,
                          const char *logmsg);
@@ -548,6 +550,7 @@ 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 c23c45f3bf46399b4eb432f2a8c1262bb8e37cbc..6bbfd5618dac16693c735994d29550da73403bf7 100644 (file)
@@ -1700,11 +1700,11 @@ done:
        return ret;
 }
 
-static int reftable_be_optimize(struct ref_store *ref_store,
-                               struct refs_optimize_opts *opts)
+static int reftable_be_pack_refs(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, "optimize_refs");
+               reftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, "pack_refs");
        struct reftable_stack *stack;
        int ret;
 
@@ -1715,7 +1715,7 @@ static int reftable_be_optimize(struct ref_store *ref_store,
        if (!stack)
                stack = refs->main_backend.stack;
 
-       if (opts->flags & REFS_OPTIMIZE_AUTO)
+       if (opts->flags & PACK_REFS_AUTO)
                ret = reftable_stack_auto_compact(stack);
        else
                ret = reftable_stack_compact_all(stack, NULL);
@@ -1733,6 +1733,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;
@@ -2755,6 +2761,7 @@ 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,
index 81086c369089b9dd77547d90cf3eea45469224c2..095823d915fd637e6212497566d3a76544d96caf 100644 (file)
@@ -459,3 +459,5 @@ test_expect_success 'pack-refs does not store invalid peeled tag value' '
                test_grep ! "^\^" .git/packed-refs
        )
 '
+
+test_done
index 3c706978efc2197c6d1bc19c4a8982f77f1b0690..12cf5d1dcba814ffe1a9d1baed41e9dbf7ba6e79 100755 (executable)
@@ -18,5 +18,3 @@ export GIT_TEST_DEFAULT_REF_FORMAT
 . ./test-lib.sh
 
 . "$TEST_DIRECTORY"/pack-refs-tests.sh
-
-test_done
index 9afe3c1ed7e33ad3a7e190c2c7dca1dfbc8ed756..c11c905d795d26b536d8f66c2807d172f54578a0 100755 (executable)
@@ -15,5 +15,3 @@ export GIT_TEST_DEFAULT_REF_FORMAT
 
 pack_refs='refs optimize'
 . "$TEST_DIRECTORY"/pack-refs-tests.sh
-
-test_done