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

Re: [PATCH 0/3] Add repository parameter to builtins

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 5, 2024, 17:21 UTC
Message-ID
<xmqqjzfq2f0f.fsf@gitster.g>
In-Reply-To
<pull.1778.git.git.1725555467.gitgitgadget@gmail.com>
"John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> As part of the effort to remove global state of the_repository, add a
> repository parameter to builtins so that a repository variable can be passed
> down. The patches are ordered as follows:
>
>  1. Changes the signature of builtins and passes the_repository down in
>     git.c to be called by all builtins.
>  2. Remove USE_THE_REPOSITORY_VARIABLE from builtin.h, and instead add it to
>     each individual builtin. This paves the way for a migration process
>     whereby each builtin can be migrated away from using the_repository.
>  3. As an example, migrate builtin/add.c to get rid of the_repository by
>     instead passing the repository argument down into helper functions.

As most of the commands require a repository (as they should---those that work without a repository ought to be outliners, things that are needed to bootstrap like "git init" and "git clone", or those that allow us to interact with a remote repository without having any repository on our side to be affected, like "git archive" or "git ls-remote"), I think this probably makes sense as a good first step.

And there are commands that are primarily for working with Git, but optionally can work outside a repository. They need to do special things in any case by calling setup_git_directory_gently() with nongit to figure out if they are in the repository, e.g.

	prefix = setup_git_directory_gently(&nongit);
	if (!nongit) {
		prepare_repo_settings(the_repository);
		the_repository->settings.command_requires_full_index = 0;
	} else {
		... do whatever it can outside a repository ...
	}

(note: this was taken from "git diff" with a bit of tweak, but others in the same category should look very similar), so I would imagine that we may want to update setup_git_directory_gently() to be more like:

	const char *setup_git_directory_gently(struct repository **repo);
and the above snippet would become:
	prefix = setup_git_directory_gently(&repo);
	if (repo) {
		prepare_repo_settings(repo);
		repo->settings.command_requires_full_index = 0;
	} else {
		...
	}

IOW, "nongit" Boolean flag we use to say "are we working without a repository?" becomes "the dispatcher in git.c usually gives us the repository in repo, but we asked them not to do the repository setup and we will call setup_git_directory_gently() ourselves, allowing the call to overwrite the repo parameter given."

Thanks.
Previous: Patrick SteinhardtNext: John Cai via GitGitGadget
Message 11 of 32 in “Add repository parameter to builtins”
  1. 0/3 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 5, 2024
  2. 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 5, 2024
  3. Junio C HamanoSep 5, 2024
  4. Patrick SteinhardtSep 6, 2024
  5. Junio C HamanoSep 6, 2024
  6. 1/3 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 5, 2024
  7. Patrick SteinhardtSep 6, 2024
  8. John CaiSep 9, 2024
  9. 3/3 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 5, 2024
  10. Patrick SteinhardtSep 6, 2024
  11. Junio C HamanoSep 5, 2024
  12. 0/3 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 10, 2024
  13. 3/3 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 10, 2024
  14. Junio C HamanoSep 11, 2024
  15. 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 10, 2024
  16. Junio C HamanoSep 11, 2024
  17. John CaiSep 13, 2024
  18. 1/3 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 10, 2024
  19. Junio C HamanoSep 10, 2024
  20. Junio C HamanoSep 11, 2024
  21. Patrick SteinhardtSep 12, 2024
  22. Jeff KingSep 12, 2024
  23. Jeff KingSep 12, 2024
  24. Patrick SteinhardtSep 12, 2024
  25. John CaiSep 13, 2024
  26. 0/4 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 13, 2024
  27. 1/4 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 13, 2024
  28. 3/4 builtin: remove USE_THE_REPOSITORY for those without the_repositoryJohn Cai via GitGitGadget, Sep 13, 2024
  29. 2/4 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 13, 2024
  30. Junio C HamanoSep 13, 2024
  31. 4/4 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 13, 2024
  32. Junio C HamanoSep 13, 2024

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.