{"thread":{"id":"62956","subject":"[PATCH 0/7][Outreachy] stop using the_repository global variable.","startedAt":"2025-02-14T23:02:17Z","lastAt":"2025-03-07T23:36:16Z","messageCount":63,"participants":["Usman Akinyemi","shejialuo","Patrick Steinhardt","Junio C Hamano","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"512447","messageId":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":null,"subject":"[PATCH 0/7][Outreachy] stop using the_repository global variable.","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:16Z","receivedAt":"2025-02-14T23:02:17Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove `the_repository` global variable in favor of the repository\nargument that gets passed in builtin commands. \n\nThese sets of commands are commands that use only RUN_SETUP macro in \"git.c\".\nBasically, When `-h` is passed to any of this command outside a Git repository,\nthe `run_builtin()` will call the `cmd_x()` function (where `x` is any\nof the command from the sets of builtin commands that `the_repository` is removed\nfrom) with `repo` set to NULL and then early in the function, `parse_options()`\nor show_usage_with_options_if_asked() call will give the options help and exit,\nwithout having to consult much of the configuration file.\n\nAs there exist some builtin commands where the `repository` variable is accessed\nbefore options is given exit and fail, we should check if the `repository` variable\nis not NULL in such scenerio.\n\nSome, functions also uses `the_repository` global internally, so, let's\nlet's refactor them and pass `struct repo` as one of the argument. \n\nI picked some of this files based on the above explanation, how easy they are to\nresolve and how easy easy to review. \n\n[1]: https://public-inbox.org/git/20250210181103.3609495-1-usmanakinyemi202@gmail.com/\n*** BLURB HERE ***\n\nUsman Akinyemi (7):\n  builtin/verify-tag: stop using `the_repository`\n  builtin/verify-commit.c: stop using `the_repository`\n  builtin/send-pack.c: stop using `the_repository`\n  builtin/pack-refs: stop using `the_repository`\n  builtin/ls-files: stop using `the_repository`\n  builtin/for-each-ref: stop using `the_repository`\n  builtin/checkout-index.c: stop using `the_repository`\n\n builtin/checkout-index.c | 43 ++++++++++++++++++++--------------------\n builtin/for-each-ref.c   |  6 +++---\n builtin/ls-files.c       | 32 +++++++++++++++---------------\n builtin/pack-refs.c      |  9 ++++-----\n builtin/send-pack.c      |  8 ++++----\n builtin/verify-commit.c  | 14 ++++++-------\n builtin/verify-tag.c     |  8 ++++----\n 7 files changed, 59 insertions(+), 61 deletions(-)\n\n-- \n2.48.1\n\n"},{"id":"512448","messageId":"20250214230210.1460111-2-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 1/7] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:17Z","receivedAt":"2025-02-14T23:02:20Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-tag.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit, without having to consult much of the\nconfiguration file. So it is safe to omit reading the config when `repo`\nargument the caller gave us is NULL.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-tag.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/verify-tag.c b/builtin/verify-tag.c\nindex f6b97048a5..990e967af3 100644\n--- a/builtin/verify-tag.c\n+++ b/builtin/verify-tag.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag.sh\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {\n int cmd_verify_tag(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n+\tif (repo)\n+\t\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, verify_tag_options,\n \t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n@@ -56,7 +56,7 @@ int cmd_verify_tag(int argc,\n \t\tstruct object_id oid;\n \t\tconst char *name = argv[i++];\n \n-\t\tif (repo_get_oid(the_repository, name, &oid)) {\n+\t\tif (repo_get_oid(repo, name, &oid)) {\n \t\t\thad_error = !!error(\"tag '%s' not found.\", name);\n \t\t\tcontinue;\n \t\t}\n-- \n2.48.1\n\n"},{"id":"512449","messageId":"20250214230210.1460111-3-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 2/7] builtin/verify-commit.c: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:18Z","receivedAt":"2025-02-14T23:02:24Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-tag.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_commit()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit, without having to consult much of the\nconfiguration file. So it is safe to omit reading the config when `repo`\nargument the caller gave us is NULL.\n\nLet's pass `repository` argument to `verify_commit()` function to remove\nit's dependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-commit.c | 14 +++++++-------\n 1 file changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex 779b7988ca..50f56d296c 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)\n \treturn ret;\n }\n \n-static int verify_commit(const char *name, unsigned flags)\n+static int verify_commit(struct repository *repo, const char *name, unsigned flags)\n {\n \tstruct object_id oid;\n \tstruct object *obj;\n \n-\tif (repo_get_oid(the_repository, name, &oid))\n+\tif (repo_get_oid(repo, name, &oid))\n \t\treturn error(\"commit '%s' not found.\", name);\n \n-\tobj = parse_object(the_repository, &oid);\n+\tobj = parse_object(repo, &oid);\n \tif (!obj)\n \t\treturn error(\"%s: unable to read file.\", name);\n \tif (obj->type != OBJ_COMMIT)\n@@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags)\n int cmd_verify_commit(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -64,7 +63,8 @@ int cmd_verify_commit(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n+\tif (repo)\n+\t\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, verify_commit_options,\n \t\t\t     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);\n@@ -78,7 +78,7 @@ int cmd_verify_commit(int argc,\n \t * was received in the process of writing the gpg input: */\n \tsignal(SIGPIPE, SIG_IGN);\n \twhile (i < argc)\n-\t\tif (verify_commit(argv[i++], flags))\n+\t\tif (verify_commit(repo, argv[i++], flags))\n \t\t\thad_error = 1;\n \treturn had_error;\n }\n-- \n2.48.1\n\n"},{"id":"512450","messageId":"20250214230210.1460111-4-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 3/7] builtin/send-pack.c: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:19Z","receivedAt":"2025-02-14T23:02:27Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/send-pack.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_send_pack()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit, without having to consult much of the\nconfiguration file. So it is safe to omit reading the config when `repo`\nargument the caller gave us is NULL.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/send-pack.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/send-pack.c b/builtin/send-pack.c\nindex 8d461008e2..737b93e4a8 100644\n--- a/builtin/send-pack.c\n+++ b/builtin/send-pack.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"hex.h\"\n@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,\n int cmd_send_pack(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 \tstruct refspec rs = REFSPEC_INIT_PUSH;\n \tconst char *remote_name = NULL;\n@@ -212,7 +211,8 @@ int cmd_send_pack(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(send_pack_config, NULL);\n+\tif (repo)\n+\t\trepo_config(repo, send_pack_config, NULL);\n \targc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);\n \tif (argc > 0) {\n \t\tdest = argv[0];\n@@ -317,7 +317,7 @@ int cmd_send_pack(int argc,\n \tset_ref_status_for_push(remote_refs, args.send_mirror,\n \t\targs.force_update);\n \n-\tret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);\n+\tret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);\n \n \tif (helper_status)\n \t\tprint_helper_status(remote_refs);\n-- \n2.48.1\n\n"},{"id":"512451","messageId":"20250214230210.1460111-5-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 4/7] builtin/pack-refs: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:20Z","receivedAt":"2025-02-14T23:02:30Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/pack-refs.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_pack_refs()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit, without having to consult much of the\nconfiguration file. So it is safe to omit reading the config when `repo`\nargument the caller gave us is NULL.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/pack-refs.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/pack-refs.c b/builtin/pack-refs.c\nindex 4fdd68880e..5c18230b6d 100644\n--- a/builtin/pack-refs.c\n+++ b/builtin/pack-refs.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {\n int cmd_pack_refs(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 \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n@@ -39,7 +37,8 @@ int cmd_pack_refs(int argc,\n \t\t\tN_(\"references to exclude\")),\n \t\tOPT_END(),\n \t};\n-\tgit_config(git_default_config, NULL);\n+\tif (repo)\n+\t\trepo_config(repo, git_default_config, NULL);\n \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n \t\tusage_with_options(pack_refs_usage, opts);\n \n@@ -52,7 +51,7 @@ int cmd_pack_refs(int argc,\n \tif (!pack_refs_opts.includes->nr)\n \t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n \n-\tret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);\n+\tret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);\n \n \tclear_ref_exclusions(&excludes);\n \tstring_list_clear(&included_refs, 0);\n-- \n2.48.1\n\n"},{"id":"512452","messageId":"20250214230210.1460111-6-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 5/7] builtin/ls-files: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:21Z","receivedAt":"2025-02-14T23:02:33Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/ls-files.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_ls_files()` function with `repo` set\nto NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit, without having to consult much\nof the configuration file.\n\nLet's pass `repository` argument to `expand_objectsize()`,\n`show_ru_info()` functions to remove their dependency on the global\n`the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/ls-files.c | 32 ++++++++++++++++----------------\n 1 file changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a4431429b7..70a377e9c0 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -6,7 +6,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -245,12 +244,13 @@ static void show_submodule(struct repository *superproject,\n \trepo_clear(&subrepo);\n }\n \n-static void expand_objectsize(struct strbuf *line, const struct object_id *oid,\n+static void expand_objectsize(struct repository *repo, struct strbuf *line,\n+\t\t\t      const struct object_id *oid,\n \t\t\t      const enum object_type type, unsigned int padded)\n {\n \tif (type == OBJ_BLOB) {\n \t\tunsigned long size;\n-\t\tif (oid_object_info(the_repository, oid, &size) < 0)\n+\t\tif (oid_object_info(repo, oid, &size) < 0)\n \t\t\tdie(_(\"could not get object info about '%s'\"),\n \t\t\t    oid_to_hex(oid));\n \t\tif (padded)\n@@ -283,10 +283,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,\n \t\telse if (skip_prefix(format, \"(objecttype)\", &format))\n \t\t\tstrbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));\n \t\telse if (skip_prefix(format, \"(objectsize:padded)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 1);\n \t\telse if (skip_prefix(format, \"(objectsize)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 0);\n \t\telse if (skip_prefix(format, \"(stage)\", &format))\n \t\t\tstrbuf_addf(&sb, \"%d\", ce_stage(ce));\n@@ -348,7 +348,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,\n \t}\n }\n \n-static void show_ru_info(struct index_state *istate)\n+static void show_ru_info(struct repository *repo, struct index_state *istate)\n {\n \tstruct string_list_item *item;\n \n@@ -370,7 +370,7 @@ static void show_ru_info(struct index_state *istate)\n \t\t\tif (!ui->mode[i])\n \t\t\t\tcontinue;\n \t\t\tprintf(\"%s%06o %s %d\\t\", tag_resolve_undo, ui->mode[i],\n-\t\t\t       repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev),\n+\t\t\t       repo_find_unique_abbrev(repo, &ui->oid[i], abbrev),\n \t\t\t       i + 1);\n \t\t\twrite_name(path);\n \t\t}\n@@ -567,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt,\n int cmd_ls_files(int argc,\n \t\t const char **argv,\n \t\t const char *cmd_prefix,\n-\t\t struct repository *repo UNUSED)\n+\t\t struct repository *repo)\n {\n \tint require_work_tree = 0, show_tag = 0, i;\n \tchar *max_prefix;\n@@ -647,15 +647,15 @@ int cmd_ls_files(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t ls_files_usage, builtin_ls_files_options);\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n \tprefix = cmd_prefix;\n \tif (prefix)\n \t\tprefix_len = strlen(prefix);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n-\tif (repo_read_index(the_repository) < 0)\n+\tif (repo_read_index(repo) < 0)\n \t\tdie(\"index file corrupt\");\n \n \targc = parse_options(argc, argv, prefix, builtin_ls_files_options,\n@@ -724,7 +724,7 @@ int cmd_ls_files(int argc,\n \t\tmax_prefix = common_prefix(&pathspec);\n \tmax_prefix_len = get_common_prefix_len(max_prefix);\n \n-\tprune_index(the_repository->index, max_prefix, max_prefix_len);\n+\tprune_index(repo->index, max_prefix, max_prefix_len);\n \n \t/* Treat unmatching pathspec elements as errors */\n \tif (pathspec.nr && error_unmatch)\n@@ -748,13 +748,13 @@ int cmd_ls_files(int argc,\n \t\t */\n \t\tif (show_stage || show_unmerged)\n \t\t\tdie(_(\"options '%s' and '%s' cannot be used together\"), \"ls-files --with-tree\", \"-s/-u\");\n-\t\toverlay_tree_on_index(the_repository->index, with_tree, max_prefix);\n+\t\toverlay_tree_on_index(repo->index, with_tree, max_prefix);\n \t}\n \n-\tshow_files(the_repository, &dir);\n+\tshow_files(repo, &dir);\n \n \tif (show_resolve_undo)\n-\t\tshow_ru_info(the_repository->index);\n+\t\tshow_ru_info(repo, repo->index);\n \n \tif (ps_matched && report_path_error(ps_matched, &pathspec)) {\n \t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\n-- \n2.48.1\n\n"},{"id":"512453","messageId":"20250214230210.1460111-7-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 6/7] builtin/for-each-ref: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:22Z","receivedAt":"2025-02-14T23:02:35Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/for-each-ref.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_for_each_ref()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit, without having to consult much of the\nconfiguration file. So it is safe to omit reading the config when `repo`\nargument the caller gave us is NULL.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/for-each-ref.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 8085ebd8fe..0e9b126605 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"commit.h\"\n #include \"config.h\"\n@@ -20,7 +19,7 @@ static char const * const for_each_ref_usage[] = {\n int cmd_for_each_ref(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 \tstruct ref_sorting *sorting;\n \tstruct string_list sorting_options = STRING_LIST_INIT_DUP;\n@@ -63,7 +62,8 @@ int cmd_for_each_ref(int argc,\n \n \tformat.format = \"%(objectname) %(objecttype)\\t%(refname)\";\n \n-\tgit_config(git_default_config, NULL);\n+\tif (repo)\n+\t\trepo_config(repo, git_default_config, NULL);\n \n \t/* Set default (refname) sorting */\n \tstring_list_append(&sorting_options, \"refname\");\n-- \n2.48.1\n\n"},{"id":"512454","messageId":"20250214230210.1460111-8-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH 7/7] builtin/checkout-index.c: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-14T22:57:23Z","receivedAt":"2025-02-14T23:02:38Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/checkout-index.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_checkout_index()` function with `repo`\nset to NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit, without having to consult much\nof the configuration file.\n\nLet's pass `repository` argument to `checkout_all()` and `checkout_file()`\nfunctions to remove their dependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/checkout-index.c | 43 ++++++++++++++++++++--------------------\n 1 file changed, 21 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex e30086c7d4..46035444eb 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -5,7 +5,6 @@\n  *\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -68,10 +67,10 @@ static void write_tempfile_record(const char *name, const char *prefix)\n \t}\n }\n \n-static int checkout_file(const char *name, const char *prefix)\n+static int checkout_file(struct repository *repo, const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = index_name_pos(the_repository->index, name, namelen);\n+\tint pos = index_name_pos(repo->index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -81,8 +80,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos <the_repository->index->cache_nr) {\n-\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n+\twhile (pos < repo->index->cache_nr) {\n+\t\tstruct cache_entry *ce =repo->index->cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -137,13 +136,13 @@ static int checkout_file(const char *name, const char *prefix)\n \treturn -1;\n }\n \n-static int checkout_all(const char *prefix, int prefix_length)\n+static int checkout_all(struct repository *repo, const char *prefix, int prefix_length)\n {\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n-\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n+\tfor (i = 0; i < repo->index->cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = repo->index->cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -156,8 +155,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t * first entry inside the expanded sparse directory).\n \t\t\t */\n \t\t\tif (ignore_skip_worktree) {\n-\t\t\t\tensure_full_index(the_repository->index);\n-\t\t\t\tce = the_repository->index->cache[i];\n+\t\t\t\tensure_full_index(repo->index);\n+\t\t\t\tce = repo->index->cache[i];\n \t\t\t}\n \t\t}\n \n@@ -213,7 +212,7 @@ static int option_parse_stage(const struct option *opt,\n int cmd_checkout_index(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 \tint i;\n \tstruct lock_file lock_file = LOCK_INIT;\n@@ -253,19 +252,19 @@ int cmd_checkout_index(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t builtin_checkout_index_usage,\n \t\t\t\t\t builtin_checkout_index_options);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tprefix_length = prefix ? strlen(prefix) : 0;\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n-\tif (repo_read_index(the_repository) < 0) {\n+\tif (repo_read_index(repo) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n \targc = parse_options(argc, argv, prefix, builtin_checkout_index_options,\n \t\t\tbuiltin_checkout_index_usage, 0);\n-\tstate.istate = the_repository->index;\n+\tstate.istate = repo->index;\n \tstate.force = force;\n \tstate.quiet = quiet;\n \tstate.not_new = not_new;\n@@ -285,8 +284,8 @@ int cmd_checkout_index(int argc,\n \t */\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n-\t\tstate.istate = the_repository->index;\n-\t\trepo_hold_locked_index(the_repository, &lock_file,\n+\t\tstate.istate = repo->index;\n+\t\trepo_hold_locked_index(repo, &lock_file,\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n@@ -304,7 +303,7 @@ int cmd_checkout_index(int argc,\n \t\tif (read_from_stdin)\n \t\t\tdie(\"git checkout-index: don't mix '--stdin' and explicit filenames\");\n \t\tp = prefix_path(prefix, prefix_length, arg);\n-\t\terr |= checkout_file(p, prefix);\n+\t\terr |= checkout_file(repo, p, prefix);\n \t\tfree(p);\n \t}\n \n@@ -326,7 +325,7 @@ int cmd_checkout_index(int argc,\n \t\t\t\tstrbuf_swap(&buf, &unquoted);\n \t\t\t}\n \t\t\tp = prefix_path(prefix, prefix_length, buf.buf);\n-\t\t\terr |= checkout_file(p, prefix);\n+\t\t\terr |= checkout_file(repo, p, prefix);\n \t\t\tfree(p);\n \t\t}\n \t\tstrbuf_release(&unquoted);\n@@ -334,7 +333,7 @@ int cmd_checkout_index(int argc,\n \t}\n \n \tif (all)\n-\t\terr |= checkout_all(prefix, prefix_length);\n+\t\terr |= checkout_all(repo, prefix, prefix_length);\n \n \tif (pc_workers > 1)\n \t\terr |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n@@ -344,7 +343,7 @@ int cmd_checkout_index(int argc,\n \t\treturn 1;\n \n \tif (is_lock_file_locked(&lock_file) &&\n-\t    write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n+\t    write_locked_index(repo->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\n-- \n2.48.1\n\n"},{"id":"512472","messageId":"Z7F4ftdJHlMB0RL-@ArchLinux","threadId":"62956","inReplyTo":"20250214230210.1460111-3-usmanakinyemi202@gmail.com","subject":"Re: [PATCH 2/7] builtin/verify-commit.c: stop using `the_repository`","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2025-02-16T05:32:46Z","receivedAt":"2025-02-16T05:32:50Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Sat, Feb 15, 2025 at 04:27:18AM +0530, Usman Akinyemi wrote:\n> Remove the_repository global variable in favor of the repository\n> argument that gets passed in \"builtin/verify-tag.c\".\n> \n\nI think this is a typo. \"builtin/verify-tag.c\" should be\n\"builtin/verify-commit.c\".\n"},{"id":"512473","messageId":"Z7F6oSEkg4JSs9bp@ArchLinux","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"Re: [PATCH 0/7][Outreachy] stop using the_repository global variable.","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2025-02-16T05:41:53Z","receivedAt":"2025-02-16T05:41:57Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Sat, Feb 15, 2025 at 04:27:16AM +0530, Usman Akinyemi wrote:\n\n[snip]\n\n> Usman Akinyemi (7):\n>   builtin/verify-tag: stop using `the_repository`\n>   builtin/verify-commit.c: stop using `the_repository`\n>   builtin/send-pack.c: stop using `the_repository`\n>   builtin/pack-refs: stop using `the_repository`\n>   builtin/ls-files: stop using `the_repository`\n>   builtin/for-each-ref: stop using `the_repository`\n>   builtin/checkout-index.c: stop using `the_repository`\n> \n\nThe commit message is not consistent. We should remove \".c\".\n"},{"id":"512500","messageId":"Z7LdauBUSfqvyvXv@pks.im","threadId":"62956","inReplyTo":"20250214230210.1460111-2-usmanakinyemi202@gmail.com","subject":"Re: [PATCH 1/7] builtin/verify-tag: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-02-17T06:55:38Z","receivedAt":"2025-02-17T06:55:51Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Feb 15, 2025 at 04:27:17AM +0530, Usman Akinyemi wrote:\n> @@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,\n>  \t\tOPT_END()\n>  \t};\n>  \n> -\tgit_config(git_default_config, NULL);\n> +\tif (repo)\n> +\t\trepo_config(repo, git_default_config, NULL);\n>  \n\nI recently noticed that we have `usage_with_options_if_asked()`. Should\nwe use that function rather than making the call to `git_config()`\nconditional? Otherwise it's not obvious why we have the conditional in\nthe first place.\n\nThe same comment also applies to subsequent commits.\n\nPatrick\n"},{"id":"512501","messageId":"Z7Lddaa3SLSEziMx@pks.im","threadId":"62956","inReplyTo":"20250214230210.1460111-6-usmanakinyemi202@gmail.com","subject":"Re: [PATCH 5/7] builtin/ls-files: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-02-17T06:55:49Z","receivedAt":"2025-02-17T06:55:53Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Feb 15, 2025 at 04:27:21AM +0530, Usman Akinyemi wrote:\n> Remove the_repository global variable in favor of the repository\n> argument that gets passed in \"builtin/ls-files.c\".\n> \n> When `-h` is passed to the command outside a Git repository, the\n> `run_builtin()` will call the `cmd_ls_files()` function with `repo` set\n> to NULL and then early in the function, `show_usage_with_options_if_asked()`\n> call will give the options help and exit, without having to consult much\n> of the configuration file.\n> \n> Let's pass `repository` argument to `expand_objectsize()`,\n> `show_ru_info()` functions to remove their dependency on the global\n> `the_repository` variable.\n\nThis paragraph made my reading hickup a bit. How about:\n\n    Pass the repository available in the calling context to both\n    `expand_objectsize()` and `show_ru_info()` to remove their\n    dependency on the global `the_repository` variable.\n\nPatrick\n"},{"id":"512502","messageId":"CAPSxiM-478vE=20gdX0QDt5J-vVcwRXZycGUAugafWPhXN093g@mail.gmail.com","threadId":"62956","inReplyTo":"Z7F4ftdJHlMB0RL-@ArchLinux","subject":"Re: [PATCH 2/7] builtin/verify-commit.c: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-17T08:55:25Z","receivedAt":"2025-02-17T08:55:38Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Sun, Feb 16, 2025 at 11:02 AM shejialuo <shejialuo@gmail.com> wrote:\n>\n> On Sat, Feb 15, 2025 at 04:27:18AM +0530, Usman Akinyemi wrote:\n> > Remove the_repository global variable in favor of the repository\n> > argument that gets passed in \"builtin/verify-tag.c\".\n> >\n>\n> I think this is a typo. \"builtin/verify-tag.c\" should be\n> \"builtin/verify-commit.c\".\nOhh, yeah, I will fix it in the next version. Thanks.\n"},{"id":"512503","messageId":"CAPSxiM_yzxTV9=U7amxZF_hxt77D42tsn8H4HgNW9S3g-q_-TA@mail.gmail.com","threadId":"62956","inReplyTo":"Z7F6oSEkg4JSs9bp@ArchLinux","subject":"Re: [PATCH 0/7][Outreachy] stop using the_repository global variable.","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-17T08:56:24Z","receivedAt":"2025-02-17T08:56:38Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Sun, Feb 16, 2025 at 11:11 AM shejialuo <shejialuo@gmail.com> wrote:\n>\n> On Sat, Feb 15, 2025 at 04:27:16AM +0530, Usman Akinyemi wrote:\n>\n> [snip]\n>\n> > Usman Akinyemi (7):\n> >   builtin/verify-tag: stop using `the_repository`\n> >   builtin/verify-commit.c: stop using `the_repository`\n> >   builtin/send-pack.c: stop using `the_repository`\n> >   builtin/pack-refs: stop using `the_repository`\n> >   builtin/ls-files: stop using `the_repository`\n> >   builtin/for-each-ref: stop using `the_repository`\n> >   builtin/checkout-index.c: stop using `the_repository`\n> >\n>\n> The commit message is not consistent. We should remove \".c\".\nYeah, I will fix it in the next version.\n"},{"id":"512504","messageId":"CAPSxiM-XmHepeWuOOU4RNj6ce_K3zmUYS=gmzUKqtnoKwRE1Xg@mail.gmail.com","threadId":"62956","inReplyTo":"Z7Lddaa3SLSEziMx@pks.im","subject":"Re: [PATCH 5/7] builtin/ls-files: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-17T08:57:12Z","receivedAt":"2025-02-17T08:57:25Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Mon, Feb 17, 2025 at 12:25 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Sat, Feb 15, 2025 at 04:27:21AM +0530, Usman Akinyemi wrote:\n> > Remove the_repository global variable in favor of the repository\n> > argument that gets passed in \"builtin/ls-files.c\".\n> >\n> > When `-h` is passed to the command outside a Git repository, the\n> > `run_builtin()` will call the `cmd_ls_files()` function with `repo` set\n> > to NULL and then early in the function, `show_usage_with_options_if_asked()`\n> > call will give the options help and exit, without having to consult much\n> > of the configuration file.\n> >\n> > Let's pass `repository` argument to `expand_objectsize()`,\n> > `show_ru_info()` functions to remove their dependency on the global\n> > `the_repository` variable.\n>\n> This paragraph made my reading hickup a bit. How about:\n>\n>     Pass the repository available in the calling context to both\n>     `expand_objectsize()` and `show_ru_info()` to remove their\n>     dependency on the global `the_repository` variable.\nThanks for the suggestion, I will use it in the next version.\n>\n> Patrick\n"},{"id":"512505","messageId":"CAPSxiM8vcH_csM21vtF11APtxfNy_QC91mfYkctaSP-8TyPmyA@mail.gmail.com","threadId":"62956","inReplyTo":"Z7LdauBUSfqvyvXv@pks.im","subject":"Re: [PATCH 1/7] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-17T10:05:05Z","receivedAt":"2025-02-17T10:05:18Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Mon, Feb 17, 2025 at 12:25 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Sat, Feb 15, 2025 at 04:27:17AM +0530, Usman Akinyemi wrote:\n> > @@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,\n> >               OPT_END()\n> >       };\n> >\n> > -     git_config(git_default_config, NULL);\n> > +     if (repo)\n> > +             repo_config(repo, git_default_config, NULL);\n> >\n>\n> I recently noticed that we have `usage_with_options_if_asked()`. Should\n> we use that function rather than making the call to `git_config()`\n> conditional? Otherwise it's not obvious why we have the conditional in\n> the first place.\nHi Patrick,\n\nI think the function is `show_usage_with_options_if_asked()`. The function\nis quite different from `git_config()` or the `repo_config()`.  The\nconfig function\nconsults the configuration file for setting up config values and it\nuses the `repo`\nvariable during this. While `show_usage_with_options_if_asked()`\nis used when the \"-h\" option is passed to the builtin functions to display\nthe help string.\n\nIn a case when \"-h\" is passed to the builtin functions which use the\nRUN_SETUP macro,\nthe `repo` config will be NULL.\n\nThere are some builtin commands functions that which has\nthe`git_config()` function\ncomes before `show_usage_with_options_if_asked()` or it's variant and\nsome, `git_config()`\ncomes after.\n\nFor those that have `git_config()` comes after\n`show_usage_with_options_if_asked()` , no need for the check, since\nthe\n `show_usage_with_options_if_asked()`call will exit without reaching\n`git_config()`. For scenario where the `git_config()`\ncomes earlier, we have to check the `repo` to see if it is NULL, if it\nis NULL, we are sure this happens when the \"-h\" is\npassed to the function and we do not need to setup and configuration\nsince `show_usage_with_options_if_asked()`\nwill exit.\n\nSo, the condition is necessary else, NULL value will be passed to the\n`git_config()` which will lead to accessing NULL\nvalue.\n\nThank you.\n>\n> The same comment also applies to subsequent commits.\n>\n> Patrick\n"},{"id":"512506","messageId":"Z7MN8-9rzf7h9zZi@pks.im","threadId":"62956","inReplyTo":"CAPSxiM8vcH_csM21vtF11APtxfNy_QC91mfYkctaSP-8TyPmyA@mail.gmail.com","subject":"Re: [PATCH 1/7] builtin/verify-tag: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-02-17T10:22:43Z","receivedAt":"2025-02-17T10:22:49Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Feb 17, 2025 at 03:35:05PM +0530, Usman Akinyemi wrote:\n> On Mon, Feb 17, 2025 at 12:25 PM Patrick Steinhardt <ps@pks.im> wrote:\n> >\n> > On Sat, Feb 15, 2025 at 04:27:17AM +0530, Usman Akinyemi wrote:\n> > > @@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,\n> > >               OPT_END()\n> > >       };\n> > >\n> > > -     git_config(git_default_config, NULL);\n> > > +     if (repo)\n> > > +             repo_config(repo, git_default_config, NULL);\n> > >\n> >\n> > I recently noticed that we have `usage_with_options_if_asked()`. Should\n> > we use that function rather than making the call to `git_config()`\n> > conditional? Otherwise it's not obvious why we have the conditional in\n> > the first place.\n> Hi Patrick,\n> \n> I think the function is `show_usage_with_options_if_asked()`. The function\n> is quite different from `git_config()` or the `repo_config()`.  The\n> config function consults the configuration file for setting up config\n> values and it uses the `repo` variable during this. While\n> `show_usage_with_options_if_asked()` is used when the \"-h\" option is\n> passed to the builtin functions to display the help string.\n> \n> In a case when \"-h\" is passed to the builtin functions which use the\n> RUN_SETUP macro, the `repo` config will be NULL.\n> \n> There are some builtin commands functions that which has\n> the`git_config()` function comes before\n> `show_usage_with_options_if_asked()` or it's variant and some,\n> `git_config()` comes after.\n> \n> For those that have `git_config()` comes after\n> `show_usage_with_options_if_asked()` , no need for the check, since\n> the `show_usage_with_options_if_asked()`call will exit without\n> reaching `git_config()`. For scenario where the `git_config()` comes\n> earlier, we have to check the `repo` to see if it is NULL, if it is\n> NULL, we are sure this happens when the \"-h\" is passed to the function\n> and we do not need to setup and configuration since\n> `show_usage_with_options_if_asked()` will exit.\n\nExactly, this is what my suggestion is. If we introduced new calls to\n`show_usage_with_options_if_asked()` before `git_config()` we wouldn't\nhave to check for a `NULL` repository in the first place because we know\nthat we'd have already exited if there was a \"-h\" parameter.\n\nPatrick\n"},{"id":"512507","messageId":"CAPSxiM-Bm9FtvVDJ_MggPFy_hV=h-ossk4p1z=ADGbttG=w-RA@mail.gmail.com","threadId":"62956","inReplyTo":"Z7MN8-9rzf7h9zZi@pks.im","subject":"Re: [PATCH 1/7] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-17T10:42:06Z","receivedAt":"2025-02-17T10:42:18Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Mon, Feb 17, 2025 at 3:52 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Mon, Feb 17, 2025 at 03:35:05PM +0530, Usman Akinyemi wrote:\n> > On Mon, Feb 17, 2025 at 12:25 PM Patrick Steinhardt <ps@pks.im> wrote:\n> > >\n> > > On Sat, Feb 15, 2025 at 04:27:17AM +0530, Usman Akinyemi wrote:\n> > > > @@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,\n> > > >               OPT_END()\n> > > >       };\n> > > >\n> > > > -     git_config(git_default_config, NULL);\n> > > > +     if (repo)\n> > > > +             repo_config(repo, git_default_config, NULL);\n> > > >\n> > >\n> > > I recently noticed that we have `usage_with_options_if_asked()`. Should\n> > > we use that function rather than making the call to `git_config()`\n> > > conditional? Otherwise it's not obvious why we have the conditional in\n> > > the first place.\n> > Hi Patrick,\n> >\n> > I think the function is `show_usage_with_options_if_asked()`. The function\n> > is quite different from `git_config()` or the `repo_config()`.  The\n> > config function consults the configuration file for setting up config\n> > values and it uses the `repo` variable during this. While\n> > `show_usage_with_options_if_asked()` is used when the \"-h\" option is\n> > passed to the builtin functions to display the help string.\n> >\n> > In a case when \"-h\" is passed to the builtin functions which use the\n> > RUN_SETUP macro, the `repo` config will be NULL.\n> >\n> > There are some builtin commands functions that which has\n> > the`git_config()` function comes before\n> > `show_usage_with_options_if_asked()` or it's variant and some,\n> > `git_config()` comes after.\n> >\n> > For those that have `git_config()` comes after\n> > `show_usage_with_options_if_asked()` , no need for the check, since\n> > the `show_usage_with_options_if_asked()`call will exit without\n> > reaching `git_config()`. For scenario where the `git_config()` comes\n> > earlier, we have to check the `repo` to see if it is NULL, if it is\n> > NULL, we are sure this happens when the \"-h\" is passed to the function\n> > and we do not need to setup and configuration since\n> > `show_usage_with_options_if_asked()` will exit.\n>\n> Exactly, this is what my suggestion is. If we introduced new calls to\n> `show_usage_with_options_if_asked()` before `git_config()` we wouldn't\n> have to check for a `NULL` repository in the first place because we know\n> that we'd have already exited if there was a \"-h\" parameter.\nYeah, that is true. Maybe having this as a preparatory patch could be better.\n\nThere was a previous similar patch also which has been accepted. Maybe\nthis can be done after this patch series got accepted, so, I could do\nit together\nwith the already accepted patch.\n\nWhat do you think ?\n\nThank you.\n>\n> Patrick\n"},{"id":"512526","messageId":"Z7NaDvnSvwI_2ZyO@pks.im","threadId":"62956","inReplyTo":"CAPSxiM-Bm9FtvVDJ_MggPFy_hV=h-ossk4p1z=ADGbttG=w-RA@mail.gmail.com","subject":"Re: [PATCH 1/7] builtin/verify-tag: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-02-17T15:47:26Z","receivedAt":"2025-02-17T15:47:31Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Feb 17, 2025 at 04:12:06PM +0530, Usman Akinyemi wrote:\n> On Mon, Feb 17, 2025 at 3:52 PM Patrick Steinhardt <ps@pks.im> wrote:\n> >\n> > On Mon, Feb 17, 2025 at 03:35:05PM +0530, Usman Akinyemi wrote:\n> > > On Mon, Feb 17, 2025 at 12:25 PM Patrick Steinhardt <ps@pks.im> wrote:\n> > > >\n> > > > On Sat, Feb 15, 2025 at 04:27:17AM +0530, Usman Akinyemi wrote:\n> > > > > @@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,\n> > > > >               OPT_END()\n> > > > >       };\n> > > > >\n> > > > > -     git_config(git_default_config, NULL);\n> > > > > +     if (repo)\n> > > > > +             repo_config(repo, git_default_config, NULL);\n> > > > >\n> > > >\n> > > > I recently noticed that we have `usage_with_options_if_asked()`. Should\n> > > > we use that function rather than making the call to `git_config()`\n> > > > conditional? Otherwise it's not obvious why we have the conditional in\n> > > > the first place.\n> > > Hi Patrick,\n> > >\n> > > I think the function is `show_usage_with_options_if_asked()`. The function\n> > > is quite different from `git_config()` or the `repo_config()`.  The\n> > > config function consults the configuration file for setting up config\n> > > values and it uses the `repo` variable during this. While\n> > > `show_usage_with_options_if_asked()` is used when the \"-h\" option is\n> > > passed to the builtin functions to display the help string.\n> > >\n> > > In a case when \"-h\" is passed to the builtin functions which use the\n> > > RUN_SETUP macro, the `repo` config will be NULL.\n> > >\n> > > There are some builtin commands functions that which has\n> > > the`git_config()` function comes before\n> > > `show_usage_with_options_if_asked()` or it's variant and some,\n> > > `git_config()` comes after.\n> > >\n> > > For those that have `git_config()` comes after\n> > > `show_usage_with_options_if_asked()` , no need for the check, since\n> > > the `show_usage_with_options_if_asked()`call will exit without\n> > > reaching `git_config()`. For scenario where the `git_config()` comes\n> > > earlier, we have to check the `repo` to see if it is NULL, if it is\n> > > NULL, we are sure this happens when the \"-h\" is passed to the function\n> > > and we do not need to setup and configuration since\n> > > `show_usage_with_options_if_asked()` will exit.\n> >\n> > Exactly, this is what my suggestion is. If we introduced new calls to\n> > `show_usage_with_options_if_asked()` before `git_config()` we wouldn't\n> > have to check for a `NULL` repository in the first place because we know\n> > that we'd have already exited if there was a \"-h\" parameter.\n> Yeah, that is true. Maybe having this as a preparatory patch could be better.\n> \n> There was a previous similar patch also which has been accepted. Maybe\n> this can be done after this patch series got accepted, so, I could do\n> it together\n> with the already accepted patch.\n\nYup, that'd be great indeed. Thanks!\n\nPatrick\n"},{"id":"512730","messageId":"20250219203349.787173-1-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250214230210.1460111-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 00/12][Outreachy] stop using the_repository global variable.","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:48Z","receivedAt":"2025-02-19T20:33:57Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove `the_repository` global variable in favor of the repository\nargument that gets passed in builtin commands. \n\nThese sets of commands are commands that use only RUN_SETUP macro in \"git.c\".\nBasically, When `-h` is passed to any of this command outside a Git repository,\nthe `run_builtin()` will call the `cmd_x()` function (where `x` is any\nof the command from the sets of builtin commands that `the_repository` is removed\nfrom) with `repo` set to NULL and then early in the function, `parse_options()`\nor show_usage_with_options_if_asked() call will give the options help and exit,\nwithout having to consult much of the configuration file.\n\nAs there exist some builtin commands where the `repository` variable is accessed\nbefore options is given exit and fail, we will move the functions which\naccessed the `repository` below the `usage_with_options()` and it\nvariants which will exit before getting to the function accessing the `repository`\nvariable. We will do this in a preparatory patches.\n\nSome, functions also uses `the_repository` global internally, so, let's\nlet's refactor them and pass `struct repo` as one of the argument. \n\nI picked some of this files based on the above explanation, how easy they are to\nresolve and how easy easy to review. \n\n[1]: https://public-inbox.org/git/20250210181103.3609495-1-usmanakinyemi202@gmail.com/\n\nChanges since v1\n================\n- Add some new preparatory patches to move the `git_config()` below the\n`usage_with_options()`.\n- Fix some errors in the commit messages.\n\nUsman Akinyemi (12):\n  builtin/verify-tag: refactor `cmd_verify_tag()`\n  builtin/verify-tag: stop using `the_repository`\n  builtin/verify-commit: refactor `cmd_verify_commit()`\n  builtin/verify-commit: stop using `the_repository`\n  builtin/send-pack: refactor `cmd_send_pack()`\n  builtin/send-pack: stop using `the_repository`\n  builtin/pack-refs: refactor `cmd_pack_refs()`\n  builtin/pack-refs: stop using `the_repository`\n  builtin/ls-files: stop using `the_repository`\n  builtin/for-each-ref: refactor `cmd_for_each_ref()`\n  builtin/for-each-ref: stop using `the_repository`\n  builtin/checkout-index: stop using `the_repository`\n\n builtin/checkout-index.c | 43 ++++++++++++++++++++--------------------\n builtin/for-each-ref.c   |  6 ++----\n builtin/ls-files.c       | 32 +++++++++++++++---------------\n builtin/pack-refs.c      |  9 ++++-----\n builtin/send-pack.c      |  8 ++++----\n builtin/verify-commit.c  | 15 +++++++-------\n builtin/verify-tag.c     |  9 ++++-----\n 7 files changed, 58 insertions(+), 64 deletions(-)\n\nRange-diff versus v1:\n\n -:  ---------- >  1:  ceb03199e1 builtin/verify-tag: refactor `cmd_verify_tag()`\n 1:  3e8d11ccfe !  2:  ecfb834600 builtin/verify-tag: stop using `the_repository`\n    @@ Commit message\n         `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\n         to NULL and then early in the function, `parse_options()` call will give\n         the options help and exit, without having to consult much of the\n    -    configuration file. So it is safe to omit reading the config when `repo`\n    -    argument the caller gave us is NULL.\n    +    configuration file.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/verify-tag.c: static const char * const verify_tag_usage[] = {\n      \tint i = 1, verbose = 0, had_error = 0;\n      \tunsigned flags = 0;\n     @@ builtin/verify-tag.c: int cmd_verify_tag(int argc,\n    - \t\tOPT_END()\n    - \t};\n    + \t\tflags |= GPG_VERIFY_OMIT_STATUS;\n    + \t}\n      \n     -\tgit_config(git_default_config, NULL);\n    -+\tif (repo)\n    -+\t\trepo_config(repo, git_default_config, NULL);\n    ++\trepo_config(repo, git_default_config, NULL);\n      \n    - \targc = parse_options(argc, argv, prefix, verify_tag_options,\n    - \t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n    -@@ builtin/verify-tag.c: int cmd_verify_tag(int argc,\n    + \twhile (i < argc) {\n      \t\tstruct object_id oid;\n      \t\tconst char *name = argv[i++];\n      \n -:  ---------- >  3:  2f770824b1 builtin/verify-commit: refactor `cmd_verify_commit()`\n 2:  88af56e220 !  4:  546588a6ae builtin/verify-commit.c: stop using `the_repository`\n    @@ Metadata\n     Author: Usman Akinyemi <usmanakinyemi202@gmail.com>\n     \n      ## Commit message ##\n    -    builtin/verify-commit.c: stop using `the_repository`\n    +    builtin/verify-commit: stop using `the_repository`\n     \n         Remove the_repository global variable in favor of the repository\n    -    argument that gets passed in \"builtin/verify-tag.c\".\n    +    argument that gets passed in \"builtin/verify-commit.c\".\n     \n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_verify_commit()` function with `repo`\n         set to NULL and then early in the function, `parse_options()` call will\n         give the options help and exit, without having to consult much of the\n    -    configuration file. So it is safe to omit reading the config when `repo`\n    -    argument the caller gave us is NULL.\n    +    configuration file.\n     \n    -    Let's pass `repository` argument to `verify_commit()` function to remove\n    -    it's dependency on the global `the_repository` variable.\n    +    Pass the repository available in the calling context to `verify_commit()`\n    +    to remove it's dependency on the global `the_repository` variable.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/verify-commit.c: static int verify_commit(const char *name, unsigned fla\n      \tint i = 1, verbose = 0, had_error = 0;\n      \tunsigned flags = 0;\n     @@ builtin/verify-commit.c: int cmd_verify_commit(int argc,\n    - \t\tOPT_END()\n    - \t};\n    + \tif (verbose)\n    + \t\tflags |= GPG_VERIFY_VERBOSE;\n      \n     -\tgit_config(git_default_config, NULL);\n    -+\tif (repo)\n    -+\t\trepo_config(repo, git_default_config, NULL);\n    ++\trepo_config(repo, git_default_config, NULL);\n      \n    - \targc = parse_options(argc, argv, prefix, verify_commit_options,\n    - \t\t\t     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);\n    -@@ builtin/verify-commit.c: int cmd_verify_commit(int argc,\n    + \t/* sometimes the program was terminated because this signal\n      \t * was received in the process of writing the gpg input: */\n      \tsignal(SIGPIPE, SIG_IGN);\n      \twhile (i < argc)\n -:  ---------- >  5:  99f10469bd builtin/send-pack: refactor `cmd_send_pack()`\n 3:  39409ea113 !  6:  cb3886bc46 builtin/send-pack.c: stop using `the_repository`\n    @@ Metadata\n     Author: Usman Akinyemi <usmanakinyemi202@gmail.com>\n     \n      ## Commit message ##\n    -    builtin/send-pack.c: stop using `the_repository`\n    +    builtin/send-pack: stop using `the_repository`\n     \n         Remove the_repository global variable in favor of the repository\n         argument that gets passed in \"builtin/send-pack.c\".\n    @@ Commit message\n         `run_builtin()` will call the `cmd_send_pack()` function with `repo` set\n         to NULL and then early in the function, `parse_options()` call will give\n         the options help and exit, without having to consult much of the\n    -    configuration file. So it is safe to omit reading the config when `repo`\n    -    argument the caller gave us is NULL.\n    +    configuration file.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/send-pack.c: static int send_pack_config(const char *k, const char *v,\n      \tstruct refspec rs = REFSPEC_INIT_PUSH;\n      \tconst char *remote_name = NULL;\n     @@ builtin/send-pack.c: int cmd_send_pack(int argc,\n    - \t\tOPT_END()\n    - \t};\n    + \tif (!dest)\n    + \t\tusage_with_options(send_pack_usage, options);\n      \n     -\tgit_config(send_pack_config, NULL);\n    -+\tif (repo)\n    -+\t\trepo_config(repo, send_pack_config, NULL);\n    - \targc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);\n    - \tif (argc > 0) {\n    - \t\tdest = argv[0];\n    ++\trepo_config(repo, send_pack_config, NULL);\n    + \n    + \targs.verbose = verbose;\n    + \targs.dry_run = dry_run;\n     @@ builtin/send-pack.c: int cmd_send_pack(int argc,\n      \tset_ref_status_for_push(remote_refs, args.send_mirror,\n      \t\targs.force_update);\n -:  ---------- >  7:  d104522e30 builtin/pack-refs: refactor `cmd_pack_refs()`\n 4:  6fd5f4727c !  8:  7f02e48663 builtin/pack-refs: stop using `the_repository`\n    @@ Commit message\n         `run_builtin()` will call the `cmd_pack_refs()` function with `repo` set\n         to NULL and then early in the function, `parse_options()` call will give\n         the options help and exit, without having to consult much of the\n    -    configuration file. So it is safe to omit reading the config when `repo`\n    -    argument the caller gave us is NULL.\n    +    configuration file.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/pack-refs.c: static char const * const pack_refs_usage[] = {\n      \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n      \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n     @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,\n    - \t\t\tN_(\"references to exclude\")),\n    - \t\tOPT_END(),\n    - \t};\n    --\tgit_config(git_default_config, NULL);\n    -+\tif (repo)\n    -+\t\trepo_config(repo, git_default_config, NULL);\n      \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n      \t\tusage_with_options(pack_refs_usage, opts);\n      \n    +-\tgit_config(git_default_config, NULL);\n    ++\trepo_config(repo, git_default_config, NULL);\n    + \tfor_each_string_list_item(item, &option_excluded_refs)\n    + \t\tadd_ref_exclusion(pack_refs_opts.exclusions, item->string);\n    + \n     @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,\n      \tif (!pack_refs_opts.includes->nr)\n      \t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n 5:  c58f27988b !  9:  b706fab321 builtin/ls-files: stop using `the_repository`\n    @@ Commit message\n         call will give the options help and exit, without having to consult much\n         of the configuration file.\n     \n    -    Let's pass `repository` argument to `expand_objectsize()`,\n    -    `show_ru_info()` functions to remove their dependency on the global\n    -    `the_repository` variable.\n    +    Pass the repository available in the calling context to both\n    +    `expand_objectsize()` and `show_ru_info()` to remove their\n    +    dependency on the global `the_repository` variable.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n -:  ---------- > 10:  d2fc527d51 builtin/for-each-ref: refactor `cmd_for_each_ref()`\n 6:  4bbca37330 ! 11:  c3a3a6cff7 builtin/for-each-ref: stop using `the_repository`\n    @@ Commit message\n         `run_builtin()` will call the `cmd_for_each_ref()` function with `repo`\n         set to NULL and then early in the function, `parse_options()` call will\n         give the options help and exit, without having to consult much of the\n    -    configuration file. So it is safe to omit reading the config when `repo`\n    -    argument the caller gave us is NULL.\n    +    configuration file.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/for-each-ref.c: static char const * const for_each_ref_usage[] = {\n      \tstruct ref_sorting *sorting;\n      \tstruct string_list sorting_options = STRING_LIST_INIT_DUP;\n     @@ builtin/for-each-ref.c: int cmd_for_each_ref(int argc,\n    - \n    - \tformat.format = \"%(objectname) %(objecttype)\\t%(refname)\";\n    + \tif (verify_ref_format(&format))\n    + \t\tusage_with_options(for_each_ref_usage, opts);\n      \n     -\tgit_config(git_default_config, NULL);\n    -+\tif (repo)\n    -+\t\trepo_config(repo, git_default_config, NULL);\n    - \n    - \t/* Set default (refname) sorting */\n    - \tstring_list_append(&sorting_options, \"refname\");\n    ++\trepo_config(repo, git_default_config, NULL);\n    + \tsorting = ref_sorting_options(&sorting_options);\n    + \tref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);\n    + \tfilter.ignore_case = icase;\n 7:  369008d554 ! 12:  d3a18f857e builtin/checkout-index.c: stop using `the_repository`\n    @@ Metadata\n     Author: Usman Akinyemi <usmanakinyemi202@gmail.com>\n     \n      ## Commit message ##\n    -    builtin/checkout-index.c: stop using `the_repository`\n    +    builtin/checkout-index: stop using `the_repository`\n     \n         Remove the_repository global variable in favor of the repository\n         argument that gets passed in \"builtin/checkout-index.c\".\n    @@ Commit message\n         call will give the options help and exit, without having to consult much\n         of the configuration file.\n     \n    -    Let's pass `repository` argument to `checkout_all()` and `checkout_file()`\n    -    functions to remove their dependency on the global `the_repository` variable.\n    +    Pass the repository available in the calling context to both `checkout_all()`\n    +    and `checkout_file()` to remove their dependency on the global\n    +    `the_repository` variable.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n\n-- \n2.48.1\n\n"},{"id":"512731","messageId":"20250219203349.787173-2-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 01/12] builtin/verify-tag: refactor `cmd_verify_tag()`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:49Z","receivedAt":"2025-02-19T20:33:59Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`\ncheck.\n\nWhen \"-h\" is passed to builtins using the RUN_SETUP macro, `repo` passed\nby `run_builtin()` will be NULL. If we use the `repo` instead of the\nglobal `the_repository` variable. We will have to switch from `git_config()`\nto `repo_config()` which takes in `repo`. We must check for NULL `repo`\nif `repo_config()` comes before `usage_with_options()`. Moving `git_config()`\nafter `usage_with_options()` eliminates this need, as `usage_with_options()`\nexit before calling `repo_config()`.\n\nThis will be useful in the following patch which remove `the_repository`\nglobal variable in favor of the `repo` passed by `run_builtin()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-tag.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/verify-tag.c b/builtin/verify-tag.c\nindex f6b97048a5..f0e7c2a2b5 100644\n--- a/builtin/verify-tag.c\n+++ b/builtin/verify-tag.c\n@@ -35,8 +35,6 @@ int cmd_verify_tag(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n-\n \targc = parse_options(argc, argv, prefix, verify_tag_options,\n \t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n \tif (argc <= i)\n@@ -52,6 +50,8 @@ int cmd_verify_tag(int argc,\n \t\tflags |= GPG_VERIFY_OMIT_STATUS;\n \t}\n \n+\tgit_config(git_default_config, NULL);\n+\n \twhile (i < argc) {\n \t\tstruct object_id oid;\n \t\tconst char *name = argv[i++];\n-- \n2.48.1\n\n"},{"id":"512732","messageId":"20250219203349.787173-3-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 02/12] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:50Z","receivedAt":"2025-02-19T20:34:02Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-tag.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit, without having to consult much of the\nconfiguration file.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-tag.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/verify-tag.c b/builtin/verify-tag.c\nindex f0e7c2a2b5..0acdb364dd 100644\n--- a/builtin/verify-tag.c\n+++ b/builtin/verify-tag.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag.sh\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {\n int cmd_verify_tag(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -50,13 +49,13 @@ int cmd_verify_tag(int argc,\n \t\tflags |= GPG_VERIFY_OMIT_STATUS;\n \t}\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \twhile (i < argc) {\n \t\tstruct object_id oid;\n \t\tconst char *name = argv[i++];\n \n-\t\tif (repo_get_oid(the_repository, name, &oid)) {\n+\t\tif (repo_get_oid(repo, name, &oid)) {\n \t\t\thad_error = !!error(\"tag '%s' not found.\", name);\n \t\t\tcontinue;\n \t\t}\n-- \n2.48.1\n\n"},{"id":"512733","messageId":"20250219203349.787173-4-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 03/12] builtin/verify-commit: refactor `cmd_verify_commit()`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:51Z","receivedAt":"2025-02-19T20:34:06Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`\ncheck.\n\nWhen \"-h\" is passed to builtins using the RUN_SETUP macro, `repo` passed\nby `run_builtin()` will be NULL. If we use the `repo` instead of the\nglobal `the_repository` variable. We will have to switch from `git_config()`\nto `repo_config()` which takes in `repo`. We must check for NULL `repo`\nif `repo_config()` comes before `usage_with_options()`. Moving `git_config()`\nafter `usage_with_options()` eliminates this need, as `usage_with_options()`\nexit before calling `repo_config()`.\n\nThis will be useful in the following patch which remove `the_repository`\nglobal variable in favor of the `repo` passed by `run_builtin()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-commit.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex 779b7988ca..ae0c625777 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -64,8 +64,6 @@ int cmd_verify_commit(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n-\n \targc = parse_options(argc, argv, prefix, verify_commit_options,\n \t\t\t     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);\n \tif (argc <= i)\n@@ -74,6 +72,8 @@ int cmd_verify_commit(int argc,\n \tif (verbose)\n \t\tflags |= GPG_VERIFY_VERBOSE;\n \n+\tgit_config(git_default_config, NULL);\n+\n \t/* sometimes the program was terminated because this signal\n \t * was received in the process of writing the gpg input: */\n \tsignal(SIGPIPE, SIG_IGN);\n-- \n2.48.1\n\n"},{"id":"512734","messageId":"20250219203349.787173-5-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 04/12] builtin/verify-commit: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:52Z","receivedAt":"2025-02-19T20:34:09Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-commit.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_commit()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit, without having to consult much of the\nconfiguration file.\n\nPass the repository available in the calling context to `verify_commit()`\nto remove it's dependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-commit.c | 13 ++++++-------\n 1 file changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex ae0c625777..037032d15c 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)\n \treturn ret;\n }\n \n-static int verify_commit(const char *name, unsigned flags)\n+static int verify_commit(struct repository *repo, const char *name, unsigned flags)\n {\n \tstruct object_id oid;\n \tstruct object *obj;\n \n-\tif (repo_get_oid(the_repository, name, &oid))\n+\tif (repo_get_oid(repo, name, &oid))\n \t\treturn error(\"commit '%s' not found.\", name);\n \n-\tobj = parse_object(the_repository, &oid);\n+\tobj = parse_object(repo, &oid);\n \tif (!obj)\n \t\treturn error(\"%s: unable to read file.\", name);\n \tif (obj->type != OBJ_COMMIT)\n@@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags)\n int cmd_verify_commit(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -72,13 +71,13 @@ int cmd_verify_commit(int argc,\n \tif (verbose)\n \t\tflags |= GPG_VERIFY_VERBOSE;\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \t/* sometimes the program was terminated because this signal\n \t * was received in the process of writing the gpg input: */\n \tsignal(SIGPIPE, SIG_IGN);\n \twhile (i < argc)\n-\t\tif (verify_commit(argv[i++], flags))\n+\t\tif (verify_commit(repo, argv[i++], flags))\n \t\t\thad_error = 1;\n \treturn had_error;\n }\n-- \n2.48.1\n\n"},{"id":"512735","messageId":"20250219203349.787173-6-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 05/12] builtin/send-pack: refactor `cmd_send_pack()`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:53Z","receivedAt":"2025-02-19T20:34:12Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`\ncheck.\n\nWhen \"-h\" is passed to builtins using the RUN_SETUP macro, `repo` passed\nby `run_builtin()` will be NULL. If we use the `repo` instead of the\nglobal `the_repository` variable. We will have to switch from `git_config()`\nto `repo_config()` which takes in `repo`. We must check for NULL `repo`\nif `repo_config()` comes before `usage_with_options()`. Moving `git_config()`\nafter `usage_with_options()` eliminates this need, as `usage_with_options()`\nexit before calling `repo_config()`.\n\nThis will be useful in the following patch which remove `the_repository`\nglobal variable in favor of the `repo` passed by `run_builtin()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/send-pack.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/send-pack.c b/builtin/send-pack.c\nindex 8d461008e2..0848d23171 100644\n--- a/builtin/send-pack.c\n+++ b/builtin/send-pack.c\n@@ -212,7 +212,6 @@ int cmd_send_pack(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(send_pack_config, NULL);\n \targc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);\n \tif (argc > 0) {\n \t\tdest = argv[0];\n@@ -222,6 +221,8 @@ int cmd_send_pack(int argc,\n \tif (!dest)\n \t\tusage_with_options(send_pack_usage, options);\n \n+\tgit_config(send_pack_config, NULL);\n+\n \targs.verbose = verbose;\n \targs.dry_run = dry_run;\n \targs.send_mirror = send_mirror;\n-- \n2.48.1\n\n"},{"id":"512736","messageId":"20250219203349.787173-7-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 06/12] builtin/send-pack: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:54Z","receivedAt":"2025-02-19T20:34:15Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/send-pack.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_send_pack()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit, without having to consult much of the\nconfiguration file.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/send-pack.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/send-pack.c b/builtin/send-pack.c\nindex 0848d23171..0ebfc98317 100644\n--- a/builtin/send-pack.c\n+++ b/builtin/send-pack.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"hex.h\"\n@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,\n int cmd_send_pack(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 \tstruct refspec rs = REFSPEC_INIT_PUSH;\n \tconst char *remote_name = NULL;\n@@ -221,7 +220,7 @@ int cmd_send_pack(int argc,\n \tif (!dest)\n \t\tusage_with_options(send_pack_usage, options);\n \n-\tgit_config(send_pack_config, NULL);\n+\trepo_config(repo, send_pack_config, NULL);\n \n \targs.verbose = verbose;\n \targs.dry_run = dry_run;\n@@ -318,7 +317,7 @@ int cmd_send_pack(int argc,\n \tset_ref_status_for_push(remote_refs, args.send_mirror,\n \t\targs.force_update);\n \n-\tret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);\n+\tret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);\n \n \tif (helper_status)\n \t\tprint_helper_status(remote_refs);\n-- \n2.48.1\n\n"},{"id":"512737","messageId":"20250219203349.787173-8-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 07/12] builtin/pack-refs: refactor `cmd_pack_refs()`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:55Z","receivedAt":"2025-02-19T20:34:19Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`\ncheck.\n\nWhen \"-h\" is passed to builtins using the RUN_SETUP macro, `repo` passed\nby `run_builtin()` will be NULL. If we use the `repo` instead of the\nglobal `the_repository` variable. We will have to switch from `git_config()`\nto `repo_config()` which takes in `repo`. We must check for NULL `repo`\nif `repo_config()` comes before `usage_with_options()`. Moving `git_config()`\nafter `usage_with_options()` eliminates this need, as `usage_with_options()`\nexit before calling `repo_config()`.\n\nThis will be useful in the following patch which remove `the_repository`\nglobal variable in favor of the `repo` passed by `run_builtin()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/pack-refs.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/pack-refs.c b/builtin/pack-refs.c\nindex 4fdd68880e..bd09366738 100644\n--- a/builtin/pack-refs.c\n+++ b/builtin/pack-refs.c\n@@ -39,10 +39,11 @@ int cmd_pack_refs(int argc,\n \t\t\tN_(\"references to exclude\")),\n \t\tOPT_END(),\n \t};\n-\tgit_config(git_default_config, NULL);\n+\n \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n \t\tusage_with_options(pack_refs_usage, opts);\n \n+\tgit_config(git_default_config, NULL);\n \tfor_each_string_list_item(item, &option_excluded_refs)\n \t\tadd_ref_exclusion(pack_refs_opts.exclusions, item->string);\n \n-- \n2.48.1\n\n"},{"id":"512738","messageId":"20250219203349.787173-9-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 08/12] builtin/pack-refs: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:56Z","receivedAt":"2025-02-19T20:34:22Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/pack-refs.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_pack_refs()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit, without having to consult much of the\nconfiguration file.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/pack-refs.c | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/pack-refs.c b/builtin/pack-refs.c\nindex bd09366738..200a5516b1 100644\n--- a/builtin/pack-refs.c\n+++ b/builtin/pack-refs.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {\n int cmd_pack_refs(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 \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n@@ -43,7 +41,7 @@ int cmd_pack_refs(int argc,\n \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n \t\tusage_with_options(pack_refs_usage, opts);\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tfor_each_string_list_item(item, &option_excluded_refs)\n \t\tadd_ref_exclusion(pack_refs_opts.exclusions, item->string);\n \n@@ -53,7 +51,7 @@ int cmd_pack_refs(int argc,\n \tif (!pack_refs_opts.includes->nr)\n \t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n \n-\tret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);\n+\tret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);\n \n \tclear_ref_exclusions(&excludes);\n \tstring_list_clear(&included_refs, 0);\n-- \n2.48.1\n\n"},{"id":"512739","messageId":"20250219203349.787173-10-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 09/12] builtin/ls-files: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:57Z","receivedAt":"2025-02-19T20:34:27Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/ls-files.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_ls_files()` function with `repo` set\nto NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit, without having to consult much\nof the configuration file.\n\nPass the repository available in the calling context to both\n`expand_objectsize()` and `show_ru_info()` to remove their\ndependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/ls-files.c | 32 ++++++++++++++++----------------\n 1 file changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a4431429b7..70a377e9c0 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -6,7 +6,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -245,12 +244,13 @@ static void show_submodule(struct repository *superproject,\n \trepo_clear(&subrepo);\n }\n \n-static void expand_objectsize(struct strbuf *line, const struct object_id *oid,\n+static void expand_objectsize(struct repository *repo, struct strbuf *line,\n+\t\t\t      const struct object_id *oid,\n \t\t\t      const enum object_type type, unsigned int padded)\n {\n \tif (type == OBJ_BLOB) {\n \t\tunsigned long size;\n-\t\tif (oid_object_info(the_repository, oid, &size) < 0)\n+\t\tif (oid_object_info(repo, oid, &size) < 0)\n \t\t\tdie(_(\"could not get object info about '%s'\"),\n \t\t\t    oid_to_hex(oid));\n \t\tif (padded)\n@@ -283,10 +283,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,\n \t\telse if (skip_prefix(format, \"(objecttype)\", &format))\n \t\t\tstrbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));\n \t\telse if (skip_prefix(format, \"(objectsize:padded)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 1);\n \t\telse if (skip_prefix(format, \"(objectsize)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 0);\n \t\telse if (skip_prefix(format, \"(stage)\", &format))\n \t\t\tstrbuf_addf(&sb, \"%d\", ce_stage(ce));\n@@ -348,7 +348,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,\n \t}\n }\n \n-static void show_ru_info(struct index_state *istate)\n+static void show_ru_info(struct repository *repo, struct index_state *istate)\n {\n \tstruct string_list_item *item;\n \n@@ -370,7 +370,7 @@ static void show_ru_info(struct index_state *istate)\n \t\t\tif (!ui->mode[i])\n \t\t\t\tcontinue;\n \t\t\tprintf(\"%s%06o %s %d\\t\", tag_resolve_undo, ui->mode[i],\n-\t\t\t       repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev),\n+\t\t\t       repo_find_unique_abbrev(repo, &ui->oid[i], abbrev),\n \t\t\t       i + 1);\n \t\t\twrite_name(path);\n \t\t}\n@@ -567,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt,\n int cmd_ls_files(int argc,\n \t\t const char **argv,\n \t\t const char *cmd_prefix,\n-\t\t struct repository *repo UNUSED)\n+\t\t struct repository *repo)\n {\n \tint require_work_tree = 0, show_tag = 0, i;\n \tchar *max_prefix;\n@@ -647,15 +647,15 @@ int cmd_ls_files(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t ls_files_usage, builtin_ls_files_options);\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n \tprefix = cmd_prefix;\n \tif (prefix)\n \t\tprefix_len = strlen(prefix);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n-\tif (repo_read_index(the_repository) < 0)\n+\tif (repo_read_index(repo) < 0)\n \t\tdie(\"index file corrupt\");\n \n \targc = parse_options(argc, argv, prefix, builtin_ls_files_options,\n@@ -724,7 +724,7 @@ int cmd_ls_files(int argc,\n \t\tmax_prefix = common_prefix(&pathspec);\n \tmax_prefix_len = get_common_prefix_len(max_prefix);\n \n-\tprune_index(the_repository->index, max_prefix, max_prefix_len);\n+\tprune_index(repo->index, max_prefix, max_prefix_len);\n \n \t/* Treat unmatching pathspec elements as errors */\n \tif (pathspec.nr && error_unmatch)\n@@ -748,13 +748,13 @@ int cmd_ls_files(int argc,\n \t\t */\n \t\tif (show_stage || show_unmerged)\n \t\t\tdie(_(\"options '%s' and '%s' cannot be used together\"), \"ls-files --with-tree\", \"-s/-u\");\n-\t\toverlay_tree_on_index(the_repository->index, with_tree, max_prefix);\n+\t\toverlay_tree_on_index(repo->index, with_tree, max_prefix);\n \t}\n \n-\tshow_files(the_repository, &dir);\n+\tshow_files(repo, &dir);\n \n \tif (show_resolve_undo)\n-\t\tshow_ru_info(the_repository->index);\n+\t\tshow_ru_info(repo, repo->index);\n \n \tif (ps_matched && report_path_error(ps_matched, &pathspec)) {\n \t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\n-- \n2.48.1\n\n"},{"id":"512740","messageId":"20250219203349.787173-11-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 10/12] builtin/for-each-ref: refactor `cmd_for_each_ref()`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:58Z","receivedAt":"2025-02-19T20:34:30Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`\ncheck.\n\nWhen \"-h\" is passed to builtins using the RUN_SETUP macro, `repo` passed\nby `run_builtin()` will be NULL. If we use the `repo` instead of the\nglobal `the_repository` variable. We will have to switch from `git_config()`\nto `repo_config()` which takes in `repo`. We must check for NULL `repo`\nif `repo_config()` comes before `usage_with_options()`. Moving `git_config()`\nafter `usage_with_options()` eliminates this need, as `usage_with_options()`\nexit before calling `repo_config()`.\n\nThis will be useful in the following patch which remove `the_repository`\nglobal variable in favor of the `repo` passed by `run_builtin()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/for-each-ref.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 8085ebd8fe..649689c92c 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -63,8 +63,6 @@ int cmd_for_each_ref(int argc,\n \n \tformat.format = \"%(objectname) %(objecttype)\\t%(refname)\";\n \n-\tgit_config(git_default_config, NULL);\n-\n \t/* Set default (refname) sorting */\n \tstring_list_append(&sorting_options, \"refname\");\n \n@@ -80,6 +78,7 @@ int cmd_for_each_ref(int argc,\n \tif (verify_ref_format(&format))\n \t\tusage_with_options(for_each_ref_usage, opts);\n \n+\tgit_config(git_default_config, NULL);\n \tsorting = ref_sorting_options(&sorting_options);\n \tref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);\n \tfilter.ignore_case = icase;\n-- \n2.48.1\n\n"},{"id":"512741","messageId":"20250219203349.787173-12-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 11/12] builtin/for-each-ref: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:32:59Z","receivedAt":"2025-02-19T20:34:33Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/for-each-ref.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_for_each_ref()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit, without having to consult much of the\nconfiguration file.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/for-each-ref.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 649689c92c..0f73f47fab 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"commit.h\"\n #include \"config.h\"\n@@ -20,7 +19,7 @@ static char const * const for_each_ref_usage[] = {\n int cmd_for_each_ref(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 \tstruct ref_sorting *sorting;\n \tstruct string_list sorting_options = STRING_LIST_INIT_DUP;\n@@ -78,7 +77,7 @@ int cmd_for_each_ref(int argc,\n \tif (verify_ref_format(&format))\n \t\tusage_with_options(for_each_ref_usage, opts);\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tsorting = ref_sorting_options(&sorting_options);\n \tref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);\n \tfilter.ignore_case = icase;\n-- \n2.48.1\n\n"},{"id":"512742","messageId":"20250219203349.787173-13-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[PATCH v2 12/12] builtin/checkout-index: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-19T20:33:00Z","receivedAt":"2025-02-19T20:34:36Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/checkout-index.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_checkout_index()` function with `repo`\nset to NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit, without having to consult much\nof the configuration file.\n\nPass the repository available in the calling context to both `checkout_all()`\nand `checkout_file()` to remove their dependency on the global\n`the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/checkout-index.c | 43 ++++++++++++++++++++--------------------\n 1 file changed, 21 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex e30086c7d4..46035444eb 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -5,7 +5,6 @@\n  *\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -68,10 +67,10 @@ static void write_tempfile_record(const char *name, const char *prefix)\n \t}\n }\n \n-static int checkout_file(const char *name, const char *prefix)\n+static int checkout_file(struct repository *repo, const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = index_name_pos(the_repository->index, name, namelen);\n+\tint pos = index_name_pos(repo->index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -81,8 +80,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos <the_repository->index->cache_nr) {\n-\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n+\twhile (pos < repo->index->cache_nr) {\n+\t\tstruct cache_entry *ce =repo->index->cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -137,13 +136,13 @@ static int checkout_file(const char *name, const char *prefix)\n \treturn -1;\n }\n \n-static int checkout_all(const char *prefix, int prefix_length)\n+static int checkout_all(struct repository *repo, const char *prefix, int prefix_length)\n {\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n-\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n+\tfor (i = 0; i < repo->index->cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = repo->index->cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -156,8 +155,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t * first entry inside the expanded sparse directory).\n \t\t\t */\n \t\t\tif (ignore_skip_worktree) {\n-\t\t\t\tensure_full_index(the_repository->index);\n-\t\t\t\tce = the_repository->index->cache[i];\n+\t\t\t\tensure_full_index(repo->index);\n+\t\t\t\tce = repo->index->cache[i];\n \t\t\t}\n \t\t}\n \n@@ -213,7 +212,7 @@ static int option_parse_stage(const struct option *opt,\n int cmd_checkout_index(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 \tint i;\n \tstruct lock_file lock_file = LOCK_INIT;\n@@ -253,19 +252,19 @@ int cmd_checkout_index(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t builtin_checkout_index_usage,\n \t\t\t\t\t builtin_checkout_index_options);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tprefix_length = prefix ? strlen(prefix) : 0;\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n-\tif (repo_read_index(the_repository) < 0) {\n+\tif (repo_read_index(repo) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n \targc = parse_options(argc, argv, prefix, builtin_checkout_index_options,\n \t\t\tbuiltin_checkout_index_usage, 0);\n-\tstate.istate = the_repository->index;\n+\tstate.istate = repo->index;\n \tstate.force = force;\n \tstate.quiet = quiet;\n \tstate.not_new = not_new;\n@@ -285,8 +284,8 @@ int cmd_checkout_index(int argc,\n \t */\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n-\t\tstate.istate = the_repository->index;\n-\t\trepo_hold_locked_index(the_repository, &lock_file,\n+\t\tstate.istate = repo->index;\n+\t\trepo_hold_locked_index(repo, &lock_file,\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n@@ -304,7 +303,7 @@ int cmd_checkout_index(int argc,\n \t\tif (read_from_stdin)\n \t\t\tdie(\"git checkout-index: don't mix '--stdin' and explicit filenames\");\n \t\tp = prefix_path(prefix, prefix_length, arg);\n-\t\terr |= checkout_file(p, prefix);\n+\t\terr |= checkout_file(repo, p, prefix);\n \t\tfree(p);\n \t}\n \n@@ -326,7 +325,7 @@ int cmd_checkout_index(int argc,\n \t\t\t\tstrbuf_swap(&buf, &unquoted);\n \t\t\t}\n \t\t\tp = prefix_path(prefix, prefix_length, buf.buf);\n-\t\t\terr |= checkout_file(p, prefix);\n+\t\t\terr |= checkout_file(repo, p, prefix);\n \t\t\tfree(p);\n \t\t}\n \t\tstrbuf_release(&unquoted);\n@@ -334,7 +333,7 @@ int cmd_checkout_index(int argc,\n \t}\n \n \tif (all)\n-\t\terr |= checkout_all(prefix, prefix_length);\n+\t\terr |= checkout_all(repo, prefix, prefix_length);\n \n \tif (pc_workers > 1)\n \t\terr |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n@@ -344,7 +343,7 @@ int cmd_checkout_index(int argc,\n \t\treturn 1;\n \n \tif (is_lock_file_locked(&lock_file) &&\n-\t    write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n+\t    write_locked_index(repo->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\n-- \n2.48.1\n\n"},{"id":"512776","messageId":"xmqqa5ageio7.fsf@gitster.g","threadId":"62956","inReplyTo":"20250219203349.787173-2-usmanakinyemi202@gmail.com","subject":"Re: [PATCH v2 01/12] builtin/verify-tag: refactor `cmd_verify_tag()`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-02-20T15:32:08Z","receivedAt":"2025-02-20T15:32:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`\n> check.\n\nTwo things and a half.\n\n - This move of a single call is not something I see usually called\n   \"refactor\".\n\n - The new call to git_config() should be chosen a bit more\n   carefully to be future-proof.  It is harder to see with the\n   reduced context, but verbose and format.format has already been\n   referenced before the new place where you read the configuration\n   file, which would mean that you are making it impossible for\n   future developers to add configuration variables to give default\n   values to these two settings.\n\nThe same comment applies to potential new configuration variables\nthat may control how parse_options() would work.  With this line of\nconversion, we are closing the door for such configuration variables\n(e.g., OPTION_FILENAME may want to understand \"~/path\" and if we had\nuser.homedirectory configuration variable, the value of the variable\nshould affect what file the string \"~/path\" given to the option\nrefers to).\n\n> When \"-h\" is passed to builtins using the RUN_SETUP macro, `repo`\n> passed by `run_builtin()` will be NULL. If we use the `repo`\n> instead of the global `the_repository` variable.  We will have to\n> switch from `git_config()` to `repo_config()` which takes in\n> `repo`.\n\nI do not quite agree with this line of reasoning behind \"will have\nto switch\".  You need to realize that this is cmd_verify_tag() that\nis designed to be ONLY called as the top-level command\nimplementation and not called from random places as a library\nfunction.  It is perfectly fine for it to work with the_repository\nwith git_config().\n\nThe helper functions that this functions call may be different\nmatter, though.\n"},{"id":"512777","messageId":"xmqq34g8ei5x.fsf@gitster.g","threadId":"62956","inReplyTo":"20250219203349.787173-3-usmanakinyemi202@gmail.com","subject":"Re: [PATCH v2 02/12] builtin/verify-tag: stop using `the_repository`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-02-20T15:43:06Z","receivedAt":"2025-02-20T15:43:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> @@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {\n>  int cmd_verify_tag(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>  \tint i = 1, verbose = 0, had_error = 0;\n>  \tunsigned flags = 0;\n> @@ -50,13 +49,13 @@ int cmd_verify_tag(int argc,\n>  \t\tflags |= GPG_VERIFY_OMIT_STATUS;\n>  \t}\n>  \n> -\tgit_config(git_default_config, NULL);\n> +\trepo_config(repo, git_default_config, NULL);\n\nI seriously think that it is a horrible idea (but the previous step\nof this series is hardly the first one that commits the same sin) to\nmove git_config() down only to deal with \"repo might be NULL if run\noutside a repository\".  We should stop making such changes, and we\nshould revert the changes we already made along that line, to solve\nit differently.\n\nWouldn't it work much better if we teach repo_config() to allow repo\nto be NULL to signal that we are outside any repository, and behave\nthe same way the current git_config() works when called outside a\nrepository?  Even though the function is called repo_config(), it is\n*NOT* limited to read from $GIT_DIR/config but does read from the\nusual \"repository configuration trumps per-user configuration which\ntrumps system-side configuration\" cascade, so it is natural to skip\nthe repository configuration when called outside any repository but\nread the other configuration sources, which should be what happens\nwhen git_config() is called from outside the repository, no?\n\n"},{"id":"513173","messageId":"CAPSxiM-bOcqEbVNAYxh0oPXKceN7YSrCU_37e7mXAbxwpq3QNQ@mail.gmail.com","threadId":"62956","inReplyTo":"xmqq34g8ei5x.fsf@gitster.g","subject":"Re: [PATCH v2 02/12] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-02-27T17:56:02Z","receivedAt":"2025-02-27T17:56:14Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Thu, Feb 20, 2025 at 9:13 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n>\nHi Junio.\n> > @@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {\n> >  int cmd_verify_tag(int argc,\n> >                  const char **argv,\n> >                  const char *prefix,\n> > -                struct repository *repo UNUSED)\n> > +                struct repository *repo)\n> >  {\n> >       int i = 1, verbose = 0, had_error = 0;\n> >       unsigned flags = 0;\n> > @@ -50,13 +49,13 @@ int cmd_verify_tag(int argc,\n> >               flags |= GPG_VERIFY_OMIT_STATUS;\n> >       }\n> >\n> > -     git_config(git_default_config, NULL);\n> > +     repo_config(repo, git_default_config, NULL);\n>\n> I seriously think that it is a horrible idea (but the previous step\n> of this series is hardly the first one that commits the same sin) to\n> move git_config() down only to deal with \"repo might be NULL if run\n> outside a repository\".  We should stop making such changes, and we\n> should revert the changes we already made along that line, to solve\n> it differently.\n>\nYeah, I agree with this after going through your comment on the other\npatch. We should look for a better solution.\n\n> Wouldn't it work much better if we teach repo_config() to allow repo\n> to be NULL to signal that we are outside any repository, and behave\n> the same way the current git_config() works when called outside a\n> repository?  Even though the function is called repo_config(), it is\n> *NOT* limited to read from $GIT_DIR/config but does read from the\n> usual \"repository configuration trumps per-user configuration which\n> trumps system-side configuration\" cascade, so it is natural to skip\n> the repository configuration when called outside any repository but\n> read the other configuration sources, which should be what happens\n> when git_config() is called from outside the repository, no?\nYeah, I was studying the config.c and config.h files to understand better\nhow all these functions work.\n\nThe git_config() when called outside the repository, uses the global\nthe_repository\nvariable basically called the repo_config(). It does not necessarily\nhandle any situation\nwhen the repo was NULL. It always uses the global the_repository variable.\nI do not think we want to handle the repo_config() the same as the point of\nall these are to reduce/remove the use of the_repository global variable.\n\nWhile going through the config.c I saw the read_very_early_config()\nwhich read the config\nfrom the system and global settings and does not require any repo\nvariable. I think, to teach\nthe repo_config() to allow NULL value, we could call the\nread_very_early_config() whenever\nthe repo is NULL as we know, this happens outside the repository. I\nsent a rfc patch for this\nand it can viewed here :-\nhttps://public-inbox.org/git/20250227175456.1129840-1-usmanakinyemi202@gmail.com/T/#u\n\nAnother approach which I was thinking about is having a local\nrepository variable inside\nthe repo_config() whenever the repo variable passed to it is NULL.\n\nWhat do you think ?\n\nThanks.\n>\n"},{"id":"513190","messageId":"xmqqsenz57xu.fsf@gitster.g","threadId":"62956","inReplyTo":"CAPSxiM-bOcqEbVNAYxh0oPXKceN7YSrCU_37e7mXAbxwpq3QNQ@mail.gmail.com","subject":"Re: [PATCH v2 02/12] builtin/verify-tag: stop using `the_repository`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-02-27T22:39:09Z","receivedAt":"2025-02-27T22:39:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> While going through the config.c I saw the\n> read_very_early_config() which read the config from the system and\n> global settings and does not require any repo variable. I think,\n> to teach the repo_config() to allow NULL value, we could call the\n> read_very_early_config() whenever the repo is NULL as we know,\n> this happens outside the repository.\n\nYeah, when I wrote the message you were responding to, I noticed\nthat do_git_config_sequence() is prepared to take NULL as repo (even\nthough it is a bit clunky interface; you need to futz with members\nof the opts structure like opts->ignore_repo to have the code ignore\nrepo that is NULL).  So a caller that calls config_with_options() with\nno config_source and no repo should be a good candidate to reuse.\n\nAs we positively know that we are not in a repository in our case,\nusing read_very_early_config() when repo is NULL sounds like a\nsensible thing to do, I would think.\n\nThanks.\n\n\n"},{"id":"513662","messageId":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250219203349.787173-1-usmanakinyemi202@gmail.com","subject":"[Outreachy PATCH v3 0/8] stop using the_repository global variable.","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:44Z","receivedAt":"2025-03-06T14:36:35Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove `the_repository` global variable in favor of the repository\nargument that gets passed in builtin commands. \n\nThese sets of commands are commands that use only RUN_SETUP macro in \"git.c\".\nBasically, When `-h` is passed to any of this command outside a Git repository,\nthe `run_builtin()` will call the `cmd_x()` function (where `x` is any\nof the command from the sets of builtin commands that `the_repository` is removed\nfrom) with `repo` set to NULL and then early in the function, `parse_options()`\nor show_usage_with_options_if_asked() call will give the options help\nand exit.\n\nSome, functions also uses `the_repository` global internally, so, let's\nlet's refactor them and pass `struct repo` as one of the argument. \n\nAs the `repo` value can be NULL if a builtin command is run outside\nany repository. The current implementation of `repo_config()` will\nfail if `repo` is NULL.\nIf the `repo` is NULL, the `repo_config()` can ignore the repository\nconfiguration but it should read the other configuration sources like\nthe system-side configuration instead of failing.\n\nTeach the `repo_config()` to allow `repo` to be NULL by calling the\n`read_very_early_config()` which read config but only enumerate system\nand global settings. This make it possible for us to savely replace\n`git_config()` with `repo_config()`.\n\nChanges since v2\n================\n- Remove preparatory patches that move the `git_config()` below the\n`usage_with_options()`.\n- Add a new preparatory patch that teach the `repo_config()` to accept\nNULL value for `repo` variable.\n- Add tests to each of the builtin function in this commit to ensure\n`repo_config()` works as expected.\n- Make changes to the commit messages. \n\nUsman Akinyemi (8):\n  config: teach repo_config to allow `repo` to be NULL\n  builtin/verify-tag: stop using `the_repository`\n  builtin/verify-commit: stop using `the_repository`\n  builtin/send-pack: stop using `the_repository`\n  builtin/pack-refs: stop using `the_repository`\n  builtin/ls-files: stop using `the_repository`\n  builtin/for-each-ref: stop using `the_repository`\n  builtin/checkout-index: stop using `the_repository`\n\n builtin/checkout-index.c        | 43 ++++++++++++++++-----------------\n builtin/for-each-ref.c          |  5 ++--\n builtin/ls-files.c              | 32 ++++++++++++------------\n builtin/pack-refs.c             |  8 +++---\n builtin/send-pack.c             |  7 +++---\n builtin/verify-commit.c         | 13 +++++-----\n builtin/verify-tag.c            |  7 +++---\n config.c                        |  4 +++\n config.h                        |  3 +++\n t/t0610-reftable-basics.sh      |  7 ++++++\n t/t2006-checkout-index-basic.sh |  7 ++++++\n t/t3004-ls-files-basic.sh       |  7 ++++++\n t/t5400-send-pack.sh            |  7 ++++++\n t/t6300-for-each-ref.sh         |  7 ++++++\n t/t7030-verify-tag.sh           |  7 ++++++\n t/t7510-signed-commit.sh        |  7 ++++++\n 16 files changed, 110 insertions(+), 61 deletions(-)\n\nRange-diff versus v2:\n\n 1:  a313f9afb7 <  -:  ---------- builtin/verify-tag: refactor `cmd_verify_tag()`\n -:  ---------- >  1:  a5c69f3753 config: teach repo_config to allow `repo` to be NULL\n 2:  f993160d90 !  2:  dfa0da4061 builtin/verify-tag: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\n         to NULL and then early in the function, `parse_options()` call will give\n    -    the options help and exit, without having to consult much of the\n    -    configuration file.\n    +    the options help and exit.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/verify-tag.c: static const char * const verify_tag_usage[] = {\n      \tint i = 1, verbose = 0, had_error = 0;\n      \tunsigned flags = 0;\n     @@ builtin/verify-tag.c: int cmd_verify_tag(int argc,\n    - \t\tflags |= GPG_VERIFY_OMIT_STATUS;\n    - \t}\n    + \t\tOPT_END()\n    + \t};\n      \n     -\tgit_config(git_default_config, NULL);\n     +\trepo_config(repo, git_default_config, NULL);\n      \n    - \twhile (i < argc) {\n    + \targc = parse_options(argc, argv, prefix, verify_tag_options,\n    + \t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n    +@@ builtin/verify-tag.c: int cmd_verify_tag(int argc,\n      \t\tstruct object_id oid;\n      \t\tconst char *name = argv[i++];\n      \n    @@ builtin/verify-tag.c: int cmd_verify_tag(int argc,\n      \t\t\thad_error = !!error(\"tag '%s' not found.\", name);\n      \t\t\tcontinue;\n      \t\t}\n    +\n    + ## t/t7030-verify-tag.sh ##\n    +@@ t/t7030-verify-tag.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n    + . ./test-lib.sh\n    + . \"$TEST_DIRECTORY/lib-gpg.sh\"\n    + \n    ++test_expect_success GPG 'verify-tag does not crash with -h' '\n    ++\ttest_expect_code 129 git verify-tag -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git verify-tag \" usage &&\n    ++\ttest_expect_code 129 nongit git verify-tag -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git verify-tag \" usage\n    ++'\n    ++\n    + test_expect_success GPG 'create signed tags' '\n    + \techo 1 >file && git add file &&\n    + \ttest_tick && git commit -m initial &&\n 3:  f2f785190d <  -:  ---------- builtin/verify-commit: refactor `cmd_verify_commit()`\n 4:  5f8dc0c0ec !  3:  ade2d026cb builtin/verify-commit: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_verify_commit()` function with `repo`\n         set to NULL and then early in the function, `parse_options()` call will\n    -    give the options help and exit, without having to consult much of the\n    -    configuration file.\n    +    give the options help and exit.\n     \n         Pass the repository available in the calling context to `verify_commit()`\n         to remove it's dependency on the global `the_repository` variable.\n    @@ builtin/verify-commit.c: static int verify_commit(const char *name, unsigned fla\n      \tint i = 1, verbose = 0, had_error = 0;\n      \tunsigned flags = 0;\n     @@ builtin/verify-commit.c: int cmd_verify_commit(int argc,\n    - \tif (verbose)\n    - \t\tflags |= GPG_VERIFY_VERBOSE;\n    + \t\tOPT_END()\n    + \t};\n      \n     -\tgit_config(git_default_config, NULL);\n     +\trepo_config(repo, git_default_config, NULL);\n      \n    - \t/* sometimes the program was terminated because this signal\n    + \targc = parse_options(argc, argv, prefix, verify_commit_options,\n    + \t\t\t     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);\n    +@@ builtin/verify-commit.c: int cmd_verify_commit(int argc,\n      \t * was received in the process of writing the gpg input: */\n      \tsignal(SIGPIPE, SIG_IGN);\n      \twhile (i < argc)\n    @@ builtin/verify-commit.c: int cmd_verify_commit(int argc,\n      \t\t\thad_error = 1;\n      \treturn had_error;\n      }\n    +\n    + ## t/t7510-signed-commit.sh ##\n    +@@ t/t7510-signed-commit.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n    + GNUPGHOME_NOT_USED=$GNUPGHOME\n    + . \"$TEST_DIRECTORY/lib-gpg.sh\"\n    + \n    ++test_expect_success GPG 'verify-commit does not crash with -h' '\n    ++\ttest_expect_code 129 git verify-commit -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git verify-commit \" usage &&\n    ++\ttest_expect_code 129 nongit git verify-commit -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git verify-commit \" usage\n    ++'\n    ++\n    + test_expect_success GPG 'create signed commits' '\n    + \ttest_oid_cache <<-\\EOF &&\n    + \theader sha1:gpgsig\n 5:  d79c3fc1ee <  -:  ---------- builtin/send-pack: refactor `cmd_send_pack()`\n 6:  f280a9c387 !  4:  e3b58bc6cf builtin/send-pack: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_send_pack()` function with `repo` set\n         to NULL and then early in the function, `parse_options()` call will give\n    -    the options help and exit, without having to consult much of the\n    -    configuration file.\n    +    the options help and exit.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/send-pack.c: static int send_pack_config(const char *k, const char *v,\n      \tstruct refspec rs = REFSPEC_INIT_PUSH;\n      \tconst char *remote_name = NULL;\n     @@ builtin/send-pack.c: int cmd_send_pack(int argc,\n    - \tif (!dest)\n    - \t\tusage_with_options(send_pack_usage, options);\n    + \t\tOPT_END()\n    + \t};\n      \n     -\tgit_config(send_pack_config, NULL);\n     +\trepo_config(repo, send_pack_config, NULL);\n    - \n    - \targs.verbose = verbose;\n    - \targs.dry_run = dry_run;\n    + \targc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);\n    + \tif (argc > 0) {\n    + \t\tdest = argv[0];\n     @@ builtin/send-pack.c: int cmd_send_pack(int argc,\n      \tset_ref_status_for_push(remote_refs, args.send_mirror,\n      \t\targs.force_update);\n    @@ builtin/send-pack.c: int cmd_send_pack(int argc,\n      \n      \tif (helper_status)\n      \t\tprint_helper_status(remote_refs);\n    +\n    + ## t/t5400-send-pack.sh ##\n    +@@ t/t5400-send-pack.sh: test_expect_success setup '\n    + \techo Rebase &&\n    + \tgit log'\n    + \n    ++test_expect_success 'send-pack does not crash with -h' '\n    ++\ttest_expect_code 129 git send-pack -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git send-pack \" usage &&\n    ++\ttest_expect_code 129 nongit git send-pack -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git send-pack \" usage\n    ++'\n    ++\n    + test_expect_success 'pack the source repository' '\n    + \tgit repack -a -d &&\n    + \tgit prune\n 7:  df192a1b2c <  -:  ---------- builtin/pack-refs: refactor `cmd_pack_refs()`\n 8:  845cd1ea7c !  5:  b11e99627c builtin/pack-refs: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_pack_refs()` function with `repo` set\n         to NULL and then early in the function, `parse_options()` call will give\n    -    the options help and exit, without having to consult much of the\n    -    configuration file.\n    +    the options help and exit.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/pack-refs.c: static char const * const pack_refs_usage[] = {\n      \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n      \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n     @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,\n    - \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n    - \t\tusage_with_options(pack_refs_usage, opts);\n    - \n    + \t\t\tN_(\"references to exclude\")),\n    + \t\tOPT_END(),\n    + \t};\n     -\tgit_config(git_default_config, NULL);\n     +\trepo_config(repo, git_default_config, NULL);\n    - \tfor_each_string_list_item(item, &option_excluded_refs)\n    - \t\tadd_ref_exclusion(pack_refs_opts.exclusions, item->string);\n    + \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n    + \t\tusage_with_options(pack_refs_usage, opts);\n      \n     @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,\n      \tif (!pack_refs_opts.includes->nr)\n    @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,\n      \n      \tclear_ref_exclusions(&excludes);\n      \tstring_list_clear(&included_refs, 0);\n    +\n    + ## t/t0610-reftable-basics.sh ##\n    +@@ t/t0610-reftable-basics.sh: export GIT_TEST_DEFAULT_REF_FORMAT\n    + \n    + INVALID_OID=$(test_oid 001)\n    + \n    ++test_expect_success 'pack-refs does not crash with -h' '\n    ++\ttest_expect_code 129 git pack-refs -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git pack-refs \" usage &&\n    ++\ttest_expect_code 129 nongit git pack-refs -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git pack-refs \" usage\n    ++'\n    ++\n    + test_expect_success 'init: creates basic reftable structures' '\n    + \ttest_when_finished \"rm -rf repo\" &&\n    + \tgit init repo &&\n 9:  2aff17b09c !  6:  51c80f9273 builtin/ls-files: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_ls_files()` function with `repo` set\n         to NULL and then early in the function, `show_usage_with_options_if_asked()`\n    -    call will give the options help and exit, without having to consult much\n    -    of the configuration file.\n    +    call will give the options help and exit.\n     \n         Pass the repository available in the calling context to both\n         `expand_objectsize()` and `show_ru_info()` to remove their\n    @@ builtin/ls-files.c: int cmd_ls_files(int argc,\n      \n      \tif (ps_matched && report_path_error(ps_matched, &pathspec)) {\n      \t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\n    +\n    + ## t/t3004-ls-files-basic.sh ##\n    +@@ t/t3004-ls-files-basic.sh: test_expect_success 'ls-files -h in corrupt repository' '\n    + \ttest_grep \"[Uu]sage: git ls-files \" broken/usage\n    + '\n    + \n    ++test_expect_success 'ls-files does not crash with -h' '\n    ++\ttest_expect_code 129 git ls-files -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git ls-files \" usage &&\n    ++\ttest_expect_code 129 nongit git ls-files -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git ls-files \" usage\n    ++'\n    ++\n    + test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' '\n    + \tmkdir subs &&\n    + \tln -s nosuch link &&\n10:  4cc9a4935a <  -:  ---------- builtin/for-each-ref: refactor `cmd_for_each_ref()`\n11:  42c1a7ae74 !  7:  63bb89291f builtin/for-each-ref: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_for_each_ref()` function with `repo`\n         set to NULL and then early in the function, `parse_options()` call will\n    -    give the options help and exit, without having to consult much of the\n    -    configuration file.\n    +    give the options help and exit.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/for-each-ref.c: static char const * const for_each_ref_usage[] = {\n      \tstruct ref_sorting *sorting;\n      \tstruct string_list sorting_options = STRING_LIST_INIT_DUP;\n     @@ builtin/for-each-ref.c: int cmd_for_each_ref(int argc,\n    - \tif (verify_ref_format(&format))\n    - \t\tusage_with_options(for_each_ref_usage, opts);\n    + \n    + \tformat.format = \"%(objectname) %(objecttype)\\t%(refname)\";\n      \n     -\tgit_config(git_default_config, NULL);\n     +\trepo_config(repo, git_default_config, NULL);\n    - \tsorting = ref_sorting_options(&sorting_options);\n    - \tref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);\n    - \tfilter.ignore_case = icase;\n    + \n    + \t/* Set default (refname) sorting */\n    + \tstring_list_append(&sorting_options, \"refname\");\n    +\n    + ## t/t6300-for-each-ref.sh ##\n    +@@ t/t6300-for-each-ref.sh: test_expect_success 'Check invalid atoms names are errors' '\n    + \ttest_must_fail git for-each-ref --format=\"%(INVALID)\" refs/heads\n    + '\n    + \n    ++test_expect_success 'for-each-ref does not crash with -h' '\n    ++\ttest_expect_code 129 git for-each-ref -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git for-each-ref \" usage &&\n    ++\ttest_expect_code 129 nongit git for-each-ref -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git for-each-ref \" usage\n    ++'\n    ++\n    + test_expect_success 'Check format specifiers are ignored in naming date atoms' '\n    + \tgit for-each-ref --format=\"%(authordate)\" refs/heads &&\n    + \tgit for-each-ref --format=\"%(authordate:default) %(authordate)\" refs/heads &&\n12:  232cbef160 !  8:  8dfe6b40c8 builtin/checkout-index: stop using `the_repository`\n    @@ Commit message\n         When `-h` is passed to the command outside a Git repository, the\n         `run_builtin()` will call the `cmd_checkout_index()` function with `repo`\n         set to NULL and then early in the function, `show_usage_with_options_if_asked()`\n    -    call will give the options help and exit, without having to consult much\n    -    of the configuration file.\n    +    call will give the options help and exit.\n     \n         Pass the repository available in the calling context to both `checkout_all()`\n         and `checkout_file()` to remove their dependency on the global\n    @@ builtin/checkout-index.c: int cmd_checkout_index(int argc,\n      \t\tdie(\"Unable to write new index file\");\n      \treturn 0;\n      }\n    +\n    + ## t/t2006-checkout-index-basic.sh ##\n    +@@ t/t2006-checkout-index-basic.sh: test_expect_success 'checkout-index -h in broken repository' '\n    + \ttest_grep \"[Uu]sage\" broken/usage\n    + '\n    + \n    ++test_expect_success 'checkout-index does not crash with -h' '\n    ++\ttest_expect_code 129 git checkout-index -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git checkout-index \" usage &&\n    ++\ttest_expect_code 129 nongit git checkout-index -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git checkout-index \" usage\n    ++'\n    ++\n    + test_expect_success 'checkout-index reports errors (cmdline)' '\n    + \ttest_must_fail git checkout-index -- does-not-exist 2>stderr &&\n    + \ttest_grep not.in.the.cache stderr\n\n-- \n2.48.1\n\n"},{"id":"513663","messageId":"20250306143629.1267358-2-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:45Z","receivedAt":"2025-03-06T14:36:39Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"The `repo` value can be NULL if a builtin command is run outside\nany repository. The current implementation of `repo_config()` will\nfail if `repo` is NULL.\n\nIf the `repo` is NULL the `repo_config()` can ignore the repository\nconfiguration but it should read the other configuration sources like\nthe system-side configuration instead of failing.\n\nTeach the `repo_config()` to allow `repo` to be NULL by calling the\n`read_very_early_config()` which read config but only enumerate system\nand global settings.\n\nThis will be useful in the following commits.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n config.c | 4 ++++\n config.h | 3 +++\n 2 files changed, 7 insertions(+)\n\ndiff --git a/config.c b/config.c\nindex 36f76fafe5..c5181fd23b 100644\n--- a/config.c\n+++ b/config.c\n@@ -2526,6 +2526,10 @@ void repo_config_clear(struct repository *repo)\n \n void repo_config(struct repository *repo, config_fn_t fn, void *data)\n {\n+\tif (!repo) {\n+\t\tread_very_early_config(fn, data);\n+\t\treturn;\n+\t}\n \tgit_config_check_init(repo);\n \tconfigset_iter(repo->config, fn, data);\n }\ndiff --git a/config.h b/config.h\nindex 5c730c4f89..1e5b22dfc4 100644\n--- a/config.h\n+++ b/config.h\n@@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data);\n  * repo-specific one; by overwriting, the higher-priority repo-specific\n  * value is left at the end).\n  *\n+ * In cases where the repository variable is NULL, repo_config() will\n+ * call read_early_config().\n+ *\n  * Unlike git_config_from_file(), this function respects includes.\n  */\n void repo_config(struct repository *r, config_fn_t fn, void *);\n-- \n2.48.1\n\n"},{"id":"513664","messageId":"20250306143629.1267358-3-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 2/8] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:46Z","receivedAt":"2025-03-06T14:36:42Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-tag.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-tag.c  | 7 +++----\n t/t7030-verify-tag.sh | 7 +++++++\n 2 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/verify-tag.c b/builtin/verify-tag.c\nindex f6b97048a5..ed1c40338f 100644\n--- a/builtin/verify-tag.c\n+++ b/builtin/verify-tag.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag.sh\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {\n int cmd_verify_tag(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -35,7 +34,7 @@ int cmd_verify_tag(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, verify_tag_options,\n \t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n@@ -56,7 +55,7 @@ int cmd_verify_tag(int argc,\n \t\tstruct object_id oid;\n \t\tconst char *name = argv[i++];\n \n-\t\tif (repo_get_oid(the_repository, name, &oid)) {\n+\t\tif (repo_get_oid(repo, name, &oid)) {\n \t\t\thad_error = !!error(\"tag '%s' not found.\", name);\n \t\t\tcontinue;\n \t\t}\ndiff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh\nindex 6f526c37c2..2c147072c1 100755\n--- a/t/t7030-verify-tag.sh\n+++ b/t/t7030-verify-tag.sh\n@@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n . ./test-lib.sh\n . \"$TEST_DIRECTORY/lib-gpg.sh\"\n \n+test_expect_success GPG 'verify-tag does not crash with -h' '\n+\ttest_expect_code 129 git verify-tag -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-tag \" usage &&\n+\ttest_expect_code 129 nongit git verify-tag -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-tag \" usage\n+'\n+\n test_expect_success GPG 'create signed tags' '\n \techo 1 >file && git add file &&\n \ttest_tick && git commit -m initial &&\n-- \n2.48.1\n\n"},{"id":"513665","messageId":"20250306143629.1267358-4-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 3/8] builtin/verify-commit: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:47Z","receivedAt":"2025-03-06T14:36:45Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-commit.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_commit()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit.\n\nPass the repository available in the calling context to `verify_commit()`\nto remove it's dependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-commit.c  | 13 ++++++-------\n t/t7510-signed-commit.sh |  7 +++++++\n 2 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex 779b7988ca..5f749a30da 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)\n \treturn ret;\n }\n \n-static int verify_commit(const char *name, unsigned flags)\n+static int verify_commit(struct repository *repo, const char *name, unsigned flags)\n {\n \tstruct object_id oid;\n \tstruct object *obj;\n \n-\tif (repo_get_oid(the_repository, name, &oid))\n+\tif (repo_get_oid(repo, name, &oid))\n \t\treturn error(\"commit '%s' not found.\", name);\n \n-\tobj = parse_object(the_repository, &oid);\n+\tobj = parse_object(repo, &oid);\n \tif (!obj)\n \t\treturn error(\"%s: unable to read file.\", name);\n \tif (obj->type != OBJ_COMMIT)\n@@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags)\n int cmd_verify_commit(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -64,7 +63,7 @@ int cmd_verify_commit(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, verify_commit_options,\n \t\t\t     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);\n@@ -78,7 +77,7 @@ int cmd_verify_commit(int argc,\n \t * was received in the process of writing the gpg input: */\n \tsignal(SIGPIPE, SIG_IGN);\n \twhile (i < argc)\n-\t\tif (verify_commit(argv[i++], flags))\n+\t\tif (verify_commit(repo, argv[i++], flags))\n \t\t\thad_error = 1;\n \treturn had_error;\n }\ndiff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh\nindex 0d2dd29fe6..39677e859a 100755\n--- a/t/t7510-signed-commit.sh\n+++ b/t/t7510-signed-commit.sh\n@@ -8,6 +8,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n GNUPGHOME_NOT_USED=$GNUPGHOME\n . \"$TEST_DIRECTORY/lib-gpg.sh\"\n \n+test_expect_success GPG 'verify-commit does not crash with -h' '\n+\ttest_expect_code 129 git verify-commit -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-commit \" usage &&\n+\ttest_expect_code 129 nongit git verify-commit -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-commit \" usage\n+'\n+\n test_expect_success GPG 'create signed commits' '\n \ttest_oid_cache <<-\\EOF &&\n \theader sha1:gpgsig\n-- \n2.48.1\n\n"},{"id":"513666","messageId":"20250306143629.1267358-5-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 4/8] builtin/send-pack: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:48Z","receivedAt":"2025-03-06T14:36:48Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/send-pack.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_send_pack()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/send-pack.c  | 7 +++----\n t/t5400-send-pack.sh | 7 +++++++\n 2 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/send-pack.c b/builtin/send-pack.c\nindex 8d461008e2..c6e0e9d051 100644\n--- a/builtin/send-pack.c\n+++ b/builtin/send-pack.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"hex.h\"\n@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,\n int cmd_send_pack(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 \tstruct refspec rs = REFSPEC_INIT_PUSH;\n \tconst char *remote_name = NULL;\n@@ -212,7 +211,7 @@ int cmd_send_pack(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(send_pack_config, NULL);\n+\trepo_config(repo, send_pack_config, NULL);\n \targc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);\n \tif (argc > 0) {\n \t\tdest = argv[0];\n@@ -317,7 +316,7 @@ int cmd_send_pack(int argc,\n \tset_ref_status_for_push(remote_refs, args.send_mirror,\n \t\targs.force_update);\n \n-\tret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);\n+\tret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);\n \n \tif (helper_status)\n \t\tprint_helper_status(remote_refs);\ndiff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh\nindex 3f81f16e13..8f018d2f23 100755\n--- a/t/t5400-send-pack.sh\n+++ b/t/t5400-send-pack.sh\n@@ -55,6 +55,13 @@ test_expect_success setup '\n \techo Rebase &&\n \tgit log'\n \n+test_expect_success 'send-pack does not crash with -h' '\n+\ttest_expect_code 129 git send-pack -h >usage &&\n+\ttest_grep \"[Uu]sage: git send-pack \" usage &&\n+\ttest_expect_code 129 nongit git send-pack -h >usage &&\n+\ttest_grep \"[Uu]sage: git send-pack \" usage\n+'\n+\n test_expect_success 'pack the source repository' '\n \tgit repack -a -d &&\n \tgit prune\n-- \n2.48.1\n\n"},{"id":"513667","messageId":"20250306143629.1267358-6-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 5/8] builtin/pack-refs: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:49Z","receivedAt":"2025-03-06T14:36:52Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/pack-refs.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_pack_refs()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/pack-refs.c        | 8 +++-----\n t/t0610-reftable-basics.sh | 7 +++++++\n 2 files changed, 10 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/pack-refs.c b/builtin/pack-refs.c\nindex 4fdd68880e..e47bae1c80 100644\n--- a/builtin/pack-refs.c\n+++ b/builtin/pack-refs.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {\n int cmd_pack_refs(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 \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n@@ -39,7 +37,7 @@ int cmd_pack_refs(int argc,\n \t\t\tN_(\"references to exclude\")),\n \t\tOPT_END(),\n \t};\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n \t\tusage_with_options(pack_refs_usage, opts);\n \n@@ -52,7 +50,7 @@ int cmd_pack_refs(int argc,\n \tif (!pack_refs_opts.includes->nr)\n \t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n \n-\tret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);\n+\tret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);\n \n \tclear_ref_exclusions(&excludes);\n \tstring_list_clear(&included_refs, 0);\ndiff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh\nindex 4618ffc108..002a75dee8 100755\n--- a/t/t0610-reftable-basics.sh\n+++ b/t/t0610-reftable-basics.sh\n@@ -14,6 +14,13 @@ export GIT_TEST_DEFAULT_REF_FORMAT\n \n INVALID_OID=$(test_oid 001)\n \n+test_expect_success 'pack-refs does not crash with -h' '\n+\ttest_expect_code 129 git pack-refs -h >usage &&\n+\ttest_grep \"[Uu]sage: git pack-refs \" usage &&\n+\ttest_expect_code 129 nongit git pack-refs -h >usage &&\n+\ttest_grep \"[Uu]sage: git pack-refs \" usage\n+'\n+\n test_expect_success 'init: creates basic reftable structures' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.48.1\n\n"},{"id":"513668","messageId":"20250306143629.1267358-7-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 6/8] builtin/ls-files: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:50Z","receivedAt":"2025-03-06T14:36:55Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/ls-files.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_ls_files()` function with `repo` set\nto NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit.\n\nPass the repository available in the calling context to both\n`expand_objectsize()` and `show_ru_info()` to remove their\ndependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/ls-files.c        | 32 ++++++++++++++++----------------\n t/t3004-ls-files-basic.sh |  7 +++++++\n 2 files changed, 23 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a4431429b7..70a377e9c0 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -6,7 +6,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -245,12 +244,13 @@ static void show_submodule(struct repository *superproject,\n \trepo_clear(&subrepo);\n }\n \n-static void expand_objectsize(struct strbuf *line, const struct object_id *oid,\n+static void expand_objectsize(struct repository *repo, struct strbuf *line,\n+\t\t\t      const struct object_id *oid,\n \t\t\t      const enum object_type type, unsigned int padded)\n {\n \tif (type == OBJ_BLOB) {\n \t\tunsigned long size;\n-\t\tif (oid_object_info(the_repository, oid, &size) < 0)\n+\t\tif (oid_object_info(repo, oid, &size) < 0)\n \t\t\tdie(_(\"could not get object info about '%s'\"),\n \t\t\t    oid_to_hex(oid));\n \t\tif (padded)\n@@ -283,10 +283,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,\n \t\telse if (skip_prefix(format, \"(objecttype)\", &format))\n \t\t\tstrbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));\n \t\telse if (skip_prefix(format, \"(objectsize:padded)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 1);\n \t\telse if (skip_prefix(format, \"(objectsize)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 0);\n \t\telse if (skip_prefix(format, \"(stage)\", &format))\n \t\t\tstrbuf_addf(&sb, \"%d\", ce_stage(ce));\n@@ -348,7 +348,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,\n \t}\n }\n \n-static void show_ru_info(struct index_state *istate)\n+static void show_ru_info(struct repository *repo, struct index_state *istate)\n {\n \tstruct string_list_item *item;\n \n@@ -370,7 +370,7 @@ static void show_ru_info(struct index_state *istate)\n \t\t\tif (!ui->mode[i])\n \t\t\t\tcontinue;\n \t\t\tprintf(\"%s%06o %s %d\\t\", tag_resolve_undo, ui->mode[i],\n-\t\t\t       repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev),\n+\t\t\t       repo_find_unique_abbrev(repo, &ui->oid[i], abbrev),\n \t\t\t       i + 1);\n \t\t\twrite_name(path);\n \t\t}\n@@ -567,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt,\n int cmd_ls_files(int argc,\n \t\t const char **argv,\n \t\t const char *cmd_prefix,\n-\t\t struct repository *repo UNUSED)\n+\t\t struct repository *repo)\n {\n \tint require_work_tree = 0, show_tag = 0, i;\n \tchar *max_prefix;\n@@ -647,15 +647,15 @@ int cmd_ls_files(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t ls_files_usage, builtin_ls_files_options);\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n \tprefix = cmd_prefix;\n \tif (prefix)\n \t\tprefix_len = strlen(prefix);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n-\tif (repo_read_index(the_repository) < 0)\n+\tif (repo_read_index(repo) < 0)\n \t\tdie(\"index file corrupt\");\n \n \targc = parse_options(argc, argv, prefix, builtin_ls_files_options,\n@@ -724,7 +724,7 @@ int cmd_ls_files(int argc,\n \t\tmax_prefix = common_prefix(&pathspec);\n \tmax_prefix_len = get_common_prefix_len(max_prefix);\n \n-\tprune_index(the_repository->index, max_prefix, max_prefix_len);\n+\tprune_index(repo->index, max_prefix, max_prefix_len);\n \n \t/* Treat unmatching pathspec elements as errors */\n \tif (pathspec.nr && error_unmatch)\n@@ -748,13 +748,13 @@ int cmd_ls_files(int argc,\n \t\t */\n \t\tif (show_stage || show_unmerged)\n \t\t\tdie(_(\"options '%s' and '%s' cannot be used together\"), \"ls-files --with-tree\", \"-s/-u\");\n-\t\toverlay_tree_on_index(the_repository->index, with_tree, max_prefix);\n+\t\toverlay_tree_on_index(repo->index, with_tree, max_prefix);\n \t}\n \n-\tshow_files(the_repository, &dir);\n+\tshow_files(repo, &dir);\n \n \tif (show_resolve_undo)\n-\t\tshow_ru_info(the_repository->index);\n+\t\tshow_ru_info(repo, repo->index);\n \n \tif (ps_matched && report_path_error(ps_matched, &pathspec)) {\n \t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\ndiff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh\nindex a1078f8701..4034a5a59f 100755\n--- a/t/t3004-ls-files-basic.sh\n+++ b/t/t3004-ls-files-basic.sh\n@@ -34,6 +34,13 @@ test_expect_success 'ls-files -h in corrupt repository' '\n \ttest_grep \"[Uu]sage: git ls-files \" broken/usage\n '\n \n+test_expect_success 'ls-files does not crash with -h' '\n+\ttest_expect_code 129 git ls-files -h >usage &&\n+\ttest_grep \"[Uu]sage: git ls-files \" usage &&\n+\ttest_expect_code 129 nongit git ls-files -h >usage &&\n+\ttest_grep \"[Uu]sage: git ls-files \" usage\n+'\n+\n test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' '\n \tmkdir subs &&\n \tln -s nosuch link &&\n-- \n2.48.1\n\n"},{"id":"513669","messageId":"20250306143629.1267358-8-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 7/8] builtin/for-each-ref: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:51Z","receivedAt":"2025-03-06T14:36:59Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/for-each-ref.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_for_each_ref()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/for-each-ref.c  | 5 ++---\n t/t6300-for-each-ref.sh | 7 +++++++\n 2 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 8085ebd8fe..3d2207ec77 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"commit.h\"\n #include \"config.h\"\n@@ -20,7 +19,7 @@ static char const * const for_each_ref_usage[] = {\n int cmd_for_each_ref(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 \tstruct ref_sorting *sorting;\n \tstruct string_list sorting_options = STRING_LIST_INIT_DUP;\n@@ -63,7 +62,7 @@ int cmd_for_each_ref(int argc,\n \n \tformat.format = \"%(objectname) %(objecttype)\\t%(refname)\";\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \t/* Set default (refname) sorting */\n \tstring_list_append(&sorting_options, \"refname\");\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex a5c7794385..9b4f4306c4 100755\n--- a/t/t6300-for-each-ref.sh\n+++ b/t/t6300-for-each-ref.sh\n@@ -292,6 +292,13 @@ test_expect_success 'Check invalid atoms names are errors' '\n \ttest_must_fail git for-each-ref --format=\"%(INVALID)\" refs/heads\n '\n \n+test_expect_success 'for-each-ref does not crash with -h' '\n+\ttest_expect_code 129 git for-each-ref -h >usage &&\n+\ttest_grep \"[Uu]sage: git for-each-ref \" usage &&\n+\ttest_expect_code 129 nongit git for-each-ref -h >usage &&\n+\ttest_grep \"[Uu]sage: git for-each-ref \" usage\n+'\n+\n test_expect_success 'Check format specifiers are ignored in naming date atoms' '\n \tgit for-each-ref --format=\"%(authordate)\" refs/heads &&\n \tgit for-each-ref --format=\"%(authordate:default) %(authordate)\" refs/heads &&\n-- \n2.48.1\n\n"},{"id":"513670","messageId":"20250306143629.1267358-9-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[PATCH v3 8/8] builtin/checkout-index: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-06T14:35:52Z","receivedAt":"2025-03-06T14:37:02Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/checkout-index.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_checkout_index()` function with `repo`\nset to NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit.\n\nPass the repository available in the calling context to both `checkout_all()`\nand `checkout_file()` to remove their dependency on the global\n`the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/checkout-index.c        | 43 ++++++++++++++++-----------------\n t/t2006-checkout-index-basic.sh |  7 ++++++\n 2 files changed, 28 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex e30086c7d4..46035444eb 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -5,7 +5,6 @@\n  *\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -68,10 +67,10 @@ static void write_tempfile_record(const char *name, const char *prefix)\n \t}\n }\n \n-static int checkout_file(const char *name, const char *prefix)\n+static int checkout_file(struct repository *repo, const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = index_name_pos(the_repository->index, name, namelen);\n+\tint pos = index_name_pos(repo->index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -81,8 +80,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos <the_repository->index->cache_nr) {\n-\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n+\twhile (pos < repo->index->cache_nr) {\n+\t\tstruct cache_entry *ce =repo->index->cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -137,13 +136,13 @@ static int checkout_file(const char *name, const char *prefix)\n \treturn -1;\n }\n \n-static int checkout_all(const char *prefix, int prefix_length)\n+static int checkout_all(struct repository *repo, const char *prefix, int prefix_length)\n {\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n-\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n+\tfor (i = 0; i < repo->index->cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = repo->index->cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -156,8 +155,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t * first entry inside the expanded sparse directory).\n \t\t\t */\n \t\t\tif (ignore_skip_worktree) {\n-\t\t\t\tensure_full_index(the_repository->index);\n-\t\t\t\tce = the_repository->index->cache[i];\n+\t\t\t\tensure_full_index(repo->index);\n+\t\t\t\tce = repo->index->cache[i];\n \t\t\t}\n \t\t}\n \n@@ -213,7 +212,7 @@ static int option_parse_stage(const struct option *opt,\n int cmd_checkout_index(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 \tint i;\n \tstruct lock_file lock_file = LOCK_INIT;\n@@ -253,19 +252,19 @@ int cmd_checkout_index(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t builtin_checkout_index_usage,\n \t\t\t\t\t builtin_checkout_index_options);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tprefix_length = prefix ? strlen(prefix) : 0;\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n-\tif (repo_read_index(the_repository) < 0) {\n+\tif (repo_read_index(repo) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n \targc = parse_options(argc, argv, prefix, builtin_checkout_index_options,\n \t\t\tbuiltin_checkout_index_usage, 0);\n-\tstate.istate = the_repository->index;\n+\tstate.istate = repo->index;\n \tstate.force = force;\n \tstate.quiet = quiet;\n \tstate.not_new = not_new;\n@@ -285,8 +284,8 @@ int cmd_checkout_index(int argc,\n \t */\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n-\t\tstate.istate = the_repository->index;\n-\t\trepo_hold_locked_index(the_repository, &lock_file,\n+\t\tstate.istate = repo->index;\n+\t\trepo_hold_locked_index(repo, &lock_file,\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n@@ -304,7 +303,7 @@ int cmd_checkout_index(int argc,\n \t\tif (read_from_stdin)\n \t\t\tdie(\"git checkout-index: don't mix '--stdin' and explicit filenames\");\n \t\tp = prefix_path(prefix, prefix_length, arg);\n-\t\terr |= checkout_file(p, prefix);\n+\t\terr |= checkout_file(repo, p, prefix);\n \t\tfree(p);\n \t}\n \n@@ -326,7 +325,7 @@ int cmd_checkout_index(int argc,\n \t\t\t\tstrbuf_swap(&buf, &unquoted);\n \t\t\t}\n \t\t\tp = prefix_path(prefix, prefix_length, buf.buf);\n-\t\t\terr |= checkout_file(p, prefix);\n+\t\t\terr |= checkout_file(repo, p, prefix);\n \t\t\tfree(p);\n \t\t}\n \t\tstrbuf_release(&unquoted);\n@@ -334,7 +333,7 @@ int cmd_checkout_index(int argc,\n \t}\n \n \tif (all)\n-\t\terr |= checkout_all(prefix, prefix_length);\n+\t\terr |= checkout_all(repo, prefix, prefix_length);\n \n \tif (pc_workers > 1)\n \t\terr |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n@@ -344,7 +343,7 @@ int cmd_checkout_index(int argc,\n \t\treturn 1;\n \n \tif (is_lock_file_locked(&lock_file) &&\n-\t    write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n+\t    write_locked_index(repo->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/t/t2006-checkout-index-basic.sh b/t/t2006-checkout-index-basic.sh\nindex bac231b167..fedd2cc097 100755\n--- a/t/t2006-checkout-index-basic.sh\n+++ b/t/t2006-checkout-index-basic.sh\n@@ -21,6 +21,13 @@ test_expect_success 'checkout-index -h in broken repository' '\n \ttest_grep \"[Uu]sage\" broken/usage\n '\n \n+test_expect_success 'checkout-index does not crash with -h' '\n+\ttest_expect_code 129 git checkout-index -h >usage &&\n+\ttest_grep \"[Uu]sage: git checkout-index \" usage &&\n+\ttest_expect_code 129 nongit git checkout-index -h >usage &&\n+\ttest_grep \"[Uu]sage: git checkout-index \" usage\n+'\n+\n test_expect_success 'checkout-index reports errors (cmdline)' '\n \ttest_must_fail git checkout-index -- does-not-exist 2>stderr &&\n \ttest_grep not.in.the.cache stderr\n-- \n2.48.1\n\n"},{"id":"513723","messageId":"xmqqcyeuhwqb.fsf@gitster.g","threadId":"62956","inReplyTo":"20250306143629.1267358-2-usmanakinyemi202@gmail.com","subject":"Re: [PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-06T17:53:16Z","receivedAt":"2025-03-06T17:53:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n>  void repo_config(struct repository *repo, config_fn_t fn, void *data)\n>  {\n> +\tif (!repo) {\n> +\t\tread_very_early_config(fn, data);\n> +\t\treturn;\n> +\t}\n>  \tgit_config_check_init(repo);\n>  \tconfigset_iter(repo->config, fn, data);\n>  }\n> diff --git a/config.h b/config.h\n> index 5c730c4f89..1e5b22dfc4 100644\n> --- a/config.h\n> +++ b/config.h\n> @@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data);\n>   * repo-specific one; by overwriting, the higher-priority repo-specific\n>   * value is left at the end).\n>   *\n> + * In cases where the repository variable is NULL, repo_config() will\n> + * call read_early_config().\n> + *\n\nearly or very early?\n\nI am wondering if we should describe the effect we want out of the\ndesign more prominently than the way we try to obtain the effect\nhere.  In other words, instead of (rather, in addition to) saying\nthat we call helper X, wouldn't it be more helpful to future\ndevelopers why we call X, to convey the intent, so that they know\nhow to adjust when for example what X does change or X even\ndisappears?  E.g., \n\n\tWhen repo==NULL, skip reading the per-repository\n\tconfiguration file but still use the system- and globa-\n\tconfiguration, by calling X.  Note that this ignores\n\tone-time configuration override \"git -c var=val\" given from\n\tthe command line.  The only use case the feature to allow\n\tpassing repo==NULL was designed for is to support handling\n\t\"git foo -h\" (which lets git.c:run_builtin() to pass NULL\n\tand have the cmd_foo() call repo_config() before calling\n\tparse_options() to notice \"-h\", give help and exit) for a\n\tcommand that ordinarily require a repository, so this\n\tlimitation may be OK (but if needed you are welcome to fix\n\tit).\n\nThat way, folks who are planning to update read_veriy_early_config()\nso that it pays attention to the \"git -c var=val\" in the future will\nbe rest assured that they won't be breaking this caller with their\nplanned change.\n\nOf course I didn't spend enough brainpower to make the above comment\nmore concise and to the point, which the final version should be,\nbut hopefully you got the idea.\n\nThanks.\n\n"},{"id":"513724","messageId":"xmqq8qpihwkp.fsf@gitster.g","threadId":"62956","inReplyTo":"20250306143629.1267358-3-usmanakinyemi202@gmail.com","subject":"Re: [PATCH v3 2/8] builtin/verify-tag: stop using `the_repository`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-06T17:56:38Z","receivedAt":"2025-03-06T17:56:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> When `-h` is passed to the command outside a Git repository, the\n> `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\n> to NULL and then early in the function, `parse_options()` call will give\n> the options help and exit.\n\nMakes sense.\n\n> diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh\n> index 6f526c37c2..2c147072c1 100755\n> --- a/t/t7030-verify-tag.sh\n> +++ b/t/t7030-verify-tag.sh\n> @@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n>  . ./test-lib.sh\n>  . \"$TEST_DIRECTORY/lib-gpg.sh\"\n>  \n> +test_expect_success GPG 'verify-tag does not crash with -h' '\n> +\ttest_expect_code 129 git verify-tag -h >usage &&\n> +\ttest_grep \"[Uu]sage: git verify-tag \" usage &&\n> +\ttest_expect_code 129 nongit git verify-tag -h >usage &&\n> +\ttest_grep \"[Uu]sage: git verify-tag \" usage\n> +'\n\nOK.  I am not sure if we want to insist that the \"-h\" invocation\nexits with status 129, but changing it would be totaly outside the\ntopic.\n\nWill queue.\n"},{"id":"513725","messageId":"xmqq4j06hwfq.fsf@gitster.g","threadId":"62956","inReplyTo":"20250306143629.1267358-7-usmanakinyemi202@gmail.com","subject":"Re: [PATCH v3 6/8] builtin/ls-files: stop using `the_repository`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-06T17:59:37Z","receivedAt":"2025-03-06T17:59:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> Pass the repository available in the calling context to both\n> `expand_objectsize()` and `show_ru_info()` to remove their\n> dependency on the global `the_repository` variable.\n\nMakes sense, and the changes look reasonable.\n"},{"id":"513726","messageId":"xmqqzfhyggzb.fsf@gitster.g","threadId":"62956","inReplyTo":"20250306143629.1267358-9-usmanakinyemi202@gmail.com","subject":"Re: [PATCH v3 8/8] builtin/checkout-index: stop using `the_repository`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-06T18:18:48Z","receivedAt":"2025-03-06T18:18:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> Remove the_repository global variable in favor of the repository\n> argument that gets passed in \"builtin/checkout-index.c\".\n>\n> When `-h` is passed to the command outside a Git repository, the\n> `run_builtin()` will call the `cmd_checkout_index()` function with `repo`\n> set to NULL and then early in the function, `show_usage_with_options_if_asked()`\n> call will give the options help and exit.\n>\n> Pass the repository available in the calling context to both `checkout_all()`\n> and `checkout_file()` to remove their dependency on the global\n> `the_repository` variable.\n\nHmph, if we are passing anything down to these code paths, I would\nhave expected that it would be an instance of \"struct index_state\".\n\nDo these two helper functions need anything other than that from the\nrepository instance?\n\nOther than that, I think this step does look great.\n\nWill queue.\n\nThanks.\n"},{"id":"513734","messageId":"CAPSxiM_fLNUvg86TtCHZTbsE_VnhKdMiDa3pfLPsLa3ThZfxmw@mail.gmail.com","threadId":"62956","inReplyTo":"xmqqzfhyggzb.fsf@gitster.g","subject":"Re: [PATCH v3 8/8] builtin/checkout-index: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T01:15:29Z","receivedAt":"2025-03-07T01:15:41Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Thu, Mar 6, 2025 at 11:48 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n>\n> > Remove the_repository global variable in favor of the repository\n> > argument that gets passed in \"builtin/checkout-index.c\".\n> >\n> > When `-h` is passed to the command outside a Git repository, the\n> > `run_builtin()` will call the `cmd_checkout_index()` function with `repo`\n> > set to NULL and then early in the function, `show_usage_with_options_if_asked()`\n> > call will give the options help and exit.\n> >\n> > Pass the repository available in the calling context to both `checkout_all()`\n> > and `checkout_file()` to remove their dependency on the global\n> > `the_repository` variable.\n>\n> Hmph, if we are passing anything down to these code paths, I would\n> have expected that it would be an instance of \"struct index_state\".\n>\n> Do these two helper functions need anything other than that from the\n> repository instance?\nNo, they do not. They could possibly do in the future and is there any\nreason why we might want to pass the \"struct index_state\" instead of\nthe whole \"struct repository\" ?\n\n\n\n>\n> Other than that, I think this step does look great.\n>\n> Will queue.\n>\n> Thanks.\n"},{"id":"513735","messageId":"CAPSxiM8m7oeQ+DNPjzZzve4F510RYhWTfM-wsg5RabJ9fSF7Yg@mail.gmail.com","threadId":"62956","inReplyTo":"xmqqcyeuhwqb.fsf@gitster.g","subject":"Re: [PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T01:33:47Z","receivedAt":"2025-03-07T01:33:58Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Thu, Mar 6, 2025 at 11:23 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n>\n> >  void repo_config(struct repository *repo, config_fn_t fn, void *data)\n> >  {\n> > +     if (!repo) {\n> > +             read_very_early_config(fn, data);\n> > +             return;\n> > +     }\n> >       git_config_check_init(repo);\n> >       configset_iter(repo->config, fn, data);\n> >  }\n> > diff --git a/config.h b/config.h\n> > index 5c730c4f89..1e5b22dfc4 100644\n> > --- a/config.h\n> > +++ b/config.h\n> > @@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data);\n> >   * repo-specific one; by overwriting, the higher-priority repo-specific\n> >   * value is left at the end).\n> >   *\n> > + * In cases where the repository variable is NULL, repo_config() will\n> > + * call read_early_config().\n> > + *\n>\n> early or very early?\n>\n> I am wondering if we should describe the effect we want out of the\n> design more prominently than the way we try to obtain the effect\n> here.  In other words, instead of (rather, in addition to) saying\n> that we call helper X, wouldn't it be more helpful to future\n> developers why we call X, to convey the intent, so that they know\n> how to adjust when for example what X does change or X even\n> disappears?  E.g.,\n>\n>         When repo==NULL, skip reading the per-repository\n>         configuration file but still use the system- and globa-\n>         configuration, by calling X.  Note that this ignores\n>         one-time configuration override \"git -c var=val\" given from\n>         the command line.  The only use case the feature to allow\n>         passing repo==NULL was designed for is to support handling\n>         \"git foo -h\" (which lets git.c:run_builtin() to pass NULL\n>         and have the cmd_foo() call repo_config() before calling\n>         parse_options() to notice \"-h\", give help and exit) for a\n>         command that ordinarily require a repository, so this\n>         limitation may be OK (but if needed you are welcome to fix\n>         it).\n>\n> That way, folks who are planning to update read_veriy_early_config()\n> so that it pays attention to the \"git -c var=val\" in the future will\n> be rest assured that they won't be breaking this caller with their\n> planned change.\n>\n> Of course I didn't spend enough brainpower to make the above comment\n> more concise and to the point, which the final version should be,\n> but hopefully you got the idea.\nYeah, thanks Junio, I understand clearly. Your comment is well explained also.\nI will refine it and add it in an updated patch.\nThank you.\n>\n> Thanks.\n>\n"},{"id":"513744","messageId":"162727f9-fb65-4bae-87fb-48fd5527064c@gmail.com","threadId":"62956","inReplyTo":"xmqqcyeuhwqb.fsf@gitster.g","subject":"Re: [PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-07T10:37:42Z","receivedAt":"2025-03-07T10:37:47Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 06/03/2025 17:53, Junio C Hamano wrote:\n> Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n >\n> I am wondering if we should describe the effect we want out of the\n> design more prominently than the way we try to obtain the effect\n> here.  In other words, instead of (rather, in addition to) saying\n> that we call helper X, wouldn't it be more helpful to future\n> developers why we call X, to convey the intent, so that they know\n> how to adjust when for example what X does change or X even\n> disappears?  E.g.,\n> \n> \tWhen repo==NULL, skip reading the per-repository\n> \tconfiguration file but still use the system- and globa-\n> \tconfiguration, by calling X.  Note that this ignores\n> \tone-time configuration override \"git -c var=val\" given from\n> \tthe command line.  The only use case the feature to allow\n> \tpassing repo==NULL was designed for is to support handling\n> \t\"git foo -h\" (which lets git.c:run_builtin() to pass NULL\n> \tand have the cmd_foo() call repo_config() before calling\n> \tparse_options() to notice \"-h\", give help and exit) for a\n> \tcommand that ordinarily require a repository, so this\n> \tlimitation may be OK (but if needed you are welcome to fix\n> \tit).\n\nI think that would be very helpful as it makes it clear why we don't \ncare about config on the commandline for this series.\n\nBest Wishes\n\nPhillip\n\n> That way, folks who are planning to update read_veriy_early_config()\n> so that it pays attention to the \"git -c var=val\" in the future will\n> be rest assured that they won't be breaking this caller with their\n> planned change.\n> \n> Of course I didn't spend enough brainpower to make the above comment\n> more concise and to the point, which the final version should be,\n> but hopefully you got the idea.\n> \n> Thanks.\n> \n> \n\n"},{"id":"513757","messageId":"xmqqfrjpexks.fsf@gitster.g","threadId":"62956","inReplyTo":"CAPSxiM_fLNUvg86TtCHZTbsE_VnhKdMiDa3pfLPsLa3ThZfxmw@mail.gmail.com","subject":"Re: [PATCH v3 8/8] builtin/checkout-index: stop using `the_repository`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-07T14:15:31Z","receivedAt":"2025-03-07T14:15:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n>> Hmph, if we are passing anything down to these code paths, I would\n>> have expected that it would be an instance of \"struct index_state\".\n>>\n>> Do these two helper functions need anything other than that from the\n>> repository instance?\n> No, they do not. They could possibly do in the future and is there any\n> reason why we might want to pass the \"struct index_state\" instead of\n> the whole \"struct repository\" ?\n\nYou are asking a wrong question.\n\nWhen there are two things, A and B, where B is a piece of data with\na smaller scope that is contained within A, unless your function\nneeds to access parts of A that is impossible to access if you fed\nit only B, limiting the interface to the smallest piece necessary\n(in this case, B) is always the better design.  A potential caller\nthat only has B and not A can still call your function that takes B\nif you designed the API that way.  If you insist that the caller\npass A (and infer which B to use as part of A), a potential caller\nthat only has B cannot call your function.\n\nSo, with that understanding of a general principle in mind, you need\na stronger justification to pass the larger object A that goes\nagainst the best practice, saying \"Even though we do not have to\npass A because only B is necessary, we pass A because ...\".  And you\njust said there is no such reason why you need a repository and for\nthese functions an index_state is sufficient.\n\nThere are many functions that only need \"struct index_state\"\ninstance and obtains one from their callers.  They do not have a\nrepository object, other than the one that is referred to from the\nindex_state (to keep track of which repository it originated from).\n\nBut this pointer is not designed to round-trip.  There can be, and\nthere indeed are, code paths that use multiple index_state instances\nassociated with one repository.  But a repository instance has only\none \".index\" member.  It means if you pass a repository, you are\nmaking it impossible for your potential callers that has secondary\nindex_state instances.\n\n"},{"id":"513785","messageId":"CAPSxiM_6Z8gVMnRYwccZTMWbJJSU56X4engcx=PK3cSN5FgDPg@mail.gmail.com","threadId":"62956","inReplyTo":"xmqqfrjpexks.fsf@gitster.g","subject":"Re: [PATCH v3 8/8] builtin/checkout-index: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T19:41:51Z","receivedAt":"2025-03-07T19:42:03Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Fri, Mar 7, 2025 at 7:45 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n>\n> >> Hmph, if we are passing anything down to these code paths, I would\n> >> have expected that it would be an instance of \"struct index_state\".\n> >>\n> >> Do these two helper functions need anything other than that from the\n> >> repository instance?\n> > No, they do not. They could possibly do in the future and is there any\n> > reason why we might want to pass the \"struct index_state\" instead of\n> > the whole \"struct repository\" ?\n>\n> You are asking a wrong question.\n>\n> When there are two things, A and B, where B is a piece of data with\n> a smaller scope that is contained within A, unless your function\n> needs to access parts of A that is impossible to access if you fed\n> it only B, limiting the interface to the smallest piece necessary\n> (in this case, B) is always the better design.  A potential caller\n> that only has B and not A can still call your function that takes B\n> if you designed the API that way.  If you insist that the caller\n> pass A (and infer which B to use as part of A), a potential caller\n> that only has B cannot call your function.\n>\n> So, with that understanding of a general principle in mind, you need\n> a stronger justification to pass the larger object A that goes\n> against the best practice, saying \"Even though we do not have to\n> pass A because only B is necessary, we pass A because ...\".  And you\n> just said there is no such reason why you need a repository and for\n> these functions an index_state is sufficient.\n>\n> There are many functions that only need \"struct index_state\"\n> instance and obtains one from their callers.  They do not have a\n> repository object, other than the one that is referred to from the\n> index_state (to keep track of which repository it originated from).\n>\n> But this pointer is not designed to round-trip.  There can be, and\n> there indeed are, code paths that use multiple index_state instances\n> associated with one repository.  But a repository instance has only\n> one \".index\" member.  It means if you pass a repository, you are\n> making it impossible for your potential callers that has secondary\n> index_state instances.\nThanks for the explanation.\n\nI did not know or think about this before.\n\nI will make changes to this in the next iteration.\n\nThank you.\n>\n"},{"id":"513810","messageId":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250306143629.1267358-1-usmanakinyemi202@gmail.com","subject":"[Outreachy PATCH v4 0/8] stop using the_repository global variable.","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:34:59Z","receivedAt":"2025-03-07T23:35:49Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove `the_repository` global variable in favor of the repository\nargument that gets passed in builtin commands. \n\nThese sets of commands are commands that use only RUN_SETUP macro in \"git.c\".\nBasically, When `-h` is passed to any of this command outside a Git repository,\nthe `run_builtin()` will call the `cmd_x()` function (where `x` is any\nof the command from the sets of builtin commands that `the_repository` is removed\nfrom) with `repo` set to NULL and then early in the function, `parse_options()`\nor show_usage_with_options_if_asked() call will give the options help\nand exit.\n\nSome functions also uses `the_repository` global internally, so, let's\nlet's refactor them and pass `struct repo` as one of the argument. Some\nfunctions only need an instance of \"struct index_state\", so, let's pass\nit to such functions.\n\nAs the `repo` value can be NULL if a builtin command is run outside\nany repository. The current implementation of `repo_config()` will\nfail if `repo` is NULL.\nIf the `repo` is NULL, the `repo_config()` can ignore the repository\nconfiguration but it should read the other configuration sources like\nthe system-side configuration instead of failing.\n\nTeach the `repo_config()` to allow `repo` to be NULL by calling the\n`read_very_early_config()` which read config but only enumerate system\nand global settings. This make it possible for us to savely replace\n`git_config()` with `repo_config()`.\n\nChanges since v3\n================\n- Add a comment to describe why we teach `repo_config()` to take NULL\nrepo value and what we intend to achieve.\n- Pass \"struct index_state\" instead of repo in functions inside\n\"builtin/checkout-index.c\"\n- Fix some typo.\n\nUsman Akinyemi (8):\n  config: teach repo_config to allow `repo` to be NULL\n  builtin/verify-tag: stop using `the_repository`\n  builtin/verify-commit: stop using `the_repository`\n  builtin/send-pack: stop using `the_repository`\n  builtin/pack-refs: stop using `the_repository`\n  builtin/ls-files: stop using `the_repository`\n  builtin/for-each-ref: stop using `the_repository`\n  builtin/checkout-index: stop using `the_repository`\n\n builtin/checkout-index.c        | 43 ++++++++++++++++-----------------\n builtin/for-each-ref.c          |  5 ++--\n builtin/ls-files.c              | 32 ++++++++++++------------\n builtin/pack-refs.c             |  8 +++---\n builtin/send-pack.c             |  7 +++---\n builtin/verify-commit.c         | 13 +++++-----\n builtin/verify-tag.c            |  7 +++---\n config.c                        |  4 +++\n config.h                        |  9 +++++++\n t/t0610-reftable-basics.sh      |  7 ++++++\n t/t2006-checkout-index-basic.sh |  7 ++++++\n t/t3004-ls-files-basic.sh       |  7 ++++++\n t/t5400-send-pack.sh            |  7 ++++++\n t/t6300-for-each-ref.sh         |  7 ++++++\n t/t7030-verify-tag.sh           |  7 ++++++\n t/t7510-signed-commit.sh        |  7 ++++++\n 16 files changed, 116 insertions(+), 61 deletions(-)\n\nRange-diff versus v3:\n\n1:  a5c69f3753 ! 1:  f53677cbd6 config: teach repo_config to allow `repo` to be NULL\n    @@ config.h: void read_very_early_config(config_fn_t cb, void *data);\n       * value is left at the end).\n       *\n     + * In cases where the repository variable is NULL, repo_config() will\n    -+ * call read_early_config().\n    ++ * skip the per-repository config but retain system and global configs\n    ++ * by calling read_very_early_config() which also ignores one-time\n    ++ * overrides like \"git -c var=val\". This is to support handling \"git foo -h\"\n    ++ * (which lets git.c:run_builtin() to pass NULL and have the cmd_foo()\n    ++ * call repo_config() before calling parse_options() to notice \"-h\", give\n    ++ * help and exit) for a command that ordinarily require a repository\n    ++ * so this limitation may be OK (but if needed you are welcome to fix it).\n     + *\n       * Unlike git_config_from_file(), this function respects includes.\n       */\n2:  dfa0da4061 = 2:  6560218b7a builtin/verify-tag: stop using `the_repository`\n3:  ade2d026cb = 3:  22681bad00 builtin/verify-commit: stop using `the_repository`\n4:  e3b58bc6cf = 4:  a2a97b10a6 builtin/send-pack: stop using `the_repository`\n5:  b11e99627c = 5:  b88e45e795 builtin/pack-refs: stop using `the_repository`\n6:  51c80f9273 = 6:  d976fab012 builtin/ls-files: stop using `the_repository`\n7:  63bb89291f = 7:  6a44666310 builtin/for-each-ref: stop using `the_repository`\n8:  8dfe6b40c8 ! 8:  677e088e55 builtin/checkout-index: stop using `the_repository`\n    @@ Commit message\n         set to NULL and then early in the function, `show_usage_with_options_if_asked()`\n         call will give the options help and exit.\n     \n    -    Pass the repository available in the calling context to both `checkout_all()`\n    -    and `checkout_file()` to remove their dependency on the global\n    -    `the_repository` variable.\n    +    Pass an instance of \"struct index_state\" available in the calling\n    +    context to both `checkout_all()` and `checkout_file()` to remove their\n    +    dependency on the global `the_repository` variable.\n     \n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n    @@ builtin/checkout-index.c: static void write_tempfile_record(const char *name, co\n      }\n      \n     -static int checkout_file(const char *name, const char *prefix)\n    -+static int checkout_file(struct repository *repo, const char *name, const char *prefix)\n    ++static int checkout_file(struct index_state *index, const char *name, const char *prefix)\n      {\n      \tint namelen = strlen(name);\n     -\tint pos = index_name_pos(the_repository->index, name, namelen);\n    -+\tint pos = index_name_pos(repo->index, name, namelen);\n    ++\tint pos = index_name_pos(index, name, namelen);\n      \tint has_same_name = 0;\n      \tint is_file = 0;\n      \tint is_skipped = 1;\n    @@ builtin/checkout-index.c: static int checkout_file(const char *name, const char\n      \n     -\twhile (pos <the_repository->index->cache_nr) {\n     -\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n    -+\twhile (pos < repo->index->cache_nr) {\n    -+\t\tstruct cache_entry *ce =repo->index->cache[pos];\n    ++\twhile (pos < index->cache_nr) {\n    ++\t\tstruct cache_entry *ce = index->cache[pos];\n      \t\tif (ce_namelen(ce) != namelen ||\n      \t\t    memcmp(ce->name, name, namelen))\n      \t\t\tbreak;\n    @@ builtin/checkout-index.c: static int checkout_file(const char *name, const char\n      }\n      \n     -static int checkout_all(const char *prefix, int prefix_length)\n    -+static int checkout_all(struct repository *repo, const char *prefix, int prefix_length)\n    ++static int checkout_all(struct index_state *index, const char *prefix, int prefix_length)\n      {\n      \tint i, errs = 0;\n      \tstruct cache_entry *last_ce = NULL;\n      \n     -\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n     -\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n    -+\tfor (i = 0; i < repo->index->cache_nr ; i++) {\n    -+\t\tstruct cache_entry *ce = repo->index->cache[i];\n    ++\tfor (i = 0; i < index->cache_nr ; i++) {\n    ++\t\tstruct cache_entry *ce = index->cache[i];\n      \n      \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n      \t\t\tif (!ce_skip_worktree(ce))\n    @@ builtin/checkout-index.c: static int checkout_all(const char *prefix, int prefix\n      \t\t\tif (ignore_skip_worktree) {\n     -\t\t\t\tensure_full_index(the_repository->index);\n     -\t\t\t\tce = the_repository->index->cache[i];\n    -+\t\t\t\tensure_full_index(repo->index);\n    -+\t\t\t\tce = repo->index->cache[i];\n    ++\t\t\t\tensure_full_index(index);\n    ++\t\t\t\tce = index->cache[i];\n      \t\t\t}\n      \t\t}\n      \n    @@ builtin/checkout-index.c: int cmd_checkout_index(int argc,\n      \t\t\tdie(\"git checkout-index: don't mix '--stdin' and explicit filenames\");\n      \t\tp = prefix_path(prefix, prefix_length, arg);\n     -\t\terr |= checkout_file(p, prefix);\n    -+\t\terr |= checkout_file(repo, p, prefix);\n    ++\t\terr |= checkout_file(repo->index, p, prefix);\n      \t\tfree(p);\n      \t}\n      \n    @@ builtin/checkout-index.c: int cmd_checkout_index(int argc,\n      \t\t\t}\n      \t\t\tp = prefix_path(prefix, prefix_length, buf.buf);\n     -\t\t\terr |= checkout_file(p, prefix);\n    -+\t\t\terr |= checkout_file(repo, p, prefix);\n    ++\t\t\terr |= checkout_file(repo->index, p, prefix);\n      \t\t\tfree(p);\n      \t\t}\n      \t\tstrbuf_release(&unquoted);\n    @@ builtin/checkout-index.c: int cmd_checkout_index(int argc,\n      \n      \tif (all)\n     -\t\terr |= checkout_all(prefix, prefix_length);\n    -+\t\terr |= checkout_all(repo, prefix, prefix_length);\n    ++\t\terr |= checkout_all(repo->index, prefix, prefix_length);\n      \n      \tif (pc_workers > 1)\n      \t\terr |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n\n-- \n2.48.1\n\n"},{"id":"513811","messageId":"20250307233543.1721552-2-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 1/8] config: teach repo_config to allow `repo` to be NULL","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:00Z","receivedAt":"2025-03-07T23:35:52Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"The `repo` value can be NULL if a builtin command is run outside\nany repository. The current implementation of `repo_config()` will\nfail if `repo` is NULL.\n\nIf the `repo` is NULL the `repo_config()` can ignore the repository\nconfiguration but it should read the other configuration sources like\nthe system-side configuration instead of failing.\n\nTeach the `repo_config()` to allow `repo` to be NULL by calling the\n`read_very_early_config()` which read config but only enumerate system\nand global settings.\n\nThis will be useful in the following commits.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n config.c | 4 ++++\n config.h | 9 +++++++++\n 2 files changed, 13 insertions(+)\n\ndiff --git a/config.c b/config.c\nindex 36f76fafe5..c5181fd23b 100644\n--- a/config.c\n+++ b/config.c\n@@ -2526,6 +2526,10 @@ void repo_config_clear(struct repository *repo)\n \n void repo_config(struct repository *repo, config_fn_t fn, void *data)\n {\n+\tif (!repo) {\n+\t\tread_very_early_config(fn, data);\n+\t\treturn;\n+\t}\n \tgit_config_check_init(repo);\n \tconfigset_iter(repo->config, fn, data);\n }\ndiff --git a/config.h b/config.h\nindex 5c730c4f89..29a0277483 100644\n--- a/config.h\n+++ b/config.h\n@@ -219,6 +219,15 @@ void read_very_early_config(config_fn_t cb, void *data);\n  * repo-specific one; by overwriting, the higher-priority repo-specific\n  * value is left at the end).\n  *\n+ * In cases where the repository variable is NULL, repo_config() will\n+ * skip the per-repository config but retain system and global configs\n+ * by calling read_very_early_config() which also ignores one-time\n+ * overrides like \"git -c var=val\". This is to support handling \"git foo -h\"\n+ * (which lets git.c:run_builtin() to pass NULL and have the cmd_foo()\n+ * call repo_config() before calling parse_options() to notice \"-h\", give\n+ * help and exit) for a command that ordinarily require a repository\n+ * so this limitation may be OK (but if needed you are welcome to fix it).\n+ *\n  * Unlike git_config_from_file(), this function respects includes.\n  */\n void repo_config(struct repository *r, config_fn_t fn, void *);\n-- \n2.48.1\n\n"},{"id":"513812","messageId":"20250307233543.1721552-3-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 2/8] builtin/verify-tag: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:01Z","receivedAt":"2025-03-07T23:35:56Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-tag.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_tag()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-tag.c  | 7 +++----\n t/t7030-verify-tag.sh | 7 +++++++\n 2 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/verify-tag.c b/builtin/verify-tag.c\nindex f6b97048a5..ed1c40338f 100644\n--- a/builtin/verify-tag.c\n+++ b/builtin/verify-tag.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag.sh\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {\n int cmd_verify_tag(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -35,7 +34,7 @@ int cmd_verify_tag(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, verify_tag_options,\n \t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n@@ -56,7 +55,7 @@ int cmd_verify_tag(int argc,\n \t\tstruct object_id oid;\n \t\tconst char *name = argv[i++];\n \n-\t\tif (repo_get_oid(the_repository, name, &oid)) {\n+\t\tif (repo_get_oid(repo, name, &oid)) {\n \t\t\thad_error = !!error(\"tag '%s' not found.\", name);\n \t\t\tcontinue;\n \t\t}\ndiff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh\nindex 6f526c37c2..2c147072c1 100755\n--- a/t/t7030-verify-tag.sh\n+++ b/t/t7030-verify-tag.sh\n@@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n . ./test-lib.sh\n . \"$TEST_DIRECTORY/lib-gpg.sh\"\n \n+test_expect_success GPG 'verify-tag does not crash with -h' '\n+\ttest_expect_code 129 git verify-tag -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-tag \" usage &&\n+\ttest_expect_code 129 nongit git verify-tag -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-tag \" usage\n+'\n+\n test_expect_success GPG 'create signed tags' '\n \techo 1 >file && git add file &&\n \ttest_tick && git commit -m initial &&\n-- \n2.48.1\n\n"},{"id":"513813","messageId":"20250307233543.1721552-4-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 3/8] builtin/verify-commit: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:02Z","receivedAt":"2025-03-07T23:35:59Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/verify-commit.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_verify_commit()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit.\n\nPass the repository available in the calling context to `verify_commit()`\nto remove it's dependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/verify-commit.c  | 13 ++++++-------\n t/t7510-signed-commit.sh |  7 +++++++\n 2 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex 779b7988ca..5f749a30da 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -5,7 +5,6 @@\n  *\n  * Based on git-verify-tag\n  */\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)\n \treturn ret;\n }\n \n-static int verify_commit(const char *name, unsigned flags)\n+static int verify_commit(struct repository *repo, const char *name, unsigned flags)\n {\n \tstruct object_id oid;\n \tstruct object *obj;\n \n-\tif (repo_get_oid(the_repository, name, &oid))\n+\tif (repo_get_oid(repo, name, &oid))\n \t\treturn error(\"commit '%s' not found.\", name);\n \n-\tobj = parse_object(the_repository, &oid);\n+\tobj = parse_object(repo, &oid);\n \tif (!obj)\n \t\treturn error(\"%s: unable to read file.\", name);\n \tif (obj->type != OBJ_COMMIT)\n@@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags)\n int cmd_verify_commit(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 \tint i = 1, verbose = 0, had_error = 0;\n \tunsigned flags = 0;\n@@ -64,7 +63,7 @@ int cmd_verify_commit(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, verify_commit_options,\n \t\t\t     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);\n@@ -78,7 +77,7 @@ int cmd_verify_commit(int argc,\n \t * was received in the process of writing the gpg input: */\n \tsignal(SIGPIPE, SIG_IGN);\n \twhile (i < argc)\n-\t\tif (verify_commit(argv[i++], flags))\n+\t\tif (verify_commit(repo, argv[i++], flags))\n \t\t\thad_error = 1;\n \treturn had_error;\n }\ndiff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh\nindex 0d2dd29fe6..39677e859a 100755\n--- a/t/t7510-signed-commit.sh\n+++ b/t/t7510-signed-commit.sh\n@@ -8,6 +8,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n GNUPGHOME_NOT_USED=$GNUPGHOME\n . \"$TEST_DIRECTORY/lib-gpg.sh\"\n \n+test_expect_success GPG 'verify-commit does not crash with -h' '\n+\ttest_expect_code 129 git verify-commit -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-commit \" usage &&\n+\ttest_expect_code 129 nongit git verify-commit -h >usage &&\n+\ttest_grep \"[Uu]sage: git verify-commit \" usage\n+'\n+\n test_expect_success GPG 'create signed commits' '\n \ttest_oid_cache <<-\\EOF &&\n \theader sha1:gpgsig\n-- \n2.48.1\n\n"},{"id":"513814","messageId":"20250307233543.1721552-5-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 4/8] builtin/send-pack: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:03Z","receivedAt":"2025-03-07T23:36:02Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/send-pack.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_send_pack()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/send-pack.c  | 7 +++----\n t/t5400-send-pack.sh | 7 +++++++\n 2 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/send-pack.c b/builtin/send-pack.c\nindex 8d461008e2..c6e0e9d051 100644\n--- a/builtin/send-pack.c\n+++ b/builtin/send-pack.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"hex.h\"\n@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,\n int cmd_send_pack(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 \tstruct refspec rs = REFSPEC_INIT_PUSH;\n \tconst char *remote_name = NULL;\n@@ -212,7 +211,7 @@ int cmd_send_pack(int argc,\n \t\tOPT_END()\n \t};\n \n-\tgit_config(send_pack_config, NULL);\n+\trepo_config(repo, send_pack_config, NULL);\n \targc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);\n \tif (argc > 0) {\n \t\tdest = argv[0];\n@@ -317,7 +316,7 @@ int cmd_send_pack(int argc,\n \tset_ref_status_for_push(remote_refs, args.send_mirror,\n \t\targs.force_update);\n \n-\tret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);\n+\tret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);\n \n \tif (helper_status)\n \t\tprint_helper_status(remote_refs);\ndiff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh\nindex 3f81f16e13..8f018d2f23 100755\n--- a/t/t5400-send-pack.sh\n+++ b/t/t5400-send-pack.sh\n@@ -55,6 +55,13 @@ test_expect_success setup '\n \techo Rebase &&\n \tgit log'\n \n+test_expect_success 'send-pack does not crash with -h' '\n+\ttest_expect_code 129 git send-pack -h >usage &&\n+\ttest_grep \"[Uu]sage: git send-pack \" usage &&\n+\ttest_expect_code 129 nongit git send-pack -h >usage &&\n+\ttest_grep \"[Uu]sage: git send-pack \" usage\n+'\n+\n test_expect_success 'pack the source repository' '\n \tgit repack -a -d &&\n \tgit prune\n-- \n2.48.1\n\n"},{"id":"513815","messageId":"20250307233543.1721552-6-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 5/8] builtin/pack-refs: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:04Z","receivedAt":"2025-03-07T23:36:06Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/pack-refs.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_pack_refs()` function with `repo` set\nto NULL and then early in the function, `parse_options()` call will give\nthe options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/pack-refs.c        | 8 +++-----\n t/t0610-reftable-basics.sh | 7 +++++++\n 2 files changed, 10 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/pack-refs.c b/builtin/pack-refs.c\nindex 4fdd68880e..e47bae1c80 100644\n--- a/builtin/pack-refs.c\n+++ b/builtin/pack-refs.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {\n int cmd_pack_refs(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 \tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n \tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n@@ -39,7 +37,7 @@ int cmd_pack_refs(int argc,\n \t\t\tN_(\"references to exclude\")),\n \t\tOPT_END(),\n \t};\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n \t\tusage_with_options(pack_refs_usage, opts);\n \n@@ -52,7 +50,7 @@ int cmd_pack_refs(int argc,\n \tif (!pack_refs_opts.includes->nr)\n \t\tstring_list_append(pack_refs_opts.includes, \"refs/tags/*\");\n \n-\tret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);\n+\tret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);\n \n \tclear_ref_exclusions(&excludes);\n \tstring_list_clear(&included_refs, 0);\ndiff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh\nindex 4618ffc108..002a75dee8 100755\n--- a/t/t0610-reftable-basics.sh\n+++ b/t/t0610-reftable-basics.sh\n@@ -14,6 +14,13 @@ export GIT_TEST_DEFAULT_REF_FORMAT\n \n INVALID_OID=$(test_oid 001)\n \n+test_expect_success 'pack-refs does not crash with -h' '\n+\ttest_expect_code 129 git pack-refs -h >usage &&\n+\ttest_grep \"[Uu]sage: git pack-refs \" usage &&\n+\ttest_expect_code 129 nongit git pack-refs -h >usage &&\n+\ttest_grep \"[Uu]sage: git pack-refs \" usage\n+'\n+\n test_expect_success 'init: creates basic reftable structures' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.48.1\n\n"},{"id":"513816","messageId":"20250307233543.1721552-7-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 6/8] builtin/ls-files: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:05Z","receivedAt":"2025-03-07T23:36:10Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/ls-files.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_ls_files()` function with `repo` set\nto NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit.\n\nPass the repository available in the calling context to both\n`expand_objectsize()` and `show_ru_info()` to remove their\ndependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/ls-files.c        | 32 ++++++++++++++++----------------\n t/t3004-ls-files-basic.sh |  7 +++++++\n 2 files changed, 23 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a4431429b7..70a377e9c0 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -6,7 +6,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -245,12 +244,13 @@ static void show_submodule(struct repository *superproject,\n \trepo_clear(&subrepo);\n }\n \n-static void expand_objectsize(struct strbuf *line, const struct object_id *oid,\n+static void expand_objectsize(struct repository *repo, struct strbuf *line,\n+\t\t\t      const struct object_id *oid,\n \t\t\t      const enum object_type type, unsigned int padded)\n {\n \tif (type == OBJ_BLOB) {\n \t\tunsigned long size;\n-\t\tif (oid_object_info(the_repository, oid, &size) < 0)\n+\t\tif (oid_object_info(repo, oid, &size) < 0)\n \t\t\tdie(_(\"could not get object info about '%s'\"),\n \t\t\t    oid_to_hex(oid));\n \t\tif (padded)\n@@ -283,10 +283,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,\n \t\telse if (skip_prefix(format, \"(objecttype)\", &format))\n \t\t\tstrbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));\n \t\telse if (skip_prefix(format, \"(objectsize:padded)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 1);\n \t\telse if (skip_prefix(format, \"(objectsize)\", &format))\n-\t\t\texpand_objectsize(&sb, &ce->oid,\n+\t\t\texpand_objectsize(repo, &sb, &ce->oid,\n \t\t\t\t\t  object_type(ce->ce_mode), 0);\n \t\telse if (skip_prefix(format, \"(stage)\", &format))\n \t\t\tstrbuf_addf(&sb, \"%d\", ce_stage(ce));\n@@ -348,7 +348,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,\n \t}\n }\n \n-static void show_ru_info(struct index_state *istate)\n+static void show_ru_info(struct repository *repo, struct index_state *istate)\n {\n \tstruct string_list_item *item;\n \n@@ -370,7 +370,7 @@ static void show_ru_info(struct index_state *istate)\n \t\t\tif (!ui->mode[i])\n \t\t\t\tcontinue;\n \t\t\tprintf(\"%s%06o %s %d\\t\", tag_resolve_undo, ui->mode[i],\n-\t\t\t       repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev),\n+\t\t\t       repo_find_unique_abbrev(repo, &ui->oid[i], abbrev),\n \t\t\t       i + 1);\n \t\t\twrite_name(path);\n \t\t}\n@@ -567,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt,\n int cmd_ls_files(int argc,\n \t\t const char **argv,\n \t\t const char *cmd_prefix,\n-\t\t struct repository *repo UNUSED)\n+\t\t struct repository *repo)\n {\n \tint require_work_tree = 0, show_tag = 0, i;\n \tchar *max_prefix;\n@@ -647,15 +647,15 @@ int cmd_ls_files(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t ls_files_usage, builtin_ls_files_options);\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n \tprefix = cmd_prefix;\n \tif (prefix)\n \t\tprefix_len = strlen(prefix);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n-\tif (repo_read_index(the_repository) < 0)\n+\tif (repo_read_index(repo) < 0)\n \t\tdie(\"index file corrupt\");\n \n \targc = parse_options(argc, argv, prefix, builtin_ls_files_options,\n@@ -724,7 +724,7 @@ int cmd_ls_files(int argc,\n \t\tmax_prefix = common_prefix(&pathspec);\n \tmax_prefix_len = get_common_prefix_len(max_prefix);\n \n-\tprune_index(the_repository->index, max_prefix, max_prefix_len);\n+\tprune_index(repo->index, max_prefix, max_prefix_len);\n \n \t/* Treat unmatching pathspec elements as errors */\n \tif (pathspec.nr && error_unmatch)\n@@ -748,13 +748,13 @@ int cmd_ls_files(int argc,\n \t\t */\n \t\tif (show_stage || show_unmerged)\n \t\t\tdie(_(\"options '%s' and '%s' cannot be used together\"), \"ls-files --with-tree\", \"-s/-u\");\n-\t\toverlay_tree_on_index(the_repository->index, with_tree, max_prefix);\n+\t\toverlay_tree_on_index(repo->index, with_tree, max_prefix);\n \t}\n \n-\tshow_files(the_repository, &dir);\n+\tshow_files(repo, &dir);\n \n \tif (show_resolve_undo)\n-\t\tshow_ru_info(the_repository->index);\n+\t\tshow_ru_info(repo, repo->index);\n \n \tif (ps_matched && report_path_error(ps_matched, &pathspec)) {\n \t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\ndiff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh\nindex a1078f8701..4034a5a59f 100755\n--- a/t/t3004-ls-files-basic.sh\n+++ b/t/t3004-ls-files-basic.sh\n@@ -34,6 +34,13 @@ test_expect_success 'ls-files -h in corrupt repository' '\n \ttest_grep \"[Uu]sage: git ls-files \" broken/usage\n '\n \n+test_expect_success 'ls-files does not crash with -h' '\n+\ttest_expect_code 129 git ls-files -h >usage &&\n+\ttest_grep \"[Uu]sage: git ls-files \" usage &&\n+\ttest_expect_code 129 nongit git ls-files -h >usage &&\n+\ttest_grep \"[Uu]sage: git ls-files \" usage\n+'\n+\n test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' '\n \tmkdir subs &&\n \tln -s nosuch link &&\n-- \n2.48.1\n\n"},{"id":"513817","messageId":"20250307233543.1721552-8-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 7/8] builtin/for-each-ref: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:06Z","receivedAt":"2025-03-07T23:36:13Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/for-each-ref.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_for_each_ref()` function with `repo`\nset to NULL and then early in the function, `parse_options()` call will\ngive the options help and exit.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/for-each-ref.c  | 5 ++---\n t/t6300-for-each-ref.sh | 7 +++++++\n 2 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 8085ebd8fe..3d2207ec77 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"commit.h\"\n #include \"config.h\"\n@@ -20,7 +19,7 @@ static char const * const for_each_ref_usage[] = {\n int cmd_for_each_ref(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 \tstruct ref_sorting *sorting;\n \tstruct string_list sorting_options = STRING_LIST_INIT_DUP;\n@@ -63,7 +62,7 @@ int cmd_for_each_ref(int argc,\n \n \tformat.format = \"%(objectname) %(objecttype)\\t%(refname)\";\n \n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \t/* Set default (refname) sorting */\n \tstring_list_append(&sorting_options, \"refname\");\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex a5c7794385..9b4f4306c4 100755\n--- a/t/t6300-for-each-ref.sh\n+++ b/t/t6300-for-each-ref.sh\n@@ -292,6 +292,13 @@ test_expect_success 'Check invalid atoms names are errors' '\n \ttest_must_fail git for-each-ref --format=\"%(INVALID)\" refs/heads\n '\n \n+test_expect_success 'for-each-ref does not crash with -h' '\n+\ttest_expect_code 129 git for-each-ref -h >usage &&\n+\ttest_grep \"[Uu]sage: git for-each-ref \" usage &&\n+\ttest_expect_code 129 nongit git for-each-ref -h >usage &&\n+\ttest_grep \"[Uu]sage: git for-each-ref \" usage\n+'\n+\n test_expect_success 'Check format specifiers are ignored in naming date atoms' '\n \tgit for-each-ref --format=\"%(authordate)\" refs/heads &&\n \tgit for-each-ref --format=\"%(authordate:default) %(authordate)\" refs/heads &&\n-- \n2.48.1\n\n"},{"id":"513818","messageId":"20250307233543.1721552-9-usmanakinyemi202@gmail.com","threadId":"62956","inReplyTo":"20250307233543.1721552-1-usmanakinyemi202@gmail.com","subject":"[PATCH v4 8/8] builtin/checkout-index: stop using `the_repository`","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-03-07T23:35:07Z","receivedAt":"2025-03-07T23:36:16Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"Remove the_repository global variable in favor of the repository\nargument that gets passed in \"builtin/checkout-index.c\".\n\nWhen `-h` is passed to the command outside a Git repository, the\n`run_builtin()` will call the `cmd_checkout_index()` function with `repo`\nset to NULL and then early in the function, `show_usage_with_options_if_asked()`\ncall will give the options help and exit.\n\nPass an instance of \"struct index_state\" available in the calling\ncontext to both `checkout_all()` and `checkout_file()` to remove their\ndependency on the global `the_repository` variable.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>\n---\n builtin/checkout-index.c        | 43 ++++++++++++++++-----------------\n t/t2006-checkout-index-basic.sh |  7 ++++++\n 2 files changed, 28 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex e30086c7d4..7f74bc702f 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -5,7 +5,6 @@\n  *\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -68,10 +67,10 @@ static void write_tempfile_record(const char *name, const char *prefix)\n \t}\n }\n \n-static int checkout_file(const char *name, const char *prefix)\n+static int checkout_file(struct index_state *index, const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = index_name_pos(the_repository->index, name, namelen);\n+\tint pos = index_name_pos(index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -81,8 +80,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos <the_repository->index->cache_nr) {\n-\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n+\twhile (pos < index->cache_nr) {\n+\t\tstruct cache_entry *ce = index->cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -137,13 +136,13 @@ static int checkout_file(const char *name, const char *prefix)\n \treturn -1;\n }\n \n-static int checkout_all(const char *prefix, int prefix_length)\n+static int checkout_all(struct index_state *index, const char *prefix, int prefix_length)\n {\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n-\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n+\tfor (i = 0; i < index->cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = index->cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -156,8 +155,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t * first entry inside the expanded sparse directory).\n \t\t\t */\n \t\t\tif (ignore_skip_worktree) {\n-\t\t\t\tensure_full_index(the_repository->index);\n-\t\t\t\tce = the_repository->index->cache[i];\n+\t\t\t\tensure_full_index(index);\n+\t\t\t\tce = index->cache[i];\n \t\t\t}\n \t\t}\n \n@@ -213,7 +212,7 @@ static int option_parse_stage(const struct option *opt,\n int cmd_checkout_index(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 \tint i;\n \tstruct lock_file lock_file = LOCK_INIT;\n@@ -253,19 +252,19 @@ int cmd_checkout_index(int argc,\n \tshow_usage_with_options_if_asked(argc, argv,\n \t\t\t\t\t builtin_checkout_index_usage,\n \t\t\t\t\t builtin_checkout_index_options);\n-\tgit_config(git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \tprefix_length = prefix ? strlen(prefix) : 0;\n \n-\tprepare_repo_settings(the_repository);\n-\tthe_repository->settings.command_requires_full_index = 0;\n+\tprepare_repo_settings(repo);\n+\trepo->settings.command_requires_full_index = 0;\n \n-\tif (repo_read_index(the_repository) < 0) {\n+\tif (repo_read_index(repo) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n \targc = parse_options(argc, argv, prefix, builtin_checkout_index_options,\n \t\t\tbuiltin_checkout_index_usage, 0);\n-\tstate.istate = the_repository->index;\n+\tstate.istate = repo->index;\n \tstate.force = force;\n \tstate.quiet = quiet;\n \tstate.not_new = not_new;\n@@ -285,8 +284,8 @@ int cmd_checkout_index(int argc,\n \t */\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n-\t\tstate.istate = the_repository->index;\n-\t\trepo_hold_locked_index(the_repository, &lock_file,\n+\t\tstate.istate = repo->index;\n+\t\trepo_hold_locked_index(repo, &lock_file,\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n@@ -304,7 +303,7 @@ int cmd_checkout_index(int argc,\n \t\tif (read_from_stdin)\n \t\t\tdie(\"git checkout-index: don't mix '--stdin' and explicit filenames\");\n \t\tp = prefix_path(prefix, prefix_length, arg);\n-\t\terr |= checkout_file(p, prefix);\n+\t\terr |= checkout_file(repo->index, p, prefix);\n \t\tfree(p);\n \t}\n \n@@ -326,7 +325,7 @@ int cmd_checkout_index(int argc,\n \t\t\t\tstrbuf_swap(&buf, &unquoted);\n \t\t\t}\n \t\t\tp = prefix_path(prefix, prefix_length, buf.buf);\n-\t\t\terr |= checkout_file(p, prefix);\n+\t\t\terr |= checkout_file(repo->index, p, prefix);\n \t\t\tfree(p);\n \t\t}\n \t\tstrbuf_release(&unquoted);\n@@ -334,7 +333,7 @@ int cmd_checkout_index(int argc,\n \t}\n \n \tif (all)\n-\t\terr |= checkout_all(prefix, prefix_length);\n+\t\terr |= checkout_all(repo->index, prefix, prefix_length);\n \n \tif (pc_workers > 1)\n \t\terr |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n@@ -344,7 +343,7 @@ int cmd_checkout_index(int argc,\n \t\treturn 1;\n \n \tif (is_lock_file_locked(&lock_file) &&\n-\t    write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n+\t    write_locked_index(repo->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/t/t2006-checkout-index-basic.sh b/t/t2006-checkout-index-basic.sh\nindex bac231b167..fedd2cc097 100755\n--- a/t/t2006-checkout-index-basic.sh\n+++ b/t/t2006-checkout-index-basic.sh\n@@ -21,6 +21,13 @@ test_expect_success 'checkout-index -h in broken repository' '\n \ttest_grep \"[Uu]sage\" broken/usage\n '\n \n+test_expect_success 'checkout-index does not crash with -h' '\n+\ttest_expect_code 129 git checkout-index -h >usage &&\n+\ttest_grep \"[Uu]sage: git checkout-index \" usage &&\n+\ttest_expect_code 129 nongit git checkout-index -h >usage &&\n+\ttest_grep \"[Uu]sage: git checkout-index \" usage\n+'\n+\n test_expect_success 'checkout-index reports errors (cmdline)' '\n \ttest_must_fail git checkout-index -- does-not-exist 2>stderr &&\n \ttest_grep not.in.the.cache stderr\n-- \n2.48.1\n\n"}]}