{"thread":{"id":"62498","subject":"[PATCH 0/8] Change midx.c and midx-write.c to not use global variables","startedAt":"2024-11-15T13:42:35Z","lastAt":"2024-12-03T23:06:21Z","messageCount":70,"participants":["Karthik Nayak","karthik nayak","brian m. carlson","shejialuo","Patrick Steinhardt","Richard Kerry","Christian Couder","Taylor Blau","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"507361","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":null,"subject":"[PATCH 0/8] Change midx.c and midx-write.c to not use global variables","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:13Z","receivedAt":"2024-11-15T13:42:35Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Similar to the earlier patch series on cleaning up packfile.c and\nremoving usage of global variables [1], we change the midx.c and\nmidx-write.c files to no longer use global variables.\n\nThis is done by the following:\n  - Usage of repository variable already available in existing structs.\n  - Passing down repository variable from other subsystems.\n  - Modifying all subcommands to obtain repository variable from the\n  command in `builtins/` and passing down the variable from there.\n\nThe biggest change is in the first commit, wherein we modify all\nsubcommands to add the repository variable. Since the subcommand\ndefinition are not often changed, it shouldn't cause too many conflicts\nwith in flight topics.\n\nSince the `packfile.c` cleanup is still in flight, this series is based\non top of master: b31fb630c0 (Merge https://github.com/j6t/git-gui,\n2024-11-11) with those patches merged in.\n\n[1]: https://lore.kernel.org/git/cover.1729504640.git.karthik.188@gmail.com/\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\nKarthik Nayak (8):\n      builtin: pass repository to sub commands\n      midx-write: add repository field to `write_midx_context`\n      midx-write: pass down repository to `write_midx_file[_only]`\n      midx: cleanup internal usage of `the_repository` and `the_hash_algo`\n      midx: pass `repository` to `load_multi_pack_index`\n      midx: pass down `hash_algo` to `get_midx_filename[_ext]`\n      midx: pass down `hash_algo` to `get_split_midx_filename_ext`\n      midx: inline the `MIDX_MIN_SIZE` definition\n\n builtin/bisect.c              |  32 +++++++----\n builtin/bundle.c              |  16 ++++--\n builtin/commit-graph.c        |  10 ++--\n builtin/config.c              |  25 +++++---\n builtin/gc.c                  |  21 ++++---\n builtin/hook.c                |   7 ++-\n builtin/multi-pack-index.c    |  20 ++++---\n builtin/notes.c               |  36 +++++++-----\n builtin/reflog.c              |  17 ++++--\n builtin/refs.c                |  10 ++--\n builtin/remote.c              |  34 +++++++----\n builtin/repack.c              |   2 +-\n builtin/sparse-checkout.c     |  25 +++++---\n builtin/stash.c               |  39 ++++++++-----\n builtin/submodule--helper.c   |  46 +++++++++------\n builtin/worktree.c            |  28 +++++----\n midx-write.c                  | 129 +++++++++++++++++++++---------------------\n midx.c                        |  88 ++++++++++++++--------------\n midx.h                        |  24 ++++----\n pack-bitmap.c                 |   6 +-\n pack-revindex.c               |   2 +-\n parse-options.h               |   4 +-\n t/helper/test-parse-options.c |  11 +++-\n t/helper/test-read-midx.c     |   8 +--\n 24 files changed, 380 insertions(+), 260 deletions(-)\n---\nbase-commit: b31fb630c0fc6869a33ed717163e8a1210460d94\nchange-id: 20241111-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-a88498c2590f\nprerequisite-message-id: <cover.1731323350.git.karthik.188@gmail.com>\nprerequisite-patch-id: 0c0b2f7ab45aa1c6a14b43577b527e388fbdbc38\nprerequisite-patch-id: e3c455e9206c11da6df31b4fed1bb5a50f4b05a2\nprerequisite-patch-id: d85a7bba34e100fe2fdcd69f9710d3791e5ea1bf\nprerequisite-patch-id: d3ad99374f4cca79ab58862ba31f61970e18eec2\nprerequisite-patch-id: bc4ede2ad40588cc2a65598e875da121251012f9\nprerequisite-patch-id: 74b62a5d62b178284a60d376aa0425758f15f514\nprerequisite-patch-id: 4a70e65446538fff399de3b019a5c187e6ee9895\nprerequisite-patch-id: bf5a723ee69217d389fc735b19b1cd04fd7a389a\nprerequisite-patch-id: 9d796bcf18fea156bd225787dbb4b8b0e2a7d23b\n\nBest regards,\n-- \nKarthik Nayak <karthik.188@gmail.com>\n\n"},{"id":"507363","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-1-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 1/8] builtin: pass repository to sub commands","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:14Z","receivedAt":"2024-11-15T13:42:35Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In 9b1cb5070f (builtin: add a repository parameter for builtin\nfunctions, 2024-09-13) we passed down the repository to all builtin\ncommands. This allowed us to pass down the repository to lower layers\nwithout depending on the global `the_repository` variable.\n\nTo continue this work, we also pass down the repository parameter from\nthe command to sub-commands. In the upcoming commit, we'll utilize this\nto remove global variable usage in `midx-write.c`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/bisect.c              | 32 +++++++++++++++++++-----------\n builtin/bundle.c              | 16 +++++++++------\n builtin/commit-graph.c        | 10 ++++++----\n builtin/config.c              | 25 ++++++++++++++---------\n builtin/gc.c                  | 21 ++++++++++++--------\n builtin/hook.c                |  7 ++++---\n builtin/multi-pack-index.c    | 16 +++++++++------\n builtin/notes.c               | 36 +++++++++++++++++++++------------\n builtin/reflog.c              | 17 ++++++++++------\n builtin/refs.c                | 10 ++++++----\n builtin/remote.c              | 34 +++++++++++++++++++++-----------\n builtin/sparse-checkout.c     | 25 ++++++++++++++---------\n builtin/stash.c               | 39 +++++++++++++++++++++++-------------\n builtin/submodule--helper.c   | 46 ++++++++++++++++++++++++++++---------------\n builtin/worktree.c            | 28 ++++++++++++++++----------\n parse-options.h               |  4 +++-\n t/helper/test-parse-options.c | 11 ++++++++---\n 17 files changed, 242 insertions(+), 135 deletions(-)\n\ndiff --git a/builtin/bisect.c b/builtin/bisect.c\nindex 21d17a6c1a83e51fb82b53703b95d89bd9028830..8166d4abf532fbc95aaac71198e9722684ccf7f5 100644\n--- a/builtin/bisect.c\n+++ b/builtin/bisect.c\n@@ -1312,7 +1312,8 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)\n \treturn res;\n }\n \n-static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tif (argc > 1)\n \t\treturn error(_(\"'%s' requires either no argument or a commit\"),\n@@ -1320,7 +1321,8 @@ static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNU\n \treturn bisect_reset(argc ? argv[0] : NULL);\n }\n \n-static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1333,7 +1335,8 @@ static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNU\n \treturn res;\n }\n \n-static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1344,7 +1347,8 @@ static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNU\n \treturn res;\n }\n \n-static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix)\n+static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1358,12 +1362,15 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref\n \treturn res;\n }\n \n-static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED)\n+static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED,\n+\t\t\t   const char *prefix UNUSED,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \treturn bisect_log();\n }\n \n-static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t      struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1376,7 +1383,8 @@ static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UN\n \treturn res;\n }\n \n-static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1388,7 +1396,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS\n \treturn res;\n }\n \n-static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t\t struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1399,7 +1408,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix\n \treturn res;\n }\n \n-static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1415,7 +1425,7 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE\n int cmd_bisect(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tint res = 0;\n \tparse_opt_subcommand_fn *fn = NULL;\n@@ -1451,7 +1461,7 @@ int cmd_bisect(int argc,\n \t} else {\n \t\targc--;\n \t\targv++;\n-\t\tres = fn(argc, argv, prefix);\n+\t\tres = fn(argc, argv, prefix, repo);\n \t}\n \n \treturn is_bisect_success(res) ? 0 : -res;\ndiff --git a/builtin/bundle.c b/builtin/bundle.c\nindex 127518c2a8d3c4ec0bde62f1932e964ce9bcf66f..3f14754197c847e7a4e98b607c1a24df2b053daf 100644\n--- a/builtin/bundle.c\n+++ b/builtin/bundle.c\n@@ -67,7 +67,8 @@ static int parse_options_cmd_bundle(int argc,\n \treturn argc;\n }\n \n-static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_create(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED) {\n \tstruct strvec pack_opts = STRVEC_INIT;\n \tint version = -1;\n \tint ret;\n@@ -123,7 +124,8 @@ static int open_bundle(const char *path, struct bundle_header *header,\n \treturn read_bundle_header(path, header);\n }\n \n-static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_verify(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED) {\n \tstruct bundle_header header = BUNDLE_HEADER_INIT;\n \tint bundle_fd = -1;\n \tint quiet = 0;\n@@ -164,7 +166,8 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {\n \treturn ret;\n }\n \n-static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix,\n+\t\t\t\t struct repository *repo UNUSED) {\n \tstruct bundle_header header = BUNDLE_HEADER_INIT;\n \tint bundle_fd = -1;\n \tint ret;\n@@ -189,7 +192,8 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix\n \treturn ret;\n }\n \n-static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED) {\n \tstruct bundle_header header = BUNDLE_HEADER_INIT;\n \tint bundle_fd = -1;\n \tint ret;\n@@ -231,7 +235,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)\n int cmd_bundle(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n@@ -247,5 +251,5 @@ int cmd_bundle(int argc,\n \n \tpacket_trace_identity(\"bundle\");\n \n-\treturn !!fn(argc, argv, prefix);\n+\treturn !!fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 7c991db6eb48ad6e935727a079abac02bb358f8a..bd70d052e706b6e34b5aaaceef158c63ea4863d5 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -62,7 +62,8 @@ static struct option *add_common_options(struct option *to)\n \treturn parse_options_concat(common_opts, to);\n }\n \n-static int graph_verify(int argc, const char **argv, const char *prefix)\n+static int graph_verify(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tstruct commit_graph *graph = NULL;\n \tstruct object_directory *odb = NULL;\n@@ -214,7 +215,8 @@ static int git_commit_graph_write_config(const char *var, const char *value,\n \treturn 0;\n }\n \n-static int graph_write(int argc, const char **argv, const char *prefix)\n+static int graph_write(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct string_list pack_indexes = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -333,7 +335,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)\n int cmd_commit_graph(int argc,\n \t\t     const char **argv,\n \t\t     const char *prefix,\n-\t\t     struct repository *repo UNUSED)\n+\t\t     struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_commit_graph_options[] = {\n@@ -352,5 +354,5 @@ int cmd_commit_graph(int argc,\n \t\t\t     builtin_commit_graph_usage, 0);\n \tFREE_AND_NULL(options);\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/config.c b/builtin/config.c\nindex cba702210815b716a5c6c93ebb69d8c485901e43..16e6e3055598f1355714dc6de458b662870214c0 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -826,7 +826,8 @@ static void display_options_init(struct config_display_options *opts)\n \t}\n }\n \n-static int cmd_config_list(int argc, const char **argv, const char *prefix)\n+static int cmd_config_list(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;\n@@ -861,7 +862,8 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int cmd_config_get(int argc, const char **argv, const char *prefix)\n+static int cmd_config_get(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;\n@@ -915,7 +917,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int cmd_config_set(int argc, const char **argv, const char *prefix)\n+static int cmd_config_set(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tconst char *value_pattern = NULL, *comment_arg = NULL;\n@@ -973,7 +976,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int cmd_config_unset(int argc, const char **argv, const char *prefix)\n+static int cmd_config_unset(int argc, const char **argv, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tconst char *value_pattern = NULL;\n@@ -1010,7 +1014,8 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int cmd_config_rename_section(int argc, const char **argv, const char *prefix)\n+static int cmd_config_rename_section(int argc, const char **argv, const char *prefix,\n+\t\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct option opts[] = {\n@@ -1039,7 +1044,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr\n \treturn ret;\n }\n \n-static int cmd_config_remove_section(int argc, const char **argv, const char *prefix)\n+static int cmd_config_remove_section(int argc, const char **argv, const char *prefix,\n+\t\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct option opts[] = {\n@@ -1099,7 +1105,8 @@ static int show_editor(struct config_location_options *opts)\n \treturn 0;\n }\n \n-static int cmd_config_edit(int argc, const char **argv, const char *prefix)\n+static int cmd_config_edit(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct option opts[] = {\n@@ -1395,7 +1402,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)\n int cmd_config(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tparse_opt_subcommand_fn *subcommand = NULL;\n \tstruct option subcommand_opts[] = {\n@@ -1422,7 +1429,7 @@ int cmd_config(int argc,\n \tif (subcommand) {\n \t\targc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage,\n \t\t       PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\t\treturn subcommand(argc, argv, prefix);\n+\t\treturn subcommand(argc, argv, prefix, repo);\n \t}\n \n \treturn cmd_config_actions(argc, argv, prefix);\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 09802eb989471be242a4b2d74606b0998fdd2b11..50ccab172365d22c8f89e9f6fb822fca948878e7 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -1567,7 +1567,8 @@ static int task_option_parse(const struct option *opt UNUSED,\n \treturn 0;\n }\n \n-static int maintenance_run(int argc, const char **argv, const char *prefix)\n+static int maintenance_run(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint i;\n \tstruct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;\n@@ -1629,7 +1630,8 @@ static char const * const builtin_maintenance_register_usage[] = {\n \tNULL\n };\n \n-static int maintenance_register(int argc, const char **argv, const char *prefix)\n+static int maintenance_register(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tchar *config_file = NULL;\n \tstruct option options[] = {\n@@ -1693,7 +1695,8 @@ static char const * const builtin_maintenance_unregister_usage[] = {\n \tNULL\n };\n \n-static int maintenance_unregister(int argc, const char **argv, const char *prefix)\n+static int maintenance_unregister(int argc, const char **argv, const char *prefix,\n+\t\t\t\t  struct repository *repo UNUSED)\n {\n \tint force = 0;\n \tchar *config_file = NULL;\n@@ -2923,7 +2926,8 @@ static const char *const builtin_maintenance_start_usage[] = {\n \tNULL\n };\n \n-static int maintenance_start(int argc, const char **argv, const char *prefix)\n+static int maintenance_start(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo)\n {\n \tstruct maintenance_start_opts opts = { 0 };\n \tstruct option options[] = {\n@@ -2946,7 +2950,7 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)\n \tif (update_background_schedule(&opts, 1))\n \t\tdie(_(\"failed to set up maintenance schedule\"));\n \n-\tif (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL))\n+\tif (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL, repo))\n \t\twarning(_(\"failed to add repo to global config\"));\n \treturn 0;\n }\n@@ -2956,7 +2960,8 @@ static const char *const builtin_maintenance_stop_usage[] = {\n \tNULL\n };\n \n-static int maintenance_stop(int argc, const char **argv, const char *prefix)\n+static int maintenance_stop(int argc, const char **argv, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -2976,7 +2981,7 @@ static const char * const builtin_maintenance_usage[] = {\n int cmd_maintenance(int argc,\n \t\t    const char **argv,\n \t\t    const char *prefix,\n-\t\t    struct repository *repo UNUSED)\n+\t\t    struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_maintenance_options[] = {\n@@ -2990,5 +2995,5 @@ int cmd_maintenance(int argc,\n \n \targc = parse_options(argc, argv, prefix, builtin_maintenance_options,\n \t\t\t     builtin_maintenance_usage, 0);\n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/hook.c b/builtin/hook.c\nindex 367ef3e0b893fa16756880395151a82ed053acd8..672d2e37e845a2118aca1c4417a837138c250590 100644\n--- a/builtin/hook.c\n+++ b/builtin/hook.c\n@@ -19,7 +19,8 @@ static const char * const builtin_hook_run_usage[] = {\n \tNULL\n };\n \n-static int run(int argc, const char **argv, const char *prefix)\n+static int run(int argc, const char **argv, const char *prefix,\n+\t       struct repository *repo UNUSED)\n {\n \tint i;\n \tstruct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;\n@@ -70,7 +71,7 @@ static int run(int argc, const char **argv, const char *prefix)\n int cmd_hook(int argc,\n \t     const char **argv,\n \t     const char *prefix,\n-\t     struct repository *repo UNUSED)\n+\t     struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_hook_options[] = {\n@@ -81,5 +82,5 @@ int cmd_hook(int argc,\n \targc = parse_options(argc, argv, NULL, builtin_hook_options,\n \t\t\t     builtin_hook_usage, 0);\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex d159ed1314d912a390ed725659b3abe7c821b83f..85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -119,7 +119,8 @@ static void read_packs_from_stdin(struct string_list *to)\n }\n \n static int cmd_multi_pack_index_write(int argc, const char **argv,\n-\t\t\t\t      const char *prefix)\n+\t\t\t\t      const char *prefix,\n+\t\t\t\t      struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_write_options[] = {\n@@ -183,7 +184,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n }\n \n static int cmd_multi_pack_index_verify(int argc, const char **argv,\n-\t\t\t\t       const char *prefix)\n+\t\t\t\t       const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_verify_options[] = {\n@@ -210,7 +212,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n }\n \n static int cmd_multi_pack_index_expire(int argc, const char **argv,\n-\t\t\t\t       const char *prefix)\n+\t\t\t\t       const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_expire_options[] = {\n@@ -237,7 +240,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n }\n \n static int cmd_multi_pack_index_repack(int argc, const char **argv,\n-\t\t\t\t       const char *prefix)\n+\t\t\t\t       const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_repack_options[] = {\n@@ -271,7 +275,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n int cmd_multi_pack_index(int argc,\n \t\t\t const char **argv,\n \t\t\t const char *prefix,\n-\t\t\t struct repository *repo UNUSED)\n+\t\t\t struct repository *repo)\n {\n \tint res;\n \tparse_opt_subcommand_fn *fn = NULL;\n@@ -297,7 +301,7 @@ int cmd_multi_pack_index(int argc,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n \tFREE_AND_NULL(options);\n \n-\tres = fn(argc, argv, prefix);\n+\tres = fn(argc, argv, prefix, repo);\n \n \tfree(opts.object_dir);\n \treturn res;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 72c8a51cfacf72e1f115774487311b3d4464d204..d051abf6dff8f2bce193fd52b4beda5060af3972 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -431,7 +431,8 @@ static struct notes_tree *init_notes_check(const char *subcommand,\n \treturn t;\n }\n \n-static int list(int argc, const char **argv, const char *prefix)\n+static int list(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tstruct notes_tree *t;\n \tstruct object_id object;\n@@ -468,9 +469,11 @@ static int list(int argc, const char **argv, const char *prefix)\n \treturn retval;\n }\n \n-static int append_edit(int argc, const char **argv, const char *prefix);\n+static int append_edit(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED);\n \n-static int add(int argc, const char **argv, const char *prefix)\n+static int add(int argc, const char **argv, const char *prefix,\n+\t       struct repository *repo)\n {\n \tint force = 0, allow_empty = 0;\n \tconst char *object_ref;\n@@ -543,7 +546,7 @@ static int add(int argc, const char **argv, const char *prefix)\n \t\t\t * argv[0-1].\n \t\t\t */\n \t\t\targv[0] = \"edit\";\n-\t\t\treturn append_edit(argc, argv, prefix);\n+\t\t\treturn append_edit(argc, argv, prefix, repo);\n \t\t}\n \t\tfprintf(stderr, _(\"Overwriting existing notes for object %s\\n\"),\n \t\t\toid_to_hex(&object));\n@@ -569,7 +572,8 @@ static int add(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int copy(int argc, const char **argv, const char *prefix)\n+static int copy(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tint retval = 0, force = 0, from_stdin = 0;\n \tconst struct object_id *from_note, *note;\n@@ -646,7 +650,8 @@ static int copy(int argc, const char **argv, const char *prefix)\n \treturn retval;\n }\n \n-static int append_edit(int argc, const char **argv, const char *prefix)\n+static int append_edit(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tint allow_empty = 0;\n \tconst char *object_ref;\n@@ -749,7 +754,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int show(int argc, const char **argv, const char *prefix)\n+static int show(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tconst char *object_ref;\n \tstruct notes_tree *t;\n@@ -875,7 +881,8 @@ static int git_config_get_notes_strategy(const char *key,\n \treturn 0;\n }\n \n-static int merge(int argc, const char **argv, const char *prefix)\n+static int merge(int argc, const char **argv, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tstruct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;\n \tstruct object_id result_oid;\n@@ -1016,7 +1023,8 @@ static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag\n \treturn (flag & IGNORE_MISSING) ? 0 : status;\n }\n \n-static int remove_cmd(int argc, const char **argv, const char *prefix)\n+static int remove_cmd(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tunsigned flag = 0;\n \tint from_stdin = 0;\n@@ -1059,7 +1067,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n \treturn retval;\n }\n \n-static int prune(int argc, const char **argv, const char *prefix)\n+static int prune(int argc, const char **argv, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tstruct notes_tree *t;\n \tint show_only = 0, verbose = 0;\n@@ -1088,7 +1097,8 @@ static int prune(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int get_ref(int argc, const char **argv, const char *prefix)\n+static int get_ref(int argc, const char **argv, const char *prefix,\n+\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = { OPT_END() };\n \tchar *notes_ref;\n@@ -1109,7 +1119,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)\n int cmd_notes(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tconst char *override_notes_ref = NULL;\n \tparse_opt_subcommand_fn *fn = NULL;\n@@ -1148,5 +1158,5 @@ int cmd_notes(int argc,\n \t\tstrbuf_release(&sb);\n \t}\n \n-\treturn !!fn(argc, argv, prefix);\n+\treturn !!fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 22df6834f71098ab8378e4423967f0fb87858340..5a0c22f2f7e58733ce636619f3f19265b394bde5 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -234,7 +234,8 @@ static int expire_total_callback(const struct option *opt,\n \treturn 0;\n }\n \n-static int cmd_reflog_show(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_show(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -253,7 +254,8 @@ static int show_reflog(const char *refname, void *cb_data UNUSED)\n \treturn 0;\n }\n \n-static int cmd_reflog_list(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_list(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -270,7 +272,8 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix)\n \treturn refs_for_each_reflog(ref_store, show_reflog, NULL);\n }\n \n-static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct cmd_reflog_expire_cb cmd = { 0 };\n \ttimestamp_t now = time(NULL);\n@@ -394,7 +397,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)\n \treturn status;\n }\n \n-static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_delete(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint i, status = 0;\n \tunsigned int flags = 0;\n@@ -424,7 +428,8 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)\n \treturn status;\n }\n \n-static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_exists(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -467,7 +472,7 @@ int cmd_reflog(int argc,\n \t\t\t     PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (fn)\n-\t\treturn fn(argc - 1, argv + 1, prefix);\n+\t\treturn fn(argc - 1, argv + 1, prefix, repository);\n \telse\n \t\treturn cmd_log_reflog(argc, argv, prefix, repository);\n }\ndiff --git a/builtin/refs.c b/builtin/refs.c\nindex 24978a7b7b081ac6ed8ca99016f201d34c0639f8..3502980d21d055d8fc5ef36d2165aae61bc4db62 100644\n--- a/builtin/refs.c\n+++ b/builtin/refs.c\n@@ -12,7 +12,8 @@\n #define REFS_VERIFY_USAGE \\\n \tN_(\"git refs verify [--strict] [--verbose]\")\n \n-static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)\n+static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tconst char * const migrate_usage[] = {\n \t\tREFS_MIGRATE_USAGE,\n@@ -63,7 +64,8 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)\n \treturn err;\n }\n \n-static int cmd_refs_verify(int argc, const char **argv, const char *prefix)\n+static int cmd_refs_verify(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT;\n \tconst char * const verify_usage[] = {\n@@ -93,7 +95,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)\n int cmd_refs(int argc,\n \t     const char **argv,\n \t     const char *prefix,\n-\t     struct repository *repo UNUSED)\n+\t     struct repository *repo)\n {\n \tconst char * const refs_usage[] = {\n \t\tREFS_MIGRATE_USAGE,\n@@ -108,5 +110,5 @@ int cmd_refs(int argc,\n \t};\n \n \targc = parse_options(argc, argv, prefix, opts, refs_usage, 0);\n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 76670ddd8b44e5b118c76522613c445ad92c5364..56214775df4ce86bf5d8e4ddb8d19140f696aeef 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -155,7 +155,8 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not)\n \treturn 0;\n }\n \n-static int add(int argc, const char **argv, const char *prefix)\n+static int add(int argc, const char **argv, const char *prefix,\n+\t       struct repository *repo UNUSED)\n {\n \tint fetch = 0, fetch_tags = TAGS_DEFAULT;\n \tunsigned mirror = MIRROR_NONE;\n@@ -706,7 +707,8 @@ static void handle_push_default(const char* old_name, const char* new_name)\n }\n \n \n-static int mv(int argc, const char **argv, const char *prefix)\n+static int mv(int argc, const char **argv, const char *prefix,\n+\t      struct repository *repo UNUSED)\n {\n \tint show_progress = isatty(2);\n \tstruct option options[] = {\n@@ -881,7 +883,8 @@ static int mv(int argc, const char **argv, const char *prefix)\n \treturn result;\n }\n \n-static int rm(int argc, const char **argv, const char *prefix)\n+static int rm(int argc, const char **argv, const char *prefix,\n+\t      struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -1303,7 +1306,8 @@ static int show_all(void)\n \treturn result;\n }\n \n-static int show(int argc, const char **argv, const char *prefix)\n+static int show(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tint no_query = 0, result = 0, query_flag = 0;\n \tstruct option options[] = {\n@@ -1399,7 +1403,8 @@ static int show(int argc, const char **argv, const char *prefix)\n \treturn result;\n }\n \n-static int set_head(int argc, const char **argv, const char *prefix)\n+static int set_head(int argc, const char **argv, const char *prefix,\n+\t\t    struct repository *repo UNUSED)\n {\n \tint i, opt_a = 0, opt_d = 0, result = 0;\n \tstruct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;\n@@ -1503,7 +1508,8 @@ static int prune_remote(const char *remote, int dry_run)\n \treturn result;\n }\n \n-static int prune(int argc, const char **argv, const char *prefix)\n+static int prune(int argc, const char **argv, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tint dry_run = 0, result = 0;\n \tstruct option options[] = {\n@@ -1534,7 +1540,8 @@ static int get_remote_default(const char *key, const char *value UNUSED,\n \treturn 0;\n }\n \n-static int update(int argc, const char **argv, const char *prefix)\n+static int update(int argc, const char **argv, const char *prefix,\n+\t\t  struct repository *repo UNUSED)\n {\n \tint i, prune = -1;\n \tstruct option options[] = {\n@@ -1616,7 +1623,8 @@ static int set_remote_branches(const char *remotename, const char **branches,\n \treturn 0;\n }\n \n-static int set_branches(int argc, const char **argv, const char *prefix)\n+static int set_branches(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint add_mode = 0;\n \tstruct option options[] = {\n@@ -1635,7 +1643,8 @@ static int set_branches(int argc, const char **argv, const char *prefix)\n \treturn set_remote_branches(argv[0], argv + 1, add_mode);\n }\n \n-static int get_url(int argc, const char **argv, const char *prefix)\n+static int get_url(int argc, const char **argv, const char *prefix,\n+\t\t   struct repository *repo UNUSED)\n {\n \tint i, push_mode = 0, all_mode = 0;\n \tconst char *remotename = NULL;\n@@ -1674,7 +1683,8 @@ static int get_url(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int set_url(int argc, const char **argv, const char *prefix)\n+static int set_url(int argc, const char **argv, const char *prefix,\n+\t\t   struct repository *repo UNUSED)\n {\n \tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n \tint matches = 0, negative_matches = 0;\n@@ -1765,7 +1775,7 @@ static int set_url(int argc, const char **argv, const char *prefix)\n int cmd_remote(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n@@ -1788,7 +1798,7 @@ int cmd_remote(int argc,\n \t\t\t     PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \n \tif (fn) {\n-\t\treturn !!fn(argc, argv, prefix);\n+\t\treturn !!fn(argc, argv, prefix, repo);\n \t} else {\n \t\tif (argc) {\n \t\t\terror(_(\"unknown subcommand: `%s'\"), argv[0]);\ndiff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\nindex 49aedc1de81a17b8b491cded7fa71b384e0e8be9..6f5fa5893b839fe21fef44ecbd837d132ebbac26 100644\n--- a/builtin/sparse-checkout.c\n+++ b/builtin/sparse-checkout.c\n@@ -48,7 +48,8 @@ static char const * const builtin_sparse_checkout_list_usage[] = {\n \tNULL\n };\n \n-static int sparse_checkout_list(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_list(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_list_options[] = {\n \t\tOPT_END(),\n@@ -443,7 +444,8 @@ static struct sparse_checkout_init_opts {\n \tint sparse_index;\n } init_opts;\n \n-static int sparse_checkout_init(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_init(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tstruct pattern_list pl;\n \tchar *sparse_filename;\n@@ -770,7 +772,8 @@ static struct sparse_checkout_add_opts {\n \tint use_stdin;\n } add_opts;\n \n-static int sparse_checkout_add(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_add(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_add_options[] = {\n \t\tOPT_BOOL_F(0, \"skip-checks\", &add_opts.skip_checks,\n@@ -808,7 +811,8 @@ static struct sparse_checkout_set_opts {\n \tint use_stdin;\n } set_opts;\n \n-static int sparse_checkout_set(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_set(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED)\n {\n \tint default_patterns_nr = 2;\n \tconst char *default_patterns[] = {\"/*\", \"!/*/\", NULL};\n@@ -866,7 +870,8 @@ static struct sparse_checkout_reapply_opts {\n } reapply_opts;\n \n static int sparse_checkout_reapply(int argc, const char **argv,\n-\t\t\t\t   const char *prefix)\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_reapply_options[] = {\n \t\tOPT_BOOL(0, \"cone\", &reapply_opts.cone_mode,\n@@ -901,7 +906,8 @@ static char const * const builtin_sparse_checkout_disable_usage[] = {\n };\n \n static int sparse_checkout_disable(int argc, const char **argv,\n-\t\t\t\t   const char *prefix)\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_disable_options[] = {\n \t\tOPT_END(),\n@@ -989,7 +995,8 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {\n \treturn 0;\n }\n \n-static int sparse_checkout_check_rules(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_check_rules(int argc, const char **argv, const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_check_rules_options[] = {\n \t\tOPT_BOOL('z', NULL, &check_rules_opts.null_termination,\n@@ -1037,7 +1044,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *\n int cmd_sparse_checkout(int argc,\n \t\t\tconst char **argv,\n \t\t\tconst char *prefix,\n-\t\t\tstruct repository *repo UNUSED)\n+\t\t\tstruct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_sparse_checkout_options[] = {\n@@ -1060,5 +1067,5 @@ int cmd_sparse_checkout(int argc,\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex 1399a1bbe2c222ed3e1c33ac2dd17bd1148f709c..c212b1c0b2c7c55de2fdd5d7d7a247ce6f530960 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -249,7 +249,8 @@ static int do_clear_stash(void)\n \t\t\t       ref_stash, &obj, 0);\n }\n \n-static int clear_stash(int argc, const char **argv, const char *prefix)\n+static int clear_stash(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -652,7 +653,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,\n \treturn ret;\n }\n \n-static int apply_stash(int argc, const char **argv, const char *prefix)\n+static int apply_stash(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tint quiet = 0;\n@@ -726,7 +728,8 @@ static int get_stash_info_assert(struct stash_info *info, int argc,\n \treturn 0;\n }\n \n-static int drop_stash(int argc, const char **argv, const char *prefix)\n+static int drop_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tint quiet = 0;\n@@ -748,7 +751,8 @@ static int drop_stash(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int pop_stash(int argc, const char **argv, const char *prefix)\n+static int pop_stash(int argc, const char **argv, const char *prefix,\n+\t\t     struct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tint index = 0;\n@@ -778,7 +782,8 @@ static int pop_stash(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int branch_stash(int argc, const char **argv, const char *prefix)\n+static int branch_stash(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tconst char *branch = NULL;\n@@ -816,7 +821,8 @@ static int branch_stash(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int list_stash(int argc, const char **argv, const char *prefix)\n+static int list_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \tstruct option options[] = {\n@@ -889,7 +895,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op\n \tdo_diff_cache(&info->b_commit, diff_opt);\n }\n \n-static int show_stash(int argc, const char **argv, const char *prefix)\n+static int show_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint i;\n \tint ret = -1;\n@@ -1017,7 +1024,8 @@ static int do_store_stash(const struct object_id *w_commit, const char *stash_ms\n \treturn 0;\n }\n \n-static int store_stash(int argc, const char **argv, const char *prefix)\n+static int store_stash(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tint quiet = 0;\n \tconst char *stash_msg = NULL;\n@@ -1491,7 +1499,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b\n \treturn ret;\n }\n \n-static int create_stash(int argc, const char **argv, const char *prefix UNUSED)\n+static int create_stash(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint ret;\n \tstruct strbuf stash_msg_buf = STRBUF_INIT;\n@@ -1827,12 +1836,14 @@ static int push_stash(int argc, const char **argv, const char *prefix,\n \treturn ret;\n }\n \n-static int push_stash_unassumed(int argc, const char **argv, const char *prefix)\n+static int push_stash_unassumed(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \treturn push_stash(argc, argv, prefix, 0);\n }\n \n-static int save_stash(int argc, const char **argv, const char *prefix)\n+static int save_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint keep_index = -1;\n \tint only_staged = 0;\n@@ -1878,7 +1889,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)\n int cmd_stash(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tpid_t pid = getpid();\n \tconst char *index_file;\n@@ -1916,9 +1927,9 @@ int cmd_stash(int argc,\n \t\t    (uintmax_t)pid);\n \n \tif (fn)\n-\t\treturn !!fn(argc, argv, prefix);\n+\t\treturn !!fn(argc, argv, prefix, repo);\n \telse if (!argc)\n-\t\treturn !!push_stash_unassumed(0, NULL, prefix);\n+\t\treturn !!push_stash_unassumed(0, NULL, prefix, repo);\n \n \t/* Assume 'stash push' */\n \tstrvec_push(&args, \"push\");\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex b6b5f1ebde7c2e4780af4097a0c4d6d838948aee..19e587838132f26e2e10dc4a9f93f7b1c78cd49d 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -399,7 +399,8 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,\n \tfree(displaypath);\n }\n \n-static int module_foreach(int argc, const char **argv, const char *prefix)\n+static int module_foreach(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct foreach_cb info = FOREACH_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -544,7 +545,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data\n \t\t       info->flags);\n }\n \n-static int module_init(int argc, const char **argv, const char *prefix)\n+static int module_init(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct init_cb info = INIT_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -738,7 +740,8 @@ static void status_submodule_cb(const struct cache_entry *list_item,\n \t\t\t info->prefix, info->super_prefix, info->flags);\n }\n \n-static int module_status(int argc, const char **argv, const char *prefix)\n+static int module_status(int argc, const char **argv, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tstruct status_cb info = STATUS_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -1163,7 +1166,8 @@ static int compute_summary_module_list(struct object_id *head_oid,\n \treturn ret;\n }\n \n-static int module_summary(int argc, const char **argv, const char *prefix)\n+static int module_summary(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct summary_cb info = SUMMARY_CB_INIT;\n \tint cached = 0;\n@@ -1339,7 +1343,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data\n \t\t       info->flags);\n }\n \n-static int module_sync(int argc, const char **argv, const char *prefix)\n+static int module_sync(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct sync_cb info = SYNC_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -1485,7 +1490,8 @@ static void deinit_submodule_cb(const struct cache_entry *list_item,\n \tdeinit_submodule(list_item->name, info->prefix, info->flags);\n }\n \n-static int module_deinit(int argc, const char **argv, const char *prefix)\n+static int module_deinit(int argc, const char **argv, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tstruct deinit_cb info = DEINIT_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -1842,7 +1848,8 @@ static int clone_submodule(const struct module_clone_data *clone_data,\n \treturn 0;\n }\n \n-static int module_clone(int argc, const char **argv, const char *prefix)\n+static int module_clone(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint dissociate = 0, quiet = 0, progress = 0, require_init = 0;\n \tstruct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;\n@@ -2779,7 +2786,8 @@ static int update_submodules(struct update_data *update_data)\n \treturn ret;\n }\n \n-static int module_update(int argc, const char **argv, const char *prefix)\n+static int module_update(int argc, const char **argv, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tstruct pathspec pathspec = { 0 };\n \tstruct pathspec pathspec2 = { 0 };\n@@ -2911,7 +2919,8 @@ static int module_update(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int push_check(int argc, const char **argv, const char *prefix UNUSED)\n+static int push_check(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t      struct repository *repo UNUSED)\n {\n \tstruct remote *remote;\n \tconst char *superproject_head;\n@@ -2991,7 +3000,8 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED)\n \treturn 0;\n }\n \n-static int absorb_git_dirs(int argc, const char **argv, const char *prefix)\n+static int absorb_git_dirs(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint i;\n \tstruct pathspec pathspec = { 0 };\n@@ -3024,7 +3034,8 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int module_set_url(int argc, const char **argv, const char *prefix)\n+static int module_set_url(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tint quiet = 0, ret;\n \tconst char *newurl;\n@@ -3063,7 +3074,8 @@ static int module_set_url(int argc, const char **argv, const char *prefix)\n \treturn !!ret;\n }\n \n-static int module_set_branch(int argc, const char **argv, const char *prefix)\n+static int module_set_branch(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint opt_default = 0, ret;\n \tconst char *opt_branch = NULL;\n@@ -3113,7 +3125,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)\n \treturn !!ret;\n }\n \n-static int module_create_branch(int argc, const char **argv, const char *prefix)\n+static int module_create_branch(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tenum branch_track track;\n \tint quiet = 0, force = 0, reflog = 0, dry_run = 0;\n@@ -3424,7 +3437,8 @@ static void die_on_repo_without_commits(const char *path)\n \tstrbuf_release(&sb);\n }\n \n-static int module_add(int argc, const char **argv, const char *prefix)\n+static int module_add(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint force = 0, quiet = 0, progress = 0, dissociate = 0;\n \tstruct add_data add_data = ADD_DATA_INIT;\n@@ -3557,7 +3571,7 @@ static int module_add(int argc, const char **argv, const char *prefix)\n int cmd_submodule__helper(int argc,\n \t\t\t  const char **argv,\n \t\t\t  const char *prefix,\n-\t\t\t  struct repository *repo UNUSED)\n+\t\t\t  struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tconst char *const usage[] = {\n@@ -3583,5 +3597,5 @@ int cmd_submodule__helper(int argc,\n \t};\n \targc = parse_options(argc, argv, prefix, options, usage, 0);\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex dae63dedf4cac2621f51f95a39aa456b33acd894..824dd71d643f112f384cde4de1373698c67de254 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -231,7 +231,8 @@ static void prune_worktrees(void)\n \tstrbuf_release(&reason);\n }\n \n-static int prune(int ac, const char **av, const char *prefix)\n+static int prune(int ac, const char **av, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT__DRY_RUN(&show_only, N_(\"do not remove, show only\")),\n@@ -763,7 +764,8 @@ static char *dwim_branch(const char *path, char **new_branch)\n \treturn NULL;\n }\n \n-static int add(int ac, const char **av, const char *prefix)\n+static int add(int ac, const char **av, const char *prefix,\n+\t       struct repository *repo UNUSED)\n {\n \tstruct add_opts opts;\n \tconst char *new_branch_force = NULL;\n@@ -1039,7 +1041,8 @@ static void pathsort(struct worktree **wt)\n \tQSORT(wt, n, pathcmp);\n }\n \n-static int list(int ac, const char **av, const char *prefix)\n+static int list(int ac, const char **av, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tint porcelain = 0;\n \tint line_terminator = '\\n';\n@@ -1084,7 +1087,8 @@ static int list(int ac, const char **av, const char *prefix)\n \treturn 0;\n }\n \n-static int lock_worktree(int ac, const char **av, const char *prefix)\n+static int lock_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tconst char *reason = \"\", *old_reason;\n \tstruct option options[] = {\n@@ -1119,7 +1123,8 @@ static int lock_worktree(int ac, const char **av, const char *prefix)\n \treturn 0;\n }\n \n-static int unlock_worktree(int ac, const char **av, const char *prefix)\n+static int unlock_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -1182,7 +1187,8 @@ static void validate_no_submodules(const struct worktree *wt)\n \t\tdie(_(\"working trees containing submodules cannot be moved or removed\"));\n }\n \n-static int move_worktree(int ac, const char **av, const char *prefix)\n+static int move_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tint force = 0;\n \tstruct option options[] = {\n@@ -1312,7 +1318,8 @@ static int delete_git_work_tree(struct worktree *wt)\n \treturn ret;\n }\n \n-static int remove_worktree(int ac, const char **av, const char *prefix)\n+static int remove_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint force = 0;\n \tstruct option options[] = {\n@@ -1377,7 +1384,8 @@ static void report_repair(int iserr, const char *path, const char *msg, void *cb\n \t}\n }\n \n-static int repair(int ac, const char **av, const char *prefix)\n+static int repair(int ac, const char **av, const char *prefix,\n+\t\t  struct repository *repo UNUSED)\n {\n \tconst char **p;\n \tconst char *self[] = { \".\", NULL };\n@@ -1397,7 +1405,7 @@ static int repair(int ac, const char **av, const char *prefix)\n int cmd_worktree(int ac,\n \t\t const char **av,\n \t\t const char *prefix,\n-\t\t struct repository *repo UNUSED)\n+\t\t struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n@@ -1422,5 +1430,5 @@ int cmd_worktree(int ac,\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\treturn fn(ac, av, prefix);\n+\treturn fn(ac, av, prefix, repo);\n }\ndiff --git a/parse-options.h b/parse-options.h\nindex ae15342390837c21503ab812648a7d8fd21432a8..f0801d4532a175b65783689f2a68fb56da2c8e87 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -3,6 +3,8 @@\n \n #include \"gettext.h\"\n \n+struct repository;\n+\n /**\n  * Refer to Documentation/technical/api-parse-options.txt for the API doc.\n  */\n@@ -73,7 +75,7 @@ typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t      const char *arg, int unset);\n \n typedef int parse_opt_subcommand_fn(int argc, const char **argv,\n-\t\t\t\t    const char *prefix);\n+\t\t\t\t    const char *prefix, struct repository *repo);\n \n /*\n  * `type`::\ndiff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c\nindex 5250913d99eba18a28878d3904cb7b2399670d02..e5b1fe287e3ec94f0d8a3a99adb68842d52992f6 100644\n--- a/t/helper/test-parse-options.c\n+++ b/t/helper/test-parse-options.c\n@@ -1,8 +1,11 @@\n+#define USE_THE_REPOSITORY_VARIABLE\n+\n #include \"test-tool.h\"\n #include \"parse-options.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n #include \"trace2.h\"\n+#include \"repository.h\"\n \n static int boolean = 0;\n static int integer = 0;\n@@ -282,14 +285,16 @@ int cmd__parse_options_flags(int argc, const char **argv)\n \treturn parse_options_flags__cmd(argc, argv, test_flags);\n }\n \n-static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED)\n+static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t      struct repository *repo UNUSED)\n {\n \tprintf(\"fn: subcmd_one\\n\");\n \tprint_args(argc, argv);\n \treturn 0;\n }\n \n-static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED)\n+static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t      struct repository *repo UNUSED)\n {\n \tprintf(\"fn: subcmd_two\\n\");\n \tprint_args(argc, argv);\n@@ -319,7 +324,7 @@ static int parse_subcommand__cmd(int argc, const char **argv,\n \n \tprintf(\"opt: %d\\n\", opt);\n \n-\treturn fn(argc, argv, NULL);\n+\treturn fn(argc, argv, NULL, the_repository);\n }\n \n int cmd__parse_subcommand(int argc, const char **argv)\n\n-- \n2.47.0\n\n"},{"id":"507362","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-2-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 2/8] midx-write: add repository field to `write_midx_context`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:15Z","receivedAt":"2024-11-15T13:42:37Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The struct `write_midx_context` is used to pass context for creating\nMIDX files. Adding the repository field here ensures that most functions\nwithin `midx-write.c` have access to the field and can use that instead\nof the global `repository` variable. This involves passing the\n`repository` field to `write_midx_internal`. To do this, we add\n`the_repository` usage to two non-static functions, which we'll remove\nin upcoming commits.\n\nWith this, modify the static functions in `midx-write.c` to not use\nglobal variables. This means, either we use existing alternatives (like\n`repository` struct), or we pass down required fields from other\nfunctions.\n\nSigned-off-by: default avatarKarthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 97 ++++++++++++++++++++++++++++++++----------------------------\n 1 file changed, 52 insertions(+), 45 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex c57726ef9475df693890d61627ce91409c1def7c..a384f7ddc8a396d0cffd528132bb8fcdc6b37e24 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -35,13 +35,13 @@ extern void clear_incremental_midx_files_ext(const char *object_dir,\n extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,\n \t\t\t\tconst char *idx_name);\n \n-static size_t write_midx_header(struct hashfile *f,\n-\t\t\t\tunsigned char num_chunks,\n+static size_t write_midx_header(const struct git_hash_algo *hash_algo,\n+\t\t\t\tstruct hashfile *f, unsigned char num_chunks,\n \t\t\t\tuint32_t num_packs)\n {\n \thashwrite_be32(f, MIDX_SIGNATURE);\n \thashwrite_u8(f, MIDX_VERSION);\n-\thashwrite_u8(f, oid_version(the_hash_algo));\n+\thashwrite_u8(f, oid_version(hash_algo));\n \thashwrite_u8(f, num_chunks);\n \thashwrite_u8(f, 0); /* unused */\n \thashwrite_be32(f, num_packs);\n@@ -110,6 +110,8 @@ struct write_midx_context {\n \tuint32_t num_multi_pack_indexes_before;\n \n \tstruct string_list *to_include;\n+\n+\tstruct repository *repo;\n };\n \n static int should_include_pack(const struct write_midx_context *ctx,\n@@ -154,7 +156,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,\n \t\t\treturn;\n \n \t\tALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);\n-\t\tp = add_packed_git(the_repository, full_path, full_path_len, 0);\n+\t\tp = add_packed_git(ctx->repo, full_path, full_path_len, 0);\n \t\tif (!p) {\n \t\t\twarning(_(\"failed to add packfile '%s'\"),\n \t\t\t\tfull_path);\n@@ -480,7 +482,7 @@ static int write_midx_oid_lookup(struct hashfile *f,\n \t\t\t\t void *data)\n {\n \tstruct write_midx_context *ctx = data;\n-\tunsigned char hash_len = the_hash_algo->rawsz;\n+\tunsigned char hash_len = ctx->repo->hash_algo->rawsz;\n \tstruct pack_midx_entry *list = ctx->entries;\n \tuint32_t i;\n \n@@ -605,7 +607,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n \tuint32_t *pack_order, base_objects = 0;\n \tuint32_t i;\n \n-\ttrace2_region_enter(\"midx\", \"midx_pack_order\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"midx_pack_order\", ctx->repo);\n \n \tif (ctx->incremental && ctx->base_midx)\n \t\tbase_objects = ctx->base_midx->num_objects +\n@@ -640,7 +642,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n \t}\n \tfree(data);\n \n-\ttrace2_region_leave(\"midx\", \"midx_pack_order\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"midx_pack_order\", ctx->repo);\n \n \treturn pack_order;\n }\n@@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n \tstruct strbuf buf = STRBUF_INIT;\n \tchar *tmp_file;\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n \n-\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex(midx_hash));\n+\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex_algop(midx_hash,\n+\t\t\t\t\t\t\t\t    ctx->repo->hash_algo));\n \n \ttmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,\n \t\t\t\t\tmidx_hash, WRITE_REV);\n@@ -664,7 +667,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n \tstrbuf_release(&buf);\n \tfree(tmp_file);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n }\n \n static void prepare_midx_packing_data(struct packing_data *pdata,\n@@ -672,10 +675,10 @@ static void prepare_midx_packing_data(struct packing_data *pdata,\n {\n \tuint32_t i;\n \n-\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n \n \tmemset(pdata, 0, sizeof(struct packing_data));\n-\tprepare_packing_data(the_repository, pdata);\n+\tprepare_packing_data(ctx->repo, pdata);\n \n \tfor (i = 0; i < ctx->entries_nr; i++) {\n \t\tuint32_t pos = ctx->pack_order[i];\n@@ -686,7 +689,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata,\n \t\t\t       ctx->info[ctx->pack_perm[from->pack_int_id]].p);\n \t}\n \n-\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n }\n \n static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n@@ -702,7 +705,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n \t\treturn 0;\n \t}\n \n-\tif (!peel_iterated_oid(the_repository, oid, &peeled))\n+\tif (!peel_iterated_oid(revs->repo, oid, &peeled))\n \t\toid = &peeled;\n \n \tobject = parse_object_or_die(oid, refname);\n@@ -760,7 +763,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n \t\t\thex = &buf.buf[1];\n \t\t}\n \n-\t\tif (parse_oid_hex(hex, &oid, &end) < 0)\n+\t\tif (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0)\n \t\t\tdie(_(\"could not parse line: %s\"), buf.buf);\n \t\tif (*end)\n \t\t\tdie(_(\"malformed line: %s\"), buf.buf);\n@@ -783,17 +786,16 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \tstruct rev_info revs;\n \tstruct bitmap_commit_cb cb = {0};\n \n-\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\",\n-\t\t\t    the_repository);\n+\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n \n \tcb.ctx = ctx;\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(ctx->repo, &revs, NULL);\n \tif (refs_snapshot) {\n \t\tread_refs_snapshot(refs_snapshot, &revs);\n \t} else {\n \t\tsetup_revisions(0, NULL, &revs, NULL);\n-\t\trefs_for_each_ref(get_main_ref_store(the_repository),\n+\t\trefs_for_each_ref(get_main_ref_store(ctx->repo),\n \t\t\t\t  add_ref_to_pending, &revs);\n \t}\n \n@@ -821,13 +823,12 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \n \trelease_revisions(&revs);\n \n-\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\",\n-\t\t\t    the_repository);\n+\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n \n \treturn cb.commits;\n }\n \n-static int write_midx_bitmap(const char *midx_name,\n+static int write_midx_bitmap(struct repository *r, const char *midx_name,\n \t\t\t     const unsigned char *midx_hash,\n \t\t\t     struct packing_data *pdata,\n \t\t\t     struct commit **commits,\n@@ -840,9 +841,9 @@ static int write_midx_bitmap(const char *midx_name,\n \tstruct bitmap_writer writer;\n \tstruct pack_idx_entry **index;\n \tchar *bitmap_name = xstrfmt(\"%s-%s.bitmap\", midx_name,\n-\t\t\t\t\thash_to_hex(midx_hash));\n+\t\t\t\t    hash_to_hex_algop(midx_hash, r->hash_algo));\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_bitmap\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_bitmap\", r);\n \n \tif (flags & MIDX_WRITE_BITMAP_HASH_CACHE)\n \t\toptions |= BITMAP_OPT_HASH_CACHE;\n@@ -859,7 +860,7 @@ static int write_midx_bitmap(const char *midx_name,\n \tfor (i = 0; i < pdata->nr_objects; i++)\n \t\tindex[i] = &pdata->objects[i].idx;\n \n-\tbitmap_writer_init(&writer, the_repository, pdata);\n+\tbitmap_writer_init(&writer, r, pdata);\n \tbitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);\n \tbitmap_writer_build_type_index(&writer, index);\n \n@@ -892,7 +893,7 @@ static int write_midx_bitmap(const char *midx_name,\n \tfree(bitmap_name);\n \tbitmap_writer_free(&writer);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_bitmap\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_bitmap\", r);\n \n \treturn ret;\n }\n@@ -944,7 +945,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,\n \t\t\t */\n \t\t\tif (flags & MIDX_WRITE_REV_INDEX ||\n \t\t\t    preferred_pack_name) {\n-\t\t\t\tif (prepare_midx_pack(the_repository, m,\n+\t\t\t\tif (prepare_midx_pack(ctx->repo, m,\n \t\t\t\t\t\t      m->num_packs_in_base + i)) {\n \t\t\t\t\terror(_(\"could not load pack\"));\n \t\t\t\t\treturn 1;\n@@ -1049,7 +1050,7 @@ static void clear_midx_files(const char *object_dir,\n \tstrbuf_release(&buf);\n }\n \n-static int write_midx_internal(const char *object_dir,\n+static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\t\t       struct string_list *packs_to_include,\n \t\t\t       struct string_list *packs_to_drop,\n \t\t\t       const char *preferred_pack_name,\n@@ -1070,7 +1071,9 @@ static int write_midx_internal(const char *object_dir,\n \tconst char **keep_hashes = NULL;\n \tstruct chunkfile *cf;\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_internal\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_internal\", r);\n+\n+\tctx.repo = r;\n \n \tctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);\n \tif (ctx.incremental && (flags & MIDX_WRITE_BITMAP))\n@@ -1087,8 +1090,7 @@ static int write_midx_internal(const char *object_dir,\n \t\t\t  midx_name.buf);\n \n \tif (!packs_to_include || ctx.incremental) {\n-\t\tstruct multi_pack_index *m = lookup_multi_pack_index(the_repository,\n-\t\t\t\t\t\t\t\t     object_dir);\n+\t\tstruct multi_pack_index *m = lookup_multi_pack_index(r, object_dir);\n \t\tif (m && !midx_checksum_valid(m)) {\n \t\t\twarning(_(\"ignoring existing multi-pack-index; checksum mismatch\"));\n \t\t\tm = NULL;\n@@ -1351,7 +1353,7 @@ static int write_midx_internal(const char *object_dir,\n \tadd_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE,\n \t\t  write_midx_oid_fanout);\n \tadd_chunk(cf, MIDX_CHUNKID_OIDLOOKUP,\n-\t\t  st_mult(ctx.entries_nr, the_hash_algo->rawsz),\n+\t\t  st_mult(ctx.entries_nr, r->hash_algo->rawsz),\n \t\t  write_midx_oid_lookup);\n \tadd_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS,\n \t\t  st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH),\n@@ -1373,7 +1375,8 @@ static int write_midx_internal(const char *object_dir,\n \t\t\t  write_midx_bitmapped_packs);\n \t}\n \n-\twrite_midx_header(f, get_num_chunks(cf), ctx.nr - dropped_packs);\n+\twrite_midx_header(r->hash_algo, f, get_num_chunks(cf),\n+\t\t\t  ctx.nr - dropped_packs);\n \twrite_chunkfile(cf, &ctx);\n \n \tfinalize_hashfile(f, midx_hash, FSYNC_COMPONENT_PACK_METADATA,\n@@ -1405,7 +1408,7 @@ static int write_midx_internal(const char *object_dir,\n \t\tFREE_AND_NULL(ctx.entries);\n \t\tctx.entries_nr = 0;\n \n-\t\tif (write_midx_bitmap(midx_name.buf, midx_hash, &pdata,\n+\t\tif (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,\n \t\t\t\t      commits, commits_nr, ctx.pack_order,\n \t\t\t\t      flags) < 0) {\n \t\t\terror(_(\"could not write multi-pack bitmap\"));\n@@ -1449,12 +1452,13 @@ static int write_midx_internal(const char *object_dir,\n \t\tstrbuf_release(&final_midx_name);\n \n \t\tkeep_hashes[ctx.num_multi_pack_indexes_before] =\n-\t\t\txstrdup(hash_to_hex(midx_hash));\n+\t\t\txstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));\n \n \t\tfor (i = 0; i < ctx.num_multi_pack_indexes_before; i++) {\n \t\t\tuint32_t j = ctx.num_multi_pack_indexes_before - i - 1;\n \n-\t\t\tkeep_hashes[j] = xstrdup(hash_to_hex(get_midx_checksum(m)));\n+\t\t\tkeep_hashes[j] = xstrdup(hash_to_hex_algop(get_midx_checksum(m),\n+\t\t\t\t\t\t\t\t   r->hash_algo));\n \t\t\tm = m->base_midx;\n \t\t}\n \n@@ -1462,11 +1466,11 @@ static int write_midx_internal(const char *object_dir,\n \t\t\tfprintf(get_lock_file_fp(&lk), \"%s\\n\", keep_hashes[i]);\n \t} else {\n \t\tkeep_hashes[ctx.num_multi_pack_indexes_before] =\n-\t\t\txstrdup(hash_to_hex(midx_hash));\n+\t\t\txstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));\n \t}\n \n \tif (ctx.m || ctx.base_midx)\n-\t\tclose_object_store(the_repository->objects);\n+\t\tclose_object_store(ctx.repo->objects);\n \n \tif (commit_lock_file(&lk) < 0)\n \t\tdie_errno(_(\"could not write multi-pack-index\"));\n@@ -1495,7 +1499,7 @@ static int write_midx_internal(const char *object_dir,\n \t}\n \tstrbuf_release(&midx_name);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_internal\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_internal\", r);\n \n \treturn result;\n }\n@@ -1505,8 +1509,8 @@ int write_midx_file(const char *object_dir,\n \t\t    const char *refs_snapshot,\n \t\t    unsigned flags)\n {\n-\treturn write_midx_internal(object_dir, NULL, NULL, preferred_pack_name,\n-\t\t\t\t   refs_snapshot, flags);\n+\treturn write_midx_internal(the_repository, object_dir, NULL, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n }\n \n int write_midx_file_only(const char *object_dir,\n@@ -1515,8 +1519,9 @@ int write_midx_file_only(const char *object_dir,\n \t\t\t const char *refs_snapshot,\n \t\t\t unsigned flags)\n {\n-\treturn write_midx_internal(object_dir, packs_to_include, NULL,\n-\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n+\treturn write_midx_internal(the_repository, object_dir, packs_to_include,\n+\t\t\t\t   NULL, preferred_pack_name, refs_snapshot,\n+\t\t\t\t   flags);\n }\n \n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)\n@@ -1572,7 +1577,8 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla\n \tfree(count);\n \n \tif (packs_to_drop.nr)\n-\t\tresult = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags);\n+\t\tresult = write_midx_internal(r, object_dir, NULL,\n+\t\t\t\t\t     &packs_to_drop, NULL, NULL, flags);\n \n \tstring_list_clear(&packs_to_drop, 0);\n \n@@ -1769,7 +1775,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,\n \t\tgoto cleanup;\n \t}\n \n-\tresult = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags);\n+\tresult = write_midx_internal(r, object_dir, NULL, NULL, NULL, NULL,\n+\t\t\t\t     flags);\n \n cleanup:\n \tfree(include_pack);\n\n-- \n2.47.0\n\n"},{"id":"507364","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-3-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 3/8] midx-write: pass down repository to `write_midx_file[_only]`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:16Z","receivedAt":"2024-11-15T13:42:37Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In the previous commit, we passed the repository field to all\nsubcommands in the `builtin/` directory. We utilize this to pass the\nrepository field down to the `write_midx_file[_only]` functions to\nremove the usage of `the_repository` global variables.\n\nWith this, we remove all usage of global variables in `midx-write.c` and\nso we can remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/multi-pack-index.c |  6 +++---\n builtin/repack.c           |  2 +-\n midx-write.c               | 22 +++++++++-------------\n midx.h                     | 10 ++++------\n 4 files changed, 17 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0..2a938466f53aaa11096170554fe11a4ed46a25e4 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to)\n \n static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n-\t\t\t\t      struct repository *repo UNUSED)\n+\t\t\t\t      struct repository *repo)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_write_options[] = {\n@@ -165,7 +165,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t\tread_packs_from_stdin(&packs);\n \n-\t\tret = write_midx_file_only(opts.object_dir, &packs,\n+\t\tret = write_midx_file_only(repo, opts.object_dir, &packs,\n \t\t\t\t\t   opts.preferred_pack,\n \t\t\t\t\t   opts.refs_snapshot, opts.flags);\n \n@@ -176,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t}\n \n-\tret = write_midx_file(opts.object_dir, opts.preferred_pack,\n+\tret = write_midx_file(repo, opts.object_dir, opts.preferred_pack,\n \t\t\t      opts.refs_snapshot, opts.flags);\n \n \tfree(opts.refs_snapshot);\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 96a4fa234bddfd2b63c8d9733379d9b1012a4014..9c21fc482dfb387c818c0d0a74f781848b5a0953 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1569,7 +1569,7 @@ int cmd_repack(int argc,\n \t\tunsigned flags = 0;\n \t\tif (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))\n \t\t\tflags |= MIDX_WRITE_INCREMENTAL;\n-\t\twrite_midx_file(repo_get_object_directory(the_repository),\n+\t\twrite_midx_file(the_repository, repo_get_object_directory(the_repository),\n \t\t\t\tNULL, NULL, flags);\n \t}\n \ndiff --git a/midx-write.c b/midx-write.c\nindex a384f7ddc8a396d0cffd528132bb8fcdc6b37e24..5af29899bbe279c7c3ff4bc2c65330620ce37ee2 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -1504,24 +1502,22 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \treturn result;\n }\n \n-int write_midx_file(const char *object_dir,\n+int write_midx_file(struct repository *r, const char *object_dir,\n \t\t    const char *preferred_pack_name,\n-\t\t    const char *refs_snapshot,\n-\t\t    unsigned flags)\n+\t\t    const char *refs_snapshot, unsigned flags)\n {\n-\treturn write_midx_internal(the_repository, object_dir, NULL, NULL,\n-\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n+\treturn write_midx_internal(r, object_dir, NULL, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot,\n+\t\t\t\t   flags);\n }\n \n-int write_midx_file_only(const char *object_dir,\n+int write_midx_file_only(struct repository *r, const char *object_dir,\n \t\t\t struct string_list *packs_to_include,\n \t\t\t const char *preferred_pack_name,\n-\t\t\t const char *refs_snapshot,\n-\t\t\t unsigned flags)\n+\t\t\t const char *refs_snapshot, unsigned flags)\n {\n-\treturn write_midx_internal(the_repository, object_dir, packs_to_include,\n-\t\t\t\t   NULL, preferred_pack_name, refs_snapshot,\n-\t\t\t\t   flags);\n+\treturn write_midx_internal(r, object_dir, packs_to_include, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n }\n \n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)\ndiff --git a/midx.h b/midx.h\nindex 3b0ac4d8788b373c59fe69ca2d78e9d914702bc0..c37ad5b5242b56d21fd76bd59957a1bdb82786ec 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -123,15 +123,13 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i\n  * Variant of write_midx_file which writes a MIDX containing only the packs\n  * specified in packs_to_include.\n  */\n-int write_midx_file(const char *object_dir,\n-\t\t    const char *preferred_pack_name,\n-\t\t    const char *refs_snapshot,\n+int write_midx_file(struct repository *r, const char *object_dir,\n+\t\t    const char *preferred_pack_name, const char *refs_snapshot,\n \t\t    unsigned flags);\n-int write_midx_file_only(const char *object_dir,\n+int write_midx_file_only(struct repository *r, const char *object_dir,\n \t\t\t struct string_list *packs_to_include,\n \t\t\t const char *preferred_pack_name,\n-\t\t\t const char *refs_snapshot,\n-\t\t\t unsigned flags);\n+\t\t\t const char *refs_snapshot, unsigned flags);\n void clear_midx_file(struct repository *r);\n int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);\n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);\n\n-- \n2.47.0\n\n"},{"id":"507365","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-4-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 4/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:17Z","receivedAt":"2024-11-15T13:42:38Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In the `midx.c` file, there are multiple usages of `the_repository` and\n`the_hash_algo` within static functions of the file. Some of the usages\ncan be simply swapped out with the available `repository` struct\navailable. While some of them can be swapped out by passing the\nrepository to the required functions.\n\nThis leaves out only some other usages of `the_repository` and\n`the_hash_algo` in the file in non-static functions, which we'll tackle\nin upcoming commits.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c | 49 +++++++++++++++++++++++++++----------------------\n 1 file changed, 27 insertions(+), 22 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 079c45a1aafb658a7b887ac216cc6ecf5f0fb6ff..6f0fb8285af14843da132ef1b0c3a8bdd06732c9 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -25,7 +25,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,\n \n const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n {\n-\treturn m->data + m->data_len - the_hash_algo->rawsz;\n+\treturn m->data + m->data_len - m->repo->hash_algo->rawsz;\n }\n \n void get_midx_filename(struct strbuf *out, const char *object_dir)\n@@ -94,7 +94,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,\n \n #define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n \n-static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir,\n+static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n+\t\t\t\t\t\t\t  const char *object_dir,\n \t\t\t\t\t\t\t  const char *midx_name,\n \t\t\t\t\t\t\t  int local)\n {\n@@ -131,7 +132,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \tm->data = midx_map;\n \tm->data_len = midx_size;\n \tm->local = local;\n-\tm->repo = the_repository;\n+\tm->repo = r;\n \n \tm->signature = get_be32(m->data);\n \tif (m->signature != MIDX_SIGNATURE)\n@@ -144,12 +145,12 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \t\t      m->version);\n \n \thash_version = m->data[MIDX_BYTE_HASH_VERSION];\n-\tif (hash_version != oid_version(the_hash_algo)) {\n+\tif (hash_version != oid_version(r->hash_algo)) {\n \t\terror(_(\"multi-pack-index hash version %u does not match version %u\"),\n-\t\t      hash_version, oid_version(the_hash_algo));\n+\t\t      hash_version, oid_version(r->hash_algo));\n \t\tgoto cleanup_fail;\n \t}\n-\tm->hash_len = the_hash_algo->rawsz;\n+\tm->hash_len = r->hash_algo->rawsz;\n \n \tm->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];\n \n@@ -206,8 +207,8 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \t\t\t      m->pack_names[i]);\n \t}\n \n-\ttrace2_data_intmax(\"midx\", the_repository, \"load/num_packs\", m->num_packs);\n-\ttrace2_data_intmax(\"midx\", the_repository, \"load/num_objects\", m->num_objects);\n+\ttrace2_data_intmax(\"midx\", r, \"load/num_packs\", m->num_packs);\n+\ttrace2_data_intmax(\"midx\", r, \"load/num_objects\", m->num_objects);\n \n \tfree_chunkfile(cf);\n \treturn m;\n@@ -240,8 +241,9 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n \tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n }\n \n-static int open_multi_pack_index_chain(const char *chain_file,\n-\t\t\t\t       int *fd, struct stat *st)\n+static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n+\t\t\t\t       const char *chain_file, int *fd,\n+\t\t\t\t       struct stat *st)\n {\n \t*fd = git_open(chain_file);\n \tif (*fd < 0)\n@@ -250,7 +252,7 @@ static int open_multi_pack_index_chain(const char *chain_file,\n \t\tclose(*fd);\n \t\treturn 0;\n \t}\n-\tif (st->st_size < the_hash_algo->hexsz) {\n+\tif (st->st_size < hash_algo->hexsz) {\n \t\tclose(*fd);\n \t\tif (!st->st_size) {\n \t\t\t/* treat empty files the same as missing */\n@@ -292,7 +294,8 @@ static int add_midx_to_chain(struct multi_pack_index *midx,\n \treturn 1;\n }\n \n-static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n+static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n+\t\t\t\t\t\t      const char *object_dir,\n \t\t\t\t\t\t      int local,\n \t\t\t\t\t\t      int fd, struct stat *st,\n \t\t\t\t\t\t      int *incomplete_chain)\n@@ -303,7 +306,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \tuint32_t i, count;\n \tFILE *fp = xfdopen(fd, \"r\");\n \n-\tcount = st->st_size / (the_hash_algo->hexsz + 1);\n+\tcount = st->st_size / (r->hash_algo->hexsz + 1);\n \n \tfor (i = 0; i < count; i++) {\n \t\tstruct multi_pack_index *m;\n@@ -312,7 +315,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tif (strbuf_getline_lf(&buf, fp) == EOF)\n \t\t\tbreak;\n \n-\t\tif (get_oid_hex(buf.buf, &layer)) {\n+\t\tif (get_oid_hex_algop(buf.buf, &layer, r->hash_algo)) {\n \t\t\twarning(_(\"invalid multi-pack-index chain: line '%s' \"\n \t\t\t\t  \"not a hash\"),\n \t\t\t\tbuf.buf);\n@@ -325,7 +328,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tstrbuf_reset(&buf);\n \t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n \t\t\t\t\t    MIDX_EXT_MIDX);\n-\t\tm = load_multi_pack_index_one(object_dir, buf.buf, local);\n+\t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n \n \t\tif (m) {\n \t\t\tif (add_midx_to_chain(m, midx_chain)) {\n@@ -348,7 +351,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \treturn midx_chain;\n }\n \n-static struct multi_pack_index *load_multi_pack_index_chain(const char *object_dir,\n+static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r,\n+\t\t\t\t\t\t\t    const char *object_dir,\n \t\t\t\t\t\t\t    int local)\n {\n \tstruct strbuf chain_file = STRBUF_INIT;\n@@ -357,10 +361,10 @@ static struct multi_pack_index *load_multi_pack_index_chain(const char *object_d\n \tstruct multi_pack_index *m = NULL;\n \n \tget_midx_chain_filename(&chain_file, object_dir);\n-\tif (open_multi_pack_index_chain(chain_file.buf, &fd, &st)) {\n+\tif (open_multi_pack_index_chain(r->hash_algo, chain_file.buf, &fd, &st)) {\n \t\tint incomplete;\n \t\t/* ownership of fd is taken over by load function */\n-\t\tm = load_midx_chain_fd_st(object_dir, local, fd, &st,\n+\t\tm = load_midx_chain_fd_st(r, object_dir, local, fd, &st,\n \t\t\t\t\t  &incomplete);\n \t}\n \n@@ -376,9 +380,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n \n \tget_midx_filename(&midx_name, object_dir);\n \n-\tm = load_multi_pack_index_one(object_dir, midx_name.buf, local);\n+\tm = load_multi_pack_index_one(the_repository, object_dir,\n+\t\t\t\t      midx_name.buf, local);\n \tif (!m)\n-\t\tm = load_multi_pack_index_chain(object_dir, local);\n+\t\tm = load_multi_pack_index_chain(the_repository, object_dir, local);\n \n \tstrbuf_release(&midx_name);\n \n@@ -520,7 +525,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,\n \t\t     uint32_t *result)\n {\n \tint ret = bsearch_hash(oid->hash, m->chunk_oid_fanout,\n-\t\t\t       m->chunk_oid_lookup, the_hash_algo->rawsz,\n+\t\t\t       m->chunk_oid_lookup, m->repo->hash_algo->rawsz,\n \t\t\t       result);\n \tif (result)\n \t\t*result += m->num_objects_in_base;\n@@ -551,7 +556,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,\n \tn = midx_for_object(&m, n);\n \n \toidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),\n-\t\tthe_repository->hash_algo);\n+\t\tm->repo->hash_algo);\n \treturn oid;\n }\n \n\n-- \n2.47.0\n\n"},{"id":"507366","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-5-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 5/8] midx: pass `repository` to `load_multi_pack_index`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:18Z","receivedAt":"2024-11-15T13:42:39Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `load_multi_pack_index` function in midx uses `the_repository`\nvariable to access the `repository` struct. Let's modify the function\nand its callee's to send the `repository` field.\n\nThis moves usage of `the_repository` to the `test-read-midx.c` file.\nWhile that is not optimal, it is okay, since we'll slowly move the usage\nof `the_repository` up the layers and eventually remove it entirely.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c                    | 11 ++++++-----\n midx.h                    |  4 +++-\n t/helper/test-read-midx.c |  8 ++++----\n 3 files changed, 13 insertions(+), 10 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 6f0fb8285af14843da132ef1b0c3a8bdd06732c9..98ee84d4a8bf388906634ad695ff39acdaa2c6d5 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -372,7 +372,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r\n \treturn m;\n }\n \n-struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n+struct multi_pack_index *load_multi_pack_index(struct repository *r,\n+\t\t\t\t\t       const char *object_dir,\n \t\t\t\t\t       int local)\n {\n \tstruct strbuf midx_name = STRBUF_INIT;\n@@ -380,10 +381,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n \n \tget_midx_filename(&midx_name, object_dir);\n \n-\tm = load_multi_pack_index_one(the_repository, object_dir,\n+\tm = load_multi_pack_index_one(r, object_dir,\n \t\t\t\t      midx_name.buf, local);\n \tif (!m)\n-\t\tm = load_multi_pack_index_chain(the_repository, object_dir, local);\n+\t\tm = load_multi_pack_index_chain(r, object_dir, local);\n \n \tstrbuf_release(&midx_name);\n \n@@ -727,7 +728,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i\n \t\tif (!strcmp(object_dir, m_search->object_dir))\n \t\t\treturn 1;\n \n-\tm = load_multi_pack_index(object_dir, local);\n+\tm = load_multi_pack_index(r, object_dir, local);\n \n \tif (m) {\n \t\tstruct multi_pack_index *mp = r->objects->multi_pack_index;\n@@ -881,7 +882,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag\n \tstruct pair_pos_vs_id *pairs = NULL;\n \tuint32_t i;\n \tstruct progress *progress = NULL;\n-\tstruct multi_pack_index *m = load_multi_pack_index(object_dir, 1);\n+\tstruct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1);\n \tstruct multi_pack_index *curr;\n \tverify_midx_error = 0;\n \ndiff --git a/midx.h b/midx.h\nindex c37ad5b5242b56d21fd76bd59957a1bdb82786ec..78efa28d35371795fa33c68660278182debb60ab 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -97,7 +97,9 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext);\n \n-struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);\n+struct multi_pack_index *load_multi_pack_index(struct repository *r,\n+\t\t\t\t\t       const char *object_dir,\n+\t\t\t\t\t       int local);\n int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);\n struct packed_git *nth_midxed_pack(struct multi_pack_index *m,\n \t\t\t\t   uint32_t pack_int_id);\ndiff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c\nindex 438fb9fc6197fc465f79d9a65b719ae315fed373..fc632369618917e2d8cdcb77bd9073c61e1544c1 100644\n--- a/t/helper/test-read-midx.c\n+++ b/t/helper/test-read-midx.c\n@@ -18,7 +18,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,\n \tstruct multi_pack_index *m;\n \n \tsetup_git_directory();\n-\tm = load_multi_pack_index(object_dir, 1);\n+\tm = load_multi_pack_index(the_repository, object_dir, 1);\n \n \tif (!m)\n \t\treturn 1;\n@@ -82,7 +82,7 @@ static int read_midx_checksum(const char *object_dir)\n \tstruct multi_pack_index *m;\n \n \tsetup_git_directory();\n-\tm = load_multi_pack_index(object_dir, 1);\n+\tm = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!m)\n \t\treturn 1;\n \tprintf(\"%s\\n\", hash_to_hex(get_midx_checksum(m)));\n@@ -98,7 +98,7 @@ static int read_midx_preferred_pack(const char *object_dir)\n \n \tsetup_git_directory();\n \n-\tmidx = load_multi_pack_index(object_dir, 1);\n+\tmidx = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!midx)\n \t\treturn 1;\n \n@@ -121,7 +121,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)\n \n \tsetup_git_directory();\n \n-\tmidx = load_multi_pack_index(object_dir, 1);\n+\tmidx = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!midx)\n \t\treturn 1;\n \n\n-- \n2.47.0\n\n"},{"id":"507367","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-6-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 6/8] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:19Z","receivedAt":"2024-11-15T13:42:40Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The function `get_midx_filename_ext` uses `hash_to_hex` which internally\nuses the global variable `the_repository`. To remove this dependency, we\npass down the `hash_algo` to both `get_midx_filename` and\n`get_midx_filename_ext`. While we add `the_repository` usage to\n`midx-write.c` for this reason, we'll resolve this in a future commit.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c    | 15 +++++++--------\n midx.c          | 16 +++++++++-------\n midx.h          |  7 +++++--\n pack-bitmap.c   |  6 +++---\n pack-revindex.c |  2 +-\n 5 files changed, 25 insertions(+), 21 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 5af29899bbe279c7c3ff4bc2c65330620ce37ee2..7c1563845993075d622f59faeb25462180434abd 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -990,8 +990,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \tfor (i = 0; i < ARRAY_SIZE(midx_exts); i++) {\n \t\tconst unsigned char *hash = get_midx_checksum(m);\n \n-\t\tget_midx_filename_ext(&from, m->object_dir, hash,\n-\t\t\t\t      midx_exts[i].non_split);\n+\t\tget_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,\n+\t\t\t\t      hash, midx_exts[i].non_split);\n \t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n \t\t\t\t\t    midx_exts[i].split);\n \n@@ -1011,9 +1011,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \treturn ret;\n }\n \n-static void clear_midx_files(const char *object_dir,\n-\t\t\t     const char **hashes,\n-\t\t\t     uint32_t hashes_nr,\n+static void clear_midx_files(struct repository *r, const char *object_dir,\n+\t\t\t     const char **hashes, uint32_t hashes_nr,\n \t\t\t     unsigned incremental)\n {\n \t/*\n@@ -1038,7 +1037,7 @@ static void clear_midx_files(const char *object_dir,\n \t}\n \n \tif (incremental)\n-\t\tget_midx_filename(&buf, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &buf, object_dir);\n \telse\n \t\tget_midx_chain_filename(&buf, object_dir);\n \n@@ -1082,7 +1081,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\t\t    \"%s/pack/multi-pack-index.d/tmp_midx_XXXXXX\",\n \t\t\t    object_dir);\n \telse\n-\t\tget_midx_filename(&midx_name, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &midx_name, object_dir);\n \tif (safe_create_leading_directories(midx_name.buf))\n \t\tdie_errno(_(\"unable to create leading directories of %s\"),\n \t\t\t  midx_name.buf);\n@@ -1473,7 +1472,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \tif (commit_lock_file(&lk) < 0)\n \t\tdie_errno(_(\"could not write multi-pack-index\"));\n \n-\tclear_midx_files(object_dir, keep_hashes,\n+\tclear_midx_files(r, object_dir, keep_hashes,\n \t\t\t ctx.num_multi_pack_indexes_before + 1,\n \t\t\t ctx.incremental);\n \ndiff --git a/midx.c b/midx.c\nindex 98ee84d4a8bf388906634ad695ff39acdaa2c6d5..9bed4185ff4d44602aedfe0329dd840ff9e85435 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -28,17 +28,19 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n \treturn m->data + m->data_len - m->repo->hash_algo->rawsz;\n }\n \n-void get_midx_filename(struct strbuf *out, const char *object_dir)\n+void get_midx_filename(const struct git_hash_algo *hash_algo,\n+\t\t       struct strbuf *out, const char *object_dir)\n {\n-\tget_midx_filename_ext(out, object_dir, NULL, NULL);\n+\tget_midx_filename_ext(hash_algo, out, object_dir, NULL, NULL);\n }\n \n-void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n+void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t   struct strbuf *out, const char *object_dir,\n \t\t\t   const unsigned char *hash, const char *ext)\n {\n \tstrbuf_addf(out, \"%s/pack/multi-pack-index\", object_dir);\n \tif (ext)\n-\t\tstrbuf_addf(out, \"-%s.%s\", hash_to_hex(hash), ext);\n+\t\tstrbuf_addf(out, \"-%s.%s\", hash_to_hex_algop(hash, hash_algo), ext);\n }\n \n static int midx_read_oid_fanout(const unsigned char *chunk_start,\n@@ -379,7 +381,7 @@ struct multi_pack_index *load_multi_pack_index(struct repository *r,\n \tstruct strbuf midx_name = STRBUF_INIT;\n \tstruct multi_pack_index *m;\n \n-\tget_midx_filename(&midx_name, object_dir);\n+\tget_midx_filename(r->hash_algo, &midx_name, object_dir);\n \n \tm = load_multi_pack_index_one(r, object_dir,\n \t\t\t\t      midx_name.buf, local);\n@@ -822,7 +824,7 @@ void clear_midx_file(struct repository *r)\n {\n \tstruct strbuf midx = STRBUF_INIT;\n \n-\tget_midx_filename(&midx, r->objects->odb->path);\n+\tget_midx_filename(r->hash_algo, &midx, r->objects->odb->path);\n \n \tif (r->objects && r->objects->multi_pack_index) {\n \t\tclose_midx(r->objects->multi_pack_index);\n@@ -891,7 +893,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag\n \t\tstruct stat sb;\n \t\tstruct strbuf filename = STRBUF_INIT;\n \n-\t\tget_midx_filename(&filename, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &filename, object_dir);\n \n \t\tif (!stat(filename.buf, &sb)) {\n \t\t\terror(_(\"multi-pack-index file exists, but failed to parse\"));\ndiff --git a/midx.h b/midx.h\nindex 78efa28d35371795fa33c68660278182debb60ab..7620820d4d0272926af9e4eeb68bfb73404c7ec2 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -7,6 +7,7 @@ struct object_id;\n struct pack_entry;\n struct repository;\n struct bitmapped_pack;\n+struct git_hash_algo;\n \n #define MIDX_SIGNATURE 0x4d494458 /* \"MIDX\" */\n #define MIDX_VERSION 1\n@@ -89,8 +90,10 @@ struct multi_pack_index {\n #define MIDX_EXT_MIDX \"midx\"\n \n const unsigned char *get_midx_checksum(struct multi_pack_index *m);\n-void get_midx_filename(struct strbuf *out, const char *object_dir);\n-void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n+void get_midx_filename(const struct git_hash_algo *hash_algo,\n+\t\t       struct strbuf *out, const char *object_dir);\n+void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t   struct strbuf *out, const char *object_dir,\n \t\t\t   const unsigned char *hash, const char *ext);\n void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 0cb1b56c9d5a55936ba53e2ff904ffe46cdcbafc..7b62d099cab5729a60a36b3ad15276fdc351aa97 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -375,8 +375,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)\n char *midx_bitmap_filename(struct multi_pack_index *midx)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tget_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx),\n-\t\t\t      MIDX_EXT_BITMAP);\n+\tget_midx_filename_ext(midx->repo->hash_algo, &buf, midx->object_dir,\n+\t\t\t      get_midx_checksum(midx), MIDX_EXT_BITMAP);\n \n \treturn strbuf_detach(&buf, NULL);\n }\n@@ -415,7 +415,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n \n \tif (bitmap_git->pack || bitmap_git->midx) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tget_midx_filename(&buf, midx->object_dir);\n+\t\tget_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir);\n \t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n \t\t\t\t   \"ignoring extra midx bitmap file\", buf.buf);\n \t\tclose(fd);\ndiff --git a/pack-revindex.c b/pack-revindex.c\nindex 22d3c2346488de6279b6f26a69fe611106c1365a..d3832478d99edffae17db0bbe85aa981c1a3ad30 100644\n--- a/pack-revindex.c\n+++ b/pack-revindex.c\n@@ -383,7 +383,7 @@ int load_midx_revindex(struct multi_pack_index *m)\n \ttrace2_data_string(\"load_midx_revindex\", the_repository,\n \t\t\t   \"source\", \"rev\");\n \n-\tget_midx_filename_ext(&revindex_name, m->object_dir,\n+\tget_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir,\n \t\t\t      get_midx_checksum(m), MIDX_EXT_REV);\n \n \tret = load_revindex_from_disk(revindex_name.buf,\n\n-- \n2.47.0\n\n"},{"id":"507368","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-7-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 7/8] midx: pass down `hash_algo` to `get_split_midx_filename_ext`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:20Z","receivedAt":"2024-11-15T13:42:41Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Similar to the previous commit, pass down `hash_algo` to\n`get_split_midx_filename_ext` so we can use `hash_to_hex_algop` and not\nrely on the `the_repository` global variable.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c |  7 ++++---\n midx.c       | 10 ++++++----\n midx.h       |  3 ++-\n 3 files changed, 12 insertions(+), 8 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 7c1563845993075d622f59faeb25462180434abd..21a64f791cd8addf33437d85304dcf35bf17d904 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -992,7 +992,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \n \t\tget_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,\n \t\t\t\t      hash, midx_exts[i].non_split);\n-\t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n+\t\tget_split_midx_filename_ext(m->repo->hash_algo, &to,\n+\t\t\t\t\t    m->object_dir, hash,\n \t\t\t\t\t    midx_exts[i].split);\n \n \t\tif (link(from.buf, to.buf) < 0 && errno != ENOENT) {\n@@ -1438,8 +1439,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\tif (link_midx_to_chain(ctx.base_midx) < 0)\n \t\t\treturn -1;\n \n-\t\tget_split_midx_filename_ext(&final_midx_name, object_dir,\n-\t\t\t\t\t    midx_hash, MIDX_EXT_MIDX);\n+\t\tget_split_midx_filename_ext(r->hash_algo, &final_midx_name,\n+\t\t\t\t\t    object_dir, midx_hash, MIDX_EXT_MIDX);\n \n \t\tif (rename_tempfile(&incr, final_midx_name.buf) < 0) {\n \t\t\terror_errno(_(\"unable to rename new multi-pack-index layer\"));\ndiff --git a/midx.c b/midx.c\nindex 9bed4185ff4d44602aedfe0329dd840ff9e85435..f45ea842cd6eda23d2eadc9deaae43839aef24c1 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -236,11 +236,13 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir)\n \tstrbuf_addstr(buf, \"/multi-pack-index-chain\");\n }\n \n-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t\t struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext)\n {\n \tget_midx_chain_dirname(buf, object_dir);\n-\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n+\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\",\n+\t\t    hash_to_hex_algop(hash, hash_algo), ext);\n }\n \n static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n@@ -328,8 +330,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n \t\tvalid = 0;\n \n \t\tstrbuf_reset(&buf);\n-\t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n-\t\t\t\t\t    MIDX_EXT_MIDX);\n+\t\tget_split_midx_filename_ext(r->hash_algo, &buf, object_dir,\n+\t\t\t\t\t    layer.hash, MIDX_EXT_MIDX);\n \t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n \n \t\tif (m) {\ndiff --git a/midx.h b/midx.h\nindex 7620820d4d0272926af9e4eeb68bfb73404c7ec2..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -97,7 +97,8 @@ void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n \t\t\t   const unsigned char *hash, const char *ext);\n void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t\t struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext);\n \n struct multi_pack_index *load_multi_pack_index(struct repository *r,\n\n-- \n2.47.0\n\n"},{"id":"507369","messageId":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-8-761f8a2c7775@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH 8/8] midx: inline the `MIDX_MIN_SIZE` definition","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T13:42:21Z","receivedAt":"2024-11-15T13:42:42Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n`local_multi_pack_index_one`. This definitions relies on the\n`the_hash_algo` global variable. Let's inline this and remove the global\nvariable usage.\n\nWith this, we can remove `USE_THE_REPOSITORY_VARIABLE` usage from\n`midx.c`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex f45ea842cd6eda23d2eadc9deaae43839aef24c1..e0eae1c25ec91f7db5670ff9bacdf0e195c35795 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"dir.h\"\n@@ -94,8 +92,6 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,\n \treturn 0;\n }\n \n-#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n-\n static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n \t\t\t\t\t\t\t  const char *object_dir,\n \t\t\t\t\t\t\t  const char *midx_name,\n@@ -122,7 +118,7 @@ static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n \n \tmidx_size = xsize_t(st.st_size);\n \n-\tif (midx_size < MIDX_MIN_SIZE) {\n+\tif (midx_size < (MIDX_HEADER_SIZE + r->hash_algo->rawsz)) {\n \t\terror(_(\"multi-pack-index file %s is too small\"), midx_name);\n \t\tgoto cleanup_fail;\n \t}\n\n-- \n2.47.0\n\n"},{"id":"507370","messageId":"CAOLa=ZTmdzZBu7M8Q4UdJPKx_LvJQruSQkrm_6XtksOKuLoM-Q@mail.gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"Re: [PATCH 0/8] Change midx.c and midx-write.c to not use global variables","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-15T14:13:11Z","receivedAt":"2024-11-15T14:13:14Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Karthik Nayak <karthik.188@gmail.com> writes:\n\n> Similar to the earlier patch series on cleaning up packfile.c and\n> removing usage of global variables [1], we change the midx.c and\n> midx-write.c files to no longer use global variables.\n>\n> This is done by the following:\n>   - Usage of repository variable already available in existing structs.\n>   - Passing down repository variable from other subsystems.\n>   - Modifying all subcommands to obtain repository variable from the\n>   command in `builtins/` and passing down the variable from there.\n>\n> The biggest change is in the first commit, wherein we modify all\n> subcommands to add the repository variable. Since the subcommand\n> definition are not often changed, it shouldn't cause too many conflicts\n> with in flight topics.\n>\n> Since the `packfile.c` cleanup is still in flight, this series is based\n> on top of master: b31fb630c0 (Merge https://github.com/j6t/git-gui,\n> 2024-11-11) with those patches merged in.\n\nThere are some topics in `seen` which would conflict with this series. I\nthink the fixes should generally be trivial and I'll try and iron them\nout in the next version.\n"},{"id":"507382","messageId":"ZzfTvGvyn7pMe3nA@tapette.crustytoothpaste.net","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-2-761f8a2c7775@gmail.com","subject":"Re: [PATCH 2/8] midx-write: add repository field to `write_midx_context`","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-11-15T23:05:32Z","receivedAt":"2024-11-15T23:05:34Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-11-15 at 13:42:15, Karthik Nayak wrote:\n> The struct `write_midx_context` is used to pass context for creating\n> MIDX files. Adding the repository field here ensures that most functions\n> within `midx-write.c` have access to the field and can use that instead\n> of the global `repository` variable. This involves passing the\n> `repository` field to `write_midx_internal`. To do this, we add\n> `the_repository` usage to two non-static functions, which we'll remove\n> in upcoming commits.\n> \n> With this, modify the static functions in `midx-write.c` to not use\n> global variables. This means, either we use existing alternatives (like\n> `repository` struct), or we pass down required fields from other\n> functions.\n> \n> Signed-off-by: default avatarKarthik Nayak <karthik.188@gmail.com>\n\nIt looks like the sign-off here may have gotten corrupted.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"507397","messageId":"ZziU3wmP0pigGRRr@ArchLinux","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-1-761f8a2c7775@gmail.com","subject":"Re: [PATCH 1/8] builtin: pass repository to sub commands","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2024-11-16T12:49:35Z","receivedAt":"2024-11-16T12:49:31Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Fri, Nov 15, 2024 at 02:42:14PM +0100, Karthik Nayak wrote:\n\n[snip]\n\n> diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c\n> index 5250913d99eba18a28878d3904cb7b2399670d02..e5b1fe287e3ec94f0d8a3a99adb68842d52992f6 100644\n> --- a/t/helper/test-parse-options.c\n> +++ b/t/helper/test-parse-options.c\n> @@ -1,8 +1,11 @@\n> +#define USE_THE_REPOSITORY_VARIABLE\n> +\n>  #include \"test-tool.h\"\n>  #include \"parse-options.h\"\n>  #include \"strbuf.h\"\n>  #include \"string-list.h\"\n>  #include \"trace2.h\"\n> +#include \"repository.h\"\n>  \n>  static int boolean = 0;\n>  static int integer = 0;\n> @@ -282,14 +285,16 @@ int cmd__parse_options_flags(int argc, const char **argv)\n>  \treturn parse_options_flags__cmd(argc, argv, test_flags);\n>  }\n>  \n> -static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED)\n> +static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED,\n> +\t\t      struct repository *repo UNUSED)\n>  {\n>  \tprintf(\"fn: subcmd_one\\n\");\n>  \tprint_args(argc, argv);\n>  \treturn 0;\n>  }\n>  \n> -static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED)\n> +static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED,\n> +\t\t      struct repository *repo UNUSED)\n>  {\n>  \tprintf(\"fn: subcmd_two\\n\");\n>  \tprint_args(argc, argv);\n> @@ -319,7 +324,7 @@ static int parse_subcommand__cmd(int argc, const char **argv,\n>  \n>  \tprintf(\"opt: %d\\n\", opt);\n>  \n> -\treturn fn(argc, argv, NULL);\n> +\treturn fn(argc, argv, NULL, the_repository);\n\nDo we need to pass the real \"the_repository\" variable here. From my\nunderstanding, we could just pass `NULL` to avoid including the\n\"repository.h\" and the macro. However, I am not familiar with the\n\"test-tool\" helper. It my comment was wrong, please ignore.\n\nThanks,\nJialuo\n"},{"id":"507398","messageId":"ZzibPPpDw518npNp@ArchLinux","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-6-761f8a2c7775@gmail.com","subject":"Re: [PATCH 6/8] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2024-11-16T13:16:44Z","receivedAt":"2024-11-16T13:16:40Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Fri, Nov 15, 2024 at 02:42:19PM +0100, Karthik Nayak wrote:\n\n[snip]\n\n> diff --git a/midx.h b/midx.h\n> index 78efa28d35371795fa33c68660278182debb60ab..7620820d4d0272926af9e4eeb68bfb73404c7ec2 100644\n> --- a/midx.h\n> +++ b/midx.h\n> @@ -7,6 +7,7 @@ struct object_id;\n>  struct pack_entry;\n>  struct repository;\n>  struct bitmapped_pack;\n> +struct git_hash_algo;\n>  \n>  #define MIDX_SIGNATURE 0x4d494458 /* \"MIDX\" */\n>  #define MIDX_VERSION 1\n> @@ -89,8 +90,10 @@ struct multi_pack_index {\n>  #define MIDX_EXT_MIDX \"midx\"\n>  \n>  const unsigned char *get_midx_checksum(struct multi_pack_index *m);\n> -void get_midx_filename(struct strbuf *out, const char *object_dir);\n> -void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n> +void get_midx_filename(const struct git_hash_algo *hash_algo,\n> +\t\t       struct strbuf *out, const char *object_dir);\n> +void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n> +\t\t\t   struct strbuf *out, const char *object_dir,\n>  \t\t\t   const unsigned char *hash, const char *ext);\n\nI don't think it's a good idea to put \"hash_algo\" in the first argument,\nwe should put it at the last to align with the code style where we use\n\"git_hash_algo\".\n\n>  void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n>  void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n"},{"id":"507399","messageId":"ZzicEz_WFWcExhDa@ArchLinux","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-7-761f8a2c7775@gmail.com","subject":"Re: [PATCH 7/8] midx: pass down `hash_algo` to `get_split_midx_filename_ext`","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2024-11-16T13:20:19Z","receivedAt":"2024-11-16T13:20:16Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Fri, Nov 15, 2024 at 02:42:20PM +0100, Karthik Nayak wrote:\n\n[snip]\n\n> diff --git a/midx.h b/midx.h\n> index 7620820d4d0272926af9e4eeb68bfb73404c7ec2..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644\n> --- a/midx.h\n> +++ b/midx.h\n> @@ -97,7 +97,8 @@ void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n>  \t\t\t   const unsigned char *hash, const char *ext);\n>  void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n>  void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n> -void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n> +void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n> +\t\t\t\t struct strbuf *buf, const char *object_dir,\n\nSimilar to comment for the previous patch, we should not put \"hash_algo\"\nat the first.\n\n>  \t\t\t\t const unsigned char *hash, const char *ext);\n>  \n>  struct multi_pack_index *load_multi_pack_index(struct repository *r,\n> \n> -- \n> 2.47.0\n> \n"},{"id":"507466","messageId":"Zzr1ZMmH9p8BF4O6@pks.im","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-2-761f8a2c7775@gmail.com","subject":"Re: [PATCH 2/8] midx-write: add repository field to `write_midx_context`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-11-18T08:05:56Z","receivedAt":"2024-11-18T08:06:07Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 15, 2024 at 02:42:15PM +0100, Karthik Nayak wrote:\n> @@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n>  \tstruct strbuf buf = STRBUF_INIT;\n>  \tchar *tmp_file;\n>  \n> -\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", the_repository);\n> +\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n>  \n> -\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex(midx_hash));\n> +\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex_algop(midx_hash,\n> +\t\t\t\t\t\t\t\t    ctx->repo->hash_algo));\n>  \n>  \ttmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,\n>  \t\t\t\t\tmidx_hash, WRITE_REV);\n\nI think it would be nice to split up the changes that start to pass down\na repo via the context and those that start to actually call a different\nfunction like we have here. Otherwise it's hard to spot the callsites\nwhere one actually has to think about what's happening.\n\nPatrick\n"},{"id":"507467","messageId":"Zzr1YaDIjweaMOm6@pks.im","threadId":"62498","inReplyTo":"ZziU3wmP0pigGRRr@ArchLinux","subject":"Re: [PATCH 1/8] builtin: pass repository to sub commands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-11-18T08:05:53Z","receivedAt":"2024-11-18T08:06:07Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Nov 16, 2024 at 08:49:35PM +0800, shejialuo wrote:\n> On Fri, Nov 15, 2024 at 02:42:14PM +0100, Karthik Nayak wrote:\n> \n> [snip]\n> \n> > diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c\n> > index 5250913d99eba18a28878d3904cb7b2399670d02..e5b1fe287e3ec94f0d8a3a99adb68842d52992f6 100644\n> > --- a/t/helper/test-parse-options.c\n> > +++ b/t/helper/test-parse-options.c\n> > @@ -1,8 +1,11 @@\n> > +#define USE_THE_REPOSITORY_VARIABLE\n> > +\n> >  #include \"test-tool.h\"\n> >  #include \"parse-options.h\"\n> >  #include \"strbuf.h\"\n> >  #include \"string-list.h\"\n> >  #include \"trace2.h\"\n> > +#include \"repository.h\"\n> >  \n> >  static int boolean = 0;\n> >  static int integer = 0;\n> > @@ -282,14 +285,16 @@ int cmd__parse_options_flags(int argc, const char **argv)\n> >  \treturn parse_options_flags__cmd(argc, argv, test_flags);\n> >  }\n> >  \n> > -static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED)\n> > +static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED,\n> > +\t\t      struct repository *repo UNUSED)\n> >  {\n> >  \tprintf(\"fn: subcmd_one\\n\");\n> >  \tprint_args(argc, argv);\n> >  \treturn 0;\n> >  }\n> >  \n> > -static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED)\n> > +static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED,\n> > +\t\t      struct repository *repo UNUSED)\n> >  {\n> >  \tprintf(\"fn: subcmd_two\\n\");\n> >  \tprint_args(argc, argv);\n> > @@ -319,7 +324,7 @@ static int parse_subcommand__cmd(int argc, const char **argv,\n> >  \n> >  \tprintf(\"opt: %d\\n\", opt);\n> >  \n> > -\treturn fn(argc, argv, NULL);\n> > +\treturn fn(argc, argv, NULL, the_repository);\n> \n> Do we need to pass the real \"the_repository\" variable here. From my\n> understanding, we could just pass `NULL` to avoid including the\n> \"repository.h\" and the macro. However, I am not familiar with the\n> \"test-tool\" helper. It my comment was wrong, please ignore.\n\nIt certainly is surprising. If this really is required I'd expect an\nexplanation in the commit message.\n\nPatrick\n"},{"id":"507468","messageId":"Zzr1Z7UEL9nCrybP@pks.im","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-3-761f8a2c7775@gmail.com","subject":"Re: [PATCH 3/8] midx-write: pass down repository to `write_midx_file[_only]`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-11-18T08:05:59Z","receivedAt":"2024-11-18T08:06:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 15, 2024 at 02:42:16PM +0100, Karthik Nayak wrote:\n> In the previous commit, we passed the repository field to all\n\nNot quite accurate, since the preceding commit is instead passing the\nrepo via the context, not adapting the subcommands.\n\n> subcommands in the `builtin/` directory. We utilize this to pass the\n> repository field down to the `write_midx_file[_only]` functions to\n> remove the usage of `the_repository` global variables.\n> \n> With this, we remove all usage of global variables in `midx-write.c` and\n> so we can remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n\nNote that we typically use imperative commit messages, as if we were\ninstructing the code to change. So you should likely drop the \"we\" both\nhere and further up in \"We utilize\".\n\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index 85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0..2a938466f53aaa11096170554fe11a4ed46a25e4 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to)\n>  \n>  static int cmd_multi_pack_index_write(int argc, const char **argv,\n>  \t\t\t\t      const char *prefix,\n> -\t\t\t\t      struct repository *repo UNUSED)\n> +\t\t\t\t      struct repository *repo)\n>  {\n>  \tstruct option *options;\n>  \tstatic struct option builtin_multi_pack_index_write_options[] = {\n\nOne thing I've briefly wondered: do we actually need the whole repo, or\ndo we only care about `packed_git`? I would have assumed that it should\nbe the latter as an MIDX only gets written for packfiles, but that is\nlikely only a naive assumption.\n\n> diff --git a/midx-write.c b/midx-write.c\n> index a384f7ddc8a396d0cffd528132bb8fcdc6b37e24..5af29899bbe279c7c3ff4bc2c65330620ce37ee2 100644\n> --- a/midx-write.c\n> +++ b/midx-write.c\n> @@ -1,5 +1,3 @@\n> -#define USE_THE_REPOSITORY_VARIABLE\n> -\n>  #include \"git-compat-util.h\"\n>  #include \"abspath.h\"\n>  #include \"config.h\"\n\nNice.\n\nPatrick\n"},{"id":"507469","messageId":"Zzr1at9niamTkEm1@pks.im","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-4-761f8a2c7775@gmail.com","subject":"Re: [PATCH 4/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-11-18T08:06:02Z","receivedAt":"2024-11-18T08:06:14Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 15, 2024 at 02:42:17PM +0100, Karthik Nayak wrote:\n> In the `midx.c` file, there are multiple usages of `the_repository` and\n> `the_hash_algo` within static functions of the file. Some of the usages\n> can be simply swapped out with the available `repository` struct\n> available. While some of them can be swapped out by passing the\n\nThe second \"available\" should probably be \"parameter\" or \"variable\" or\nsomething like this? Or it just needs to be dropped altogether.\n\nPatrick\n"},{"id":"507503","messageId":"CAOLa=ZQ=+ex1SaRJ9-XuCTMoRrfdgXDMyjvRkTLZUfahTfFhnQ@mail.gmail.com","threadId":"62498","inReplyTo":"ZziU3wmP0pigGRRr@ArchLinux","subject":"Re: [PATCH 1/8] builtin: pass repository to sub commands","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-18T15:17:09Z","receivedAt":"2024-11-18T15:17:10Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"shejialuo <shejialuo@gmail.com> writes:\n\n> On Fri, Nov 15, 2024 at 02:42:14PM +0100, Karthik Nayak wrote:\n>\n> [snip]\n>\n>> diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c\n>> index 5250913d99eba18a28878d3904cb7b2399670d02..e5b1fe287e3ec94f0d8a3a99adb68842d52992f6 100644\n>> --- a/t/helper/test-parse-options.c\n>> +++ b/t/helper/test-parse-options.c\n>> @@ -1,8 +1,11 @@\n>> +#define USE_THE_REPOSITORY_VARIABLE\n>> +\n>>  #include \"test-tool.h\"\n>>  #include \"parse-options.h\"\n>>  #include \"strbuf.h\"\n>>  #include \"string-list.h\"\n>>  #include \"trace2.h\"\n>> +#include \"repository.h\"\n>>\n>>  static int boolean = 0;\n>>  static int integer = 0;\n>> @@ -282,14 +285,16 @@ int cmd__parse_options_flags(int argc, const char **argv)\n>>  \treturn parse_options_flags__cmd(argc, argv, test_flags);\n>>  }\n>>\n>> -static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED)\n>> +static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED,\n>> +\t\t      struct repository *repo UNUSED)\n>>  {\n>>  \tprintf(\"fn: subcmd_one\\n\");\n>>  \tprint_args(argc, argv);\n>>  \treturn 0;\n>>  }\n>>\n>> -static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED)\n>> +static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED,\n>> +\t\t      struct repository *repo UNUSED)\n>>  {\n>>  \tprintf(\"fn: subcmd_two\\n\");\n>>  \tprint_args(argc, argv);\n>> @@ -319,7 +324,7 @@ static int parse_subcommand__cmd(int argc, const char **argv,\n>>\n>>  \tprintf(\"opt: %d\\n\", opt);\n>>\n>> -\treturn fn(argc, argv, NULL);\n>> +\treturn fn(argc, argv, NULL, the_repository);\n>\n> Do we need to pass the real \"the_repository\" variable here. From my\n> understanding, we could just pass `NULL` to avoid including the\n> \"repository.h\" and the macro. However, I am not familiar with the\n> \"test-tool\" helper. It my comment was wrong, please ignore.\n>\n\nWe don't _need_ to. The test should work with NULL too. Let me modify\nthis, thanks!\n\n> Thanks,\n> Jialuo\n"},{"id":"507504","messageId":"CAOLa=ZS_b0HQg-2AaDvbsZrzujyKAs0Spe1irDw9QugWyzNw0w@mail.gmail.com","threadId":"62498","inReplyTo":"ZzfTvGvyn7pMe3nA@tapette.crustytoothpaste.net","subject":"Re: [PATCH 2/8] midx-write: add repository field to `write_midx_context`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-18T15:17:48Z","receivedAt":"2024-11-18T15:17:52Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> On 2024-11-15 at 13:42:15, Karthik Nayak wrote:\n>> The struct `write_midx_context` is used to pass context for creating\n>> MIDX files. Adding the repository field here ensures that most functions\n>> within `midx-write.c` have access to the field and can use that instead\n>> of the global `repository` variable. This involves passing the\n>> `repository` field to `write_midx_internal`. To do this, we add\n>> `the_repository` usage to two non-static functions, which we'll remove\n>> in upcoming commits.\n>>\n>> With this, modify the static functions in `midx-write.c` to not use\n>> global variables. This means, either we use existing alternatives (like\n>> `repository` struct), or we pass down required fields from other\n>> functions.\n>>\n>> Signed-off-by: default avatarKarthik Nayak <karthik.188@gmail.com>\n>\n> It looks like the sign-off here may have gotten corrupted.\n> --\n> brian m. carlson (they/them or he/him)\n> Toronto, Ontario, CA\n\nIndeed, will fix. Thanks!\n"},{"id":"507525","messageId":"CAOLa=ZSevO8HmKCWbZqPJzLs9eA6Lb942BP6h_=1iWjzETeihA@mail.gmail.com","threadId":"62498","inReplyTo":"Zzr1ZMmH9p8BF4O6@pks.im","subject":"Re: [PATCH 2/8] midx-write: add repository field to `write_midx_context`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-18T15:37:18Z","receivedAt":"2024-11-18T15:37:20Z","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 Fri, Nov 15, 2024 at 02:42:15PM +0100, Karthik Nayak wrote:\n>> @@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n>>  \tstruct strbuf buf = STRBUF_INIT;\n>>  \tchar *tmp_file;\n>>\n>> -\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", the_repository);\n>> +\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n>>\n>> -\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex(midx_hash));\n>> +\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex_algop(midx_hash,\n>> +\t\t\t\t\t\t\t\t    ctx->repo->hash_algo));\n>>\n>>  \ttmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,\n>>  \t\t\t\t\tmidx_hash, WRITE_REV);\n>\n> I think it would be nice to split up the changes that start to pass down\n> a repo via the context and those that start to actually call a different\n> function like we have here. Otherwise it's hard to spot the callsites\n> where one actually has to think about what's happening.\n>\n> Patrick\n\nFair enough, I've split it into 3 separate commits for the next\nversion:\n\n- To pass down `the_repository` to non-static functions\n- To use `revs-repo` in `read_refs_snapshot`\n- To add repository to `write_midx_context`\n\nThis should make it easier for reviewers. Thanks\n"},{"id":"507526","messageId":"CAOLa=ZSP=GCu6_2=BauH8fvetjryygL6vopStFm64K=s7yBp=A@mail.gmail.com","threadId":"62498","inReplyTo":"Zzr1at9niamTkEm1@pks.im","subject":"Re: [PATCH 4/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-18T16:16:25Z","receivedAt":"2024-11-18T16:16:26Z","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 Fri, Nov 15, 2024 at 02:42:17PM +0100, Karthik Nayak wrote:\n>> In the `midx.c` file, there are multiple usages of `the_repository` and\n>> `the_hash_algo` within static functions of the file. Some of the usages\n>> can be simply swapped out with the available `repository` struct\n>> available. While some of them can be swapped out by passing the\n>\n> The second \"available\" should probably be \"parameter\" or \"variable\" or\n> something like this? Or it just needs to be dropped altogether.\n>\n> Patrick\n\nI think it is best dropped. Thanks\n"},{"id":"507527","messageId":"CAOLa=ZTU08VGeATHDwnREiYT=PMevrTvG3BzffLCc8DBcHy-tQ@mail.gmail.com","threadId":"62498","inReplyTo":"ZzibPPpDw518npNp@ArchLinux","subject":"Re: [PATCH 6/8] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-18T16:25:09Z","receivedAt":"2024-11-18T16:25:11Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"shejialuo <shejialuo@gmail.com> writes:\n\n> On Fri, Nov 15, 2024 at 02:42:19PM +0100, Karthik Nayak wrote:\n>\n> [snip]\n>\n>> diff --git a/midx.h b/midx.h\n>> index 78efa28d35371795fa33c68660278182debb60ab..7620820d4d0272926af9e4eeb68bfb73404c7ec2 100644\n>> --- a/midx.h\n>> +++ b/midx.h\n>> @@ -7,6 +7,7 @@ struct object_id;\n>>  struct pack_entry;\n>>  struct repository;\n>>  struct bitmapped_pack;\n>> +struct git_hash_algo;\n>>\n>>  #define MIDX_SIGNATURE 0x4d494458 /* \"MIDX\" */\n>>  #define MIDX_VERSION 1\n>> @@ -89,8 +90,10 @@ struct multi_pack_index {\n>>  #define MIDX_EXT_MIDX \"midx\"\n>>\n>>  const unsigned char *get_midx_checksum(struct multi_pack_index *m);\n>> -void get_midx_filename(struct strbuf *out, const char *object_dir);\n>> -void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n>> +void get_midx_filename(const struct git_hash_algo *hash_algo,\n>> +\t\t       struct strbuf *out, const char *object_dir);\n>> +void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n>> +\t\t\t   struct strbuf *out, const char *object_dir,\n>>  \t\t\t   const unsigned char *hash, const char *ext);\n>\n> I don't think it's a good idea to put \"hash_algo\" in the first argument,\n> we should put it at the last to align with the code style where we use\n> \"git_hash_algo\".\n>\n\nCould you elaborate on why you think it is not a good idea?\n\nI've mostly done this to stay consistent, because I see `struct\nrepository *repo` being passed as the first variable in our code base.\n\nRoughly:\n\n    $ grep -Iir \"struct repository \\*r\" --include=\\*.h | wc -l\n    524\n\n    $ grep -Iir \"(struct repository \\*r\" --include=\\*.h | wc -l\n    327\n\nSince `hash_algo` is similar, I thought it would be nicer to be\nconsistent.\n\n>>  void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n>>  void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n"},{"id":"507612","messageId":"ZzyAyMs0_A77DtGS@ArchLinux","threadId":"62498","inReplyTo":"CAOLa=ZTU08VGeATHDwnREiYT=PMevrTvG3BzffLCc8DBcHy-tQ@mail.gmail.com","subject":"Re: [PATCH 6/8] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2024-11-19T12:12:56Z","receivedAt":"2024-11-19T12:12:50Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Mon, Nov 18, 2024 at 10:25:09AM -0600, karthik nayak wrote:\n> shejialuo <shejialuo@gmail.com> writes:\n> \n> > On Fri, Nov 15, 2024 at 02:42:19PM +0100, Karthik Nayak wrote:\n> >\n> > [snip]\n> >\n> >> diff --git a/midx.h b/midx.h\n> >> index 78efa28d35371795fa33c68660278182debb60ab..7620820d4d0272926af9e4eeb68bfb73404c7ec2 100644\n> >> --- a/midx.h\n> >> +++ b/midx.h\n> >> @@ -7,6 +7,7 @@ struct object_id;\n> >>  struct pack_entry;\n> >>  struct repository;\n> >>  struct bitmapped_pack;\n> >> +struct git_hash_algo;\n> >>\n> >>  #define MIDX_SIGNATURE 0x4d494458 /* \"MIDX\" */\n> >>  #define MIDX_VERSION 1\n> >> @@ -89,8 +90,10 @@ struct multi_pack_index {\n> >>  #define MIDX_EXT_MIDX \"midx\"\n> >>\n> >>  const unsigned char *get_midx_checksum(struct multi_pack_index *m);\n> >> -void get_midx_filename(struct strbuf *out, const char *object_dir);\n> >> -void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n> >> +void get_midx_filename(const struct git_hash_algo *hash_algo,\n> >> +\t\t       struct strbuf *out, const char *object_dir);\n> >> +void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n> >> +\t\t\t   struct strbuf *out, const char *object_dir,\n> >>  \t\t\t   const unsigned char *hash, const char *ext);\n> >\n> > I don't think it's a good idea to put \"hash_algo\" in the first argument,\n> > we should put it at the last to align with the code style where we use\n> > \"git_hash_algo\".\n> >\n> \n> Could you elaborate on why you think it is not a good idea?\n> \n> I've mostly done this to stay consistent, because I see `struct\n> repository *repo` being passed as the first variable in our code base.\n> \n> Roughly:\n> \n>     $ grep -Iir \"struct repository \\*r\" --include=\\*.h | wc -l\n>     524\n> \n>     $ grep -Iir \"(struct repository \\*r\" --include=\\*.h | wc -l\n>     327\n> \n> Since `hash_algo` is similar, I thought it would be nicer to be\n> consistent.\n> \n\nI will elaborate on this. The reason why I think this is not a good idea\ncomes from two aspects:\n\n    1. I have thought that we will always put \"struct git_hash_algo\"\n       to the end of the function definition. However, when I carefully\n       inspect the code today, we could put it everywhere. So, I wrongly\n       made above statement.\n    2. Another aspect is that I think \"struct git_hash_algo\" is not the\n       most important parameter for these functions. When the caller\n       sees this function name \"get_midx_filename_ext\" without any\n       knowledge, passing the \"hash_algo\" firstly is a little wired.\n\nHowever, as 1 shows, we may not care about which position we put this\nparameter into. So, I agree with you that we could just align with the\n\"struct repository *\".\n\nThanks.\n\n> >>  void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n> >>  void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n\n"},{"id":"507617","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com","subject":"[PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:39Z","receivedAt":"2024-11-19T15:37:00Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Similar to the earlier patch series on cleaning up packfile.c and\nremoving usage of global variables [1], we change the midx.c and\nmidx-write.c files to no longer use global variables.\n\nThis is done by the following:\n  - Usage of repository variable already available in existing structs.\n  - Passing down repository variable from other subsystems.\n  - Modifying all subcommands to obtain repository variable from the\n  command in `builtins/` and passing down the variable from there.\n\nThe biggest change is in the first commit, wherein we modify all\nsubcommands to add the repository variable. Since the subcommand\ndefinition are not often changed, it shouldn't cause too many conflicts\nwith in flight topics.\n\nSince the `packfile.c` cleanup is still in flight, this series is based\non top of master: b31fb630c0 (Merge https://github.com/j6t/git-gui,\n2024-11-11) with those patches merged in. This applies cleanly on top \nof next, but conflicts with `bf/set-head-symref` in seen, the conflict\nis mostly straight forward. I'll merge the topic in if it is merged into\nnext soon.\n\n[1]: https://lore.kernel.org/git/cover.1729504640.git.karthik.188@gmail.com/\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\nChanges in v2:\n- Split commit modifying static functions in `midx-write.c` to multiple\ncommits, which makes it easier to review.\n- Remove usage of `the_repository` in `test-parse-options.c` and use\nNULL instead.\n- Fix the commit messages to be imperative.\n- Fix error in commit sign off.\n- Link to v1: https://lore.kernel.org/r/20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com\n\n---\nKarthik Nayak (10):\n      builtin: pass repository to sub commands\n      midx-write: pass down repository to static functions\n      midx-write: use `revs->repo` inside `read_refs_snapshot`\n      write-midx: add repository field to `write_midx_context`\n      midx-write: pass down repository to `write_midx_file[_only]`\n      midx: cleanup internal usage of `the_repository` and `the_hash_algo`\n      midx: pass `repository` to `load_multi_pack_index`\n      midx: pass down `hash_algo` to `get_midx_filename[_ext]`\n      midx: pass down `hash_algo` to `get_split_midx_filename_ext`\n      midx: inline the `MIDX_MIN_SIZE` definition\n\n builtin/bisect.c              |  32 +++++++----\n builtin/bundle.c              |  16 ++++--\n builtin/commit-graph.c        |  10 ++--\n builtin/config.c              |  25 +++++---\n builtin/gc.c                  |  21 ++++---\n builtin/hook.c                |   7 ++-\n builtin/multi-pack-index.c    |  20 ++++---\n builtin/notes.c               |  36 +++++++-----\n builtin/reflog.c              |  17 ++++--\n builtin/refs.c                |  10 ++--\n builtin/remote.c              |  34 +++++++----\n builtin/repack.c              |   2 +-\n builtin/sparse-checkout.c     |  25 +++++---\n builtin/stash.c               |  39 ++++++++-----\n builtin/submodule--helper.c   |  46 +++++++++------\n builtin/worktree.c            |  28 +++++----\n midx-write.c                  | 130 ++++++++++++++++++++++--------------------\n midx.c                        |  88 +++++++++++++++-------------\n midx.h                        |  24 ++++----\n pack-bitmap.c                 |   6 +-\n pack-revindex.c               |   2 +-\n parse-options.h               |   4 +-\n t/helper/test-parse-options.c |   8 ++-\n t/helper/test-read-midx.c     |   8 +--\n 24 files changed, 378 insertions(+), 260 deletions(-)\n---\n\nRange-diff versus v1:\n\n 1:  277db8a45a <  -:  ---------- packfile: add repository to struct `packed_git`\n 2:  10ff177a40 <  -:  ---------- packfile: use `repository` from `packed_git` directly\n 3:  c531a865d7 <  -:  ---------- packfile: pass `repository` to static function in the file\n 4:  36cda6c7e9 <  -:  ---------- packfile: pass down repository to `odb_pack_name`\n 5:  dbe2d93cbe <  -:  ---------- packfile: pass down repository to `has_object[_kept]_pack`\n 6:  5b030a81c4 <  -:  ---------- packfile: pass down repository to `for_each_packed_object`\n 7:  b4d6dda97c <  -:  ---------- config: make `delta_base_cache_limit` a non-global variable\n 8:  bf13b948d4 <  -:  ---------- config: make `packed_git_(limit|window_size)` non-global variables\n 9:  3ec55c737b <  -:  ---------- midx: add repository to `multi_pack_index` struct\n10:  4df5b4fb30 !  1:  a423d7785c builtin: pass repository to sub commands\n    @@ Commit message\n         builtin: pass repository to sub commands\n     \n         In 9b1cb5070f (builtin: add a repository parameter for builtin\n    -    functions, 2024-09-13) we passed down the repository to all builtin\n    -    commands. This allowed us to pass down the repository to lower layers\n    +    functions, 2024-09-13) the repository was passed down to all builtin\n    +    commands. This allowed the repository to be passed down to lower layers\n         without depending on the global `the_repository` variable.\n     \n    -    To continue this work, we also pass down the repository parameter from\n    -    the command to sub-commands. In the upcoming commit, we'll utilize this\n    -    to remove global variable usage in `midx-write.c`.\n    +    Continue this work by also passing down the repository parameter from\n    +    the command to sub-commands. In the upcoming commit, utilize this to\n    +    remove global variable usage in `midx-write.c`.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n    @@ parse-options.h: typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_\n       * `type`::\n     \n      ## t/helper/test-parse-options.c ##\n    -@@\n    -+#define USE_THE_REPOSITORY_VARIABLE\n    -+\n    - #include \"test-tool.h\"\n    - #include \"parse-options.h\"\n    - #include \"strbuf.h\"\n    - #include \"string-list.h\"\n    - #include \"trace2.h\"\n    -+#include \"repository.h\"\n    - \n    - static int boolean = 0;\n    - static int integer = 0;\n     @@ t/helper/test-parse-options.c: int cmd__parse_options_flags(int argc, const char **argv)\n      \treturn parse_options_flags__cmd(argc, argv, test_flags);\n      }\n    @@ t/helper/test-parse-options.c: static int parse_subcommand__cmd(int argc, const\n      \tprintf(\"opt: %d\\n\", opt);\n      \n     -\treturn fn(argc, argv, NULL);\n    -+\treturn fn(argc, argv, NULL, the_repository);\n    ++\treturn fn(argc, argv, NULL, NULL);\n      }\n      \n      int cmd__parse_subcommand(int argc, const char **argv)\n11:  3cfab22dc1 !  2:  3f39af60b4 midx-write: add repository field to `write_midx_context`\n    @@ Metadata\n     Author: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## Commit message ##\n    -    midx-write: add repository field to `write_midx_context`\n    +    midx-write: pass down repository to static functions\n     \n    -    The struct `write_midx_context` is used to pass context for creating\n    -    MIDX files. Adding the repository field here ensures that most functions\n    -    within `midx-write.c` have access to the field and can use that instead\n    -    of the global `repository` variable. This involves passing the\n    -    `repository` field to `write_midx_internal`. To do this, we add\n    -    `the_repository` usage to two non-static functions, which we'll remove\n    -    in upcoming commits.\n    +    In 'midx-write.c' there are a lot of static functions which use global\n    +    variables `the_repository` or `the_hash_algo`. In a follow up commit,\n    +    the repository variable will be added to `write_midx_context`, which\n    +    some of the functions can use. But for functions which do not have\n    +    access to this struct, pass down the required information from\n    +    non-static functions `write_midx_file` and `write_midx_file_only`.\n     \n    -    With this, modify the static functions in `midx-write.c` to not use\n    -    global variables. This means, either we use existing alternatives (like\n    -    `repository` struct), or we pass down required fields from other\n    -    functions.\n    +    This ensures that the usage of global variables is limited to these\n    +    non-static functions, which will be cleaned up in a follow up commits.\n     \n    -    Signed-off-by: default avatarKarthik Nayak <karthik.188@gmail.com>\n    +    Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## midx-write.c ##\n     @@ midx-write.c: extern void clear_incremental_midx_files_ext(const char *object_dir,\n    @@ midx-write.c: extern void clear_incremental_midx_files_ext(const char *object_di\n      \thashwrite_u8(f, num_chunks);\n      \thashwrite_u8(f, 0); /* unused */\n      \thashwrite_be32(f, num_packs);\n    -@@ midx-write.c: struct write_midx_context {\n    - \tuint32_t num_multi_pack_indexes_before;\n    - \n    - \tstruct string_list *to_include;\n    -+\n    -+\tstruct repository *repo;\n    - };\n    - \n    - static int should_include_pack(const struct write_midx_context *ctx,\n    -@@ midx-write.c: static void add_pack_to_midx(const char *full_path, size_t full_path_len,\n    - \t\t\treturn;\n    - \n    - \t\tALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);\n    --\t\tp = add_packed_git(the_repository, full_path, full_path_len, 0);\n    -+\t\tp = add_packed_git(ctx->repo, full_path, full_path_len, 0);\n    - \t\tif (!p) {\n    - \t\t\twarning(_(\"failed to add packfile '%s'\"),\n    - \t\t\t\tfull_path);\n    -@@ midx-write.c: static int write_midx_oid_lookup(struct hashfile *f,\n    - \t\t\t\t void *data)\n    - {\n    - \tstruct write_midx_context *ctx = data;\n    --\tunsigned char hash_len = the_hash_algo->rawsz;\n    -+\tunsigned char hash_len = ctx->repo->hash_algo->rawsz;\n    - \tstruct pack_midx_entry *list = ctx->entries;\n    - \tuint32_t i;\n    - \n    -@@ midx-write.c: static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n    - \tuint32_t *pack_order, base_objects = 0;\n    - \tuint32_t i;\n    - \n    --\ttrace2_region_enter(\"midx\", \"midx_pack_order\", the_repository);\n    -+\ttrace2_region_enter(\"midx\", \"midx_pack_order\", ctx->repo);\n    - \n    - \tif (ctx->incremental && ctx->base_midx)\n    - \t\tbase_objects = ctx->base_midx->num_objects +\n    -@@ midx-write.c: static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n    - \t}\n    - \tfree(data);\n    - \n    --\ttrace2_region_leave(\"midx\", \"midx_pack_order\", the_repository);\n    -+\ttrace2_region_leave(\"midx\", \"midx_pack_order\", ctx->repo);\n    - \n    - \treturn pack_order;\n    - }\n    -@@ midx-write.c: static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n    - \tstruct strbuf buf = STRBUF_INIT;\n    - \tchar *tmp_file;\n    - \n    --\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", the_repository);\n    -+\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n    - \n    --\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex(midx_hash));\n    -+\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex_algop(midx_hash,\n    -+\t\t\t\t\t\t\t\t    ctx->repo->hash_algo));\n    - \n    - \ttmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,\n    - \t\t\t\t\tmidx_hash, WRITE_REV);\n    -@@ midx-write.c: static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n    - \tstrbuf_release(&buf);\n    - \tfree(tmp_file);\n    - \n    --\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", the_repository);\n    -+\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n    - }\n    - \n    - static void prepare_midx_packing_data(struct packing_data *pdata,\n    -@@ midx-write.c: static void prepare_midx_packing_data(struct packing_data *pdata,\n    - {\n    - \tuint32_t i;\n    - \n    --\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", the_repository);\n    -+\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n    - \n    - \tmemset(pdata, 0, sizeof(struct packing_data));\n    --\tprepare_packing_data(the_repository, pdata);\n    -+\tprepare_packing_data(ctx->repo, pdata);\n    - \n    - \tfor (i = 0; i < ctx->entries_nr; i++) {\n    - \t\tuint32_t pos = ctx->pack_order[i];\n    -@@ midx-write.c: static void prepare_midx_packing_data(struct packing_data *pdata,\n    - \t\t\t       ctx->info[ctx->pack_perm[from->pack_int_id]].p);\n    - \t}\n    - \n    --\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", the_repository);\n    -+\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n    - }\n    - \n    - static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n     @@ midx-write.c: static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n      \t\treturn 0;\n      \t}\n    @@ midx-write.c: static int add_ref_to_pending(const char *refname, const char *ref\n      \t\toid = &peeled;\n      \n      \tobject = parse_object_or_die(oid, refname);\n    -@@ midx-write.c: static int read_refs_snapshot(const char *refs_snapshot,\n    - \t\t\thex = &buf.buf[1];\n    - \t\t}\n    - \n    --\t\tif (parse_oid_hex(hex, &oid, &end) < 0)\n    -+\t\tif (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0)\n    - \t\t\tdie(_(\"could not parse line: %s\"), buf.buf);\n    - \t\tif (*end)\n    - \t\t\tdie(_(\"malformed line: %s\"), buf.buf);\n    -@@ midx-write.c: static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n    - \tstruct rev_info revs;\n    - \tstruct bitmap_commit_cb cb = {0};\n    - \n    --\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\",\n    --\t\t\t    the_repository);\n    -+\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n    - \n    - \tcb.ctx = ctx;\n    - \n    --\trepo_init_revisions(the_repository, &revs, NULL);\n    -+\trepo_init_revisions(ctx->repo, &revs, NULL);\n    - \tif (refs_snapshot) {\n    - \t\tread_refs_snapshot(refs_snapshot, &revs);\n    - \t} else {\n    - \t\tsetup_revisions(0, NULL, &revs, NULL);\n    --\t\trefs_for_each_ref(get_main_ref_store(the_repository),\n    -+\t\trefs_for_each_ref(get_main_ref_store(ctx->repo),\n    - \t\t\t\t  add_ref_to_pending, &revs);\n    - \t}\n    - \n     @@ midx-write.c: static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n    - \n    - \trelease_revisions(&revs);\n    - \n    --\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\",\n    --\t\t\t    the_repository);\n    -+\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n    - \n      \treturn cb.commits;\n      }\n      \n    @@ midx-write.c: static int write_midx_bitmap(const char *midx_name,\n      \n      \treturn ret;\n      }\n    -@@ midx-write.c: static int fill_packs_from_midx(struct write_midx_context *ctx,\n    - \t\t\t */\n    - \t\t\tif (flags & MIDX_WRITE_REV_INDEX ||\n    - \t\t\t    preferred_pack_name) {\n    --\t\t\t\tif (prepare_midx_pack(the_repository, m,\n    -+\t\t\t\tif (prepare_midx_pack(ctx->repo, m,\n    - \t\t\t\t\t\t      m->num_packs_in_base + i)) {\n    - \t\t\t\t\terror(_(\"could not load pack\"));\n    - \t\t\t\t\treturn 1;\n     @@ midx-write.c: static void clear_midx_files(const char *object_dir,\n      \tstrbuf_release(&buf);\n      }\n    @@ midx-write.c: static int write_midx_internal(const char *object_dir,\n     -\ttrace2_region_enter(\"midx\", \"write_midx_internal\", the_repository);\n     +\ttrace2_region_enter(\"midx\", \"write_midx_internal\", r);\n     +\n    -+\tctx.repo = r;\n      \n      \tctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);\n      \tif (ctx.incremental && (flags & MIDX_WRITE_BITMAP))\n    @@ midx-write.c: static int write_midx_internal(const char *object_dir,\n      \t}\n      \n      \tif (ctx.m || ctx.base_midx)\n    --\t\tclose_object_store(the_repository->objects);\n    -+\t\tclose_object_store(ctx.repo->objects);\n    - \n    - \tif (commit_lock_file(&lk) < 0)\n    - \t\tdie_errno(_(\"could not write multi-pack-index\"));\n     @@ midx-write.c: static int write_midx_internal(const char *object_dir,\n      \t}\n      \tstrbuf_release(&midx_name);\n -:  ---------- >  3:  774eea311a midx-write: use `revs->repo` inside `read_refs_snapshot`\n -:  ---------- >  4:  9ddfbdc0f8 write-midx: add repository field to `write_midx_context`\n12:  5cdc724a0c !  5:  d25ea08541 midx-write: pass down repository to `write_midx_file[_only]`\n    @@ Metadata\n      ## Commit message ##\n         midx-write: pass down repository to `write_midx_file[_only]`\n     \n    -    In the previous commit, we passed the repository field to all\n    -    subcommands in the `builtin/` directory. We utilize this to pass the\n    +    In a previous commit, we passed the repository field to all\n    +    subcommands in the `builtin/` directory. Utilize this to pass the\n         repository field down to the `write_midx_file[_only]` functions to\n         remove the usage of `the_repository` global variables.\n     \n    -    With this, we remove all usage of global variables in `midx-write.c` and\n    -    so we can remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n    +    With this, all usage of global variables in `midx-write.c` is removed,\n    +    hence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n13:  c6964becef !  6:  ca123e8c73 midx: cleanup internal usage of `the_repository` and `the_hash_algo`\n    @@ Commit message\n     \n         In the `midx.c` file, there are multiple usages of `the_repository` and\n         `the_hash_algo` within static functions of the file. Some of the usages\n    -    can be simply swapped out with the available `repository` struct\n    -    available. While some of them can be swapped out by passing the\n    -    repository to the required functions.\n    +    can be simply swapped out with the available `repository` struct. While\n    +    some of them can be swapped out by passing the repository to the\n    +    required functions.\n     \n         This leaves out only some other usages of `the_repository` and\n         `the_hash_algo` in the file in non-static functions, which we'll tackle\n14:  adcb6f0c6c !  7:  7e941aa0ba midx: pass `repository` to `load_multi_pack_index`\n    @@ Commit message\n         midx: pass `repository` to `load_multi_pack_index`\n     \n         The `load_multi_pack_index` function in midx uses `the_repository`\n    -    variable to access the `repository` struct. Let's modify the function\n    -    and its callee's to send the `repository` field.\n    +    variable to access the `repository` struct. Modify the function and its\n    +    callee's to send the `repository` field.\n     \n         This moves usage of `the_repository` to the `test-read-midx.c` file.\n    -    While that is not optimal, it is okay, since we'll slowly move the usage\n    -    of `the_repository` up the layers and eventually remove it entirely.\n    +    While that is not optimal, it is okay, since the upcoming commits will\n    +    slowly move the usage of `the_repository` up the layers and remove it\n    +    eventually.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n15:  cea8e6c252 !  8:  3e6dd4e146 midx: pass down `hash_algo` to `get_midx_filename[_ext]`\n    @@ Commit message\n         midx: pass down `hash_algo` to `get_midx_filename[_ext]`\n     \n         The function `get_midx_filename_ext` uses `hash_to_hex` which internally\n    -    uses the global variable `the_repository`. To remove this dependency, we\n    +    uses the global variable `the_repository`. To remove this dependency,\n         pass down the `hash_algo` to both `get_midx_filename` and\n    -    `get_midx_filename_ext`. While we add `the_repository` usage to\n    -    `midx-write.c` for this reason, we'll resolve this in a future commit.\n    +    `get_midx_filename_ext`. This adds `the_repository` variable usage to\n    +    `midx-write.c`, which will be resolved in a future commit.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n16:  66dd34c862 !  9:  704a5a4392 midx: pass down `hash_algo` to `get_split_midx_filename_ext`\n    @@ Commit message\n         midx: pass down `hash_algo` to `get_split_midx_filename_ext`\n     \n         Similar to the previous commit, pass down `hash_algo` to\n    -    `get_split_midx_filename_ext` so we can use `hash_to_hex_algop` and not\n    -    rely on the `the_repository` global variable.\n    +    `get_split_midx_filename_ext` and use `hash_to_hex_algop`.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n17:  1f0602aec6 ! 10:  0a4a68bcff midx: inline the `MIDX_MIN_SIZE` definition\n    @@ Commit message\n     \n         The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n         `local_multi_pack_index_one`. This definitions relies on the\n    -    `the_hash_algo` global variable. Let's inline this and remove the global\n    +    `the_hash_algo` global variable. Inline this and remove the global\n         variable usage.\n     \n    -    With this, we can remove `USE_THE_REPOSITORY_VARIABLE` usage from\n    -    `midx.c`.\n    +    With this, remove `USE_THE_REPOSITORY_VARIABLE` usage from `midx.c`.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n\n\n--- \n\nbase-commit: b31fb630c0fc6869a33ed717163e8a1210460d94\nchange-id: 20241111-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-a88498c2590f\n\nThanks\n- Karthik\n\n"},{"id":"507620","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-1-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 01/10] builtin: pass repository to sub commands","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:40Z","receivedAt":"2024-11-19T15:37:01Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In 9b1cb5070f (builtin: add a repository parameter for builtin\nfunctions, 2024-09-13) the repository was passed down to all builtin\ncommands. This allowed the repository to be passed down to lower layers\nwithout depending on the global `the_repository` variable.\n\nContinue this work by also passing down the repository parameter from\nthe command to sub-commands. In the upcoming commit, utilize this to\nremove global variable usage in `midx-write.c`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/bisect.c              | 32 +++++++++++++++++++-----------\n builtin/bundle.c              | 16 +++++++++------\n builtin/commit-graph.c        | 10 ++++++----\n builtin/config.c              | 25 ++++++++++++++---------\n builtin/gc.c                  | 21 ++++++++++++--------\n builtin/hook.c                |  7 ++++---\n builtin/multi-pack-index.c    | 16 +++++++++------\n builtin/notes.c               | 36 +++++++++++++++++++++------------\n builtin/reflog.c              | 17 ++++++++++------\n builtin/refs.c                | 10 ++++++----\n builtin/remote.c              | 34 +++++++++++++++++++++-----------\n builtin/sparse-checkout.c     | 25 ++++++++++++++---------\n builtin/stash.c               | 39 +++++++++++++++++++++++-------------\n builtin/submodule--helper.c   | 46 ++++++++++++++++++++++++++++---------------\n builtin/worktree.c            | 28 ++++++++++++++++----------\n parse-options.h               |  4 +++-\n t/helper/test-parse-options.c |  8 +++++---\n 17 files changed, 239 insertions(+), 135 deletions(-)\n\ndiff --git a/builtin/bisect.c b/builtin/bisect.c\nindex 21d17a6c1a83e51fb82b53703b95d89bd9028830..8166d4abf532fbc95aaac71198e9722684ccf7f5 100644\n--- a/builtin/bisect.c\n+++ b/builtin/bisect.c\n@@ -1312,7 +1312,8 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)\n \treturn res;\n }\n \n-static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tif (argc > 1)\n \t\treturn error(_(\"'%s' requires either no argument or a commit\"),\n@@ -1320,7 +1321,8 @@ static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNU\n \treturn bisect_reset(argc ? argv[0] : NULL);\n }\n \n-static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1333,7 +1335,8 @@ static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNU\n \treturn res;\n }\n \n-static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1344,7 +1347,8 @@ static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNU\n \treturn res;\n }\n \n-static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix)\n+static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1358,12 +1362,15 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref\n \treturn res;\n }\n \n-static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED)\n+static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED,\n+\t\t\t   const char *prefix UNUSED,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \treturn bisect_log();\n }\n \n-static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t      struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1376,7 +1383,8 @@ static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UN\n \treturn res;\n }\n \n-static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1388,7 +1396,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS\n \treturn res;\n }\n \n-static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t\t struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1399,7 +1408,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix\n \treturn res;\n }\n \n-static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED)\n+static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint res;\n \tstruct bisect_terms terms = { 0 };\n@@ -1415,7 +1425,7 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE\n int cmd_bisect(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tint res = 0;\n \tparse_opt_subcommand_fn *fn = NULL;\n@@ -1451,7 +1461,7 @@ int cmd_bisect(int argc,\n \t} else {\n \t\targc--;\n \t\targv++;\n-\t\tres = fn(argc, argv, prefix);\n+\t\tres = fn(argc, argv, prefix, repo);\n \t}\n \n \treturn is_bisect_success(res) ? 0 : -res;\ndiff --git a/builtin/bundle.c b/builtin/bundle.c\nindex 127518c2a8d3c4ec0bde62f1932e964ce9bcf66f..3f14754197c847e7a4e98b607c1a24df2b053daf 100644\n--- a/builtin/bundle.c\n+++ b/builtin/bundle.c\n@@ -67,7 +67,8 @@ static int parse_options_cmd_bundle(int argc,\n \treturn argc;\n }\n \n-static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_create(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED) {\n \tstruct strvec pack_opts = STRVEC_INIT;\n \tint version = -1;\n \tint ret;\n@@ -123,7 +124,8 @@ static int open_bundle(const char *path, struct bundle_header *header,\n \treturn read_bundle_header(path, header);\n }\n \n-static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_verify(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED) {\n \tstruct bundle_header header = BUNDLE_HEADER_INIT;\n \tint bundle_fd = -1;\n \tint quiet = 0;\n@@ -164,7 +166,8 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {\n \treturn ret;\n }\n \n-static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix,\n+\t\t\t\t struct repository *repo UNUSED) {\n \tstruct bundle_header header = BUNDLE_HEADER_INIT;\n \tint bundle_fd = -1;\n \tint ret;\n@@ -189,7 +192,8 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix\n \treturn ret;\n }\n \n-static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) {\n+static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED) {\n \tstruct bundle_header header = BUNDLE_HEADER_INIT;\n \tint bundle_fd = -1;\n \tint ret;\n@@ -231,7 +235,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)\n int cmd_bundle(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n@@ -247,5 +251,5 @@ int cmd_bundle(int argc,\n \n \tpacket_trace_identity(\"bundle\");\n \n-\treturn !!fn(argc, argv, prefix);\n+\treturn !!fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 7c991db6eb48ad6e935727a079abac02bb358f8a..bd70d052e706b6e34b5aaaceef158c63ea4863d5 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -62,7 +62,8 @@ static struct option *add_common_options(struct option *to)\n \treturn parse_options_concat(common_opts, to);\n }\n \n-static int graph_verify(int argc, const char **argv, const char *prefix)\n+static int graph_verify(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tstruct commit_graph *graph = NULL;\n \tstruct object_directory *odb = NULL;\n@@ -214,7 +215,8 @@ static int git_commit_graph_write_config(const char *var, const char *value,\n \treturn 0;\n }\n \n-static int graph_write(int argc, const char **argv, const char *prefix)\n+static int graph_write(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct string_list pack_indexes = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -333,7 +335,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)\n int cmd_commit_graph(int argc,\n \t\t     const char **argv,\n \t\t     const char *prefix,\n-\t\t     struct repository *repo UNUSED)\n+\t\t     struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_commit_graph_options[] = {\n@@ -352,5 +354,5 @@ int cmd_commit_graph(int argc,\n \t\t\t     builtin_commit_graph_usage, 0);\n \tFREE_AND_NULL(options);\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/config.c b/builtin/config.c\nindex cba702210815b716a5c6c93ebb69d8c485901e43..16e6e3055598f1355714dc6de458b662870214c0 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -826,7 +826,8 @@ static void display_options_init(struct config_display_options *opts)\n \t}\n }\n \n-static int cmd_config_list(int argc, const char **argv, const char *prefix)\n+static int cmd_config_list(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;\n@@ -861,7 +862,8 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int cmd_config_get(int argc, const char **argv, const char *prefix)\n+static int cmd_config_get(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;\n@@ -915,7 +917,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int cmd_config_set(int argc, const char **argv, const char *prefix)\n+static int cmd_config_set(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tconst char *value_pattern = NULL, *comment_arg = NULL;\n@@ -973,7 +976,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int cmd_config_unset(int argc, const char **argv, const char *prefix)\n+static int cmd_config_unset(int argc, const char **argv, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tconst char *value_pattern = NULL;\n@@ -1010,7 +1014,8 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int cmd_config_rename_section(int argc, const char **argv, const char *prefix)\n+static int cmd_config_rename_section(int argc, const char **argv, const char *prefix,\n+\t\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct option opts[] = {\n@@ -1039,7 +1044,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr\n \treturn ret;\n }\n \n-static int cmd_config_remove_section(int argc, const char **argv, const char *prefix)\n+static int cmd_config_remove_section(int argc, const char **argv, const char *prefix,\n+\t\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct option opts[] = {\n@@ -1099,7 +1105,8 @@ static int show_editor(struct config_location_options *opts)\n \treturn 0;\n }\n \n-static int cmd_config_edit(int argc, const char **argv, const char *prefix)\n+static int cmd_config_edit(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;\n \tstruct option opts[] = {\n@@ -1395,7 +1402,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)\n int cmd_config(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tparse_opt_subcommand_fn *subcommand = NULL;\n \tstruct option subcommand_opts[] = {\n@@ -1422,7 +1429,7 @@ int cmd_config(int argc,\n \tif (subcommand) {\n \t\targc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage,\n \t\t       PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\t\treturn subcommand(argc, argv, prefix);\n+\t\treturn subcommand(argc, argv, prefix, repo);\n \t}\n \n \treturn cmd_config_actions(argc, argv, prefix);\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 09802eb989471be242a4b2d74606b0998fdd2b11..50ccab172365d22c8f89e9f6fb822fca948878e7 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -1567,7 +1567,8 @@ static int task_option_parse(const struct option *opt UNUSED,\n \treturn 0;\n }\n \n-static int maintenance_run(int argc, const char **argv, const char *prefix)\n+static int maintenance_run(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint i;\n \tstruct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;\n@@ -1629,7 +1630,8 @@ static char const * const builtin_maintenance_register_usage[] = {\n \tNULL\n };\n \n-static int maintenance_register(int argc, const char **argv, const char *prefix)\n+static int maintenance_register(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tchar *config_file = NULL;\n \tstruct option options[] = {\n@@ -1693,7 +1695,8 @@ static char const * const builtin_maintenance_unregister_usage[] = {\n \tNULL\n };\n \n-static int maintenance_unregister(int argc, const char **argv, const char *prefix)\n+static int maintenance_unregister(int argc, const char **argv, const char *prefix,\n+\t\t\t\t  struct repository *repo UNUSED)\n {\n \tint force = 0;\n \tchar *config_file = NULL;\n@@ -2923,7 +2926,8 @@ static const char *const builtin_maintenance_start_usage[] = {\n \tNULL\n };\n \n-static int maintenance_start(int argc, const char **argv, const char *prefix)\n+static int maintenance_start(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo)\n {\n \tstruct maintenance_start_opts opts = { 0 };\n \tstruct option options[] = {\n@@ -2946,7 +2950,7 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)\n \tif (update_background_schedule(&opts, 1))\n \t\tdie(_(\"failed to set up maintenance schedule\"));\n \n-\tif (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL))\n+\tif (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL, repo))\n \t\twarning(_(\"failed to add repo to global config\"));\n \treturn 0;\n }\n@@ -2956,7 +2960,8 @@ static const char *const builtin_maintenance_stop_usage[] = {\n \tNULL\n };\n \n-static int maintenance_stop(int argc, const char **argv, const char *prefix)\n+static int maintenance_stop(int argc, const char **argv, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -2976,7 +2981,7 @@ static const char * const builtin_maintenance_usage[] = {\n int cmd_maintenance(int argc,\n \t\t    const char **argv,\n \t\t    const char *prefix,\n-\t\t    struct repository *repo UNUSED)\n+\t\t    struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_maintenance_options[] = {\n@@ -2990,5 +2995,5 @@ int cmd_maintenance(int argc,\n \n \targc = parse_options(argc, argv, prefix, builtin_maintenance_options,\n \t\t\t     builtin_maintenance_usage, 0);\n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/hook.c b/builtin/hook.c\nindex 367ef3e0b893fa16756880395151a82ed053acd8..672d2e37e845a2118aca1c4417a837138c250590 100644\n--- a/builtin/hook.c\n+++ b/builtin/hook.c\n@@ -19,7 +19,8 @@ static const char * const builtin_hook_run_usage[] = {\n \tNULL\n };\n \n-static int run(int argc, const char **argv, const char *prefix)\n+static int run(int argc, const char **argv, const char *prefix,\n+\t       struct repository *repo UNUSED)\n {\n \tint i;\n \tstruct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;\n@@ -70,7 +71,7 @@ static int run(int argc, const char **argv, const char *prefix)\n int cmd_hook(int argc,\n \t     const char **argv,\n \t     const char *prefix,\n-\t     struct repository *repo UNUSED)\n+\t     struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_hook_options[] = {\n@@ -81,5 +82,5 @@ int cmd_hook(int argc,\n \targc = parse_options(argc, argv, NULL, builtin_hook_options,\n \t\t\t     builtin_hook_usage, 0);\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex d159ed1314d912a390ed725659b3abe7c821b83f..85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -119,7 +119,8 @@ static void read_packs_from_stdin(struct string_list *to)\n }\n \n static int cmd_multi_pack_index_write(int argc, const char **argv,\n-\t\t\t\t      const char *prefix)\n+\t\t\t\t      const char *prefix,\n+\t\t\t\t      struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_write_options[] = {\n@@ -183,7 +184,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n }\n \n static int cmd_multi_pack_index_verify(int argc, const char **argv,\n-\t\t\t\t       const char *prefix)\n+\t\t\t\t       const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_verify_options[] = {\n@@ -210,7 +212,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n }\n \n static int cmd_multi_pack_index_expire(int argc, const char **argv,\n-\t\t\t\t       const char *prefix)\n+\t\t\t\t       const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_expire_options[] = {\n@@ -237,7 +240,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n }\n \n static int cmd_multi_pack_index_repack(int argc, const char **argv,\n-\t\t\t\t       const char *prefix)\n+\t\t\t\t       const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_repack_options[] = {\n@@ -271,7 +275,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n int cmd_multi_pack_index(int argc,\n \t\t\t const char **argv,\n \t\t\t const char *prefix,\n-\t\t\t struct repository *repo UNUSED)\n+\t\t\t struct repository *repo)\n {\n \tint res;\n \tparse_opt_subcommand_fn *fn = NULL;\n@@ -297,7 +301,7 @@ int cmd_multi_pack_index(int argc,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n \tFREE_AND_NULL(options);\n \n-\tres = fn(argc, argv, prefix);\n+\tres = fn(argc, argv, prefix, repo);\n \n \tfree(opts.object_dir);\n \treturn res;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 72c8a51cfacf72e1f115774487311b3d4464d204..d051abf6dff8f2bce193fd52b4beda5060af3972 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -431,7 +431,8 @@ static struct notes_tree *init_notes_check(const char *subcommand,\n \treturn t;\n }\n \n-static int list(int argc, const char **argv, const char *prefix)\n+static int list(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tstruct notes_tree *t;\n \tstruct object_id object;\n@@ -468,9 +469,11 @@ static int list(int argc, const char **argv, const char *prefix)\n \treturn retval;\n }\n \n-static int append_edit(int argc, const char **argv, const char *prefix);\n+static int append_edit(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED);\n \n-static int add(int argc, const char **argv, const char *prefix)\n+static int add(int argc, const char **argv, const char *prefix,\n+\t       struct repository *repo)\n {\n \tint force = 0, allow_empty = 0;\n \tconst char *object_ref;\n@@ -543,7 +546,7 @@ static int add(int argc, const char **argv, const char *prefix)\n \t\t\t * argv[0-1].\n \t\t\t */\n \t\t\targv[0] = \"edit\";\n-\t\t\treturn append_edit(argc, argv, prefix);\n+\t\t\treturn append_edit(argc, argv, prefix, repo);\n \t\t}\n \t\tfprintf(stderr, _(\"Overwriting existing notes for object %s\\n\"),\n \t\t\toid_to_hex(&object));\n@@ -569,7 +572,8 @@ static int add(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int copy(int argc, const char **argv, const char *prefix)\n+static int copy(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tint retval = 0, force = 0, from_stdin = 0;\n \tconst struct object_id *from_note, *note;\n@@ -646,7 +650,8 @@ static int copy(int argc, const char **argv, const char *prefix)\n \treturn retval;\n }\n \n-static int append_edit(int argc, const char **argv, const char *prefix)\n+static int append_edit(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tint allow_empty = 0;\n \tconst char *object_ref;\n@@ -749,7 +754,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int show(int argc, const char **argv, const char *prefix)\n+static int show(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tconst char *object_ref;\n \tstruct notes_tree *t;\n@@ -875,7 +881,8 @@ static int git_config_get_notes_strategy(const char *key,\n \treturn 0;\n }\n \n-static int merge(int argc, const char **argv, const char *prefix)\n+static int merge(int argc, const char **argv, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tstruct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;\n \tstruct object_id result_oid;\n@@ -1016,7 +1023,8 @@ static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag\n \treturn (flag & IGNORE_MISSING) ? 0 : status;\n }\n \n-static int remove_cmd(int argc, const char **argv, const char *prefix)\n+static int remove_cmd(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tunsigned flag = 0;\n \tint from_stdin = 0;\n@@ -1059,7 +1067,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n \treturn retval;\n }\n \n-static int prune(int argc, const char **argv, const char *prefix)\n+static int prune(int argc, const char **argv, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tstruct notes_tree *t;\n \tint show_only = 0, verbose = 0;\n@@ -1088,7 +1097,8 @@ static int prune(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int get_ref(int argc, const char **argv, const char *prefix)\n+static int get_ref(int argc, const char **argv, const char *prefix,\n+\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = { OPT_END() };\n \tchar *notes_ref;\n@@ -1109,7 +1119,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)\n int cmd_notes(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tconst char *override_notes_ref = NULL;\n \tparse_opt_subcommand_fn *fn = NULL;\n@@ -1148,5 +1158,5 @@ int cmd_notes(int argc,\n \t\tstrbuf_release(&sb);\n \t}\n \n-\treturn !!fn(argc, argv, prefix);\n+\treturn !!fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 22df6834f71098ab8378e4423967f0fb87858340..5a0c22f2f7e58733ce636619f3f19265b394bde5 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -234,7 +234,8 @@ static int expire_total_callback(const struct option *opt,\n \treturn 0;\n }\n \n-static int cmd_reflog_show(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_show(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -253,7 +254,8 @@ static int show_reflog(const char *refname, void *cb_data UNUSED)\n \treturn 0;\n }\n \n-static int cmd_reflog_list(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_list(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -270,7 +272,8 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix)\n \treturn refs_for_each_reflog(ref_store, show_reflog, NULL);\n }\n \n-static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct cmd_reflog_expire_cb cmd = { 0 };\n \ttimestamp_t now = time(NULL);\n@@ -394,7 +397,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)\n \treturn status;\n }\n \n-static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_delete(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint i, status = 0;\n \tunsigned int flags = 0;\n@@ -424,7 +428,8 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)\n \treturn status;\n }\n \n-static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)\n+static int cmd_reflog_exists(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -467,7 +472,7 @@ int cmd_reflog(int argc,\n \t\t\t     PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (fn)\n-\t\treturn fn(argc - 1, argv + 1, prefix);\n+\t\treturn fn(argc - 1, argv + 1, prefix, repository);\n \telse\n \t\treturn cmd_log_reflog(argc, argv, prefix, repository);\n }\ndiff --git a/builtin/refs.c b/builtin/refs.c\nindex 24978a7b7b081ac6ed8ca99016f201d34c0639f8..3502980d21d055d8fc5ef36d2165aae61bc4db62 100644\n--- a/builtin/refs.c\n+++ b/builtin/refs.c\n@@ -12,7 +12,8 @@\n #define REFS_VERIFY_USAGE \\\n \tN_(\"git refs verify [--strict] [--verbose]\")\n \n-static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)\n+static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,\n+\t\t\t    struct repository *repo UNUSED)\n {\n \tconst char * const migrate_usage[] = {\n \t\tREFS_MIGRATE_USAGE,\n@@ -63,7 +64,8 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)\n \treturn err;\n }\n \n-static int cmd_refs_verify(int argc, const char **argv, const char *prefix)\n+static int cmd_refs_verify(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT;\n \tconst char * const verify_usage[] = {\n@@ -93,7 +95,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)\n int cmd_refs(int argc,\n \t     const char **argv,\n \t     const char *prefix,\n-\t     struct repository *repo UNUSED)\n+\t     struct repository *repo)\n {\n \tconst char * const refs_usage[] = {\n \t\tREFS_MIGRATE_USAGE,\n@@ -108,5 +110,5 @@ int cmd_refs(int argc,\n \t};\n \n \targc = parse_options(argc, argv, prefix, opts, refs_usage, 0);\n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 76670ddd8b44e5b118c76522613c445ad92c5364..56214775df4ce86bf5d8e4ddb8d19140f696aeef 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -155,7 +155,8 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not)\n \treturn 0;\n }\n \n-static int add(int argc, const char **argv, const char *prefix)\n+static int add(int argc, const char **argv, const char *prefix,\n+\t       struct repository *repo UNUSED)\n {\n \tint fetch = 0, fetch_tags = TAGS_DEFAULT;\n \tunsigned mirror = MIRROR_NONE;\n@@ -706,7 +707,8 @@ static void handle_push_default(const char* old_name, const char* new_name)\n }\n \n \n-static int mv(int argc, const char **argv, const char *prefix)\n+static int mv(int argc, const char **argv, const char *prefix,\n+\t      struct repository *repo UNUSED)\n {\n \tint show_progress = isatty(2);\n \tstruct option options[] = {\n@@ -881,7 +883,8 @@ static int mv(int argc, const char **argv, const char *prefix)\n \treturn result;\n }\n \n-static int rm(int argc, const char **argv, const char *prefix)\n+static int rm(int argc, const char **argv, const char *prefix,\n+\t      struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -1303,7 +1306,8 @@ static int show_all(void)\n \treturn result;\n }\n \n-static int show(int argc, const char **argv, const char *prefix)\n+static int show(int argc, const char **argv, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tint no_query = 0, result = 0, query_flag = 0;\n \tstruct option options[] = {\n@@ -1399,7 +1403,8 @@ static int show(int argc, const char **argv, const char *prefix)\n \treturn result;\n }\n \n-static int set_head(int argc, const char **argv, const char *prefix)\n+static int set_head(int argc, const char **argv, const char *prefix,\n+\t\t    struct repository *repo UNUSED)\n {\n \tint i, opt_a = 0, opt_d = 0, result = 0;\n \tstruct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;\n@@ -1503,7 +1508,8 @@ static int prune_remote(const char *remote, int dry_run)\n \treturn result;\n }\n \n-static int prune(int argc, const char **argv, const char *prefix)\n+static int prune(int argc, const char **argv, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tint dry_run = 0, result = 0;\n \tstruct option options[] = {\n@@ -1534,7 +1540,8 @@ static int get_remote_default(const char *key, const char *value UNUSED,\n \treturn 0;\n }\n \n-static int update(int argc, const char **argv, const char *prefix)\n+static int update(int argc, const char **argv, const char *prefix,\n+\t\t  struct repository *repo UNUSED)\n {\n \tint i, prune = -1;\n \tstruct option options[] = {\n@@ -1616,7 +1623,8 @@ static int set_remote_branches(const char *remotename, const char **branches,\n \treturn 0;\n }\n \n-static int set_branches(int argc, const char **argv, const char *prefix)\n+static int set_branches(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint add_mode = 0;\n \tstruct option options[] = {\n@@ -1635,7 +1643,8 @@ static int set_branches(int argc, const char **argv, const char *prefix)\n \treturn set_remote_branches(argv[0], argv + 1, add_mode);\n }\n \n-static int get_url(int argc, const char **argv, const char *prefix)\n+static int get_url(int argc, const char **argv, const char *prefix,\n+\t\t   struct repository *repo UNUSED)\n {\n \tint i, push_mode = 0, all_mode = 0;\n \tconst char *remotename = NULL;\n@@ -1674,7 +1683,8 @@ static int get_url(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static int set_url(int argc, const char **argv, const char *prefix)\n+static int set_url(int argc, const char **argv, const char *prefix,\n+\t\t   struct repository *repo UNUSED)\n {\n \tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n \tint matches = 0, negative_matches = 0;\n@@ -1765,7 +1775,7 @@ static int set_url(int argc, const char **argv, const char *prefix)\n int cmd_remote(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n@@ -1788,7 +1798,7 @@ int cmd_remote(int argc,\n \t\t\t     PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \n \tif (fn) {\n-\t\treturn !!fn(argc, argv, prefix);\n+\t\treturn !!fn(argc, argv, prefix, repo);\n \t} else {\n \t\tif (argc) {\n \t\t\terror(_(\"unknown subcommand: `%s'\"), argv[0]);\ndiff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\nindex 49aedc1de81a17b8b491cded7fa71b384e0e8be9..6f5fa5893b839fe21fef44ecbd837d132ebbac26 100644\n--- a/builtin/sparse-checkout.c\n+++ b/builtin/sparse-checkout.c\n@@ -48,7 +48,8 @@ static char const * const builtin_sparse_checkout_list_usage[] = {\n \tNULL\n };\n \n-static int sparse_checkout_list(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_list(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_list_options[] = {\n \t\tOPT_END(),\n@@ -443,7 +444,8 @@ static struct sparse_checkout_init_opts {\n \tint sparse_index;\n } init_opts;\n \n-static int sparse_checkout_init(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_init(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tstruct pattern_list pl;\n \tchar *sparse_filename;\n@@ -770,7 +772,8 @@ static struct sparse_checkout_add_opts {\n \tint use_stdin;\n } add_opts;\n \n-static int sparse_checkout_add(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_add(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_add_options[] = {\n \t\tOPT_BOOL_F(0, \"skip-checks\", &add_opts.skip_checks,\n@@ -808,7 +811,8 @@ static struct sparse_checkout_set_opts {\n \tint use_stdin;\n } set_opts;\n \n-static int sparse_checkout_set(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_set(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED)\n {\n \tint default_patterns_nr = 2;\n \tconst char *default_patterns[] = {\"/*\", \"!/*/\", NULL};\n@@ -866,7 +870,8 @@ static struct sparse_checkout_reapply_opts {\n } reapply_opts;\n \n static int sparse_checkout_reapply(int argc, const char **argv,\n-\t\t\t\t   const char *prefix)\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_reapply_options[] = {\n \t\tOPT_BOOL(0, \"cone\", &reapply_opts.cone_mode,\n@@ -901,7 +906,8 @@ static char const * const builtin_sparse_checkout_disable_usage[] = {\n };\n \n static int sparse_checkout_disable(int argc, const char **argv,\n-\t\t\t\t   const char *prefix)\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_disable_options[] = {\n \t\tOPT_END(),\n@@ -989,7 +995,8 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {\n \treturn 0;\n }\n \n-static int sparse_checkout_check_rules(int argc, const char **argv, const char *prefix)\n+static int sparse_checkout_check_rules(int argc, const char **argv, const char *prefix,\n+\t\t\t\t       struct repository *repo UNUSED)\n {\n \tstatic struct option builtin_sparse_checkout_check_rules_options[] = {\n \t\tOPT_BOOL('z', NULL, &check_rules_opts.null_termination,\n@@ -1037,7 +1044,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *\n int cmd_sparse_checkout(int argc,\n \t\t\tconst char **argv,\n \t\t\tconst char *prefix,\n-\t\t\tstruct repository *repo UNUSED)\n+\t\t\tstruct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_sparse_checkout_options[] = {\n@@ -1060,5 +1067,5 @@ int cmd_sparse_checkout(int argc,\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex 1399a1bbe2c222ed3e1c33ac2dd17bd1148f709c..c212b1c0b2c7c55de2fdd5d7d7a247ce6f530960 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -249,7 +249,8 @@ static int do_clear_stash(void)\n \t\t\t       ref_stash, &obj, 0);\n }\n \n-static int clear_stash(int argc, const char **argv, const char *prefix)\n+static int clear_stash(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -652,7 +653,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,\n \treturn ret;\n }\n \n-static int apply_stash(int argc, const char **argv, const char *prefix)\n+static int apply_stash(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tint quiet = 0;\n@@ -726,7 +728,8 @@ static int get_stash_info_assert(struct stash_info *info, int argc,\n \treturn 0;\n }\n \n-static int drop_stash(int argc, const char **argv, const char *prefix)\n+static int drop_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tint quiet = 0;\n@@ -748,7 +751,8 @@ static int drop_stash(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int pop_stash(int argc, const char **argv, const char *prefix)\n+static int pop_stash(int argc, const char **argv, const char *prefix,\n+\t\t     struct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tint index = 0;\n@@ -778,7 +782,8 @@ static int pop_stash(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int branch_stash(int argc, const char **argv, const char *prefix)\n+static int branch_stash(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint ret = -1;\n \tconst char *branch = NULL;\n@@ -816,7 +821,8 @@ static int branch_stash(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int list_stash(int argc, const char **argv, const char *prefix)\n+static int list_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \tstruct option options[] = {\n@@ -889,7 +895,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op\n \tdo_diff_cache(&info->b_commit, diff_opt);\n }\n \n-static int show_stash(int argc, const char **argv, const char *prefix)\n+static int show_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint i;\n \tint ret = -1;\n@@ -1017,7 +1024,8 @@ static int do_store_stash(const struct object_id *w_commit, const char *stash_ms\n \treturn 0;\n }\n \n-static int store_stash(int argc, const char **argv, const char *prefix)\n+static int store_stash(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tint quiet = 0;\n \tconst char *stash_msg = NULL;\n@@ -1491,7 +1499,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b\n \treturn ret;\n }\n \n-static int create_stash(int argc, const char **argv, const char *prefix UNUSED)\n+static int create_stash(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint ret;\n \tstruct strbuf stash_msg_buf = STRBUF_INIT;\n@@ -1827,12 +1836,14 @@ static int push_stash(int argc, const char **argv, const char *prefix,\n \treturn ret;\n }\n \n-static int push_stash_unassumed(int argc, const char **argv, const char *prefix)\n+static int push_stash_unassumed(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \treturn push_stash(argc, argv, prefix, 0);\n }\n \n-static int save_stash(int argc, const char **argv, const char *prefix)\n+static int save_stash(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint keep_index = -1;\n \tint only_staged = 0;\n@@ -1878,7 +1889,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)\n int cmd_stash(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tpid_t pid = getpid();\n \tconst char *index_file;\n@@ -1916,9 +1927,9 @@ int cmd_stash(int argc,\n \t\t    (uintmax_t)pid);\n \n \tif (fn)\n-\t\treturn !!fn(argc, argv, prefix);\n+\t\treturn !!fn(argc, argv, prefix, repo);\n \telse if (!argc)\n-\t\treturn !!push_stash_unassumed(0, NULL, prefix);\n+\t\treturn !!push_stash_unassumed(0, NULL, prefix, repo);\n \n \t/* Assume 'stash push' */\n \tstrvec_push(&args, \"push\");\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex b6b5f1ebde7c2e4780af4097a0c4d6d838948aee..19e587838132f26e2e10dc4a9f93f7b1c78cd49d 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -399,7 +399,8 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,\n \tfree(displaypath);\n }\n \n-static int module_foreach(int argc, const char **argv, const char *prefix)\n+static int module_foreach(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct foreach_cb info = FOREACH_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -544,7 +545,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data\n \t\t       info->flags);\n }\n \n-static int module_init(int argc, const char **argv, const char *prefix)\n+static int module_init(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct init_cb info = INIT_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -738,7 +740,8 @@ static void status_submodule_cb(const struct cache_entry *list_item,\n \t\t\t info->prefix, info->super_prefix, info->flags);\n }\n \n-static int module_status(int argc, const char **argv, const char *prefix)\n+static int module_status(int argc, const char **argv, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tstruct status_cb info = STATUS_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -1163,7 +1166,8 @@ static int compute_summary_module_list(struct object_id *head_oid,\n \treturn ret;\n }\n \n-static int module_summary(int argc, const char **argv, const char *prefix)\n+static int module_summary(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct summary_cb info = SUMMARY_CB_INIT;\n \tint cached = 0;\n@@ -1339,7 +1343,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data\n \t\t       info->flags);\n }\n \n-static int module_sync(int argc, const char **argv, const char *prefix)\n+static int module_sync(int argc, const char **argv, const char *prefix,\n+\t\t       struct repository *repo UNUSED)\n {\n \tstruct sync_cb info = SYNC_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -1485,7 +1490,8 @@ static void deinit_submodule_cb(const struct cache_entry *list_item,\n \tdeinit_submodule(list_item->name, info->prefix, info->flags);\n }\n \n-static int module_deinit(int argc, const char **argv, const char *prefix)\n+static int module_deinit(int argc, const char **argv, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tstruct deinit_cb info = DEINIT_CB_INIT;\n \tstruct pathspec pathspec = { 0 };\n@@ -1842,7 +1848,8 @@ static int clone_submodule(const struct module_clone_data *clone_data,\n \treturn 0;\n }\n \n-static int module_clone(int argc, const char **argv, const char *prefix)\n+static int module_clone(int argc, const char **argv, const char *prefix,\n+\t\t\tstruct repository *repo UNUSED)\n {\n \tint dissociate = 0, quiet = 0, progress = 0, require_init = 0;\n \tstruct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;\n@@ -2779,7 +2786,8 @@ static int update_submodules(struct update_data *update_data)\n \treturn ret;\n }\n \n-static int module_update(int argc, const char **argv, const char *prefix)\n+static int module_update(int argc, const char **argv, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tstruct pathspec pathspec = { 0 };\n \tstruct pathspec pathspec2 = { 0 };\n@@ -2911,7 +2919,8 @@ static int module_update(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int push_check(int argc, const char **argv, const char *prefix UNUSED)\n+static int push_check(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t      struct repository *repo UNUSED)\n {\n \tstruct remote *remote;\n \tconst char *superproject_head;\n@@ -2991,7 +3000,8 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED)\n \treturn 0;\n }\n \n-static int absorb_git_dirs(int argc, const char **argv, const char *prefix)\n+static int absorb_git_dirs(int argc, const char **argv, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint i;\n \tstruct pathspec pathspec = { 0 };\n@@ -3024,7 +3034,8 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)\n \treturn ret;\n }\n \n-static int module_set_url(int argc, const char **argv, const char *prefix)\n+static int module_set_url(int argc, const char **argv, const char *prefix,\n+\t\t\t  struct repository *repo UNUSED)\n {\n \tint quiet = 0, ret;\n \tconst char *newurl;\n@@ -3063,7 +3074,8 @@ static int module_set_url(int argc, const char **argv, const char *prefix)\n \treturn !!ret;\n }\n \n-static int module_set_branch(int argc, const char **argv, const char *prefix)\n+static int module_set_branch(int argc, const char **argv, const char *prefix,\n+\t\t\t     struct repository *repo UNUSED)\n {\n \tint opt_default = 0, ret;\n \tconst char *opt_branch = NULL;\n@@ -3113,7 +3125,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)\n \treturn !!ret;\n }\n \n-static int module_create_branch(int argc, const char **argv, const char *prefix)\n+static int module_create_branch(int argc, const char **argv, const char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n {\n \tenum branch_track track;\n \tint quiet = 0, force = 0, reflog = 0, dry_run = 0;\n@@ -3424,7 +3437,8 @@ static void die_on_repo_without_commits(const char *path)\n \tstrbuf_release(&sb);\n }\n \n-static int module_add(int argc, const char **argv, const char *prefix)\n+static int module_add(int argc, const char **argv, const char *prefix,\n+\t\t      struct repository *repo UNUSED)\n {\n \tint force = 0, quiet = 0, progress = 0, dissociate = 0;\n \tstruct add_data add_data = ADD_DATA_INIT;\n@@ -3557,7 +3571,7 @@ static int module_add(int argc, const char **argv, const char *prefix)\n int cmd_submodule__helper(int argc,\n \t\t\t  const char **argv,\n \t\t\t  const char *prefix,\n-\t\t\t  struct repository *repo UNUSED)\n+\t\t\t  struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tconst char *const usage[] = {\n@@ -3583,5 +3597,5 @@ int cmd_submodule__helper(int argc,\n \t};\n \targc = parse_options(argc, argv, prefix, options, usage, 0);\n \n-\treturn fn(argc, argv, prefix);\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex dae63dedf4cac2621f51f95a39aa456b33acd894..824dd71d643f112f384cde4de1373698c67de254 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -231,7 +231,8 @@ static void prune_worktrees(void)\n \tstrbuf_release(&reason);\n }\n \n-static int prune(int ac, const char **av, const char *prefix)\n+static int prune(int ac, const char **av, const char *prefix,\n+\t\t struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT__DRY_RUN(&show_only, N_(\"do not remove, show only\")),\n@@ -763,7 +764,8 @@ static char *dwim_branch(const char *path, char **new_branch)\n \treturn NULL;\n }\n \n-static int add(int ac, const char **av, const char *prefix)\n+static int add(int ac, const char **av, const char *prefix,\n+\t       struct repository *repo UNUSED)\n {\n \tstruct add_opts opts;\n \tconst char *new_branch_force = NULL;\n@@ -1039,7 +1041,8 @@ static void pathsort(struct worktree **wt)\n \tQSORT(wt, n, pathcmp);\n }\n \n-static int list(int ac, const char **av, const char *prefix)\n+static int list(int ac, const char **av, const char *prefix,\n+\t\tstruct repository *repo UNUSED)\n {\n \tint porcelain = 0;\n \tint line_terminator = '\\n';\n@@ -1084,7 +1087,8 @@ static int list(int ac, const char **av, const char *prefix)\n \treturn 0;\n }\n \n-static int lock_worktree(int ac, const char **av, const char *prefix)\n+static int lock_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tconst char *reason = \"\", *old_reason;\n \tstruct option options[] = {\n@@ -1119,7 +1123,8 @@ static int lock_worktree(int ac, const char **av, const char *prefix)\n \treturn 0;\n }\n \n-static int unlock_worktree(int ac, const char **av, const char *prefix)\n+static int unlock_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct option options[] = {\n \t\tOPT_END()\n@@ -1182,7 +1187,8 @@ static void validate_no_submodules(const struct worktree *wt)\n \t\tdie(_(\"working trees containing submodules cannot be moved or removed\"));\n }\n \n-static int move_worktree(int ac, const char **av, const char *prefix)\n+static int move_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t struct repository *repo UNUSED)\n {\n \tint force = 0;\n \tstruct option options[] = {\n@@ -1312,7 +1318,8 @@ static int delete_git_work_tree(struct worktree *wt)\n \treturn ret;\n }\n \n-static int remove_worktree(int ac, const char **av, const char *prefix)\n+static int remove_worktree(int ac, const char **av, const char *prefix,\n+\t\t\t   struct repository *repo UNUSED)\n {\n \tint force = 0;\n \tstruct option options[] = {\n@@ -1377,7 +1384,8 @@ static void report_repair(int iserr, const char *path, const char *msg, void *cb\n \t}\n }\n \n-static int repair(int ac, const char **av, const char *prefix)\n+static int repair(int ac, const char **av, const char *prefix,\n+\t\t  struct repository *repo UNUSED)\n {\n \tconst char **p;\n \tconst char *self[] = { \".\", NULL };\n@@ -1397,7 +1405,7 @@ static int repair(int ac, const char **av, const char *prefix)\n int cmd_worktree(int ac,\n \t\t const char **av,\n \t\t const char *prefix,\n-\t\t struct repository *repo UNUSED)\n+\t\t struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n@@ -1422,5 +1430,5 @@ int cmd_worktree(int ac,\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\treturn fn(ac, av, prefix);\n+\treturn fn(ac, av, prefix, repo);\n }\ndiff --git a/parse-options.h b/parse-options.h\nindex ae15342390837c21503ab812648a7d8fd21432a8..f0801d4532a175b65783689f2a68fb56da2c8e87 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -3,6 +3,8 @@\n \n #include \"gettext.h\"\n \n+struct repository;\n+\n /**\n  * Refer to Documentation/technical/api-parse-options.txt for the API doc.\n  */\n@@ -73,7 +75,7 @@ typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,\n \t\t\t\t\t      const char *arg, int unset);\n \n typedef int parse_opt_subcommand_fn(int argc, const char **argv,\n-\t\t\t\t    const char *prefix);\n+\t\t\t\t    const char *prefix, struct repository *repo);\n \n /*\n  * `type`::\ndiff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c\nindex 5250913d99eba18a28878d3904cb7b2399670d02..5da359486cdcb353b277653111bc201c5f82851e 100644\n--- a/t/helper/test-parse-options.c\n+++ b/t/helper/test-parse-options.c\n@@ -282,14 +282,16 @@ int cmd__parse_options_flags(int argc, const char **argv)\n \treturn parse_options_flags__cmd(argc, argv, test_flags);\n }\n \n-static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED)\n+static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t      struct repository *repo UNUSED)\n {\n \tprintf(\"fn: subcmd_one\\n\");\n \tprint_args(argc, argv);\n \treturn 0;\n }\n \n-static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED)\n+static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED,\n+\t\t      struct repository *repo UNUSED)\n {\n \tprintf(\"fn: subcmd_two\\n\");\n \tprint_args(argc, argv);\n@@ -319,7 +321,7 @@ static int parse_subcommand__cmd(int argc, const char **argv,\n \n \tprintf(\"opt: %d\\n\", opt);\n \n-\treturn fn(argc, argv, NULL);\n+\treturn fn(argc, argv, NULL, NULL);\n }\n \n int cmd__parse_subcommand(int argc, const char **argv)\n\n-- \n2.47.0\n\n"},{"id":"507618","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-3-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:42Z","receivedAt":"2024-11-19T15:37:03Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `read_refs_snapshot` uses the `parse_oid_hex` function which\ninternally uses global variables. Let's instead use\n`parse_oid_hex_algop` and provide the hash algo via `revs->repo`.\n\nAlso, while here, fix a missing newline after the functions definition.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 22b5233f51ec6c6d99b8f9613818f1581dca5982..564438f616f59cd24edda956e4af0e0acf167138 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -760,7 +760,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n \t\t\thex = &buf.buf[1];\n \t\t}\n \n-\t\tif (parse_oid_hex(hex, &oid, &end) < 0)\n+\t\tif (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0)\n \t\t\tdie(_(\"could not parse line: %s\"), buf.buf);\n \t\tif (*end)\n \t\t\tdie(_(\"malformed line: %s\"), buf.buf);\n@@ -776,6 +776,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n \tstrbuf_release(&buf);\n \treturn 0;\n }\n+\n static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr_p,\n \t\t\t\t\t\t    const char *refs_snapshot,\n \t\t\t\t\t\t    struct write_midx_context *ctx)\n\n-- \n2.47.0\n\n"},{"id":"507619","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-5-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 05/10] midx-write: pass down repository to `write_midx_file[_only]`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:44Z","receivedAt":"2024-11-19T15:37:04Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In a previous commit, we passed the repository field to all\nsubcommands in the `builtin/` directory. Utilize this to pass the\nrepository field down to the `write_midx_file[_only]` functions to\nremove the usage of `the_repository` global variables.\n\nWith this, all usage of global variables in `midx-write.c` is removed,\nhence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/multi-pack-index.c |  6 +++---\n builtin/repack.c           |  2 +-\n midx-write.c               | 22 +++++++++-------------\n midx.h                     | 10 ++++------\n 4 files changed, 17 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0..2a938466f53aaa11096170554fe11a4ed46a25e4 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to)\n \n static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n-\t\t\t\t      struct repository *repo UNUSED)\n+\t\t\t\t      struct repository *repo)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_write_options[] = {\n@@ -165,7 +165,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t\tread_packs_from_stdin(&packs);\n \n-\t\tret = write_midx_file_only(opts.object_dir, &packs,\n+\t\tret = write_midx_file_only(repo, opts.object_dir, &packs,\n \t\t\t\t\t   opts.preferred_pack,\n \t\t\t\t\t   opts.refs_snapshot, opts.flags);\n \n@@ -176,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t}\n \n-\tret = write_midx_file(opts.object_dir, opts.preferred_pack,\n+\tret = write_midx_file(repo, opts.object_dir, opts.preferred_pack,\n \t\t\t      opts.refs_snapshot, opts.flags);\n \n \tfree(opts.refs_snapshot);\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 96a4fa234bddfd2b63c8d9733379d9b1012a4014..9c21fc482dfb387c818c0d0a74f781848b5a0953 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1569,7 +1569,7 @@ int cmd_repack(int argc,\n \t\tunsigned flags = 0;\n \t\tif (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))\n \t\t\tflags |= MIDX_WRITE_INCREMENTAL;\n-\t\twrite_midx_file(repo_get_object_directory(the_repository),\n+\t\twrite_midx_file(the_repository, repo_get_object_directory(the_repository),\n \t\t\t\tNULL, NULL, flags);\n \t}\n \ndiff --git a/midx-write.c b/midx-write.c\nindex 1c355cdf8db4e9fed61a4aabf61a237ad26181ce..1bc2f5256916e69924245951f654c1047ffeab84 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -1505,24 +1503,22 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \treturn result;\n }\n \n-int write_midx_file(const char *object_dir,\n+int write_midx_file(struct repository *r, const char *object_dir,\n \t\t    const char *preferred_pack_name,\n-\t\t    const char *refs_snapshot,\n-\t\t    unsigned flags)\n+\t\t    const char *refs_snapshot, unsigned flags)\n {\n-\treturn write_midx_internal(the_repository, object_dir, NULL, NULL,\n-\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n+\treturn write_midx_internal(r, object_dir, NULL, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot,\n+\t\t\t\t   flags);\n }\n \n-int write_midx_file_only(const char *object_dir,\n+int write_midx_file_only(struct repository *r, const char *object_dir,\n \t\t\t struct string_list *packs_to_include,\n \t\t\t const char *preferred_pack_name,\n-\t\t\t const char *refs_snapshot,\n-\t\t\t unsigned flags)\n+\t\t\t const char *refs_snapshot, unsigned flags)\n {\n-\treturn write_midx_internal(the_repository, object_dir, packs_to_include,\n-\t\t\t\t   NULL, preferred_pack_name, refs_snapshot,\n-\t\t\t\t   flags);\n+\treturn write_midx_internal(r, object_dir, packs_to_include, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n }\n \n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)\ndiff --git a/midx.h b/midx.h\nindex 3b0ac4d8788b373c59fe69ca2d78e9d914702bc0..c37ad5b5242b56d21fd76bd59957a1bdb82786ec 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -123,15 +123,13 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i\n  * Variant of write_midx_file which writes a MIDX containing only the packs\n  * specified in packs_to_include.\n  */\n-int write_midx_file(const char *object_dir,\n-\t\t    const char *preferred_pack_name,\n-\t\t    const char *refs_snapshot,\n+int write_midx_file(struct repository *r, const char *object_dir,\n+\t\t    const char *preferred_pack_name, const char *refs_snapshot,\n \t\t    unsigned flags);\n-int write_midx_file_only(const char *object_dir,\n+int write_midx_file_only(struct repository *r, const char *object_dir,\n \t\t\t struct string_list *packs_to_include,\n \t\t\t const char *preferred_pack_name,\n-\t\t\t const char *refs_snapshot,\n-\t\t\t unsigned flags);\n+\t\t\t const char *refs_snapshot, unsigned flags);\n void clear_midx_file(struct repository *r);\n int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);\n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);\n\n-- \n2.47.0\n\n"},{"id":"507621","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-6-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 06/10] midx: cleanup internal usage of `the_repository` and `the_hash_algo`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:45Z","receivedAt":"2024-11-19T15:37:05Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In the `midx.c` file, there are multiple usages of `the_repository` and\n`the_hash_algo` within static functions of the file. Some of the usages\ncan be simply swapped out with the available `repository` struct. While\nsome of them can be swapped out by passing the repository to the\nrequired functions.\n\nThis leaves out only some other usages of `the_repository` and\n`the_hash_algo` in the file in non-static functions, which we'll tackle\nin upcoming commits.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c | 49 +++++++++++++++++++++++++++----------------------\n 1 file changed, 27 insertions(+), 22 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 079c45a1aafb658a7b887ac216cc6ecf5f0fb6ff..6f0fb8285af14843da132ef1b0c3a8bdd06732c9 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -25,7 +25,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,\n \n const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n {\n-\treturn m->data + m->data_len - the_hash_algo->rawsz;\n+\treturn m->data + m->data_len - m->repo->hash_algo->rawsz;\n }\n \n void get_midx_filename(struct strbuf *out, const char *object_dir)\n@@ -94,7 +94,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,\n \n #define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n \n-static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir,\n+static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n+\t\t\t\t\t\t\t  const char *object_dir,\n \t\t\t\t\t\t\t  const char *midx_name,\n \t\t\t\t\t\t\t  int local)\n {\n@@ -131,7 +132,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \tm->data = midx_map;\n \tm->data_len = midx_size;\n \tm->local = local;\n-\tm->repo = the_repository;\n+\tm->repo = r;\n \n \tm->signature = get_be32(m->data);\n \tif (m->signature != MIDX_SIGNATURE)\n@@ -144,12 +145,12 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \t\t      m->version);\n \n \thash_version = m->data[MIDX_BYTE_HASH_VERSION];\n-\tif (hash_version != oid_version(the_hash_algo)) {\n+\tif (hash_version != oid_version(r->hash_algo)) {\n \t\terror(_(\"multi-pack-index hash version %u does not match version %u\"),\n-\t\t      hash_version, oid_version(the_hash_algo));\n+\t\t      hash_version, oid_version(r->hash_algo));\n \t\tgoto cleanup_fail;\n \t}\n-\tm->hash_len = the_hash_algo->rawsz;\n+\tm->hash_len = r->hash_algo->rawsz;\n \n \tm->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];\n \n@@ -206,8 +207,8 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \t\t\t      m->pack_names[i]);\n \t}\n \n-\ttrace2_data_intmax(\"midx\", the_repository, \"load/num_packs\", m->num_packs);\n-\ttrace2_data_intmax(\"midx\", the_repository, \"load/num_objects\", m->num_objects);\n+\ttrace2_data_intmax(\"midx\", r, \"load/num_packs\", m->num_packs);\n+\ttrace2_data_intmax(\"midx\", r, \"load/num_objects\", m->num_objects);\n \n \tfree_chunkfile(cf);\n \treturn m;\n@@ -240,8 +241,9 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n \tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n }\n \n-static int open_multi_pack_index_chain(const char *chain_file,\n-\t\t\t\t       int *fd, struct stat *st)\n+static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n+\t\t\t\t       const char *chain_file, int *fd,\n+\t\t\t\t       struct stat *st)\n {\n \t*fd = git_open(chain_file);\n \tif (*fd < 0)\n@@ -250,7 +252,7 @@ static int open_multi_pack_index_chain(const char *chain_file,\n \t\tclose(*fd);\n \t\treturn 0;\n \t}\n-\tif (st->st_size < the_hash_algo->hexsz) {\n+\tif (st->st_size < hash_algo->hexsz) {\n \t\tclose(*fd);\n \t\tif (!st->st_size) {\n \t\t\t/* treat empty files the same as missing */\n@@ -292,7 +294,8 @@ static int add_midx_to_chain(struct multi_pack_index *midx,\n \treturn 1;\n }\n \n-static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n+static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n+\t\t\t\t\t\t      const char *object_dir,\n \t\t\t\t\t\t      int local,\n \t\t\t\t\t\t      int fd, struct stat *st,\n \t\t\t\t\t\t      int *incomplete_chain)\n@@ -303,7 +306,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \tuint32_t i, count;\n \tFILE *fp = xfdopen(fd, \"r\");\n \n-\tcount = st->st_size / (the_hash_algo->hexsz + 1);\n+\tcount = st->st_size / (r->hash_algo->hexsz + 1);\n \n \tfor (i = 0; i < count; i++) {\n \t\tstruct multi_pack_index *m;\n@@ -312,7 +315,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tif (strbuf_getline_lf(&buf, fp) == EOF)\n \t\t\tbreak;\n \n-\t\tif (get_oid_hex(buf.buf, &layer)) {\n+\t\tif (get_oid_hex_algop(buf.buf, &layer, r->hash_algo)) {\n \t\t\twarning(_(\"invalid multi-pack-index chain: line '%s' \"\n \t\t\t\t  \"not a hash\"),\n \t\t\t\tbuf.buf);\n@@ -325,7 +328,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tstrbuf_reset(&buf);\n \t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n \t\t\t\t\t    MIDX_EXT_MIDX);\n-\t\tm = load_multi_pack_index_one(object_dir, buf.buf, local);\n+\t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n \n \t\tif (m) {\n \t\t\tif (add_midx_to_chain(m, midx_chain)) {\n@@ -348,7 +351,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \treturn midx_chain;\n }\n \n-static struct multi_pack_index *load_multi_pack_index_chain(const char *object_dir,\n+static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r,\n+\t\t\t\t\t\t\t    const char *object_dir,\n \t\t\t\t\t\t\t    int local)\n {\n \tstruct strbuf chain_file = STRBUF_INIT;\n@@ -357,10 +361,10 @@ static struct multi_pack_index *load_multi_pack_index_chain(const char *object_d\n \tstruct multi_pack_index *m = NULL;\n \n \tget_midx_chain_filename(&chain_file, object_dir);\n-\tif (open_multi_pack_index_chain(chain_file.buf, &fd, &st)) {\n+\tif (open_multi_pack_index_chain(r->hash_algo, chain_file.buf, &fd, &st)) {\n \t\tint incomplete;\n \t\t/* ownership of fd is taken over by load function */\n-\t\tm = load_midx_chain_fd_st(object_dir, local, fd, &st,\n+\t\tm = load_midx_chain_fd_st(r, object_dir, local, fd, &st,\n \t\t\t\t\t  &incomplete);\n \t}\n \n@@ -376,9 +380,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n \n \tget_midx_filename(&midx_name, object_dir);\n \n-\tm = load_multi_pack_index_one(object_dir, midx_name.buf, local);\n+\tm = load_multi_pack_index_one(the_repository, object_dir,\n+\t\t\t\t      midx_name.buf, local);\n \tif (!m)\n-\t\tm = load_multi_pack_index_chain(object_dir, local);\n+\t\tm = load_multi_pack_index_chain(the_repository, object_dir, local);\n \n \tstrbuf_release(&midx_name);\n \n@@ -520,7 +525,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,\n \t\t     uint32_t *result)\n {\n \tint ret = bsearch_hash(oid->hash, m->chunk_oid_fanout,\n-\t\t\t       m->chunk_oid_lookup, the_hash_algo->rawsz,\n+\t\t\t       m->chunk_oid_lookup, m->repo->hash_algo->rawsz,\n \t\t\t       result);\n \tif (result)\n \t\t*result += m->num_objects_in_base;\n@@ -551,7 +556,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,\n \tn = midx_for_object(&m, n);\n \n \toidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),\n-\t\tthe_repository->hash_algo);\n+\t\tm->repo->hash_algo);\n \treturn oid;\n }\n \n\n-- \n2.47.0\n\n"},{"id":"507622","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-7-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 07/10] midx: pass `repository` to `load_multi_pack_index`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:46Z","receivedAt":"2024-11-19T15:37:06Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `load_multi_pack_index` function in midx uses `the_repository`\nvariable to access the `repository` struct. Modify the function and its\ncallee's to send the `repository` field.\n\nThis moves usage of `the_repository` to the `test-read-midx.c` file.\nWhile that is not optimal, it is okay, since the upcoming commits will\nslowly move the usage of `the_repository` up the layers and remove it\neventually.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c                    | 11 ++++++-----\n midx.h                    |  4 +++-\n t/helper/test-read-midx.c |  8 ++++----\n 3 files changed, 13 insertions(+), 10 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 6f0fb8285af14843da132ef1b0c3a8bdd06732c9..98ee84d4a8bf388906634ad695ff39acdaa2c6d5 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -372,7 +372,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r\n \treturn m;\n }\n \n-struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n+struct multi_pack_index *load_multi_pack_index(struct repository *r,\n+\t\t\t\t\t       const char *object_dir,\n \t\t\t\t\t       int local)\n {\n \tstruct strbuf midx_name = STRBUF_INIT;\n@@ -380,10 +381,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n \n \tget_midx_filename(&midx_name, object_dir);\n \n-\tm = load_multi_pack_index_one(the_repository, object_dir,\n+\tm = load_multi_pack_index_one(r, object_dir,\n \t\t\t\t      midx_name.buf, local);\n \tif (!m)\n-\t\tm = load_multi_pack_index_chain(the_repository, object_dir, local);\n+\t\tm = load_multi_pack_index_chain(r, object_dir, local);\n \n \tstrbuf_release(&midx_name);\n \n@@ -727,7 +728,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i\n \t\tif (!strcmp(object_dir, m_search->object_dir))\n \t\t\treturn 1;\n \n-\tm = load_multi_pack_index(object_dir, local);\n+\tm = load_multi_pack_index(r, object_dir, local);\n \n \tif (m) {\n \t\tstruct multi_pack_index *mp = r->objects->multi_pack_index;\n@@ -881,7 +882,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag\n \tstruct pair_pos_vs_id *pairs = NULL;\n \tuint32_t i;\n \tstruct progress *progress = NULL;\n-\tstruct multi_pack_index *m = load_multi_pack_index(object_dir, 1);\n+\tstruct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1);\n \tstruct multi_pack_index *curr;\n \tverify_midx_error = 0;\n \ndiff --git a/midx.h b/midx.h\nindex c37ad5b5242b56d21fd76bd59957a1bdb82786ec..78efa28d35371795fa33c68660278182debb60ab 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -97,7 +97,9 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext);\n \n-struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);\n+struct multi_pack_index *load_multi_pack_index(struct repository *r,\n+\t\t\t\t\t       const char *object_dir,\n+\t\t\t\t\t       int local);\n int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);\n struct packed_git *nth_midxed_pack(struct multi_pack_index *m,\n \t\t\t\t   uint32_t pack_int_id);\ndiff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c\nindex 438fb9fc6197fc465f79d9a65b719ae315fed373..fc632369618917e2d8cdcb77bd9073c61e1544c1 100644\n--- a/t/helper/test-read-midx.c\n+++ b/t/helper/test-read-midx.c\n@@ -18,7 +18,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,\n \tstruct multi_pack_index *m;\n \n \tsetup_git_directory();\n-\tm = load_multi_pack_index(object_dir, 1);\n+\tm = load_multi_pack_index(the_repository, object_dir, 1);\n \n \tif (!m)\n \t\treturn 1;\n@@ -82,7 +82,7 @@ static int read_midx_checksum(const char *object_dir)\n \tstruct multi_pack_index *m;\n \n \tsetup_git_directory();\n-\tm = load_multi_pack_index(object_dir, 1);\n+\tm = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!m)\n \t\treturn 1;\n \tprintf(\"%s\\n\", hash_to_hex(get_midx_checksum(m)));\n@@ -98,7 +98,7 @@ static int read_midx_preferred_pack(const char *object_dir)\n \n \tsetup_git_directory();\n \n-\tmidx = load_multi_pack_index(object_dir, 1);\n+\tmidx = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!midx)\n \t\treturn 1;\n \n@@ -121,7 +121,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)\n \n \tsetup_git_directory();\n \n-\tmidx = load_multi_pack_index(object_dir, 1);\n+\tmidx = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!midx)\n \t\treturn 1;\n \n\n-- \n2.47.0\n\n"},{"id":"507623","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-8-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 08/10] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:47Z","receivedAt":"2024-11-19T15:37:06Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The function `get_midx_filename_ext` uses `hash_to_hex` which internally\nuses the global variable `the_repository`. To remove this dependency,\npass down the `hash_algo` to both `get_midx_filename` and\n`get_midx_filename_ext`. This adds `the_repository` variable usage to\n`midx-write.c`, which will be resolved in a future commit.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c    | 15 +++++++--------\n midx.c          | 16 +++++++++-------\n midx.h          |  7 +++++--\n pack-bitmap.c   |  6 +++---\n pack-revindex.c |  2 +-\n 5 files changed, 25 insertions(+), 21 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 1bc2f5256916e69924245951f654c1047ffeab84..2f0c09211282fa651af8f9a342f0564729468306 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -991,8 +991,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \tfor (i = 0; i < ARRAY_SIZE(midx_exts); i++) {\n \t\tconst unsigned char *hash = get_midx_checksum(m);\n \n-\t\tget_midx_filename_ext(&from, m->object_dir, hash,\n-\t\t\t\t      midx_exts[i].non_split);\n+\t\tget_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,\n+\t\t\t\t      hash, midx_exts[i].non_split);\n \t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n \t\t\t\t\t    midx_exts[i].split);\n \n@@ -1012,9 +1012,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \treturn ret;\n }\n \n-static void clear_midx_files(const char *object_dir,\n-\t\t\t     const char **hashes,\n-\t\t\t     uint32_t hashes_nr,\n+static void clear_midx_files(struct repository *r, const char *object_dir,\n+\t\t\t     const char **hashes, uint32_t hashes_nr,\n \t\t\t     unsigned incremental)\n {\n \t/*\n@@ -1039,7 +1038,7 @@ static void clear_midx_files(const char *object_dir,\n \t}\n \n \tif (incremental)\n-\t\tget_midx_filename(&buf, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &buf, object_dir);\n \telse\n \t\tget_midx_chain_filename(&buf, object_dir);\n \n@@ -1083,7 +1082,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\t\t    \"%s/pack/multi-pack-index.d/tmp_midx_XXXXXX\",\n \t\t\t    object_dir);\n \telse\n-\t\tget_midx_filename(&midx_name, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &midx_name, object_dir);\n \tif (safe_create_leading_directories(midx_name.buf))\n \t\tdie_errno(_(\"unable to create leading directories of %s\"),\n \t\t\t  midx_name.buf);\n@@ -1474,7 +1473,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \tif (commit_lock_file(&lk) < 0)\n \t\tdie_errno(_(\"could not write multi-pack-index\"));\n \n-\tclear_midx_files(object_dir, keep_hashes,\n+\tclear_midx_files(r, object_dir, keep_hashes,\n \t\t\t ctx.num_multi_pack_indexes_before + 1,\n \t\t\t ctx.incremental);\n \ndiff --git a/midx.c b/midx.c\nindex 98ee84d4a8bf388906634ad695ff39acdaa2c6d5..9bed4185ff4d44602aedfe0329dd840ff9e85435 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -28,17 +28,19 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n \treturn m->data + m->data_len - m->repo->hash_algo->rawsz;\n }\n \n-void get_midx_filename(struct strbuf *out, const char *object_dir)\n+void get_midx_filename(const struct git_hash_algo *hash_algo,\n+\t\t       struct strbuf *out, const char *object_dir)\n {\n-\tget_midx_filename_ext(out, object_dir, NULL, NULL);\n+\tget_midx_filename_ext(hash_algo, out, object_dir, NULL, NULL);\n }\n \n-void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n+void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t   struct strbuf *out, const char *object_dir,\n \t\t\t   const unsigned char *hash, const char *ext)\n {\n \tstrbuf_addf(out, \"%s/pack/multi-pack-index\", object_dir);\n \tif (ext)\n-\t\tstrbuf_addf(out, \"-%s.%s\", hash_to_hex(hash), ext);\n+\t\tstrbuf_addf(out, \"-%s.%s\", hash_to_hex_algop(hash, hash_algo), ext);\n }\n \n static int midx_read_oid_fanout(const unsigned char *chunk_start,\n@@ -379,7 +381,7 @@ struct multi_pack_index *load_multi_pack_index(struct repository *r,\n \tstruct strbuf midx_name = STRBUF_INIT;\n \tstruct multi_pack_index *m;\n \n-\tget_midx_filename(&midx_name, object_dir);\n+\tget_midx_filename(r->hash_algo, &midx_name, object_dir);\n \n \tm = load_multi_pack_index_one(r, object_dir,\n \t\t\t\t      midx_name.buf, local);\n@@ -822,7 +824,7 @@ void clear_midx_file(struct repository *r)\n {\n \tstruct strbuf midx = STRBUF_INIT;\n \n-\tget_midx_filename(&midx, r->objects->odb->path);\n+\tget_midx_filename(r->hash_algo, &midx, r->objects->odb->path);\n \n \tif (r->objects && r->objects->multi_pack_index) {\n \t\tclose_midx(r->objects->multi_pack_index);\n@@ -891,7 +893,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag\n \t\tstruct stat sb;\n \t\tstruct strbuf filename = STRBUF_INIT;\n \n-\t\tget_midx_filename(&filename, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &filename, object_dir);\n \n \t\tif (!stat(filename.buf, &sb)) {\n \t\t\terror(_(\"multi-pack-index file exists, but failed to parse\"));\ndiff --git a/midx.h b/midx.h\nindex 78efa28d35371795fa33c68660278182debb60ab..7620820d4d0272926af9e4eeb68bfb73404c7ec2 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -7,6 +7,7 @@ struct object_id;\n struct pack_entry;\n struct repository;\n struct bitmapped_pack;\n+struct git_hash_algo;\n \n #define MIDX_SIGNATURE 0x4d494458 /* \"MIDX\" */\n #define MIDX_VERSION 1\n@@ -89,8 +90,10 @@ struct multi_pack_index {\n #define MIDX_EXT_MIDX \"midx\"\n \n const unsigned char *get_midx_checksum(struct multi_pack_index *m);\n-void get_midx_filename(struct strbuf *out, const char *object_dir);\n-void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n+void get_midx_filename(const struct git_hash_algo *hash_algo,\n+\t\t       struct strbuf *out, const char *object_dir);\n+void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t   struct strbuf *out, const char *object_dir,\n \t\t\t   const unsigned char *hash, const char *ext);\n void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 0cb1b56c9d5a55936ba53e2ff904ffe46cdcbafc..7b62d099cab5729a60a36b3ad15276fdc351aa97 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -375,8 +375,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)\n char *midx_bitmap_filename(struct multi_pack_index *midx)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tget_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx),\n-\t\t\t      MIDX_EXT_BITMAP);\n+\tget_midx_filename_ext(midx->repo->hash_algo, &buf, midx->object_dir,\n+\t\t\t      get_midx_checksum(midx), MIDX_EXT_BITMAP);\n \n \treturn strbuf_detach(&buf, NULL);\n }\n@@ -415,7 +415,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n \n \tif (bitmap_git->pack || bitmap_git->midx) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tget_midx_filename(&buf, midx->object_dir);\n+\t\tget_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir);\n \t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n \t\t\t\t   \"ignoring extra midx bitmap file\", buf.buf);\n \t\tclose(fd);\ndiff --git a/pack-revindex.c b/pack-revindex.c\nindex 22d3c2346488de6279b6f26a69fe611106c1365a..d3832478d99edffae17db0bbe85aa981c1a3ad30 100644\n--- a/pack-revindex.c\n+++ b/pack-revindex.c\n@@ -383,7 +383,7 @@ int load_midx_revindex(struct multi_pack_index *m)\n \ttrace2_data_string(\"load_midx_revindex\", the_repository,\n \t\t\t   \"source\", \"rev\");\n \n-\tget_midx_filename_ext(&revindex_name, m->object_dir,\n+\tget_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir,\n \t\t\t      get_midx_checksum(m), MIDX_EXT_REV);\n \n \tret = load_revindex_from_disk(revindex_name.buf,\n\n-- \n2.47.0\n\n"},{"id":"507624","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-10-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 10/10] midx: inline the `MIDX_MIN_SIZE` definition","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:49Z","receivedAt":"2024-11-19T15:37:08Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n`local_multi_pack_index_one`. This definitions relies on the\n`the_hash_algo` global variable. Inline this and remove the global\nvariable usage.\n\nWith this, remove `USE_THE_REPOSITORY_VARIABLE` usage from `midx.c`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex f45ea842cd6eda23d2eadc9deaae43839aef24c1..e0eae1c25ec91f7db5670ff9bacdf0e195c35795 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"dir.h\"\n@@ -94,8 +92,6 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,\n \treturn 0;\n }\n \n-#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n-\n static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n \t\t\t\t\t\t\t  const char *object_dir,\n \t\t\t\t\t\t\t  const char *midx_name,\n@@ -122,7 +118,7 @@ static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n \n \tmidx_size = xsize_t(st.st_size);\n \n-\tif (midx_size < MIDX_MIN_SIZE) {\n+\tif (midx_size < (MIDX_HEADER_SIZE + r->hash_algo->rawsz)) {\n \t\terror(_(\"multi-pack-index file %s is too small\"), midx_name);\n \t\tgoto cleanup_fail;\n \t}\n\n-- \n2.47.0\n\n"},{"id":"507626","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-9-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 09/10] midx: pass down `hash_algo` to `get_split_midx_filename_ext`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:48Z","receivedAt":"2024-11-19T15:43:22Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Similar to the previous commit, pass down `hash_algo` to\n`get_split_midx_filename_ext` and use `hash_to_hex_algop`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c |  7 ++++---\n midx.c       | 10 ++++++----\n midx.h       |  3 ++-\n 3 files changed, 12 insertions(+), 8 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 2f0c09211282fa651af8f9a342f0564729468306..bcd1d50eb0f5c292c904a38f13279b1ebec9c855 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -993,7 +993,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \n \t\tget_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,\n \t\t\t\t      hash, midx_exts[i].non_split);\n-\t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n+\t\tget_split_midx_filename_ext(m->repo->hash_algo, &to,\n+\t\t\t\t\t    m->object_dir, hash,\n \t\t\t\t\t    midx_exts[i].split);\n \n \t\tif (link(from.buf, to.buf) < 0 && errno != ENOENT) {\n@@ -1439,8 +1440,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\tif (link_midx_to_chain(ctx.base_midx) < 0)\n \t\t\treturn -1;\n \n-\t\tget_split_midx_filename_ext(&final_midx_name, object_dir,\n-\t\t\t\t\t    midx_hash, MIDX_EXT_MIDX);\n+\t\tget_split_midx_filename_ext(r->hash_algo, &final_midx_name,\n+\t\t\t\t\t    object_dir, midx_hash, MIDX_EXT_MIDX);\n \n \t\tif (rename_tempfile(&incr, final_midx_name.buf) < 0) {\n \t\t\terror_errno(_(\"unable to rename new multi-pack-index layer\"));\ndiff --git a/midx.c b/midx.c\nindex 9bed4185ff4d44602aedfe0329dd840ff9e85435..f45ea842cd6eda23d2eadc9deaae43839aef24c1 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -236,11 +236,13 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir)\n \tstrbuf_addstr(buf, \"/multi-pack-index-chain\");\n }\n \n-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t\t struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext)\n {\n \tget_midx_chain_dirname(buf, object_dir);\n-\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n+\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\",\n+\t\t    hash_to_hex_algop(hash, hash_algo), ext);\n }\n \n static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n@@ -328,8 +330,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n \t\tvalid = 0;\n \n \t\tstrbuf_reset(&buf);\n-\t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n-\t\t\t\t\t    MIDX_EXT_MIDX);\n+\t\tget_split_midx_filename_ext(r->hash_algo, &buf, object_dir,\n+\t\t\t\t\t    layer.hash, MIDX_EXT_MIDX);\n \t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n \n \t\tif (m) {\ndiff --git a/midx.h b/midx.h\nindex 7620820d4d0272926af9e4eeb68bfb73404c7ec2..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -97,7 +97,8 @@ void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n \t\t\t   const unsigned char *hash, const char *ext);\n void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t\t struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext);\n \n struct multi_pack_index *load_multi_pack_index(struct repository *r,\n\n-- \n2.47.0\n\n"},{"id":"507627","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-2-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 02/10] midx-write: pass down repository to static functions","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:41Z","receivedAt":"2024-11-19T15:45:28Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In 'midx-write.c' there are a lot of static functions which use global\nvariables `the_repository` or `the_hash_algo`. In a follow up commit,\nthe repository variable will be added to `write_midx_context`, which\nsome of the functions can use. But for functions which do not have\naccess to this struct, pass down the required information from\nnon-static functions `write_midx_file` and `write_midx_file_only`.\n\nThis ensures that the usage of global variables is limited to these\nnon-static functions, which will be cleaned up in a follow up commits.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 57 +++++++++++++++++++++++++++++++--------------------------\n 1 file changed, 31 insertions(+), 26 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex c57726ef9475df693890d61627ce91409c1def7c..22b5233f51ec6c6d99b8f9613818f1581dca5982 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -35,13 +35,13 @@ extern void clear_incremental_midx_files_ext(const char *object_dir,\n extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,\n \t\t\t\tconst char *idx_name);\n \n-static size_t write_midx_header(struct hashfile *f,\n-\t\t\t\tunsigned char num_chunks,\n+static size_t write_midx_header(const struct git_hash_algo *hash_algo,\n+\t\t\t\tstruct hashfile *f, unsigned char num_chunks,\n \t\t\t\tuint32_t num_packs)\n {\n \thashwrite_be32(f, MIDX_SIGNATURE);\n \thashwrite_u8(f, MIDX_VERSION);\n-\thashwrite_u8(f, oid_version(the_hash_algo));\n+\thashwrite_u8(f, oid_version(hash_algo));\n \thashwrite_u8(f, num_chunks);\n \thashwrite_u8(f, 0); /* unused */\n \thashwrite_be32(f, num_packs);\n@@ -702,7 +702,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n \t\treturn 0;\n \t}\n \n-\tif (!peel_iterated_oid(the_repository, oid, &peeled))\n+\tif (!peel_iterated_oid(revs->repo, oid, &peeled))\n \t\toid = &peeled;\n \n \tobject = parse_object_or_die(oid, refname);\n@@ -827,7 +827,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \treturn cb.commits;\n }\n \n-static int write_midx_bitmap(const char *midx_name,\n+static int write_midx_bitmap(struct repository *r, const char *midx_name,\n \t\t\t     const unsigned char *midx_hash,\n \t\t\t     struct packing_data *pdata,\n \t\t\t     struct commit **commits,\n@@ -840,9 +840,9 @@ static int write_midx_bitmap(const char *midx_name,\n \tstruct bitmap_writer writer;\n \tstruct pack_idx_entry **index;\n \tchar *bitmap_name = xstrfmt(\"%s-%s.bitmap\", midx_name,\n-\t\t\t\t\thash_to_hex(midx_hash));\n+\t\t\t\t    hash_to_hex_algop(midx_hash, r->hash_algo));\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_bitmap\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_bitmap\", r);\n \n \tif (flags & MIDX_WRITE_BITMAP_HASH_CACHE)\n \t\toptions |= BITMAP_OPT_HASH_CACHE;\n@@ -859,7 +859,7 @@ static int write_midx_bitmap(const char *midx_name,\n \tfor (i = 0; i < pdata->nr_objects; i++)\n \t\tindex[i] = &pdata->objects[i].idx;\n \n-\tbitmap_writer_init(&writer, the_repository, pdata);\n+\tbitmap_writer_init(&writer, r, pdata);\n \tbitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);\n \tbitmap_writer_build_type_index(&writer, index);\n \n@@ -892,7 +892,7 @@ static int write_midx_bitmap(const char *midx_name,\n \tfree(bitmap_name);\n \tbitmap_writer_free(&writer);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_bitmap\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_bitmap\", r);\n \n \treturn ret;\n }\n@@ -1049,7 +1049,7 @@ static void clear_midx_files(const char *object_dir,\n \tstrbuf_release(&buf);\n }\n \n-static int write_midx_internal(const char *object_dir,\n+static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\t\t       struct string_list *packs_to_include,\n \t\t\t       struct string_list *packs_to_drop,\n \t\t\t       const char *preferred_pack_name,\n@@ -1070,7 +1070,8 @@ static int write_midx_internal(const char *object_dir,\n \tconst char **keep_hashes = NULL;\n \tstruct chunkfile *cf;\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_internal\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_internal\", r);\n+\n \n \tctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);\n \tif (ctx.incremental && (flags & MIDX_WRITE_BITMAP))\n@@ -1087,8 +1088,7 @@ static int write_midx_internal(const char *object_dir,\n \t\t\t  midx_name.buf);\n \n \tif (!packs_to_include || ctx.incremental) {\n-\t\tstruct multi_pack_index *m = lookup_multi_pack_index(the_repository,\n-\t\t\t\t\t\t\t\t     object_dir);\n+\t\tstruct multi_pack_index *m = lookup_multi_pack_index(r, object_dir);\n \t\tif (m && !midx_checksum_valid(m)) {\n \t\t\twarning(_(\"ignoring existing multi-pack-index; checksum mismatch\"));\n \t\t\tm = NULL;\n@@ -1351,7 +1351,7 @@ static int write_midx_internal(const char *object_dir,\n \tadd_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE,\n \t\t  write_midx_oid_fanout);\n \tadd_chunk(cf, MIDX_CHUNKID_OIDLOOKUP,\n-\t\t  st_mult(ctx.entries_nr, the_hash_algo->rawsz),\n+\t\t  st_mult(ctx.entries_nr, r->hash_algo->rawsz),\n \t\t  write_midx_oid_lookup);\n \tadd_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS,\n \t\t  st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH),\n@@ -1373,7 +1373,8 @@ static int write_midx_internal(const char *object_dir,\n \t\t\t  write_midx_bitmapped_packs);\n \t}\n \n-\twrite_midx_header(f, get_num_chunks(cf), ctx.nr - dropped_packs);\n+\twrite_midx_header(r->hash_algo, f, get_num_chunks(cf),\n+\t\t\t  ctx.nr - dropped_packs);\n \twrite_chunkfile(cf, &ctx);\n \n \tfinalize_hashfile(f, midx_hash, FSYNC_COMPONENT_PACK_METADATA,\n@@ -1405,7 +1406,7 @@ static int write_midx_internal(const char *object_dir,\n \t\tFREE_AND_NULL(ctx.entries);\n \t\tctx.entries_nr = 0;\n \n-\t\tif (write_midx_bitmap(midx_name.buf, midx_hash, &pdata,\n+\t\tif (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,\n \t\t\t\t      commits, commits_nr, ctx.pack_order,\n \t\t\t\t      flags) < 0) {\n \t\t\terror(_(\"could not write multi-pack bitmap\"));\n@@ -1449,12 +1450,13 @@ static int write_midx_internal(const char *object_dir,\n \t\tstrbuf_release(&final_midx_name);\n \n \t\tkeep_hashes[ctx.num_multi_pack_indexes_before] =\n-\t\t\txstrdup(hash_to_hex(midx_hash));\n+\t\t\txstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));\n \n \t\tfor (i = 0; i < ctx.num_multi_pack_indexes_before; i++) {\n \t\t\tuint32_t j = ctx.num_multi_pack_indexes_before - i - 1;\n \n-\t\t\tkeep_hashes[j] = xstrdup(hash_to_hex(get_midx_checksum(m)));\n+\t\t\tkeep_hashes[j] = xstrdup(hash_to_hex_algop(get_midx_checksum(m),\n+\t\t\t\t\t\t\t\t   r->hash_algo));\n \t\t\tm = m->base_midx;\n \t\t}\n \n@@ -1462,7 +1464,7 @@ static int write_midx_internal(const char *object_dir,\n \t\t\tfprintf(get_lock_file_fp(&lk), \"%s\\n\", keep_hashes[i]);\n \t} else {\n \t\tkeep_hashes[ctx.num_multi_pack_indexes_before] =\n-\t\t\txstrdup(hash_to_hex(midx_hash));\n+\t\t\txstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));\n \t}\n \n \tif (ctx.m || ctx.base_midx)\n@@ -1495,7 +1497,7 @@ static int write_midx_internal(const char *object_dir,\n \t}\n \tstrbuf_release(&midx_name);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_internal\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_internal\", r);\n \n \treturn result;\n }\n@@ -1505,8 +1507,8 @@ int write_midx_file(const char *object_dir,\n \t\t    const char *refs_snapshot,\n \t\t    unsigned flags)\n {\n-\treturn write_midx_internal(object_dir, NULL, NULL, preferred_pack_name,\n-\t\t\t\t   refs_snapshot, flags);\n+\treturn write_midx_internal(the_repository, object_dir, NULL, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n }\n \n int write_midx_file_only(const char *object_dir,\n@@ -1515,8 +1517,9 @@ int write_midx_file_only(const char *object_dir,\n \t\t\t const char *refs_snapshot,\n \t\t\t unsigned flags)\n {\n-\treturn write_midx_internal(object_dir, packs_to_include, NULL,\n-\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n+\treturn write_midx_internal(the_repository, object_dir, packs_to_include,\n+\t\t\t\t   NULL, preferred_pack_name, refs_snapshot,\n+\t\t\t\t   flags);\n }\n \n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)\n@@ -1572,7 +1575,8 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla\n \tfree(count);\n \n \tif (packs_to_drop.nr)\n-\t\tresult = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags);\n+\t\tresult = write_midx_internal(r, object_dir, NULL,\n+\t\t\t\t\t     &packs_to_drop, NULL, NULL, flags);\n \n \tstring_list_clear(&packs_to_drop, 0);\n \n@@ -1769,7 +1773,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,\n \t\tgoto cleanup;\n \t}\n \n-\tresult = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags);\n+\tresult = write_midx_internal(r, object_dir, NULL, NULL, NULL, NULL,\n+\t\t\t\t     flags);\n \n cleanup:\n \tfree(include_pack);\n\n-- \n2.47.0\n\n"},{"id":"507628","messageId":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-4-e2f607174efc@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v2 04/10] write-midx: add repository field to `write_midx_context`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-19T15:36:43Z","receivedAt":"2024-11-19T15:46:22Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The struct `write_midx_context` is used to pass context for creating\nMIDX files. Add the repository field here to ensure that most functions\nwithin `midx-write.c` have access to the field and can use that instead\nof the global `the_repository` variable.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 38 ++++++++++++++++++++------------------\n 1 file changed, 20 insertions(+), 18 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 564438f616f59cd24edda956e4af0e0acf167138..1c355cdf8db4e9fed61a4aabf61a237ad26181ce 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -110,6 +110,8 @@ struct write_midx_context {\n \tuint32_t num_multi_pack_indexes_before;\n \n \tstruct string_list *to_include;\n+\n+\tstruct repository *repo;\n };\n \n static int should_include_pack(const struct write_midx_context *ctx,\n@@ -154,7 +156,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,\n \t\t\treturn;\n \n \t\tALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);\n-\t\tp = add_packed_git(the_repository, full_path, full_path_len, 0);\n+\t\tp = add_packed_git(ctx->repo, full_path, full_path_len, 0);\n \t\tif (!p) {\n \t\t\twarning(_(\"failed to add packfile '%s'\"),\n \t\t\t\tfull_path);\n@@ -480,7 +482,7 @@ static int write_midx_oid_lookup(struct hashfile *f,\n \t\t\t\t void *data)\n {\n \tstruct write_midx_context *ctx = data;\n-\tunsigned char hash_len = the_hash_algo->rawsz;\n+\tunsigned char hash_len = ctx->repo->hash_algo->rawsz;\n \tstruct pack_midx_entry *list = ctx->entries;\n \tuint32_t i;\n \n@@ -605,7 +607,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n \tuint32_t *pack_order, base_objects = 0;\n \tuint32_t i;\n \n-\ttrace2_region_enter(\"midx\", \"midx_pack_order\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"midx_pack_order\", ctx->repo);\n \n \tif (ctx->incremental && ctx->base_midx)\n \t\tbase_objects = ctx->base_midx->num_objects +\n@@ -640,7 +642,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n \t}\n \tfree(data);\n \n-\ttrace2_region_leave(\"midx\", \"midx_pack_order\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"midx_pack_order\", ctx->repo);\n \n \treturn pack_order;\n }\n@@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n \tstruct strbuf buf = STRBUF_INIT;\n \tchar *tmp_file;\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n \n-\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex(midx_hash));\n+\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex_algop(midx_hash,\n+\t\t\t\t\t\t\t\t    ctx->repo->hash_algo));\n \n \ttmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,\n \t\t\t\t\tmidx_hash, WRITE_REV);\n@@ -664,7 +667,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n \tstrbuf_release(&buf);\n \tfree(tmp_file);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n }\n \n static void prepare_midx_packing_data(struct packing_data *pdata,\n@@ -672,10 +675,10 @@ static void prepare_midx_packing_data(struct packing_data *pdata,\n {\n \tuint32_t i;\n \n-\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n \n \tmemset(pdata, 0, sizeof(struct packing_data));\n-\tprepare_packing_data(the_repository, pdata);\n+\tprepare_packing_data(ctx->repo, pdata);\n \n \tfor (i = 0; i < ctx->entries_nr; i++) {\n \t\tuint32_t pos = ctx->pack_order[i];\n@@ -686,7 +689,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata,\n \t\t\t       ctx->info[ctx->pack_perm[from->pack_int_id]].p);\n \t}\n \n-\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n }\n \n static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n@@ -784,17 +787,16 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \tstruct rev_info revs;\n \tstruct bitmap_commit_cb cb = {0};\n \n-\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\",\n-\t\t\t    the_repository);\n+\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n \n \tcb.ctx = ctx;\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(ctx->repo, &revs, NULL);\n \tif (refs_snapshot) {\n \t\tread_refs_snapshot(refs_snapshot, &revs);\n \t} else {\n \t\tsetup_revisions(0, NULL, &revs, NULL);\n-\t\trefs_for_each_ref(get_main_ref_store(the_repository),\n+\t\trefs_for_each_ref(get_main_ref_store(ctx->repo),\n \t\t\t\t  add_ref_to_pending, &revs);\n \t}\n \n@@ -822,8 +824,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \n \trelease_revisions(&revs);\n \n-\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\",\n-\t\t\t    the_repository);\n+\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n \n \treturn cb.commits;\n }\n@@ -945,7 +946,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,\n \t\t\t */\n \t\t\tif (flags & MIDX_WRITE_REV_INDEX ||\n \t\t\t    preferred_pack_name) {\n-\t\t\t\tif (prepare_midx_pack(the_repository, m,\n+\t\t\t\tif (prepare_midx_pack(ctx->repo, m,\n \t\t\t\t\t\t      m->num_packs_in_base + i)) {\n \t\t\t\t\terror(_(\"could not load pack\"));\n \t\t\t\t\treturn 1;\n@@ -1073,6 +1074,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \n \ttrace2_region_enter(\"midx\", \"write_midx_internal\", r);\n \n+\tctx.repo = r;\n \n \tctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);\n \tif (ctx.incremental && (flags & MIDX_WRITE_BITMAP))\n@@ -1469,7 +1471,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t}\n \n \tif (ctx.m || ctx.base_midx)\n-\t\tclose_object_store(the_repository->objects);\n+\t\tclose_object_store(ctx.repo->objects);\n \n \tif (commit_lock_file(&lk) < 0)\n \t\tdie_errno(_(\"could not write multi-pack-index\"));\n\n-- \n2.47.0\n\n"},{"id":"507732","messageId":"Zz3dAZGAG3BupQqE@ArchLinux","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-3-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2024-11-20T12:58:41Z","receivedAt":"2024-11-20T12:58:35Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Tue, Nov 19, 2024 at 04:36:42PM +0100, Karthik Nayak wrote:\n> The `read_refs_snapshot` uses the `parse_oid_hex` function which\n> internally uses global variables. Let's instead use\n\nNit: s/variables/variable\n\n> `parse_oid_hex_algop` and provide the hash algo via `revs->repo`.\n> \n> Also, while here, fix a missing newline after the functions definition.\n> \n\nNit: s/functions/function\n\n> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n"},{"id":"507733","messageId":"Zz3gguyjTKJ8RY-z@ArchLinux","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-10-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 10/10] midx: inline the `MIDX_MIN_SIZE` definition","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2024-11-20T13:13:38Z","receivedAt":"2024-11-20T13:13:29Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Tue, Nov 19, 2024 at 04:36:49PM +0100, Karthik Nayak wrote:\n> The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n> `local_multi_pack_index_one`. This definitions relies on the\n\nNit: s/definitions/definition\n\n> `the_hash_algo` global variable. Inline this and remove the global\n> variable usage.\n> \n> With this, remove `USE_THE_REPOSITORY_VARIABLE` usage from `midx.c`.\n> \n> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n> ---\n"},{"id":"507765","messageId":"PA4PR07MB74069403837F36FD07D075EB9E212@PA4PR07MB7406.eurprd07.prod.outlook.com","threadId":"62498","inReplyTo":"Zz3dAZGAG3BupQqE@ArchLinux","subject":"RE: [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"Richard Kerry","fromEmail":"richard.kerry@eviden.com","sentAt":"2024-11-20T14:26:23Z","receivedAt":"2024-11-20T14:31:36Z","isPatch":true,"sender":{"key":"richard.kerry@eviden.com","avatar":null},"body":"\n>> The `read_refs_snapshot` uses the `parse_oid_hex` function which \n>> internally uses global variables. Let's instead use\n>\n>Nit: s/variables/variable\n\nNo, that's fine.\nIt's plural, so ends with 's'.\nUnless it should be \"uses a global variable\"\n\n>>\n>> Also, while here, fix a missing newline after the functions definition.\n>>\n>\n>Nit: s/functions/function\n\nMaybe.\nBut it could be \"the function's definition\" as it could be seen as possessive.\n\nRegards,\nRichard.\n\n\n"},{"id":"507768","messageId":"CAP8UFD0RpTXCdeYPA44yiS1E-LsmSHVrGxNKaUFkvUqq+zNTZw@mail.gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-2-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 02/10] midx-write: pass down repository to static functions","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-11-20T18:15:04Z","receivedAt":"2024-11-20T18:15:18Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Tue, Nov 19, 2024 at 5:36 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>\n> In 'midx-write.c' there are a lot of static functions which use global\n> variables `the_repository` or `the_hash_algo`. In a follow up commit,\n> the repository variable will be added to `write_midx_context`, which\n> some of the functions can use. But for functions which do not have\n> access to this struct, pass down the required information from\n> non-static functions `write_midx_file` and `write_midx_file_only`.\n>\n> This ensures that the usage of global variables is limited to these\n> non-static functions, which will be cleaned up in a follow up commits.\n\ns/commits/commit/\n\nThere are a few places in the patch where hash_to_hex() is replaced\nwith hash_to_hex_algop(). However hash_to_hex() is not quite a static\nfunction and is not defined in 'midx-write.c'. So you might want to\nmention this additional change in the commit message.\n\nThanks.\n"},{"id":"507769","messageId":"CAP8UFD3ZuTtd2SckoyvXmkMG3eeGqH3eHSHtda-4o5yGdj6cBg@mail.gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-8-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 08/10] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-11-20T18:15:32Z","receivedAt":"2024-11-20T18:15:46Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Tue, Nov 19, 2024 at 4:39 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>\n> The function `get_midx_filename_ext` uses `hash_to_hex` which internally\n> uses the global variable `the_repository`. To remove this dependency,\n> pass down the `hash_algo` to both `get_midx_filename` and\n> `get_midx_filename_ext`.\n\nTechnically passing down the `hash_algo` to both functions is not\nenough to remove the dependency, as replacing `hash_to_hex()` with\n`hash_to_hex_algop*()` is also needed. It's a bit unclear if\n`hash_to_hex()` calls are replaced with other calls in this patch or\nnot though.\n\nSo you might want to add something like: \"Replacing `hash_to_hex` with\nfunctions that take an `hash_algo` as argument will be done in a\nfollowup commit.\"\n\n\n> This adds `the_repository` variable usage to\n> `midx-write.c`, which will be resolved in a future commit.\n"},{"id":"507770","messageId":"CAP8UFD02a+ZfHo1L5qhbzD2r4bmhXadSj4sy0acPncnj4pcRpg@mail.gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-9-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 09/10] midx: pass down `hash_algo` to `get_split_midx_filename_ext`","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-11-20T18:15:40Z","receivedAt":"2024-11-20T18:15:54Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Tue, Nov 19, 2024 at 4:47 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>\n> Similar to the previous commit, pass down `hash_algo` to\n> `get_split_midx_filename_ext` and use `hash_to_hex_algop`.\n\nI think we prefer explanations in commit messages to be a bit more\nself-contained, and not to rely much only on other commit messages, or\nlinks to a mailing list thread on a mailing list archive, or other\nexternal content. It's better to err on the side of copying more.\n"},{"id":"507771","messageId":"CAP8UFD08qQ2hm98dKfMNEABs19Bbs_O6T6EMLpHOofQ9=A_WpQ@mail.gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-11-20T18:20:33Z","receivedAt":"2024-11-20T18:20:46Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Tue, Nov 19, 2024 at 4:38 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>\n> Similar to the earlier patch series on cleaning up packfile.c and\n> removing usage of global variables [1], we change the midx.c and\n> midx-write.c files to no longer use global variables.\n>\n> This is done by the following:\n>   - Usage of repository variable already available in existing structs.\n>   - Passing down repository variable from other subsystems.\n>   - Modifying all subcommands to obtain repository variable from the\n>   command in `builtins/` and passing down the variable from there.\n>\n> The biggest change is in the first commit, wherein we modify all\n> subcommands to add the repository variable. Since the subcommand\n> definition are not often changed, it shouldn't cause too many conflicts\n> with in flight topics.\n\nOverall I like the way it's done. I found a few improvements that\ncould be made to some commit messages though.\n\nThanks.\n"},{"id":"507780","messageId":"Zz47cIz5EzMLI0h4@nand.local","threadId":"62498","inReplyTo":"CAP8UFD0RpTXCdeYPA44yiS1E-LsmSHVrGxNKaUFkvUqq+zNTZw@mail.gmail.com","subject":"Re: [PATCH v2 02/10] midx-write: pass down repository to static functions","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T19:41:36Z","receivedAt":"2024-11-20T19:41:38Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Nov 20, 2024 at 07:15:04PM +0100, Christian Couder wrote:\n> On Tue, Nov 19, 2024 at 5:36 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n> >\n> > In 'midx-write.c' there are a lot of static functions which use global\n> > variables `the_repository` or `the_hash_algo`. In a follow up commit,\n> > the repository variable will be added to `write_midx_context`, which\n> > some of the functions can use. But for functions which do not have\n> > access to this struct, pass down the required information from\n> > non-static functions `write_midx_file` and `write_midx_file_only`.\n> >\n> > This ensures that the usage of global variables is limited to these\n> > non-static functions, which will be cleaned up in a follow up commits.\n>\n> s/commits/commit/\n\nGood eyes.\n\n> There are a few places in the patch where hash_to_hex() is replaced\n> with hash_to_hex_algop(). However hash_to_hex() is not quite a static\n> function and is not defined in 'midx-write.c'. So you might want to\n> mention this additional change in the commit message.\n\nI think this is fine to leave out personally. Since hash_to_hex()\nrelies on the_hash_algo only, it's natural to expect that when a caller\nhas access to a new variable pointing at a 'struct git_hash_algo' that\nthey would convert that function to hash_to_hex_algop().\n\nThanks,\nTaylor\n"},{"id":"507781","messageId":"Zz472iMq3nZMoRMf@nand.local","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-2-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 02/10] midx-write: pass down repository to static functions","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T19:43:22Z","receivedAt":"2024-11-20T19:43:24Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Nov 19, 2024 at 04:36:41PM +0100, Karthik Nayak wrote:\n> ---\n>  midx-write.c | 57 +++++++++++++++++++++++++++++++--------------------------\n>  1 file changed, 31 insertions(+), 26 deletions(-)\n\nThis patch all seems reasonable to me. When reviewing it in this way, it\nis a little unclear to see which functions need just a repository, just\na hash_algo, or the whole write_midx_context structure.\n\nI think I might have erred on the side of just passing the\nwrite_midx_context structure throughout the midx-write.c internals. That\nexposes more of the implementation details than is strictly necessary,\nbut it does so to the benefit of making the code (and this patch) easier\nto follow.\n\nI don't feel strongly about it, and I trust that you modified the right\nfunctions to pass the right data. I just wanted to mention it in case\nyou hadn't considered an alternative way to structure this patch.\n\nThanks,\nTaylor\n"},{"id":"507782","messageId":"Zz48HXREk6esJ7xX@nand.local","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-3-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T19:44:29Z","receivedAt":"2024-11-20T19:44:31Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Nov 19, 2024 at 04:36:42PM +0100, Karthik Nayak wrote:\n> ---\n>  midx-write.c | 3 ++-\n>  1 file changed, 2 insertions(+), 1 deletion(-)\n>\n> diff --git a/midx-write.c b/midx-write.c\n> index 22b5233f51ec6c6d99b8f9613818f1581dca5982..564438f616f59cd24edda956e4af0e0acf167138 100644\n> --- a/midx-write.c\n> +++ b/midx-write.c\n> @@ -760,7 +760,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n>  \t\t\thex = &buf.buf[1];\n>  \t\t}\n>\n> -\t\tif (parse_oid_hex(hex, &oid, &end) < 0)\n> +\t\tif (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0)\n\nLooks obviously correct.\n\n>  \t\t\tdie(_(\"could not parse line: %s\"), buf.buf);\n>  \t\tif (*end)\n>  \t\t\tdie(_(\"malformed line: %s\"), buf.buf);\n> @@ -776,6 +776,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n>  \tstrbuf_release(&buf);\n>  \treturn 0;\n>  }\n> +\n\nGood spotting :-).\n\nThanks,\nTaylor\n"},{"id":"507783","messageId":"Zz48r6ZZcol6TQaF@nand.local","threadId":"62498","inReplyTo":"PA4PR07MB74069403837F36FD07D075EB9E212@PA4PR07MB7406.eurprd07.prod.outlook.com","subject":"Re: [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T19:46:55Z","receivedAt":"2024-11-20T19:46:58Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Nov 20, 2024 at 02:26:23PM +0000, Richard Kerry wrote:\n>\n> >> The `read_refs_snapshot` uses the `parse_oid_hex` function which\n> >> internally uses global variables. Let's instead use\n> >\n> >Nit: s/variables/variable\n>\n> No, that's fine.\n> It's plural, so ends with 's'.\n> Unless it should be \"uses a global variable\"\n\nThe global variable in question here is just \"the_hash_algo\", so I think\nshejialuo's suggestion to use \"variable\" is correct, but it would need\nto be \"uses a global variable\" instead of \"uses global variable\"\n(without the article).\n\nBut I think we're being unnecessarily vague here, and could instead say:\n\n    The function `read_refs_snapshot()` uses `parse_oid_hex()`, which\n    relies on the global `the_hash_algo` variable. Let's instead use\n    [...]\n\n> >> Also, while here, fix a missing newline after the functions definition.\n> >>\n> >\n> >Nit: s/functions/function\n>\n> Maybe.\n> But it could be \"the function's definition\" as it could be seen as possessive.\n\nIt should be \"function's definition\", as the possessive is the correct\nform.\n\nThanks,\nTaylor\n"},{"id":"507785","messageId":"Zz5CjWrMFozkEBh9@nand.local","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-5-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 05/10] midx-write: pass down repository to `write_midx_file[_only]`","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T20:11:57Z","receivedAt":"2024-11-20T20:11:59Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Nov 19, 2024 at 04:36:44PM +0100, Karthik Nayak wrote:\n> With this, all usage of global variables in `midx-write.c` is removed,\n> hence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n\nVery nicely done :-). Thanks for cleaning these up!\n\nThanks,\nTaylor\n"},{"id":"507786","messageId":"Zz5hYfHLL1vsxdY5@nand.local","threadId":"62498","inReplyTo":"CAP8UFD02a+ZfHo1L5qhbzD2r4bmhXadSj4sy0acPncnj4pcRpg@mail.gmail.com","subject":"Re: [PATCH v2 09/10] midx: pass down `hash_algo` to `get_split_midx_filename_ext`","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T22:23:29Z","receivedAt":"2024-11-20T22:23:32Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Nov 20, 2024 at 07:15:40PM +0100, Christian Couder wrote:\n> On Tue, Nov 19, 2024 at 4:47 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n> >\n> > Similar to the previous commit, pass down `hash_algo` to\n> > `get_split_midx_filename_ext` and use `hash_to_hex_algop`.\n>\n> I think we prefer explanations in commit messages to be a bit more\n> self-contained, and not to rely much only on other commit messages, or\n> links to a mailing list thread on a mailing list archive, or other\n> external content. It's better to err on the side of copying more.\n\nI agree, but in this instance think it would be better to simply\ncombine the two into one. I do not see a reason why these commits should\nbe split.\n\nThanks,\nTaylor\n"},{"id":"507787","messageId":"Zz5hgZ1DM9XRdXqj@nand.local","threadId":"62498","inReplyTo":"CAP8UFD08qQ2hm98dKfMNEABs19Bbs_O6T6EMLpHOofQ9=A_WpQ@mail.gmail.com","subject":"Re: [PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-11-20T22:24:01Z","receivedAt":"2024-11-20T22:24:04Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Nov 20, 2024 at 07:20:33PM +0100, Christian Couder wrote:\n> On Tue, Nov 19, 2024 at 4:38 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n> >\n> > Similar to the earlier patch series on cleaning up packfile.c and\n> > removing usage of global variables [1], we change the midx.c and\n> > midx-write.c files to no longer use global variables.\n> >\n> > This is done by the following:\n> >   - Usage of repository variable already available in existing structs.\n> >   - Passing down repository variable from other subsystems.\n> >   - Modifying all subcommands to obtain repository variable from the\n> >   command in `builtins/` and passing down the variable from there.\n> >\n> > The biggest change is in the first commit, wherein we modify all\n> > subcommands to add the repository variable. Since the subcommand\n> > definition are not often changed, it shouldn't cause too many conflicts\n> > with in flight topics.\n>\n> Overall I like the way it's done. I found a few improvements that\n> could be made to some commit messages though.\n\nSame here!\n\nThanks,\nTaylor\n"},{"id":"507800","messageId":"xmqqbjy9h2h2.fsf@gitster.g","threadId":"62498","inReplyTo":"Zz5hgZ1DM9XRdXqj@nand.local","subject":"Re: [PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-21T00:09:29Z","receivedAt":"2024-11-21T00:09:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Wed, Nov 20, 2024 at 07:20:33PM +0100, Christian Couder wrote:\n>\n>> Overall I like the way it's done. I found a few improvements that\n>> could be made to some commit messages though.\n>\n> Same here!\n\nThanks, all.  It seems to me that we are getting fairly close to the\ngoal post on this topic?\n\n"},{"id":"507803","messageId":"xmqqh681fhve.fsf@gitster.g","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"Re: [PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-21T02:19:49Z","receivedAt":"2024-11-21T02:19:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Karthik Nayak <karthik.188@gmail.com> writes:\n\n> Since the `packfile.c` cleanup is still in flight, this series is based\n> on top of master: b31fb630c0 (Merge https://github.com/j6t/git-gui,\n> 2024-11-11) with those patches merged in. This applies cleanly on top \n> of next, but conflicts with `bf/set-head-symref` in seen, the conflict\n> is mostly straight forward. I'll merge the topic in if it is merged into\n> next soon.\n\nI think set_head() part is fairly trivial.  But there seems to be a\nmuch bigger conflicts with the incremental midx topic.\n\nI actually do not understand offhand why doing anything to the midx\nlayer needs to change the calling convention of set_head() or many\nother things that are unrelated to what midx layer does, and that do\n*not* use the new parameter *anyway*.  Shouldn't the \"subsubcommand\ncan inherit the repository from the builtin subcommand\nimplementation\" be split out as a separate topic, which the midx\nthing later builds on?\n\nThanks.\n"},{"id":"507824","messageId":"CAOLa=ZRRohwY85wbhJcb0zJhWx5MKfPJqSXDdSkPR5br1CBeCQ@mail.gmail.com","threadId":"62498","inReplyTo":"CAP8UFD0RpTXCdeYPA44yiS1E-LsmSHVrGxNKaUFkvUqq+zNTZw@mail.gmail.com","subject":"Re: [PATCH v2 02/10] midx-write: pass down repository to static functions","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-21T14:57:32Z","receivedAt":"2024-11-21T14:57:34Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> On Tue, Nov 19, 2024 at 5:36 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>>\n>> In 'midx-write.c' there are a lot of static functions which use global\n>> variables `the_repository` or `the_hash_algo`. In a follow up commit,\n>> the repository variable will be added to `write_midx_context`, which\n>> some of the functions can use. But for functions which do not have\n>> access to this struct, pass down the required information from\n>> non-static functions `write_midx_file` and `write_midx_file_only`.\n>>\n>> This ensures that the usage of global variables is limited to these\n>> non-static functions, which will be cleaned up in a follow up commits.\n>\n> s/commits/commit/\n>\n\nWill fix.\n\n> There are a few places in the patch where hash_to_hex() is replaced\n> with hash_to_hex_algop(). However hash_to_hex() is not quite a static\n> function and is not defined in 'midx-write.c'. So you might want to\n> mention this additional change in the commit message.\n>\n\nWhile I think it is obvious, that might not be the case, so I'll add in\na line to explain why we swap those functions.\n\n> Thanks.\n"},{"id":"507825","messageId":"CAOLa=ZQhjPRnfUhsZOir-a=djC523waw8qn3E8rk0ou7pdH8Hw@mail.gmail.com","threadId":"62498","inReplyTo":"Zz472iMq3nZMoRMf@nand.local","subject":"Re: [PATCH v2 02/10] midx-write: pass down repository to static functions","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-21T15:06:44Z","receivedAt":"2024-11-21T15:06:46Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Tue, Nov 19, 2024 at 04:36:41PM +0100, Karthik Nayak wrote:\n>> ---\n>>  midx-write.c | 57 +++++++++++++++++++++++++++++++--------------------------\n>>  1 file changed, 31 insertions(+), 26 deletions(-)\n>\n> This patch all seems reasonable to me. When reviewing it in this way, it\n> is a little unclear to see which functions need just a repository, just\n> a hash_algo, or the whole write_midx_context structure.\n>\n> I think I might have erred on the side of just passing the\n> write_midx_context structure throughout the midx-write.c internals. That\n> exposes more of the implementation details than is strictly necessary,\n> but it does so to the benefit of making the code (and this patch) easier\n> to follow.\n>\n> I don't feel strongly about it, and I trust that you modified the right\n> functions to pass the right data. I just wanted to mention it in case\n> you hadn't considered an alternative way to structure this patch.\n>\n\nI remember doing something like that and it seemed a lot more noisy than\nthe current iteration.\n\nRegarding `write_midx_context`, I wonder if all these functions need to\nreceive it. Passing only what’s necessary might make the functions'\nrequirements clearer, instead of bundling everything into a large\nstruct.\n\nBut then again, if you feel otherwise, I'm happy to change it, I don't\nfeel so strongly about it :)\n\n> Thanks,\n> Taylor\n"},{"id":"507826","messageId":"CAOLa=ZSjwUjV71H2tNwF1J-qxP3ikrVbmKOGAAWv27KcgeTo+Q@mail.gmail.com","threadId":"62498","inReplyTo":"Zz48r6ZZcol6TQaF@nand.local","subject":"Re: [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-21T15:30:17Z","receivedAt":"2024-11-21T15:30:18Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Wed, Nov 20, 2024 at 02:26:23PM +0000, Richard Kerry wrote:\n>>\n>> >> The `read_refs_snapshot` uses the `parse_oid_hex` function which\n>> >> internally uses global variables. Let's instead use\n>> >\n>> >Nit: s/variables/variable\n>>\n>> No, that's fine.\n>> It's plural, so ends with 's'.\n>> Unless it should be \"uses a global variable\"\n>\n> The global variable in question here is just \"the_hash_algo\", so I think\n> shejialuo's suggestion to use \"variable\" is correct, but it would need\n> to be \"uses a global variable\" instead of \"uses global variable\"\n> (without the article).\n>\n> But I think we're being unnecessarily vague here, and could instead say:\n>\n>     The function `read_refs_snapshot()` uses `parse_oid_hex()`, which\n>     relies on the global `the_hash_algo` variable. Let's instead use\n>     [...]\n>\n>> >> Also, while here, fix a missing newline after the functions definition.\n>> >>\n>> >\n>> >Nit: s/functions/function\n>>\n>> Maybe.\n>> But it could be \"the function's definition\" as it could be seen as possessive.\n>\n> It should be \"function's definition\", as the possessive is the correct\n> form.\n>\n\nWill fix all of this and re-do the commit message, thanks all.\n\n> Thanks,\n> Taylor\n"},{"id":"507828","messageId":"CAOLa=ZQPtxeuqf3VaZKai8=15shpynOA5yn1pWjnQ89wnc2U7w@mail.gmail.com","threadId":"62498","inReplyTo":"CAP8UFD3ZuTtd2SckoyvXmkMG3eeGqH3eHSHtda-4o5yGdj6cBg@mail.gmail.com","subject":"Re: [PATCH v2 08/10] midx: pass down `hash_algo` to `get_midx_filename[_ext]`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-21T15:35:22Z","receivedAt":"2024-11-21T15:35:24Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> On Tue, Nov 19, 2024 at 4:39 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>>\n>> The function `get_midx_filename_ext` uses `hash_to_hex` which internally\n>> uses the global variable `the_repository`. To remove this dependency,\n>> pass down the `hash_algo` to both `get_midx_filename` and\n>> `get_midx_filename_ext`.\n>\n> Technically passing down the `hash_algo` to both functions is not\n> enough to remove the dependency, as replacing `hash_to_hex()` with\n> `hash_to_hex_algop*()` is also needed. It's a bit unclear if\n> `hash_to_hex()` calls are replaced with other calls in this patch or\n> not though.\n>\n\nI see what you mean, this patch itself swaps `hash_to_hex()` with\n`hash_to_hex_algop()`, but only in `get_midx_filename[_ext]`.\n\n> So you might want to add something like: \"Replacing `hash_to_hex` with\n> functions that take an `hash_algo` as argument will be done in a\n> followup commit.\"\n\nWhile we also do something similar in the next patch, I'll amend this\ncommit message to be less vague and clarify the intention. Thanks.\n\n>\n>> This adds `the_repository` variable usage to\n>> `midx-write.c`, which will be resolved in a future commit.\n\nI think this is stale too and will remove it ;)\n"},{"id":"507829","messageId":"CAOLa=ZRr0LYSnC47K-ifZ-v+pCWx7msBpQc+65-biWK+dm4XMA@mail.gmail.com","threadId":"62498","inReplyTo":"Zz5hYfHLL1vsxdY5@nand.local","subject":"Re: [PATCH v2 09/10] midx: pass down `hash_algo` to `get_split_midx_filename_ext`","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-21T15:41:35Z","receivedAt":"2024-11-21T15:41:37Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Wed, Nov 20, 2024 at 07:15:40PM +0100, Christian Couder wrote:\n>> On Tue, Nov 19, 2024 at 4:47 PM Karthik Nayak <karthik.188@gmail.com> wrote:\n>> >\n>> > Similar to the previous commit, pass down `hash_algo` to\n>> > `get_split_midx_filename_ext` and use `hash_to_hex_algop`.\n>>\n>> I think we prefer explanations in commit messages to be a bit more\n>> self-contained, and not to rely much only on other commit messages, or\n>> links to a mailing list thread on a mailing list archive, or other\n>> external content. It's better to err on the side of copying more.\n>\n> I agree, but in this instance think it would be better to simply\n> combine the two into one. I do not see a reason why these commits should\n> be split.\n>\n\nFair enough, let me combine the two commits and rewrite the message to\nmake it clearer.\n"},{"id":"507830","messageId":"CAOLa=ZQ-u6H5P5Jpk8W-SU=u5-XPxYe7_XX84w5R2obmLnE5iA@mail.gmail.com","threadId":"62498","inReplyTo":"Zz3gguyjTKJ8RY-z@ArchLinux","subject":"Re: [PATCH v2 10/10] midx: inline the `MIDX_MIN_SIZE` definition","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-21T15:41:57Z","receivedAt":"2024-11-21T15:41:59Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"shejialuo <shejialuo@gmail.com> writes:\n\n> On Tue, Nov 19, 2024 at 04:36:49PM +0100, Karthik Nayak wrote:\n>> The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n>> `local_multi_pack_index_one`. This definitions relies on the\n>\n> Nit: s/definitions/definition\n>\n\nThanks, will fix!\n"},{"id":"507905","messageId":"CAOLa=ZTMk-xDF1o3jfowLeghxa3uAPdZo2_Fmz2chz9PxAOUaw@mail.gmail.com","threadId":"62498","inReplyTo":"xmqqh681fhve.fsf@gitster.g","subject":"Re: [PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-22T10:25:53Z","receivedAt":"2024-11-22T10:25:54Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Karthik Nayak <karthik.188@gmail.com> writes:\n>\n>> Since the `packfile.c` cleanup is still in flight, this series is based\n>> on top of master: b31fb630c0 (Merge https://github.com/j6t/git-gui,\n>> 2024-11-11) with those patches merged in. This applies cleanly on top\n>> of next, but conflicts with `bf/set-head-symref` in seen, the conflict\n>> is mostly straight forward. I'll merge the topic in if it is merged into\n>> next soon.\n>\n> I think set_head() part is fairly trivial.  But there seems to be a\n> much bigger conflicts with the incremental midx topic.\n>\n\nI see that you've merged the topic to seen and the merge resolution\nlooks ok to me, I'll also merge in `tb/incremental-midx-part-2` for my\nnext version.\n\n> I actually do not understand offhand why doing anything to the midx\n> layer needs to change the calling convention of set_head() or many\n> other things that are unrelated to what midx layer does, and that do\n> *not* use the new parameter *anyway*.  Shouldn't the \"subsubcommand\n> can inherit the repository from the builtin subcommand\n> implementation\" be split out as a separate topic, which the midx\n> thing later builds on?\n>\n\nThat was just the progression of how I worked on these patches. My goal\nwas to remove global variables, the subsubcommand can inherit just was a\ndependency which I bundled along, since it was a single patch.\n\nThere is no reason it cannot be split, Let me go ahead and do that.\n"},{"id":"508232","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com","subject":"[PATCH v3 0/8] Change midx.c and midx-write.c to not use global variables","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:25Z","receivedAt":"2024-11-27T16:28:48Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Similar to the earlier patch series on cleaning up packfile.c and\nremoving usage of global variables [1], we change the midx.c and\nmidx-write.c files to no longer use global variables.\n\nThis is done by the following:\n  - Usage of repository variable already available in existing structs.\n  - Passing down repository variable from other subsystems.\n  - Modifying all subcommands to obtain repository variable from the\n  command in `builtins/` and passing down the variable from there.\n\nThe biggest change is in the first commit, wherein we modify all\nsubcommands to add the repository variable. Since the subcommand\ndefinition are not often changed, it shouldn't cause too many conflicts\nwith in flight topics.\n\nSince the `packfile.c` cleanup is still in flight, this series is based\non top of master: b31fb630c0 (Merge https://github.com/j6t/git-gui,\n2024-11-11) with those patches merged in.\n\nSince v3 this series also depends on\n'kn/pass-repo-to-builtin-sub-sub-commands', which was split out from\nthis series.\n\n[1]: https://lore.kernel.org/git/cover.1729504640.git.karthik.188@gmail.com/\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\nChanges in v3:\n- Split out the first commit into a separate series [1].\n- Improved some of the commit messages to be more descriptive.\n- Merged the 8th and 9th commits together, since they were similar.\n- v2: https://lore.kernel.org/r/20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com\n\nChanges in v2:\n- Split commit modifying static functions in `midx-write.c` to multiple\ncommits, which makes it easier to review.\n- Remove usage of `the_repository` in `test-parse-options.c` and use\nNULL instead.\n- Fix the commit messages to be imperative.\n- Fix error in commit sign off.\n- v1: https://lore.kernel.org/r/20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com\n\n[1]: https://lore.kernel.org/git/xmqq34jdyey3.fsf@gitster.g/T/#t\n\n---\nKarthik Nayak (8):\n      midx-write: pass down repository to static functions\n      midx-write: use `revs->repo` inside `read_refs_snapshot`\n      write-midx: add repository field to `write_midx_context`\n      midx-write: pass down repository to `write_midx_file[_only]`\n      midx: cleanup internal usage of `the_repository` and `the_hash_algo`\n      midx: pass `repository` to `load_multi_pack_index`\n      midx: pass down `hash_algo` to functions using global variables\n      midx: inline the `MIDX_MIN_SIZE` definition\n\n builtin/multi-pack-index.c |   6 +--\n builtin/repack.c           |   2 +-\n midx-write.c               | 130 +++++++++++++++++++++++----------------------\n midx.c                     |  88 ++++++++++++++++--------------\n midx.h                     |  24 +++++----\n pack-bitmap.c              |   6 +--\n pack-revindex.c            |   2 +-\n t/helper/test-read-midx.c  |   8 +--\n 8 files changed, 140 insertions(+), 126 deletions(-)\n---\n\nRange-diff versus v2:\n\n 1:  6c00e25c86 <  -:  ---------- packfile: add repository to struct `packed_git`\n 2:  70fc8a79af <  -:  ---------- packfile: use `repository` from `packed_git` directly\n 3:  167a1f3a11 <  -:  ---------- packfile: pass `repository` to static function in the file\n 4:  b7cfe78217 <  -:  ---------- packfile: pass down repository to `odb_pack_name`\n 5:  5566f5554c <  -:  ---------- packfile: pass down repository to `has_object[_kept]_pack`\n 6:  1b26e45a9b <  -:  ---------- packfile: pass down repository to `for_each_packed_object`\n 7:  1bdc34f4d8 <  -:  ---------- config: make `delta_base_cache_limit` a non-global variable\n 8:  7b6baa89ac <  -:  ---------- config: make `packed_git_(limit|window_size)` non-global variables\n 9:  a3667d87ec <  -:  ---------- midx: add repository to `multi_pack_index` struct\n10:  91a35c4876 <  -:  ---------- builtin: pass repository to sub commands\n11:  a916fe708f !  1:  d7c1056ebd midx-write: pass down repository to static functions\n    @@ Commit message\n         access to this struct, pass down the required information from\n         non-static functions `write_midx_file` and `write_midx_file_only`.\n     \n    +    This requires that the function `hash_to_hex` is also replaced with\n    +    `hash_to_hex_algop` since the former internally accesses the\n    +    `the_hash_algo` global variable.\n    +\n         This ensures that the usage of global variables is limited to these\n    -    non-static functions, which will be cleaned up in a follow up commits.\n    +    non-static functions, which will be cleaned up in a follow up commit.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n12:  a2fa59eca5 !  2:  11cd6c6bec midx-write: use `revs->repo` inside `read_refs_snapshot`\n    @@ Metadata\n      ## Commit message ##\n         midx-write: use `revs->repo` inside `read_refs_snapshot`\n     \n    -    The `read_refs_snapshot` uses the `parse_oid_hex` function which\n    -    internally uses global variables. Let's instead use\n    -    `parse_oid_hex_algop` and provide the hash algo via `revs->repo`.\n    +    The function `read_refs_snapshot()` uses `parse_oid_hex()`, which relies\n    +    on the global `the_hash_algo` variable. Let's instead use\n    +    `parse_oid_hex_algop()` and provide the hash algo via `revs->repo`.\n     \n    -    Also, while here, fix a missing newline after the functions definition.\n    +    Also, while here, fix a missing newline after the function's definition.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n13:  bc6ff987c5 =  3:  d74bf1fa51 write-midx: add repository field to `write_midx_context`\n14:  27affa11fb =  4:  630bffe661 midx-write: pass down repository to `write_midx_file[_only]`\n15:  02484793f6 =  5:  32d001bdd6 midx: cleanup internal usage of `the_repository` and `the_hash_algo`\n16:  790215da01 =  6:  392a96de6a midx: pass `repository` to `load_multi_pack_index`\n17:  8eac01e7ac !  7:  35bdc6d6b1 midx: pass down `hash_algo` to `get_midx_filename[_ext]`\n    @@ Metadata\n     Author: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## Commit message ##\n    -    midx: pass down `hash_algo` to `get_midx_filename[_ext]`\n    +    midx: pass down `hash_algo` to functions using global variables\n     \n    -    The function `get_midx_filename_ext` uses `hash_to_hex` which internally\n    -    uses the global variable `the_repository`. To remove this dependency,\n    -    pass down the `hash_algo` to both `get_midx_filename` and\n    -    `get_midx_filename_ext`. This adds `the_repository` variable usage to\n    -    `midx-write.c`, which will be resolved in a future commit.\n    +    The functions `get_split_midx_filename_ext()`, `get_midx_filename()` and\n    +    `get_midx_filename_ext()` use `hash_to_hex()` which internally uses the\n    +    `the_hash_algo` global variable.\n    +\n    +    Remove this dependency on global variables by passing down the\n    +    `hash_algo` through to the functions mentioned and instead calling\n    +    `hash_to_hex_algop()` along with the obtained `hash_algo`.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n    @@ midx-write.c: static int link_midx_to_chain(struct multi_pack_index *m)\n      \n     -\t\tget_midx_filename_ext(&from, m->object_dir, hash,\n     -\t\t\t\t      midx_exts[i].non_split);\n    +-\t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n     +\t\tget_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,\n     +\t\t\t\t      hash, midx_exts[i].non_split);\n    - \t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n    ++\t\tget_split_midx_filename_ext(m->repo->hash_algo, &to,\n    ++\t\t\t\t\t    m->object_dir, hash,\n      \t\t\t\t\t    midx_exts[i].split);\n      \n    + \t\tif (link(from.buf, to.buf) < 0 && errno != ENOENT) {\n     @@ midx-write.c: static int link_midx_to_chain(struct multi_pack_index *m)\n      \treturn ret;\n      }\n    @@ midx-write.c: static int write_midx_internal(struct repository *r, const char *o\n      \tif (safe_create_leading_directories(midx_name.buf))\n      \t\tdie_errno(_(\"unable to create leading directories of %s\"),\n      \t\t\t  midx_name.buf);\n    +@@ midx-write.c: static int write_midx_internal(struct repository *r, const char *object_dir,\n    + \t\tif (link_midx_to_chain(ctx.base_midx) < 0)\n    + \t\t\treturn -1;\n    + \n    +-\t\tget_split_midx_filename_ext(&final_midx_name, object_dir,\n    +-\t\t\t\t\t    midx_hash, MIDX_EXT_MIDX);\n    ++\t\tget_split_midx_filename_ext(r->hash_algo, &final_midx_name,\n    ++\t\t\t\t\t    object_dir, midx_hash, MIDX_EXT_MIDX);\n    + \n    + \t\tif (rename_tempfile(&incr, final_midx_name.buf) < 0) {\n    + \t\t\terror_errno(_(\"unable to rename new multi-pack-index layer\"));\n     @@ midx-write.c: static int write_midx_internal(struct repository *r, const char *object_dir,\n      \tif (commit_lock_file(&lk) < 0)\n      \t\tdie_errno(_(\"could not write multi-pack-index\"));\n    @@ midx.c: const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n      }\n      \n      static int midx_read_oid_fanout(const unsigned char *chunk_start,\n    +@@ midx.c: void get_midx_chain_filename(struct strbuf *buf, const char *object_dir)\n    + \tstrbuf_addstr(buf, \"/multi-pack-index-chain\");\n    + }\n    + \n    +-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n    ++void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n    ++\t\t\t\t struct strbuf *buf, const char *object_dir,\n    + \t\t\t\t const unsigned char *hash, const char *ext)\n    + {\n    + \tget_midx_chain_dirname(buf, object_dir);\n    +-\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n    ++\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\",\n    ++\t\t    hash_to_hex_algop(hash, hash_algo), ext);\n    + }\n    + \n    + static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n    +@@ midx.c: static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n    + \t\tvalid = 0;\n    + \n    + \t\tstrbuf_reset(&buf);\n    +-\t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n    +-\t\t\t\t\t    MIDX_EXT_MIDX);\n    ++\t\tget_split_midx_filename_ext(r->hash_algo, &buf, object_dir,\n    ++\t\t\t\t\t    layer.hash, MIDX_EXT_MIDX);\n    + \t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n    + \n    + \t\tif (m) {\n     @@ midx.c: struct multi_pack_index *load_multi_pack_index(struct repository *r,\n      \tstruct strbuf midx_name = STRBUF_INIT;\n      \tstruct multi_pack_index *m;\n    @@ midx.h: struct multi_pack_index {\n      \t\t\t   const unsigned char *hash, const char *ext);\n      void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n      void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n    +-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n    ++void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n    ++\t\t\t\t struct strbuf *buf, const char *object_dir,\n    + \t\t\t\t const unsigned char *hash, const char *ext);\n    + \n    + struct multi_pack_index *load_multi_pack_index(struct repository *r,\n     \n      ## pack-bitmap.c ##\n     @@ pack-bitmap.c: static int load_bitmap_entries_v1(struct bitmap_index *index)\n18:  3357d47ec0 <  -:  ---------- midx: pass down `hash_algo` to `get_split_midx_filename_ext`\n19:  6a1ae9d11c !  8:  128f4f08b0 midx: inline the `MIDX_MIN_SIZE` definition\n    @@ Commit message\n         midx: inline the `MIDX_MIN_SIZE` definition\n     \n         The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n    -    `local_multi_pack_index_one`. This definitions relies on the\n    +    `local_multi_pack_index_one`. This definition relies on the\n         `the_hash_algo` global variable. Inline this and remove the global\n         variable usage.\n     \n\n\n--- \n\nbase-commit: b31fb630c0fc6869a33ed717163e8a1210460d94\nchange-id: 20241111-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-a88498c2590f\n\nThanks\n- Karthik\n\n"},{"id":"508233","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-1-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 1/8] midx-write: pass down repository to static functions","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:26Z","receivedAt":"2024-11-27T16:28:49Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In 'midx-write.c' there are a lot of static functions which use global\nvariables `the_repository` or `the_hash_algo`. In a follow up commit,\nthe repository variable will be added to `write_midx_context`, which\nsome of the functions can use. But for functions which do not have\naccess to this struct, pass down the required information from\nnon-static functions `write_midx_file` and `write_midx_file_only`.\n\nThis requires that the function `hash_to_hex` is also replaced with\n`hash_to_hex_algop` since the former internally accesses the\n`the_hash_algo` global variable.\n\nThis ensures that the usage of global variables is limited to these\nnon-static functions, which will be cleaned up in a follow up commit.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 57 +++++++++++++++++++++++++++++++--------------------------\n 1 file changed, 31 insertions(+), 26 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex c57726ef9475df693890d61627ce91409c1def7c..22b5233f51ec6c6d99b8f9613818f1581dca5982 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -35,13 +35,13 @@ extern void clear_incremental_midx_files_ext(const char *object_dir,\n extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,\n \t\t\t\tconst char *idx_name);\n \n-static size_t write_midx_header(struct hashfile *f,\n-\t\t\t\tunsigned char num_chunks,\n+static size_t write_midx_header(const struct git_hash_algo *hash_algo,\n+\t\t\t\tstruct hashfile *f, unsigned char num_chunks,\n \t\t\t\tuint32_t num_packs)\n {\n \thashwrite_be32(f, MIDX_SIGNATURE);\n \thashwrite_u8(f, MIDX_VERSION);\n-\thashwrite_u8(f, oid_version(the_hash_algo));\n+\thashwrite_u8(f, oid_version(hash_algo));\n \thashwrite_u8(f, num_chunks);\n \thashwrite_u8(f, 0); /* unused */\n \thashwrite_be32(f, num_packs);\n@@ -702,7 +702,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n \t\treturn 0;\n \t}\n \n-\tif (!peel_iterated_oid(the_repository, oid, &peeled))\n+\tif (!peel_iterated_oid(revs->repo, oid, &peeled))\n \t\toid = &peeled;\n \n \tobject = parse_object_or_die(oid, refname);\n@@ -827,7 +827,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \treturn cb.commits;\n }\n \n-static int write_midx_bitmap(const char *midx_name,\n+static int write_midx_bitmap(struct repository *r, const char *midx_name,\n \t\t\t     const unsigned char *midx_hash,\n \t\t\t     struct packing_data *pdata,\n \t\t\t     struct commit **commits,\n@@ -840,9 +840,9 @@ static int write_midx_bitmap(const char *midx_name,\n \tstruct bitmap_writer writer;\n \tstruct pack_idx_entry **index;\n \tchar *bitmap_name = xstrfmt(\"%s-%s.bitmap\", midx_name,\n-\t\t\t\t\thash_to_hex(midx_hash));\n+\t\t\t\t    hash_to_hex_algop(midx_hash, r->hash_algo));\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_bitmap\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_bitmap\", r);\n \n \tif (flags & MIDX_WRITE_BITMAP_HASH_CACHE)\n \t\toptions |= BITMAP_OPT_HASH_CACHE;\n@@ -859,7 +859,7 @@ static int write_midx_bitmap(const char *midx_name,\n \tfor (i = 0; i < pdata->nr_objects; i++)\n \t\tindex[i] = &pdata->objects[i].idx;\n \n-\tbitmap_writer_init(&writer, the_repository, pdata);\n+\tbitmap_writer_init(&writer, r, pdata);\n \tbitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);\n \tbitmap_writer_build_type_index(&writer, index);\n \n@@ -892,7 +892,7 @@ static int write_midx_bitmap(const char *midx_name,\n \tfree(bitmap_name);\n \tbitmap_writer_free(&writer);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_bitmap\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_bitmap\", r);\n \n \treturn ret;\n }\n@@ -1049,7 +1049,7 @@ static void clear_midx_files(const char *object_dir,\n \tstrbuf_release(&buf);\n }\n \n-static int write_midx_internal(const char *object_dir,\n+static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\t\t       struct string_list *packs_to_include,\n \t\t\t       struct string_list *packs_to_drop,\n \t\t\t       const char *preferred_pack_name,\n@@ -1070,7 +1070,8 @@ static int write_midx_internal(const char *object_dir,\n \tconst char **keep_hashes = NULL;\n \tstruct chunkfile *cf;\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_internal\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_internal\", r);\n+\n \n \tctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);\n \tif (ctx.incremental && (flags & MIDX_WRITE_BITMAP))\n@@ -1087,8 +1088,7 @@ static int write_midx_internal(const char *object_dir,\n \t\t\t  midx_name.buf);\n \n \tif (!packs_to_include || ctx.incremental) {\n-\t\tstruct multi_pack_index *m = lookup_multi_pack_index(the_repository,\n-\t\t\t\t\t\t\t\t     object_dir);\n+\t\tstruct multi_pack_index *m = lookup_multi_pack_index(r, object_dir);\n \t\tif (m && !midx_checksum_valid(m)) {\n \t\t\twarning(_(\"ignoring existing multi-pack-index; checksum mismatch\"));\n \t\t\tm = NULL;\n@@ -1351,7 +1351,7 @@ static int write_midx_internal(const char *object_dir,\n \tadd_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE,\n \t\t  write_midx_oid_fanout);\n \tadd_chunk(cf, MIDX_CHUNKID_OIDLOOKUP,\n-\t\t  st_mult(ctx.entries_nr, the_hash_algo->rawsz),\n+\t\t  st_mult(ctx.entries_nr, r->hash_algo->rawsz),\n \t\t  write_midx_oid_lookup);\n \tadd_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS,\n \t\t  st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH),\n@@ -1373,7 +1373,8 @@ static int write_midx_internal(const char *object_dir,\n \t\t\t  write_midx_bitmapped_packs);\n \t}\n \n-\twrite_midx_header(f, get_num_chunks(cf), ctx.nr - dropped_packs);\n+\twrite_midx_header(r->hash_algo, f, get_num_chunks(cf),\n+\t\t\t  ctx.nr - dropped_packs);\n \twrite_chunkfile(cf, &ctx);\n \n \tfinalize_hashfile(f, midx_hash, FSYNC_COMPONENT_PACK_METADATA,\n@@ -1405,7 +1406,7 @@ static int write_midx_internal(const char *object_dir,\n \t\tFREE_AND_NULL(ctx.entries);\n \t\tctx.entries_nr = 0;\n \n-\t\tif (write_midx_bitmap(midx_name.buf, midx_hash, &pdata,\n+\t\tif (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,\n \t\t\t\t      commits, commits_nr, ctx.pack_order,\n \t\t\t\t      flags) < 0) {\n \t\t\terror(_(\"could not write multi-pack bitmap\"));\n@@ -1449,12 +1450,13 @@ static int write_midx_internal(const char *object_dir,\n \t\tstrbuf_release(&final_midx_name);\n \n \t\tkeep_hashes[ctx.num_multi_pack_indexes_before] =\n-\t\t\txstrdup(hash_to_hex(midx_hash));\n+\t\t\txstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));\n \n \t\tfor (i = 0; i < ctx.num_multi_pack_indexes_before; i++) {\n \t\t\tuint32_t j = ctx.num_multi_pack_indexes_before - i - 1;\n \n-\t\t\tkeep_hashes[j] = xstrdup(hash_to_hex(get_midx_checksum(m)));\n+\t\t\tkeep_hashes[j] = xstrdup(hash_to_hex_algop(get_midx_checksum(m),\n+\t\t\t\t\t\t\t\t   r->hash_algo));\n \t\t\tm = m->base_midx;\n \t\t}\n \n@@ -1462,7 +1464,7 @@ static int write_midx_internal(const char *object_dir,\n \t\t\tfprintf(get_lock_file_fp(&lk), \"%s\\n\", keep_hashes[i]);\n \t} else {\n \t\tkeep_hashes[ctx.num_multi_pack_indexes_before] =\n-\t\t\txstrdup(hash_to_hex(midx_hash));\n+\t\t\txstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));\n \t}\n \n \tif (ctx.m || ctx.base_midx)\n@@ -1495,7 +1497,7 @@ static int write_midx_internal(const char *object_dir,\n \t}\n \tstrbuf_release(&midx_name);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_internal\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_internal\", r);\n \n \treturn result;\n }\n@@ -1505,8 +1507,8 @@ int write_midx_file(const char *object_dir,\n \t\t    const char *refs_snapshot,\n \t\t    unsigned flags)\n {\n-\treturn write_midx_internal(object_dir, NULL, NULL, preferred_pack_name,\n-\t\t\t\t   refs_snapshot, flags);\n+\treturn write_midx_internal(the_repository, object_dir, NULL, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n }\n \n int write_midx_file_only(const char *object_dir,\n@@ -1515,8 +1517,9 @@ int write_midx_file_only(const char *object_dir,\n \t\t\t const char *refs_snapshot,\n \t\t\t unsigned flags)\n {\n-\treturn write_midx_internal(object_dir, packs_to_include, NULL,\n-\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n+\treturn write_midx_internal(the_repository, object_dir, packs_to_include,\n+\t\t\t\t   NULL, preferred_pack_name, refs_snapshot,\n+\t\t\t\t   flags);\n }\n \n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)\n@@ -1572,7 +1575,8 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla\n \tfree(count);\n \n \tif (packs_to_drop.nr)\n-\t\tresult = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags);\n+\t\tresult = write_midx_internal(r, object_dir, NULL,\n+\t\t\t\t\t     &packs_to_drop, NULL, NULL, flags);\n \n \tstring_list_clear(&packs_to_drop, 0);\n \n@@ -1769,7 +1773,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,\n \t\tgoto cleanup;\n \t}\n \n-\tresult = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags);\n+\tresult = write_midx_internal(r, object_dir, NULL, NULL, NULL, NULL,\n+\t\t\t\t     flags);\n \n cleanup:\n \tfree(include_pack);\n\n-- \n2.47.1\n\n"},{"id":"508234","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-2-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 2/8] midx-write: use `revs->repo` inside `read_refs_snapshot`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:27Z","receivedAt":"2024-11-27T16:28:51Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The function `read_refs_snapshot()` uses `parse_oid_hex()`, which relies\non the global `the_hash_algo` variable. Let's instead use\n`parse_oid_hex_algop()` and provide the hash algo via `revs->repo`.\n\nAlso, while here, fix a missing newline after the function's definition.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 22b5233f51ec6c6d99b8f9613818f1581dca5982..564438f616f59cd24edda956e4af0e0acf167138 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -760,7 +760,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n \t\t\thex = &buf.buf[1];\n \t\t}\n \n-\t\tif (parse_oid_hex(hex, &oid, &end) < 0)\n+\t\tif (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0)\n \t\t\tdie(_(\"could not parse line: %s\"), buf.buf);\n \t\tif (*end)\n \t\t\tdie(_(\"malformed line: %s\"), buf.buf);\n@@ -776,6 +776,7 @@ static int read_refs_snapshot(const char *refs_snapshot,\n \tstrbuf_release(&buf);\n \treturn 0;\n }\n+\n static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr_p,\n \t\t\t\t\t\t    const char *refs_snapshot,\n \t\t\t\t\t\t    struct write_midx_context *ctx)\n\n-- \n2.47.1\n\n"},{"id":"508235","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-3-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 3/8] write-midx: add repository field to `write_midx_context`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:28Z","receivedAt":"2024-11-27T16:28:52Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The struct `write_midx_context` is used to pass context for creating\nMIDX files. Add the repository field here to ensure that most functions\nwithin `midx-write.c` have access to the field and can use that instead\nof the global `the_repository` variable.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c | 38 ++++++++++++++++++++------------------\n 1 file changed, 20 insertions(+), 18 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 564438f616f59cd24edda956e4af0e0acf167138..1c355cdf8db4e9fed61a4aabf61a237ad26181ce 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -110,6 +110,8 @@ struct write_midx_context {\n \tuint32_t num_multi_pack_indexes_before;\n \n \tstruct string_list *to_include;\n+\n+\tstruct repository *repo;\n };\n \n static int should_include_pack(const struct write_midx_context *ctx,\n@@ -154,7 +156,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,\n \t\t\treturn;\n \n \t\tALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);\n-\t\tp = add_packed_git(the_repository, full_path, full_path_len, 0);\n+\t\tp = add_packed_git(ctx->repo, full_path, full_path_len, 0);\n \t\tif (!p) {\n \t\t\twarning(_(\"failed to add packfile '%s'\"),\n \t\t\t\tfull_path);\n@@ -480,7 +482,7 @@ static int write_midx_oid_lookup(struct hashfile *f,\n \t\t\t\t void *data)\n {\n \tstruct write_midx_context *ctx = data;\n-\tunsigned char hash_len = the_hash_algo->rawsz;\n+\tunsigned char hash_len = ctx->repo->hash_algo->rawsz;\n \tstruct pack_midx_entry *list = ctx->entries;\n \tuint32_t i;\n \n@@ -605,7 +607,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n \tuint32_t *pack_order, base_objects = 0;\n \tuint32_t i;\n \n-\ttrace2_region_enter(\"midx\", \"midx_pack_order\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"midx_pack_order\", ctx->repo);\n \n \tif (ctx->incremental && ctx->base_midx)\n \t\tbase_objects = ctx->base_midx->num_objects +\n@@ -640,7 +642,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)\n \t}\n \tfree(data);\n \n-\ttrace2_region_leave(\"midx\", \"midx_pack_order\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"midx_pack_order\", ctx->repo);\n \n \treturn pack_order;\n }\n@@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n \tstruct strbuf buf = STRBUF_INIT;\n \tchar *tmp_file;\n \n-\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n \n-\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex(midx_hash));\n+\tstrbuf_addf(&buf, \"%s-%s.rev\", midx_name, hash_to_hex_algop(midx_hash,\n+\t\t\t\t\t\t\t\t    ctx->repo->hash_algo));\n \n \ttmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,\n \t\t\t\t\tmidx_hash, WRITE_REV);\n@@ -664,7 +667,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,\n \tstrbuf_release(&buf);\n \tfree(tmp_file);\n \n-\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"write_midx_reverse_index\", ctx->repo);\n }\n \n static void prepare_midx_packing_data(struct packing_data *pdata,\n@@ -672,10 +675,10 @@ static void prepare_midx_packing_data(struct packing_data *pdata,\n {\n \tuint32_t i;\n \n-\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", the_repository);\n+\ttrace2_region_enter(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n \n \tmemset(pdata, 0, sizeof(struct packing_data));\n-\tprepare_packing_data(the_repository, pdata);\n+\tprepare_packing_data(ctx->repo, pdata);\n \n \tfor (i = 0; i < ctx->entries_nr; i++) {\n \t\tuint32_t pos = ctx->pack_order[i];\n@@ -686,7 +689,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata,\n \t\t\t       ctx->info[ctx->pack_perm[from->pack_int_id]].p);\n \t}\n \n-\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", the_repository);\n+\ttrace2_region_leave(\"midx\", \"prepare_midx_packing_data\", ctx->repo);\n }\n \n static int add_ref_to_pending(const char *refname, const char *referent UNUSED,\n@@ -784,17 +787,16 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \tstruct rev_info revs;\n \tstruct bitmap_commit_cb cb = {0};\n \n-\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\",\n-\t\t\t    the_repository);\n+\ttrace2_region_enter(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n \n \tcb.ctx = ctx;\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(ctx->repo, &revs, NULL);\n \tif (refs_snapshot) {\n \t\tread_refs_snapshot(refs_snapshot, &revs);\n \t} else {\n \t\tsetup_revisions(0, NULL, &revs, NULL);\n-\t\trefs_for_each_ref(get_main_ref_store(the_repository),\n+\t\trefs_for_each_ref(get_main_ref_store(ctx->repo),\n \t\t\t\t  add_ref_to_pending, &revs);\n \t}\n \n@@ -822,8 +824,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr\n \n \trelease_revisions(&revs);\n \n-\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\",\n-\t\t\t    the_repository);\n+\ttrace2_region_leave(\"midx\", \"find_commits_for_midx_bitmap\", ctx->repo);\n \n \treturn cb.commits;\n }\n@@ -945,7 +946,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,\n \t\t\t */\n \t\t\tif (flags & MIDX_WRITE_REV_INDEX ||\n \t\t\t    preferred_pack_name) {\n-\t\t\t\tif (prepare_midx_pack(the_repository, m,\n+\t\t\t\tif (prepare_midx_pack(ctx->repo, m,\n \t\t\t\t\t\t      m->num_packs_in_base + i)) {\n \t\t\t\t\terror(_(\"could not load pack\"));\n \t\t\t\t\treturn 1;\n@@ -1073,6 +1074,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \n \ttrace2_region_enter(\"midx\", \"write_midx_internal\", r);\n \n+\tctx.repo = r;\n \n \tctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);\n \tif (ctx.incremental && (flags & MIDX_WRITE_BITMAP))\n@@ -1469,7 +1471,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t}\n \n \tif (ctx.m || ctx.base_midx)\n-\t\tclose_object_store(the_repository->objects);\n+\t\tclose_object_store(ctx.repo->objects);\n \n \tif (commit_lock_file(&lk) < 0)\n \t\tdie_errno(_(\"could not write multi-pack-index\"));\n\n-- \n2.47.1\n\n"},{"id":"508236","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-4-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 4/8] midx-write: pass down repository to `write_midx_file[_only]`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:29Z","receivedAt":"2024-11-27T16:28:52Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In a previous commit, we passed the repository field to all\nsubcommands in the `builtin/` directory. Utilize this to pass the\nrepository field down to the `write_midx_file[_only]` functions to\nremove the usage of `the_repository` global variables.\n\nWith this, all usage of global variables in `midx-write.c` is removed,\nhence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/multi-pack-index.c |  6 +++---\n builtin/repack.c           |  2 +-\n midx-write.c               | 22 +++++++++-------------\n midx.h                     | 10 ++++------\n 4 files changed, 17 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0..2a938466f53aaa11096170554fe11a4ed46a25e4 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to)\n \n static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n-\t\t\t\t      struct repository *repo UNUSED)\n+\t\t\t\t      struct repository *repo)\n {\n \tstruct option *options;\n \tstatic struct option builtin_multi_pack_index_write_options[] = {\n@@ -165,7 +165,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t\tread_packs_from_stdin(&packs);\n \n-\t\tret = write_midx_file_only(opts.object_dir, &packs,\n+\t\tret = write_midx_file_only(repo, opts.object_dir, &packs,\n \t\t\t\t\t   opts.preferred_pack,\n \t\t\t\t\t   opts.refs_snapshot, opts.flags);\n \n@@ -176,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t}\n \n-\tret = write_midx_file(opts.object_dir, opts.preferred_pack,\n+\tret = write_midx_file(repo, opts.object_dir, opts.preferred_pack,\n \t\t\t      opts.refs_snapshot, opts.flags);\n \n \tfree(opts.refs_snapshot);\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 96a4fa234bddfd2b63c8d9733379d9b1012a4014..9c21fc482dfb387c818c0d0a74f781848b5a0953 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1569,7 +1569,7 @@ int cmd_repack(int argc,\n \t\tunsigned flags = 0;\n \t\tif (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))\n \t\t\tflags |= MIDX_WRITE_INCREMENTAL;\n-\t\twrite_midx_file(repo_get_object_directory(the_repository),\n+\t\twrite_midx_file(the_repository, repo_get_object_directory(the_repository),\n \t\t\t\tNULL, NULL, flags);\n \t}\n \ndiff --git a/midx-write.c b/midx-write.c\nindex 1c355cdf8db4e9fed61a4aabf61a237ad26181ce..1bc2f5256916e69924245951f654c1047ffeab84 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -1505,24 +1503,22 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \treturn result;\n }\n \n-int write_midx_file(const char *object_dir,\n+int write_midx_file(struct repository *r, const char *object_dir,\n \t\t    const char *preferred_pack_name,\n-\t\t    const char *refs_snapshot,\n-\t\t    unsigned flags)\n+\t\t    const char *refs_snapshot, unsigned flags)\n {\n-\treturn write_midx_internal(the_repository, object_dir, NULL, NULL,\n-\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n+\treturn write_midx_internal(r, object_dir, NULL, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot,\n+\t\t\t\t   flags);\n }\n \n-int write_midx_file_only(const char *object_dir,\n+int write_midx_file_only(struct repository *r, const char *object_dir,\n \t\t\t struct string_list *packs_to_include,\n \t\t\t const char *preferred_pack_name,\n-\t\t\t const char *refs_snapshot,\n-\t\t\t unsigned flags)\n+\t\t\t const char *refs_snapshot, unsigned flags)\n {\n-\treturn write_midx_internal(the_repository, object_dir, packs_to_include,\n-\t\t\t\t   NULL, preferred_pack_name, refs_snapshot,\n-\t\t\t\t   flags);\n+\treturn write_midx_internal(r, object_dir, packs_to_include, NULL,\n+\t\t\t\t   preferred_pack_name, refs_snapshot, flags);\n }\n \n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)\ndiff --git a/midx.h b/midx.h\nindex 3b0ac4d8788b373c59fe69ca2d78e9d914702bc0..c37ad5b5242b56d21fd76bd59957a1bdb82786ec 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -123,15 +123,13 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i\n  * Variant of write_midx_file which writes a MIDX containing only the packs\n  * specified in packs_to_include.\n  */\n-int write_midx_file(const char *object_dir,\n-\t\t    const char *preferred_pack_name,\n-\t\t    const char *refs_snapshot,\n+int write_midx_file(struct repository *r, const char *object_dir,\n+\t\t    const char *preferred_pack_name, const char *refs_snapshot,\n \t\t    unsigned flags);\n-int write_midx_file_only(const char *object_dir,\n+int write_midx_file_only(struct repository *r, const char *object_dir,\n \t\t\t struct string_list *packs_to_include,\n \t\t\t const char *preferred_pack_name,\n-\t\t\t const char *refs_snapshot,\n-\t\t\t unsigned flags);\n+\t\t\t const char *refs_snapshot, unsigned flags);\n void clear_midx_file(struct repository *r);\n int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);\n int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);\n\n-- \n2.47.1\n\n"},{"id":"508237","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-5-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 5/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:30Z","receivedAt":"2024-11-27T16:28:53Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In the `midx.c` file, there are multiple usages of `the_repository` and\n`the_hash_algo` within static functions of the file. Some of the usages\ncan be simply swapped out with the available `repository` struct. While\nsome of them can be swapped out by passing the repository to the\nrequired functions.\n\nThis leaves out only some other usages of `the_repository` and\n`the_hash_algo` in the file in non-static functions, which we'll tackle\nin upcoming commits.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c | 49 +++++++++++++++++++++++++++----------------------\n 1 file changed, 27 insertions(+), 22 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 079c45a1aafb658a7b887ac216cc6ecf5f0fb6ff..6f0fb8285af14843da132ef1b0c3a8bdd06732c9 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -25,7 +25,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,\n \n const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n {\n-\treturn m->data + m->data_len - the_hash_algo->rawsz;\n+\treturn m->data + m->data_len - m->repo->hash_algo->rawsz;\n }\n \n void get_midx_filename(struct strbuf *out, const char *object_dir)\n@@ -94,7 +94,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,\n \n #define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n \n-static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir,\n+static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n+\t\t\t\t\t\t\t  const char *object_dir,\n \t\t\t\t\t\t\t  const char *midx_name,\n \t\t\t\t\t\t\t  int local)\n {\n@@ -131,7 +132,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \tm->data = midx_map;\n \tm->data_len = midx_size;\n \tm->local = local;\n-\tm->repo = the_repository;\n+\tm->repo = r;\n \n \tm->signature = get_be32(m->data);\n \tif (m->signature != MIDX_SIGNATURE)\n@@ -144,12 +145,12 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \t\t      m->version);\n \n \thash_version = m->data[MIDX_BYTE_HASH_VERSION];\n-\tif (hash_version != oid_version(the_hash_algo)) {\n+\tif (hash_version != oid_version(r->hash_algo)) {\n \t\terror(_(\"multi-pack-index hash version %u does not match version %u\"),\n-\t\t      hash_version, oid_version(the_hash_algo));\n+\t\t      hash_version, oid_version(r->hash_algo));\n \t\tgoto cleanup_fail;\n \t}\n-\tm->hash_len = the_hash_algo->rawsz;\n+\tm->hash_len = r->hash_algo->rawsz;\n \n \tm->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];\n \n@@ -206,8 +207,8 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \t\t\t      m->pack_names[i]);\n \t}\n \n-\ttrace2_data_intmax(\"midx\", the_repository, \"load/num_packs\", m->num_packs);\n-\ttrace2_data_intmax(\"midx\", the_repository, \"load/num_objects\", m->num_objects);\n+\ttrace2_data_intmax(\"midx\", r, \"load/num_packs\", m->num_packs);\n+\ttrace2_data_intmax(\"midx\", r, \"load/num_objects\", m->num_objects);\n \n \tfree_chunkfile(cf);\n \treturn m;\n@@ -240,8 +241,9 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n \tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n }\n \n-static int open_multi_pack_index_chain(const char *chain_file,\n-\t\t\t\t       int *fd, struct stat *st)\n+static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n+\t\t\t\t       const char *chain_file, int *fd,\n+\t\t\t\t       struct stat *st)\n {\n \t*fd = git_open(chain_file);\n \tif (*fd < 0)\n@@ -250,7 +252,7 @@ static int open_multi_pack_index_chain(const char *chain_file,\n \t\tclose(*fd);\n \t\treturn 0;\n \t}\n-\tif (st->st_size < the_hash_algo->hexsz) {\n+\tif (st->st_size < hash_algo->hexsz) {\n \t\tclose(*fd);\n \t\tif (!st->st_size) {\n \t\t\t/* treat empty files the same as missing */\n@@ -292,7 +294,8 @@ static int add_midx_to_chain(struct multi_pack_index *midx,\n \treturn 1;\n }\n \n-static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n+static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n+\t\t\t\t\t\t      const char *object_dir,\n \t\t\t\t\t\t      int local,\n \t\t\t\t\t\t      int fd, struct stat *st,\n \t\t\t\t\t\t      int *incomplete_chain)\n@@ -303,7 +306,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \tuint32_t i, count;\n \tFILE *fp = xfdopen(fd, \"r\");\n \n-\tcount = st->st_size / (the_hash_algo->hexsz + 1);\n+\tcount = st->st_size / (r->hash_algo->hexsz + 1);\n \n \tfor (i = 0; i < count; i++) {\n \t\tstruct multi_pack_index *m;\n@@ -312,7 +315,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tif (strbuf_getline_lf(&buf, fp) == EOF)\n \t\t\tbreak;\n \n-\t\tif (get_oid_hex(buf.buf, &layer)) {\n+\t\tif (get_oid_hex_algop(buf.buf, &layer, r->hash_algo)) {\n \t\t\twarning(_(\"invalid multi-pack-index chain: line '%s' \"\n \t\t\t\t  \"not a hash\"),\n \t\t\t\tbuf.buf);\n@@ -325,7 +328,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tstrbuf_reset(&buf);\n \t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n \t\t\t\t\t    MIDX_EXT_MIDX);\n-\t\tm = load_multi_pack_index_one(object_dir, buf.buf, local);\n+\t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n \n \t\tif (m) {\n \t\t\tif (add_midx_to_chain(m, midx_chain)) {\n@@ -348,7 +351,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \treturn midx_chain;\n }\n \n-static struct multi_pack_index *load_multi_pack_index_chain(const char *object_dir,\n+static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r,\n+\t\t\t\t\t\t\t    const char *object_dir,\n \t\t\t\t\t\t\t    int local)\n {\n \tstruct strbuf chain_file = STRBUF_INIT;\n@@ -357,10 +361,10 @@ static struct multi_pack_index *load_multi_pack_index_chain(const char *object_d\n \tstruct multi_pack_index *m = NULL;\n \n \tget_midx_chain_filename(&chain_file, object_dir);\n-\tif (open_multi_pack_index_chain(chain_file.buf, &fd, &st)) {\n+\tif (open_multi_pack_index_chain(r->hash_algo, chain_file.buf, &fd, &st)) {\n \t\tint incomplete;\n \t\t/* ownership of fd is taken over by load function */\n-\t\tm = load_midx_chain_fd_st(object_dir, local, fd, &st,\n+\t\tm = load_midx_chain_fd_st(r, object_dir, local, fd, &st,\n \t\t\t\t\t  &incomplete);\n \t}\n \n@@ -376,9 +380,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n \n \tget_midx_filename(&midx_name, object_dir);\n \n-\tm = load_multi_pack_index_one(object_dir, midx_name.buf, local);\n+\tm = load_multi_pack_index_one(the_repository, object_dir,\n+\t\t\t\t      midx_name.buf, local);\n \tif (!m)\n-\t\tm = load_multi_pack_index_chain(object_dir, local);\n+\t\tm = load_multi_pack_index_chain(the_repository, object_dir, local);\n \n \tstrbuf_release(&midx_name);\n \n@@ -520,7 +525,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,\n \t\t     uint32_t *result)\n {\n \tint ret = bsearch_hash(oid->hash, m->chunk_oid_fanout,\n-\t\t\t       m->chunk_oid_lookup, the_hash_algo->rawsz,\n+\t\t\t       m->chunk_oid_lookup, m->repo->hash_algo->rawsz,\n \t\t\t       result);\n \tif (result)\n \t\t*result += m->num_objects_in_base;\n@@ -551,7 +556,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,\n \tn = midx_for_object(&m, n);\n \n \toidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),\n-\t\tthe_repository->hash_algo);\n+\t\tm->repo->hash_algo);\n \treturn oid;\n }\n \n\n-- \n2.47.1\n\n"},{"id":"508238","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-6-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 6/8] midx: pass `repository` to `load_multi_pack_index`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:31Z","receivedAt":"2024-11-27T16:28:54Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `load_multi_pack_index` function in midx uses `the_repository`\nvariable to access the `repository` struct. Modify the function and its\ncallee's to send the `repository` field.\n\nThis moves usage of `the_repository` to the `test-read-midx.c` file.\nWhile that is not optimal, it is okay, since the upcoming commits will\nslowly move the usage of `the_repository` up the layers and remove it\neventually.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c                    | 11 ++++++-----\n midx.h                    |  4 +++-\n t/helper/test-read-midx.c |  8 ++++----\n 3 files changed, 13 insertions(+), 10 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 6f0fb8285af14843da132ef1b0c3a8bdd06732c9..98ee84d4a8bf388906634ad695ff39acdaa2c6d5 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -372,7 +372,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r\n \treturn m;\n }\n \n-struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n+struct multi_pack_index *load_multi_pack_index(struct repository *r,\n+\t\t\t\t\t       const char *object_dir,\n \t\t\t\t\t       int local)\n {\n \tstruct strbuf midx_name = STRBUF_INIT;\n@@ -380,10 +381,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,\n \n \tget_midx_filename(&midx_name, object_dir);\n \n-\tm = load_multi_pack_index_one(the_repository, object_dir,\n+\tm = load_multi_pack_index_one(r, object_dir,\n \t\t\t\t      midx_name.buf, local);\n \tif (!m)\n-\t\tm = load_multi_pack_index_chain(the_repository, object_dir, local);\n+\t\tm = load_multi_pack_index_chain(r, object_dir, local);\n \n \tstrbuf_release(&midx_name);\n \n@@ -727,7 +728,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i\n \t\tif (!strcmp(object_dir, m_search->object_dir))\n \t\t\treturn 1;\n \n-\tm = load_multi_pack_index(object_dir, local);\n+\tm = load_multi_pack_index(r, object_dir, local);\n \n \tif (m) {\n \t\tstruct multi_pack_index *mp = r->objects->multi_pack_index;\n@@ -881,7 +882,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag\n \tstruct pair_pos_vs_id *pairs = NULL;\n \tuint32_t i;\n \tstruct progress *progress = NULL;\n-\tstruct multi_pack_index *m = load_multi_pack_index(object_dir, 1);\n+\tstruct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1);\n \tstruct multi_pack_index *curr;\n \tverify_midx_error = 0;\n \ndiff --git a/midx.h b/midx.h\nindex c37ad5b5242b56d21fd76bd59957a1bdb82786ec..78efa28d35371795fa33c68660278182debb60ab 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -97,7 +97,9 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext);\n \n-struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);\n+struct multi_pack_index *load_multi_pack_index(struct repository *r,\n+\t\t\t\t\t       const char *object_dir,\n+\t\t\t\t\t       int local);\n int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);\n struct packed_git *nth_midxed_pack(struct multi_pack_index *m,\n \t\t\t\t   uint32_t pack_int_id);\ndiff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c\nindex 438fb9fc6197fc465f79d9a65b719ae315fed373..fc632369618917e2d8cdcb77bd9073c61e1544c1 100644\n--- a/t/helper/test-read-midx.c\n+++ b/t/helper/test-read-midx.c\n@@ -18,7 +18,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,\n \tstruct multi_pack_index *m;\n \n \tsetup_git_directory();\n-\tm = load_multi_pack_index(object_dir, 1);\n+\tm = load_multi_pack_index(the_repository, object_dir, 1);\n \n \tif (!m)\n \t\treturn 1;\n@@ -82,7 +82,7 @@ static int read_midx_checksum(const char *object_dir)\n \tstruct multi_pack_index *m;\n \n \tsetup_git_directory();\n-\tm = load_multi_pack_index(object_dir, 1);\n+\tm = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!m)\n \t\treturn 1;\n \tprintf(\"%s\\n\", hash_to_hex(get_midx_checksum(m)));\n@@ -98,7 +98,7 @@ static int read_midx_preferred_pack(const char *object_dir)\n \n \tsetup_git_directory();\n \n-\tmidx = load_multi_pack_index(object_dir, 1);\n+\tmidx = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!midx)\n \t\treturn 1;\n \n@@ -121,7 +121,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)\n \n \tsetup_git_directory();\n \n-\tmidx = load_multi_pack_index(object_dir, 1);\n+\tmidx = load_multi_pack_index(the_repository, object_dir, 1);\n \tif (!midx)\n \t\treturn 1;\n \n\n-- \n2.47.1\n\n"},{"id":"508239","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-7-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 7/8] midx: pass down `hash_algo` to functions using global variables","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:32Z","receivedAt":"2024-11-27T16:28:55Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The functions `get_split_midx_filename_ext()`, `get_midx_filename()` and\n`get_midx_filename_ext()` use `hash_to_hex()` which internally uses the\n`the_hash_algo` global variable.\n\nRemove this dependency on global variables by passing down the\n`hash_algo` through to the functions mentioned and instead calling\n`hash_to_hex_algop()` along with the obtained `hash_algo`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx-write.c    | 22 +++++++++++-----------\n midx.c          | 26 +++++++++++++++-----------\n midx.h          | 10 +++++++---\n pack-bitmap.c   |  6 +++---\n pack-revindex.c |  2 +-\n 5 files changed, 37 insertions(+), 29 deletions(-)\n\ndiff --git a/midx-write.c b/midx-write.c\nindex 1bc2f5256916e69924245951f654c1047ffeab84..bcd1d50eb0f5c292c904a38f13279b1ebec9c855 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -991,9 +991,10 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \tfor (i = 0; i < ARRAY_SIZE(midx_exts); i++) {\n \t\tconst unsigned char *hash = get_midx_checksum(m);\n \n-\t\tget_midx_filename_ext(&from, m->object_dir, hash,\n-\t\t\t\t      midx_exts[i].non_split);\n-\t\tget_split_midx_filename_ext(&to, m->object_dir, hash,\n+\t\tget_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,\n+\t\t\t\t      hash, midx_exts[i].non_split);\n+\t\tget_split_midx_filename_ext(m->repo->hash_algo, &to,\n+\t\t\t\t\t    m->object_dir, hash,\n \t\t\t\t\t    midx_exts[i].split);\n \n \t\tif (link(from.buf, to.buf) < 0 && errno != ENOENT) {\n@@ -1012,9 +1013,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)\n \treturn ret;\n }\n \n-static void clear_midx_files(const char *object_dir,\n-\t\t\t     const char **hashes,\n-\t\t\t     uint32_t hashes_nr,\n+static void clear_midx_files(struct repository *r, const char *object_dir,\n+\t\t\t     const char **hashes, uint32_t hashes_nr,\n \t\t\t     unsigned incremental)\n {\n \t/*\n@@ -1039,7 +1039,7 @@ static void clear_midx_files(const char *object_dir,\n \t}\n \n \tif (incremental)\n-\t\tget_midx_filename(&buf, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &buf, object_dir);\n \telse\n \t\tget_midx_chain_filename(&buf, object_dir);\n \n@@ -1083,7 +1083,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\t\t    \"%s/pack/multi-pack-index.d/tmp_midx_XXXXXX\",\n \t\t\t    object_dir);\n \telse\n-\t\tget_midx_filename(&midx_name, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &midx_name, object_dir);\n \tif (safe_create_leading_directories(midx_name.buf))\n \t\tdie_errno(_(\"unable to create leading directories of %s\"),\n \t\t\t  midx_name.buf);\n@@ -1440,8 +1440,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \t\tif (link_midx_to_chain(ctx.base_midx) < 0)\n \t\t\treturn -1;\n \n-\t\tget_split_midx_filename_ext(&final_midx_name, object_dir,\n-\t\t\t\t\t    midx_hash, MIDX_EXT_MIDX);\n+\t\tget_split_midx_filename_ext(r->hash_algo, &final_midx_name,\n+\t\t\t\t\t    object_dir, midx_hash, MIDX_EXT_MIDX);\n \n \t\tif (rename_tempfile(&incr, final_midx_name.buf) < 0) {\n \t\t\terror_errno(_(\"unable to rename new multi-pack-index layer\"));\n@@ -1474,7 +1474,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,\n \tif (commit_lock_file(&lk) < 0)\n \t\tdie_errno(_(\"could not write multi-pack-index\"));\n \n-\tclear_midx_files(object_dir, keep_hashes,\n+\tclear_midx_files(r, object_dir, keep_hashes,\n \t\t\t ctx.num_multi_pack_indexes_before + 1,\n \t\t\t ctx.incremental);\n \ndiff --git a/midx.c b/midx.c\nindex 98ee84d4a8bf388906634ad695ff39acdaa2c6d5..f45ea842cd6eda23d2eadc9deaae43839aef24c1 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -28,17 +28,19 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)\n \treturn m->data + m->data_len - m->repo->hash_algo->rawsz;\n }\n \n-void get_midx_filename(struct strbuf *out, const char *object_dir)\n+void get_midx_filename(const struct git_hash_algo *hash_algo,\n+\t\t       struct strbuf *out, const char *object_dir)\n {\n-\tget_midx_filename_ext(out, object_dir, NULL, NULL);\n+\tget_midx_filename_ext(hash_algo, out, object_dir, NULL, NULL);\n }\n \n-void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n+void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t   struct strbuf *out, const char *object_dir,\n \t\t\t   const unsigned char *hash, const char *ext)\n {\n \tstrbuf_addf(out, \"%s/pack/multi-pack-index\", object_dir);\n \tif (ext)\n-\t\tstrbuf_addf(out, \"-%s.%s\", hash_to_hex(hash), ext);\n+\t\tstrbuf_addf(out, \"-%s.%s\", hash_to_hex_algop(hash, hash_algo), ext);\n }\n \n static int midx_read_oid_fanout(const unsigned char *chunk_start,\n@@ -234,11 +236,13 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir)\n \tstrbuf_addstr(buf, \"/multi-pack-index-chain\");\n }\n \n-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t\t struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext)\n {\n \tget_midx_chain_dirname(buf, object_dir);\n-\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\", hash_to_hex(hash), ext);\n+\tstrbuf_addf(buf, \"/multi-pack-index-%s.%s\",\n+\t\t    hash_to_hex_algop(hash, hash_algo), ext);\n }\n \n static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,\n@@ -326,8 +330,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,\n \t\tvalid = 0;\n \n \t\tstrbuf_reset(&buf);\n-\t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n-\t\t\t\t\t    MIDX_EXT_MIDX);\n+\t\tget_split_midx_filename_ext(r->hash_algo, &buf, object_dir,\n+\t\t\t\t\t    layer.hash, MIDX_EXT_MIDX);\n \t\tm = load_multi_pack_index_one(r, object_dir, buf.buf, local);\n \n \t\tif (m) {\n@@ -379,7 +383,7 @@ struct multi_pack_index *load_multi_pack_index(struct repository *r,\n \tstruct strbuf midx_name = STRBUF_INIT;\n \tstruct multi_pack_index *m;\n \n-\tget_midx_filename(&midx_name, object_dir);\n+\tget_midx_filename(r->hash_algo, &midx_name, object_dir);\n \n \tm = load_multi_pack_index_one(r, object_dir,\n \t\t\t\t      midx_name.buf, local);\n@@ -822,7 +826,7 @@ void clear_midx_file(struct repository *r)\n {\n \tstruct strbuf midx = STRBUF_INIT;\n \n-\tget_midx_filename(&midx, r->objects->odb->path);\n+\tget_midx_filename(r->hash_algo, &midx, r->objects->odb->path);\n \n \tif (r->objects && r->objects->multi_pack_index) {\n \t\tclose_midx(r->objects->multi_pack_index);\n@@ -891,7 +895,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag\n \t\tstruct stat sb;\n \t\tstruct strbuf filename = STRBUF_INIT;\n \n-\t\tget_midx_filename(&filename, object_dir);\n+\t\tget_midx_filename(r->hash_algo, &filename, object_dir);\n \n \t\tif (!stat(filename.buf, &sb)) {\n \t\t\terror(_(\"multi-pack-index file exists, but failed to parse\"));\ndiff --git a/midx.h b/midx.h\nindex 78efa28d35371795fa33c68660278182debb60ab..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -7,6 +7,7 @@ struct object_id;\n struct pack_entry;\n struct repository;\n struct bitmapped_pack;\n+struct git_hash_algo;\n \n #define MIDX_SIGNATURE 0x4d494458 /* \"MIDX\" */\n #define MIDX_VERSION 1\n@@ -89,12 +90,15 @@ struct multi_pack_index {\n #define MIDX_EXT_MIDX \"midx\"\n \n const unsigned char *get_midx_checksum(struct multi_pack_index *m);\n-void get_midx_filename(struct strbuf *out, const char *object_dir);\n-void get_midx_filename_ext(struct strbuf *out, const char *object_dir,\n+void get_midx_filename(const struct git_hash_algo *hash_algo,\n+\t\t       struct strbuf *out, const char *object_dir);\n+void get_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t   struct strbuf *out, const char *object_dir,\n \t\t\t   const unsigned char *hash, const char *ext);\n void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);\n void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);\n-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,\n+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,\n+\t\t\t\t struct strbuf *buf, const char *object_dir,\n \t\t\t\t const unsigned char *hash, const char *ext);\n \n struct multi_pack_index *load_multi_pack_index(struct repository *r,\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 0cb1b56c9d5a55936ba53e2ff904ffe46cdcbafc..7b62d099cab5729a60a36b3ad15276fdc351aa97 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -375,8 +375,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)\n char *midx_bitmap_filename(struct multi_pack_index *midx)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tget_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx),\n-\t\t\t      MIDX_EXT_BITMAP);\n+\tget_midx_filename_ext(midx->repo->hash_algo, &buf, midx->object_dir,\n+\t\t\t      get_midx_checksum(midx), MIDX_EXT_BITMAP);\n \n \treturn strbuf_detach(&buf, NULL);\n }\n@@ -415,7 +415,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n \n \tif (bitmap_git->pack || bitmap_git->midx) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tget_midx_filename(&buf, midx->object_dir);\n+\t\tget_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir);\n \t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n \t\t\t\t   \"ignoring extra midx bitmap file\", buf.buf);\n \t\tclose(fd);\ndiff --git a/pack-revindex.c b/pack-revindex.c\nindex 22d3c2346488de6279b6f26a69fe611106c1365a..d3832478d99edffae17db0bbe85aa981c1a3ad30 100644\n--- a/pack-revindex.c\n+++ b/pack-revindex.c\n@@ -383,7 +383,7 @@ int load_midx_revindex(struct multi_pack_index *m)\n \ttrace2_data_string(\"load_midx_revindex\", the_repository,\n \t\t\t   \"source\", \"rev\");\n \n-\tget_midx_filename_ext(&revindex_name, m->object_dir,\n+\tget_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir,\n \t\t\t      get_midx_checksum(m), MIDX_EXT_REV);\n \n \tret = load_revindex_from_disk(revindex_name.buf,\n\n-- \n2.47.1\n\n"},{"id":"508240","messageId":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-8-c5a99f85009b@gmail.com","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"[PATCH v3 8/8] midx: inline the `MIDX_MIN_SIZE` definition","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-11-27T16:28:33Z","receivedAt":"2024-11-27T16:28:56Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `MIDX_MIN_SIZE` definition is used to check the midx_size in\n`local_multi_pack_index_one`. This definition relies on the\n`the_hash_algo` global variable. Inline this and remove the global\nvariable usage.\n\nWith this, remove `USE_THE_REPOSITORY_VARIABLE` usage from `midx.c`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex f45ea842cd6eda23d2eadc9deaae43839aef24c1..e0eae1c25ec91f7db5670ff9bacdf0e195c35795 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"dir.h\"\n@@ -94,8 +92,6 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,\n \treturn 0;\n }\n \n-#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n-\n static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n \t\t\t\t\t\t\t  const char *object_dir,\n \t\t\t\t\t\t\t  const char *midx_name,\n@@ -122,7 +118,7 @@ static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,\n \n \tmidx_size = xsize_t(st.st_size);\n \n-\tif (midx_size < MIDX_MIN_SIZE) {\n+\tif (midx_size < (MIDX_HEADER_SIZE + r->hash_algo->rawsz)) {\n \t\terror(_(\"multi-pack-index file %s is too small\"), midx_name);\n \t\tgoto cleanup_fail;\n \t}\n\n-- \n2.47.1\n\n"},{"id":"508257","messageId":"xmqq5xo8qh9h.fsf@gitster.g","threadId":"62498","inReplyTo":"20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com","subject":"Re: [PATCH v3 0/8] Change midx.c and midx-write.c to not use global variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-28T01:27:54Z","receivedAt":"2024-11-28T01:27:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Karthik Nayak <karthik.188@gmail.com> writes:\n\n> Changes in v3:\n> - Split out the first commit into a separate series [1].\n> - Improved some of the commit messages to be more descriptive.\n> - Merged the 8th and 9th commits together, since they were similar.\n> - v2: https://lore.kernel.org/r/20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com\n\nMerging either v2 or v3 to 'master', together with their\nprerequisite topics/patches, seems to result in identical trees,\nwhich is fine if reviews on previous rounds did not find any bugs.\n\nWill queue.  Thanks.\n\n"},{"id":"508522","messageId":"Z07SsWL6sExkYUdi@pks.im","threadId":"62498","inReplyTo":"xmqq5xo8qh9h.fsf@gitster.g","subject":"Re: [PATCH v3 0/8] Change midx.c and midx-write.c to not use global variables","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-12-03T09:43:13Z","receivedAt":"2024-12-03T09:43:32Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 28, 2024 at 10:27:54AM +0900, Junio C Hamano wrote:\n> Karthik Nayak <karthik.188@gmail.com> writes:\n> \n> > Changes in v3:\n> > - Split out the first commit into a separate series [1].\n> > - Improved some of the commit messages to be more descriptive.\n> > - Merged the 8th and 9th commits together, since they were similar.\n> > - v2: https://lore.kernel.org/r/20241119-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v2-0-e2f607174efc@gmail.com\n> \n> Merging either v2 or v3 to 'master', together with their\n> prerequisite topics/patches, seems to result in identical trees,\n> which is fine if reviews on previous rounds did not find any bugs.\n> \n> Will queue.  Thanks.\n\nI've had another read through the series and couldn't find any issues\nwith it. I also scanned through v2 to see whether there was any feedback\non code, but it seems like the only complaints there were about commit\nmessages. So I guess it is expected that the trees are identical.\n\nSo this looks good to me overall, thanks!\n\nPatrick\n"},{"id":"508578","messageId":"xmqq7c8gbc45.fsf@gitster.g","threadId":"62498","inReplyTo":"Z07SsWL6sExkYUdi@pks.im","subject":"Re: [PATCH v3 0/8] Change midx.c and midx-write.c to not use global variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-12-03T23:06:18Z","receivedAt":"2024-12-03T23:06:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> I've had another read through the series and couldn't find any issues\n> with it. I also scanned through v2 to see whether there was any feedback\n> on code, but it seems like the only complaints there were about commit\n> messages. So I guess it is expected that the trees are identical.\n>\n> So this looks good to me overall, thanks!\n\nLet's merge it down to 'next', then.  Thanks, all.\n"}]}