{"thread":{"id":"64355","subject":"[PATCH v2 0/3] refs: cleanup code around optimizations","startedAt":"2025-10-20T08:18:39Z","lastAt":"2025-10-22T11:59:04Z","messageCount":6,"participants":["Karthik Nayak","Patrick Steinhardt"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"529160","messageId":"20251020-refs-code-cleanup-v2-0-f5349ed0f6a5@gmail.com","threadId":"64355","inReplyTo":null,"subject":"[PATCH v2 0/3] refs: cleanup code around optimizations","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-10-20T08:18:28Z","receivedAt":"2025-10-20T08:18:39Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"This is extracted from a recent series I sent [1], which I've since\ndropped to follow up with a different approach. I think these patches\nhold value individually.\n\nThey mostly cleanup code around 'git refs optimize' which was added\nrecently in db0babf9b2 (Merge branch 'ms/refs-optimize', 2025-10-02).\nThe code in the refs subsystem contains both 'pack-refs' and 'optimize'\nfunctions, which are one and the same.\n\nThis series unifies this to only retain the 'optimize' functions and\nnaming, since it backend generic.\n\nThis is based on top of master 143f58ef75 (Sync with Git 2.51.1,\n2025-10-15) with 'ps/ref-peeled-tags' merged in.\n\n[1]: 20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-0-c7962be584fa@gmail.com\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\nChanges in v2:\n- Squash the second commit into the first.\n- Change some variable names to also no longer refer to pack_refs.\n- Fix commit messages.\n- Link to v1: https://lore.kernel.org/r/20251015-refs-code-cleanup-v1-0-550fdd8a3b41@gmail.com\n\n---\n pack-refs.c                   | 20 ++++++++++----------\n refs.c                        |  8 +-------\n refs.h                        | 24 +++++++++---------------\n refs/debug.c                  |  8 ++++----\n refs/files-backend.c          | 22 ++++++----------------\n refs/packed-backend.c         |  6 +++---\n refs/refs-internal.h          |  5 +----\n refs/reftable-backend.c       | 15 ++++-----------\n t/pack-refs-tests.sh          |  2 --\n t/t0601-reffiles-pack-refs.sh |  2 ++\n t/t1463-refs-optimize.sh      |  2 ++\n 11 files changed, 42 insertions(+), 72 deletions(-)\n\nKarthik Nayak (3):\n      refs: move to using the '.optimize' functions\n      refs: rename 'pack_refs_opts' to 'refs_optimize_opts'\n      t/pack-refs-tests: move the 'test_done' to callees\n\nRange-diff versus v1:\n\n1:  ded0c04d60 ! 1:  fa153f2552 refs: move to using the '.optimize' functions\n    @@ Metadata\n      ## Commit message ##\n         refs: move to using the '.optimize' functions\n     \n    -    The `struct ref_store` variable, exposes two ways to optimize a reftable\n    +    The `struct ref_store` variable exposes two ways to optimize a reftable\n         backend:\n     \n           1. pack_refs\n    @@ Commit message\n         latter is more generic and covers all backends. While the naming is\n         different, both of these functions perform the same functionality.\n     \n    -    In the following commit, we will consolidate this code to only maintain\n    -    the 'optimize' functions. In preparation, modify the backends so that\n    -    they exclusively implement the `optimize` callback, only. All users of\n    -    the refs subsystem already use the 'optimize' function so there is no\n    -    changes needed on the callee side.\n    +    Consolidate this code to only maintain the 'optimize' functions. Do this\n    +    by modifying the backends so that they exclusively implement the\n    +    `optimize` callback, only. All users of the refs subsystem already use\n    +    the 'optimize' function so there is no changes needed on the callee\n    +    side. Finally, cleanup all references to the 'pack_refs' field of the\n    +    structure and code around it.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n    + ## refs.c ##\n    +@@ refs.c: void base_ref_store_init(struct ref_store *refs, struct repository *repo,\n    + \trefs->gitdir = xstrdup(path);\n    + }\n    + \n    +-/* backend functions */\n    +-int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)\n    +-{\n    +-\treturn refs->be->pack_refs(refs, opts);\n    +-}\n    +-\n    + int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)\n    + {\n    + \treturn refs->be->optimize(refs, opts);\n    +\n    + ## refs.h ##\n    +@@ refs.h: struct pack_refs_opts {\n    + \tstruct string_list *includes;\n    + };\n    + \n    +-/*\n    +- * Write a packed-refs file for the current repository.\n    +- * flags: Combination of the above PACK_REFS_* flags.\n    +- */\n    +-int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);\n    +-\n    + /*\n    +  * Optimize the ref store. The exact behavior is up to the backend.\n    +  * For the files backend, this is equivalent to packing refs.\n    +\n      ## refs/debug.c ##\n     @@ refs/debug.c: static int debug_transaction_abort(struct ref_store *refs,\n      \treturn res;\n    @@ refs/packed-backend.c: struct ref_storage_be refs_be_packed = {\n      \t.copy_ref = NULL,\n      \n     \n    + ## refs/refs-internal.h ##\n    +@@ refs/refs-internal.h: typedef int ref_transaction_commit_fn(struct ref_store *refs,\n    + \t\t\t\t      struct ref_transaction *transaction,\n    + \t\t\t\t      struct strbuf *err);\n    + \n    +-typedef int pack_refs_fn(struct ref_store *ref_store,\n    +-\t\t\t struct pack_refs_opts *opts);\n    + typedef int optimize_fn(struct ref_store *ref_store,\n    + \t\t\tstruct pack_refs_opts *opts);\n    + typedef int rename_ref_fn(struct ref_store *ref_store,\n    +@@ refs/refs-internal.h: struct ref_storage_be {\n    + \tref_transaction_finish_fn *transaction_finish;\n    + \tref_transaction_abort_fn *transaction_abort;\n    + \n    +-\tpack_refs_fn *pack_refs;\n    + \toptimize_fn *optimize;\n    + \trename_ref_fn *rename_ref;\n    + \tcopy_ref_fn *copy_ref;\n    +\n      ## refs/reftable-backend.c ##\n     @@ refs/reftable-backend.c: static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,\n      \treturn ret;\n2:  7670a662af < -:  ---------- refs: cleanup code around optimization\n3:  ad2c55175e ! 2:  16e8ec5501 refs: rename 'pack_refs_opts' to 'refs_optimize_opts'\n    @@ pack-refs.c: int pack_refs_core(int argc,\n      \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n      \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n     -\tstruct pack_refs_opts pack_refs_opts = {\n    -+\tstruct refs_optimize_opts pack_refs_opts = {\n    ++\tstruct refs_optimize_opts optimize_opts = {\n      \t\t.exclusions = &excludes,\n      \t\t.includes = &included_refs,\n     -\t\t.flags = PACK_REFS_PRUNE,\n    @@ pack-refs.c: int pack_refs_core(int argc,\n      \t\tOPT_BOOL(0, \"all\",   &pack_all, N_(\"pack everything\")),\n     -\t\tOPT_BIT(0, \"prune\", &pack_refs_opts.flags, N_(\"prune loose refs (default)\"), PACK_REFS_PRUNE),\n     -\t\tOPT_BIT(0, \"auto\", &pack_refs_opts.flags, N_(\"auto-pack refs as needed\"), PACK_REFS_AUTO),\n    -+\t\tOPT_BIT(0, \"prune\", &pack_refs_opts.flags, N_(\"prune loose refs (default)\"), REFS_OPTIMIZE_PRUNE),\n    -+\t\tOPT_BIT(0, \"auto\", &pack_refs_opts.flags, N_(\"auto-pack refs as needed\"), REFS_OPTIMIZE_AUTO),\n    - \t\tOPT_STRING_LIST(0, \"include\", pack_refs_opts.includes, N_(\"pattern\"),\n    +-\t\tOPT_STRING_LIST(0, \"include\", pack_refs_opts.includes, N_(\"pattern\"),\n    ++\t\tOPT_BIT(0, \"prune\", &optimize_opts.flags, N_(\"prune loose refs (default)\"), REFS_OPTIMIZE_PRUNE),\n    ++\t\tOPT_BIT(0, \"auto\", &optimize_opts.flags, N_(\"auto-pack refs as needed\"), REFS_OPTIMIZE_AUTO),\n    ++\t\tOPT_STRING_LIST(0, \"include\", optimize_opts.includes, N_(\"pattern\"),\n      \t\t\tN_(\"references to include\")),\n      \t\tOPT_STRING_LIST(0, \"exclude\", &option_excluded_refs, N_(\"pattern\"),\n    + \t\t\tN_(\"references to exclude\")),\n    +@@ pack-refs.c: int pack_refs_core(int argc,\n    + \t\tusage_with_options(usage_opts, opts);\n    + \n    + \tfor_each_string_list_item(item, &option_excluded_refs)\n    +-\t\tadd_ref_exclusion(pack_refs_opts.exclusions, item->string);\n    ++\t\tadd_ref_exclusion(optimize_opts.exclusions, item->string);\n    + \n    + \tif (pack_all)\n    +-\t\tstring_list_append(pack_refs_opts.includes, \"*\");\n    ++\t\tstring_list_append(optimize_opts.includes, \"*\");\n    + \n    +-\tif (!pack_refs_opts.includes->nr)\n    +-\t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n    ++\tif (!optimize_opts.includes->nr)\n    ++\t\tstring_list_append(optimize_opts.includes, \"refs/tags/*\");\n    + \n    +-\tret = refs_optimize(get_main_ref_store(repo), &pack_refs_opts);\n    ++\tret = refs_optimize(get_main_ref_store(repo), &optimize_opts);\n    + \n    + \tclear_ref_exclusions(&excludes);\n    + \tstring_list_clear(&included_refs, 0);\n     \n      ## refs.c ##\n     @@ refs.c: void base_ref_store_init(struct ref_store *refs, struct repository *repo,\n    @@ refs.c: void base_ref_store_init(struct ref_store *refs, struct repository *repo\n     \n      ## refs.h ##\n     @@ refs.h: void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,\n    + \t\t\t\tconst struct string_list *refnames);\n      \n      /*\n    -  * Flags for controlling behaviour of refs_optimize()\n    +- * Flags for controlling behaviour of pack_refs()\n     - * PACK_REFS_PRUNE: Prune loose refs after packing\n     - * PACK_REFS_AUTO: Pack refs on a best effort basis. The heuristics and end\n     - *                 result are decided by the ref backend. Backends may ignore\n     - *                 this flag and fall back to a normal repack.\n    ++ * Flags for controlling behaviour of refs_optimize()\n     + * REFS_OPTIMIZE_PRUNE: Prune loose refs after packing\n     + * REFS_OPTIMIZE_AUTO: Pack refs on a best effort basis. The heuristics and end\n     + *                     result are decided by the ref backend. Backends may ignore\n    @@ refs/packed-backend.c: static int packed_transaction_finish(struct ref_store *re\n      \n      static int packed_optimize(struct ref_store *ref_store UNUSED,\n     -\t\t\t   struct pack_refs_opts *pack_opts UNUSED)\n    -+\t\t\t   struct refs_optimize_opts *pack_opts UNUSED)\n    ++\t\t\t   struct refs_optimize_opts *opts UNUSED)\n      {\n      \t/*\n      \t * Packed refs are already packed. It might be that loose refs\n4:  c065b61ffb = 3:  6cfaeb7207 t/pack-refs-tests: move the 'test_done' to callees\n\n\nbase-commit: 854a80fd48848f942c4a566c9880dc5f089887af\nchange-id: 20251015-refs-code-cleanup-871a7ce7c8dd\n\nThanks\n- Karthik\n\n"},{"id":"529161","messageId":"20251020-refs-code-cleanup-v2-1-f5349ed0f6a5@gmail.com","threadId":"64355","inReplyTo":"20251020-refs-code-cleanup-v2-0-f5349ed0f6a5@gmail.com","subject":"[PATCH v2 1/3] refs: move to using the '.optimize' functions","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-10-20T08:18:29Z","receivedAt":"2025-10-20T08:18:40Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `struct ref_store` variable exposes two ways to optimize a reftable\nbackend:\n\n  1. pack_refs\n  2. optimize\n\nThe former was specific to the 'files' + 'packed' refs backend. The\nlatter is more generic and covers all backends. While the naming is\ndifferent, both of these functions perform the same functionality.\n\nConsolidate this code to only maintain the 'optimize' functions. Do this\nby modifying the backends so that they exclusively implement the\n`optimize` callback, only. All users of the refs subsystem already use\nthe 'optimize' function so there is no changes needed on the callee\nside. Finally, cleanup all references to the 'pack_refs' field of the\nstructure and code around it.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n refs.c                  |  6 ------\n refs.h                  |  6 ------\n refs/debug.c            |  8 ++++----\n refs/files-backend.c    | 14 ++------------\n refs/packed-backend.c   |  6 +++---\n refs/refs-internal.h    |  3 ---\n refs/reftable-backend.c | 13 +++----------\n 7 files changed, 12 insertions(+), 44 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex a41a94ae55..b9a4a60646 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2313,12 +2313,6 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,\n \trefs->gitdir = xstrdup(path);\n }\n \n-/* backend functions */\n-int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)\n-{\n-\treturn refs->be->pack_refs(refs, opts);\n-}\n-\n int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)\n {\n \treturn refs->be->optimize(refs, opts);\ndiff --git a/refs.h b/refs.h\nindex 23437d1220..6edb633eb6 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -514,12 +514,6 @@ struct pack_refs_opts {\n \tstruct string_list *includes;\n };\n \n-/*\n- * Write a packed-refs file for the current repository.\n- * flags: Combination of the above PACK_REFS_* flags.\n- */\n-int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);\n-\n /*\n  * Optimize the ref store. The exact behavior is up to the backend.\n  * For the files backend, this is equivalent to packing refs.\ndiff --git a/refs/debug.c b/refs/debug.c\nindex 01499b9033..40cd1d9c15 100644\n--- a/refs/debug.c\n+++ b/refs/debug.c\n@@ -116,11 +116,11 @@ static int debug_transaction_abort(struct ref_store *refs,\n \treturn res;\n }\n \n-static int debug_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *opts)\n+static int debug_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts)\n {\n \tstruct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;\n-\tint res = drefs->refs->be->pack_refs(drefs->refs, opts);\n-\ttrace_printf_key(&trace_refs, \"pack_refs: %d\\n\", res);\n+\tint res = drefs->refs->be->optimize(drefs->refs, opts);\n+\ttrace_printf_key(&trace_refs, \"optimize: %d\\n\", res);\n \treturn res;\n }\n \n@@ -430,7 +430,7 @@ struct ref_storage_be refs_be_debug = {\n \t.transaction_finish = debug_transaction_finish,\n \t.transaction_abort = debug_transaction_abort,\n \n-\t.pack_refs = debug_pack_refs,\n+\t.optimize = debug_optimize,\n \t.rename_ref = debug_rename_ref,\n \t.copy_ref = debug_copy_ref,\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex ed8a1729d6..92d90fc508 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -1444,8 +1444,8 @@ static int should_pack_refs(struct files_ref_store *refs,\n \treturn 0;\n }\n \n-static int files_pack_refs(struct ref_store *ref_store,\n-\t\t\t   struct pack_refs_opts *opts)\n+static int files_optimize(struct ref_store *ref_store,\n+\t\t\t  struct pack_refs_opts *opts)\n {\n \tstruct files_ref_store *refs =\n \t\tfiles_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB,\n@@ -1512,15 +1512,6 @@ static int files_pack_refs(struct ref_store *ref_store,\n \treturn 0;\n }\n \n-static int files_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts)\n-{\n-\t/*\n-\t * For the \"files\" backend, \"optimizing\" is the same as \"packing\".\n-\t * So, we just call the existing worker function for packing.\n-\t */\n-\treturn files_pack_refs(ref_store, opts);\n-}\n-\n /*\n  * People using contrib's git-new-workdir have .git/logs/refs ->\n  * /some/other/path/.git/logs/refs, and that may live on another device.\n@@ -3969,7 +3960,6 @@ struct ref_storage_be refs_be_files = {\n \t.transaction_finish = files_transaction_finish,\n \t.transaction_abort = files_transaction_abort,\n \n-\t.pack_refs = files_pack_refs,\n \t.optimize = files_optimize,\n \t.rename_ref = files_rename_ref,\n \t.copy_ref = files_copy_ref,\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 1ab0c50393..20cf9fab18 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1773,8 +1773,8 @@ static int packed_transaction_finish(struct ref_store *ref_store,\n \treturn ret;\n }\n \n-static int packed_pack_refs(struct ref_store *ref_store UNUSED,\n-\t\t\t    struct pack_refs_opts *pack_opts UNUSED)\n+static int packed_optimize(struct ref_store *ref_store UNUSED,\n+\t\t\t   struct pack_refs_opts *pack_opts UNUSED)\n {\n \t/*\n \t * Packed refs are already packed. It might be that loose refs\n@@ -2129,7 +2129,7 @@ struct ref_storage_be refs_be_packed = {\n \t.transaction_finish = packed_transaction_finish,\n \t.transaction_abort = packed_transaction_abort,\n \n-\t.pack_refs = packed_pack_refs,\n+\t.optimize = packed_optimize,\n \t.rename_ref = NULL,\n \t.copy_ref = NULL,\n \ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex 4671517dad..fc5149df5b 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -422,8 +422,6 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,\n \t\t\t\t      struct ref_transaction *transaction,\n \t\t\t\t      struct strbuf *err);\n \n-typedef int pack_refs_fn(struct ref_store *ref_store,\n-\t\t\t struct pack_refs_opts *opts);\n typedef int optimize_fn(struct ref_store *ref_store,\n \t\t\tstruct pack_refs_opts *opts);\n typedef int rename_ref_fn(struct ref_store *ref_store,\n@@ -550,7 +548,6 @@ struct ref_storage_be {\n \tref_transaction_finish_fn *transaction_finish;\n \tref_transaction_abort_fn *transaction_abort;\n \n-\tpack_refs_fn *pack_refs;\n \toptimize_fn *optimize;\n \trename_ref_fn *rename_ref;\n \tcopy_ref_fn *copy_ref;\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex 6bbfd5618d..43cc66a48e 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -1700,11 +1700,11 @@ static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,\n \treturn ret;\n }\n \n-static int reftable_be_pack_refs(struct ref_store *ref_store,\n-\t\t\t\t struct pack_refs_opts *opts)\n+static int reftable_be_optimize(struct ref_store *ref_store,\n+\t\t\t\tstruct pack_refs_opts *opts)\n {\n \tstruct reftable_ref_store *refs =\n-\t\treftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, \"pack_refs\");\n+\t\treftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, \"optimize_refs\");\n \tstruct reftable_stack *stack;\n \tint ret;\n \n@@ -1733,12 +1733,6 @@ static int reftable_be_pack_refs(struct ref_store *ref_store,\n \treturn ret;\n }\n \n-static int reftable_be_optimize(struct ref_store *ref_store,\n-\t\t\t\tstruct pack_refs_opts *opts)\n-{\n-\treturn reftable_be_pack_refs(ref_store, opts);\n-}\n-\n struct write_create_symref_arg {\n \tstruct reftable_ref_store *refs;\n \tstruct reftable_stack *stack;\n@@ -2761,7 +2755,6 @@ struct ref_storage_be refs_be_reftable = {\n \t.transaction_finish = reftable_be_transaction_finish,\n \t.transaction_abort = reftable_be_transaction_abort,\n \n-\t.pack_refs = reftable_be_pack_refs,\n \t.optimize = reftable_be_optimize,\n \t.rename_ref = reftable_be_rename_ref,\n \t.copy_ref = reftable_be_copy_ref,\n\n-- \n2.51.0\n\n"},{"id":"529162","messageId":"20251020-refs-code-cleanup-v2-2-f5349ed0f6a5@gmail.com","threadId":"64355","inReplyTo":"20251020-refs-code-cleanup-v2-0-f5349ed0f6a5@gmail.com","subject":"[PATCH v2 2/3] refs: rename 'pack_refs_opts' to 'refs_optimize_opts'","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-10-20T08:18:30Z","receivedAt":"2025-10-20T08:18:40Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The previous commit removed all references to 'pack_refs()' within\nthe refs subsystem. Continue this cleanup by also renaming\n'pack_refs_opts' to 'refs_optimize_opts' and the respective flags\naccordingly. Keeping the naming consistent will make the code easier to\nmaintain.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n pack-refs.c             | 20 ++++++++++----------\n refs.c                  |  2 +-\n refs.h                  | 18 +++++++++---------\n refs/debug.c            |  2 +-\n refs/files-backend.c    | 10 +++++-----\n refs/packed-backend.c   |  2 +-\n refs/refs-internal.h    |  2 +-\n refs/reftable-backend.c |  4 ++--\n 8 files changed, 30 insertions(+), 30 deletions(-)\n\ndiff --git a/pack-refs.c b/pack-refs.c\nindex 1a5e07d8b8..eb6b2ba2c2 100644\n--- a/pack-refs.c\n+++ b/pack-refs.c\n@@ -14,10 +14,10 @@ int pack_refs_core(int argc,\n {\n \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n-\tstruct pack_refs_opts pack_refs_opts = {\n+\tstruct refs_optimize_opts optimize_opts = {\n \t\t.exclusions = &excludes,\n \t\t.includes = &included_refs,\n-\t\t.flags = PACK_REFS_PRUNE,\n+\t\t.flags = REFS_OPTIMIZE_PRUNE,\n \t};\n \tstruct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;\n \tstruct string_list_item *item;\n@@ -26,9 +26,9 @@ int pack_refs_core(int argc,\n \n \tstruct option opts[] = {\n \t\tOPT_BOOL(0, \"all\",   &pack_all, N_(\"pack everything\")),\n-\t\tOPT_BIT(0, \"prune\", &pack_refs_opts.flags, N_(\"prune loose refs (default)\"), PACK_REFS_PRUNE),\n-\t\tOPT_BIT(0, \"auto\", &pack_refs_opts.flags, N_(\"auto-pack refs as needed\"), PACK_REFS_AUTO),\n-\t\tOPT_STRING_LIST(0, \"include\", pack_refs_opts.includes, N_(\"pattern\"),\n+\t\tOPT_BIT(0, \"prune\", &optimize_opts.flags, N_(\"prune loose refs (default)\"), REFS_OPTIMIZE_PRUNE),\n+\t\tOPT_BIT(0, \"auto\", &optimize_opts.flags, N_(\"auto-pack refs as needed\"), REFS_OPTIMIZE_AUTO),\n+\t\tOPT_STRING_LIST(0, \"include\", optimize_opts.includes, N_(\"pattern\"),\n \t\t\tN_(\"references to include\")),\n \t\tOPT_STRING_LIST(0, \"exclude\", &option_excluded_refs, N_(\"pattern\"),\n \t\t\tN_(\"references to exclude\")),\n@@ -39,15 +39,15 @@ int pack_refs_core(int argc,\n \t\tusage_with_options(usage_opts, opts);\n \n \tfor_each_string_list_item(item, &option_excluded_refs)\n-\t\tadd_ref_exclusion(pack_refs_opts.exclusions, item->string);\n+\t\tadd_ref_exclusion(optimize_opts.exclusions, item->string);\n \n \tif (pack_all)\n-\t\tstring_list_append(pack_refs_opts.includes, \"*\");\n+\t\tstring_list_append(optimize_opts.includes, \"*\");\n \n-\tif (!pack_refs_opts.includes->nr)\n-\t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n+\tif (!optimize_opts.includes->nr)\n+\t\tstring_list_append(optimize_opts.includes, \"refs/tags/*\");\n \n-\tret = refs_optimize(get_main_ref_store(repo), &pack_refs_opts);\n+\tret = refs_optimize(get_main_ref_store(repo), &optimize_opts);\n \n \tclear_ref_exclusions(&excludes);\n \tstring_list_clear(&included_refs, 0);\ndiff --git a/refs.c b/refs.c\nindex b9a4a60646..0d0831f29b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2313,7 +2313,7 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,\n \trefs->gitdir = xstrdup(path);\n }\n \n-int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)\n+int refs_optimize(struct ref_store *refs, struct refs_optimize_opts *opts)\n {\n \treturn refs->be->optimize(refs, opts);\n }\ndiff --git a/refs.h b/refs.h\nindex 6edb633eb6..d2630af97f 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -499,16 +499,16 @@ void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,\n \t\t\t\tconst struct string_list *refnames);\n \n /*\n- * Flags for controlling behaviour of pack_refs()\n- * PACK_REFS_PRUNE: Prune loose refs after packing\n- * PACK_REFS_AUTO: Pack refs on a best effort basis. The heuristics and end\n- *                 result are decided by the ref backend. Backends may ignore\n- *                 this flag and fall back to a normal repack.\n+ * Flags for controlling behaviour of refs_optimize()\n+ * REFS_OPTIMIZE_PRUNE: Prune loose refs after packing\n+ * REFS_OPTIMIZE_AUTO: Pack refs on a best effort basis. The heuristics and end\n+ *                     result are decided by the ref backend. Backends may ignore\n+ *                     this flag and fall back to a normal repack.\n  */\n-#define PACK_REFS_PRUNE (1 << 0)\n-#define PACK_REFS_AUTO  (1 << 1)\n+#define REFS_OPTIMIZE_PRUNE (1 << 0)\n+#define REFS_OPTIMIZE_AUTO  (1 << 1)\n \n-struct pack_refs_opts {\n+struct refs_optimize_opts {\n \tunsigned int flags;\n \tstruct ref_exclusions *exclusions;\n \tstruct string_list *includes;\n@@ -518,7 +518,7 @@ struct pack_refs_opts {\n  * Optimize the ref store. The exact behavior is up to the backend.\n  * For the files backend, this is equivalent to packing refs.\n  */\n-int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts);\n+int refs_optimize(struct ref_store *refs, struct refs_optimize_opts *opts);\n \n /*\n  * Setup reflog before using. Fill in err and return -1 on failure.\ndiff --git a/refs/debug.c b/refs/debug.c\nindex 40cd1d9c15..2defd2d465 100644\n--- a/refs/debug.c\n+++ b/refs/debug.c\n@@ -116,7 +116,7 @@ static int debug_transaction_abort(struct ref_store *refs,\n \treturn res;\n }\n \n-static int debug_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts)\n+static int debug_optimize(struct ref_store *ref_store, struct refs_optimize_opts *opts)\n {\n \tstruct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;\n \tint res = drefs->refs->be->optimize(drefs->refs, opts);\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 92d90fc508..2f60395cd2 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -1355,7 +1355,7 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_\n  */\n static int should_pack_ref(struct files_ref_store *refs,\n \t\t\t   const struct reference *ref,\n-\t\t\t   struct pack_refs_opts *opts)\n+\t\t\t   struct refs_optimize_opts *opts)\n {\n \tstruct string_list_item *item;\n \n@@ -1383,7 +1383,7 @@ static int should_pack_ref(struct files_ref_store *refs,\n }\n \n static int should_pack_refs(struct files_ref_store *refs,\n-\t\t\t    struct pack_refs_opts *opts)\n+\t\t\t    struct refs_optimize_opts *opts)\n {\n \tstruct ref_iterator *iter;\n \tsize_t packed_size;\n@@ -1391,7 +1391,7 @@ static int should_pack_refs(struct files_ref_store *refs,\n \tsize_t limit;\n \tint ret;\n \n-\tif (!(opts->flags & PACK_REFS_AUTO))\n+\tif (!(opts->flags & REFS_OPTIMIZE_AUTO))\n \t\treturn 1;\n \n \tret = packed_refs_size(refs->packed_ref_store, &packed_size);\n@@ -1445,7 +1445,7 @@ static int should_pack_refs(struct files_ref_store *refs,\n }\n \n static int files_optimize(struct ref_store *ref_store,\n-\t\t\t  struct pack_refs_opts *opts)\n+\t\t\t  struct refs_optimize_opts *opts)\n {\n \tstruct files_ref_store *refs =\n \t\tfiles_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB,\n@@ -1488,7 +1488,7 @@ static int files_optimize(struct ref_store *ref_store,\n \t\t\t    iter->ref.name, err.buf);\n \n \t\t/* Schedule the loose reference for pruning if requested. */\n-\t\tif ((opts->flags & PACK_REFS_PRUNE)) {\n+\t\tif ((opts->flags & REFS_OPTIMIZE_PRUNE)) {\n \t\t\tstruct ref_to_prune *n;\n \t\t\tFLEX_ALLOC_STR(n, name, iter->ref.name);\n \t\t\toidcpy(&n->oid, iter->ref.oid);\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 20cf9fab18..10062fd8b6 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1774,7 +1774,7 @@ static int packed_transaction_finish(struct ref_store *ref_store,\n }\n \n static int packed_optimize(struct ref_store *ref_store UNUSED,\n-\t\t\t   struct pack_refs_opts *pack_opts UNUSED)\n+\t\t\t   struct refs_optimize_opts *opts UNUSED)\n {\n \t/*\n \t * Packed refs are already packed. It might be that loose refs\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex fc5149df5b..dee42f231d 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -423,7 +423,7 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,\n \t\t\t\t      struct strbuf *err);\n \n typedef int optimize_fn(struct ref_store *ref_store,\n-\t\t\tstruct pack_refs_opts *opts);\n+\t\t\tstruct refs_optimize_opts *opts);\n typedef int rename_ref_fn(struct ref_store *ref_store,\n \t\t\t  const char *oldref, const char *newref,\n \t\t\t  const char *logmsg);\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex 43cc66a48e..c23c45f3bf 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -1701,7 +1701,7 @@ static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,\n }\n \n static int reftable_be_optimize(struct ref_store *ref_store,\n-\t\t\t\tstruct pack_refs_opts *opts)\n+\t\t\t\tstruct refs_optimize_opts *opts)\n {\n \tstruct reftable_ref_store *refs =\n \t\treftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, \"optimize_refs\");\n@@ -1715,7 +1715,7 @@ static int reftable_be_optimize(struct ref_store *ref_store,\n \tif (!stack)\n \t\tstack = refs->main_backend.stack;\n \n-\tif (opts->flags & PACK_REFS_AUTO)\n+\tif (opts->flags & REFS_OPTIMIZE_AUTO)\n \t\tret = reftable_stack_auto_compact(stack);\n \telse\n \t\tret = reftable_stack_compact_all(stack, NULL);\n\n-- \n2.51.0\n\n"},{"id":"529163","messageId":"20251020-refs-code-cleanup-v2-3-f5349ed0f6a5@gmail.com","threadId":"64355","inReplyTo":"20251020-refs-code-cleanup-v2-0-f5349ed0f6a5@gmail.com","subject":"[PATCH v2 3/3] t/pack-refs-tests: move the 'test_done' to callees","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-10-20T08:18:31Z","receivedAt":"2025-10-20T08:18:41Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In ac0bad0af4 (t0601: refactor tests to be shareable, 2025-09-19), we\nrefactored 't/t0601-reffiles-pack-refs.sh' to move all of the tests to\n't/pack-refs-tests.sh', which became a common test suite which was also\nused by 't/t1463-refs-optimize.sh'.\n\nThis also moved the 'test_done' directive to 't/pack-refs-tests.sh'.\nWhich inhibits additional tests from being added to either of the tests.\nLet's move the directive out to both the tests, so that we can add\nadditional specific tests to them. Also the test flow logic shouldn't be\npart of tests which can be embedded in other test scripts.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n t/pack-refs-tests.sh          | 2 --\n t/t0601-reffiles-pack-refs.sh | 2 ++\n t/t1463-refs-optimize.sh      | 2 ++\n 3 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/t/pack-refs-tests.sh b/t/pack-refs-tests.sh\nindex 095823d915..81086c3690 100644\n--- a/t/pack-refs-tests.sh\n+++ b/t/pack-refs-tests.sh\n@@ -459,5 +459,3 @@ test_expect_success 'pack-refs does not store invalid peeled tag value' '\n \t\ttest_grep ! \"^\\^\" .git/packed-refs\n \t)\n '\n-\n-test_done\ndiff --git a/t/t0601-reffiles-pack-refs.sh b/t/t0601-reffiles-pack-refs.sh\nindex 12cf5d1dcb..3c706978ef 100755\n--- a/t/t0601-reffiles-pack-refs.sh\n+++ b/t/t0601-reffiles-pack-refs.sh\n@@ -18,3 +18,5 @@ export GIT_TEST_DEFAULT_REF_FORMAT\n . ./test-lib.sh\n \n . \"$TEST_DIRECTORY\"/pack-refs-tests.sh\n+\n+test_done\ndiff --git a/t/t1463-refs-optimize.sh b/t/t1463-refs-optimize.sh\nindex c11c905d79..9afe3c1ed7 100755\n--- a/t/t1463-refs-optimize.sh\n+++ b/t/t1463-refs-optimize.sh\n@@ -15,3 +15,5 @@ export GIT_TEST_DEFAULT_REF_FORMAT\n \n pack_refs='refs optimize'\n . \"$TEST_DIRECTORY\"/pack-refs-tests.sh\n+\n+test_done\n\n-- \n2.51.0\n\n"},{"id":"529215","messageId":"aPcXNOz7HdxfUzcC@pks.im","threadId":"64355","inReplyTo":"20251020-refs-code-cleanup-v2-0-f5349ed0f6a5@gmail.com","subject":"Re: [PATCH v2 0/3] refs: cleanup code around optimizations","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-10-21T05:16:36Z","receivedAt":"2025-10-21T05:16:43Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Oct 20, 2025 at 10:18:28AM +0200, Karthik Nayak wrote:\n> This is extracted from a recent series I sent [1], which I've since\n> dropped to follow up with a different approach. I think these patches\n> hold value individually.\n> \n> They mostly cleanup code around 'git refs optimize' which was added\n> recently in db0babf9b2 (Merge branch 'ms/refs-optimize', 2025-10-02).\n> The code in the refs subsystem contains both 'pack-refs' and 'optimize'\n> functions, which are one and the same.\n> \n> This series unifies this to only retain the 'optimize' functions and\n> naming, since it backend generic.\n> \n> This is based on top of master 143f58ef75 (Sync with Git 2.51.1,\n> 2025-10-15) with 'ps/ref-peeled-tags' merged in.\n> \n> [1]: 20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-0-c7962be584fa@gmail.com\n> \n> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n> ---\n> Changes in v2:\n> - Squash the second commit into the first.\n> - Change some variable names to also no longer refer to pack_refs.\n> - Fix commit messages.\n> - Link to v1: https://lore.kernel.org/r/20251015-refs-code-cleanup-v1-0-550fdd8a3b41@gmail.com\n\nThis version looks good to me. Thanks for all these cleanups!\n\nPatrick\n"},{"id":"529408","messageId":"CAOLa=ZRmp3PDg7q+SEirO-UXZdvE_nRvSYCMYRdqa72OcTaauA@mail.gmail.com","threadId":"64355","inReplyTo":"aPcXNOz7HdxfUzcC@pks.im","subject":"Re: [PATCH v2 0/3] refs: cleanup code around optimizations","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-10-22T11:59:02Z","receivedAt":"2025-10-22T11:59:04Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Mon, Oct 20, 2025 at 10:18:28AM +0200, Karthik Nayak wrote:\n>> This is extracted from a recent series I sent [1], which I've since\n>> dropped to follow up with a different approach. I think these patches\n>> hold value individually.\n>>\n>> They mostly cleanup code around 'git refs optimize' which was added\n>> recently in db0babf9b2 (Merge branch 'ms/refs-optimize', 2025-10-02).\n>> The code in the refs subsystem contains both 'pack-refs' and 'optimize'\n>> functions, which are one and the same.\n>>\n>> This series unifies this to only retain the 'optimize' functions and\n>> naming, since it backend generic.\n>>\n>> This is based on top of master 143f58ef75 (Sync with Git 2.51.1,\n>> 2025-10-15) with 'ps/ref-peeled-tags' merged in.\n>>\n>> [1]: 20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-0-c7962be584fa@gmail.com\n>>\n>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n>> ---\n>> Changes in v2:\n>> - Squash the second commit into the first.\n>> - Change some variable names to also no longer refer to pack_refs.\n>> - Fix commit messages.\n>> - Link to v1: https://lore.kernel.org/r/20251015-refs-code-cleanup-v1-0-550fdd8a3b41@gmail.com\n>\n> This version looks good to me. Thanks for all these cleanups!\n>\n> Patrick\n\nThanks for the review!\n"}]}