{"thread":{"id":"66797","subject":"[PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","startedAt":"2026-11-07T01:26:52Z","lastAt":"2026-11-11T12:48:48Z","messageCount":15,"participants":["Junio C Hamano","Patrick Steinhardt","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"557751","messageId":"xmqqtsltbfdv.fsf@gitster.g","threadId":"66797","inReplyTo":null,"subject":"[PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-07T01:26:52Z","receivedAt":"2026-11-07T01:26:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This file defines a set of fairly low level functions to implement\nmerge and checkout behaviour, many of which depended on and can only\nwork with the_repository.\n\nTwo key data structures passed around in the code paths, \"struct\nunpack_trees_options\" and \"struct index_state\", both have a pointer\nto the repository instance, and we can use it to make it work on an\narbitrary repository, not just the_repository.\n\nIn any correctly written clients of this library file, the\nrepository instance that is pointed at by these two structs MUST be\nthe same one.  For now, make sure that is the case (and otherwise\nBUG out) by introducing a unpack_repo() helper function that takes\nthese two structures (when available) and returns the repository.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * I wrote this change when I ranted in\n\n   https://lore.kernel.org/git/xmqq33tdcuub.fsf@gitster.g/\n\n   on 'seen', and \"git checkout -m --detach master\" was sufficient\n   to build and start a new branch based on 'master' and there\n   wasn't any need for adjustment.  All tests seem to pass.\n\n unpack-trees.c | 94 ++++++++++++++++++++++++++++++++++++++++----------\n 1 file changed, 76 insertions(+), 18 deletions(-)\n\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex d6a859420f..79341d7fa6 100644\n--- a/unpack-trees.c\n+++ b/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-- \n2.56.0-599-geab4b2c7f0\n\n\n"},{"id":"557752","messageId":"xmqqpkwhbfa1.fsf@gitster.g","threadId":"66797","inReplyTo":"xmqqtsltbfdv.fsf@gitster.g","subject":"[PATCH 2/2] unpack-trees: consistently use \"struct index_state *istate\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-07T01:29:10Z","receivedAt":"2026-11-07T01:29:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"There are some functions that call it index.  Make them consistent.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n * This change is not necessary for functioning of anything, but\n   while writing the previous patch, the inconsistency was\n   irritating enough.\n\n unpack-trees.c | 94 +++++++++++++++++++++++++-------------------------\n 1 file changed, 47 insertions(+), 47 deletions(-)\n\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 79341d7fa6..eedc1ce7a5 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -390,14 +390,14 @@ static int check_submodule_move_head(const struct cache_entry *ce,\n  * (2) before checking out entries to the working tree if the gitmodules file\n  *     has been marked for update.  This situation is specified by 'state' != NULL.\n  */\n-static void load_gitmodules_file(struct index_state *index,\n+static void load_gitmodules_file(struct index_state *istate,\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+\tint pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE));\n+\tstruct repository *repo = unpack_repo(istate, NULL);\n \n \tif (pos >= 0) {\n-\t\tstruct cache_entry *ce = index->cache[pos];\n+\t\tstruct cache_entry *ce = istate->cache[pos];\n \t\tif (!state && ce->ce_flags & CE_WT_REMOVE) {\n \t\t\trepo_read_gitmodules(repo, 0);\n \t\t} else if (state && (ce->ce_flags & CE_UPDATE)) {\n@@ -409,16 +409,16 @@ static void load_gitmodules_file(struct index_state *index,\n }\n \n static struct progress *get_progress(struct unpack_trees_options *o,\n-\t\t\t\t     struct index_state *index)\n+\t\t\t\t     struct index_state *istate)\n {\n \tunsigned cnt = 0, total = 0;\n-\tstruct repository *repo = unpack_repo(index, o);\n+\tstruct repository *repo = unpack_repo(istate, o);\n \n \tif (!o->update || !o->verbose_update)\n \t\treturn NULL;\n \n-\tfor (; cnt < index->cache_nr; cnt++) {\n-\t\tconst struct cache_entry *ce = index->cache[cnt];\n+\tfor (; cnt < istate->cache_nr; cnt++) {\n+\t\tconst struct cache_entry *ce = istate->cache[cnt];\n \t\tif (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))\n \t\t\ttotal++;\n \t}\n@@ -428,22 +428,22 @@ static struct progress *get_progress(struct unpack_trees_options *o,\n }\n \n static void setup_collided_checkout_detection(struct checkout *state,\n-\t\t\t\t\t      struct index_state *index)\n+\t\t\t\t\t      struct index_state *istate)\n {\n \tint i;\n \n \tstate->clone = 1;\n-\tfor (i = 0; i < index->cache_nr; i++)\n-\t\tindex->cache[i]->ce_flags &= ~CE_MATCHED;\n+\tfor (i = 0; i < istate->cache_nr; i++)\n+\t\tistate->cache[i]->ce_flags &= ~CE_MATCHED;\n }\n \n-static void report_collided_checkout(struct index_state *index)\n+static void report_collided_checkout(struct index_state *istate)\n {\n \tstruct string_list list = STRING_LIST_INIT_NODUP;\n \tint i;\n \n-\tfor (i = 0; i < index->cache_nr; i++) {\n-\t\tstruct cache_entry *ce = index->cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = istate->cache[i];\n \n \t\tif (!(ce->ce_flags & CE_MATCHED))\n \t\t\tcontinue;\n@@ -474,33 +474,33 @@ static int must_checkout(const struct cache_entry *ce,\n }\n \n static int check_updates(struct unpack_trees_options *o,\n-\t\t\t struct index_state *index)\n+\t\t\t struct index_state *istate)\n {\n \tunsigned cnt = 0;\n \tint errs = 0;\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+\tstruct repository *repo = unpack_repo(istate, o);\n \n \ttrace_performance_enter();\n \tstate.super_prefix = o->super_prefix;\n \tstate.force = 1;\n \tstate.quiet = 1;\n \tstate.refresh_cache = 1;\n-\tstate.istate = index;\n+\tstate.istate = istate;\n \tclone_checkout_metadata(&state.meta, &o->meta, NULL);\n \n \tif (!o->update || o->dry_run) {\n-\t\tremove_marked_cache_entries(index, 0);\n+\t\tremove_marked_cache_entries(istate, 0);\n \t\ttrace_performance_leave(\"check_updates\");\n \t\treturn 0;\n \t}\n \n \tif (o->clone)\n-\t\tsetup_collided_checkout_detection(&state, index);\n+\t\tsetup_collided_checkout_detection(&state, istate);\n \n-\tprogress = get_progress(o, index);\n+\tprogress = get_progress(o, istate);\n \n \t/* Start with clean cache to avoid using any possibly outdated info. */\n \tinvalidate_lstat_cache();\n@@ -508,10 +508,10 @@ static int check_updates(struct unpack_trees_options *o,\n \tgit_attr_set_direction(GIT_ATTR_CHECKOUT);\n \n \tif (should_update_submodules())\n-\t\tload_gitmodules_file(index, NULL);\n+\t\tload_gitmodules_file(istate, NULL);\n \n-\tfor (i = 0; i < index->cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = index->cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = istate->cache[i];\n \n \t\tif (ce->ce_flags & CE_WT_REMOVE) {\n \t\t\tdisplay_progress(progress, ++cnt);\n@@ -519,26 +519,26 @@ static int check_updates(struct unpack_trees_options *o,\n \t\t}\n \t}\n \n-\tremove_marked_cache_entries(index, 0);\n+\tremove_marked_cache_entries(istate, 0);\n \tremove_scheduled_dirs();\n \n \tif (should_update_submodules())\n-\t\tload_gitmodules_file(index, &state);\n+\t\tload_gitmodules_file(istate, &state);\n \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 \t\t */\n-\t\tprefetch_cache_entries(index, must_checkout, NULL);\n+\t\tprefetch_cache_entries(istate, must_checkout, NULL);\n \n \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\n \n \tenable_delayed_checkout(&state);\n \tif (pc_workers > 1)\n \t\tinit_parallel_checkout();\n-\tfor (i = 0; i < index->cache_nr; i++) {\n-\t\tstruct cache_entry *ce = index->cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = istate->cache[i];\n \n \t\tif (must_checkout(ce, NULL)) {\n \t\t\tsize_t last_pc_queue_size = pc_queue_size();\n@@ -561,7 +561,7 @@ static int check_updates(struct unpack_trees_options *o,\n \tgit_attr_set_direction(GIT_ATTR_CHECKIN);\n \n \tif (o->clone)\n-\t\treport_collided_checkout(index);\n+\t\treport_collided_checkout(istate);\n \n \ttrace_performance_leave(\"check_updates\");\n \treturn errs != 0;\n@@ -678,19 +678,19 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o)\n \t}\n }\n \n-static void mark_all_ce_unused(struct index_state *index)\n+static void mark_all_ce_unused(struct index_state *istate)\n {\n \tint i;\n-\tfor (i = 0; i < index->cache_nr; i++)\n-\t\tindex->cache[i]->ce_flags &= ~(CE_UNPACKED | CE_ADDED | CE_NEW_SKIP_WORKTREE);\n+\tfor (i = 0; i < istate->cache_nr; i++)\n+\t\tistate->cache[i]->ce_flags &= ~(CE_UNPACKED | CE_ADDED | CE_NEW_SKIP_WORKTREE);\n }\n \n static int locate_in_src_index(const struct cache_entry *ce,\n \t\t\t       struct unpack_trees_options *o)\n {\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint len = ce_namelen(ce);\n-\tint pos = index_name_pos(index, ce->name, len);\n+\tint pos = index_name_pos(istate, ce->name, len);\n \tif (pos < 0)\n \t\tpos = -1 - pos;\n \treturn pos;\n@@ -704,12 +704,12 @@ static int locate_in_src_index(const struct cache_entry *ce,\n static void mark_ce_used_same_name(struct cache_entry *ce,\n \t\t\t\t   struct unpack_trees_options *o)\n {\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint len = ce_namelen(ce);\n \tint pos;\n \n-\tfor (pos = locate_in_src_index(ce, o); pos < index->cache_nr; pos++) {\n-\t\tstruct cache_entry *next = index->cache[pos];\n+\tfor (pos = locate_in_src_index(ce, o); pos < istate->cache_nr; pos++) {\n+\t\tstruct cache_entry *next = istate->cache[pos];\n \t\tif (len != ce_namelen(next) ||\n \t\t    memcmp(ce->name, next->name, len))\n \t\t\tbreak;\n@@ -719,11 +719,11 @@ static void mark_ce_used_same_name(struct cache_entry *ce,\n \n static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)\n {\n-\tconst struct index_state *index = o->src_index;\n+\tconst struct index_state *istate = o->src_index;\n \tint pos = o->internal.cache_bottom;\n \n-\twhile (pos < index->cache_nr) {\n-\t\tstruct cache_entry *ce = index->cache[pos];\n+\twhile (pos < istate->cache_nr) {\n+\t\tstruct cache_entry *ce = istate->cache[pos];\n \t\tif (!(ce->ce_flags & CE_UNPACKED)) {\n \t\t\to->internal.cache_bottom = pos;\n \t\t\treturn ce;\n@@ -736,14 +736,14 @@ static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)\n static void add_same_unmerged(const struct cache_entry *ce,\n \t\t\t      struct unpack_trees_options *o)\n {\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint len = ce_namelen(ce);\n-\tint pos = index_name_pos(index, ce->name, len);\n+\tint pos = index_name_pos(istate, ce->name, len);\n \n \tif (0 <= pos)\n \t\tdie(\"programming error in a caller of mark_ce_used_same_name\");\n-\tfor (pos = -pos - 1; pos < index->cache_nr; pos++) {\n-\t\tstruct cache_entry *next = index->cache[pos];\n+\tfor (pos = -pos - 1; pos < istate->cache_nr; pos++) {\n+\t\tstruct cache_entry *next = istate->cache[pos];\n \t\tif (len != ce_namelen(next) ||\n \t\t    memcmp(ce->name, next->name, len))\n \t\t\tbreak;\n@@ -1335,11 +1335,11 @@ static int find_cache_pos(struct traverse_info *info,\n {\n \tint pos;\n \tstruct unpack_trees_options *o = info->data;\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint pfxlen = info->pathlen;\n \n-\tfor (pos = o->internal.cache_bottom; pos < index->cache_nr; pos++) {\n-\t\tconst struct cache_entry *ce = index->cache[pos];\n+\tfor (pos = o->internal.cache_bottom; pos < istate->cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = istate->cache[pos];\n \t\tconst char *ce_name, *ce_slash;\n \t\tint cmp, ce_len;\n \n-- \n2.56.0-599-geab4b2c7f0\n\n\n"},{"id":"557936","messageId":"avHNf-aaxdsyim7g@pks.im","threadId":"66797","inReplyTo":"xmqqtsltbfdv.fsf@gitster.g","subject":"Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-09T13:41:19Z","receivedAt":"2026-11-09T13:41:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 06, 2026 at 05:26:52PM -0800, Junio C Hamano wrote:\n> This file defines a set of fairly low level functions to implement\n> merge and checkout behaviour, many of which depended on and can only\n> work with the_repository.\n> \n> Two key data structures passed around in the code paths, \"struct\n> unpack_trees_options\" and \"struct index_state\", both have a pointer\n> to the repository instance, and we can use it to make it work on an\n> arbitrary repository, not just the_repository.\n\nOkay.\n\n> In any correctly written clients of this library file, the\n> repository instance that is pointed at by these two structs MUST be\n> the same one.  For now, make sure that is the case (and otherwise\n> BUG out) by introducing a unpack_repo() helper function that takes\n> these two structures (when available) and returns the repository.\n\nFair. It's a bit curious of an interface to have this kind of ambiguity.\nBut as an intermediate step I think the proposed solution is okayish,\nand I do like that we at least verify that it's the same repository.\n\n> diff --git a/unpack-trees.c b/unpack-trees.c\n> index d6a859420f..79341d7fa6 100644\n> --- a/unpack-trees.c\n> +++ b/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\nSo this overall surprisingly complex, but I think it's sensible to be\ndefensive.\n\n> +\n> +\n\nNit: two empty lines.\n\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\nThis conversion here raises the question what we want to do in the case\nwhere the caller has both structures available, but we don't end up\npassing them to the pointer. This could in theory hide a bug where we\nhave mismatching repositories when the entry points don't verify that\nproperty.\n\nI guess that's ultimately not much of a problem. But an alternative take\ncould ensure the propert only at the borders of this subsystem, so any\nexternally-visible function. And internally, we'd then only ever pass\naround a repository.\n\nBut in the end I don't really think this matters much, so please only\ntake this as me thinking out loud.\n\nPatrick\n\n"},{"id":"557939","messageId":"784778b3-173d-4226-ae9e-4efcd4f556af@gmail.com","threadId":"66797","inReplyTo":"xmqqtsltbfdv.fsf@gitster.g","subject":"Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-11-09T13:45:19Z","receivedAt":"2026-11-09T13:45:19Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/6/2026 8:26 PM, Junio C Hamano wrote:\n> This file defines a set of fairly low level functions to implement\n> merge and checkout behaviour, many of which depended on and can only\n> work with the_repository.\n> \n> Two key data structures passed around in the code paths, \"struct\n> unpack_trees_options\" and \"struct index_state\", both have a pointer\n> to the repository instance, and we can use it to make it work on an\n> arbitrary repository, not just the_repository.\n> \n> In any correctly written clients of this library file, the\n> repository instance that is pointed at by these two structs MUST be\n> the same one.  For now, make sure that is the case (and otherwise\n> BUG out) by introducing a unpack_repo() helper function that takes\n> these two structures (when available) and returns the repository.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>  * I wrote this change when I ranted in\n> \n>    https://lore.kernel.org/git/xmqq33tdcuub.fsf@gitster.g/\n> \n>    on 'seen', and \"git checkout -m --detach master\" was sufficient\n>    to build and start a new branch based on 'master' and there\n>    wasn't any need for adjustment.  All tests seem to pass.\n> \n>  unpack-trees.c | 94 ++++++++++++++++++++++++++++++++++++++++----------\n>  1 file changed, 76 insertions(+), 18 deletions(-)\n> \n> diff --git a/unpack-trees.c b/unpack-trees.c\n> index d6a859420f..79341d7fa6 100644\n> --- a/unpack-trees.c\n> +++ b/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;\nOverall, this is a good helper implementation.\n\n> +\tif (!repo)\n> +\t\tBUG(\"no repository for unpack_trees()?\");\n> +\treturn repo;\n> +\n> +}\n\nnit: extra empty line.\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\nThis sample of how it is used makes it clear how this is a\nvaluable abstraction.\n\nThanks,\n-Stolee\n\n\n\n"},{"id":"557940","messageId":"b3004724-3ed6-4b41-8b3f-eaa19a09394d@gmail.com","threadId":"66797","inReplyTo":"xmqqpkwhbfa1.fsf@gitster.g","subject":"Re: [PATCH 2/2] unpack-trees: consistently use \"struct index_state *istate\"","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-11-09T13:46:45Z","receivedAt":"2026-11-09T13:46:45Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/6/2026 8:29 PM, Junio C Hamano wrote:\n> There are some functions that call it index.  Make them consistent.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  * This change is not necessary for functioning of anything, but\n>    while writing the previous patch, the inconsistency was\n>    irritating enough.\nI agree that making this consistent will help a lot when mutating\nthe code in the future. Doing this cleanup next to the_repository\ncleanup makes sense.\n\nThanks,\n-Stolee\n\n\n"},{"id":"557980","messageId":"xmqqecctzttt.fsf@gitster.g","threadId":"66797","inReplyTo":"avHNf-aaxdsyim7g@pks.im","subject":"Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T19:30:06Z","receivedAt":"2026-11-09T19:30:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> In any correctly written clients of this library file, the\n>> repository instance that is pointed at by these two structs MUST be\n>> the same one.  For now, make sure that is the case (and otherwise\n>> BUG out) by introducing a unpack_repo() helper function that takes\n>> these two structures (when available) and returns the repository.\n>\n> Fair. It's a bit curious of an interface to have this kind of ambiguity.\n> But as an intermediate step I think the proposed solution is okayish,\n> and I do like that we at least verify that it's the same repository.\n\nYeah, while I am reasonably sure that all three (when they exist)\nmust always be pointing at the same repository, I may have missed a\nlegitimate use case where that assumption does not hold.  And that\nis why the initial implementation is checking them with paranoia to\neasily detect cases that I missed.\n\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> So this overall surprisingly complex, but I think it's sensible to be\n> defensive.\n\nYes, we could do\n\n\tif (istate && istate->repo)\n\t\treturn itate->repo;\n\tif (o && o->src_index && o->src_index->repo)\n\t\treturn o->src_index->repo;\n\tif (o && o->dst_index && o->dst_index->repo)\n\t\treturn o->dst_index->repo;\n\tBUG();\n\nbut then you'd need to start a debugger to tell which assumption was\nviolated.\n\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> This conversion here raises the question what we want to do in the case\n> where the caller has both structures available, but we don't end up\n> passing them to the pointer. This could in theory hide a bug where we\n> have mismatching repositories when the entry points don't verify that\n> property.\n\nPuzzled.  Here we do have an istate but have no unpack_trees_options\navailable, so it is natural to pass NULL for the latter to tell the\nvalidator \"we do not have unpack_trees_options\".  Are you worried\nabout a case where a programmer who writes an unpack_repo() call\npasses NULL by mistake efven when istate or unpack_trees_options are\navailable?\n\nThanks.\n\n"},{"id":"557991","messageId":"20261109205438.369060-1-gitster@pobox.com","threadId":"66797","inReplyTo":"xmqqtsltbfdv.fsf@gitster.g","subject":"[PATCH v2 0/2] unpack-trees.c w/o the_repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T20:54:35Z","receivedAt":"2026-11-09T20:54:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"unpack_trees() API serves as low-level functions to implement merge\nand checkout.  It heavily relies on the_repository, making it clear\nit only works with that repository instance.  We however can use the\nrepository instance pointed at by key data structures passed\nthroughout the callchain.\n\nThis is almost the exact copy of what I have at \n\n    https://lore.kernel.org/git/xmqqtsltbfdv.fsf@gitster.g/\n\nThe only changes since that version are removals of two blank lines.\n\n 1/2: unpack-trees: lose USE_THE_REPOSITORY\n 2/2: unpack-trees: consistently use \"struct index_state *istate\"\n\n unpack-trees.c | 180 ++++++++++++++++++++++++++++++++-----------------\n 1 file changed, 118 insertions(+), 62 deletions(-)\n\n-- \n2.56.0-626-gaba6dc7e00\n\n\n"},{"id":"557992","messageId":"20261109205438.369060-2-gitster@pobox.com","threadId":"66797","inReplyTo":"20261109205438.369060-1-gitster@pobox.com","subject":"[PATCH v2 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T20:54:36Z","receivedAt":"2026-11-09T20:54:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This file defines a set of fairly low level functions to implement\nmerge and checkout behaviour, many of which depended on and can only\nwork with the_repository.\n\nTwo key data structures passed around in the code paths, \"struct\nunpack_trees_options\" and \"struct index_state\", both have a pointer\nto the repository instance, and we can use it to make it work on an\narbitrary repository, not just the_repository.\n\nIn any correctly written clients of this library file, the\nrepository instance that is pointed at by these two structs MUST be\nthe same one.  For now, make sure that is the case (and otherwise\nBUG out) by introducing a unpack_repo() helper function that takes\nthese two structures (when available) and returns the repository.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n unpack-trees.c | 92 ++++++++++++++++++++++++++++++++++++++++----------\n 1 file changed, 74 insertions(+), 18 deletions(-)\n\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 1802809ad3..a1f7d8bd6a 100644\n--- a/unpack-trees.c\n+++ b/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,54 @@ 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 static const char *super_prefixed(const char *path, const char *super_prefix)\n {\n \t/*\n@@ -345,15 +392,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 +410,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 +421,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 +479,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 +523,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 +929,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 +991,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 +1824,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 +1937,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 +1988,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@@ -2080,7 +2132,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@@ -2136,10 +2188,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@@ -2332,10 +2385,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@@ -2423,6 +2477,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@@ -2431,7 +2486,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@@ -2651,6 +2706,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@@ -2664,7 +2720,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-- \n2.56.0-626-gaba6dc7e00\n\n\n"},{"id":"557993","messageId":"20261109205438.369060-3-gitster@pobox.com","threadId":"66797","inReplyTo":"20261109205438.369060-1-gitster@pobox.com","subject":"[PATCH v2 2/2] unpack-trees: consistently use \"struct index_state *istate\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T20:54:37Z","receivedAt":"2026-11-09T20:54:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"There are some functions that call it index.  Make them consistent.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n unpack-trees.c | 94 +++++++++++++++++++++++++-------------------------\n 1 file changed, 47 insertions(+), 47 deletions(-)\n\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex a1f7d8bd6a..0d00f6120a 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -388,14 +388,14 @@ static int check_submodule_move_head(const struct cache_entry *ce,\n  * (2) before checking out entries to the working tree if the gitmodules file\n  *     has been marked for update.  This situation is specified by 'state' != NULL.\n  */\n-static void load_gitmodules_file(struct index_state *index,\n+static void load_gitmodules_file(struct index_state *istate,\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+\tint pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE));\n+\tstruct repository *repo = unpack_repo(istate, NULL);\n \n \tif (pos >= 0) {\n-\t\tstruct cache_entry *ce = index->cache[pos];\n+\t\tstruct cache_entry *ce = istate->cache[pos];\n \t\tif (!state && ce->ce_flags & CE_WT_REMOVE) {\n \t\t\trepo_read_gitmodules(repo, 0);\n \t\t} else if (state && (ce->ce_flags & CE_UPDATE)) {\n@@ -407,16 +407,16 @@ static void load_gitmodules_file(struct index_state *index,\n }\n \n static struct progress *get_progress(struct unpack_trees_options *o,\n-\t\t\t\t     struct index_state *index)\n+\t\t\t\t     struct index_state *istate)\n {\n \tunsigned cnt = 0, total = 0;\n-\tstruct repository *repo = unpack_repo(index, o);\n+\tstruct repository *repo = unpack_repo(istate, o);\n \n \tif (!o->update || !o->verbose_update)\n \t\treturn NULL;\n \n-\tfor (; cnt < index->cache_nr; cnt++) {\n-\t\tconst struct cache_entry *ce = index->cache[cnt];\n+\tfor (; cnt < istate->cache_nr; cnt++) {\n+\t\tconst struct cache_entry *ce = istate->cache[cnt];\n \t\tif (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))\n \t\t\ttotal++;\n \t}\n@@ -426,22 +426,22 @@ static struct progress *get_progress(struct unpack_trees_options *o,\n }\n \n static void setup_collided_checkout_detection(struct checkout *state,\n-\t\t\t\t\t      struct index_state *index)\n+\t\t\t\t\t      struct index_state *istate)\n {\n \tint i;\n \n \tstate->clone = 1;\n-\tfor (i = 0; i < index->cache_nr; i++)\n-\t\tindex->cache[i]->ce_flags &= ~CE_MATCHED;\n+\tfor (i = 0; i < istate->cache_nr; i++)\n+\t\tistate->cache[i]->ce_flags &= ~CE_MATCHED;\n }\n \n-static void report_collided_checkout(struct index_state *index)\n+static void report_collided_checkout(struct index_state *istate)\n {\n \tstruct string_list list = STRING_LIST_INIT_NODUP;\n \tint i;\n \n-\tfor (i = 0; i < index->cache_nr; i++) {\n-\t\tstruct cache_entry *ce = index->cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = istate->cache[i];\n \n \t\tif (!(ce->ce_flags & CE_MATCHED))\n \t\t\tcontinue;\n@@ -472,33 +472,33 @@ static int must_checkout(const struct cache_entry *ce,\n }\n \n static int check_updates(struct unpack_trees_options *o,\n-\t\t\t struct index_state *index)\n+\t\t\t struct index_state *istate)\n {\n \tunsigned cnt = 0;\n \tint errs = 0;\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+\tstruct repository *repo = unpack_repo(istate, o);\n \n \ttrace_performance_enter();\n \tstate.super_prefix = o->super_prefix;\n \tstate.force = 1;\n \tstate.quiet = 1;\n \tstate.refresh_cache = 1;\n-\tstate.istate = index;\n+\tstate.istate = istate;\n \tclone_checkout_metadata(&state.meta, &o->meta, NULL);\n \n \tif (!o->update || o->dry_run) {\n-\t\tremove_marked_cache_entries(index, 0);\n+\t\tremove_marked_cache_entries(istate, 0);\n \t\ttrace_performance_leave(\"check_updates\");\n \t\treturn 0;\n \t}\n \n \tif (o->clone)\n-\t\tsetup_collided_checkout_detection(&state, index);\n+\t\tsetup_collided_checkout_detection(&state, istate);\n \n-\tprogress = get_progress(o, index);\n+\tprogress = get_progress(o, istate);\n \n \t/* Start with clean cache to avoid using any possibly outdated info. */\n \tinvalidate_lstat_cache();\n@@ -506,10 +506,10 @@ static int check_updates(struct unpack_trees_options *o,\n \tgit_attr_set_direction(GIT_ATTR_CHECKOUT);\n \n \tif (should_update_submodules())\n-\t\tload_gitmodules_file(index, NULL);\n+\t\tload_gitmodules_file(istate, NULL);\n \n-\tfor (i = 0; i < index->cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = index->cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = istate->cache[i];\n \n \t\tif (ce->ce_flags & CE_WT_REMOVE) {\n \t\t\tdisplay_progress(progress, ++cnt);\n@@ -517,26 +517,26 @@ static int check_updates(struct unpack_trees_options *o,\n \t\t}\n \t}\n \n-\tremove_marked_cache_entries(index, 0);\n+\tremove_marked_cache_entries(istate, 0);\n \tremove_scheduled_dirs();\n \n \tif (should_update_submodules())\n-\t\tload_gitmodules_file(index, &state);\n+\t\tload_gitmodules_file(istate, &state);\n \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 \t\t */\n-\t\tprefetch_cache_entries(index, must_checkout, NULL);\n+\t\tprefetch_cache_entries(istate, must_checkout, NULL);\n \n \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\n \n \tenable_delayed_checkout(&state);\n \tif (pc_workers > 1)\n \t\tinit_parallel_checkout();\n-\tfor (i = 0; i < index->cache_nr; i++) {\n-\t\tstruct cache_entry *ce = index->cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = istate->cache[i];\n \n \t\tif (must_checkout(ce, NULL)) {\n \t\t\tsize_t last_pc_queue_size = pc_queue_size();\n@@ -559,7 +559,7 @@ static int check_updates(struct unpack_trees_options *o,\n \tgit_attr_set_direction(GIT_ATTR_CHECKIN);\n \n \tif (o->clone)\n-\t\treport_collided_checkout(index);\n+\t\treport_collided_checkout(istate);\n \n \ttrace_performance_leave(\"check_updates\");\n \treturn errs != 0;\n@@ -676,19 +676,19 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o)\n \t}\n }\n \n-static void mark_all_ce_unused(struct index_state *index)\n+static void mark_all_ce_unused(struct index_state *istate)\n {\n \tint i;\n-\tfor (i = 0; i < index->cache_nr; i++)\n-\t\tindex->cache[i]->ce_flags &= ~(CE_UNPACKED | CE_ADDED | CE_NEW_SKIP_WORKTREE);\n+\tfor (i = 0; i < istate->cache_nr; i++)\n+\t\tistate->cache[i]->ce_flags &= ~(CE_UNPACKED | CE_ADDED | CE_NEW_SKIP_WORKTREE);\n }\n \n static int locate_in_src_index(const struct cache_entry *ce,\n \t\t\t       struct unpack_trees_options *o)\n {\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint len = ce_namelen(ce);\n-\tint pos = index_name_pos(index, ce->name, len);\n+\tint pos = index_name_pos(istate, ce->name, len);\n \tif (pos < 0)\n \t\tpos = -1 - pos;\n \treturn pos;\n@@ -702,12 +702,12 @@ static int locate_in_src_index(const struct cache_entry *ce,\n static void mark_ce_used_same_name(struct cache_entry *ce,\n \t\t\t\t   struct unpack_trees_options *o)\n {\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint len = ce_namelen(ce);\n \tint pos;\n \n-\tfor (pos = locate_in_src_index(ce, o); pos < index->cache_nr; pos++) {\n-\t\tstruct cache_entry *next = index->cache[pos];\n+\tfor (pos = locate_in_src_index(ce, o); pos < istate->cache_nr; pos++) {\n+\t\tstruct cache_entry *next = istate->cache[pos];\n \t\tif (len != ce_namelen(next) ||\n \t\t    memcmp(ce->name, next->name, len))\n \t\t\tbreak;\n@@ -717,11 +717,11 @@ static void mark_ce_used_same_name(struct cache_entry *ce,\n \n static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)\n {\n-\tconst struct index_state *index = o->src_index;\n+\tconst struct index_state *istate = o->src_index;\n \tint pos = o->internal.cache_bottom;\n \n-\twhile (pos < index->cache_nr) {\n-\t\tstruct cache_entry *ce = index->cache[pos];\n+\twhile (pos < istate->cache_nr) {\n+\t\tstruct cache_entry *ce = istate->cache[pos];\n \t\tif (!(ce->ce_flags & CE_UNPACKED)) {\n \t\t\to->internal.cache_bottom = pos;\n \t\t\treturn ce;\n@@ -734,14 +734,14 @@ static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)\n static void add_same_unmerged(const struct cache_entry *ce,\n \t\t\t      struct unpack_trees_options *o)\n {\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint len = ce_namelen(ce);\n-\tint pos = index_name_pos(index, ce->name, len);\n+\tint pos = index_name_pos(istate, ce->name, len);\n \n \tif (0 <= pos)\n \t\tdie(\"programming error in a caller of mark_ce_used_same_name\");\n-\tfor (pos = -pos - 1; pos < index->cache_nr; pos++) {\n-\t\tstruct cache_entry *next = index->cache[pos];\n+\tfor (pos = -pos - 1; pos < istate->cache_nr; pos++) {\n+\t\tstruct cache_entry *next = istate->cache[pos];\n \t\tif (len != ce_namelen(next) ||\n \t\t    memcmp(ce->name, next->name, len))\n \t\t\tbreak;\n@@ -1333,11 +1333,11 @@ static int find_cache_pos(struct traverse_info *info,\n {\n \tint pos;\n \tstruct unpack_trees_options *o = info->data;\n-\tstruct index_state *index = o->src_index;\n+\tstruct index_state *istate = o->src_index;\n \tint pfxlen = info->pathlen;\n \n-\tfor (pos = o->internal.cache_bottom; pos < index->cache_nr; pos++) {\n-\t\tconst struct cache_entry *ce = index->cache[pos];\n+\tfor (pos = o->internal.cache_bottom; pos < istate->cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = istate->cache[pos];\n \t\tconst char *ce_name, *ce_slash;\n \t\tint cmp, ce_len;\n \n-- \n2.56.0-626-gaba6dc7e00\n\n\n"},{"id":"558026","messageId":"avLCDTHuScp4iLyj@pks.im","threadId":"66797","inReplyTo":"xmqqecctzttt.fsf@gitster.g","subject":"Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-10T07:04:45Z","receivedAt":"2026-11-10T07:04:45Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 09, 2026 at 11:30:06AM -0800, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\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> > This conversion here raises the question what we want to do in the case\n> > where the caller has both structures available, but we don't end up\n> > passing them to the pointer. This could in theory hide a bug where we\n> > have mismatching repositories when the entry points don't verify that\n> > property.\n> \n> Puzzled.  Here we do have an istate but have no unpack_trees_options\n> available, so it is natural to pass NULL for the latter to tell the\n> validator \"we do not have unpack_trees_options\".\n\nIt is natural, but the calling context _does_ have options available.\nIt's just that the caller of this function here decided to not pass it\ndown because we previously didn't need it. In fact, every new callsite\nof `unpack_repo()` does have options available in their call stack.\n\n> Are you worried about a case where a programmer who writes an\n> unpack_repo() call passes NULL by mistake efven when istate or\n> unpack_trees_options are available?\n\nAll I'm pointing out is that there are cases where we could be as\ndefensive as everywhere else if we started passing down the options to\ncalling contexts that don't have it yet. I wouldn't say I'm \"worried\"\nthough. The proposed patch is very defensive overall, and I'm not overly\nconcerned about us missing that defense in some cases.\n\nPatrick\n\n"},{"id":"558080","messageId":"37267fd4-c565-4559-9c5c-01d58cd0426d@gmail.com","threadId":"66797","inReplyTo":"20261109205438.369060-1-gitster@pobox.com","subject":"Re: [PATCH v2 0/2] unpack-trees.c w/o the_repository","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-11-10T13:22:26Z","receivedAt":"2026-11-10T13:22:26Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/9/2026 3:54 PM, Junio C Hamano wrote:\n> unpack_trees() API serves as low-level functions to implement merge\n> and checkout.  It heavily relies on the_repository, making it clear\n> it only works with that repository instance.  We however can use the\n> repository instance pointed at by key data structures passed\n> throughout the callchain.\n> \n> This is almost the exact copy of what I have at \n> \n>     https://lore.kernel.org/git/xmqqtsltbfdv.fsf@gitster.g/\n> \n> The only changes since that version are removals of two blank lines.\nLGTM.\n\nThanks,\n-Stolee\n\n\n"},{"id":"558104","messageId":"xmqqse18u0jw.fsf@gitster.g","threadId":"66797","inReplyTo":"avLCDTHuScp4iLyj@pks.im","subject":"Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-10T16:13:39Z","receivedAt":"2026-11-10T16:13:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> All I'm pointing out is that there are cases where we could be as\n> defensive as everywhere else if we started passing down the options to\n> calling contexts that don't have it yet.\n\nOK, that does make sense, but I suspect the current helper functions\nthat do not get unpack_opt do not because they do not have a reason\nto access anything in it.  We could throw \"struct repository *\" into\nthat struct and use that one (ignoring the one in the istates).\n\nI however think that would be a separate clean-up.\n\nThanks.\n\n"},{"id":"558105","messageId":"avNI9rHN3GS7Kmlz@pks.im","threadId":"66797","inReplyTo":"xmqqse18u0jw.fsf@gitster.g","subject":"Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-10T16:40:22Z","receivedAt":"2026-11-10T16:40:22Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Nov 10, 2026 at 08:13:39AM -0800, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > All I'm pointing out is that there are cases where we could be as\n> > defensive as everywhere else if we started passing down the options to\n> > calling contexts that don't have it yet.\n> \n> OK, that does make sense, but I suspect the current helper functions\n> that do not get unpack_opt do not because they do not have a reason\n> to access anything in it.  We could throw \"struct repository *\" into\n> that struct and use that one (ignoring the one in the istates).\n> \n> I however think that would be a separate clean-up.\n\nYup, that's reasonable. Thanks!\n\nPatrick\n\n"},{"id":"558118","messageId":"xmqq4idotx2g.fsf@gitster.g","threadId":"66797","inReplyTo":"37267fd4-c565-4559-9c5c-01d58cd0426d@gmail.com","subject":"Re: [PATCH v2 0/2] unpack-trees.c w/o the_repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-10T17:28:55Z","receivedAt":"2026-11-10T17:28:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <stolee@gmail.com> writes:\n\n> On 11/9/2026 3:54 PM, Junio C Hamano wrote:\n>> unpack_trees() API serves as low-level functions to implement merge\n>> and checkout.  It heavily relies on the_repository, making it clear\n>> it only works with that repository instance.  We however can use the\n>> repository instance pointed at by key data structures passed\n>> throughout the callchain.\n>> \n>> This is almost the exact copy of what I have at \n>> \n>>     https://lore.kernel.org/git/xmqqtsltbfdv.fsf@gitster.g/\n>> \n>> The only changes since that version are removals of two blank lines.\n> LGTM.\n>\n> Thanks,\n> -Stolee\n\nThanks.\n\n"},{"id":"558201","messageId":"avRkMPUmkqoCGmQC@pks.im","threadId":"66797","inReplyTo":"37267fd4-c565-4559-9c5c-01d58cd0426d@gmail.com","subject":"Re: [PATCH v2 0/2] unpack-trees.c w/o the_repository","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:48:48Z","receivedAt":"2026-11-11T12:48:48Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Nov 10, 2026 at 08:22:26AM -0500, Derrick Stolee wrote:\n> On 11/9/2026 3:54 PM, Junio C Hamano wrote:\n> > unpack_trees() API serves as low-level functions to implement merge\n> > and checkout.  It heavily relies on the_repository, making it clear\n> > it only works with that repository instance.  We however can use the\n> > repository instance pointed at by key data structures passed\n> > throughout the callchain.\n> > \n> > This is almost the exact copy of what I have at \n> > \n> >     https://lore.kernel.org/git/xmqqtsltbfdv.fsf@gitster.g/\n> > \n> > The only changes since that version are removals of two blank lines.\n> LGTM.\n\nLikewise, I'm happy with this version. Thanks!\n\nPatrick\n\n"}]}