mbox series

[0/3] Add repository parameter to builtins

Message ID pull.1778.git.git.1725555467.gitgitgadget@gmail.com (mailing list archive)
Headers show
Series Add repository parameter to builtins | expand

Message

Jean-Noël Avila via GitGitGadget Sept. 5, 2024, 4:57 p.m. UTC
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.

John Cai (3):
  builtin: add a repository parameter for builtin functions
  builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h
  add: pass in repo variable instead of global the_repository

 builtin.h                          | 285 ++++++++++++++---------------
 builtin/add.c                      |  99 +++++-----
 builtin/am.c                       |   3 +-
 builtin/annotate.c                 |   4 +-
 builtin/apply.c                    |   3 +-
 builtin/archive.c                  |   3 +-
 builtin/bisect.c                   |   3 +-
 builtin/blame.c                    |   4 +-
 builtin/branch.c                   |   5 +-
 builtin/bugreport.c                |   3 +-
 builtin/bundle.c                   |   3 +-
 builtin/cat-file.c                 |   7 +-
 builtin/check-attr.c               |   3 +-
 builtin/check-ignore.c             |   3 +-
 builtin/check-mailmap.c            |   3 +-
 builtin/check-ref-format.c         |   2 +-
 builtin/checkout--worker.c         |   3 +-
 builtin/checkout-index.c           |   3 +-
 builtin/checkout.c                 |   7 +-
 builtin/clean.c                    |   4 +-
 builtin/clone.c                    |   5 +-
 builtin/column.c                   |   4 +-
 builtin/commit-graph.c             |   3 +-
 builtin/commit-tree.c              |   3 +-
 builtin/commit.c                   |   9 +-
 builtin/config.c                   |   3 +-
 builtin/count-objects.c            |   4 +-
 builtin/credential-cache--daemon.c |   5 +-
 builtin/credential-cache.c         |   2 +-
 builtin/credential-store.c         |   3 +-
 builtin/credential.c               |   4 +-
 builtin/describe.c                 |   5 +-
 builtin/diagnose.c                 |   2 +-
 builtin/diff-files.c               |   3 +-
 builtin/diff-index.c               |   3 +-
 builtin/diff-tree.c                |   3 +-
 builtin/diff.c                     |   5 +-
 builtin/difftool.c                 |   5 +-
 builtin/fast-export.c              |   4 +-
 builtin/fast-import.c              |   3 +-
 builtin/fetch-pack.c               |   3 +-
 builtin/fetch.c                    |   3 +-
 builtin/fmt-merge-msg.c            |   3 +-
 builtin/for-each-ref.c             |   3 +-
 builtin/for-each-repo.c            |   3 +-
 builtin/fsck.c                     |   3 +-
 builtin/fsmonitor--daemon.c        |   5 +-
 builtin/gc.c                       |   6 +-
 builtin/get-tar-commit-id.c        |   2 +-
 builtin/grep.c                     |   3 +-
 builtin/hash-object.c              |   4 +-
 builtin/help.c                     |   4 +-
 builtin/hook.c                     |   3 +-
 builtin/index-pack.c               |   3 +-
 builtin/init-db.c                  |   2 +-
 builtin/interpret-trailers.c       |   4 +-
 builtin/log.c                      |  13 +-
 builtin/ls-files.c                 |   3 +-
 builtin/ls-remote.c                |   3 +-
 builtin/ls-tree.c                  |   4 +-
 builtin/mailinfo.c                 |   2 +-
 builtin/mailsplit.c                |   2 +-
 builtin/merge-base.c               |   3 +-
 builtin/merge-file.c               |   3 +-
 builtin/merge-index.c              |   3 +-
 builtin/merge-ours.c               |   3 +-
 builtin/merge-recursive.c          |   3 +-
 builtin/merge-tree.c               |   3 +-
 builtin/merge.c                    |   9 +-
 builtin/mktag.c                    |   3 +-
 builtin/mktree.c                   |   4 +-
 builtin/multi-pack-index.c         |   3 +-
 builtin/mv.c                       |   3 +-
 builtin/name-rev.c                 |   3 +-
 builtin/notes.c                    |   4 +-
 builtin/pack-objects.c             |   3 +-
 builtin/pack-redundant.c           |   3 +-
 builtin/pack-refs.c                |   3 +-
 builtin/patch-id.c                 |   3 +-
 builtin/prune-packed.c             |   2 +-
 builtin/prune.c                    |   3 +-
 builtin/pull.c                     |   3 +-
 builtin/push.c                     |   3 +-
 builtin/range-diff.c               |   3 +-
 builtin/read-tree.c                |   4 +-
 builtin/rebase.c                   |   5 +-
 builtin/receive-pack.c             |   3 +-
 builtin/reflog.c                   |   7 +-
 builtin/refs.c                     |   3 +-
 builtin/remote-ext.c               |   2 +-
 builtin/remote-fd.c                |   2 +-
 builtin/remote.c                   |   3 +-
 builtin/repack.c                   |   3 +-
 builtin/replace.c                  |   3 +-
 builtin/replay.c                   |   3 +-
 builtin/rerere.c                   |   3 +-
 builtin/reset.c                    |   5 +-
 builtin/rev-list.c                 |   3 +-
 builtin/rev-parse.c                |   5 +-
 builtin/revert.c                   |   5 +-
 builtin/rm.c                       |   4 +-
 builtin/send-pack.c                |   3 +-
 builtin/shortlog.c                 |   3 +-
 builtin/show-branch.c              |   3 +-
 builtin/show-index.c               |   3 +-
 builtin/show-ref.c                 |   3 +-
 builtin/sparse-checkout.c          |   3 +-
 builtin/stash.c                    |   3 +-
 builtin/stripspace.c               |   3 +-
 builtin/submodule--helper.c        |   3 +-
 builtin/symbolic-ref.c             |   3 +-
 builtin/tag.c                      |   5 +-
 builtin/unpack-file.c              |   3 +-
 builtin/unpack-objects.c           |   3 +-
 builtin/update-index.c             |   3 +-
 builtin/update-ref.c               |   3 +-
 builtin/update-server-info.c       |   3 +-
 builtin/upload-archive.c           |   5 +-
 builtin/upload-pack.c              |   2 +-
 builtin/var.c                      |   4 +-
 builtin/verify-commit.c            |   3 +-
 builtin/verify-pack.c              |   3 +-
 builtin/verify-tag.c               |   4 +-
 builtin/worktree.c                 |   3 +-
 builtin/write-tree.c               |   4 +-
 commit.h                           |   3 +-
 git.c                              |  14 +-
 help.c                             |   3 +-
 128 files changed, 477 insertions(+), 366 deletions(-)


base-commit: 4590f2e9412378c61eac95966709c78766d326ba
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1778%2Fjohn-cai%2Fjc%2Fadd-the-repository-to-builtin-signature-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1778/john-cai/jc/add-the-repository-to-builtin-signature-v1
Pull-Request: https://github.com/git/git/pull/1778

Comments

Junio C Hamano Sept. 5, 2024, 5:21 p.m. UTC | #1
"John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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.