git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 05/13] setup: introduce explicit repository discovery

From
Toon Claes <toon@iotcl.com>
Date
Jul 8, 2026, 09:32 UTC
Message-ID
<87ldblomh3.fsf@emacs.iotcl.com>
In-Reply-To
<20260707-pks-setup-split-discovery-and-setup-v2-5-aab372cd227c@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 49 quoted lines
> When setting up the global repository we intermix repository discovery
> and repository configuration: we repeatedly call `set_git_work_tree()`
> and `apply_and_export_relative_gitdir()` until we're happy with the
> result. The result of this is then a partially-configured repository
> that we use for further setup.
>
> This process is quite hard to follow, as it's never quite clear which
> parts of the repository have been configured already and which haven't.
> Furthermore, it means that the repository configuration is distributed
> across many different places instead of having it neatly contained in a
> single location. Ultimately, this is the reason that we cannot use a
> central function like `repo_init()`.
>
> Refactor the logic so that we stop partially-configuring a repository
> and instead populate a new `struct repo_discovery`. This allow us to
> essentially split repository setup into two phases:
>
>   - The first phase only figures out parameters required to configure
>     the repository.
>
>   - The second phase then takes these parameters and applies them to the
>     repository.
>
> Like this, we'll never end up with a partially-configured repository and
> can eventually extend `repo_init()` to handle the full initialization
> for us.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  setup.c | 155 ++++++++++++++++++++++++++++++++++++++++------------------------
>  1 file changed, 98 insertions(+), 57 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 324a235dd1..f713d024f7 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -1090,14 +1090,47 @@ static void apply_and_export_relative_gitdir(struct repository *repo, const char
>  	strbuf_release(&realpath);
>  }
>  
> -static const char *setup_explicit_git_dir(struct repository *repo,
> -					  const char *gitdirenv,
> -					  struct strbuf *cwd,
> -					  struct repository_format *repo_fmt,
> -					  int *nongit_ok)
> +struct repo_discovery {
> +	char *gitdir;
> +	char *worktree;
> +};

I like where you're going with this. It's nicer to have a struct that captures what we know and has accurate data, instead of having a `repository` that's only partly initialized.

-- 
Cheers,
Toon
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 7 of 18 in “setup: split up repository discovery and setup”
  1. 00/13 setup: split up repository discovery and setupPatrick Steinhardt, Jul 7, 2026
  2. 01/13 setup: rename `check_repository_format_gently()`Patrick Steinhardt, Jul 7, 2026
  3. 02/13 setup: mark bogus worktree in `apply_repository_format()`Patrick Steinhardt, Jul 7, 2026
  4. 03/13 setup: unify setup of shallow filePatrick Steinhardt, Jul 7, 2026
  5. 04/13 setup: split up concerns of `setup_git_env_internal()`Patrick Steinhardt, Jul 7, 2026
  6. 05/13 setup: introduce explicit repository discoveryPatrick Steinhardt, Jul 7, 2026
  7. Toon ClaesJul 8, 2026
  8. 06/13 setup: embed repository format in discoveryPatrick Steinhardt, Jul 7, 2026
  9. 08/13 setup: drop static `cwd` variablePatrick Steinhardt, Jul 7, 2026
  10. 07/13 setup: move prefix into repositoryPatrick Steinhardt, Jul 7, 2026
  11. 09/13 setup: propagate prefix via repository discoveryPatrick Steinhardt, Jul 7, 2026
  12. 10/13 setup: make repository discovery self-containedPatrick Steinhardt, Jul 7, 2026
  13. 11/13 setup: drop redundant configuration of `startup_info->have_repository`Patrick Steinhardt, Jul 7, 2026
  14. 12/13 setup: pass worktree to `init_db()`Patrick Steinhardt, Jul 7, 2026
  15. 13/13 setup: mark `set_git_work_tree()` as file-localPatrick Steinhardt, Jul 7, 2026
  16. Justin ToblerJul 7, 2026
  17. Junio C HamanoJul 7, 2026
  18. Toon ClaesJul 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.