{"thread":{"id":"66546","subject":"[Outreachy PATCH] merge: stop using the_repository","startedAt":"2026-10-15T14:25:32Z","lastAt":"2026-11-09T08:17:42Z","messageCount":7,"participants":["Okhuomon Ajayi","Usman Akinyemi","Junio C Hamano","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555146","messageId":"20261015142532.48175-1-okhuomonajayi54@gmail.com","threadId":"66546","inReplyTo":null,"subject":"[Outreachy PATCH] merge: stop using the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-15T14:25:32Z","receivedAt":"2026-10-15T14:25:32Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"try_merge_command() and checkout_fast_forward() already receive a\nrepository, so use it instead of relying on global variables.\n\nAdd a repository parameter to merge_argument() and pass it\nfrom try_merge_command(). Use the repository in\ncheckout_fast_forward() when parsing trees.\n\nRemove the now-unnecessary USE_THE_REPOSITORY_VARIABLE\ndefinition.\n\nSigned-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n---\n merge.c | 16 +++++++---------\n 1 file changed, 7 insertions(+), 9 deletions(-)\n\ndiff --git a/merge.c b/merge.c\nindex 0f5e823e63..85dad63a94 100644\n--- a/merge.c\n+++ b/merge.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n@@ -14,9 +12,9 @@\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n \n-static const char *merge_argument(struct commit *commit)\n+static const char *merge_argument(struct repository *r, struct commit *commit)\n {\n-\treturn oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);\n+\treturn oid_to_hex(commit ? &commit->object.oid : r->hash_algo->empty_tree);\n }\n \n int try_merge_command(struct repository *r,\n@@ -32,11 +30,11 @@ int try_merge_command(struct repository *r,\n \tfor (size_t i = 0; i < xopts_nr; i++)\n \t\tstrvec_pushf(&cmd.args, \"--%s\", xopts[i]);\n \tfor (j = common; j; j = j->next)\n-\t\tstrvec_push(&cmd.args, merge_argument(j->item));\n+\t\tstrvec_push(&cmd.args, merge_argument(r, j->item));\n \tstrvec_push(&cmd.args, \"--\");\n \tstrvec_push(&cmd.args, head_arg);\n \tfor (j = remotes; j; j = j->next)\n-\t\tstrvec_push(&cmd.args, merge_argument(j->item));\n+\t\tstrvec_push(&cmd.args, merge_argument(r, j->item));\n \n \tcmd.git_cmd = 1;\n \tret = run_command(&cmd);\n@@ -68,18 +66,18 @@ int checkout_fast_forward(struct repository *r,\n \tmemset(&trees, 0, sizeof(trees));\n \tmemset(&t, 0, sizeof(t));\n \n-\ttrees[nr_trees] = repo_parse_tree_indirect(the_repository, head);\n+\ttrees[nr_trees] = repo_parse_tree_indirect(r, head);\n \tif (!trees[nr_trees++]) {\n \t\trollback_lock_file(&lock_file);\n \t\treturn -1;\n \t}\n-\ttrees[nr_trees] = repo_parse_tree_indirect(the_repository, remote);\n+\ttrees[nr_trees] = repo_parse_tree_indirect(r, remote);\n \tif (!trees[nr_trees++]) {\n \t\trollback_lock_file(&lock_file);\n \t\treturn -1;\n \t}\n \tfor (i = 0; i < nr_trees; i++) {\n-\t\tif (repo_parse_tree(the_repository, trees[i]) < 0) {\n+\t\tif (repo_parse_tree(r, trees[i]) < 0) {\n \t\t\trollback_lock_file(&lock_file);\n \t\t\treturn -1;\n \t\t}\n-- \n2.54.0\n\n\n"},{"id":"555163","messageId":"CAPSxiM_2Dd86rBKPj7jaT8Wmazo3PFZajJaaL2bVhB1GFsfnbg@mail.gmail.com","threadId":"66546","inReplyTo":"20261015142532.48175-1-okhuomonajayi54@gmail.com","subject":"Re: [Outreachy PATCH] merge: stop using the_repository","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2026-10-15T16:59:20Z","receivedAt":"2026-10-15T16:59:20Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":">\n> try_merge_command() and checkout_fast_forward() already receive a\n> repository, so use it instead of relying on global variables.\n>\n> Add a repository parameter to merge_argument() and pass it\n> from try_merge_command(). Use the repository in\n> checkout_fast_forward() when parsing trees.\n>\n> Remove the now-unnecessary USE_THE_REPOSITORY_VARIABLE\n> definition.\n>\n> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\nGood catch.\n> ---\n>  merge.c | 16 +++++++---------\n>  1 file changed, 7 insertions(+), 9 deletions(-)\n\n> +               strvec_push(&cmd.args, merge_argument(r, j->item));\n>         strvec_push(&cmd.args, \"--\");\n>         strvec_push(&cmd.args, head_arg);\n>         for (j = remotes; j; j = j->next)\n> -               strvec_push(&cmd.args, merge_argument(j->item));\n> +               strvec_push(&cmd.args, merge_argument(r, j->item));\n>\n>         cmd.git_cmd = 1;\n>         ret = run_command(&cmd);\n> @@ -68,18 +66,18 @@ int checkout_fast_forward(struct repository *r,\n>         memset(&trees, 0, sizeof(trees));\n>         memset(&t, 0, sizeof(t));\n>         }\n>         for (i = 0; i < nr_trees; i++) {\n> -               if (repo_parse_tree(the_repository, trees[i]) < 0) {\n> +               if (repo_parse_tree(r, trees[i]) < 0) {\n>                         rollback_lock_file(&lock_file);\n>                         return -1;\n>                 }\n> --\n> 2.54.0\n>\nlooks good to me.\n\n"},{"id":"555172","messageId":"CAFpMFfAZoUgRUqc4xmiqUpPq9pKCe_MtBoPPxkxGO3t=Ux-7Vg@mail.gmail.com","threadId":"66546","inReplyTo":"CAPSxiM_2Dd86rBKPj7jaT8Wmazo3PFZajJaaL2bVhB1GFsfnbg@mail.gmail.com","subject":"Re: [Outreachy PATCH] merge: stop using the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-15T17:20:31Z","receivedAt":"2026-10-15T17:20:31Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"On Thu, Oct 15, 2026 at 5:59 PM Usman Akinyemi\n<usmanakinyemi202@gmail.com> wrote:\n> looks good to me.\n\nThank you\n\n"},{"id":"555186","messageId":"xmqqo6cun53j.fsf@gitster.g","threadId":"66546","inReplyTo":"20261015142532.48175-1-okhuomonajayi54@gmail.com","subject":"Re: [Outreachy PATCH] merge: stop using the_repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-15T19:20:16Z","receivedAt":"2026-10-15T19:20:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:\n\n> try_merge_command() and checkout_fast_forward() already receive a\n> repository, so use it instead of relying on global variables.\n>\n> Add a repository parameter to merge_argument() and pass it\n> from try_merge_command(). Use the repository in\n> checkout_fast_forward() when parsing trees.\n>\n> Remove the now-unnecessary USE_THE_REPOSITORY_VARIABLE\n> definition.\n>\n> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n> ---\n>  merge.c | 16 +++++++---------\n>  1 file changed, 7 insertions(+), 9 deletions(-)\n\n    To: gitster@pobox.com\n    Cc: git@vger.kernel.org, christian.couder@gmail.com, usmanakinyemi202@gmail.com,\n     siddharthasthana31@gmail.com, kaartic.sivaraam@gmail.com, Okhuomon Ajayi\n     <okhuomonajayi54@gmail.com> \n\nPlease do not put me on \"To:\" alone unless the patch has been fully\nreviewed and reviewered acked it.  Placing reviewers on Cc: line (or\nTo: line) as \"area experts\" asking for review is fine, and if the\npatch is in the area where I happen to be an area expert, my address\nmay appear there together with other reviewers, but the default\n\"To:\" address on this list for a brand new patch should be the list\naddress itself.\n\n> diff --git a/merge.c b/merge.c\n> index 0f5e823e63..85dad63a94 100644\n> --- a/merge.c\n> +++ b/merge.c\n> @@ -1,5 +1,3 @@\n> -#define USE_THE_REPOSITORY_VARIABLE\n> -\n>  #include \"git-compat-util.h\"\n>  #include \"gettext.h\"\n>  #include \"hash.h\"\n> @@ -14,9 +12,9 @@\n>  #include \"tree-walk.h\"\n>  #include \"unpack-trees.h\"\n>  \n> -static const char *merge_argument(struct commit *commit)\n> +static const char *merge_argument(struct repository *r, struct commit *commit)\n>  {\n> -\treturn oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);\n> +\treturn oid_to_hex(commit ? &commit->object.oid : r->hash_algo->empty_tree);\n>  }\n>  \n>  int try_merge_command(struct repository *r,\n> @@ -32,11 +30,11 @@ int try_merge_command(struct repository *r,\n>  \tfor (size_t i = 0; i < xopts_nr; i++)\n>  \t\tstrvec_pushf(&cmd.args, \"--%s\", xopts[i]);\n>  \tfor (j = common; j; j = j->next)\n> -\t\tstrvec_push(&cmd.args, merge_argument(j->item));\n> +\t\tstrvec_push(&cmd.args, merge_argument(r, j->item));\n>  \tstrvec_push(&cmd.args, \"--\");\n>  \tstrvec_push(&cmd.args, head_arg);\n>  \tfor (j = remotes; j; j = j->next)\n> -\t\tstrvec_push(&cmd.args, merge_argument(j->item));\n> +\t\tstrvec_push(&cmd.args, merge_argument(r, j->item));\n>  \n>  \tcmd.git_cmd = 1;\n>  \tret = run_command(&cmd);\n> @@ -68,18 +66,18 @@ int checkout_fast_forward(struct repository *r,\n>  \tmemset(&trees, 0, sizeof(trees));\n>  \tmemset(&t, 0, sizeof(t));\n>  \n> -\ttrees[nr_trees] = repo_parse_tree_indirect(the_repository, head);\n> +\ttrees[nr_trees] = repo_parse_tree_indirect(r, head);\n>  \tif (!trees[nr_trees++]) {\n>  \t\trollback_lock_file(&lock_file);\n>  \t\treturn -1;\n>  \t}\n> -\ttrees[nr_trees] = repo_parse_tree_indirect(the_repository, remote);\n> +\ttrees[nr_trees] = repo_parse_tree_indirect(r, remote);\n>  \tif (!trees[nr_trees++]) {\n>  \t\trollback_lock_file(&lock_file);\n>  \t\treturn -1;\n>  \t}\n>  \tfor (i = 0; i < nr_trees; i++) {\n> -\t\tif (repo_parse_tree(the_repository, trees[i]) < 0) {\n> +\t\tif (repo_parse_tree(r, trees[i]) < 0) {\n>  \t\t\trollback_lock_file(&lock_file);\n>  \t\t\treturn -1;\n>  \t\t}\n\n"},{"id":"555189","messageId":"CAFpMFfAg2aMuUsyLz-YZC6T1VXgtBjv75v9hAFzKJVgrBOL2Vw@mail.gmail.com","threadId":"66546","inReplyTo":"xmqqo6cun53j.fsf@gitster.g","subject":"Re: [Outreachy PATCH] merge: stop using the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-15T19:56:41Z","receivedAt":"2026-10-15T19:56:41Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"On Thu, Oct 15, 2026 at 8:20 PM Junio C Hamano <gitster@pobox.com> wrote:\n\n> Please do not put me on \"To:\" alone unless the patch has been fully\n> reviewed and reviewered acked it.  Placing reviewers on Cc: line (or\n> To: line) as \"area experts\" asking for review is fine, and if the\n> patch is in the area where I happen to be an area expert, my address\n> may appear there together with other reviewers, but the default\n> \"To:\" address on this list for a brand new patch should be the list\n> address itself.\n\n\nThanks for pointing that out, i'll address new patches to the list\nfrom now on , with reviewers on the Cc\n\n"},{"id":"557750","messageId":"xmqq33tdcuub.fsf@gitster.g","threadId":"66546","inReplyTo":"CAPSxiM_2Dd86rBKPj7jaT8Wmazo3PFZajJaaL2bVhB1GFsfnbg@mail.gmail.com","subject":"Re: [Outreachy PATCH] merge: stop using the_repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-07T01:07:40Z","receivedAt":"2026-11-07T01:07:40Z","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>>  merge.c | 16 +++++++---------\n>>  1 file changed, 7 insertions(+), 9 deletions(-)\n>\n>> +               strvec_push(&cmd.args, merge_argument(r, j->item));\n>>         strvec_push(&cmd.args, \"--\");\n>>         strvec_push(&cmd.args, head_arg);\n>>         for (j = remotes; j; j = j->next)\n>> -               strvec_push(&cmd.args, merge_argument(j->item));\n>> +               strvec_push(&cmd.args, merge_argument(r, j->item));\n>>\n>>         cmd.git_cmd = 1;\n>>         ret = run_command(&cmd);\n>> @@ -68,18 +66,18 @@ int checkout_fast_forward(struct repository *r,\n>>         memset(&trees, 0, sizeof(trees));\n>>         memset(&t, 0, sizeof(t));\n>>         }\n>>         for (i = 0; i < nr_trees; i++) {\n>> -               if (repo_parse_tree(the_repository, trees[i]) < 0) {\n>> +               if (repo_parse_tree(r, trees[i]) < 0) {\n>>                         rollback_lock_file(&lock_file);\n>>                         return -1;\n>>                 }\n\nThis shows one thing that I really hate about the current\nUSE_THE_REPOSITORY model.\n\nThis function still calls unpack_trees(), which explicitly refers to\nand depends on the_repository.  It is somewhat misleading to claim\nthat merge.c no longer depends on the_repository because of that.\nEven if you pass an arbitrary repository to checkout_fast_forward(),\nthe call would not work as intended because unpack_trees() called by\nit will only work with the_repository under the hood.\n\nYet, this file now compiles without USE_THE_REPOSITORY defined,\ngiving a false sense of achievement.\n\nThe attached patch is what I did while reviewing your patch, trying\nto get unpack_trees.c to compile without USE_THE_REPOSITORY.  This\nwas done on top of 'seen', so it is more of an RFC or technology\ndemonstration than a serious patch to be applied (yet).\n\nNote that I did not say that the patch allows unpack_trees() to work\non a repository other than the_repository.  That is because many\ncode paths called by unpack_trees() may still have hidden, hardcoded\ndependencies on the_repository.\n\nAgain, that is why I really hate the USE_THE_REPOSITORY macro.  It\ndoes not help us measure our progress incrementally.  Perhaps we\ncould hide certain symbols from their header files (like the\nfunctions I converted in this demonstration patch to rid them of\nthe_repository dependency) for those who do not define the macro,\nso we can get a more accurate picture of our progress.  However,\nan earlier attempt to do exactly that on notes-utils.h in\nhttps://lore.kernel.org/git/xmqqjymt94l3.fsf@gitster.g/ was shot\ndown by Patrick, so I am not sure what a good direction would be\nto provide a real incremental progress indicator.\n\nAnyway, provided that we will someday make the functions called by\nthe functions your patch touched to remove the references to\nthe_repository also work on arbitrary repositories (and the attached\npatch could be one of the changes necessary to go there), I think\nyour patch is taking us in a better direction.  Let's mark the topic\nas ready for 'next'.\n\nThanks.\n\n unpack-trees.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++-----------\n 1 file changed, 76 insertions(+), 18 deletions(-)\n\ndiff --git c/unpack-trees.c w/unpack-trees.c\nindex 2e40537dd4..7419793cda 100644\n--- c/unpack-trees.c\n+++ w/unpack-trees.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"git-compat-util.h\"\n@@ -82,6 +81,56 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = {\n \t  ? ((o)->internal.msgs[(type)])      \\\n \t  : (unpack_plumbing_errors[(type)]) )\n \n+\n+/*\n+ * Some functions in these code paths get unpack_trees_options, which\n+ * has up to two istates, and some get an istate.  These istates can\n+ * be used to find the repository to be used for this operation.\n+ *\n+ * As these are all working on the same repository, they must match.\n+ * For now, with a super paranoid check, make sure all potential\n+ * sources of the information match before using it.\n+ *\n+ * Once this proves working well, we could just use the first one we\n+ * find in a production setting.\n+ */\n+static struct repository *unpack_repo(struct index_state *istate,\n+\t\t\t\t      struct unpack_trees_options *o)\n+{\n+\tstruct repository *repo = NULL;\n+\tconst char *camefrom = NULL;\n+\n+\tif (istate) {\n+\t\tif (!istate->repo)\n+\t\t\tBUG(\"istate->repo == NULL\");\n+\t\trepo = istate->repo;\n+\t\tcamefrom = \"istate->repo\";\n+\t}\n+\tif (o) {\n+\t\tif (o->src_index) {\n+\t\t\tif (!o->src_index->repo)\n+\t\t\t\tBUG(\"o->src_index->repo == NULL\");\n+\t\t\tif (repo && repo != o->src_index->repo)\n+\t\t\t\tBUG(\"%s != o->src_index->repo\", camefrom);\n+\t\t\trepo = o->src_index->repo;\n+\t\t\tcamefrom = \"o->src_index->repo\";\n+\t\t}\n+\n+\t\tif (o->dst_index) {\n+\t\t\tif (!o->dst_index->repo)\n+\t\t\t\tBUG(\"o->dst_index->repo == NULL\");\n+\t\t\tif (repo && repo != o->dst_index->repo)\n+\t\t\t\tBUG(\"%s != o->dst_index->repo\", camefrom);\n+\t\t\trepo = o->dst_index->repo;\n+\t\t}\n+\t}\n+\tif (!repo)\n+\t\tBUG(\"no repository for unpack_trees()?\");\n+\treturn repo;\n+\n+}\n+\n+\n static const char *super_prefixed(const char *path, const char *super_prefix)\n {\n \t/*\n@@ -345,15 +394,16 @@ static void load_gitmodules_file(struct index_state *index,\n \t\t\t\t struct checkout *state)\n {\n \tint pos = index_name_pos(index, GITMODULES_FILE, strlen(GITMODULES_FILE));\n+\tstruct repository *repo = unpack_repo(index, NULL);\n \n \tif (pos >= 0) {\n \t\tstruct cache_entry *ce = index->cache[pos];\n \t\tif (!state && ce->ce_flags & CE_WT_REMOVE) {\n-\t\t\trepo_read_gitmodules(the_repository, 0);\n+\t\t\trepo_read_gitmodules(repo, 0);\n \t\t} else if (state && (ce->ce_flags & CE_UPDATE)) {\n-\t\t\tsubmodule_free(the_repository);\n+\t\t\tsubmodule_free(repo);\n \t\t\tcheckout_entry(ce, state, NULL, NULL);\n-\t\t\trepo_read_gitmodules(the_repository, 0);\n+\t\t\trepo_read_gitmodules(repo, 0);\n \t\t}\n \t}\n }\n@@ -362,6 +412,7 @@ static struct progress *get_progress(struct unpack_trees_options *o,\n \t\t\t\t     struct index_state *index)\n {\n \tunsigned cnt = 0, total = 0;\n+\tstruct repository *repo = unpack_repo(index, o);\n \n \tif (!o->update || !o->verbose_update)\n \t\treturn NULL;\n@@ -372,7 +423,7 @@ static struct progress *get_progress(struct unpack_trees_options *o,\n \t\t\ttotal++;\n \t}\n \n-\treturn start_delayed_progress(the_repository,\n+\treturn start_delayed_progress(repo,\n \t\t\t\t      _(\"Updating files\"), total);\n }\n \n@@ -430,6 +481,7 @@ static int check_updates(struct unpack_trees_options *o,\n \tstruct progress *progress;\n \tstruct checkout state = CHECKOUT_INIT;\n \tint i, pc_workers, pc_threshold;\n+\tstruct repository *repo = unpack_repo(index, o);\n \n \ttrace_performance_enter();\n \tstate.super_prefix = o->super_prefix;\n@@ -473,7 +525,7 @@ static int check_updates(struct unpack_trees_options *o,\n \tif (should_update_submodules())\n \t\tload_gitmodules_file(index, &state);\n \n-\tif (repo_has_promisor_remote(the_repository))\n+\tif (repo_has_promisor_remote(repo))\n \t\t/*\n \t\t * Prefetch the objects that are to be checked out in the loop\n \t\t * below.\n@@ -879,6 +931,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,\n \tstruct traverse_info newinfo;\n \tstruct name_entry *p;\n \tint nr_entries;\n+\tstruct repository *repo = unpack_repo(NULL, o);\n \n \tnr_entries = all_trees_same_as_cache_tree(n, dirmask, names, info);\n \tif (nr_entries > 0) {\n@@ -940,7 +993,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,\n \t\t\tconst struct object_id *oid = NULL;\n \t\t\tif (dirmask & 1)\n \t\t\t\toid = &names[i].oid;\n-\t\t\tbuf[nr_buf++] = fill_tree_descriptor(the_repository, t + i, oid);\n+\t\t\tbuf[nr_buf++] = fill_tree_descriptor(repo, t + i, oid);\n \t\t}\n \t}\n \n@@ -1773,24 +1826,25 @@ static int clear_ce_flags(struct index_state *istate,\n \tstatic struct strbuf prefix = STRBUF_INIT;\n \tchar label[100];\n \tint rval;\n+\tstruct repository *repo = unpack_repo(istate, NULL);\n \n \tstrbuf_reset(&prefix);\n \tif (show_progress)\n \t\tistate->progress = start_delayed_progress(\n-\t\t\t\t\tthe_repository,\n+\t\t\t\t\trepo,\n \t\t\t\t\t_(\"Updating index flags\"),\n \t\t\t\t\tistate->cache_nr);\n \n \txsnprintf(label, sizeof(label), \"clear_ce_flags(0x%08lx,0x%08lx)\",\n \t\t  (unsigned long)select_mask, (unsigned long)clear_mask);\n-\ttrace2_region_enter(\"unpack_trees\", label, istate->repo);\n+\ttrace2_region_enter(\"unpack_trees\", label, repo);\n \trval = clear_ce_flags_1(istate,\n \t\t\t\tistate->cache,\n \t\t\t\tistate->cache_nr,\n \t\t\t\t&prefix,\n \t\t\t\tselect_mask, clear_mask,\n \t\t\t\tpl, 0, 0);\n-\ttrace2_region_leave(\"unpack_trees\", label, istate->repo);\n+\ttrace2_region_leave(\"unpack_trees\", label, repo);\n \n \tstop_progress(&istate->progress);\n \treturn rval;\n@@ -1885,13 +1939,13 @@ static int verify_absent(const struct cache_entry *,\n  */\n int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)\n {\n-\tstruct repository *repo = o->src_index->repo;\n+\tstruct repository *repo = unpack_repo(NULL, o);\n \tint i, ret;\n \tstatic struct cache_entry *dfc;\n \tstruct pattern_list pl;\n \tint free_pattern_list = 0;\n \tstruct dir_struct dir = DIR_INIT;\n-\tstruct repo_config_values *cfg = repo_config_values(the_repository);\n+\tstruct repo_config_values *cfg = repo_config_values(repo);\n \n \tif (o->reset == UNPACK_RESET_INVALID)\n \t\tBUG(\"o->reset had a value of 1; should be UNPACK_TREES_*_UNTRACKED\");\n@@ -1936,7 +1990,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \t\tpopulate_from_existing_patterns(o, &pl);\n \t}\n \n-\tindex_state_init(&o->internal.result, o->src_index->repo);\n+\tindex_state_init(&o->internal.result, repo);\n \to->internal.result.initialized = 1;\n \to->internal.result.timestamp.sec = o->src_index->timestamp.sec;\n \to->internal.result.timestamp.nsec = o->src_index->timestamp.nsec;\n@@ -2081,7 +2135,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \t\tmove_index_extensions(&o->internal.result, o->src_index);\n \t\tif (!ret) {\n \t\t\tif (git_env_bool(\"GIT_TEST_CHECK_CACHE_TREE\", 0) &&\n-\t\t\t    cache_tree_verify(the_repository,\n+\t\t\t    cache_tree_verify(repo,\n \t\t\t\t\t      &o->internal.result) < 0) {\n \t\t\t\tret = -1;\n \t\t\t\tgoto done;\n@@ -2137,10 +2191,11 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o,\n \tint i;\n \tunsigned old_show_all_errors;\n \tint free_pattern_list = 0;\n+\tstruct repository *repo = unpack_repo(NULL, o);\n \n \told_show_all_errors = o->internal.show_all_errors;\n \to->internal.show_all_errors = 1;\n-\tindex_state_init(&o->internal.result, o->src_index->repo);\n+\tindex_state_init(&o->internal.result, repo);\n \n \t/* Sanity checks */\n \tif (!o->update || o->index_only || o->skip_sparse_checkout)\n@@ -2333,10 +2388,11 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,\n \tstruct dir_struct d;\n \tchar *pathbuf;\n \tint cnt = 0;\n+\tstruct repository *repo = unpack_repo(NULL, o);\n \n \tif (S_ISGITLINK(ce->ce_mode)) {\n \t\tstruct object_id oid;\n-\t\tint sub_head = repo_resolve_gitlink_ref(the_repository, ce->name,\n+\t\tint sub_head = repo_resolve_gitlink_ref(repo, ce->name,\n \t\t\t\t\t\t\t\"HEAD\", &oid);\n \t\t/*\n \t\t * If we are not going to update the submodule, then\n@@ -2424,6 +2480,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,\n \t\t\t      struct unpack_trees_options *o)\n {\n \tconst struct cache_entry *result;\n+\tstruct repository *repo = unpack_repo(NULL, o);\n \n \t/*\n \t * It may be that the 'lstat()' succeeded even though\n@@ -2432,7 +2489,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,\n \t *\n \t * Ignore that lstat() if it matches.\n \t */\n-\tif (repo_ignore_case(the_repository) && icase_exists(o, name, len, st))\n+\tif (repo_ignore_case(repo) && icase_exists(o, name, len, st))\n \t\treturn 0;\n \n \tif (o->internal.dir &&\n@@ -2652,6 +2709,7 @@ static int merged_sparse_dir(const struct cache_entry * const *src, int n,\n \tvoid * tree_bufs[MAX_UNPACK_TREES + 1];\n \tstruct traverse_info info;\n \tint i, ret;\n+\tstruct repository *repo = unpack_repo(NULL, o);\n \n \t/*\n \t * Create the tree traversal information for traversing into *only* the\n@@ -2665,7 +2723,7 @@ static int merged_sparse_dir(const struct cache_entry * const *src, int n,\n \n \t/* Get the tree descriptors of the sparse directory in each of the merging trees */\n \tfor (i = 0; i < n; i++)\n-\t\ttree_bufs[i] = fill_tree_descriptor(o->src_index->repo, &t[i],\n+\t\ttree_bufs[i] = fill_tree_descriptor(repo, &t[i],\n \t\t\t\t\t\t    src[i] && !is_null_oid(&src[i]->oid) ? &src[i]->oid : NULL);\n \n \tret = traverse_trees(o->src_index, n, t, &info);\n\n\n\n"},{"id":"557898","messageId":"avGBpifgkHQ4L6WZ@pks.im","threadId":"66546","inReplyTo":"xmqq33tdcuub.fsf@gitster.g","subject":"Re: [Outreachy PATCH] merge: stop using the_repository","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-09T08:17:42Z","receivedAt":"2026-11-09T08:17:42Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 06, 2026 at 05:07:40PM -0800, Junio C Hamano wrote:\n> Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n> \n> >>  merge.c | 16 +++++++---------\n> >>  1 file changed, 7 insertions(+), 9 deletions(-)\n> >\n> >> +               strvec_push(&cmd.args, merge_argument(r, j->item));\n> >>         strvec_push(&cmd.args, \"--\");\n> >>         strvec_push(&cmd.args, head_arg);\n> >>         for (j = remotes; j; j = j->next)\n> >> -               strvec_push(&cmd.args, merge_argument(j->item));\n> >> +               strvec_push(&cmd.args, merge_argument(r, j->item));\n> >>\n> >>         cmd.git_cmd = 1;\n> >>         ret = run_command(&cmd);\n> >> @@ -68,18 +66,18 @@ int checkout_fast_forward(struct repository *r,\n> >>         memset(&trees, 0, sizeof(trees));\n> >>         memset(&t, 0, sizeof(t));\n> >>         }\n> >>         for (i = 0; i < nr_trees; i++) {\n> >> -               if (repo_parse_tree(the_repository, trees[i]) < 0) {\n> >> +               if (repo_parse_tree(r, trees[i]) < 0) {\n> >>                         rollback_lock_file(&lock_file);\n> >>                         return -1;\n> >>                 }\n> \n> This shows one thing that I really hate about the current\n> USE_THE_REPOSITORY model.\n> \n> This function still calls unpack_trees(), which explicitly refers to\n> and depends on the_repository.  It is somewhat misleading to claim\n> that merge.c no longer depends on the_repository because of that.\n> Even if you pass an arbitrary repository to checkout_fast_forward(),\n> the call would not work as intended because unpack_trees() called by\n> it will only work with the_repository under the hood.\n> \n> Yet, this file now compiles without USE_THE_REPOSITORY defined,\n> giving a false sense of achievement.\n\nIt _is_ an achievement. That achievement isn't that this file is now\nproperly libified and that it can be used with an arbitrary repo.\nBecause even if the subsystem didn't reference `the_repository` at all\nanymore, \"libification\" to me isn't only about that but also about\nhaving a sane API.\n\nBut it is an achievement because we have one less file to worry about\nwith regards to our end goal of getting rid of `the_repository`, and\nthis file cannot grow new explicit references to it.\n\n[snip]\n> Again, that is why I really hate the USE_THE_REPOSITORY macro.  It\n> does not help us measure our progress incrementally.  Perhaps we\n> could hide certain symbols from their header files (like the\n> functions I converted in this demonstration patch to rid them of\n> the_repository dependency) for those who do not define the macro,\n> so we can get a more accurate picture of our progress.  However,\n> an earlier attempt to do exactly that on notes-utils.h in\n> https://lore.kernel.org/git/xmqqjymt94l3.fsf@gitster.g/ was shot\n> down by Patrick, so I am not sure what a good direction would be\n> to provide a real incremental progress indicator.\n\nThe thing is that no matter what, unless we now start to hide every\nsingle symbol that implicitly references `the_repository`, it will be\nan imperfect measure anyway. And sure, in a perfect world we'd do\nexactly that. But it would result in a ton of churn, and I don't think\nit's easy to get right.\n\nSo from my perspective, the best direction here is \"forward\", because\nthe problem will solve itself automatically once libgit.a does not use\n`the_repository` at all anymore.\n\nPatrick\n\n"}]}