Skip to contentSkip to conversation

Add repository parameter to builtins

PATCH Superseded John Cai via GitGitGadget 5 participants 32 messages Sep 5, 2024 – Sep 13, 2024 Kbuild Page 1 of 2

lore
Share & tools
lore
#0 lore raw

cover Add repository parameter to builtins

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

Signature · 1 line
gitgitgadget
#1 lore raw

PATCH 1/3 builtin: add a repository parameter for builtin functions

From: John Cai <[email protected]>

In order to reduce the usage of the global the_repository, add a parameter to builtin functions that will get passed a repository variable.

This commit uses UNUSED on most of the builtin functions, as subsequent commits will modify the actual builtins to pass the repository parameter down.

---
 builtin.h                          | 277 +++++++++++++++--------------
 builtin/add.c                      |   2 +-
 builtin/am.c                       |   2 +-
 builtin/annotate.c                 |   4 +-
 builtin/apply.c                    |   2 +-
 builtin/archive.c                  |   2 +-
 builtin/bisect.c                   |   2 +-
 builtin/blame.c                    |   2 +-
 builtin/branch.c                   |   2 +-
 builtin/bugreport.c                |   2 +-
 builtin/bundle.c                   |   2 +-
 builtin/cat-file.c                 |   4 +-
 builtin/check-attr.c               |   2 +-
 builtin/check-ignore.c             |   2 +-
 builtin/check-mailmap.c            |   2 +-
 builtin/check-ref-format.c         |   2 +-
 builtin/checkout--worker.c         |   2 +-
 builtin/checkout-index.c           |   2 +-
 builtin/checkout.c                 |   6 +-
 builtin/clean.c                    |   2 +-
 builtin/clone.c                    |   2 +-
 builtin/column.c                   |   2 +-
 builtin/commit-graph.c             |   2 +-
 builtin/commit-tree.c              |   2 +-
 builtin/commit.c                   |   4 +-
 builtin/config.c                   |   2 +-
 builtin/count-objects.c            |   2 +-
 builtin/credential-cache--daemon.c |   4 +-
 builtin/credential-cache.c         |   2 +-
 builtin/credential-store.c         |   2 +-
 builtin/credential.c               |   2 +-
 builtin/describe.c                 |   4 +-
 builtin/diagnose.c                 |   2 +-
 builtin/diff-files.c               |   2 +-
 builtin/diff-index.c               |   2 +-
 builtin/diff-tree.c                |   2 +-
 builtin/diff.c                     |   2 +-
 builtin/difftool.c                 |   2 +-
 builtin/fast-export.c              |   2 +-
 builtin/fast-import.c              |   2 +-
 builtin/fetch-pack.c               |   2 +-
 builtin/fetch.c                    |   2 +-
 builtin/fmt-merge-msg.c            |   2 +-
 builtin/for-each-ref.c             |   2 +-
 builtin/for-each-repo.c            |   2 +-
 builtin/fsck.c                     |   2 +-
 builtin/fsmonitor--daemon.c        |   4 +-
 builtin/gc.c                       |   4 +-
 builtin/get-tar-commit-id.c        |   2 +-
 builtin/grep.c                     |   2 +-
 builtin/hash-object.c              |   2 +-
 builtin/help.c                     |   2 +-
 builtin/hook.c                     |   2 +-
 builtin/index-pack.c               |   2 +-
 builtin/init-db.c                  |   2 +-
 builtin/interpret-trailers.c       |   2 +-
 builtin/log.c                      |  12 +-
 builtin/ls-files.c                 |   2 +-
 builtin/ls-remote.c                |   2 +-
 builtin/ls-tree.c                  |   2 +-
 builtin/mailinfo.c                 |   2 +-
 builtin/mailsplit.c                |   2 +-
 builtin/merge-base.c               |   2 +-
 builtin/merge-file.c               |   2 +-
 builtin/merge-index.c              |   2 +-
 builtin/merge-ours.c               |   2 +-
 builtin/merge-recursive.c          |   2 +-
 builtin/merge-tree.c               |   2 +-
 builtin/merge.c                    |   6 +-
 builtin/mktag.c                    |   2 +-
 builtin/mktree.c                   |   2 +-
 builtin/multi-pack-index.c         |   2 +-
 builtin/mv.c                       |   2 +-
 builtin/name-rev.c                 |   2 +-
 builtin/notes.c                    |   2 +-
 builtin/pack-objects.c             |   2 +-
 builtin/pack-redundant.c           |   2 +-
 builtin/pack-refs.c                |   2 +-
 builtin/patch-id.c                 |   2 +-
 builtin/prune-packed.c             |   2 +-
 builtin/prune.c                    |   2 +-
 builtin/pull.c                     |   2 +-
 builtin/push.c                     |   2 +-
 builtin/range-diff.c               |   2 +-
 builtin/read-tree.c                |   2 +-
 builtin/rebase.c                   |   2 +-
 builtin/receive-pack.c             |   2 +-
 builtin/reflog.c                   |   6 +-
 builtin/refs.c                     |   2 +-
 builtin/remote-ext.c               |   2 +-
 builtin/remote-fd.c                |   2 +-
 builtin/remote.c                   |   2 +-
 builtin/repack.c                   |   2 +-
 builtin/replace.c                  |   2 +-
 builtin/replay.c                   |   2 +-
 builtin/rerere.c                   |   2 +-
 builtin/reset.c                    |   2 +-
 builtin/rev-list.c                 |   2 +-
 builtin/rev-parse.c                |   2 +-
 builtin/revert.c                   |   4 +-
 builtin/rm.c                       |   2 +-
 builtin/send-pack.c                |   2 +-
 builtin/shortlog.c                 |   2 +-
 builtin/show-branch.c              |   2 +-
 builtin/show-index.c               |   2 +-
 builtin/show-ref.c                 |   2 +-
 builtin/sparse-checkout.c          |   2 +-
 builtin/stash.c                    |   2 +-
 builtin/stripspace.c               |   2 +-
 builtin/submodule--helper.c        |   2 +-
 builtin/symbolic-ref.c             |   2 +-
 builtin/tag.c                      |   2 +-
 builtin/unpack-file.c              |   2 +-
 builtin/unpack-objects.c           |   2 +-
 builtin/update-index.c             |   2 +-
 builtin/update-ref.c               |   2 +-
 builtin/update-server-info.c       |   2 +-
 builtin/upload-archive.c           |   4 +-
 builtin/upload-pack.c              |   2 +-
 builtin/var.c                      |   2 +-
 builtin/verify-commit.c            |   2 +-
 builtin/verify-pack.c              |   2 +-
 builtin/verify-tag.c               |   2 +-
 builtin/worktree.c                 |   2 +-
 builtin/write-tree.c               |   2 +-
 git.c                              |  14 +-
 help.c                             |   3 +-
 127 files changed, 293 insertions(+), 289 deletions(-)
builtin.h +139 -138
index 14fa0171607..fc6fc8ffed8 100644
@@ -10,6 +10,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 
 #include "git-compat-util.h"
+#include "repository.h"
 
 /*
  * builtin API
@@ -122,143 +123,143 @@ int is_builtin(const char *s);
 		BUG("unexpected prefix in builtin: %s", (prefix)); \
 } while (0)
 
-int cmd_add(int argc, const char **argv, const char *prefix);
-int cmd_am(int argc, const char **argv, const char *prefix);
-int cmd_annotate(int argc, const char **argv, const char *prefix);
-int cmd_apply(int argc, const char **argv, const char *prefix);
-int cmd_archive(int argc, const char **argv, const char *prefix);
-int cmd_bisect(int argc, const char **argv, const char *prefix);
-int cmd_blame(int argc, const char **argv, const char *prefix);
-int cmd_branch(int argc, const char **argv, const char *prefix);
-int cmd_bugreport(int argc, const char **argv, const char *prefix);
-int cmd_bundle(int argc, const char **argv, const char *prefix);
-int cmd_cat_file(int argc, const char **argv, const char *prefix);
-int cmd_checkout(int argc, const char **argv, const char *prefix);
-int cmd_checkout__worker(int argc, const char **argv, const char *prefix);
-int cmd_checkout_index(int argc, const char **argv, const char *prefix);
-int cmd_check_attr(int argc, const char **argv, const char *prefix);
-int cmd_check_ignore(int argc, const char **argv, const char *prefix);
-int cmd_check_mailmap(int argc, const char **argv, const char *prefix);
-int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
-int cmd_cherry(int argc, const char **argv, const char *prefix);
-int cmd_cherry_pick(int argc, const char **argv, const char *prefix);
-int cmd_clone(int argc, const char **argv, const char *prefix);
-int cmd_clean(int argc, const char **argv, const char *prefix);
-int cmd_column(int argc, const char **argv, const char *prefix);
-int cmd_commit(int argc, const char **argv, const char *prefix);
-int cmd_commit_graph(int argc, const char **argv, const char *prefix);
-int cmd_commit_tree(int argc, const char **argv, const char *prefix);
-int cmd_config(int argc, const char **argv, const char *prefix);
-int cmd_count_objects(int argc, const char **argv, const char *prefix);
-int cmd_credential(int argc, const char **argv, const char *prefix);
-int cmd_credential_cache(int argc, const char **argv, const char *prefix);
-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix);
-int cmd_credential_store(int argc, const char **argv, const char *prefix);
-int cmd_describe(int argc, const char **argv, const char *prefix);
-int cmd_diagnose(int argc, const char **argv, const char *prefix);
-int cmd_diff_files(int argc, const char **argv, const char *prefix);
-int cmd_diff_index(int argc, const char **argv, const char *prefix);
-int cmd_diff(int argc, const char **argv, const char *prefix);
-int cmd_diff_tree(int argc, const char **argv, const char *prefix);
-int cmd_difftool(int argc, const char **argv, const char *prefix);
-int cmd_env__helper(int argc, const char **argv, const char *prefix);
-int cmd_fast_export(int argc, const char **argv, const char *prefix);
-int cmd_fast_import(int argc, const char **argv, const char *prefix);
-int cmd_fetch(int argc, const char **argv, const char *prefix);
-int cmd_fetch_pack(int argc, const char **argv, const char *prefix);
-int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
-int cmd_for_each_ref(int argc, const char **argv, const char *prefix);
-int cmd_for_each_repo(int argc, const char **argv, const char *prefix);
-int cmd_format_patch(int argc, const char **argv, const char *prefix);
-int cmd_fsck(int argc, const char **argv, const char *prefix);
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix);
-int cmd_gc(int argc, const char **argv, const char *prefix);
-int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
-int cmd_grep(int argc, const char **argv, const char *prefix);
-int cmd_hash_object(int argc, const char **argv, const char *prefix);
-int cmd_help(int argc, const char **argv, const char *prefix);
-int cmd_hook(int argc, const char **argv, const char *prefix);
-int cmd_index_pack(int argc, const char **argv, const char *prefix);
-int cmd_init_db(int argc, const char **argv, const char *prefix);
-int cmd_interpret_trailers(int argc, const char **argv, const char *prefix);
-int cmd_log(int argc, const char **argv, const char *prefix);
-int cmd_log_reflog(int argc, const char **argv, const char *prefix);
-int cmd_ls_files(int argc, const char **argv, const char *prefix);
-int cmd_ls_tree(int argc, const char **argv, const char *prefix);
-int cmd_ls_remote(int argc, const char **argv, const char *prefix);
-int cmd_mailinfo(int argc, const char **argv, const char *prefix);
-int cmd_mailsplit(int argc, const char **argv, const char *prefix);
-int cmd_maintenance(int argc, const char **argv, const char *prefix);
-int cmd_merge(int argc, const char **argv, const char *prefix);
-int cmd_merge_base(int argc, const char **argv, const char *prefix);
-int cmd_merge_index(int argc, const char **argv, const char *prefix);
-int cmd_merge_ours(int argc, const char **argv, const char *prefix);
-int cmd_merge_file(int argc, const char **argv, const char *prefix);
-int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
-int cmd_merge_tree(int argc, const char **argv, const char *prefix);
-int cmd_mktag(int argc, const char **argv, const char *prefix);
-int cmd_mktree(int argc, const char **argv, const char *prefix);
-int cmd_multi_pack_index(int argc, const char **argv, const char *prefix);
-int cmd_mv(int argc, const char **argv, const char *prefix);
-int cmd_name_rev(int argc, const char **argv, const char *prefix);
-int cmd_notes(int argc, const char **argv, const char *prefix);
-int cmd_pack_objects(int argc, const char **argv, const char *prefix);
-int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
-int cmd_patch_id(int argc, const char **argv, const char *prefix);
-int cmd_prune(int argc, const char **argv, const char *prefix);
-int cmd_prune_packed(int argc, const char **argv, const char *prefix);
-int cmd_pull(int argc, const char **argv, const char *prefix);
-int cmd_push(int argc, const char **argv, const char *prefix);
-int cmd_range_diff(int argc, const char **argv, const char *prefix);
-int cmd_read_tree(int argc, const char **argv, const char *prefix);
-int cmd_rebase(int argc, const char **argv, const char *prefix);
-int cmd_rebase__interactive(int argc, const char **argv, const char *prefix);
-int cmd_receive_pack(int argc, const char **argv, const char *prefix);
-int cmd_reflog(int argc, const char **argv, const char *prefix);
-int cmd_refs(int argc, const char **argv, const char *prefix);
-int cmd_remote(int argc, const char **argv, const char *prefix);
-int cmd_remote_ext(int argc, const char **argv, const char *prefix);
-int cmd_remote_fd(int argc, const char **argv, const char *prefix);
-int cmd_repack(int argc, const char **argv, const char *prefix);
-int cmd_replay(int argc, const char **argv, const char *prefix);
-int cmd_rerere(int argc, const char **argv, const char *prefix);
-int cmd_reset(int argc, const char **argv, const char *prefix);
-int cmd_restore(int argc, const char **argv, const char *prefix);
-int cmd_rev_list(int argc, const char **argv, const char *prefix);
-int cmd_rev_parse(int argc, const char **argv, const char *prefix);
-int cmd_revert(int argc, const char **argv, const char *prefix);
-int cmd_rm(int argc, const char **argv, const char *prefix);
-int cmd_send_pack(int argc, const char **argv, const char *prefix);
-int cmd_shortlog(int argc, const char **argv, const char *prefix);
-int cmd_show(int argc, const char **argv, const char *prefix);
-int cmd_show_branch(int argc, const char **argv, const char *prefix);
-int cmd_show_index(int argc, const char **argv, const char *prefix);
-int cmd_sparse_checkout(int argc, const char **argv, const char *prefix);
-int cmd_status(int argc, const char **argv, const char *prefix);
-int cmd_stash(int argc, const char **argv, const char *prefix);
-int cmd_stripspace(int argc, const char **argv, const char *prefix);
-int cmd_submodule__helper(int argc, const char **argv, const char *prefix);
-int cmd_switch(int argc, const char **argv, const char *prefix);
-int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
-int cmd_tag(int argc, const char **argv, const char *prefix);
-int cmd_unpack_file(int argc, const char **argv, const char *prefix);
-int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
-int cmd_update_index(int argc, const char **argv, const char *prefix);
-int cmd_update_ref(int argc, const char **argv, const char *prefix);
-int cmd_update_server_info(int argc, const char **argv, const char *prefix);
-int cmd_upload_archive(int argc, const char **argv, const char *prefix);
-int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix);
-int cmd_upload_pack(int argc, const char **argv, const char *prefix);
-int cmd_var(int argc, const char **argv, const char *prefix);
-int cmd_verify_commit(int argc, const char **argv, const char *prefix);
-int cmd_verify_tag(int argc, const char **argv, const char *prefix);
-int cmd_version(int argc, const char **argv, const char *prefix);
-int cmd_whatchanged(int argc, const char **argv, const char *prefix);
-int cmd_worktree(int argc, const char **argv, const char *prefix);
-int cmd_write_tree(int argc, const char **argv, const char *prefix);
-int cmd_verify_pack(int argc, const char **argv, const char *prefix);
-int cmd_show_ref(int argc, const char **argv, const char *prefix);
-int cmd_pack_refs(int argc, const char **argv, const char *prefix);
-int cmd_replace(int argc, const char **argv, const char *prefix);
+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_am(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_annotate(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_apply(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_archive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_bisect(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_blame(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_branch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_bugreport(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_bundle(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_cat_file(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_checkout(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_checkout__worker(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_checkout_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_attr(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_ignore(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_mailmap(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_ref_format(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_cherry(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_cherry_pick(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_clone(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_clean(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_column(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_commit(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_commit_graph(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_commit_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_config(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_count_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential_cache(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential_store(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_describe(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diagnose(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff_files(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_difftool(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_env__helper(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fast_export(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fast_import(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fetch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fetch_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_for_each_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_for_each_repo(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_format_patch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fsck(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_gc(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_grep(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_hash_object(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_help(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_hook(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_index_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_init_db(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_interpret_trailers(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_log_reflog(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_log(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_ls_files(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_ls_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_ls_remote(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mailinfo(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mailsplit(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_maintenance(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_base(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_ours(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_file(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_recursive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mktag(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mktree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_multi_pack_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mv(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_name_rev(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_notes(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pack_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pack_redundant(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_patch_id(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_prune(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_prune_packed(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pull(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_push(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_range_diff(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_read_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rebase(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rebase__interactive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_receive_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_reflog(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_refs(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_remote(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_remote_ext(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_remote_fd(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_repack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_replay(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rerere(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_reset(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_restore(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rev_list(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rev_parse(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_revert(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rm(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_send_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_shortlog(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show_branch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_sparse_checkout(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_status(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_stash(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_stripspace(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_submodule__helper(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_switch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_symbolic_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_tag(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_unpack_file(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_unpack_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_update_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_update_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_update_server_info(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_upload_archive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_upload_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_var(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_verify_commit(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_verify_tag(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_whatchanged(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_worktree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_write_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_verify_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pack_refs(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_replace(int argc, const char **argv, const char *prefix, struct repository *repo);
 
 #endif
builtin/add.c +1 -1
index 40b61ef90d9..3b9bc93ed9a 100644
@@ -358,7 +358,7 @@ static int add_files(struct dir_struct *dir, int flags)
 	return exit_status;
 }
 
-int cmd_add(int argc, const char **argv, const char *prefix)
+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	int exit_status = 0;
 	struct pathspec pathspec;
builtin/am.c +1 -1
index d8875ad4022..830c295314b 100644
@@ -2298,7 +2298,7 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
 	return 0;
 }
 
-int cmd_am(int argc, const char **argv, const char *prefix)
+int cmd_am(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct am_state state;
 	int binary = -1;
builtin/annotate.c +2 -2
index 58ff977a231..3878b1994d8 100644
@@ -7,7 +7,7 @@
 #include "builtin.h"
 #include "strvec.h"
 
-int cmd_annotate(int argc, const char **argv, const char *prefix)
+int cmd_annotate(int argc, const char **argv, const char *prefix, struct repository *repo)
 {
 	struct strvec args = STRVEC_INIT;
 	int i;
@@ -18,5 +18,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix)
 		strvec_push(&args, argv[i]);
 	}
 
-	return cmd_blame(args.nr, args.v, prefix);
+	return cmd_blame(args.nr, args.v, prefix, repo);
 }
builtin/apply.c +1 -1
index d623c52f78f..923ce992bdd 100644
@@ -9,7 +9,7 @@ static const char * const apply_usage[] = {
 	NULL
 };
 
-int cmd_apply(int argc, const char **argv, const char *prefix)
+int cmd_apply(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int force_apply = 0;
 	int options = 0;
builtin/archive.c +1 -1
index b50981504f3..21e5e3b877b 100644
@@ -76,7 +76,7 @@ static int run_remote_archiver(int argc, const char **argv,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT |	\
 			     PARSE_OPT_NO_INTERNAL_HELP	)
 
-int cmd_archive(int argc, const char **argv, const char *prefix)
+int cmd_archive(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *exec = "git-upload-archive";
 	char *output = NULL;
builtin/bisect.c +1 -1
index 453a6cccd70..8cf6167df61 100644
@@ -1411,7 +1411,7 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
 	return res;
 }
 
-int cmd_bisect(int argc, const char **argv, const char *prefix)
+int cmd_bisect(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int res = 0;
 	parse_opt_subcommand_fn *fn = NULL;
builtin/blame.c +1 -1
index 35e975fb132..522f564d6b0 100644
@@ -864,7 +864,7 @@ static void build_ignorelist(struct blame_scoreboard *sb,
 	}
 }
 
-int cmd_blame(int argc, const char **argv, const char *prefix)
+int cmd_blame(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	char *path = NULL;
builtin/branch.c +1 -1
index 3f870741bfd..e20420059a2 100644
@@ -704,7 +704,7 @@ static int edit_branch_description(const char *branch_name)
 	return 0;
 }
 
-int cmd_branch(int argc, const char **argv, const char *prefix)
+int cmd_branch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	/* possible actions */
 	int delete = 0, rename = 0, copy = 0, list = 0,
builtin/bugreport.c +1 -1
index bdfed3d8f18..5269f073d59 100644
@@ -98,7 +98,7 @@ static void get_header(struct strbuf *buf, const char *title)
 	strbuf_addf(buf, "\n\n[%s]\n", title);
 }
 
-int cmd_bugreport(int argc, const char **argv, const char *prefix)
+int cmd_bugreport(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct strbuf buffer = STRBUF_INIT;
 	struct strbuf report_path = STRBUF_INIT;
builtin/bundle.c +1 -1
index 86d0ed7049c..e26c1f7d4a7 100644
@@ -226,7 +226,7 @@ cleanup:
 	return ret;
 }
 
-int cmd_bundle(int argc, const char **argv, const char *prefix)
+int cmd_bundle(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
builtin/cat-file.c +2 -2
index 18fe58d6b8b..6e6f134eab1 100644
@@ -191,7 +191,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 			const char *ls_args[3] = { NULL };
 			ls_args[0] =  "ls-tree";
 			ls_args[1] =  obj_name;
-			ret = cmd_ls_tree(2, ls_args, NULL);
+			ret = cmd_ls_tree(2, ls_args, NULL, the_repository);
 			goto cleanup;
 		}
 
@@ -923,7 +923,7 @@ static int batch_option_callback(const struct option *opt,
 	return 0;
 }
 
-int cmd_cat_file(int argc, const char **argv, const char *prefix)
+int cmd_cat_file(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int opt = 0;
 	int opt_cw = 0;
builtin/check-attr.c +1 -1
index 93768107100..0f180350bec 100644
@@ -107,7 +107,7 @@ static NORETURN void error_with_usage(const char *msg)
 	usage_with_options(check_attr_usage, check_attr_options);
 }
 
-int cmd_check_attr(int argc, const char **argv, const char *prefix)
+int cmd_check_attr(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct attr_check *check;
 	struct object_id initialized_oid;
builtin/check-ignore.c +1 -1
index 2bda6a1d462..4067127c8b4 100644
@@ -151,7 +151,7 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
 	return num_ignored;
 }
 
-int cmd_check_ignore(int argc, const char **argv, const char *prefix)
+int cmd_check_ignore(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int num_ignored;
 	struct dir_struct dir = DIR_INIT;
builtin/check-mailmap.c +1 -1
index b8a05b8e07b..07ab8fa9b3c 100644
@@ -40,7 +40,7 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)
 	printf("<%.*s>\n", (int)maillen, mail);
 }
 
-int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
+int cmd_check_mailmap(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i;
 	struct string_list mailmap = STRING_LIST_INIT_NODUP;
builtin/check-ref-format.c +1 -1
index 5eb6bdc3f69..594a5465d4d 100644
@@ -51,7 +51,7 @@ static int check_ref_format_branch(const char *arg)
 	return 0;
 }
 
-int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
+int cmd_check_ref_format(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i;
 	int normalize = 0;
builtin/checkout--worker.c +1 -1
index 6b62b5375bd..61758a11d5d 100644
@@ -113,7 +113,7 @@ static const char * const checkout_worker_usage[] = {
 	NULL
 };
 
-int cmd_checkout__worker(int argc, const char **argv, const char *prefix)
+int cmd_checkout__worker(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct checkout state = CHECKOUT_INIT;
 	struct option checkout_worker_options[] = {
builtin/checkout-index.c +1 -1
index 29e744d11be..dcf58a4fe13 100644
@@ -208,7 +208,7 @@ static int option_parse_stage(const struct option *opt,
 	return 0;
 }
 
-int cmd_checkout_index(int argc, const char **argv, const char *prefix)
+int cmd_checkout_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i;
 	struct lock_file lock_file = LOCK_INIT;
builtin/checkout.c +3 -3
index 4cfe6fab505..c43bba082f5 100644
@@ -1953,7 +1953,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
 	return ret;
 }
 
-int cmd_checkout(int argc, const char **argv, const char *prefix)
+int cmd_checkout(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct checkout_opts opts = CHECKOUT_OPTS_INIT;
 	struct option *options;
@@ -2000,7 +2000,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 			     checkout_usage);
 }
 
-int cmd_switch(int argc, const char **argv, const char *prefix)
+int cmd_switch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct checkout_opts opts = CHECKOUT_OPTS_INIT;
 	struct option *options = NULL;
@@ -2036,7 +2036,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
 			     switch_branch_usage);
 }
 
-int cmd_restore(int argc, const char **argv, const char *prefix)
+int cmd_restore(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct checkout_opts opts = CHECKOUT_OPTS_INIT;
 	struct option *options;
builtin/clean.c +1 -1
index ded5a91534c..d4e00f4f3af 100644
@@ -915,7 +915,7 @@ static void correct_untracked_entries(struct dir_struct *dir)
 	dir->nr = dst;
 }
 
-int cmd_clean(int argc, const char **argv, const char *prefix)
+int cmd_clean(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i, res;
 	int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
builtin/clone.c +1 -1
index 269b6e18a4e..fb820861cd9 100644
@@ -956,7 +956,7 @@ static int path_exists(const char *path)
 	return !stat(path, &sb);
 }
 
-int cmd_clone(int argc, const char **argv, const char *prefix)
+int cmd_clone(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	int is_bundle = 0, is_local;
 	int reject_shallow = 0;
builtin/column.c +1 -1
index 10ff7e01668..ca2b522284e 100644
@@ -18,7 +18,7 @@ static int column_config(const char *var, const char *value,
 	return git_column_config(var, value, cb, &colopts);
 }
 
-int cmd_column(int argc, const char **argv, const char *prefix)
+int cmd_column(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct string_list list = STRING_LIST_INIT_DUP;
 	struct strbuf sb = STRBUF_INIT;
builtin/commit-graph.c +1 -1
index 7102ee90a00..67e27ef0cd7 100644
@@ -331,7 +331,7 @@ cleanup:
 	return result;
 }
 
-int cmd_commit_graph(int argc, const char **argv, const char *prefix)
+int cmd_commit_graph(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_commit_graph_options[] = {
builtin/commit-tree.c +1 -1
index 84bb4502229..42f88d007ff 100644
@@ -90,7 +90,7 @@ static int parse_file_arg_callback(const struct option *opt,
 	return 0;
 }
 
-int cmd_commit_tree(int argc, const char **argv, const char *prefix)
+int cmd_commit_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	static struct strbuf buffer = STRBUF_INIT;
 	struct commit_list *parents = NULL;
builtin/commit.c +2 -2
index b2033c48877..27c807cde08 100644
@@ -1502,7 +1502,7 @@ static int git_status_config(const char *k, const char *v,
 	return git_diff_ui_config(k, v, ctx, NULL);
 }
 
-int cmd_status(int argc, const char **argv, const char *prefix)
+int cmd_status(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	static int no_renames = -1;
 	static const char *rename_score_arg = (const char *)-1;
@@ -1641,7 +1641,7 @@ static int git_commit_config(const char *k, const char *v,
 	return git_status_config(k, v, ctx, s);
 }
 
-int cmd_commit(int argc, const char **argv, const char *prefix)
+int cmd_commit(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	static struct wt_status s;
 	static struct option builtin_commit_options[] = {
builtin/config.c +1 -1
index e00d983596b..8604986fa98 100644
@@ -1392,7 +1392,7 @@ out:
 	return ret;
 }
 
-int cmd_config(int argc, const char **argv, const char *prefix)
+int cmd_config(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *subcommand = NULL;
 	struct option subcommand_opts[] = {
builtin/count-objects.c +1 -1
index ec6098a149d..74225ff2488 100644
@@ -95,7 +95,7 @@ static char const * const count_objects_usage[] = {
 	NULL
 };
 
-int cmd_count_objects(int argc, const char **argv, const char *prefix)
+int cmd_count_objects(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int human_readable = 0;
 	struct option opts[] = {
builtin/credential-cache--daemon.c +2 -2
index 4952b225477..0c4d29a0745 100644
@@ -287,7 +287,7 @@ static void init_socket_directory(const char *path)
 	free(path_copy);
 }
 
-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct tempfile *socket_file;
 	const char *socket_path;
@@ -330,7 +330,7 @@ int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
 
 #else
 
-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char * const usage[] = {
 		"git credential-cache--daemon [--debug] <socket-path>",
builtin/credential-cache.c +1 -1
index aaf2f8438b4..7e6e749ed45 100644
@@ -137,7 +137,7 @@ static void announce_capabilities(void)
 	credential_announce_capabilities(&c, stdout);
 }
 
-int cmd_credential_cache(int argc, const char **argv, const char *prefix)
+int cmd_credential_cache(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *socket_path_arg = NULL;
 	char *socket_path;
builtin/credential-store.c +1 -1
index 97968bfa1c2..e79d72d9695 100644
@@ -170,7 +170,7 @@ static void lookup_credential(const struct string_list *fns, struct credential *
 			return; /* Found credential */
 }
 
-int cmd_credential_store(int argc, const char **argv, const char *prefix)
+int cmd_credential_store(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char * const usage[] = {
 		"git credential-store [<options>] <action>",
builtin/credential.c +1 -1
index b72e76dd9a6..9235fbf1977 100644
@@ -6,7 +6,7 @@
 static const char usage_msg[] =
 	"git credential (fill|approve|reject)";
 
-int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_credential(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	const char *op;
 	struct credential c = CREDENTIAL_INIT;
builtin/describe.c +2 -2
index b43093c099f..32ab17de651 100644
@@ -571,7 +571,7 @@ static int option_parse_exact_match(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_describe(int argc, const char **argv, const char *prefix)
+int cmd_describe(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED )
 {
 	int contains = 0;
 	struct option options[] = {
@@ -650,7 +650,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			argv_copy[i] = args.v[i];
 		argv_copy[args.nr] = NULL;
 
-		ret = cmd_name_rev(args.nr, argv_copy, prefix);
+		ret = cmd_name_rev(args.nr, argv_copy, prefix, the_repository);
 
 		strvec_clear(&args);
 		free(argv_copy);
builtin/diagnose.c +1 -1
index 4857a4395ba..8d13df9b991 100644
@@ -11,7 +11,7 @@ static const char * const diagnose_usage[] = {
 	NULL
 };
 
-int cmd_diagnose(int argc, const char **argv, const char *prefix)
+int cmd_diagnose(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct strbuf zip_path = STRBUF_INIT;
 	time_t now = time(NULL);
builtin/diff-files.c +1 -1
index 018011f29ea..93a3df766ad 100644
@@ -17,7 +17,7 @@ static const char diff_files_usage[] =
 "\n"
 COMMON_DIFF_OPTIONS_HELP;
 
-int cmd_diff_files(int argc, const char **argv, const char *prefix)
+int cmd_diff_files(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info rev;
 	int result;
builtin/diff-index.c +1 -1
index 685b60284fd..645d2fba359 100644
@@ -14,7 +14,7 @@ static const char diff_cache_usage[] =
 "\n"
 COMMON_DIFF_OPTIONS_HELP;
 
-int cmd_diff_index(int argc, const char **argv, const char *prefix)
+int cmd_diff_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info rev;
 	unsigned int option = 0;
builtin/diff-tree.c +1 -1
index b8df1d4b79b..0d17708d2a3 100644
@@ -108,7 +108,7 @@ static void diff_tree_tweak_rev(struct rev_info *rev)
 	}
 }
 
-int cmd_diff_tree(int argc, const char **argv, const char *prefix)
+int cmd_diff_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	char line[1000];
 	struct object *tree1, *tree2;
builtin/diff.c +1 -1
index 6eac445579b..ebf71aa5592 100644
@@ -393,7 +393,7 @@ static void symdiff_release(struct symdiff *sdiff)
 	bitmap_free(sdiff->skip);
 }
 
-int cmd_diff(int argc, const char **argv, const char *prefix)
+int cmd_diff(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i;
 	struct rev_info rev;
builtin/difftool.c +1 -1
index dcc68e190c2..94f3bf72a7c 100644
@@ -690,7 +690,7 @@ static int run_file_diff(int prompt, const char *prefix,
 	return run_command(child);
 }
 
-int cmd_difftool(int argc, const char **argv, const char *prefix)
+int cmd_difftool(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int use_gui_tool = -1, dir_diff = 0, prompt = -1, symlinks = 0,
 	    tool_help = 0, no_index = 0;
builtin/fast-export.c +1 -1
index f253b79322a..37482785b81 100644
@@ -1180,7 +1180,7 @@ static int parse_opt_anonymize_map(const struct option *opt,
 	return 0;
 }
 
-int cmd_fast_export(int argc, const char **argv, const char *prefix)
+int cmd_fast_export(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	struct commit *commit;
builtin/fast-import.c +1 -1
index 2214c105f17..36b76490e1e 100644
@@ -3537,7 +3537,7 @@ static void parse_argv(void)
 	build_mark_map(&sub_marks_from, &sub_marks_to);
 }
 
-int cmd_fast_import(int argc, const char **argv, const char *prefix)
+int cmd_fast_import(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	unsigned int i;
 
builtin/fetch-pack.c +1 -1
index af329e8d5cf..fcabd1906d4 100644
@@ -43,7 +43,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
 	(*sought)[*nr - 1] = ref;
 }
 
-int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	int i, ret;
 	struct ref *ref = NULL;
builtin/fetch.c +1 -1
index c297569a473..ccdb409da43 100644
@@ -2138,7 +2138,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
 	return exit_code;
 }
 
-int cmd_fetch(int argc, const char **argv, const char *prefix)
+int cmd_fetch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct fetch_config config = {
 		.display_format = DISPLAY_FORMAT_FULL,
builtin/fmt-merge-msg.c +1 -1
index 957786d1b3a..0a9c2008429 100644
@@ -9,7 +9,7 @@ static const char * const fmt_merge_msg_usage[] = {
 	NULL
 };
 
-int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
+int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	char *inpath = NULL;
 	const char *message = NULL;
builtin/for-each-ref.c +1 -1
index 5517a4a1c08..70391638a3d 100644
@@ -16,7 +16,7 @@ static char const * const for_each_ref_usage[] = {
 	NULL
 };
 
-int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
+int cmd_for_each_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct ref_sorting *sorting;
 	struct string_list sorting_options = STRING_LIST_INIT_DUP;
builtin/for-each-repo.c +1 -1
index c4fa41fda9f..6b2935ae140 100644
@@ -29,7 +29,7 @@ static int run_command_on_repo(const char *path, int argc, const char ** argv)
 	return run_command(&child);
 }
 
-int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
+int cmd_for_each_repo(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	static const char *config_key = NULL;
 	int keep_going = 0;
builtin/fsck.c +1 -1
index 60f4e6fad97..2b69c963b2e 100644
@@ -925,7 +925,7 @@ static struct option fsck_opts[] = {
 	OPT_END(),
 };
 
-int cmd_fsck(int argc, const char **argv, const char *prefix)
+int cmd_fsck(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i;
 	struct object_directory *odb;
builtin/fsmonitor--daemon.c +2 -2
index 1593713f4cb..93f4a60ca22 100644
@@ -1521,7 +1521,7 @@ static int try_to_start_background_daemon(void)
 	}
 }
 
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *subcmd;
 	enum fsmonitor_reason reason;
@@ -1584,7 +1584,7 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
 }
 
 #else
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	struct option options[] = {
 		OPT_END()
builtin/gc.c +2 -2
index 427faf1cfe1..462dacb0bdb 100644
@@ -657,7 +657,7 @@ static void gc_before_repack(struct maintenance_run_opts *opts,
 	}
 }
 
-int cmd_gc(int argc, const char **argv, const char *prefix)
+int cmd_gc(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int aggressive = 0;
 	int quiet = 0;
@@ -2890,7 +2890,7 @@ static const char * const builtin_maintenance_usage[] = {
 	NULL,
 };
 
-int cmd_maintenance(int argc, const char **argv, const char *prefix)
+int cmd_maintenance(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_maintenance_options[] = {
builtin/get-tar-commit-id.c +1 -1
index 7195a072edc..627133807b7 100644
@@ -12,7 +12,7 @@ static const char builtin_get_tar_commit_id_usage[] =
 #define RECORDSIZE	(512)
 #define HEADERSIZE (2 * RECORDSIZE)
 
-int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix)
+int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix, struct repository *repo UNUSED)
 {
 	char buffer[HEADERSIZE];
 	struct ustar_header *header = (struct ustar_header *)buffer;
builtin/grep.c +1 -1
index dfc3c3e8bd2..98eea1f4dc5 100644
@@ -888,7 +888,7 @@ static int pattern_callback(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_grep(int argc, const char **argv, const char *prefix)
+int cmd_grep(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int hit = 0;
 	int cached = 0, untracked = 0, opt_exclude = -1;
builtin/hash-object.c +1 -1
index c767414a0cc..59a48345394 100644
@@ -84,7 +84,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
 	strbuf_release(&unquoted);
 }
 
-int cmd_hash_object(int argc, const char **argv, const char *prefix)
+int cmd_hash_object(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	static const char * const hash_object_usage[] = {
 		N_("git hash-object [-t <type>] [-w] [--path=<file> | --no-filters]\n"
builtin/help.c +1 -1
index dc1fbe2b986..4efdccfb7fb 100644
@@ -631,7 +631,7 @@ static void opt_mode_usage(int argc, const char *opt_mode,
 	no_help_format(opt_mode, fmt);
 }
 
-int cmd_help(int argc, const char **argv, const char *prefix)
+int cmd_help(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int nongit;
 	enum help_format parsed_help_format;
builtin/hook.c +1 -1
index cc37438fdee..2aa6476f8fc 100644
@@ -66,7 +66,7 @@ usage:
 	usage_with_options(builtin_hook_run_usage, run_options);
 }
 
-int cmd_hook(int argc, const char **argv, const char *prefix)
+int cmd_hook(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_hook_options[] = {
builtin/index-pack.c +1 -1
index fd968d673d2..64754da036d 100644
@@ -1718,7 +1718,7 @@ static void show_pack_info(int stat_only)
 	free(chain_histogram);
 }
 
-int cmd_index_pack(int argc, const char **argv, const char *prefix)
+int cmd_index_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
 	const char *curr_index;
builtin/init-db.c +1 -1
index 582dcf20f86..fe16d91aaba 100644
@@ -70,7 +70,7 @@ static const char *const init_db_usage[] = {
  * On the other hand, it might just make lookup slower and messier. You
  * be the judge.  The default case is to have one DB per managed directory.
  */
-int cmd_init_db(int argc, const char **argv, const char *prefix)
+int cmd_init_db(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *git_dir;
 	const char *real_git_dir = NULL;
builtin/interpret-trailers.c +1 -1
index 1d969494cf5..79da472e8eb 100644
@@ -188,7 +188,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,
 	strbuf_release(&sb);
 }
 
-int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
+int cmd_interpret_trailers(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
 	LIST_HEAD(trailers);
builtin/log.c +6 -6
index 36769bab3b6..c9018e89e55 100644
@@ -637,7 +637,7 @@ static int git_log_config(const char *var, const char *value,
 	return git_diff_ui_config(var, value, ctx, cb);
 }
 
-int cmd_whatchanged(int argc, const char **argv, const char *prefix)
+int cmd_whatchanged(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -758,7 +758,7 @@ static void show_setup_revisions_tweak(struct rev_info *rev)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 }
 
-int cmd_show(int argc, const char **argv, const char *prefix)
+int cmd_show(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -874,7 +874,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 /*
  * This is equivalent to "git log -g --abbrev-commit --pretty=oneline"
  */
-int cmd_log_reflog(int argc, const char **argv, const char *prefix)
+int cmd_log_reflog(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -916,7 +916,7 @@ static void log_setup_revisions_tweak(struct rev_info *rev)
 		diff_merges_default_to_first_parent(rev);
 }
 
-int cmd_log(int argc, const char **argv, const char *prefix)
+int cmd_log(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -1986,7 +1986,7 @@ static void infer_range_diff_ranges(struct strbuf *r1,
 	}
 }
 
-int cmd_format_patch(int argc, const char **argv, const char *prefix)
+int cmd_format_patch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct format_config cfg;
 	struct commit *commit;
@@ -2619,7 +2619,7 @@ static void print_commit(char sign, struct commit *commit, int verbose,
 	}
 }
 
-int cmd_cherry(int argc, const char **argv, const char *prefix)
+int cmd_cherry(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	struct patch_ids ids;
builtin/ls-files.c +1 -1
index 6eeb5cba783..5185f264e8d 100644
@@ -561,7 +561,7 @@ static int option_parse_exclude_standard(const struct option *opt,
 	return 0;
 }
 
-int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
+int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix, struct repository *repo UNUSED)
 {
 	int require_work_tree = 0, show_tag = 0, i;
 	char *max_prefix;
builtin/ls-remote.c +1 -1
index 0a491595ca8..ce826d32686 100644
@@ -37,7 +37,7 @@ static int tail_match(const struct strvec *pattern, const char *path)
 	return 0;
 }
 
-int cmd_ls_remote(int argc, const char **argv, const char *prefix)
+int cmd_ls_remote(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *dest = NULL;
 	unsigned flags = 0;
builtin/ls-tree.c +1 -1
index bf372c67d77..f91361ca788 100644
@@ -329,7 +329,7 @@ static struct ls_tree_cmdmode_to_fmt ls_tree_cmdmode_format[] = {
 	},
 };
 
-int cmd_ls_tree(int argc, const char **argv, const char *prefix)
+int cmd_ls_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct object_id oid;
 	struct tree *tree;
builtin/mailinfo.c +1 -1
index 53a22645da5..d883ccf4590 100644
@@ -48,7 +48,7 @@ static int parse_opt_quoted_cr(const struct option *opt, const char *arg, int un
 	return 0;
 }
 
-int cmd_mailinfo(int argc, const char **argv, const char *prefix)
+int cmd_mailinfo(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct metainfo_charset meta_charset;
 	struct mailinfo mi;
builtin/mailsplit.c +1 -1
index fe6dbc5d053..585b81834c2 100644
@@ -269,7 +269,7 @@ out:
 	return ret;
 }
 
-int cmd_mailsplit(int argc, const char **argv, const char *prefix)
+int cmd_mailsplit(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int nr = 0, nr_prec = 4, num = 0;
 	int allow_bare = 0;
builtin/merge-base.c +1 -1
index 5a8e7295029..d5aef8b32c0 100644
@@ -143,7 +143,7 @@ static int handle_fork_point(int argc, const char **argv)
 	return 0;
 }
 
-int cmd_merge_base(int argc, const char **argv, const char *prefix)
+int cmd_merge_base(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct commit **rev;
 	int rev_nr = 0;
builtin/merge-file.c +1 -1
index 1f987334a31..a538edf2a46 100644
@@ -53,7 +53,7 @@ static int diff_algorithm_cb(const struct option *opt,
 	return 0;
 }
 
-int cmd_merge_file(int argc, const char **argv, const char *prefix)
+int cmd_merge_file(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *names[3] = { 0 };
 	mmfile_t mmfs[3] = { 0 };
builtin/merge-index.c +1 -1
index 0fabe3f6bb2..39870e14bfa 100644
@@ -73,7 +73,7 @@ static void merge_all(void)
 	}
 }
 
-int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	int i, force_file = 0;
 
builtin/merge-ours.c +1 -1
index 932924e5d0e..391c767e122 100644
@@ -15,7 +15,7 @@
 static const char builtin_merge_ours_usage[] =
 	"git merge-ours <base>... -- HEAD <remote>...";
 
-int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage(builtin_merge_ours_usage);
builtin/merge-recursive.c +1 -1
index e951b09805d..cd2b4d9a721 100644
@@ -21,7 +21,7 @@ static char *better_branch_name(const char *branch)
 	return xstrdup(name ? name : branch);
 }
 
-int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	struct object_id bases[21];
 	unsigned bases_count = 0;
builtin/merge-tree.c +1 -1
index 9bca9b5f33c..e69ed337f46 100644
@@ -526,7 +526,7 @@ static int real_merge(struct merge_tree_options *o,
 	return !result.clean; /* result.clean < 0 handled above */
 }
 
-int cmd_merge_tree(int argc, const char **argv, const char *prefix)
+int cmd_merge_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct merge_tree_options o = { .show_messages = -1 };
 	struct strvec xopts = STRVEC_INIT;
builtin/merge.c +3 -3
index 662a49a0e8c..4e817f6e91f 100644
@@ -1275,7 +1275,7 @@ static int merging_a_throwaway_tag(struct commit *commit)
 	return is_throwaway_tag;
 }
 
-int cmd_merge(int argc, const char **argv, const char *prefix)
+int cmd_merge(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct object_id result_tree, stash, head_oid;
 	struct commit *head_commit;
@@ -1347,7 +1347,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 					REF_NO_DEREF);
 
 		/* Invoke 'git reset --merge' */
-		ret = cmd_reset(nargc, nargv, prefix);
+		ret = cmd_reset(nargc, nargv, prefix, the_repository);
 
 		if (!is_null_oid(&stash_oid)) {
 			oid_to_hex_r(stash_oid_hex, &stash_oid);
@@ -1379,7 +1379,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			die(_("There is no merge in progress (MERGE_HEAD missing)."));
 
 		/* Invoke 'git commit' */
-		ret = cmd_commit(nargc, nargv, prefix);
+		ret = cmd_commit(nargc, nargv, prefix, the_repository);
 		goto done;
 	}
 
builtin/mktag.c +1 -1
index c6b644219fb..cc3f1b7c5bb 100644
@@ -71,7 +71,7 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
 	return ret;
 }
 
-int cmd_mktag(int argc, const char **argv, const char *prefix)
+int cmd_mktag(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	static struct option builtin_mktag_options[] = {
 		OPT_BOOL(0, "strict", &option_strict,
builtin/mktree.c +1 -1
index 9a22d4e2773..1c43360b50c 100644
@@ -150,7 +150,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
 	free(to_free);
 }
 
-int cmd_mktree(int ac, const char **av, const char *prefix)
+int cmd_mktree(int ac, const char **av, const char *prefix, struct repository *repo UNUSED)
 {
 	struct strbuf sb = STRBUF_INIT;
 	struct object_id oid;
builtin/multi-pack-index.c +1 -1
index 8805cbbeb3b..91324a5581d 100644
@@ -268,7 +268,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
 }
 
 int cmd_multi_pack_index(int argc, const char **argv,
-			 const char *prefix)
+			 const char *prefix, struct repository *repo UNUSED)
 {
 	int res;
 	parse_opt_subcommand_fn *fn = NULL;
builtin/mv.c +1 -1
index 6c69033c5f5..3069d1d9ce8 100644
@@ -178,7 +178,7 @@ static void remove_empty_src_dirs(const char **src_dir, size_t src_dir_nr)
 	strbuf_release(&a_src_dir);
 }
 
-int cmd_mv(int argc, const char **argv, const char *prefix)
+int cmd_mv(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i, flags, gitmodules_modified = 0;
 	int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0;
builtin/name-rev.c +1 -1
index a468ef84c37..f46f5546629 100644
@@ -558,7 +558,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
 	strbuf_release(&buf);
 }
 
-int cmd_name_rev(int argc, const char **argv, const char *prefix)
+int cmd_name_rev(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct mem_pool string_pool;
 	struct object_array revs = OBJECT_ARRAY_INIT;
builtin/notes.c +1 -1
index 04f9dfb7fbd..2f8e896283a 100644
@@ -1096,7 +1096,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
-int cmd_notes(int argc, const char **argv, const char *prefix)
+int cmd_notes(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *override_notes_ref = NULL;
 	parse_opt_subcommand_fn *fn = NULL;
builtin/pack-objects.c +1 -1
index 778be80f564..702d10ea86b 100644
@@ -4284,7 +4284,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
 	return 0;
 }
 
-int cmd_pack_objects(int argc, const char **argv, const char *prefix)
+int cmd_pack_objects(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int use_internal_rev_list = 0;
 	int shallow = 0;
builtin/pack-redundant.c +1 -1
index dd9bf35f5b8..42d367c95d1 100644
@@ -561,7 +561,7 @@ static void load_all(void)
 	}
 }
 
-int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	int i;
 	int i_still_use_this = 0;
builtin/pack-refs.c +1 -1
index db408256663..c61e876216a 100644
@@ -11,7 +11,7 @@ static char const * const pack_refs_usage[] = {
 	NULL
 };
 
-int cmd_pack_refs(int argc, const char **argv, const char *prefix)
+int cmd_pack_refs(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
 	struct string_list included_refs = STRING_LIST_INIT_NODUP;
builtin/patch-id.c +1 -1
index 35c1179f7e9..4449c44580a 100644
@@ -260,7 +260,7 @@ static int git_patch_id_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_patch_id(int argc, const char **argv, const char *prefix)
+int cmd_patch_id(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	/* if nothing is set, default to unstable */
 	struct patch_id_opts config = {0, 0};
builtin/prune-packed.c +1 -1
index ca3578e1588..d22cd632340 100644
@@ -8,7 +8,7 @@ static const char * const prune_packed_usage[] = {
 	NULL
 };
 
-int cmd_prune_packed(int argc, const char **argv, const char *prefix)
+int cmd_prune_packed(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
 	const struct option prune_packed_options[] = {
builtin/prune.c +1 -1
index 57fe31467fe..ed532fab0a5 100644
@@ -147,7 +147,7 @@ static void remove_temporary_files(const char *path)
 	closedir(dir);
 }
 
-int cmd_prune(int argc, const char **argv, const char *prefix)
+int cmd_prune(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	int exclude_promisor_objects = 0;
builtin/pull.c +1 -1
index 4c54d8196fa..906c02e5a97 100644
@@ -977,7 +977,7 @@ static void show_advice_pull_non_ff(void)
 		 "invocation.\n"));
 }
 
-int cmd_pull(int argc, const char **argv, const char *prefix)
+int cmd_pull(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	const char *repo, **refspecs;
 	struct oid_array merge_heads = OID_ARRAY_INIT;
builtin/push.c +1 -1
index 7a67398124f..a6b7fcd9538 100644
@@ -546,7 +546,7 @@ static int git_push_config(const char *k, const char *v,
 	return git_default_config(k, v, ctx, NULL);
 }
 
-int cmd_push(int argc, const char **argv, const char *prefix)
+int cmd_push(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	int flags = 0;
 	int tags = 0;
builtin/range-diff.c +1 -1
index f02cbac087d..30a5b003bab 100644
@@ -13,7 +13,7 @@ N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
 NULL
 };
 
-int cmd_range_diff(int argc, const char **argv, const char *prefix)
+int cmd_range_diff(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct diff_options diffopt = { NULL };
 	struct strvec other_arg = STRVEC_INIT;
builtin/read-tree.c +1 -1
index a8cf8504b8a..89fa0b728d7 100644
@@ -108,7 +108,7 @@ static int git_read_tree_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
+int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix, struct repository *repo UNUSED)
 {
 	int i, stage = 0;
 	struct object_id oid;
builtin/rebase.c +1 -1
index a2c96c080e1..20a0a324aff 100644
@@ -1063,7 +1063,7 @@ static int check_exec_cmd(const char *cmd)
 	return 0;
 }
 
-int cmd_rebase(int argc, const char **argv, const char *prefix)
+int cmd_rebase(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rebase_options options = REBASE_OPTIONS_INIT;
 	const char *branch_name;
builtin/receive-pack.c +1 -1
index 3f35140e489..74677ff1a24 100644
@@ -2480,7 +2480,7 @@ static int delete_only(struct command *commands)
 	return 1;
 }
 
-int cmd_receive_pack(int argc, const char **argv, const char *prefix)
+int cmd_receive_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int advertise_refs = 0;
 	struct command *commands;
builtin/reflog.c +3 -3
index 0d2ff95c6e7..1eab96aca98 100644
@@ -244,7 +244,7 @@ static int cmd_reflog_show(int argc, const char **argv, const char *prefix)
 		      PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
 		      PARSE_OPT_KEEP_UNKNOWN_OPT);
 
-	return cmd_log_reflog(argc, argv, prefix);
+	return cmd_log_reflog(argc, argv, prefix, the_repository);
 }
 
 static int show_reflog(const char *refname, void *cb_data UNUSED)
@@ -447,7 +447,7 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
  * main "reflog"
  */
 
-int cmd_reflog(int argc, const char **argv, const char *prefix)
+int cmd_reflog(int argc, const char **argv, const char *prefix, struct repository *repository)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
@@ -466,5 +466,5 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
 	if (fn)
 		return fn(argc - 1, argv + 1, prefix);
 	else
-		return cmd_log_reflog(argc, argv, prefix);
+		return cmd_log_reflog(argc, argv, prefix, repository);
 }
builtin/refs.c +1 -1
index 131f98be986..355e0abce76 100644
@@ -90,7 +90,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)
 	return ret;
 }
 
-int cmd_refs(int argc, const char **argv, const char *prefix)
+int cmd_refs(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char * const refs_usage[] = {
 		REFS_MIGRATE_USAGE,
builtin/remote-ext.c +1 -1
index 282782eccdd..b325dff729d 100644
@@ -195,7 +195,7 @@ static int command_loop(const char *child)
 	}
 }
 
-int cmd_remote_ext(int argc, const char **argv, const char *prefix)
+int cmd_remote_ext(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	BUG_ON_NON_EMPTY_PREFIX(prefix);
 
builtin/remote-fd.c +1 -1
index 9020fab9c58..6ec2b45c97d 100644
@@ -53,7 +53,7 @@ static void command_loop(int input_fd, int output_fd)
 	}
 }
 
-int cmd_remote_fd(int argc, const char **argv, const char *prefix)
+int cmd_remote_fd(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int input_fd = -1;
 	int output_fd = -1;
builtin/remote.c +1 -1
index d1f9292ed2b..d24d4966ccb 100644
@@ -1754,7 +1754,7 @@ out:
 	return 0;
 }
 
-int cmd_remote(int argc, const char **argv, const char *prefix)
+int cmd_remote(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
builtin/repack.c +1 -1
index 62cfa50c50f..ea06f0b4a0f 100644
@@ -1116,7 +1116,7 @@ static const char *find_pack_prefix(const char *packdir, const char *packtmp)
 	return pack_prefix;
 }
 
-int cmd_repack(int argc, const char **argv, const char *prefix)
+int cmd_repack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
 	struct string_list_item *item;
builtin/replace.c +1 -1
index 34cc4672bc1..9c6d846c497 100644
@@ -545,7 +545,7 @@ static int convert_graft_file(int force)
 	return -1;
 }
 
-int cmd_replace(int argc, const char **argv, const char *prefix)
+int cmd_replace(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int force = 0;
 	int raw = 0;
builtin/replay.c +1 -1
index 138198ce9ca..66f417aab78 100644
@@ -274,7 +274,7 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	return create_commit(result->tree, pickme, replayed_base);
 }
 
-int cmd_replay(int argc, const char **argv, const char *prefix)
+int cmd_replay(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *advance_name_opt = NULL;
 	char *advance_name = NULL;
builtin/rerere.c +1 -1
index 81b65ffa39c..7bccf393c8d 100644
@@ -48,7 +48,7 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
-int cmd_rerere(int argc, const char **argv, const char *prefix)
+int cmd_rerere(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int i, autoupdate = -1, flags = 0;
builtin/reset.c +1 -1
index 5f941fb3a29..a8e293b0c57 100644
@@ -330,7 +330,7 @@ static int git_reset_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_reset(int argc, const char **argv, const char *prefix)
+int cmd_reset(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int reset_type = NONE, update_ref_status = 0, quiet = 0;
 	int no_refresh = 0;
builtin/rev-list.c +1 -1
index 97d077a9943..71bc12ee6b2 100644
@@ -513,7 +513,7 @@ static int try_bitmap_disk_usage(struct rev_info *revs,
 	return 0;
 }
 
-int cmd_rev_list(int argc, const char **argv, const char *prefix)
+int cmd_rev_list(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	struct rev_list_info info;
builtin/rev-parse.c +1 -1
index 4285dc34a7b..ba5bc0facd7 100644
@@ -688,7 +688,7 @@ static void print_path(const char *path, const char *prefix, enum format_type fo
 	free(cwd);
 }
 
-int cmd_rev_parse(int argc, const char **argv, const char *prefix)
+int cmd_rev_parse(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
 	const struct git_hash_algo *output_algo = NULL;
builtin/revert.c +2 -2
index 7bf2b4e11d6..e6be55a2bd9 100644
@@ -261,7 +261,7 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
 	return sequencer_pick_revisions(the_repository, opts);
 }
 
-int cmd_revert(int argc, const char **argv, const char *prefix)
+int cmd_revert(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int res;
@@ -275,7 +275,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
 	return res;
 }
 
-int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
+int cmd_cherry_pick(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int res;
builtin/rm.c +1 -1
index 0e79cbab62b..4fd94f7e7e8 100644
@@ -261,7 +261,7 @@ static struct option builtin_rm_options[] = {
 	OPT_END(),
 };
 
-int cmd_rm(int argc, const char **argv, const char *prefix)
+int cmd_rm(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct lock_file lock_file = LOCK_INIT;
 	int i, ret = 0;
builtin/send-pack.c +1 -1
index 17cae6bbbdf..5479cd5731c 100644
@@ -147,7 +147,7 @@ static int send_pack_config(const char *k, const char *v,
 	return git_default_config(k, v, ctx, cb);
 }
 
-int cmd_send_pack(int argc, const char **argv, const char *prefix)
+int cmd_send_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct refspec rs = REFSPEC_INIT_PUSH;
 	const char *remote_name = NULL;
builtin/shortlog.c +1 -1
index b529608c923..c911383026d 100644
@@ -378,7 +378,7 @@ void shortlog_finish_setup(struct shortlog *log)
 	string_list_sort(&log->trailers);
 }
 
-int cmd_shortlog(int argc, const char **argv, const char *prefix)
+int cmd_shortlog(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct shortlog log = { STRING_LIST_INIT_NODUP };
 	struct rev_info rev;
builtin/show-branch.c +1 -1
index 29237f653d8..800a64fd4c7 100644
@@ -632,7 +632,7 @@ static int parse_reflog_param(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_show_branch(int ac, const char **av, const char *prefix)
+int cmd_show_branch(int ac, const char **av, const char *prefix, struct repository *repo UNUSED)
 {
 	struct commit *rev[MAX_REVS], *commit;
 	char *reflog_msg[MAX_REVS] = {0};
builtin/show-index.c +1 -1
index 540dc3dad1c..952ea798fc1 100644
@@ -11,7 +11,7 @@ static const char *const show_index_usage[] = {
 	NULL
 };
 
-int cmd_show_index(int argc, const char **argv, const char *prefix)
+int cmd_show_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i;
 	unsigned nr;
builtin/show-ref.c +1 -1
index f5899ce9ff7..8d908a03949 100644
@@ -287,7 +287,7 @@ static int exclude_existing_callback(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_show_ref(int argc, const char **argv, const char *prefix)
+int cmd_show_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct exclude_existing_options exclude_existing_opts = {0};
 	struct patterns_options patterns_opts = {0};
builtin/sparse-checkout.c +1 -1
index 2604ab04df5..da9d582b12d 100644
@@ -1030,7 +1030,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
 	return ret;
 }
 
-int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
+int cmd_sparse_checkout(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_sparse_checkout_options[] = {
builtin/stash.c +1 -1
index fcfd97972a4..da90d18f16d 100644
@@ -1871,7 +1871,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
 	return ret;
 }
 
-int cmd_stash(int argc, const char **argv, const char *prefix)
+int cmd_stash(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	pid_t pid = getpid();
 	const char *index_file;
builtin/stripspace.c +1 -1
index e5626e51266..a83ad2b5f30 100644
@@ -29,7 +29,7 @@ enum stripspace_mode {
 	COMMENT_LINES
 };
 
-int cmd_stripspace(int argc, const char **argv, const char *prefix)
+int cmd_stripspace(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	enum stripspace_mode mode = STRIP_DEFAULT;
builtin/submodule--helper.c +1 -1
index 85fb23dee84..1a1fc40e467 100644
@@ -3528,7 +3528,7 @@ cleanup:
 	return ret;
 }
 
-int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
+int cmd_submodule__helper(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	const char *const usage[] = {
builtin/symbolic-ref.c +1 -1
index 81abdd170fe..682f3cf3ae4 100644
@@ -41,7 +41,7 @@ static int check_symref(const char *HEAD, int quiet, int shorten, int recurse, i
 	return 0;
 }
 
-int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
+int cmd_symbolic_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int quiet = 0, delete = 0, shorten = 0, recurse = 1, ret = 0;
 	const char *msg = NULL;
builtin/tag.c +1 -1
index a1fb218512c..925e269f0f4 100644
@@ -457,7 +457,7 @@ static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
 	return check_refname_format(sb->buf, 0);
 }
 
-int cmd_tag(int argc, const char **argv, const char *prefix)
+int cmd_tag(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	struct strbuf ref = STRBUF_INIT;
builtin/unpack-file.c +1 -1
index c129e2bb6cb..366d4743d4c 100644
@@ -25,7 +25,7 @@ static char *create_temp_file(struct object_id *oid)
 	return path;
 }
 
-int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	struct object_id oid;
 
builtin/unpack-objects.c +1 -1
index 08fa2a7a743..c6f9456a0ec 100644
@@ -601,7 +601,7 @@ static void unpack_all(void)
 		die("unresolved deltas left after unpacking");
 }
 
-int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	int i;
 	struct object_id oid;
builtin/update-index.c +1 -1
index 35a1f957adc..c2974b57661 100644
@@ -917,7 +917,7 @@ static enum parse_opt_result reupdate_callback(
 	return 0;
 }
 
-int cmd_update_index(int argc, const char **argv, const char *prefix)
+int cmd_update_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int newfd, entries, has_errors = 0, nul_term_line = 0;
 	enum uc_mode untracked_cache = UC_UNSPECIFIED;
builtin/update-ref.c +1 -1
index 8f31da9a4b7..97f116ed391 100644
@@ -713,7 +713,7 @@ static void update_refs_stdin(void)
 	strbuf_release(&input);
 }
 
-int cmd_update_ref(int argc, const char **argv, const char *prefix)
+int cmd_update_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *refname, *oldval;
 	struct object_id oid, oldoid;
builtin/update-server-info.c +1 -1
index 1dc3971edeb..b09527b2865 100644
@@ -9,7 +9,7 @@ static const char * const update_server_info_usage[] = {
 	NULL
 };
 
-int cmd_update_server_info(int argc, const char **argv, const char *prefix)
+int cmd_update_server_info(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int force = 0;
 	struct option options[] = {
builtin/upload-archive.c +2 -2
index 1b09e5e1aa3..447fbbb90b5 100644
@@ -18,7 +18,7 @@ static const char deadchild[] =
 
 #define MAX_ARGS (64)
 
-int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
+int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct strvec sent_argv = STRVEC_INIT;
 	const char *arg_cmd = "argument ";
@@ -76,7 +76,7 @@ static ssize_t process_input(int child_fd, int band)
 	return sz;
 }
 
-int cmd_upload_archive(int argc, const char **argv, const char *prefix)
+int cmd_upload_archive(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	struct child_process writer = CHILD_PROCESS_INIT;
 
builtin/upload-pack.c +1 -1
index 46d93278d9a..a6fd26d4a7c 100644
@@ -17,7 +17,7 @@ static const char * const upload_pack_usage[] = {
 	NULL
 };
 
-int cmd_upload_pack(int argc, const char **argv, const char *prefix)
+int cmd_upload_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	const char *dir;
 	int strict = 0;
builtin/var.c +1 -1
index e30ff45be1c..8b07a7a6a09 100644
@@ -210,7 +210,7 @@ static int show_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_var(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	const struct git_var *git_var;
 	char *val;
builtin/verify-commit.c +1 -1
index 0d2b9aea2ae..dbf5b315569 100644
@@ -51,7 +51,7 @@ static int verify_commit(const char *name, unsigned flags)
 	return run_gpg_verify((struct commit *)obj, flags);
 }
 
-int cmd_verify_commit(int argc, const char **argv, const char *prefix)
+int cmd_verify_commit(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i = 1, verbose = 0, had_error = 0;
 	unsigned flags = 0;
builtin/verify-pack.c +1 -1
index 011dddd2dc3..1d0a789d19a 100644
@@ -61,7 +61,7 @@ static const char * const verify_pack_usage[] = {
 	NULL
 };
 
-int cmd_verify_pack(int argc, const char **argv, const char *prefix)
+int cmd_verify_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int err = 0;
 	unsigned int flags = 0;
builtin/verify-tag.c +1 -1
index c731e2f87b4..8e81a9a9e05 100644
@@ -19,7 +19,7 @@ static const char * const verify_tag_usage[] = {
 		NULL
 };
 
-int cmd_verify_tag(int argc, const char **argv, const char *prefix)
+int cmd_verify_tag(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED)
 {
 	int i = 1, verbose = 0, had_error = 0;
 	unsigned flags = 0;
builtin/worktree.c +1 -1
index 41e7f6a3271..4c2b9e19217 100644
@@ -1392,7 +1392,7 @@ static int repair(int ac, const char **av, const char *prefix)
 	return rc;
 }
 
-int cmd_worktree(int ac, const char **av, const char *prefix)
+int cmd_worktree(int ac, const char **av, const char *prefix, struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
builtin/write-tree.c +1 -1
index 8c75b4609b5..91b80e05d3a 100644
@@ -19,7 +19,7 @@ static const char * const write_tree_usage[] = {
 	NULL
 };
 
-int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
+int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix, struct repository *repo UNUSED)
 {
 	int flags = 0, ret;
 	const char *tree_prefix = NULL;
git.c +8 -6
index 9a618a2740f..0ea6e351dfd 100644
@@ -31,7 +31,7 @@
 
 struct cmd_struct {
 	const char *cmd;
-	int (*fn)(int, const char **, const char *);
+	int (*fn)(int, const char **, const char *, struct repository *);
 	unsigned int option;
 };
 
@@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
 	return ret;
 }
 
-static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
+static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
 {
 	int status, help;
 	struct stat st;
@@ -479,9 +479,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	trace_argv_printf(argv, "trace: built-in: git");
 	trace2_cmd_name(p->cmd);
 
-	validate_cache_entries(the_repository->index);
-	status = p->fn(argc, argv, prefix);
-	validate_cache_entries(the_repository->index);
+	validate_cache_entries(repo->index);
+
+	status = p->fn(argc, argv, prefix, startup_info->have_repository? repo: NULL) ;
+
+	validate_cache_entries(repo->index);
 
 	if (status)
 		return status;
@@ -736,7 +738,7 @@ static void handle_builtin(int argc, const char **argv)
 
 	builtin = get_builtin(cmd);
 	if (builtin)
-		exit(run_builtin(builtin, argc, argv));
+		exit(run_builtin(builtin, argc, argv, the_repository));
 	strvec_clear(&args);
 }
 
help.c +2 -1
index c03863f2265..e7cdfab6432 100644
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "prompt.h"
 #include "fsmonitor-ipc.h"
+#include "repository.h"
 
 #ifndef NO_CURL
 #include "git-curl-compat.h" /* For LIBCURL_VERSION only */
@@ -775,7 +776,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
 	}
 }
 
-int cmd_version(int argc, const char **argv, const char *prefix)
+int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	int build_options = 0;
Signature · 1 line
gitgitgadget
#4 lore raw

PATCH 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it where necessary to individual builtins/*. The next step will be to migrate each builtin from having to use the_repository.

---
 builtin.h                          | 8 --------
 builtin/add.c                      | 2 +-
 builtin/am.c                       | 1 +
 builtin/apply.c                    | 1 +
 builtin/archive.c                  | 1 +
 builtin/bisect.c                   | 1 +
 builtin/blame.c                    | 2 +-
 builtin/branch.c                   | 3 ++-
 builtin/bugreport.c                | 1 +
 builtin/bundle.c                   | 1 +
 builtin/cat-file.c                 | 3 ++-
 builtin/check-attr.c               | 1 +
 builtin/check-ignore.c             | 1 +
 builtin/check-mailmap.c            | 1 +
 builtin/checkout--worker.c         | 1 +
 builtin/checkout-index.c           | 1 +
 builtin/checkout.c                 | 1 +
 builtin/clean.c                    | 2 +-
 builtin/clone.c                    | 3 ++-
 builtin/column.c                   | 2 ++
 builtin/commit-graph.c             | 1 +
 builtin/commit-tree.c              | 1 +
 builtin/commit.c                   | 3 ++-
 builtin/config.c                   | 1 +
 builtin/count-objects.c            | 2 +-
 builtin/credential-cache--daemon.c | 1 +
 builtin/credential-store.c         | 1 +
 builtin/credential.c               | 2 ++
 builtin/describe.c                 | 1 +
 builtin/diff-files.c               | 1 +
 builtin/diff-index.c               | 1 +
 builtin/diff-tree.c                | 1 +
 builtin/diff.c                     | 3 ++-
 builtin/difftool.c                 | 3 ++-
 builtin/fast-export.c              | 2 ++
 builtin/fast-import.c              | 1 +
 builtin/fetch-pack.c               | 1 +
 builtin/fetch.c                    | 1 +
 builtin/fmt-merge-msg.c            | 1 +
 builtin/for-each-ref.c             | 1 +
 builtin/for-each-repo.c            | 1 +
 builtin/fsck.c                     | 1 +
 builtin/fsmonitor--daemon.c        | 1 +
 builtin/gc.c                       | 2 +-
 builtin/grep.c                     | 1 +
 builtin/hash-object.c              | 2 ++
 builtin/help.c                     | 2 ++
 builtin/hook.c                     | 1 +
 builtin/index-pack.c               | 1 +
 builtin/interpret-trailers.c       | 2 +-
 builtin/log.c                      | 1 +
 builtin/ls-files.c                 | 1 +
 builtin/ls-remote.c                | 1 +
 builtin/ls-tree.c                  | 2 ++
 builtin/merge-base.c               | 1 +
 builtin/merge-file.c               | 1 +
 builtin/merge-index.c              | 1 +
 builtin/merge-ours.c               | 1 +
 builtin/merge-recursive.c          | 1 +
 builtin/merge-tree.c               | 1 +
 builtin/merge.c                    | 3 ++-
 builtin/mktag.c                    | 1 +
 builtin/mktree.c                   | 2 ++
 builtin/multi-pack-index.c         | 1 +
 builtin/mv.c                       | 1 +
 builtin/name-rev.c                 | 1 +
 builtin/notes.c                    | 2 +-
 builtin/pack-objects.c             | 1 +
 builtin/pack-redundant.c           | 1 +
 builtin/pack-refs.c                | 1 +
 builtin/patch-id.c                 | 1 +
 builtin/prune.c                    | 1 +
 builtin/pull.c                     | 1 +
 builtin/push.c                     | 1 +
 builtin/range-diff.c               | 1 +
 builtin/read-tree.c                | 2 +-
 builtin/rebase.c                   | 3 ++-
 builtin/receive-pack.c             | 1 +
 builtin/reflog.c                   | 1 +
 builtin/refs.c                     | 1 +
 builtin/remote.c                   | 1 +
 builtin/repack.c                   | 1 +
 builtin/replace.c                  | 1 +
 builtin/replay.c                   | 1 +
 builtin/rerere.c                   | 1 +
 builtin/reset.c                    | 3 ++-
 builtin/rev-list.c                 | 1 +
 builtin/rev-parse.c                | 3 ++-
 builtin/revert.c                   | 1 +
 builtin/rm.c                       | 2 +-
 builtin/send-pack.c                | 1 +
 builtin/shortlog.c                 | 1 +
 builtin/show-branch.c              | 1 +
 builtin/show-index.c               | 1 +
 builtin/show-ref.c                 | 1 +
 builtin/sparse-checkout.c          | 1 +
 builtin/stash.c                    | 1 +
 builtin/stripspace.c               | 1 +
 builtin/submodule--helper.c        | 1 +
 builtin/symbolic-ref.c             | 1 +
 builtin/tag.c                      | 3 ++-
 builtin/unpack-file.c              | 1 +
 builtin/unpack-objects.c           | 1 +
 builtin/update-index.c             | 1 +
 builtin/update-ref.c               | 1 +
 builtin/update-server-info.c       | 1 +
 builtin/upload-archive.c           | 1 +
 builtin/var.c                      | 2 ++
 builtin/verify-commit.c            | 1 +
 builtin/verify-pack.c              | 1 +
 builtin/verify-tag.c               | 2 ++
 builtin/worktree.c                 | 1 +
 builtin/write-tree.c               | 2 +-
 113 files changed, 132 insertions(+), 29 deletions(-)
builtin.h +0 -8
index fc6fc8ffed8..f7b166b3348 100644
@@ -1,14 +1,6 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
-/*
- * TODO: Almost all of our builtins access `the_repository` by necessity
- * because they do not get passed a pointer to it. We should adapt the function
- * signature of those main functions to accept a `struct repository *` and then
- * remove the macro here.
- */
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "repository.h"
 
builtin/add.c +1 -1
index 3b9bc93ed9a..dac832df3e7 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Linus Torvalds
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/am.c +1 -0
index 830c295314b..0546aee12ad 100644
@@ -4,6 +4,7 @@
  * Based on git-am.sh by Junio C Hamano.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
builtin/apply.c +1 -0
index 923ce992bdd..456b1498067 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "repository.h"
builtin/archive.c +1 -0
index 21e5e3b877b..e1743b93ac0 100644
@@ -2,6 +2,7 @@
  * Copyright (c) 2006 Franck Bui-Huu
  * Copyright (c) 2006 Rene Scharfe
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "archive.h"
 #include "gettext.h"
builtin/bisect.c +1 -0
index 8cf6167df61..23af9a3ae4d 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "copy.h"
 #include "environment.h"
builtin/blame.c +1 -1
index 522f564d6b0..2d263074e90 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2006, 2014 by its authors
  * See COPYING for licensing conditions
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "color.h"
builtin/branch.c +2 -1
index e20420059a2..8a5424c836f 100644
@@ -4,8 +4,9 @@
  * Copyright (c) 2006 Kristian Høgsberg <[email protected]>
  * Based on git-branch.sh by Junio C Hamano.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "color.h"
 #include "editor.h"
builtin/bugreport.c +1 -0
index 5269f073d59..428d3a26f80 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "editor.h"
builtin/bundle.c +1 -0
index e26c1f7d4a7..f54559a54ea 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
builtin/cat-file.c +2 -1
index 6e6f134eab1..34888633e4f 100644
@@ -3,8 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "convert.h"
 #include "diff.h"
builtin/check-attr.c +1 -0
index 0f180350bec..704da2743bf 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "attr.h"
builtin/check-ignore.c +1 -0
index 4067127c8b4..319676e2b8e 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
builtin/check-mailmap.c +1 -0
index 07ab8fa9b3c..18733e78fb6 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/checkout--worker.c +1 -0
index 61758a11d5d..369097aa43e 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "entry.h"
builtin/checkout-index.c +1 -0
index dcf58a4fe13..118845bcc25 100644
@@ -4,6 +4,7 @@
  * Copyright (C) 2005 Linus Torvalds
  *
  */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "config.h"
builtin/checkout.c +1 -0
index c43bba082f5..74052571026 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "branch.h"
builtin/clean.c +1 -1
index d4e00f4f3af..f3eb6a0886e 100644
@@ -5,7 +5,7 @@
  *
  * Based on git-clean.sh by Pavel Roskin
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/clone.c +2 -1
index fb820861cd9..9772a9723e7 100644
@@ -7,8 +7,9 @@
  *
  * Clone a repository into a different directory that does not yet exist.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
builtin/column.c +2 -0
index ca2b522284e..e3e95a9ee20 100644
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/commit-graph.c +1 -0
index 67e27ef0cd7..83e566de652 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "commit.h"
 #include "config.h"
builtin/commit-tree.c +1 -0
index 42f88d007ff..2e7e2ecb203 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/commit.c +2 -1
index 27c807cde08..141c8d85620 100644
@@ -4,8 +4,9 @@
  * Copyright (c) 2007 Kristian Høgsberg <[email protected]>
  * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "advice.h"
 #include "config.h"
 #include "lockfile.h"
builtin/config.c +1 -0
index 8604986fa98..69b2e857888 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/count-objects.c +1 -1
index 74225ff2488..7d9d7cd94ab 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
builtin/credential-cache--daemon.c +1 -0
index 0c4d29a0745..9cda9f30739 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
builtin/credential-store.c +1 -0
index e79d72d9695..6dfa66b300e 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/credential.c +2 -0
index 9235fbf1977..73510946cac 100644
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "credential.h"
 #include "builtin.h"
builtin/describe.c +1 -0
index 32ab17de651..d8ea2e8fdf8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
builtin/diff-files.c +1 -0
index 93a3df766ad..b2e3628d9ef 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
builtin/diff-index.c +1 -0
index 645d2fba359..15e0dcf60f8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
builtin/diff-tree.c +1 -0
index 0d17708d2a3..e01caea94d7 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
builtin/diff.c +2 -1
index ebf71aa5592..bf3b7ab3350 100644
@@ -3,8 +3,9 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "ewah/ewok.h"
 #include "lockfile.h"
builtin/difftool.c +2 -1
index 94f3bf72a7c..f1a2c7e7e1e 100644
@@ -11,8 +11,9 @@
  *
  * Copyright (C) 2016 Johannes Schindelin
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "abspath.h"
 #include "config.h"
 #include "copy.h"
builtin/fast-export.c +2 -0
index 37482785b81..d2e1a5028d3 100644
@@ -3,7 +3,9 @@
  *
  * Copyright (C) 2007 Johannes E. Schindelin
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
builtin/fast-import.c +1 -0
index 36b76490e1e..e0df21bf5fe 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
builtin/fetch-pack.c +1 -0
index fcabd1906d4..83b131d5c5d 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/fetch.c +1 -0
index ccdb409da43..b4bd8d89851 100644
@@ -1,6 +1,7 @@
 /*
  * "git fetch"
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/fmt-merge-msg.c +1 -0
index 0a9c2008429..af4264159af 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "fmt-merge-msg.h"
builtin/for-each-ref.c +1 -0
index 70391638a3d..aeba8e69408 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "commit.h"
 #include "config.h"
builtin/for-each-repo.c +1 -0
index 6b2935ae140..47a97653474 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/fsck.c +1 -0
index 2b69c963b2e..bc6046c3c73 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/fsmonitor--daemon.c +1 -0
index 93f4a60ca22..1bd7cf41ffd 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/gc.c +1 -1
index 462dacb0bdb..2cca94afce4 100644
@@ -9,7 +9,7 @@
  *
  * Copyright (c) 2006 Shawn O. Pearce
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "date.h"
builtin/grep.c +1 -0
index 98eea1f4dc5..b0b149d81bf 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
builtin/hash-object.c +2 -0
index 59a48345394..293fc2ab879 100644
@@ -4,7 +4,9 @@
  * Copyright (C) Linus Torvalds, 2005
  * Copyright (C) Junio C Hamano, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "abspath.h"
 #include "config.h"
 #include "gettext.h"
builtin/help.c +2 -0
index 4efdccfb7fb..557d2b645e6 100644
@@ -1,6 +1,8 @@
+
 /*
  * Builtin help command
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "exec-cmd.h"
builtin/hook.c +1 -0
index 2aa6476f8fc..1b71eb021c2 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/index-pack.c +1 -0
index 64754da036d..a0acfad823d 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "delta.h"
builtin/interpret-trailers.c +1 -1
index 79da472e8eb..2e05551b4dd 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013, 2014 Christian Couder <[email protected]>
  *
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
builtin/log.c +1 -0
index c9018e89e55..5353ec02df7 100644
@@ -4,6 +4,7 @@
  * (C) Copyright 2006 Linus Torvalds
  *		 2006 Junio Hamano
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/ls-files.c +1 -0
index 5185f264e8d..5496536b0ff 100644
@@ -5,6 +5,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "repository.h"
 #include "config.h"
builtin/ls-remote.c +1 -0
index ce826d32686..de282999059 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/ls-tree.c +2 -0
index f91361ca788..57a9a00c348 100644
@@ -3,7 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
builtin/merge-base.c +1 -0
index d5aef8b32c0..b6b28d60df2 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
builtin/merge-file.c +1 -0
index a538edf2a46..a5a6d821f20 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "diff.h"
builtin/merge-index.c +1 -0
index 39870e14bfa..7ca6af69539 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "hex.h"
 #include "read-cache-ll.h"
builtin/merge-ours.c +1 -0
index 391c767e122..258d5560a17 100644
@@ -7,6 +7,7 @@
  *
  * Pretend we resolved the heads, but declare our tree trumps everybody else.
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
builtin/merge-recursive.c +1 -0
index cd2b4d9a721..c7ec78b0d66 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "gettext.h"
builtin/merge-tree.c +1 -0
index e69ed337f46..f247480b434 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
builtin/merge.c +2 -1
index 4e817f6e91f..6427b7c4a8b 100644
@@ -5,8 +5,9 @@
  *
  * Based on git-merge.sh by Junio C Hamano.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
builtin/mktag.c +1 -0
index cc3f1b7c5bb..d4bcebb0abf 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/mktree.c +2 -0
index 1c43360b50c..f52015a5e81 100644
@@ -3,7 +3,9 @@
  *
  * Copyright (c) Junio C Hamano, 2006, 2009
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "gettext.h"
 #include "hex.h"
 #include "quote.h"
builtin/multi-pack-index.c +1 -0
index 91324a5581d..86f974bc6ae 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/mv.c +1 -0
index 3069d1d9ce8..1123c3d5f1a 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "abspath.h"
builtin/name-rev.c +1 -0
index f46f5546629..8bccc3ebf59 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "environment.h"
 #include "gettext.h"
builtin/notes.c +1 -1
index 2f8e896283a..9b894ab85f3 100644
@@ -6,7 +6,7 @@
  * Based on git-notes.sh by Johannes Schindelin,
  * and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "editor.h"
builtin/pack-objects.c +1 -0
index 702d10ea86b..cf255e537d0 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "environment.h"
 #include "gettext.h"
builtin/pack-redundant.c +1 -0
index 42d367c95d1..690dbe233f9 100644
@@ -5,6 +5,7 @@
 * This file is licensed under the GPL v2.
 *
 */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "gettext.h"
builtin/pack-refs.c +1 -0
index c61e876216a..ea155d4f076 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/patch-id.c +1 -0
index 4449c44580a..7853f052ce1 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
builtin/prune.c +1 -0
index ed532fab0a5..289344efdb8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
builtin/pull.c +1 -0
index 906c02e5a97..60ac523e4f4 100644
@@ -6,6 +6,7 @@
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/push.c +1 -0
index a6b7fcd9538..5d5e4899bb8 100644
@@ -1,6 +1,7 @@
 /*
  * "git push"
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "branch.h"
builtin/range-diff.c +1 -0
index 30a5b003bab..82a44684805 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
builtin/read-tree.c +1 -1
index 89fa0b728d7..b08627980da 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/rebase.c +2 -1
index 20a0a324aff..232b1fecffd 100644
@@ -3,8 +3,9 @@
  *
  * Copyright (c) 2018 Pratik Karki
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
builtin/receive-pack.c +1 -0
index 74677ff1a24..db23fff7dac 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "repository.h"
builtin/reflog.c +1 -0
index 1eab96aca98..d946d1b2245 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/refs.c +1 -0
index 355e0abce76..aa020eef7f8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "fsck.h"
builtin/remote.c +1 -0
index d24d4966ccb..cfd5b891181 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/repack.c +1 -0
index ea06f0b4a0f..8a7e8e80af1 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
builtin/replace.c +1 -0
index 9c6d846c497..d157c237d57 100644
@@ -7,6 +7,7 @@
  * and Carlos Rica <[email protected]> that was itself based on
  * git-tag.sh and mktag.c by Linus Torvalds.
  */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "config.h"
builtin/replay.c +1 -0
index 66f417aab78..feb2e0192c6 100644
@@ -4,6 +4,7 @@
 
 #include "git-compat-util.h"
 
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "environment.h"
 #include "hex.h"
builtin/rerere.c +1 -0
index 7bccf393c8d..2a33c57c481 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/reset.c +2 -1
index a8e293b0c57..956d716c787 100644
@@ -7,8 +7,9 @@
  *
  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "advice.h"
 #include "config.h"
 #include "environment.h"
builtin/rev-list.c +1 -0
index 71bc12ee6b2..c90c7e77a11 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
builtin/rev-parse.c +2 -1
index ba5bc0facd7..b84b2ef642a 100644
@@ -3,8 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "abspath.h"
 #include "config.h"
 #include "commit.h"
builtin/revert.c +1 -0
index e6be55a2bd9..e4f71b5fbf0 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "parse-options.h"
builtin/rm.c +1 -1
index 4fd94f7e7e8..6f9638ca079 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds 2006
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/send-pack.c +1 -0
index 5479cd5731c..02654613ed5 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "hex.h"
builtin/shortlog.c +1 -0
index c911383026d..f12f7ad0a53 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
builtin/show-branch.c +1 -0
index 800a64fd4c7..27207e515be 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
builtin/show-index.c +1 -0
index 952ea798fc1..b96a28531cd 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hash.h"
builtin/show-ref.c +1 -0
index 8d908a03949..47831bf793b 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/sparse-checkout.c +1 -0
index da9d582b12d..138cece3ac9 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
builtin/stash.c +1 -0
index da90d18f16d..557bbcc6740 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/stripspace.c +1 -0
index a83ad2b5f30..336194a93f4 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
builtin/submodule--helper.c +1 -0
index 1a1fc40e467..970d0b93022 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
builtin/symbolic-ref.c +1 -0
index 682f3cf3ae4..a13dc8b35a2 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/tag.c +2 -1
index 925e269f0f4..757fd390b29 100644
@@ -5,8 +5,9 @@
  *                    Carlos Rica <[email protected]>
  * Based on git-tag.sh and mktag.c by Linus Torvalds.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "advice.h"
 #include "config.h"
 #include "editor.h"
builtin/unpack-file.c +1 -0
index 366d4743d4c..f4ba988711c 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "hex.h"
builtin/unpack-objects.c +1 -0
index c6f9456a0ec..51075fc0e54 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "bulk-checkin.h"
 #include "config.h"
builtin/update-index.c +1 -0
index c2974b57661..df1ee60dd2d 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "bulk-checkin.h"
builtin/update-ref.c +1 -0
index 97f116ed391..ede553a34c8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/update-server-info.c +1 -0
index b09527b2865..ce0784f390b 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/upload-archive.c +1 -0
index 447fbbb90b5..f7f89771827 100644
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "archive.h"
 #include "path.h"
builtin/var.c +2 -0
index 8b07a7a6a09..07785b3dd1b 100644
@@ -3,7 +3,9 @@
  *
  * Copyright (C) Eric Biederman, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "attr.h"
 #include "config.h"
 #include "editor.h"
builtin/verify-commit.c +1 -0
index dbf5b315569..57fa5657add 100644
@@ -5,6 +5,7 @@
  *
  * Based on git-verify-tag
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/verify-pack.c +1 -0
index 1d0a789d19a..323466af865 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/verify-tag.c +2 -0
index 8e81a9a9e05..818c373cc63 100644
@@ -5,7 +5,9 @@
  *
  * Based on git-verify-tag.sh
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "gettext.h"
 #include "tag.h"
builtin/worktree.c +1 -0
index 4c2b9e19217..e4f024cf2db 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
builtin/write-tree.c +1 -1
index 91b80e05d3a..47a2837cb8e 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
Signature · 1 line
gitgitgadget
#8 lore raw

PATCH 3/3 add: pass in repo variable instead of global the_repository

In reply to John Cai via GitGitGadget

From: John Cai <[email protected]>

With the repository variable available in the builtin function as an argument, pass this down into helper functions instead of using the global the_repository.

---
 builtin/add.c    | 97 +++++++++++++++++++++++++-----------------------
 builtin/commit.c |  2 +-
 commit.h         |  3 +-
 3 files changed, 53 insertions(+), 49 deletions(-)
builtin/add.c +50 -47
index dac832df3e7..a68fd7c8313 100644
@@ -36,24 +36,27 @@ static int pathspec_file_nul;
 static int include_sparse;
 static const char *pathspec_from_file;
 
-static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
+static int chmod_pathspec(struct pathspec *pathspec,
+			  char flip,
+			  int show_only,
+			  struct repository *repo)
 {
 	int i, ret = 0;
 
-	for (i = 0; i < the_repository->index->cache_nr; i++) {
-		struct cache_entry *ce = the_repository->index->cache[i];
+	for (i = 0; i < repo->index->cache_nr; i++) {
+		struct cache_entry *ce = repo->index->cache[i];
 		int err;
 
 		if (!include_sparse &&
 		    (ce_skip_worktree(ce) ||
-		     !path_in_sparse_checkout(ce->name, the_repository->index)))
+		     !path_in_sparse_checkout(ce->name, repo->index)))
 			continue;
 
-		if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
+		if (pathspec && !ce_path_match(repo->index, ce, pathspec, NULL))
 			continue;
 
 		if (!show_only)
-			err = chmod_index_entry(the_repository->index, ce, flip);
+			err = chmod_index_entry(repo->index, ce, flip);
 		else
 			err = S_ISREG(ce->ce_mode) ? 0 : -1;
 
@@ -64,31 +67,31 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 	return ret;
 }
 
-static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
+static int renormalize_tracked_files(const struct pathspec *pathspec, int flags, struct repository *repo)
 {
 	int i, retval = 0;
 
-	for (i = 0; i < the_repository->index->cache_nr; i++) {
-		struct cache_entry *ce = the_repository->index->cache[i];
+	for (i = 0; i < repo->index->cache_nr; i++) {
+		struct cache_entry *ce = repo->index->cache[i];
 
 		if (!include_sparse &&
 		    (ce_skip_worktree(ce) ||
-		     !path_in_sparse_checkout(ce->name, the_repository->index)))
+		     !path_in_sparse_checkout(ce->name, repo->index)))
 			continue;
 		if (ce_stage(ce))
 			continue; /* do not touch unmerged paths */
 		if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
 			continue; /* do not touch non blobs */
-		if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
+		if (pathspec && !ce_path_match(repo->index, ce, pathspec, NULL))
 			continue;
-		retval |= add_file_to_index(the_repository->index, ce->name,
+		retval |= add_file_to_index(repo->index, ce->name,
 					    flags | ADD_CACHE_RENORMALIZE);
 	}
 
 	return retval;
 }
 
-static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix)
+static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix, struct repository *repo)
 {
 	char *seen;
 	int i;
@@ -100,16 +103,16 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
 	i = dir->nr;
 	while (--i >= 0) {
 		struct dir_entry *entry = *src++;
-		if (dir_path_match(the_repository->index, entry, pathspec, prefix, seen))
+		if (dir_path_match(repo->index, entry, pathspec, prefix, seen))
 			*dst++ = entry;
 	}
 	dir->nr = dst - dir->entries;
-	add_pathspec_matches_against_index(pathspec, the_repository->index, seen,
+	add_pathspec_matches_against_index(pathspec, repo->index, seen,
 					   PS_IGNORE_SKIP_WORKTREE);
 	return seen;
 }
 
-static int refresh(int verbose, const struct pathspec *pathspec)
+static int refresh(int verbose, const struct pathspec *pathspec, struct repository *repo)
 {
 	char *seen;
 	int i, ret = 0;
@@ -119,14 +122,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)
 		    (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
 
 	seen = xcalloc(pathspec->nr, 1);
-	refresh_index(the_repository->index, flags, pathspec, seen,
+	refresh_index(repo->index, flags, pathspec, seen,
 		      _("Unstaged changes after refreshing the index:"));
 	for (i = 0; i < pathspec->nr; i++) {
 		if (!seen[i]) {
 			const char *path = pathspec->items[i].original;
 
 			if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
-			    !path_in_sparse_checkout(path, the_repository->index)) {
+			    !path_in_sparse_checkout(path, repo->index)) {
 				string_list_append(&only_match_skip_worktree,
 						   pathspec->items[i].original);
 			} else {
@@ -147,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)
 	return ret;
 }
 
-int interactive_add(const char **argv, const char *prefix, int patch)
+int interactive_add(const char **argv, const char *prefix, int patch, struct repository *repo)
 {
 	struct pathspec pathspec;
 	int ret;
@@ -159,15 +162,15 @@ int interactive_add(const char **argv, const char *prefix, int patch)
 		       prefix, argv);
 
 	if (patch)
-		ret = !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
+		ret = !!run_add_p(repo, ADD_P_ADD, NULL, &pathspec);
 	else
-		ret = !!run_add_i(the_repository, &pathspec);
+		ret = !!run_add_i(repo, &pathspec);
 
 	clear_pathspec(&pathspec);
 	return ret;
 }
 
-static int edit_patch(int argc, const char **argv, const char *prefix)
+static int edit_patch(int argc, const char **argv, const char *prefix, struct repository *repo)
 {
 	char *file = git_pathdup("ADD_EDIT.patch");
 	struct child_process child = CHILD_PROCESS_INIT;
@@ -177,10 +180,10 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
 
 	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
 
-	if (repo_read_index(the_repository) < 0)
+	if (repo_read_index(repo) < 0)
 		die(_("could not read the index"));
 
-	repo_init_revisions(the_repository, &rev, prefix);
+	repo_init_revisions(repo, &rev, prefix);
 	rev.diffopt.context = 7;
 
 	argc = setup_revisions(argc, argv, &rev, NULL);
@@ -318,7 +321,7 @@ static void check_embedded_repo(const char *path)
 	strbuf_release(&name);
 }
 
-static int add_files(struct dir_struct *dir, int flags)
+static int add_files(struct dir_struct *dir, int flags, struct repository *repo)
 {
 	int i, exit_status = 0;
 	struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP;
@@ -334,12 +337,12 @@ static int add_files(struct dir_struct *dir, int flags)
 
 	for (i = 0; i < dir->nr; i++) {
 		if (!include_sparse &&
-		    !path_in_sparse_checkout(dir->entries[i]->name, the_repository->index)) {
+		    !path_in_sparse_checkout(dir->entries[i]->name, repo->index)) {
 			string_list_append(&matched_sparse_paths,
 					   dir->entries[i]->name);
 			continue;
 		}
-		if (add_file_to_index(the_repository->index, dir->entries[i]->name, flags)) {
+		if (add_file_to_index(repo->index, dir->entries[i]->name, flags)) {
 			if (!ignore_add_errors)
 				die(_("adding files failed"));
 			exit_status = 1;
@@ -358,7 +361,7 @@ static int add_files(struct dir_struct *dir, int flags)
 	return exit_status;
 }
 
-int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repo)
 {
 	int exit_status = 0;
 	struct pathspec pathspec;
@@ -381,13 +384,13 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 			die(_("options '%s' and '%s' cannot be used together"), "--dry-run", "--interactive/--patch");
 		if (pathspec_from_file)
 			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--interactive/--patch");
-		exit(interactive_add(argv + 1, prefix, patch_interactive));
+		exit(interactive_add(argv + 1, prefix, patch_interactive, repo));
 	}
 
 	if (edit_interactive) {
 		if (pathspec_from_file)
 			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--edit");
-		return(edit_patch(argc, argv, prefix));
+		return(edit_patch(argc, argv, prefix, repo));
 	}
 	argc--;
 	argv++;
@@ -410,10 +413,10 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 	add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
 	require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
 
-	prepare_repo_settings(the_repository);
-	the_repository->settings.command_requires_full_index = 0;
+	prepare_repo_settings(repo);
+	repo->settings.command_requires_full_index = 0;
 
-	repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
+	repo_hold_locked_index(repo, &lock_file, LOCK_DIE_ON_ERROR);
 
 	/*
 	 * Check the "pathspec '%s' did not match any files" block
@@ -454,11 +457,11 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 		 (!(addremove || take_worktree_changes)
 		  ? ADD_CACHE_IGNORE_REMOVAL : 0));
 
-	if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
+	if (repo_read_index_preload(repo, &pathspec, 0) < 0)
 		die(_("index file corrupt"));
 
-	die_in_unpopulated_submodule(the_repository->index, prefix);
-	die_path_inside_submodule(the_repository->index, &pathspec);
+	die_in_unpopulated_submodule(repo->index, prefix);
+	die_path_inside_submodule(repo->index, &pathspec);
 
 	if (add_new_files) {
 		int baselen;
@@ -470,13 +473,13 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 		}
 
 		/* This picks up the paths that are not tracked */
-		baselen = fill_directory(&dir, the_repository->index, &pathspec);
+		baselen = fill_directory(&dir, repo->index, &pathspec);
 		if (pathspec.nr)
-			seen = prune_directory(&dir, &pathspec, baselen);
+			seen = prune_directory(&dir, &pathspec, baselen, repo);
 	}
 
 	if (refresh_only) {
-		exit_status |= refresh(verbose, &pathspec);
+		exit_status |= refresh(verbose, &pathspec, repo);
 		goto finish;
 	}
 
@@ -487,7 +490,7 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 
 		if (!seen)
 			seen = find_pathspecs_matching_against_index(&pathspec,
-					the_repository->index, PS_IGNORE_SKIP_WORKTREE);
+					repo->index, PS_IGNORE_SKIP_WORKTREE);
 
 		/*
 		 * file_exists() assumes exact match
@@ -523,8 +526,8 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 			    !file_exists(path)) {
 				if (ignore_missing) {
 					int dtype = DT_UNKNOWN;
-					if (is_excluded(&dir, the_repository->index, path, &dtype))
-						dir_add_ignored(&dir, the_repository->index,
+					if (is_excluded(&dir, repo->index, path, &dtype))
+						dir_add_ignored(&dir, repo->index,
 								path, pathspec.items[i].len);
 				} else
 					die(_("pathspec '%s' did not match any files"),
@@ -547,9 +550,9 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 
 	ps_matched = xcalloc(pathspec.nr, 1);
 	if (add_renormalize)
-		exit_status |= renormalize_tracked_files(&pathspec, flags);
+		exit_status |= renormalize_tracked_files(&pathspec, flags, repo);
 	else
-		exit_status |= add_files_to_cache(the_repository, prefix,
+		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
 						  include_sparse, flags);
 
@@ -558,14 +561,14 @@ int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
 		exit(128);
 
 	if (add_new_files)
-		exit_status |= add_files(&dir, flags);
+		exit_status |= add_files(&dir, flags, repo);
 
 	if (chmod_arg && pathspec.nr)
-		exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
+		exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only, repo);
 	end_odb_transaction();
 
 finish:
-	if (write_locked_index(the_repository->index, &lock_file,
+	if (write_locked_index(repo->index, &lock_file,
 			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
 		die(_("unable to write new index file"));
 
builtin/commit.c +1 -1
index 141c8d85620..d9ee6502448 100644
@@ -396,7 +396,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
 		setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
 
-		if (interactive_add(argv, prefix, patch_interactive) != 0)
+		if (interactive_add(argv, prefix, patch_interactive, the_repository) != 0)
 			die(_("interactive add failed"));
 
 		the_repository->index_file = old_repo_index_file;
commit.h +2 -1
index 0e5fce543c2..92fef717be1 100644
@@ -2,6 +2,7 @@
 #define COMMIT_H
 
 #include "object.h"
+#include "repository.h"
 
 struct signature_check;
 struct strbuf;
@@ -253,7 +254,7 @@ struct oid_array;
 struct ref;
 int for_each_commit_graft(each_commit_graft_fn, void *);
 
-int interactive_add(const char **argv, const char *prefix, int patch);
+int interactive_add(const char **argv, const char *prefix, int patch, struct repository *repo);
 
 struct commit_extra_header {
 	struct commit_extra_header *next;
Signature · 1 line
gitgitgadget
#10 lore raw
In reply to John Cai via GitGitGadget
Quoted 11 lines · John Cai via GitGitGadget

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.

#5 lore raw

Re: [PATCH 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to John Cai via GitGitGadget
Quoted 9 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it where necessary to individual builtins/*. The next step will be to migrate each builtin from having to use the_repository.

---

We at least need the following fix-up in order to play nice with others, specifically Patrick's ps/environ-wo-the-repository, when the topic is merged to 'seen'.

Thanks.

builtin/init-db.c +2 -0
index b0ac318cc6..cb5fc340a2 100644
@@ -3,6 +3,8 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
builtin/mailinfo.c +2 -0
index d883ccf459..aed1199710 100644
@@ -2,6 +2,8 @@
  * Another stupid program, this one parsing the headers of an
  * email to figure out authorship and subject
  */
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
#2 lore raw

Re: [PATCH 1/3] builtin: add a repository parameter for builtin functions

In reply to John Cai via GitGitGadget
Quoted 6 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

builtin/add.c +0 -0
index 40b61ef90d9..3b9bc93ed9a 100644

builtin/add.c static int add_files(struct dir_struct *dir, int flags) · line 364

Quoted 8 lines
builtin/add.c +1 -1
@@ -358,7 +358,7 @@ static int add_files(struct dir_struct *dir, int flags)
 	return exit_status;
 }
 
-int cmd_add(int argc, const char **argv, const char *prefix)
+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	int exit_status = 0;
 	struct pathspec pathspec;

Nit: all of these are now overly long as we typically wrap at 80 characters.

Quoted 27 lines
git.c +2 -3
index 9a618a2740f..0ea6e351dfd 100644
@@ -31,7 +31,7 @@
 
 struct cmd_struct {
 	const char *cmd;
-	int (*fn)(int, const char **, const char *);
+	int (*fn)(int, const char **, const char *, struct repository *);
 	unsigned int option;
 };
 
@@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
 	return ret;
 }
 
-static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
+static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
 {
 	int status, help;
 	struct stat st;
@@ -479,9 +479,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	trace_argv_printf(argv, "trace: built-in: git");
 	trace2_cmd_name(p->cmd);
 
-	validate_cache_entries(the_repository->index);

git.c static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · line 489

Quoted 10 lines
git.c +5 -2
-	status = p->fn(argc, argv, prefix);
-	validate_cache_entries(the_repository->index);
+	validate_cache_entries(repo->index);
+
+	status = p->fn(argc, argv, prefix, startup_info->have_repository? repo: NULL) ;
+
+	validate_cache_entries(repo->index);
 
 	if (status)
 		return status;

Looks sensible.

git.c static void handle_builtin(int argc, const char **argv) · line 744

Quoted 9 lines
git.c +1 -1
@@ -736,7 +738,7 @@ static void handle_builtin(int argc, const char **argv)
 
 	builtin = get_builtin(cmd);
 	if (builtin)
-		exit(run_builtin(builtin, argc, argv));
+		exit(run_builtin(builtin, argc, argv, the_repository));
 	strvec_clear(&args);
 }
 

Why don't we need a check for startup_info->have_repository here?

help.c line 22

Quoted 12 lines
help.c +1 -0
index c03863f2265..e7cdfab6432 100644
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "prompt.h"
 #include "fsmonitor-ipc.h"
+#include "repository.h"
 
 #ifndef NO_CURL
 #include "git-curl-compat.h" /* For LIBCURL_VERSION only */

The include shouldn't be necessary. You can instead add a forward declaration.

help.c void get_version_info(struct strbuf *buf, int show_build_options) · line 782

Quoted 9 lines
help.c +1 -1
@@ -775,7 +776,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
 	}
 }
 
-int cmd_version(int argc, const char **argv, const char *prefix)
+int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	int build_options = 0;

Patrick

#6 lore raw

Re: [PATCH 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it where necessary to individual builtins/*. The next step will be to migrate each builtin from having to use the_repository.

Quoted 6 lines
Quoted 2 lines

---

We at least need the following fix-up in order to play nice with others, specifically Patrick's ps/environ-wo-the-repository, when the topic is merged to 'seen'.

I was wondering whether there were interactions with this topic. Thanks for checking.

Patrick

#9 lore raw

Re: [PATCH 3/3] add: pass in repo variable instead of global the_repository

In reply to John Cai via GitGitGadget

builtin/add.c

Quoted 4 lines · John Cai via GitGitGadget

Fr> diff --git a/builtin/add.c b/builtin/add.c
index dac832df3e7..a68fd7c8313 100644

builtin/add.c +0 -0

One thing I'm missing in this patch is it getting rid of USE_THE_REPOSITORY_VARIABLE. Without that change it is impossible to see whether we are now free of the_repository in this file.

builtin/add.c static int pathspec_file_nul; · line 43

Quoted 10 lines
builtin/add.c +4 -1
@@ -36,24 +36,27 @@ static int pathspec_file_nul;
 static int include_sparse;
 static const char *pathspec_from_file;
 
-static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
+static int chmod_pathspec(struct pathspec *pathspec,
+			  char flip,
+			  int show_only,
+			  struct repository *repo)
 {

Nit: We typically tend to pass the repository as first argument. Also applies to all the other functions.

commit.h line 8

Quoted 12 lines
commit.h +1 -0
index 0e5fce543c2..92fef717be1 100644
@@ -2,6 +2,7 @@
 #define COMMIT_H
 
 #include "object.h"
+#include "repository.h"
 
 struct signature_check;
 struct strbuf;

There is no need for the include here, let's instead add a forward declaration.

Patrick

#7 lore raw

Re: [PATCH 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to John Cai via GitGitGadget
Quoted 6 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it where necessary to individual builtins/*. The next step will be to migrate each builtin from having to use the_repository.

I didn't notice this until I compile-tested the merge result to 'seen', but this omits some files in builtin/*.c hierarchy and add the USE_* variable to the rest.

That makes the step impossible to review this step.

Can we make this step to mechanically (1) remove definition of the USE_* variable from builtin.h and (2) add it to everything that includes builtin.h and (3) do nothing else?

Then each of the files in builtin/*.c that this iteration omitted can explicitly lose the USE_* variable in its own separate follow-up patch (e.g. "this file did not need to access the_repository either directly or indirectly", or "with these changes, this file now does not depend implicitly on the_repository, so lose USE_* definition at the same time").

Thanks.

#3 lore raw

Re: [PATCH 1/3] builtin: add a repository parameter for builtin functions

In reply to Patrick Steinhardt

Hi Patrick,

Quoted 62 lines · Patrick Steinhardt
Quoted 6 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

builtin/add.c +0 -0
index 40b61ef90d9..3b9bc93ed9a 100644

builtin/add.c static int add_files(struct dir_struct *dir, int flags) · line 364

Quoted 8 lines
builtin/add.c +1 -1
@@ -358,7 +358,7 @@ static int add_files(struct dir_struct *dir, int flags)
      return exit_status;
 }
 
-int cmd_add(int argc, const char **argv, const char *prefix)
+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
      int exit_status = 0;
      struct pathspec pathspec;

Nit: all of these are now overly long as we typically wrap at 80 characters.

Quoted 27 lines
git.c +2 -3
index 9a618a2740f..0ea6e351dfd 100644
@@ -31,7 +31,7 @@
 
 struct cmd_struct {
      const char *cmd;
-     int (*fn)(int, const char **, const char *);
+     int (*fn)(int, const char **, const char *, struct repository *);
      unsigned int option;
 };
 
@@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
      return ret;
 }
 
-static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
+static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
 {
      int status, help;
      struct stat st;
@@ -479,9 +479,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
      trace_argv_printf(argv, "trace: built-in: git");
      trace2_cmd_name(p->cmd);
 
-     validate_cache_entries(the_repository->index);

git.c static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · line 489

Quoted 10 lines
git.c +5 -2
-     status = p->fn(argc, argv, prefix);
-     validate_cache_entries(the_repository->index);
+     validate_cache_entries(repo->index);
+
+     status = p->fn(argc, argv, prefix, startup_info->have_repository? repo: NULL) ;
+
+     validate_cache_entries(repo->index);
 
      if (status)
              return status;

Looks sensible.

Quoted 2 lines
git.c +0 -0
@@ -736,7 +738,7 @@ static void handle_builtin(int argc, const char **argv)
 
Quoted 9 lines

git.c static void handle_builtin(int argc, const char **argv) · line 744

Quoted 7 lines
git.c +1 -1
      builtin = get_builtin(cmd);
      if (builtin)
-             exit(run_builtin(builtin, argc, argv));
+             exit(run_builtin(builtin, argc, argv, the_repository));
      strvec_clear(&args);
 }
 

Why don't we need a check for startup_info->have_repository here?

We do the check inside of run_builtin(), which calls the fn() directly. There's a call to validate_cache_entries(repo->index) in run_builtin(), so if we passed in NULL then we would need another guard to prevent a segfault in run_builtin().

Quoted 11 lines
Quoted 11 lines
help.c +1 -0
index c03863f2265..e7cdfab6432 100644
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "prompt.h"
 #include "fsmonitor-ipc.h"
+#include "repository.h"
 
Quoted 4 lines

help.c line 22

Quoted 2 lines
help.c +0 -0
 #ifndef NO_CURL
 #include "git-curl-compat.h" /* For LIBCURL_VERSION only */

The include shouldn't be necessary. You can instead add a forward declaration.

indeed, I'll remove this in the next version.

Quoted 12 lines

help.c void get_version_info(struct strbuf *buf, int show_build_options) · line 782

Quoted 10 lines
help.c +1 -1
@@ -775,7 +776,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
      }
 }
 
-int cmd_version(int argc, const char **argv, const char *prefix)
+int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
      struct strbuf buf = STRBUF_INIT;
      int build_options = 0;

Patrick

#11 lore raw

v2 cover Add repository parameter to builtins

In reply to John Cai via GitGitGadget

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.

Changes since V1:

* Removed USE_THE_REPOSITORY_VARIABLE from add.c
* removed changes that conflict with existing topics in seen
* Fixed overly long lines formatting issues

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

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

Range-diff vs v1:

1: 3301a34f763 ! 1: 9aaf9662544 builtin: add a repository parameter for builtin functions
@@ builtin.h: int is_builtin(const char *s);
#endif

## builtin/add.c ##
+@@ builtin/add.c: int interactive_add(const char **argv, const char *prefix, int patch)
+ return ret;
+ }
+
+-static int edit_patch(int argc, const char **argv, const char *prefix) ++static int edit_patch(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
+ {
+ char *file = git_pathdup("ADD_EDIT.patch");
+ struct child_process child = CHILD_PROCESS_INIT;
@@ builtin/add.c: static int add_files(struct dir_struct *dir, int flags)
return exit_status;
}

-int cmd_add(int argc, const char **argv, const char *prefix)
-+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED) ++int cmd_add(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int exit_status = 0;
struct pathspec pathspec;
+@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix)
+ if (edit_interactive) {
+ if (pathspec_from_file)
+ die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--edit");
+- return(edit_patch(argc, argv, prefix));
++ return(edit_patch(argc, argv, prefix, the_repository));
+ }
+ argc--;
+ argv++;

## builtin/am.c ##
@@ builtin/am.c: static int parse_opt_show_current_patch(const struct option *opt, const char *ar
@@ builtin/am.c: static int parse_opt_show_current_patch(const struct option *opt,
}

-int cmd_am(int argc, const char **argv, const char *prefix)
-+int cmd_am(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_am(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct am_state state;
int binary = -1;
@@ builtin/annotate.c
#include "strvec.h"

-int cmd_annotate(int argc, const char **argv, const char *prefix)
-+int cmd_annotate(int argc, const char **argv, const char *prefix, struct repository *repo) ++int cmd_annotate(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strvec args = STRVEC_INIT;
int i;
@@ builtin/annotate.c: int cmd_annotate(int argc, const char **argv, const char *pr
}

- return cmd_blame(args.nr, args.v, prefix);
-+ return cmd_blame(args.nr, args.v, prefix, repo);
++ return cmd_blame(args.nr, args.v, prefix, the_repository);
}

## builtin/apply.c ##
@@ builtin/apply.c: static const char * const apply_usage[] = {
};

-int cmd_apply(int argc, const char **argv, const char *prefix)
-+int cmd_apply(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_apply(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int force_apply = 0;
int options = 0;
@@ builtin/archive.c: static int run_remote_archiver(int argc, const char **argv,
PARSE_OPT_NO_INTERNAL_HELP )

-int cmd_archive(int argc, const char **argv, const char *prefix)
-+int cmd_archive(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_archive(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *exec = "git-upload-archive";
char *output = NULL;
@@ builtin/bisect.c: static int cmd_bisect__run(int argc, const char **argv, const
}

-int cmd_bisect(int argc, const char **argv, const char *prefix)
-+int cmd_bisect(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_bisect(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int res = 0;
parse_opt_subcommand_fn *fn = NULL;
@@ builtin/blame.c: static void build_ignorelist(struct blame_scoreboard *sb,
}

-int cmd_blame(int argc, const char **argv, const char *prefix)
-+int cmd_blame(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_blame(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info revs;
char *path = NULL;
@@ builtin/branch.c: static int edit_branch_description(const char *branch_name)
}

-int cmd_branch(int argc, const char **argv, const char *prefix)
-+int cmd_branch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_branch(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
/* possible actions */
int delete = 0, rename = 0, copy = 0, list = 0,
@@ builtin/bugreport.c: static void get_header(struct strbuf *buf, const char *titl
}

-int cmd_bugreport(int argc, const char **argv, const char *prefix)
-+int cmd_bugreport(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_bugreport(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strbuf buffer = STRBUF_INIT;
struct strbuf report_path = STRBUF_INIT;
@@ builtin/bundle.c: cleanup:
}

-int cmd_bundle(int argc, const char **argv, const char *prefix)
-+int cmd_bundle(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_bundle(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
@@ builtin/cat-file.c: static int batch_option_callback(const struct option *opt,
}

-int cmd_cat_file(int argc, const char **argv, const char *prefix)
-+int cmd_cat_file(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_cat_file(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int opt = 0;
int opt_cw = 0;
@@ builtin/check-attr.c: static NORETURN void error_with_usage(const char *msg)
}

-int cmd_check_attr(int argc, const char **argv, const char *prefix)
-+int cmd_check_attr(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_check_attr(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct attr_check *check;
struct object_id initialized_oid;
@@ builtin/check-ignore.c: static int check_ignore_stdin_paths(struct dir_struct *d
}

-int cmd_check_ignore(int argc, const char **argv, const char *prefix)
-+int cmd_check_ignore(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_check_ignore(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int num_ignored;
struct dir_struct dir = DIR_INIT;
@@ builtin/check-mailmap.c: static void check_mailmap(struct string_list *mailmap,
}

-int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
-+int cmd_check_mailmap(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_check_mailmap(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i;
struct string_list mailmap = STRING_LIST_INIT_NODUP;
@@ builtin/check-ref-format.c: static int check_ref_format_branch(const char *arg)
}

-int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
-+int cmd_check_ref_format(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_check_ref_format(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i;
int normalize = 0;
@@ builtin/checkout--worker.c: static const char * const checkout_worker_usage[] =
};

-int cmd_checkout__worker(int argc, const char **argv, const char *prefix)
-+int cmd_checkout__worker(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_checkout__worker(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct checkout state = CHECKOUT_INIT;
struct option checkout_worker_options[] = {
@@ builtin/checkout-index.c: static int option_parse_stage(const struct option *opt
}

-int cmd_checkout_index(int argc, const char **argv, const char *prefix)
-+int cmd_checkout_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_checkout_index(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i;
struct lock_file lock_file = LOCK_INIT;
@@ builtin/checkout.c: static int checkout_main(int argc, const char **argv, const
}

-int cmd_checkout(int argc, const char **argv, const char *prefix)
-+int cmd_checkout(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_checkout(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct checkout_opts opts = CHECKOUT_OPTS_INIT;
struct option *options;
@@ builtin/checkout.c: int cmd_checkout(int argc, const char **argv, const char *pr
}

-int cmd_switch(int argc, const char **argv, const char *prefix)
-+int cmd_switch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_switch(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct checkout_opts opts = CHECKOUT_OPTS_INIT;
struct option *options = NULL;
@@ builtin/checkout.c: int cmd_switch(int argc, const char **argv, const char *pref
}

-int cmd_restore(int argc, const char **argv, const char *prefix)
-+int cmd_restore(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_restore(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct checkout_opts opts = CHECKOUT_OPTS_INIT;
struct option *options;
@@ builtin/clean.c: static void correct_untracked_entries(struct dir_struct *dir)
}

-int cmd_clean(int argc, const char **argv, const char *prefix)
-+int cmd_clean(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_clean(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i, res;
int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
@@ builtin/clone.c: static int path_exists(const char *path)
}

-int cmd_clone(int argc, const char **argv, const char *prefix)
-+int cmd_clone(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED) ++int cmd_clone(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repository UNUSED)
{
int is_bundle = 0, is_local;
int reject_shallow = 0;
@@ builtin/column.c: static int column_config(const char *var, const char *value,
}

-int cmd_column(int argc, const char **argv, const char *prefix)
-+int cmd_column(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_column(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct string_list list = STRING_LIST_INIT_DUP;
struct strbuf sb = STRBUF_INIT;
@@ builtin/commit-graph.c: cleanup:
}

-int cmd_commit_graph(int argc, const char **argv, const char *prefix)
-+int cmd_commit_graph(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_commit_graph(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option builtin_commit_graph_options[] = {
@@ builtin/commit-tree.c: static int parse_file_arg_callback(const struct option *o
}

-int cmd_commit_tree(int argc, const char **argv, const char *prefix)
-+int cmd_commit_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_commit_tree(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
static struct strbuf buffer = STRBUF_INIT;
struct commit_list *parents = NULL;
@@ builtin/commit.c: static int git_status_config(const char *k, const char *v,
}

-int cmd_status(int argc, const char **argv, const char *prefix)
-+int cmd_status(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_status(int argc,
++const char **argv,
++const char *prefix,
++struct repository *repo UNUSED)
{
static int no_renames = -1;
static const char *rename_score_arg = (const char *)-1;
@@ builtin/commit.c: static int git_commit_config(const char *k, const char *v,
}

-int cmd_commit(int argc, const char **argv, const char *prefix)
-+int cmd_commit(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_commit(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
static struct wt_status s;
static struct option builtin_commit_options[] = {
@@ builtin/config.c: out:
}

-int cmd_config(int argc, const char **argv, const char *prefix)
-+int cmd_config(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_config(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *subcommand = NULL;
struct option subcommand_opts[] = {
@@ builtin/count-objects.c: static char const * const count_objects_usage[] = {
};

-int cmd_count_objects(int argc, const char **argv, const char *prefix)
-+int cmd_count_objects(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_count_objects(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int human_readable = 0;
struct option opts[] = {
@@ builtin/credential-cache--daemon.c: static void init_socket_directory(const char
}

-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
-+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_credential_cache_daemon(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct tempfile *socket_file;
const char *socket_path;
@@ builtin/credential-cache--daemon.c: int cmd_credential_cache_daemon(int argc, co
#else

-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
-+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_credential_cache_daemon(int argc,
++const char **argv,
++const char *prefix,
++struct repository *repo UNUSED)
{
const char * const usage[] = {
"git credential-cache--daemon [--debug] <socket-path>",
@@ builtin/credential-cache.c: static void announce_capabilities(void)
}

-int cmd_credential_cache(int argc, const char **argv, const char *prefix)
-+int cmd_credential_cache(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_credential_cache(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *socket_path_arg = NULL;
char *socket_path;
@@ builtin/credential-store.c: static void lookup_credential(const struct string_li
}

-int cmd_credential_store(int argc, const char **argv, const char *prefix)
-+int cmd_credential_store(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_credential_store(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char * const usage[] = {
"git credential-store [<options>] <action>",
@@ builtin/credential.c
"git credential (fill|approve|reject)";

-int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_credential(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_credential(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
const char *op;
struct credential c = CREDENTIAL_INIT;
@@ builtin/describe.c: static int option_parse_exact_match(const struct option *opt
}

-int cmd_describe(int argc, const char **argv, const char *prefix)
-+int cmd_describe(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED ) ++int cmd_describe(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED )
{
int contains = 0;
struct option options[] = {
@@ builtin/diagnose.c: static const char * const diagnose_usage[] = {
};

-int cmd_diagnose(int argc, const char **argv, const char *prefix)
-+int cmd_diagnose(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_diagnose(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strbuf zip_path = STRBUF_INIT;
time_t now = time(NULL);
@@ builtin/diff-files.c: static const char diff_files_usage[] =
COMMON_DIFF_OPTIONS_HELP;

-int cmd_diff_files(int argc, const char **argv, const char *prefix)
-+int cmd_diff_files(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_diff_files(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info rev;
int result;
@@ builtin/diff-index.c: static const char diff_cache_usage[] =
COMMON_DIFF_OPTIONS_HELP;

-int cmd_diff_index(int argc, const char **argv, const char *prefix)
-+int cmd_diff_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_diff_index(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info rev;
unsigned int option = 0;
@@ builtin/diff-tree.c: static void diff_tree_tweak_rev(struct rev_info *rev)
}

-int cmd_diff_tree(int argc, const char **argv, const char *prefix)
-+int cmd_diff_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_diff_tree(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
char line[1000];
struct object *tree1, *tree2;
@@ builtin/diff.c: static void symdiff_release(struct symdiff *sdiff)
}

-int cmd_diff(int argc, const char **argv, const char *prefix)
-+int cmd_diff(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_diff(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i;
struct rev_info rev;
@@ builtin/difftool.c: static int run_file_diff(int prompt, const char *prefix,
}

-int cmd_difftool(int argc, const char **argv, const char *prefix)
-+int cmd_difftool(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_difftool(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int use_gui_tool = -1, dir_diff = 0, prompt = -1, symlinks = 0,
tool_help = 0, no_index = 0;
@@ builtin/fast-export.c: static int parse_opt_anonymize_map(const struct option *o
}

-int cmd_fast_export(int argc, const char **argv, const char *prefix)
-+int cmd_fast_export(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_fast_export(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info revs;
struct commit *commit;
@@ builtin/fast-import.c: static void parse_argv(void)
}

-int cmd_fast_import(int argc, const char **argv, const char *prefix)
-+int cmd_fast_import(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_fast_import(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
unsigned int i;

@@ builtin/fetch-pack.c: static void add_sought_entry(struct ref ***sought, int *nr
}

-int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_fetch_pack(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
int i, ret;
struct ref *ref = NULL;
@@ builtin/fetch.c: static int fetch_one(struct remote *remote, int argc, const cha
}

-int cmd_fetch(int argc, const char **argv, const char *prefix)
-+int cmd_fetch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_fetch(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct fetch_config config = {
.display_format = DISPLAY_FORMAT_FULL,
@@ builtin/fmt-merge-msg.c: static const char * const fmt_merge_msg_usage[] = {
};

-int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
-+int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_fmt_merge_msg(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
char *inpath = NULL;
const char *message = NULL;
@@ builtin/for-each-ref.c: static char const * const for_each_ref_usage[] = {
};

-int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
-+int cmd_for_each_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_for_each_ref(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct ref_sorting *sorting;
struct string_list sorting_options = STRING_LIST_INIT_DUP;
@@ builtin/for-each-repo.c: static int run_command_on_repo(const char *path, int ar
}

-int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
-+int cmd_for_each_repo(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_for_each_repo(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
static const char *config_key = NULL;
int keep_going = 0;
@@ builtin/fsck.c: static struct option fsck_opts[] = {
};

-int cmd_fsck(int argc, const char **argv, const char *prefix)
-+int cmd_fsck(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_fsck(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i;
struct object_directory *odb;
@@ builtin/fsmonitor--daemon.c: static int try_to_start_background_daemon(void)
}

-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
-+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_fsmonitor__daemon(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *subcmd;
enum fsmonitor_reason reason;
@@ builtin/gc.c: static void gc_before_repack(struct maintenance_run_opts *opts,
}

-int cmd_gc(int argc, const char **argv, const char *prefix)
-+int cmd_gc(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_gc(int argc,
++const char **argv,
++const char *prefix,
++struct repository *repo UNUSED)
{
int aggressive = 0;
int quiet = 0;
@@ builtin/gc.c: static const char * const builtin_maintenance_usage[] = {
};

-int cmd_maintenance(int argc, const char **argv, const char *prefix)
-+int cmd_maintenance(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_maintenance(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option builtin_maintenance_options[] = {
@@ builtin/get-tar-commit-id.c: static const char builtin_get_tar_commit_id_usage[]
#define HEADERSIZE (2 * RECORDSIZE)

-int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix)
-+int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix, struct repository *repo UNUSED) ++int cmd_get_tar_commit_id(int argc,
++ const char **argv UNUSED,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
char buffer[HEADERSIZE];
struct ustar_header *header = (struct ustar_header *)buffer;
@@ builtin/grep.c: static int pattern_callback(const struct option *opt, const char
}

-int cmd_grep(int argc, const char **argv, const char *prefix)
-+int cmd_grep(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_grep(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int hit = 0;
int cached = 0, untracked = 0, opt_exclude = -1;
@@ builtin/hash-object.c: static void hash_stdin_paths(const char *type, int no_fil
}

-int cmd_hash_object(int argc, const char **argv, const char *prefix)
-+int cmd_hash_object(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_hash_object(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
static const char * const hash_object_usage[] = {
N_("git hash-object [-t <type>] [-w] [--path=<file> | --no-filters]\n"
@@ builtin/help.c: static void opt_mode_usage(int argc, const char *opt_mode,
}

-int cmd_help(int argc, const char **argv, const char *prefix)
-+int cmd_help(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_help(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int nongit;
enum help_format parsed_help_format;
@@ builtin/hook.c: usage:
}

-int cmd_hook(int argc, const char **argv, const char *prefix)
-+int cmd_hook(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_hook(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option builtin_hook_options[] = {
@@ builtin/index-pack.c: static void show_pack_info(int stat_only)
}

-int cmd_index_pack(int argc, const char **argv, const char *prefix)
-+int cmd_index_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_index_pack(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
const char *curr_index;
@@ builtin/init-db.c: static const char *const init_db_usage[] = {
* be the judge. The default case is to have one DB per managed directory.
*/
-int cmd_init_db(int argc, const char **argv, const char *prefix)
-+int cmd_init_db(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_init_db(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *git_dir;
const char *real_git_dir = NULL;
@@ builtin/interpret-trailers.c: static void interpret_trailers(const struct proces
}

-int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
-+int cmd_interpret_trailers(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_interpret_trailers(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; LIST_HEAD(trailers);
@@ builtin/log.c: static int git_log_config(const char *var, const char *value,
}

-int cmd_whatchanged(int argc, const char **argv, const char *prefix)
-+int cmd_whatchanged(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_whatchanged(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct log_config cfg;
struct rev_info rev;
@@ builtin/log.c: static void show_setup_revisions_tweak(struct rev_info *rev)
}

-int cmd_show(int argc, const char **argv, const char *prefix)
-+int cmd_show(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_show(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct log_config cfg;
struct rev_info rev;
@@ builtin/log.c: int cmd_show(int argc, const char **argv, const char *prefix)
* This is equivalent to "git log -g --abbrev-commit --pretty=oneline"
*/
-int cmd_log_reflog(int argc, const char **argv, const char *prefix)
-+int cmd_log_reflog(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_log_reflog(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct log_config cfg;
struct rev_info rev;
@@ builtin/log.c: static void log_setup_revisions_tweak(struct rev_info *rev)
}

-int cmd_log(int argc, const char **argv, const char *prefix)
-+int cmd_log(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_log(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct log_config cfg;
struct rev_info rev;
@@ builtin/log.c: static void infer_range_diff_ranges(struct strbuf *r1,
}

-int cmd_format_patch(int argc, const char **argv, const char *prefix)
-+int cmd_format_patch(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_format_patch(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct format_config cfg;
struct commit *commit;
@@ builtin/log.c: static void print_commit(char sign, struct commit *commit, int ve
}

-int cmd_cherry(int argc, const char **argv, const char *prefix)
-+int cmd_cherry(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_cherry(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info revs;
struct patch_ids ids;
@@ builtin/ls-files.c: static int option_parse_exclude_standard(const struct option
}

-int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
-+int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix, struct repository *repo UNUSED) ++int cmd_ls_files(int argc,
++ const char **argv,
++ const char *cmd_prefix,
++ struct repository *repo UNUSED)
{
int require_work_tree = 0, show_tag = 0, i;
char *max_prefix;
@@ builtin/ls-remote.c: static int tail_match(const struct strvec *pattern, const c
}

-int cmd_ls_remote(int argc, const char **argv, const char *prefix)
-+int cmd_ls_remote(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_ls_remote(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *dest = NULL;
unsigned flags = 0;
@@ builtin/ls-tree.c: static struct ls_tree_cmdmode_to_fmt ls_tree_cmdmode_format[]
};

-int cmd_ls_tree(int argc, const char **argv, const char *prefix)
-+int cmd_ls_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_ls_tree(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct object_id oid;
struct tree *tree;
@@ builtin/mailinfo.c: static int parse_opt_quoted_cr(const struct option *opt, con
}

-int cmd_mailinfo(int argc, const char **argv, const char *prefix)
-+int cmd_mailinfo(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_mailinfo(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct metainfo_charset meta_charset;
struct mailinfo mi;
@@ builtin/mailsplit.c: out:
}

-int cmd_mailsplit(int argc, const char **argv, const char *prefix)
-+int cmd_mailsplit(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_mailsplit(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int nr = 0, nr_prec = 4, num = 0;
int allow_bare = 0;
@@ builtin/merge-base.c: static int handle_fork_point(int argc, const char **argv)
}

-int cmd_merge_base(int argc, const char **argv, const char *prefix)
-+int cmd_merge_base(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_merge_base(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct commit **rev;
int rev_nr = 0;
@@ builtin/merge-file.c: static int diff_algorithm_cb(const struct option *opt,
}

-int cmd_merge_file(int argc, const char **argv, const char *prefix)
-+int cmd_merge_file(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_merge_file(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *names[3] = { 0 };
mmfile_t mmfs[3] = { 0 };
@@ builtin/merge-index.c: static void merge_all(void)
}

-int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_merge_index(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
int i, force_file = 0;

@@ builtin/merge-ours.c
"git merge-ours <base>... -- HEAD <remote>...";

-int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_merge_ours(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(builtin_merge_ours_usage);
@@ builtin/merge-recursive.c: static char *better_branch_name(const char *branch)
}

-int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_merge_recursive(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
struct object_id bases[21];
unsigned bases_count = 0;
@@ builtin/merge-tree.c: static int real_merge(struct merge_tree_options *o,
}

-int cmd_merge_tree(int argc, const char **argv, const char *prefix)
-+int cmd_merge_tree(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_merge_tree(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct merge_tree_options o = { .show_messages = -1 };
struct strvec xopts = STRVEC_INIT;
@@ builtin/merge.c: static int merging_a_throwaway_tag(struct commit *commit)
}

-int cmd_merge(int argc, const char **argv, const char *prefix)
-+int cmd_merge(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_merge(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct object_id result_tree, stash, head_oid;
struct commit *head_commit;
@@ builtin/mktag.c: static int verify_object_in_tag(struct object_id *tagged_oid, i
}

-int cmd_mktag(int argc, const char **argv, const char *prefix)
-+int cmd_mktag(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_mktag(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
static struct option builtin_mktag_options[] = {
OPT_BOOL(0, "strict", &option_strict,
@@ builtin/mktree.c: static void mktree_line(char *buf, int nul_term_line, int allo
}

-int cmd_mktree(int ac, const char **av, const char *prefix)
-+int cmd_mktree(int ac, const char **av, const char *prefix, struct repository *repo UNUSED) ++int cmd_mktree(int ac,
++ const char **av,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strbuf sb = STRBUF_INIT;
struct object_id oid;
+@@ builtin/mktree.c: int cmd_mktree(int ac, const char **av, const char *prefix)
+ used=0; /* reset tree entry buffer for re-use in batch mode */
+ }
+ strbuf_release(&sb);
++
+ return 0;
+ }

## builtin/multi-pack-index.c ##
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv,
+ (size_t)opts.batch_size, opts.flags);
}

- int cmd_multi_pack_index(int argc, const char **argv,
+-int cmd_multi_pack_index(int argc, const char **argv,
- const char *prefix)
-+ const char *prefix, struct repository *repo UNUSED)
++int cmd_multi_pack_index(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int res;
parse_opt_subcommand_fn *fn = NULL;
@@ builtin/mv.c: static void remove_empty_src_dirs(const char **src_dir, size_t src
}

-int cmd_mv(int argc, const char **argv, const char *prefix)
-+int cmd_mv(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_mv(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i, flags, gitmodules_modified = 0;
int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0;
@@ builtin/name-rev.c: static void name_rev_line(char *p, struct name_ref_data *dat
}

-int cmd_name_rev(int argc, const char **argv, const char *prefix)
-+int cmd_name_rev(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_name_rev(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct mem_pool string_pool;
struct object_array revs = OBJECT_ARRAY_INIT;
@@ builtin/notes.c: static int get_ref(int argc, const char **argv, const char *pre
}

-int cmd_notes(int argc, const char **argv, const char *prefix)
-+int cmd_notes(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_notes(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *override_notes_ref = NULL;
parse_opt_subcommand_fn *fn = NULL;
@@ builtin/pack-objects.c: static int option_parse_cruft_expiration(const struct op
}

-int cmd_pack_objects(int argc, const char **argv, const char *prefix)
-+int cmd_pack_objects(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_pack_objects(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int use_internal_rev_list = 0;
int shallow = 0;
@@ builtin/pack-redundant.c: static void load_all(void)
}

-int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
- {
- int i;
- int i_still_use_this = 0;
+-{
+- int i;
+- int i_still_use_this = 0;
+- struct pack_list *min = NULL, *red, *pl;
++int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
++ int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;
+ struct llist *ignore;
+ struct object_id *oid;
+ char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */

## builtin/pack-refs.c ##
@@ builtin/pack-refs.c: static char const * const pack_refs_usage[] = {
@@ builtin/pack-refs.c: static char const * const pack_refs_usage[] = {
};

-int cmd_pack_refs(int argc, const char **argv, const char *prefix)
-+int cmd_pack_refs(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_pack_refs(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
struct string_list included_refs = STRING_LIST_INIT_NODUP;
@@ builtin/patch-id.c: static int git_patch_id_config(const char *var, const char *
}

-int cmd_patch_id(int argc, const char **argv, const char *prefix)
-+int cmd_patch_id(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_patch_id(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
/* if nothing is set, default to unstable */
struct patch_id_opts config = {0, 0};
@@ builtin/prune-packed.c: static const char * const prune_packed_usage[] = {
};

-int cmd_prune_packed(int argc, const char **argv, const char *prefix)
-+int cmd_prune_packed(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_prune_packed(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
const struct option prune_packed_options[] = {
@@ builtin/prune.c: static void remove_temporary_files(const char *path)
}

-int cmd_prune(int argc, const char **argv, const char *prefix)
-+int cmd_prune(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_prune(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info revs;
int exclude_promisor_objects = 0;
@@ builtin/pull.c: static void show_advice_pull_non_ff(void)
}

-int cmd_pull(int argc, const char **argv, const char *prefix)
-+int cmd_pull(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED) ++int cmd_pull(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repository UNUSED)
{
const char *repo, **refspecs;
struct oid_array merge_heads = OID_ARRAY_INIT;
@@ builtin/push.c: static int git_push_config(const char *k, const char *v,
}

-int cmd_push(int argc, const char **argv, const char *prefix)
-+int cmd_push(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED) ++int cmd_push(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repository UNUSED)
{
int flags = 0;
int tags = 0;
@@ builtin/range-diff.c: N_("git range-diff [<options>] <base> <old-tip> <new-tip>"
};

-int cmd_range_diff(int argc, const char **argv, const char *prefix)
-+int cmd_range_diff(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_range_diff(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct diff_options diffopt = { NULL };
struct strvec other_arg = STRVEC_INIT;
@@ builtin/read-tree.c: static int git_read_tree_config(const char *var, const char
}

-int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
-+int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix, struct repository *repo UNUSED) ++int cmd_read_tree(int argc,
++ const char **argv,
++ const char *cmd_prefix,
++ struct repository *repo UNUSED)
{
int i, stage = 0;
struct object_id oid;
@@ builtin/rebase.c: static int check_exec_cmd(const char *cmd)
}

-int cmd_rebase(int argc, const char **argv, const char *prefix)
-+int cmd_rebase(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_rebase(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rebase_options options = REBASE_OPTIONS_INIT;
const char *branch_name;
@@ builtin/receive-pack.c: static int delete_only(struct command *commands)
}

-int cmd_receive_pack(int argc, const char **argv, const char *prefix)
-+int cmd_receive_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_receive_pack(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int advertise_refs = 0;
struct command *commands;
@@ builtin/reflog.c: static int cmd_reflog_exists(int argc, const char **argv, cons
*/

-int cmd_reflog(int argc, const char **argv, const char *prefix)
-+int cmd_reflog(int argc, const char **argv, const char *prefix, struct repository *repository) ++int cmd_reflog(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repository)
{
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
@@ builtin/refs.c: static int cmd_refs_verify(int argc, const char **argv, const ch
}

-int cmd_refs(int argc, const char **argv, const char *prefix)
-+int cmd_refs(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_refs(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char * const refs_usage[] = {
REFS_MIGRATE_USAGE,
@@ builtin/remote-ext.c: static int command_loop(const char *child)
}

-int cmd_remote_ext(int argc, const char **argv, const char *prefix)
-+int cmd_remote_ext(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_remote_ext(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
BUG_ON_NON_EMPTY_PREFIX(prefix);

@@ builtin/remote-fd.c: static void command_loop(int input_fd, int output_fd)
}

-int cmd_remote_fd(int argc, const char **argv, const char *prefix)
-+int cmd_remote_fd(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_remote_fd(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int input_fd = -1;
int output_fd = -1;
@@ builtin/remote.c: out:
}

-int cmd_remote(int argc, const char **argv, const char *prefix)
-+int cmd_remote(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_remote(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
@@ builtin/repack.c: static const char *find_pack_prefix(const char *packdir, const
}

-int cmd_repack(int argc, const char **argv, const char *prefix)
-+int cmd_repack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_repack(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct string_list_item *item;
@@ builtin/replace.c: static int convert_graft_file(int force)
}

-int cmd_replace(int argc, const char **argv, const char *prefix)
-+int cmd_replace(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_replace(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int force = 0;
int raw = 0;
@@ builtin/replay.c: static struct commit *pick_regular_commit(struct commit *pickm
}

-int cmd_replay(int argc, const char **argv, const char *prefix)
-+int cmd_replay(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_replay(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *advance_name_opt = NULL;
char *advance_name = NULL;
@@ builtin/rerere.c: static int diff_two(const char *file1, const char *label1,
}

-int cmd_rerere(int argc, const char **argv, const char *prefix)
-+int cmd_rerere(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_rerere(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct string_list merge_rr = STRING_LIST_INIT_DUP;
int i, autoupdate = -1, flags = 0;
@@ builtin/reset.c: static int git_reset_config(const char *var, const char *value,
}

-int cmd_reset(int argc, const char **argv, const char *prefix)
-+int cmd_reset(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_reset(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int reset_type = NONE, update_ref_status = 0, quiet = 0;
int no_refresh = 0;
@@ builtin/rev-list.c: static int try_bitmap_disk_usage(struct rev_info *revs,
}

-int cmd_rev_list(int argc, const char **argv, const char *prefix)
-+int cmd_rev_list(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_rev_list(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct rev_info revs;
struct rev_list_info info;
@@ builtin/rev-parse.c: static void print_path(const char *path, const char *prefix
}

-int cmd_rev_parse(int argc, const char **argv, const char *prefix)
-+int cmd_rev_parse(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_rev_parse(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
const struct git_hash_algo *output_algo = NULL;
@@ builtin/revert.c: static int run_sequencer(int argc, const char **argv, const ch
}

-int cmd_revert(int argc, const char **argv, const char *prefix)
-+int cmd_revert(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_revert(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct replay_opts opts = REPLAY_OPTS_INIT;
int res;
@@ builtin/revert.c: int cmd_revert(int argc, const char **argv, const char *prefix
}

-int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
-+int cmd_cherry_pick(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_cherry_pick(int argc,
++const char **argv,
++const char *prefix,
++struct repository *repo UNUSED)
{
struct replay_opts opts = REPLAY_OPTS_INIT;
int res;
@@ builtin/rm.c: static struct option builtin_rm_options[] = {
};

-int cmd_rm(int argc, const char **argv, const char *prefix)
-+int cmd_rm(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_rm(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct lock_file lock_file = LOCK_INIT;
int i, ret = 0;
@@ builtin/send-pack.c: static int send_pack_config(const char *k, const char *v,
}

-int cmd_send_pack(int argc, const char **argv, const char *prefix)
-+int cmd_send_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_send_pack(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct refspec rs = REFSPEC_INIT_PUSH;
const char *remote_name = NULL;
@@ builtin/shortlog.c: void shortlog_finish_setup(struct shortlog *log)
}

-int cmd_shortlog(int argc, const char **argv, const char *prefix)
-+int cmd_shortlog(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_shortlog(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct shortlog log = { STRING_LIST_INIT_NODUP };
struct rev_info rev;
@@ builtin/show-branch.c: static int parse_reflog_param(const struct option *opt, c
}

-int cmd_show_branch(int ac, const char **av, const char *prefix)
-+int cmd_show_branch(int ac, const char **av, const char *prefix, struct repository *repo UNUSED) ++int cmd_show_branch(int ac,
++ const char **av,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct commit *rev[MAX_REVS], *commit;
char *reflog_msg[MAX_REVS] = {0};
@@ builtin/show-index.c: static const char *const show_index_usage[] = {
};

-int cmd_show_index(int argc, const char **argv, const char *prefix)
-+int cmd_show_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_show_index(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i;
unsigned nr;
@@ builtin/show-ref.c: static int exclude_existing_callback(const struct option *op
}

-int cmd_show_ref(int argc, const char **argv, const char *prefix)
-+int cmd_show_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_show_ref(int argc,
++const char **argv,
++const char *prefix,
++struct repository *repo UNUSED)
{
struct exclude_existing_options exclude_existing_opts = {0};
struct patterns_options patterns_opts = {0};
@@ builtin/sparse-checkout.c: static int sparse_checkout_check_rules(int argc, cons
}

-int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
-+int cmd_sparse_checkout(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_sparse_checkout(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option builtin_sparse_checkout_options[] = {
@@ builtin/stash.c: static int save_stash(int argc, const char **argv, const char *
}

-int cmd_stash(int argc, const char **argv, const char *prefix)
-+int cmd_stash(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_stash(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
pid_t pid = getpid();
const char *index_file;
@@ builtin/stripspace.c: enum stripspace_mode {
};

-int cmd_stripspace(int argc, const char **argv, const char *prefix)
-+int cmd_stripspace(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_stripspace(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strbuf buf = STRBUF_INIT;
enum stripspace_mode mode = STRIP_DEFAULT;
@@ builtin/submodule--helper.c: cleanup:
}

-int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
-+int cmd_submodule__helper(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_submodule__helper(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
const char *const usage[] = {
@@ builtin/symbolic-ref.c: static int check_symref(const char *HEAD, int quiet, int
}

-int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
-+int cmd_symbolic_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_symbolic_ref(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int quiet = 0, delete = 0, shorten = 0, recurse = 1, ret = 0;
const char *msg = NULL;
@@ builtin/tag.c: static int strbuf_check_tag_ref(struct strbuf *sb, const char *na
}

-int cmd_tag(int argc, const char **argv, const char *prefix)
-+int cmd_tag(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_tag(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strbuf buf = STRBUF_INIT;
struct strbuf ref = STRBUF_INIT;
@@ builtin/unpack-file.c: static char *create_temp_file(struct object_id *oid)
}

-int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_unpack_file(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
struct object_id oid;

@@ builtin/unpack-objects.c: static void unpack_all(void)
}

-int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_unpack_objects(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
int i;
struct object_id oid;
@@ builtin/update-index.c: static enum parse_opt_result reupdate_callback(
}

-int cmd_update_index(int argc, const char **argv, const char *prefix)
-+int cmd_update_index(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_update_index(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int newfd, entries, has_errors = 0, nul_term_line = 0;
enum uc_mode untracked_cache = UC_UNSPECIFIED;
@@ builtin/update-ref.c: static void update_refs_stdin(void)
}

-int cmd_update_ref(int argc, const char **argv, const char *prefix)
-+int cmd_update_ref(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_update_ref(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *refname, *oldval;
struct object_id oid, oldoid;
@@ builtin/update-server-info.c: static const char * const update_server_info_usage
};

-int cmd_update_server_info(int argc, const char **argv, const char *prefix)
-+int cmd_update_server_info(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_update_server_info(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int force = 0;
struct option options[] = {
@@ builtin/upload-archive.c: static const char deadchild[] =
#define MAX_ARGS (64)

-int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
-+int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_upload_archive_writer(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
struct strvec sent_argv = STRVEC_INIT;
const char *arg_cmd = "argument ";
@@ builtin/upload-archive.c: static ssize_t process_input(int child_fd, int band)
}

-int cmd_upload_archive(int argc, const char **argv, const char *prefix)
-+int cmd_upload_archive(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_upload_archive(int argc,
++const char **argv,
++const char *prefix,
++struct repository *repo UNUSED)
{
struct child_process writer = CHILD_PROCESS_INIT;

@@ builtin/upload-pack.c: static const char * const upload_pack_usage[] = {
};

-int cmd_upload_pack(int argc, const char **argv, const char *prefix)
-+int cmd_upload_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_upload_pack(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
const char *dir;
int strict = 0;
@@ builtin/var.c: static int show_config(const char *var, const char *value,
}

-int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
-+int cmd_var(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) ++int cmd_var(int argc,
++ const char **argv,
++ const char *prefix UNUSED,
++ struct repository *repo UNUSED)
{
const struct git_var *git_var;
char *val;
@@ builtin/verify-commit.c: static int verify_commit(const char *name, unsigned fla
}

-int cmd_verify_commit(int argc, const char **argv, const char *prefix)
-+int cmd_verify_commit(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_verify_commit(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i = 1, verbose = 0, had_error = 0;
unsigned flags = 0;
@@ builtin/verify-pack.c: static const char * const verify_pack_usage[] = {
};

-int cmd_verify_pack(int argc, const char **argv, const char *prefix)
-+int cmd_verify_pack(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_verify_pack(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int err = 0;
unsigned int flags = 0;
@@ builtin/verify-tag.c: static const char * const verify_tag_usage[] = {
};

-int cmd_verify_tag(int argc, const char **argv, const char *prefix)
-+int cmd_verify_tag(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) ++int cmd_verify_tag(int argc,
++ const char **argv,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
int i = 1, verbose = 0, had_error = 0;
unsigned flags = 0;
@@ builtin/worktree.c: static int repair(int ac, const char **av, const char *prefi
}

-int cmd_worktree(int ac, const char **av, const char *prefix)
-+int cmd_worktree(int ac, const char **av, const char *prefix, struct repository *repo UNUSED) ++int cmd_worktree(int ac,
++ const char **av,
++ const char *prefix,
++ struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
@@ builtin/write-tree.c: static const char * const write_tree_usage[] = {
};

-int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
-+int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix, struct repository *repo UNUSED) ++int cmd_write_tree(int argc,
++ const char **argv,
++ const char *cmd_prefix,
++ struct repository *repo UNUSED)
{
int flags = 0, ret;
const char *tree_prefix = NULL;
@@ git.c: static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
- status = p->fn(argc, argv, prefix);
- validate_cache_entries(the_repository->index);
+ validate_cache_entries(repo->index);
-+
-+ status = p->fn(argc, argv, prefix, startup_info->have_repository? repo: NULL) ;
-+
++ status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
+ validate_cache_entries(repo->index);

if (status)
@@ help.c: void get_version_info(struct strbuf *buf, int show_build_options)
{
struct strbuf buf = STRBUF_INIT;
int build_options = 0;
+
+ ## stkOs5Qh (new) ##
+ Binary files /dev/null and stkOs5Qh differ
2: 17acc1e054c ! 2: 434c8babbb1 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

     @@ Commit message
          builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h
      
          Instead of including USE_THE_REPOSITORY_VARIABLE by default on every
     -    builtin, remove it from builtin.h and add it where necessary to
     -    individual builtins/*. The next step will be to migrate each builtin
     +    builtin, remove it from builtin.h and add it to all the builtins that
     +    reference the_repository.
     +
     +    Also, remove the include statement for repository.h since it gets
     +    brought in through builtin.h.
     +
     +    The next step will be to migrate each builtin
          from having to use the_repository.
      
          Signed-off-by: John Cai <[email protected]>
     @@ builtin/add.c
       #include "builtin.h"
       #include "advice.h"
       #include "config.h"
     +@@
     + #include "preload-index.h"
     + #include "diff.h"
     + #include "read-cache.h"
     +-#include "repository.h"
     + #include "revision.h"
     + #include "bulk-checkin.h"
     + #include "strvec.h"
      
       ## builtin/am.c ##
      @@
     @@ builtin/am.c
       #include "builtin.h"
       #include "abspath.h"
       #include "advice.h"
     +@@
     + #include "string-list.h"
     + #include "pager.h"
     + #include "path.h"
     +-#include "repository.h"
     + #include "pretty.h"
     + 
     + /**
     +
     + ## builtin/annotate.c ##
     +@@
     +  *
     +  * Copyright (C) 2006 Ryan Anderson
     +  */
     ++
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "git-compat-util.h"
     + #include "builtin.h"
     + #include "strvec.h"
      
       ## builtin/apply.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
       #include "gettext.h"
     - #include "repository.h"
     +-#include "repository.h"
     + #include "hash.h"
     + #include "apply.h"
     + 
      
       ## builtin/archive.c ##
      @@
     @@ builtin/archive.c
       #include "builtin.h"
       #include "archive.h"
       #include "gettext.h"
     + #include "transport.h"
     + #include "parse-options.h"
     + #include "pkt-line.h"
     +-#include "repository.h"
     + 
     + static void create_output_file(const char *output_file)
     + {
      
       ## builtin/bisect.c ##
      @@
     @@ builtin/blame.c
       #include "builtin.h"
       #include "config.h"
       #include "color.h"
     +@@
     + #include "environment.h"
     + #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "commit.h"
     + #include "diff.h"
     + #include "revision.h"
      
       ## builtin/branch.c ##
      @@
     @@ builtin/branch.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "config.h"
       #include "color.h"
     - #include "editor.h"
      
       ## builtin/bugreport.c ##
      @@
     @@ builtin/bundle.c
       #include "builtin.h"
       #include "abspath.h"
       #include "gettext.h"
     +@@
     + #include "strvec.h"
     + #include "parse-options.h"
     + #include "pkt-line.h"
     +-#include "repository.h"
     + #include "bundle.h"
     + 
     + /*
      
       ## builtin/cat-file.c ##
      @@
     @@ builtin/cat-file.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "config.h"
       #include "convert.h"
     - #include "diff.h"
      
       ## builtin/check-attr.c ##
      @@
     @@ builtin/check-attr.c
       #include "builtin.h"
       #include "config.h"
       #include "attr.h"
     +@@
     + #include "gettext.h"
     + #include "object-name.h"
     + #include "quote.h"
     +-#include "repository.h"
     + #include "setup.h"
     + #include "parse-options.h"
     + #include "write-or-die.h"
      
       ## builtin/check-ignore.c ##
      @@
     @@ builtin/check-ignore.c
       #include "builtin.h"
       #include "config.h"
       #include "dir.h"
     +@@
     + #include "quote.h"
     + #include "pathspec.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + #include "submodule.h"
     + #include "write-or-die.h"
     + 
      
       ## builtin/check-mailmap.c ##
      @@
     @@ builtin/checkout-index.c
        * Copyright (C) 2005 Linus Torvalds
        *
        */
     +-
      +#define USE_THE_REPOSITORY_VARIABLE
     - 
       #include "builtin.h"
       #include "config.h"
     + #include "gettext.h"
     + #include "lockfile.h"
     + #include "quote.h"
     +-#include "repository.h"
     + #include "cache-tree.h"
     + #include "parse-options.h"
     + #include "entry.h"
      
       ## builtin/checkout.c ##
      @@
     @@ builtin/clean.c
       #include "builtin.h"
       #include "abspath.h"
       #include "config.h"
     +@@
     + #include "parse-options.h"
     + #include "path.h"
     + #include "read-cache-ll.h"
     +-#include "repository.h"
     + #include "setup.h"
     + #include "string-list.h"
     + #include "quote.h"
      
       ## builtin/clone.c ##
      @@
     @@ builtin/clone.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "abspath.h"
       #include "advice.h"
       #include "config.h"
     @@ builtin/clone.c
       ## builtin/column.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
     -+
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     @@ builtin/commit-graph.c
       #include "builtin.h"
       #include "commit.h"
       #include "config.h"
     +@@
     + #include "gettext.h"
     + #include "hex.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + #include "commit-graph.h"
     + #include "object-store-ll.h"
     + #include "progress.h"
      
       ## builtin/commit-tree.c ##
      @@
     @@ builtin/commit-tree.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     + #include "hex.h"
     + #include "object-name.h"
     + #include "object-store-ll.h"
     +-#include "repository.h"
     ++
     + #include "commit.h"
     + #include "parse-options.h"
     + 
      
       ## builtin/commit.c ##
      @@
     @@ builtin/commit.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "advice.h"
       #include "config.h"
     - #include "lockfile.h"
      
       ## builtin/config.c ##
      @@
     @@ builtin/config.c
       #include "builtin.h"
       #include "abspath.h"
       #include "config.h"
     + #include "color.h"
     + #include "editor.h"
     + #include "environment.h"
     +-#include "repository.h"
     + #include "gettext.h"
     + #include "ident.h"
     + #include "parse-options.h"
      
       ## builtin/count-objects.c ##
      @@
     @@ builtin/count-objects.c
       #include "builtin.h"
       #include "config.h"
       #include "dir.h"
     + #include "environment.h"
     + #include "gettext.h"
     + #include "path.h"
     +-#include "repository.h"
     + #include "parse-options.h"
     + #include "quote.h"
     + #include "packfile.h"
      
       ## builtin/credential-cache--daemon.c ##
      @@
     @@ builtin/diff-files.c
       #include "builtin.h"
       #include "config.h"
       #include "diff.h"
     + #include "diff-merges.h"
     + #include "commit.h"
     + #include "preload-index.h"
     +-#include "repository.h"
     + #include "revision.h"
     + 
     + static const char diff_files_usage[] =
      
       ## builtin/diff-index.c ##
      @@
     @@ builtin/diff-index.c
       #include "builtin.h"
       #include "config.h"
       #include "diff.h"
     + #include "diff-merges.h"
     + #include "commit.h"
     + #include "preload-index.h"
     +-#include "repository.h"
     + #include "revision.h"
     + #include "setup.h"
     + 
      
       ## builtin/diff-tree.c ##
      @@
     @@ builtin/diff-tree.c
       #include "builtin.h"
       #include "config.h"
       #include "diff.h"
     +@@
     + #include "hex.h"
     + #include "log-tree.h"
     + #include "read-cache-ll.h"
     +-#include "repository.h"
     + #include "revision.h"
     + #include "tmp-objdir.h"
     + #include "tree.h"
      
       ## builtin/diff.c ##
      @@
     @@ builtin/diff.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "config.h"
       #include "ewah/ewok.h"
     - #include "lockfile.h"
      
       ## builtin/difftool.c ##
      @@
     @@ builtin/difftool.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "abspath.h"
       #include "config.h"
       #include "copy.h"
     @@ builtin/fast-export.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "config.h"
       #include "gettext.h"
     - #include "hex.h"
      
       ## builtin/fast-import.c ##
      @@
     @@ builtin/fast-import.c
       #include "builtin.h"
       #include "abspath.h"
       #include "environment.h"
     + #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "config.h"
     + #include "lockfile.h"
     + #include "object.h"
      
       ## builtin/fetch-pack.c ##
      @@
     @@ builtin/fetch.c
       #include "builtin.h"
       #include "advice.h"
       #include "config.h"
     + #include "gettext.h"
     + #include "environment.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "refs.h"
     + #include "refspec.h"
     + #include "object-name.h"
      
       ## builtin/fmt-merge-msg.c ##
      @@
     @@ builtin/for-each-repo.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     + #include "parse-options.h"
     + #include "path.h"
     +-#include "repository.h"
     + #include "run-command.h"
     + #include "string-list.h"
     + 
      
       ## builtin/fsck.c ##
      @@
     @@ builtin/fsck.c
       #include "builtin.h"
       #include "gettext.h"
       #include "hex.h"
     +-#include "repository.h"
     + #include "config.h"
     + #include "commit.h"
     + #include "tree.h"
      
       ## builtin/fsmonitor--daemon.c ##
      @@
     @@ builtin/fsmonitor--daemon.c
       #include "builtin.h"
       #include "abspath.h"
       #include "config.h"
     +@@
     + #include "compat/fsmonitor/fsm-health.h"
     + #include "compat/fsmonitor/fsm-listen.h"
     + #include "fsmonitor--daemon.h"
     +-#include "repository.h"
     ++
     + #include "simple-ipc.h"
     + #include "khash.h"
     + #include "run-command.h"
      
       ## builtin/gc.c ##
      @@
     @@ builtin/gc.c
       #include "builtin.h"
       #include "abspath.h"
       #include "date.h"
     + #include "environment.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "config.h"
     + #include "tempfile.h"
     + #include "lockfile.h"
      
       ## builtin/grep.c ##
      @@
     @@ builtin/grep.c
       #include "builtin.h"
       #include "abspath.h"
       #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "config.h"
     + #include "tag.h"
     + #include "tree-walk.h"
      
       ## builtin/hash-object.c ##
      @@
     @@ builtin/hash-object.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "abspath.h"
       #include "config.h"
     - #include "gettext.h"
      
       ## builtin/help.c ##
      @@
     @@ builtin/index-pack.c
       #include "config.h"
       #include "delta.h"
      
     + ## builtin/init-db.c ##
     +@@
     +  *
     +  * Copyright (C) Linus Torvalds, 2005
     +  */
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "abspath.h"
     + #include "environment.h"
     +@@
     + #include "parse-options.h"
     + #include "path.h"
     + #include "refs.h"
     +-#include "repository.h"
     + #include "setup.h"
     + #include "strbuf.h"
     + 
     +
       ## builtin/interpret-trailers.c ##
      @@
        * Copyright (c) 2013, 2014 Christian Couder <[email protected]>
     @@ builtin/log.c
       #include "builtin.h"
       #include "abspath.h"
       #include "config.h"
     +@@
     + #include "mailmap.h"
     + #include "progress.h"
     + #include "commit-slab.h"
     +-#include "repository.h"
     ++
     + #include "commit-reach.h"
     + #include "range-diff.h"
     + #include "tmp-objdir.h"
      
       ## builtin/ls-files.c ##
      @@
     @@ builtin/ls-files.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     - #include "repository.h"
     +-#include "repository.h"
       #include "config.h"
     + #include "convert.h"
     + #include "quote.h"
      
       ## builtin/ls-remote.c ##
      @@
     @@ builtin/ls-tree.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "config.h"
       #include "gettext.h"
       #include "hex.h"
      
     + ## builtin/mailinfo.c ##
     +@@
     +  * Another stupid program, this one parsing the headers of an
     +  * email to figure out authorship and subject
     +  */
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "abspath.h"
     + #include "environment.h"
     +
       ## builtin/merge-base.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
       #include "config.h"
       #include "commit.h"
     +@@
     + #include "hex.h"
     + #include "object-name.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + #include "commit-reach.h"
     + 
     + static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
      
       ## builtin/merge-file.c ##
      @@
     @@ builtin/merge-index.c
       #include "builtin.h"
       #include "hex.h"
       #include "read-cache-ll.h"
     +-#include "repository.h"
     + #include "run-command.h"
     + #include "sparse-index.h"
     + 
      
       ## builtin/merge-ours.c ##
      @@
     @@ builtin/merge-ours.c
       #include "git-compat-util.h"
       #include "builtin.h"
       #include "diff.h"
     +-#include "repository.h"
     ++
     + 
     + static const char builtin_merge_ours_usage[] =
     + 	"git merge-ours <base>... -- HEAD <remote>...";
      
       ## builtin/merge-recursive.c ##
      @@
     @@ builtin/merge-recursive.c
       #include "builtin.h"
       #include "advice.h"
       #include "gettext.h"
     + #include "hash.h"
     + #include "merge-recursive.h"
     + #include "object-name.h"
     +-#include "repository.h"
     + 
     + static const char builtin_merge_recursive_usage[] =
     + 	"git %s <base>... -- <head> <remote> ...";
      
       ## builtin/merge-tree.c ##
      @@
     @@ builtin/merge-tree.c
       #include "builtin.h"
       #include "tree-walk.h"
       #include "xdiff-interface.h"
     +@@
     + #include "object-name.h"
     + #include "object-store-ll.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + #include "blob.h"
     + #include "merge-blobs.h"
     + #include "quote.h"
      
       ## builtin/merge.c ##
      @@
     @@ builtin/merge.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "abspath.h"
       #include "advice.h"
       #include "config.h"
     @@ builtin/mktree.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "gettext.h"
       #include "hex.h"
     - #include "quote.h"
      
       ## builtin/multi-pack-index.c ##
      @@
     @@ builtin/mv.c
       
       #include "builtin.h"
       #include "abspath.h"
     +@@
     + #include "string-list.h"
     + #include "parse-options.h"
     + #include "read-cache-ll.h"
     +-#include "repository.h"
     ++
     + #include "setup.h"
     + #include "strvec.h"
     + #include "submodule.h"
      
       ## builtin/name-rev.c ##
      @@
     @@ builtin/name-rev.c
       #include "builtin.h"
       #include "environment.h"
       #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "config.h"
     + #include "commit.h"
     + #include "tag.h"
      
       ## builtin/notes.c ##
      @@
     @@ builtin/notes.c
       #include "builtin.h"
       #include "config.h"
       #include "editor.h"
     +@@
     + #include "object-name.h"
     + #include "object-store-ll.h"
     + #include "path.h"
     +-#include "repository.h"
     ++
     + #include "pretty.h"
     + #include "refs.h"
     + #include "exec-cmd.h"
      
       ## builtin/pack-objects.c ##
      @@
     @@ builtin/pack-objects.c
       #include "builtin.h"
       #include "environment.h"
       #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     + #include "config.h"
     + #include "attr.h"
     + #include "object.h"
      
       ## builtin/pack-redundant.c ##
      @@
     @@ builtin/pack-redundant.c
       
       #include "builtin.h"
       #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     ++
     + #include "packfile.h"
     + #include "object-store-ll.h"
     + 
      
       ## builtin/pack-refs.c ##
      @@
     @@ builtin/pack-refs.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     + #include "parse-options.h"
     + #include "refs.h"
     +-#include "repository.h"
     + #include "revision.h"
     + 
     + static char const * const pack_refs_usage[] = {
      
       ## builtin/patch-id.c ##
      @@
     @@ builtin/push.c
       #include "builtin.h"
       #include "advice.h"
       #include "branch.h"
     +@@
     + #include "transport.h"
     + #include "parse-options.h"
     + #include "pkt-line.h"
     +-#include "repository.h"
     + #include "submodule.h"
     + #include "submodule-config.h"
     + #include "send-pack.h"
      
       ## builtin/range-diff.c ##
      @@
     @@ builtin/range-diff.c
       #include "builtin.h"
       #include "gettext.h"
       #include "object-name.h"
     + #include "parse-options.h"
     + #include "range-diff.h"
     + #include "config.h"
     +-#include "repository.h"
     ++
     + 
     + static const char * const builtin_range_diff_usage[] = {
     + N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
      
       ## builtin/read-tree.c ##
      @@
     @@ builtin/read-tree.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     +@@
     + #include "cache-tree.h"
     + #include "unpack-trees.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + #include "resolve-undo.h"
     + #include "setup.h"
     + #include "sparse-index.h"
      
       ## builtin/rebase.c ##
      @@
     @@ builtin/rebase.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "abspath.h"
       #include "environment.h"
       #include "gettext.h"
     @@ builtin/receive-pack.c
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
       #include "abspath.h"
     - #include "repository.h"
     +-#include "repository.h"
     ++
     + #include "config.h"
     + #include "environment.h"
     + #include "gettext.h"
      
       ## builtin/reflog.c ##
      @@
     @@ builtin/reflog.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     +-#include "repository.h"
     + #include "revision.h"
     + #include "reachable.h"
     + #include "wildmatch.h"
      
       ## builtin/refs.c ##
      @@
     @@ builtin/refs.c
       #include "builtin.h"
       #include "config.h"
       #include "fsck.h"
     + #include "parse-options.h"
     + #include "refs.h"
     +-#include "repository.h"
     + #include "strbuf.h"
     + 
     + #define REFS_MIGRATE_USAGE \
      
       ## builtin/remote.c ##
      @@
     @@ builtin/replace.c
        * and Carlos Rica <[email protected]> that was itself based on
        * git-tag.sh and mktag.c by Linus Torvalds.
        */
     +-
      +#define USE_THE_REPOSITORY_VARIABLE
     - 
       #include "builtin.h"
       #include "config.h"
     + #include "editor.h"
     +@@
     + #include "object-name.h"
     + #include "object-store-ll.h"
     + #include "replace-object.h"
     +-#include "repository.h"
     + #include "tag.h"
     + #include "wildmatch.h"
     + 
      
       ## builtin/replay.c ##
      @@
     @@ builtin/rerere.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     ++
     + #include "string-list.h"
     + #include "rerere.h"
     + #include "xdiff/xdiff.h"
      
       ## builtin/reset.c ##
      @@
     @@ builtin/reset.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "advice.h"
       #include "config.h"
     - #include "environment.h"
      
       ## builtin/rev-list.c ##
      @@
     @@ builtin/rev-parse.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "abspath.h"
       #include "config.h"
       #include "commit.h"
     @@ builtin/revert.c
       #include "git-compat-util.h"
       #include "builtin.h"
       #include "parse-options.h"
     + #include "diff.h"
     + #include "gettext.h"
     +-#include "repository.h"
     + #include "revision.h"
     + #include "rerere.h"
     + #include "sequencer.h"
      
       ## builtin/rm.c ##
      @@
     @@ builtin/rm.c
       #include "builtin.h"
       #include "advice.h"
       #include "config.h"
     +@@
     + #include "object-name.h"
     + #include "parse-options.h"
     + #include "read-cache.h"
     +-#include "repository.h"
     ++
     + #include "string-list.h"
     + #include "setup.h"
     + #include "sparse-index.h"
      
       ## builtin/send-pack.c ##
      @@
     @@ builtin/shortlog.c
       #include "builtin.h"
       #include "config.h"
       #include "commit.h"
     +@@
     + #include "environment.h"
     + #include "gettext.h"
     + #include "string-list.h"
     +-#include "repository.h"
     + #include "revision.h"
     + #include "utf8.h"
     + #include "mailmap.h"
      
       ## builtin/show-branch.c ##
      @@
     @@ builtin/show-branch.c
       #include "builtin.h"
       #include "config.h"
       #include "environment.h"
     +@@
     + #include "strvec.h"
     + #include "object-name.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     ++
     + #include "dir.h"
     + #include "commit-slab.h"
     + #include "date.h"
      
       ## builtin/show-index.c ##
      @@
     @@ builtin/show-index.c
       #include "builtin.h"
       #include "gettext.h"
       #include "hash.h"
     + #include "hex.h"
     + #include "pack.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + 
     + static const char *const show_index_usage[] = {
     + 	"git show-index [--object-format=<hash-algorithm>]",
      
       ## builtin/show-ref.c ##
      @@
     @@ builtin/sparse-checkout.c
       #include "builtin.h"
       #include "config.h"
       #include "dir.h"
     +@@
     + #include "object-name.h"
     + #include "parse-options.h"
     + #include "pathspec.h"
     +-#include "repository.h"
     + #include "strbuf.h"
     + #include "string-list.h"
     + #include "lockfile.h"
      
       ## builtin/stash.c ##
      @@
     @@ builtin/submodule--helper.c
       #include "builtin.h"
       #include "abspath.h"
       #include "environment.h"
     + #include "gettext.h"
     + #include "hex.h"
     +-#include "repository.h"
     ++
     + #include "config.h"
     + #include "parse-options.h"
     + #include "quote.h"
      
       ## builtin/symbolic-ref.c ##
      @@
     @@ builtin/tag.c
      -
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "advice.h"
       #include "config.h"
     - #include "editor.h"
      
       ## builtin/unpack-file.c ##
      @@
     @@ builtin/update-index.c
        *
        * Copyright (C) Linus Torvalds, 2005
        */
     +-
      +#define USE_THE_REPOSITORY_VARIABLE
     - 
       #include "builtin.h"
       #include "bulk-checkin.h"
     + #include "config.h"
     +@@
     + #include "pathspec.h"
     + #include "dir.h"
     + #include "read-cache.h"
     +-#include "repository.h"
     + #include "setup.h"
     + #include "sparse-index.h"
     + #include "split-index.h"
      
       ## builtin/update-ref.c ##
      @@
     @@ builtin/update-ref.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     +@@
     + #include "object-name.h"
     + #include "parse-options.h"
     + #include "quote.h"
     +-#include "repository.h"
     + 
     + static const char * const git_update_ref_usage[] = {
     + 	N_("git update-ref [<options>] -d <refname> [<old-oid>]"),
      
       ## builtin/update-server-info.c ##
      @@
     @@ builtin/upload-archive.c
       #include "builtin.h"
       #include "archive.h"
       #include "path.h"
     + #include "pkt-line.h"
     + #include "sideband.h"
     +-#include "repository.h"
     + #include "run-command.h"
     + #include "strvec.h"
     + 
      
       ## builtin/var.c ##
      @@
     @@ builtin/var.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
     ++
       #include "attr.h"
       #include "config.h"
       #include "editor.h"
     @@ builtin/verify-commit.c
       #include "builtin.h"
       #include "config.h"
       #include "gettext.h"
     + #include "object-name.h"
     +-#include "repository.h"
     + #include "commit.h"
     + #include "parse-options.h"
     + #include "gpg-interface.h"
      
       ## builtin/verify-pack.c ##
      @@
     @@ builtin/verify-tag.c
        */
      +#define USE_THE_REPOSITORY_VARIABLE
       #include "builtin.h"
     -+#include "repository.h"
       #include "config.h"
       #include "gettext.h"
     - #include "tag.h"
      
       ## builtin/worktree.c ##
      @@
     @@ builtin/worktree.c
       #include "builtin.h"
       #include "abspath.h"
       #include "advice.h"
     +@@
     + #include "read-cache-ll.h"
     + #include "refs.h"
     + #include "remote.h"
     +-#include "repository.h"
     + #include "run-command.h"
     + #include "hook.h"
     + #include "sigchain.h"
      
       ## builtin/write-tree.c ##
      @@
     @@ builtin/write-tree.c
       #include "builtin.h"
       #include "config.h"
       #include "environment.h"
     +@@
     + #include "tree.h"
     + #include "cache-tree.h"
     + #include "parse-options.h"
     +-#include "repository.h"
     + 
     + static const char * const write_tree_usage[] = {
     + 	N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
 3:  bc909046934 ! 3:  6956d3fe897 add: pass in repo variable instead of global the_repository
     @@ Commit message
          Signed-off-by: John Cai <[email protected]>
      
       ## builtin/add.c ##
     +@@
     +  *
     +  * Copyright (C) 2006 Linus Torvalds
     +  */
     +-#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "advice.h"
     + #include "config.h"
      @@ builtin/add.c: static int pathspec_file_nul;
       static int include_sparse;
       static const char *pathspec_from_file;
       
      -static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
     -+static int chmod_pathspec(struct pathspec *pathspec,
     ++static int chmod_pathspec(struct repository *repo,
     ++			  struct pathspec *pathspec,
      +			  char flip,
     -+			  int show_only,
     -+			  struct repository *repo)
     ++			  int show_only)
       {
       	int i, ret = 0;
       
     @@ builtin/add.c: static int chmod_pathspec(struct pathspec *pathspec, char flip, i
       }
       
      -static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
     -+static int renormalize_tracked_files(const struct pathspec *pathspec, int flags, struct repository *repo)
     ++static int renormalize_tracked_files(struct repository *repo,
     ++				     const struct pathspec *pathspec,
     ++				     int flags)
       {
       	int i, retval = 0;
       
     @@ builtin/add.c: static int chmod_pathspec(struct pathspec *pathspec, char flip, i
       }
       
      -static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix)
     -+static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix, struct repository *repo)
     ++static char *prune_directory(struct repository *repo,
     ++			     struct dir_struct *dir,
     ++			     struct pathspec *pathspec,
     ++			     int prefix)
       {
       	char *seen;
       	int i;
     @@ builtin/add.c: static char *prune_directory(struct dir_struct *dir, struct paths
       }
       
      -static int refresh(int verbose, const struct pathspec *pathspec)
     -+static int refresh(int verbose, const struct pathspec *pathspec, struct repository *repo)
     ++static int refresh(struct repository *repo, int verbose, const struct pathspec *pathspec)
       {
       	char *seen;
       	int i, ret = 0;
     @@ builtin/add.c: static int refresh(int verbose, const struct pathspec *pathspec)
       }
       
      -int interactive_add(const char **argv, const char *prefix, int patch)
     -+int interactive_add(const char **argv, const char *prefix, int patch, struct repository *repo)
     ++int interactive_add(struct repository *repo,
     ++		    const char **argv,
     ++		    const char *prefix,
     ++		    int patch)
       {
       	struct pathspec pathspec;
       	int ret;
     @@ builtin/add.c: int interactive_add(const char **argv, const char *prefix, int pa
       	return ret;
       }
       
     --static int edit_patch(int argc, const char **argv, const char *prefix)
     -+static int edit_patch(int argc, const char **argv, const char *prefix, struct repository *repo)
     +-static int edit_patch(int argc,
     ++static int edit_patch(struct repository *repo,
     ++		      int argc,
     + 		      const char **argv,
     +-		      const char *prefix,
     +-		      struct repository *repo UNUSED)
     ++		      const char *prefix)
       {
     - 	char *file = git_pathdup("ADD_EDIT.patch");
     +-	char *file = git_pathdup("ADD_EDIT.patch");
     ++	char *file = repo_git_path(repo, "ADD_EDIT.patch");
       	struct child_process child = CHILD_PROCESS_INIT;
     -@@ builtin/add.c: static int edit_patch(int argc, const char **argv, const char *prefix)
     + 	struct rev_info rev;
     + 	int out;
     + 	struct stat st;
       
     - 	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
     +-	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
     ++	repo_config(repo, git_diff_basic_config, NULL);
       
      -	if (repo_read_index(the_repository) < 0)
      +	if (repo_read_index(repo) < 0)
     @@ builtin/add.c: static void check_embedded_repo(const char *path)
       }
       
      -static int add_files(struct dir_struct *dir, int flags)
     -+static int add_files(struct dir_struct *dir, int flags, struct repository *repo)
     ++static int add_files(struct repository *repo, struct dir_struct *dir, int flags)
       {
       	int i, exit_status = 0;
       	struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP;
     @@ builtin/add.c: static int add_files(struct dir_struct *dir, int flags)
       				die(_("adding files failed"));
       			exit_status = 1;
      @@ builtin/add.c: static int add_files(struct dir_struct *dir, int flags)
     - 	return exit_status;
     - }
     - 
     --int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
     -+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repo)
     + int cmd_add(int argc,
     + 	    const char **argv,
     + 	    const char *prefix,
     +-	    struct repository *repo UNUSED)
     ++	    struct repository *repo)
       {
       	int exit_status = 0;
       	struct pathspec pathspec;
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
     + 	char *ps_matched = NULL;
     + 	struct lock_file lock_file = LOCK_INIT;
     + 
     +-	git_config(add_config, NULL);
     ++	repo_config(repo, add_config, NULL);
     + 
     + 	argc = parse_options(argc, argv, prefix, builtin_add_options,
     + 			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
     +@@ builtin/add.c: int cmd_add(int argc,
       			die(_("options '%s' and '%s' cannot be used together"), "--dry-run", "--interactive/--patch");
       		if (pathspec_from_file)
       			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--interactive/--patch");
      -		exit(interactive_add(argv + 1, prefix, patch_interactive));
     -+		exit(interactive_add(argv + 1, prefix, patch_interactive, repo));
     ++		exit(interactive_add(repo, argv + 1, prefix, patch_interactive));
       	}
       
       	if (edit_interactive) {
       		if (pathspec_from_file)
       			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--edit");
     --		return(edit_patch(argc, argv, prefix));
     -+		return(edit_patch(argc, argv, prefix, repo));
     +-		return(edit_patch(argc, argv, prefix, the_repository));
     ++		return(edit_patch(repo, argc, argv, prefix));
       	}
       	argc--;
       	argv++;
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       	add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
       	require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
       
     @@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, stru
       
       	/*
       	 * Check the "pathspec '%s' did not match any files" block
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       		 (!(addremove || take_worktree_changes)
       		  ? ADD_CACHE_IGNORE_REMOVAL : 0));
       
     @@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, stru
       
       	if (add_new_files) {
       		int baselen;
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       		}
       
       		/* This picks up the paths that are not tracked */
     @@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, stru
      +		baselen = fill_directory(&dir, repo->index, &pathspec);
       		if (pathspec.nr)
      -			seen = prune_directory(&dir, &pathspec, baselen);
     -+			seen = prune_directory(&dir, &pathspec, baselen, repo);
     ++			seen = prune_directory(repo, &dir, &pathspec, baselen);
       	}
       
       	if (refresh_only) {
      -		exit_status |= refresh(verbose, &pathspec);
     -+		exit_status |= refresh(verbose, &pathspec, repo);
     ++		exit_status |= refresh(repo, verbose, &pathspec);
       		goto finish;
       	}
       
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       
       		if (!seen)
       			seen = find_pathspecs_matching_against_index(&pathspec,
     @@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, stru
       
       		/*
       		 * file_exists() assumes exact match
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       			    !file_exists(path)) {
       				if (ignore_missing) {
       					int dtype = DT_UNKNOWN;
     @@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, stru
       								path, pathspec.items[i].len);
       				} else
       					die(_("pathspec '%s' did not match any files"),
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       
       	ps_matched = xcalloc(pathspec.nr, 1);
       	if (add_renormalize)
      -		exit_status |= renormalize_tracked_files(&pathspec, flags);
     -+		exit_status |= renormalize_tracked_files(&pathspec, flags, repo);
     ++		exit_status |= renormalize_tracked_files(repo, &pathspec, flags);
       	else
      -		exit_status |= add_files_to_cache(the_repository, prefix,
      +		exit_status |= add_files_to_cache(repo, prefix,
       						  &pathspec, ps_matched,
       						  include_sparse, flags);
       
     -@@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix, struct repository *
     +@@ builtin/add.c: int cmd_add(int argc,
       		exit(128);
       
       	if (add_new_files)
      -		exit_status |= add_files(&dir, flags);
     -+		exit_status |= add_files(&dir, flags, repo);
     ++		exit_status |= add_files(repo, &dir, flags);
       
       	if (chmod_arg && pathspec.nr)
      -		exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
     -+		exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only, repo);
     ++		exit_status |= chmod_pathspec(repo, &pathspec, chmod_arg[0], show_only);
       	end_odb_transaction();
       
       finish:
     @@ builtin/commit.c: static const char *prepare_index(const char **argv, const char
       		setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
       
      -		if (interactive_add(argv, prefix, patch_interactive) != 0)
     -+		if (interactive_add(argv, prefix, patch_interactive, the_repository) != 0)
     ++		if (interactive_add(the_repository, argv, prefix, patch_interactive) != 0)
       			die(_("interactive add failed"));
       
       		the_repository->index_file = old_repo_index_file;
      
       ## commit.h ##
     -@@
     - #define COMMIT_H
     - 
     - #include "object.h"
     -+#include "repository.h"
     - 
     - struct signature_check;
     - struct strbuf;
      @@ commit.h: struct oid_array;
       struct ref;
       int for_each_commit_graft(each_commit_graft_fn, void *);
       
      -int interactive_add(const char **argv, const char *prefix, int patch);
     -+int interactive_add(const char **argv, const char *prefix, int patch, struct repository *repo);
     ++int interactive_add(struct repository *repo,
     ++		    const char **argv,
     ++		    const char *prefix,
     ++		    int patch);
       
       struct commit_extra_header {
       	struct commit_extra_header *next;
Signature · 1 line
gitgitgadget
#12 lore raw

PATCH v2 1/3 builtin: add a repository parameter for builtin functions

From: John Cai <[email protected]>

In order to reduce the usage of the global the_repository, add a parameter to builtin functions that will get passed a repository variable.

This commit uses UNUSED on most of the builtin functions, as subsequent commits will modify the actual builtins to pass the repository parameter down.

---
 builtin.h                          | 277 +++++++++++++++--------------
 builtin/add.c                      |  12 +-
 builtin/am.c                       |   5 +-
 builtin/annotate.c                 |   7 +-
 builtin/apply.c                    |   5 +-
 builtin/archive.c                  |   5 +-
 builtin/bisect.c                   |   5 +-
 builtin/blame.c                    |   5 +-
 builtin/branch.c                   |   5 +-
 builtin/bugreport.c                |   5 +-
 builtin/bundle.c                   |   5 +-
 builtin/cat-file.c                 |   7 +-
 builtin/check-attr.c               |   5 +-
 builtin/check-ignore.c             |   5 +-
 builtin/check-mailmap.c            |   5 +-
 builtin/check-ref-format.c         |   5 +-
 builtin/checkout--worker.c         |   5 +-
 builtin/checkout-index.c           |   5 +-
 builtin/checkout.c                 |  15 +-
 builtin/clean.c                    |   5 +-
 builtin/clone.c                    |   5 +-
 builtin/column.c                   |   5 +-
 builtin/commit-graph.c             |   5 +-
 builtin/commit-tree.c              |   5 +-
 builtin/commit.c                   |  10 +-
 builtin/config.c                   |   5 +-
 builtin/count-objects.c            |   5 +-
 builtin/credential-cache--daemon.c |  10 +-
 builtin/credential-cache.c         |   5 +-
 builtin/credential-store.c         |   5 +-
 builtin/credential.c               |   5 +-
 builtin/describe.c                 |   7 +-
 builtin/diagnose.c                 |   5 +-
 builtin/diff-files.c               |   5 +-
 builtin/diff-index.c               |   5 +-
 builtin/diff-tree.c                |   5 +-
 builtin/diff.c                     |   5 +-
 builtin/difftool.c                 |   5 +-
 builtin/fast-export.c              |   5 +-
 builtin/fast-import.c              |   5 +-
 builtin/fetch-pack.c               |   5 +-
 builtin/fetch.c                    |   5 +-
 builtin/fmt-merge-msg.c            |   5 +-
 builtin/for-each-ref.c             |   5 +-
 builtin/for-each-repo.c            |   5 +-
 builtin/fsck.c                     |   5 +-
 builtin/fsmonitor--daemon.c        |   7 +-
 builtin/gc.c                       |  10 +-
 builtin/get-tar-commit-id.c        |   5 +-
 builtin/grep.c                     |   5 +-
 builtin/hash-object.c              |   5 +-
 builtin/help.c                     |   5 +-
 builtin/hook.c                     |   5 +-
 builtin/index-pack.c               |   5 +-
 builtin/init-db.c                  |   5 +-
 builtin/interpret-trailers.c       |   5 +-
 builtin/log.c                      |  30 +++-
 builtin/ls-files.c                 |   5 +-
 builtin/ls-remote.c                |   5 +-
 builtin/ls-tree.c                  |   5 +-
 builtin/mailinfo.c                 |   5 +-
 builtin/mailsplit.c                |   5 +-
 builtin/merge-base.c               |   5 +-
 builtin/merge-file.c               |   5 +-
 builtin/merge-index.c              |   5 +-
 builtin/merge-ours.c               |   5 +-
 builtin/merge-recursive.c          |   5 +-
 builtin/merge-tree.c               |   5 +-
 builtin/merge.c                    |   9 +-
 builtin/mktag.c                    |   5 +-
 builtin/mktree.c                   |   6 +-
 builtin/multi-pack-index.c         |   6 +-
 builtin/mv.c                       |   5 +-
 builtin/name-rev.c                 |   5 +-
 builtin/notes.c                    |   5 +-
 builtin/pack-objects.c             |   5 +-
 builtin/pack-redundant.c           |   7 +-
 builtin/pack-refs.c                |   5 +-
 builtin/patch-id.c                 |   5 +-
 builtin/prune-packed.c             |   5 +-
 builtin/prune.c                    |   5 +-
 builtin/pull.c                     |   5 +-
 builtin/push.c                     |   5 +-
 builtin/range-diff.c               |   5 +-
 builtin/read-tree.c                |   5 +-
 builtin/rebase.c                   |   5 +-
 builtin/receive-pack.c             |   5 +-
 builtin/reflog.c                   |   9 +-
 builtin/refs.c                     |   5 +-
 builtin/remote-ext.c               |   5 +-
 builtin/remote-fd.c                |   5 +-
 builtin/remote.c                   |   5 +-
 builtin/repack.c                   |   5 +-
 builtin/replace.c                  |   5 +-
 builtin/replay.c                   |   5 +-
 builtin/rerere.c                   |   5 +-
 builtin/reset.c                    |   5 +-
 builtin/rev-list.c                 |   5 +-
 builtin/rev-parse.c                |   5 +-
 builtin/revert.c                   |  10 +-
 builtin/rm.c                       |   5 +-
 builtin/send-pack.c                |   5 +-
 builtin/shortlog.c                 |   5 +-
 builtin/show-branch.c              |   5 +-
 builtin/show-index.c               |   5 +-
 builtin/show-ref.c                 |   5 +-
 builtin/sparse-checkout.c          |   5 +-
 builtin/stash.c                    |   5 +-
 builtin/stripspace.c               |   5 +-
 builtin/submodule--helper.c        |   5 +-
 builtin/symbolic-ref.c             |   5 +-
 builtin/tag.c                      |   5 +-
 builtin/unpack-file.c              |   5 +-
 builtin/unpack-objects.c           |   5 +-
 builtin/update-index.c             |   5 +-
 builtin/update-ref.c               |   5 +-
 builtin/update-server-info.c       |   5 +-
 builtin/upload-archive.c           |  10 +-
 builtin/upload-pack.c              |   5 +-
 builtin/var.c                      |   5 +-
 builtin/verify-commit.c            |   5 +-
 builtin/verify-pack.c              |   5 +-
 builtin/verify-tag.c               |   5 +-
 builtin/worktree.c                 |   5 +-
 builtin/write-tree.c               |   5 +-
 git.c                              |  12 +-
 help.c                             |   3 +-
 stkOs5Qh                           | Bin 0 -> 10485768 bytes
 128 files changed, 703 insertions(+), 296 deletions(-)
 create mode 100644 stkOs5Qh
builtin.h +139 -138
index 14fa0171607..fc6fc8ffed8 100644
@@ -10,6 +10,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 
 #include "git-compat-util.h"
+#include "repository.h"
 
 /*
  * builtin API
@@ -122,143 +123,143 @@ int is_builtin(const char *s);
 		BUG("unexpected prefix in builtin: %s", (prefix)); \
 } while (0)
 
-int cmd_add(int argc, const char **argv, const char *prefix);
-int cmd_am(int argc, const char **argv, const char *prefix);
-int cmd_annotate(int argc, const char **argv, const char *prefix);
-int cmd_apply(int argc, const char **argv, const char *prefix);
-int cmd_archive(int argc, const char **argv, const char *prefix);
-int cmd_bisect(int argc, const char **argv, const char *prefix);
-int cmd_blame(int argc, const char **argv, const char *prefix);
-int cmd_branch(int argc, const char **argv, const char *prefix);
-int cmd_bugreport(int argc, const char **argv, const char *prefix);
-int cmd_bundle(int argc, const char **argv, const char *prefix);
-int cmd_cat_file(int argc, const char **argv, const char *prefix);
-int cmd_checkout(int argc, const char **argv, const char *prefix);
-int cmd_checkout__worker(int argc, const char **argv, const char *prefix);
-int cmd_checkout_index(int argc, const char **argv, const char *prefix);
-int cmd_check_attr(int argc, const char **argv, const char *prefix);
-int cmd_check_ignore(int argc, const char **argv, const char *prefix);
-int cmd_check_mailmap(int argc, const char **argv, const char *prefix);
-int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
-int cmd_cherry(int argc, const char **argv, const char *prefix);
-int cmd_cherry_pick(int argc, const char **argv, const char *prefix);
-int cmd_clone(int argc, const char **argv, const char *prefix);
-int cmd_clean(int argc, const char **argv, const char *prefix);
-int cmd_column(int argc, const char **argv, const char *prefix);
-int cmd_commit(int argc, const char **argv, const char *prefix);
-int cmd_commit_graph(int argc, const char **argv, const char *prefix);
-int cmd_commit_tree(int argc, const char **argv, const char *prefix);
-int cmd_config(int argc, const char **argv, const char *prefix);
-int cmd_count_objects(int argc, const char **argv, const char *prefix);
-int cmd_credential(int argc, const char **argv, const char *prefix);
-int cmd_credential_cache(int argc, const char **argv, const char *prefix);
-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix);
-int cmd_credential_store(int argc, const char **argv, const char *prefix);
-int cmd_describe(int argc, const char **argv, const char *prefix);
-int cmd_diagnose(int argc, const char **argv, const char *prefix);
-int cmd_diff_files(int argc, const char **argv, const char *prefix);
-int cmd_diff_index(int argc, const char **argv, const char *prefix);
-int cmd_diff(int argc, const char **argv, const char *prefix);
-int cmd_diff_tree(int argc, const char **argv, const char *prefix);
-int cmd_difftool(int argc, const char **argv, const char *prefix);
-int cmd_env__helper(int argc, const char **argv, const char *prefix);
-int cmd_fast_export(int argc, const char **argv, const char *prefix);
-int cmd_fast_import(int argc, const char **argv, const char *prefix);
-int cmd_fetch(int argc, const char **argv, const char *prefix);
-int cmd_fetch_pack(int argc, const char **argv, const char *prefix);
-int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
-int cmd_for_each_ref(int argc, const char **argv, const char *prefix);
-int cmd_for_each_repo(int argc, const char **argv, const char *prefix);
-int cmd_format_patch(int argc, const char **argv, const char *prefix);
-int cmd_fsck(int argc, const char **argv, const char *prefix);
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix);
-int cmd_gc(int argc, const char **argv, const char *prefix);
-int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
-int cmd_grep(int argc, const char **argv, const char *prefix);
-int cmd_hash_object(int argc, const char **argv, const char *prefix);
-int cmd_help(int argc, const char **argv, const char *prefix);
-int cmd_hook(int argc, const char **argv, const char *prefix);
-int cmd_index_pack(int argc, const char **argv, const char *prefix);
-int cmd_init_db(int argc, const char **argv, const char *prefix);
-int cmd_interpret_trailers(int argc, const char **argv, const char *prefix);
-int cmd_log(int argc, const char **argv, const char *prefix);
-int cmd_log_reflog(int argc, const char **argv, const char *prefix);
-int cmd_ls_files(int argc, const char **argv, const char *prefix);
-int cmd_ls_tree(int argc, const char **argv, const char *prefix);
-int cmd_ls_remote(int argc, const char **argv, const char *prefix);
-int cmd_mailinfo(int argc, const char **argv, const char *prefix);
-int cmd_mailsplit(int argc, const char **argv, const char *prefix);
-int cmd_maintenance(int argc, const char **argv, const char *prefix);
-int cmd_merge(int argc, const char **argv, const char *prefix);
-int cmd_merge_base(int argc, const char **argv, const char *prefix);
-int cmd_merge_index(int argc, const char **argv, const char *prefix);
-int cmd_merge_ours(int argc, const char **argv, const char *prefix);
-int cmd_merge_file(int argc, const char **argv, const char *prefix);
-int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
-int cmd_merge_tree(int argc, const char **argv, const char *prefix);
-int cmd_mktag(int argc, const char **argv, const char *prefix);
-int cmd_mktree(int argc, const char **argv, const char *prefix);
-int cmd_multi_pack_index(int argc, const char **argv, const char *prefix);
-int cmd_mv(int argc, const char **argv, const char *prefix);
-int cmd_name_rev(int argc, const char **argv, const char *prefix);
-int cmd_notes(int argc, const char **argv, const char *prefix);
-int cmd_pack_objects(int argc, const char **argv, const char *prefix);
-int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
-int cmd_patch_id(int argc, const char **argv, const char *prefix);
-int cmd_prune(int argc, const char **argv, const char *prefix);
-int cmd_prune_packed(int argc, const char **argv, const char *prefix);
-int cmd_pull(int argc, const char **argv, const char *prefix);
-int cmd_push(int argc, const char **argv, const char *prefix);
-int cmd_range_diff(int argc, const char **argv, const char *prefix);
-int cmd_read_tree(int argc, const char **argv, const char *prefix);
-int cmd_rebase(int argc, const char **argv, const char *prefix);
-int cmd_rebase__interactive(int argc, const char **argv, const char *prefix);
-int cmd_receive_pack(int argc, const char **argv, const char *prefix);
-int cmd_reflog(int argc, const char **argv, const char *prefix);
-int cmd_refs(int argc, const char **argv, const char *prefix);
-int cmd_remote(int argc, const char **argv, const char *prefix);
-int cmd_remote_ext(int argc, const char **argv, const char *prefix);
-int cmd_remote_fd(int argc, const char **argv, const char *prefix);
-int cmd_repack(int argc, const char **argv, const char *prefix);
-int cmd_replay(int argc, const char **argv, const char *prefix);
-int cmd_rerere(int argc, const char **argv, const char *prefix);
-int cmd_reset(int argc, const char **argv, const char *prefix);
-int cmd_restore(int argc, const char **argv, const char *prefix);
-int cmd_rev_list(int argc, const char **argv, const char *prefix);
-int cmd_rev_parse(int argc, const char **argv, const char *prefix);
-int cmd_revert(int argc, const char **argv, const char *prefix);
-int cmd_rm(int argc, const char **argv, const char *prefix);
-int cmd_send_pack(int argc, const char **argv, const char *prefix);
-int cmd_shortlog(int argc, const char **argv, const char *prefix);
-int cmd_show(int argc, const char **argv, const char *prefix);
-int cmd_show_branch(int argc, const char **argv, const char *prefix);
-int cmd_show_index(int argc, const char **argv, const char *prefix);
-int cmd_sparse_checkout(int argc, const char **argv, const char *prefix);
-int cmd_status(int argc, const char **argv, const char *prefix);
-int cmd_stash(int argc, const char **argv, const char *prefix);
-int cmd_stripspace(int argc, const char **argv, const char *prefix);
-int cmd_submodule__helper(int argc, const char **argv, const char *prefix);
-int cmd_switch(int argc, const char **argv, const char *prefix);
-int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
-int cmd_tag(int argc, const char **argv, const char *prefix);
-int cmd_unpack_file(int argc, const char **argv, const char *prefix);
-int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
-int cmd_update_index(int argc, const char **argv, const char *prefix);
-int cmd_update_ref(int argc, const char **argv, const char *prefix);
-int cmd_update_server_info(int argc, const char **argv, const char *prefix);
-int cmd_upload_archive(int argc, const char **argv, const char *prefix);
-int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix);
-int cmd_upload_pack(int argc, const char **argv, const char *prefix);
-int cmd_var(int argc, const char **argv, const char *prefix);
-int cmd_verify_commit(int argc, const char **argv, const char *prefix);
-int cmd_verify_tag(int argc, const char **argv, const char *prefix);
-int cmd_version(int argc, const char **argv, const char *prefix);
-int cmd_whatchanged(int argc, const char **argv, const char *prefix);
-int cmd_worktree(int argc, const char **argv, const char *prefix);
-int cmd_write_tree(int argc, const char **argv, const char *prefix);
-int cmd_verify_pack(int argc, const char **argv, const char *prefix);
-int cmd_show_ref(int argc, const char **argv, const char *prefix);
-int cmd_pack_refs(int argc, const char **argv, const char *prefix);
-int cmd_replace(int argc, const char **argv, const char *prefix);
+int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_am(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_annotate(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_apply(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_archive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_bisect(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_blame(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_branch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_bugreport(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_bundle(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_cat_file(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_checkout(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_checkout__worker(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_checkout_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_attr(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_ignore(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_mailmap(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_check_ref_format(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_cherry(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_cherry_pick(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_clone(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_clean(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_column(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_commit(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_commit_graph(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_commit_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_config(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_count_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential_cache(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_credential_store(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_describe(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diagnose(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff_files(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_diff_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_difftool(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_env__helper(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fast_export(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fast_import(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fetch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fetch_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_for_each_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_for_each_repo(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_format_patch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fsck(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_gc(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_grep(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_hash_object(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_help(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_hook(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_index_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_init_db(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_interpret_trailers(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_log_reflog(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_log(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_ls_files(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_ls_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_ls_remote(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mailinfo(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mailsplit(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_maintenance(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_base(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_ours(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_file(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_recursive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_merge_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mktag(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mktree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_multi_pack_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_mv(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_name_rev(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_notes(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pack_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pack_redundant(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_patch_id(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_prune(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_prune_packed(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pull(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_push(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_range_diff(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_read_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rebase(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rebase__interactive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_receive_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_reflog(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_refs(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_remote(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_remote_ext(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_remote_fd(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_repack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_replay(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rerere(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_reset(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_restore(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rev_list(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rev_parse(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_revert(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_rm(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_send_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_shortlog(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show_branch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_sparse_checkout(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_status(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_stash(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_stripspace(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_submodule__helper(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_switch(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_symbolic_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_tag(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_unpack_file(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_unpack_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_update_index(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_update_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_update_server_info(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_upload_archive(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_upload_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_var(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_verify_commit(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_verify_tag(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_whatchanged(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_worktree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_write_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_verify_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_show_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_pack_refs(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_replace(int argc, const char **argv, const char *prefix, struct repository *repo);
 
 #endif
builtin/add.c +9 -3
index 40b61ef90d9..ba331519cac 100644
@@ -167,7 +167,10 @@ int interactive_add(const char **argv, const char *prefix, int patch)
 	return ret;
 }
 
-static int edit_patch(int argc, const char **argv, const char *prefix)
+static int edit_patch(int argc,
+		      const char **argv,
+		      const char *prefix,
+		      struct repository *repo UNUSED)
 {
 	char *file = git_pathdup("ADD_EDIT.patch");
 	struct child_process child = CHILD_PROCESS_INIT;
@@ -358,7 +361,10 @@ static int add_files(struct dir_struct *dir, int flags)
 	return exit_status;
 }
 
-int cmd_add(int argc, const char **argv, const char *prefix)
+int cmd_add(int argc,
+	    const char **argv,
+	    const char *prefix,
+	    struct repository *repo UNUSED)
 {
 	int exit_status = 0;
 	struct pathspec pathspec;
@@ -387,7 +393,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (edit_interactive) {
 		if (pathspec_from_file)
 			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--edit");
-		return(edit_patch(argc, argv, prefix));
+		return(edit_patch(argc, argv, prefix, the_repository));
 	}
 	argc--;
 	argv++;
builtin/am.c +4 -1
index d8875ad4022..8c610eed3e6 100644
@@ -2298,7 +2298,10 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
 	return 0;
 }
 
-int cmd_am(int argc, const char **argv, const char *prefix)
+int cmd_am(int argc,
+	   const char **argv,
+	   const char *prefix,
+	   struct repository *repo UNUSED)
 {
 	struct am_state state;
 	int binary = -1;
builtin/annotate.c +5 -2
index 58ff977a231..0abf89ef186 100644
@@ -7,7 +7,10 @@
 #include "builtin.h"
 #include "strvec.h"
 
-int cmd_annotate(int argc, const char **argv, const char *prefix)
+int cmd_annotate(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct strvec args = STRVEC_INIT;
 	int i;
@@ -18,5 +21,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix)
 		strvec_push(&args, argv[i]);
 	}
 
-	return cmd_blame(args.nr, args.v, prefix);
+	return cmd_blame(args.nr, args.v, prefix, the_repository);
 }
builtin/apply.c +4 -1
index d623c52f78f..ca0bb97df40 100644
@@ -9,7 +9,10 @@ static const char * const apply_usage[] = {
 	NULL
 };
 
-int cmd_apply(int argc, const char **argv, const char *prefix)
+int cmd_apply(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	int force_apply = 0;
 	int options = 0;
builtin/archive.c +4 -1
index b50981504f3..de59c3ae97a 100644
@@ -76,7 +76,10 @@ static int run_remote_archiver(int argc, const char **argv,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT |	\
 			     PARSE_OPT_NO_INTERNAL_HELP	)
 
-int cmd_archive(int argc, const char **argv, const char *prefix)
+int cmd_archive(int argc,
+		const char **argv,
+		const char *prefix,
+		struct repository *repo UNUSED)
 {
 	const char *exec = "git-upload-archive";
 	char *output = NULL;
builtin/bisect.c +4 -1
index 453a6cccd70..b83056df9f4 100644
@@ -1411,7 +1411,10 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
 	return res;
 }
 
-int cmd_bisect(int argc, const char **argv, const char *prefix)
+int cmd_bisect(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	int res = 0;
 	parse_opt_subcommand_fn *fn = NULL;
builtin/blame.c +4 -1
index 35e975fb132..728a62402b5 100644
@@ -864,7 +864,10 @@ static void build_ignorelist(struct blame_scoreboard *sb,
 	}
 }
 
-int cmd_blame(int argc, const char **argv, const char *prefix)
+int cmd_blame(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	char *path = NULL;
builtin/branch.c +4 -1
index 3f870741bfd..7980d2e83d6 100644
@@ -704,7 +704,10 @@ static int edit_branch_description(const char *branch_name)
 	return 0;
 }
 
-int cmd_branch(int argc, const char **argv, const char *prefix)
+int cmd_branch(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	/* possible actions */
 	int delete = 0, rename = 0, copy = 0, list = 0,
builtin/bugreport.c +4 -1
index bdfed3d8f18..aeab40c4902 100644
@@ -98,7 +98,10 @@ static void get_header(struct strbuf *buf, const char *title)
 	strbuf_addf(buf, "\n\n[%s]\n", title);
 }
 
-int cmd_bugreport(int argc, const char **argv, const char *prefix)
+int cmd_bugreport(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	struct strbuf buffer = STRBUF_INIT;
 	struct strbuf report_path = STRBUF_INIT;
builtin/bundle.c +4 -1
index 86d0ed7049c..97f7f530d0e 100644
@@ -226,7 +226,10 @@ cleanup:
 	return ret;
 }
 
-int cmd_bundle(int argc, const char **argv, const char *prefix)
+int cmd_bundle(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
builtin/cat-file.c +5 -2
index 18fe58d6b8b..b244b5a1ab6 100644
@@ -191,7 +191,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 			const char *ls_args[3] = { NULL };
 			ls_args[0] =  "ls-tree";
 			ls_args[1] =  obj_name;
-			ret = cmd_ls_tree(2, ls_args, NULL);
+			ret = cmd_ls_tree(2, ls_args, NULL, the_repository);
 			goto cleanup;
 		}
 
@@ -923,7 +923,10 @@ static int batch_option_callback(const struct option *opt,
 	return 0;
 }
 
-int cmd_cat_file(int argc, const char **argv, const char *prefix)
+int cmd_cat_file(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	int opt = 0;
 	int opt_cw = 0;
builtin/check-attr.c +4 -1
index 93768107100..ffd1067558d 100644
@@ -107,7 +107,10 @@ static NORETURN void error_with_usage(const char *msg)
 	usage_with_options(check_attr_usage, check_attr_options);
 }
 
-int cmd_check_attr(int argc, const char **argv, const char *prefix)
+int cmd_check_attr(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct attr_check *check;
 	struct object_id initialized_oid;
builtin/check-ignore.c +4 -1
index 2bda6a1d462..70565b9f892 100644
@@ -151,7 +151,10 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
 	return num_ignored;
 }
 
-int cmd_check_ignore(int argc, const char **argv, const char *prefix)
+int cmd_check_ignore(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	int num_ignored;
 	struct dir_struct dir = DIR_INIT;
builtin/check-mailmap.c +4 -1
index b8a05b8e07b..87cc036dd14 100644
@@ -40,7 +40,10 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)
 	printf("<%.*s>\n", (int)maillen, mail);
 }
 
-int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
+int cmd_check_mailmap(int argc,
+		      const char **argv,
+		      const char *prefix,
+		      struct repository *repo UNUSED)
 {
 	int i;
 	struct string_list mailmap = STRING_LIST_INIT_NODUP;
builtin/check-ref-format.c +4 -1
index 5eb6bdc3f69..6874edb4f41 100644
@@ -51,7 +51,10 @@ static int check_ref_format_branch(const char *arg)
 	return 0;
 }
 
-int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
+int cmd_check_ref_format(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo UNUSED)
 {
 	int i;
 	int normalize = 0;
builtin/checkout--worker.c +4 -1
index 6b62b5375bd..f53e1082690 100644
@@ -113,7 +113,10 @@ static const char * const checkout_worker_usage[] = {
 	NULL
 };
 
-int cmd_checkout__worker(int argc, const char **argv, const char *prefix)
+int cmd_checkout__worker(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo UNUSED)
 {
 	struct checkout state = CHECKOUT_INIT;
 	struct option checkout_worker_options[] = {
builtin/checkout-index.c +4 -1
index 29e744d11be..98247ff8236 100644
@@ -208,7 +208,10 @@ static int option_parse_stage(const struct option *opt,
 	return 0;
 }
 
-int cmd_checkout_index(int argc, const char **argv, const char *prefix)
+int cmd_checkout_index(int argc,
+		       const char **argv,
+		       const char *prefix,
+		       struct repository *repo UNUSED)
 {
 	int i;
 	struct lock_file lock_file = LOCK_INIT;
builtin/checkout.c +12 -3
index 4cfe6fab505..d3bc48684f9 100644
@@ -1953,7 +1953,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
 	return ret;
 }
 
-int cmd_checkout(int argc, const char **argv, const char *prefix)
+int cmd_checkout(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct checkout_opts opts = CHECKOUT_OPTS_INIT;
 	struct option *options;
@@ -2000,7 +2003,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 			     checkout_usage);
 }
 
-int cmd_switch(int argc, const char **argv, const char *prefix)
+int cmd_switch(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct checkout_opts opts = CHECKOUT_OPTS_INIT;
 	struct option *options = NULL;
@@ -2036,7 +2042,10 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
 			     switch_branch_usage);
 }
 
-int cmd_restore(int argc, const char **argv, const char *prefix)
+int cmd_restore(int argc,
+		const char **argv,
+		const char *prefix,
+		struct repository *repo UNUSED)
 {
 	struct checkout_opts opts = CHECKOUT_OPTS_INIT;
 	struct option *options;
builtin/clean.c +4 -1
index ded5a91534c..b5887f877e0 100644
@@ -915,7 +915,10 @@ static void correct_untracked_entries(struct dir_struct *dir)
 	dir->nr = dst;
 }
 
-int cmd_clean(int argc, const char **argv, const char *prefix)
+int cmd_clean(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	int i, res;
 	int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
builtin/clone.c +4 -1
index 269b6e18a4e..1b82310ac5b 100644
@@ -956,7 +956,10 @@ static int path_exists(const char *path)
 	return !stat(path, &sb);
 }
 
-int cmd_clone(int argc, const char **argv, const char *prefix)
+int cmd_clone(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repository UNUSED)
 {
 	int is_bundle = 0, is_local;
 	int reject_shallow = 0;
builtin/column.c +4 -1
index 10ff7e01668..93f84beeee7 100644
@@ -18,7 +18,10 @@ static int column_config(const char *var, const char *value,
 	return git_column_config(var, value, cb, &colopts);
 }
 
-int cmd_column(int argc, const char **argv, const char *prefix)
+int cmd_column(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct string_list list = STRING_LIST_INIT_DUP;
 	struct strbuf sb = STRBUF_INIT;
builtin/commit-graph.c +4 -1
index 7102ee90a00..65ce98d4675 100644
@@ -331,7 +331,10 @@ cleanup:
 	return result;
 }
 
-int cmd_commit_graph(int argc, const char **argv, const char *prefix)
+int cmd_commit_graph(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_commit_graph_options[] = {
builtin/commit-tree.c +4 -1
index 84bb4502229..bd8bf3296ed 100644
@@ -90,7 +90,10 @@ static int parse_file_arg_callback(const struct option *opt,
 	return 0;
 }
 
-int cmd_commit_tree(int argc, const char **argv, const char *prefix)
+int cmd_commit_tree(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	static struct strbuf buffer = STRBUF_INIT;
 	struct commit_list *parents = NULL;
builtin/commit.c +8 -2
index b2033c48877..768d76ac461 100644
@@ -1502,7 +1502,10 @@ static int git_status_config(const char *k, const char *v,
 	return git_diff_ui_config(k, v, ctx, NULL);
 }
 
-int cmd_status(int argc, const char **argv, const char *prefix)
+int cmd_status(int argc,
+const char **argv,
+const char *prefix,
+struct repository *repo UNUSED)
 {
 	static int no_renames = -1;
 	static const char *rename_score_arg = (const char *)-1;
@@ -1641,7 +1644,10 @@ static int git_commit_config(const char *k, const char *v,
 	return git_status_config(k, v, ctx, s);
 }
 
-int cmd_commit(int argc, const char **argv, const char *prefix)
+int cmd_commit(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	static struct wt_status s;
 	static struct option builtin_commit_options[] = {
builtin/config.c +4 -1
index e00d983596b..841a5d706f4 100644
@@ -1392,7 +1392,10 @@ out:
 	return ret;
 }
 
-int cmd_config(int argc, const char **argv, const char *prefix)
+int cmd_config(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *subcommand = NULL;
 	struct option subcommand_opts[] = {
builtin/count-objects.c +4 -1
index ec6098a149d..6b905da3c3d 100644
@@ -95,7 +95,10 @@ static char const * const count_objects_usage[] = {
 	NULL
 };
 
-int cmd_count_objects(int argc, const char **argv, const char *prefix)
+int cmd_count_objects(int argc,
+		      const char **argv,
+		      const char *prefix,
+		      struct repository *repo UNUSED)
 {
 	int human_readable = 0;
 	struct option opts[] = {
builtin/credential-cache--daemon.c +8 -2
index 4952b225477..4caaf38b841 100644
@@ -287,7 +287,10 @@ static void init_socket_directory(const char *path)
 	free(path_copy);
 }
 
-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
+int cmd_credential_cache_daemon(int argc,
+				const char **argv,
+				const char *prefix,
+				struct repository *repo UNUSED)
 {
 	struct tempfile *socket_file;
 	const char *socket_path;
@@ -330,7 +333,10 @@ int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
 
 #else
 
-int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
+int cmd_credential_cache_daemon(int argc,
+const char **argv,
+const char *prefix,
+struct repository *repo UNUSED)
 {
 	const char * const usage[] = {
 		"git credential-cache--daemon [--debug] <socket-path>",
builtin/credential-cache.c +4 -1
index aaf2f8438b4..5de8b9123bf 100644
@@ -137,7 +137,10 @@ static void announce_capabilities(void)
 	credential_announce_capabilities(&c, stdout);
 }
 
-int cmd_credential_cache(int argc, const char **argv, const char *prefix)
+int cmd_credential_cache(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo UNUSED)
 {
 	const char *socket_path_arg = NULL;
 	char *socket_path;
builtin/credential-store.c +4 -1
index 97968bfa1c2..128704078e9 100644
@@ -170,7 +170,10 @@ static void lookup_credential(const struct string_list *fns, struct credential *
 			return; /* Found credential */
 }
 
-int cmd_credential_store(int argc, const char **argv, const char *prefix)
+int cmd_credential_store(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo UNUSED)
 {
 	const char * const usage[] = {
 		"git credential-store [<options>] <action>",
builtin/credential.c +4 -1
index b72e76dd9a6..796422c6fe7 100644
@@ -6,7 +6,10 @@
 static const char usage_msg[] =
 	"git credential (fill|approve|reject)";
 
-int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_credential(int argc,
+		   const char **argv,
+		   const char *prefix UNUSED,
+		   struct repository *repo UNUSED)
 {
 	const char *op;
 	struct credential c = CREDENTIAL_INIT;
builtin/describe.c +5 -2
index b43093c099f..1c1c250fe0c 100644
@@ -571,7 +571,10 @@ static int option_parse_exact_match(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_describe(int argc, const char **argv, const char *prefix)
+int cmd_describe(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED )
 {
 	int contains = 0;
 	struct option options[] = {
@@ -650,7 +653,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			argv_copy[i] = args.v[i];
 		argv_copy[args.nr] = NULL;
 
-		ret = cmd_name_rev(args.nr, argv_copy, prefix);
+		ret = cmd_name_rev(args.nr, argv_copy, prefix, the_repository);
 
 		strvec_clear(&args);
 		free(argv_copy);
builtin/diagnose.c +4 -1
index 4857a4395ba..66a22d918e6 100644
@@ -11,7 +11,10 @@ static const char * const diagnose_usage[] = {
 	NULL
 };
 
-int cmd_diagnose(int argc, const char **argv, const char *prefix)
+int cmd_diagnose(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct strbuf zip_path = STRBUF_INIT;
 	time_t now = time(NULL);
builtin/diff-files.c +4 -1
index 018011f29ea..7f4f9bcb3eb 100644
@@ -17,7 +17,10 @@ static const char diff_files_usage[] =
 "\n"
 COMMON_DIFF_OPTIONS_HELP;
 
-int cmd_diff_files(int argc, const char **argv, const char *prefix)
+int cmd_diff_files(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct rev_info rev;
 	int result;
builtin/diff-index.c +4 -1
index 685b60284fd..8abec38592f 100644
@@ -14,7 +14,10 @@ static const char diff_cache_usage[] =
 "\n"
 COMMON_DIFF_OPTIONS_HELP;
 
-int cmd_diff_index(int argc, const char **argv, const char *prefix)
+int cmd_diff_index(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct rev_info rev;
 	unsigned int option = 0;
builtin/diff-tree.c +4 -1
index b8df1d4b79b..841448b023f 100644
@@ -108,7 +108,10 @@ static void diff_tree_tweak_rev(struct rev_info *rev)
 	}
 }
 
-int cmd_diff_tree(int argc, const char **argv, const char *prefix)
+int cmd_diff_tree(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	char line[1000];
 	struct object *tree1, *tree2;
builtin/diff.c +4 -1
index 6eac445579b..499b7872dd4 100644
@@ -393,7 +393,10 @@ static void symdiff_release(struct symdiff *sdiff)
 	bitmap_free(sdiff->skip);
 }
 
-int cmd_diff(int argc, const char **argv, const char *prefix)
+int cmd_diff(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	int i;
 	struct rev_info rev;
builtin/difftool.c +4 -1
index dcc68e190c2..c8700d67f4d 100644
@@ -690,7 +690,10 @@ static int run_file_diff(int prompt, const char *prefix,
 	return run_command(child);
 }
 
-int cmd_difftool(int argc, const char **argv, const char *prefix)
+int cmd_difftool(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	int use_gui_tool = -1, dir_diff = 0, prompt = -1, symlinks = 0,
 	    tool_help = 0, no_index = 0;
builtin/fast-export.c +4 -1
index f253b79322a..1bd5949dd24 100644
@@ -1180,7 +1180,10 @@ static int parse_opt_anonymize_map(const struct option *opt,
 	return 0;
 }
 
-int cmd_fast_export(int argc, const char **argv, const char *prefix)
+int cmd_fast_export(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	struct commit *commit;
builtin/fast-import.c +4 -1
index 2214c105f17..4b9e341aa44 100644
@@ -3537,7 +3537,10 @@ static void parse_argv(void)
 	build_mark_map(&sub_marks_from, &sub_marks_to);
 }
 
-int cmd_fast_import(int argc, const char **argv, const char *prefix)
+int cmd_fast_import(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	unsigned int i;
 
builtin/fetch-pack.c +4 -1
index af329e8d5cf..fddd8a2c1cd 100644
@@ -43,7 +43,10 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
 	(*sought)[*nr - 1] = ref;
 }
 
-int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_fetch_pack(int argc,
+		   const char **argv,
+		   const char *prefix UNUSED,
+		   struct repository *repo UNUSED)
 {
 	int i, ret;
 	struct ref *ref = NULL;
builtin/fetch.c +4 -1
index c297569a473..46ecfc5bc62 100644
@@ -2138,7 +2138,10 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
 	return exit_code;
 }
 
-int cmd_fetch(int argc, const char **argv, const char *prefix)
+int cmd_fetch(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	struct fetch_config config = {
 		.display_format = DISPLAY_FORMAT_FULL,
builtin/fmt-merge-msg.c +4 -1
index 957786d1b3a..1fba4cf5590 100644
@@ -9,7 +9,10 @@ static const char * const fmt_merge_msg_usage[] = {
 	NULL
 };
 
-int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
+int cmd_fmt_merge_msg(int argc,
+		      const char **argv,
+		      const char *prefix,
+		      struct repository *repo UNUSED)
 {
 	char *inpath = NULL;
 	const char *message = NULL;
builtin/for-each-ref.c +4 -1
index 5517a4a1c08..b1187587135 100644
@@ -16,7 +16,10 @@ static char const * const for_each_ref_usage[] = {
 	NULL
 };
 
-int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
+int cmd_for_each_ref(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	struct ref_sorting *sorting;
 	struct string_list sorting_options = STRING_LIST_INIT_DUP;
builtin/for-each-repo.c +4 -1
index c4fa41fda9f..93d82b952e9 100644
@@ -29,7 +29,10 @@ static int run_command_on_repo(const char *path, int argc, const char ** argv)
 	return run_command(&child);
 }
 
-int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
+int cmd_for_each_repo(int argc,
+		      const char **argv,
+		      const char *prefix,
+		      struct repository *repo UNUSED)
 {
 	static const char *config_key = NULL;
 	int keep_going = 0;
builtin/fsck.c +4 -1
index 60f4e6fad97..87068cee09d 100644
@@ -925,7 +925,10 @@ static struct option fsck_opts[] = {
 	OPT_END(),
 };
 
-int cmd_fsck(int argc, const char **argv, const char *prefix)
+int cmd_fsck(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	int i;
 	struct object_directory *odb;
builtin/fsmonitor--daemon.c +5 -2
index 1593713f4cb..73a4b885661 100644
@@ -1521,7 +1521,10 @@ static int try_to_start_background_daemon(void)
 	}
 }
 
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
+int cmd_fsmonitor__daemon(int argc,
+			  const char **argv,
+			  const char *prefix,
+			  struct repository *repo UNUSED)
 {
 	const char *subcmd;
 	enum fsmonitor_reason reason;
@@ -1584,7 +1587,7 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
 }
 
 #else
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
 {
 	struct option options[] = {
 		OPT_END()
builtin/gc.c +8 -2
index 427faf1cfe1..0727de1ae8e 100644
@@ -657,7 +657,10 @@ static void gc_before_repack(struct maintenance_run_opts *opts,
 	}
 }
 
-int cmd_gc(int argc, const char **argv, const char *prefix)
+int cmd_gc(int argc,
+const char **argv,
+const char *prefix,
+struct repository *repo UNUSED)
 {
 	int aggressive = 0;
 	int quiet = 0;
@@ -2890,7 +2893,10 @@ static const char * const builtin_maintenance_usage[] = {
 	NULL,
 };
 
-int cmd_maintenance(int argc, const char **argv, const char *prefix)
+int cmd_maintenance(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_maintenance_options[] = {
builtin/get-tar-commit-id.c +4 -1
index 7195a072edc..6bec0d1854c 100644
@@ -12,7 +12,10 @@ static const char builtin_get_tar_commit_id_usage[] =
 #define RECORDSIZE	(512)
 #define HEADERSIZE (2 * RECORDSIZE)
 
-int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix)
+int cmd_get_tar_commit_id(int argc,
+			  const char **argv UNUSED,
+			  const char *prefix,
+			  struct repository *repo UNUSED)
 {
 	char buffer[HEADERSIZE];
 	struct ustar_header *header = (struct ustar_header *)buffer;
builtin/grep.c +4 -1
index dfc3c3e8bd2..da11879c637 100644
@@ -888,7 +888,10 @@ static int pattern_callback(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_grep(int argc, const char **argv, const char *prefix)
+int cmd_grep(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	int hit = 0;
 	int cached = 0, untracked = 0, opt_exclude = -1;
builtin/hash-object.c +4 -1
index c767414a0cc..090daea5cd8 100644
@@ -84,7 +84,10 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
 	strbuf_release(&unquoted);
 }
 
-int cmd_hash_object(int argc, const char **argv, const char *prefix)
+int cmd_hash_object(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	static const char * const hash_object_usage[] = {
 		N_("git hash-object [-t <type>] [-w] [--path=<file> | --no-filters]\n"
builtin/help.c +4 -1
index dc1fbe2b986..f7723bdf5c8 100644
@@ -631,7 +631,10 @@ static void opt_mode_usage(int argc, const char *opt_mode,
 	no_help_format(opt_mode, fmt);
 }
 
-int cmd_help(int argc, const char **argv, const char *prefix)
+int cmd_help(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	int nongit;
 	enum help_format parsed_help_format;
builtin/hook.c +4 -1
index cc37438fdee..f02e2421ac0 100644
@@ -66,7 +66,10 @@ usage:
 	usage_with_options(builtin_hook_run_usage, run_options);
 }
 
-int cmd_hook(int argc, const char **argv, const char *prefix)
+int cmd_hook(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_hook_options[] = {
builtin/index-pack.c +4 -1
index fd968d673d2..3207130bfee 100644
@@ -1718,7 +1718,10 @@ static void show_pack_info(int stat_only)
 	free(chain_histogram);
 }
 
-int cmd_index_pack(int argc, const char **argv, const char *prefix)
+int cmd_index_pack(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
 	const char *curr_index;
builtin/init-db.c +4 -1
index 582dcf20f86..94bd6075095 100644
@@ -70,7 +70,10 @@ static const char *const init_db_usage[] = {
  * On the other hand, it might just make lookup slower and messier. You
  * be the judge.  The default case is to have one DB per managed directory.
  */
-int cmd_init_db(int argc, const char **argv, const char *prefix)
+int cmd_init_db(int argc,
+		const char **argv,
+		const char *prefix,
+		struct repository *repo UNUSED)
 {
 	const char *git_dir;
 	const char *real_git_dir = NULL;
builtin/interpret-trailers.c +4 -1
index 1d969494cf5..fb93e54e5ea 100644
@@ -188,7 +188,10 @@ static void interpret_trailers(const struct process_trailer_options *opts,
 	strbuf_release(&sb);
 }
 
-int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
+int cmd_interpret_trailers(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo UNUSED)
 {
 	struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
 	LIST_HEAD(trailers);
builtin/log.c +24 -6
index 36769bab3b6..67140575f4b 100644
@@ -637,7 +637,10 @@ static int git_log_config(const char *var, const char *value,
 	return git_diff_ui_config(var, value, ctx, cb);
 }
 
-int cmd_whatchanged(int argc, const char **argv, const char *prefix)
+int cmd_whatchanged(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -758,7 +761,10 @@ static void show_setup_revisions_tweak(struct rev_info *rev)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 }
 
-int cmd_show(int argc, const char **argv, const char *prefix)
+int cmd_show(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -874,7 +880,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 /*
  * This is equivalent to "git log -g --abbrev-commit --pretty=oneline"
  */
-int cmd_log_reflog(int argc, const char **argv, const char *prefix)
+int cmd_log_reflog(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -916,7 +925,10 @@ static void log_setup_revisions_tweak(struct rev_info *rev)
 		diff_merges_default_to_first_parent(rev);
 }
 
-int cmd_log(int argc, const char **argv, const char *prefix)
+int cmd_log(int argc,
+	    const char **argv,
+	    const char *prefix,
+	    struct repository *repo UNUSED)
 {
 	struct log_config cfg;
 	struct rev_info rev;
@@ -1986,7 +1998,10 @@ static void infer_range_diff_ranges(struct strbuf *r1,
 	}
 }
 
-int cmd_format_patch(int argc, const char **argv, const char *prefix)
+int cmd_format_patch(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	struct format_config cfg;
 	struct commit *commit;
@@ -2619,7 +2634,10 @@ static void print_commit(char sign, struct commit *commit, int verbose,
 	}
 }
 
-int cmd_cherry(int argc, const char **argv, const char *prefix)
+int cmd_cherry(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	struct patch_ids ids;
builtin/ls-files.c +4 -1
index 6eeb5cba783..7f45cb62cf6 100644
@@ -561,7 +561,10 @@ static int option_parse_exclude_standard(const struct option *opt,
 	return 0;
 }
 
-int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
+int cmd_ls_files(int argc,
+		 const char **argv,
+		 const char *cmd_prefix,
+		 struct repository *repo UNUSED)
 {
 	int require_work_tree = 0, show_tag = 0, i;
 	char *max_prefix;
builtin/ls-remote.c +4 -1
index 0a491595ca8..f2c2854d0c3 100644
@@ -37,7 +37,10 @@ static int tail_match(const struct strvec *pattern, const char *path)
 	return 0;
 }
 
-int cmd_ls_remote(int argc, const char **argv, const char *prefix)
+int cmd_ls_remote(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	const char *dest = NULL;
 	unsigned flags = 0;
builtin/ls-tree.c +4 -1
index bf372c67d77..363cb948d92 100644
@@ -329,7 +329,10 @@ static struct ls_tree_cmdmode_to_fmt ls_tree_cmdmode_format[] = {
 	},
 };
 
-int cmd_ls_tree(int argc, const char **argv, const char *prefix)
+int cmd_ls_tree(int argc,
+		const char **argv,
+		const char *prefix,
+		struct repository *repo UNUSED)
 {
 	struct object_id oid;
 	struct tree *tree;
builtin/mailinfo.c +4 -1
index 53a22645da5..00bfcd1afa0 100644
@@ -48,7 +48,10 @@ static int parse_opt_quoted_cr(const struct option *opt, const char *arg, int un
 	return 0;
 }
 
-int cmd_mailinfo(int argc, const char **argv, const char *prefix)
+int cmd_mailinfo(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct metainfo_charset meta_charset;
 	struct mailinfo mi;
builtin/mailsplit.c +4 -1
index fe6dbc5d053..b8f7150ce9a 100644
@@ -269,7 +269,10 @@ out:
 	return ret;
 }
 
-int cmd_mailsplit(int argc, const char **argv, const char *prefix)
+int cmd_mailsplit(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	int nr = 0, nr_prec = 4, num = 0;
 	int allow_bare = 0;
builtin/merge-base.c +4 -1
index 5a8e7295029..afeae8d8346 100644
@@ -143,7 +143,10 @@ static int handle_fork_point(int argc, const char **argv)
 	return 0;
 }
 
-int cmd_merge_base(int argc, const char **argv, const char *prefix)
+int cmd_merge_base(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct commit **rev;
 	int rev_nr = 0;
builtin/merge-file.c +4 -1
index 1f987334a31..f785813ddae 100644
@@ -53,7 +53,10 @@ static int diff_algorithm_cb(const struct option *opt,
 	return 0;
 }
 
-int cmd_merge_file(int argc, const char **argv, const char *prefix)
+int cmd_merge_file(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	const char *names[3] = { 0 };
 	mmfile_t mmfs[3] = { 0 };
builtin/merge-index.c +4 -1
index 0fabe3f6bb2..1309a8ff471 100644
@@ -73,7 +73,10 @@ static void merge_all(void)
 	}
 }
 
-int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_merge_index(int argc,
+		    const char **argv,
+		    const char *prefix UNUSED,
+		    struct repository *repo UNUSED)
 {
 	int i, force_file = 0;
 
builtin/merge-ours.c +4 -1
index 932924e5d0e..62267f12dd8 100644
@@ -15,7 +15,10 @@
 static const char builtin_merge_ours_usage[] =
 	"git merge-ours <base>... -- HEAD <remote>...";
 
-int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_merge_ours(int argc,
+		   const char **argv,
+		   const char *prefix UNUSED,
+		   struct repository *repo UNUSED)
 {
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage(builtin_merge_ours_usage);
builtin/merge-recursive.c +4 -1
index e951b09805d..2bd3fb0e553 100644
@@ -21,7 +21,10 @@ static char *better_branch_name(const char *branch)
 	return xstrdup(name ? name : branch);
 }
 
-int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_merge_recursive(int argc,
+			const char **argv,
+			const char *prefix UNUSED,
+			struct repository *repo UNUSED)
 {
 	struct object_id bases[21];
 	unsigned bases_count = 0;
builtin/merge-tree.c +4 -1
index 9bca9b5f33c..8751d86fd0f 100644
@@ -526,7 +526,10 @@ static int real_merge(struct merge_tree_options *o,
 	return !result.clean; /* result.clean < 0 handled above */
 }
 
-int cmd_merge_tree(int argc, const char **argv, const char *prefix)
+int cmd_merge_tree(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct merge_tree_options o = { .show_messages = -1 };
 	struct strvec xopts = STRVEC_INIT;
builtin/merge.c +6 -3
index 662a49a0e8c..fd6dc00d6c0 100644
@@ -1275,7 +1275,10 @@ static int merging_a_throwaway_tag(struct commit *commit)
 	return is_throwaway_tag;
 }
 
-int cmd_merge(int argc, const char **argv, const char *prefix)
+int cmd_merge(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	struct object_id result_tree, stash, head_oid;
 	struct commit *head_commit;
@@ -1347,7 +1350,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 					REF_NO_DEREF);
 
 		/* Invoke 'git reset --merge' */
-		ret = cmd_reset(nargc, nargv, prefix);
+		ret = cmd_reset(nargc, nargv, prefix, the_repository);
 
 		if (!is_null_oid(&stash_oid)) {
 			oid_to_hex_r(stash_oid_hex, &stash_oid);
@@ -1379,7 +1382,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			die(_("There is no merge in progress (MERGE_HEAD missing)."));
 
 		/* Invoke 'git commit' */
-		ret = cmd_commit(nargc, nargv, prefix);
+		ret = cmd_commit(nargc, nargv, prefix, the_repository);
 		goto done;
 	}
 
builtin/mktag.c +4 -1
index c6b644219fb..5cd8a3e6fa0 100644
@@ -71,7 +71,10 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
 	return ret;
 }
 
-int cmd_mktag(int argc, const char **argv, const char *prefix)
+int cmd_mktag(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	static struct option builtin_mktag_options[] = {
 		OPT_BOOL(0, "strict", &option_strict,
builtin/mktree.c +5 -1
index 9a22d4e2773..72a1af1bca5 100644
@@ -150,7 +150,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
 	free(to_free);
 }
 
-int cmd_mktree(int ac, const char **av, const char *prefix)
+int cmd_mktree(int ac,
+	       const char **av,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct strbuf sb = STRBUF_INIT;
 	struct object_id oid;
@@ -199,5 +202,6 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
 		used=0; /* reset tree entry buffer for re-use in batch mode */
 	}
 	strbuf_release(&sb);
+
 	return 0;
 }
builtin/multi-pack-index.c +4 -2
index 8805cbbeb3b..154fc77075f 100644
@@ -267,8 +267,10 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
 			   (size_t)opts.batch_size, opts.flags);
 }
 
-int cmd_multi_pack_index(int argc, const char **argv,
-			 const char *prefix)
+int cmd_multi_pack_index(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo UNUSED)
 {
 	int res;
 	parse_opt_subcommand_fn *fn = NULL;
builtin/mv.c +4 -1
index 6c69033c5f5..6e2eb9cf4b8 100644
@@ -178,7 +178,10 @@ static void remove_empty_src_dirs(const char **src_dir, size_t src_dir_nr)
 	strbuf_release(&a_src_dir);
 }
 
-int cmd_mv(int argc, const char **argv, const char *prefix)
+int cmd_mv(int argc,
+	   const char **argv,
+	   const char *prefix,
+	   struct repository *repo UNUSED)
 {
 	int i, flags, gitmodules_modified = 0;
 	int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0;
builtin/name-rev.c +4 -1
index a468ef84c37..19d92fb382d 100644
@@ -558,7 +558,10 @@ static void name_rev_line(char *p, struct name_ref_data *data)
 	strbuf_release(&buf);
 }
 
-int cmd_name_rev(int argc, const char **argv, const char *prefix)
+int cmd_name_rev(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct mem_pool string_pool;
 	struct object_array revs = OBJECT_ARRAY_INIT;
builtin/notes.c +4 -1
index 04f9dfb7fbd..49d8364af60 100644
@@ -1096,7 +1096,10 @@ static int get_ref(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
-int cmd_notes(int argc, const char **argv, const char *prefix)
+int cmd_notes(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	const char *override_notes_ref = NULL;
 	parse_opt_subcommand_fn *fn = NULL;
builtin/pack-objects.c +4 -1
index 778be80f564..127972f3cdf 100644
@@ -4284,7 +4284,10 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
 	return 0;
 }
 
-int cmd_pack_objects(int argc, const char **argv, const char *prefix)
+int cmd_pack_objects(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	int use_internal_rev_list = 0;
 	int shallow = 0;
builtin/pack-redundant.c +2 -5
index dd9bf35f5b8..84f0d83affb 100644
@@ -561,11 +561,8 @@ static void load_all(void)
 	}
 }
 
-int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED)
-{
-	int i;
-	int i_still_use_this = 0;
-	struct pack_list *min = NULL, *red, *pl;
+int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
+	int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;
 	struct llist *ignore;
 	struct object_id *oid;
 	char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */
builtin/pack-refs.c +4 -1
index db408256663..67dabb39756 100644
@@ -11,7 +11,10 @@ static char const * const pack_refs_usage[] = {
 	NULL
 };
 
-int cmd_pack_refs(int argc, const char **argv, const char *prefix)
+int cmd_pack_refs(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
 	struct string_list included_refs = STRING_LIST_INIT_NODUP;
builtin/patch-id.c +4 -1
index 35c1179f7e9..fa31a1b7a60 100644
@@ -260,7 +260,10 @@ static int git_patch_id_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_patch_id(int argc, const char **argv, const char *prefix)
+int cmd_patch_id(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	/* if nothing is set, default to unstable */
 	struct patch_id_opts config = {0, 0};
builtin/prune-packed.c +4 -1
index ca3578e1588..4d63f26b0a1 100644
@@ -8,7 +8,10 @@ static const char * const prune_packed_usage[] = {
 	NULL
 };
 
-int cmd_prune_packed(int argc, const char **argv, const char *prefix)
+int cmd_prune_packed(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
 	const struct option prune_packed_options[] = {
builtin/prune.c +4 -1
index 57fe31467fe..cbd4c38fa0a 100644
@@ -147,7 +147,10 @@ static void remove_temporary_files(const char *path)
 	closedir(dir);
 }
 
-int cmd_prune(int argc, const char **argv, const char *prefix)
+int cmd_prune(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	int exclude_promisor_objects = 0;
builtin/pull.c +4 -1
index 4c54d8196fa..1a926f0b0d7 100644
@@ -977,7 +977,10 @@ static void show_advice_pull_non_ff(void)
 		 "invocation.\n"));
 }
 
-int cmd_pull(int argc, const char **argv, const char *prefix)
+int cmd_pull(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repository UNUSED)
 {
 	const char *repo, **refspecs;
 	struct oid_array merge_heads = OID_ARRAY_INIT;
builtin/push.c +4 -1
index 7a67398124f..9636ad52f4d 100644
@@ -546,7 +546,10 @@ static int git_push_config(const char *k, const char *v,
 	return git_default_config(k, v, ctx, NULL);
 }
 
-int cmd_push(int argc, const char **argv, const char *prefix)
+int cmd_push(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repository UNUSED)
 {
 	int flags = 0;
 	int tags = 0;
builtin/range-diff.c +4 -1
index f02cbac087d..3e67259aecc 100644
@@ -13,7 +13,10 @@ N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
 NULL
 };
 
-int cmd_range_diff(int argc, const char **argv, const char *prefix)
+int cmd_range_diff(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct diff_options diffopt = { NULL };
 	struct strvec other_arg = STRVEC_INIT;
builtin/read-tree.c +4 -1
index a8cf8504b8a..89410db6a7a 100644
@@ -108,7 +108,10 @@ static int git_read_tree_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
+int cmd_read_tree(int argc,
+		  const char **argv,
+		  const char *cmd_prefix,
+		  struct repository *repo UNUSED)
 {
 	int i, stage = 0;
 	struct object_id oid;
builtin/rebase.c +4 -1
index a2c96c080e1..727d9df847f 100644
@@ -1063,7 +1063,10 @@ static int check_exec_cmd(const char *cmd)
 	return 0;
 }
 
-int cmd_rebase(int argc, const char **argv, const char *prefix)
+int cmd_rebase(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct rebase_options options = REBASE_OPTIONS_INIT;
 	const char *branch_name;
builtin/receive-pack.c +4 -1
index 3f35140e489..36a6229c2a4 100644
@@ -2480,7 +2480,10 @@ static int delete_only(struct command *commands)
 	return 1;
 }
 
-int cmd_receive_pack(int argc, const char **argv, const char *prefix)
+int cmd_receive_pack(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	int advertise_refs = 0;
 	struct command *commands;
builtin/reflog.c +6 -3
index 0d2ff95c6e7..6250f5ad49f 100644
@@ -244,7 +244,7 @@ static int cmd_reflog_show(int argc, const char **argv, const char *prefix)
 		      PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
 		      PARSE_OPT_KEEP_UNKNOWN_OPT);
 
-	return cmd_log_reflog(argc, argv, prefix);
+	return cmd_log_reflog(argc, argv, prefix, the_repository);
 }
 
 static int show_reflog(const char *refname, void *cb_data UNUSED)
@@ -447,7 +447,10 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
  * main "reflog"
  */
 
-int cmd_reflog(int argc, const char **argv, const char *prefix)
+int cmd_reflog(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repository)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
@@ -466,5 +469,5 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
 	if (fn)
 		return fn(argc - 1, argv + 1, prefix);
 	else
-		return cmd_log_reflog(argc, argv, prefix);
+		return cmd_log_reflog(argc, argv, prefix, repository);
 }
builtin/refs.c +4 -1
index 131f98be986..70bca724d2a 100644
@@ -90,7 +90,10 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)
 	return ret;
 }
 
-int cmd_refs(int argc, const char **argv, const char *prefix)
+int cmd_refs(int argc,
+	     const char **argv,
+	     const char *prefix,
+	     struct repository *repo UNUSED)
 {
 	const char * const refs_usage[] = {
 		REFS_MIGRATE_USAGE,
builtin/remote-ext.c +4 -1
index 282782eccdd..33c8ae0fc7d 100644
@@ -195,7 +195,10 @@ static int command_loop(const char *child)
 	}
 }
 
-int cmd_remote_ext(int argc, const char **argv, const char *prefix)
+int cmd_remote_ext(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	BUG_ON_NON_EMPTY_PREFIX(prefix);
 
builtin/remote-fd.c +4 -1
index 9020fab9c58..ae896eda57b 100644
@@ -53,7 +53,10 @@ static void command_loop(int input_fd, int output_fd)
 	}
 }
 
-int cmd_remote_fd(int argc, const char **argv, const char *prefix)
+int cmd_remote_fd(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	int input_fd = -1;
 	int output_fd = -1;
builtin/remote.c +4 -1
index d1f9292ed2b..1ac7e5fbce3 100644
@@ -1754,7 +1754,10 @@ out:
 	return 0;
 }
 
-int cmd_remote(int argc, const char **argv, const char *prefix)
+int cmd_remote(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
builtin/repack.c +4 -1
index 62cfa50c50f..a6f2a4de1b8 100644
@@ -1116,7 +1116,10 @@ static const char *find_pack_prefix(const char *packdir, const char *packtmp)
 	return pack_prefix;
 }
 
-int cmd_repack(int argc, const char **argv, const char *prefix)
+int cmd_repack(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
 	struct string_list_item *item;
builtin/replace.c +4 -1
index 34cc4672bc1..293ae6d327f 100644
@@ -545,7 +545,10 @@ static int convert_graft_file(int force)
 	return -1;
 }
 
-int cmd_replace(int argc, const char **argv, const char *prefix)
+int cmd_replace(int argc,
+		const char **argv,
+		const char *prefix,
+		struct repository *repo UNUSED)
 {
 	int force = 0;
 	int raw = 0;
builtin/replay.c +4 -1
index 138198ce9ca..c8e9098fc12 100644
@@ -274,7 +274,10 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	return create_commit(result->tree, pickme, replayed_base);
 }
 
-int cmd_replay(int argc, const char **argv, const char *prefix)
+int cmd_replay(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	const char *advance_name_opt = NULL;
 	char *advance_name = NULL;
builtin/rerere.c +4 -1
index 81b65ffa39c..ae345155834 100644
@@ -48,7 +48,10 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
-int cmd_rerere(int argc, const char **argv, const char *prefix)
+int cmd_rerere(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int i, autoupdate = -1, flags = 0;
builtin/reset.c +4 -1
index 5f941fb3a29..75529072606 100644
@@ -330,7 +330,10 @@ static int git_reset_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_reset(int argc, const char **argv, const char *prefix)
+int cmd_reset(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	int reset_type = NONE, update_ref_status = 0, quiet = 0;
 	int no_refresh = 0;
builtin/rev-list.c +4 -1
index 97d077a9943..a4186d47ce3 100644
@@ -513,7 +513,10 @@ static int try_bitmap_disk_usage(struct rev_info *revs,
 	return 0;
 }
 
-int cmd_rev_list(int argc, const char **argv, const char *prefix)
+int cmd_rev_list(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct rev_info revs;
 	struct rev_list_info info;
builtin/rev-parse.c +4 -1
index 4285dc34a7b..26190aaa3ed 100644
@@ -688,7 +688,10 @@ static void print_path(const char *path, const char *prefix, enum format_type fo
 	free(cwd);
 }
 
-int cmd_rev_parse(int argc, const char **argv, const char *prefix)
+int cmd_rev_parse(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
 	const struct git_hash_algo *output_algo = NULL;
builtin/revert.c +8 -2
index 7bf2b4e11d6..5f2ec3ade73 100644
@@ -261,7 +261,10 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
 	return sequencer_pick_revisions(the_repository, opts);
 }
 
-int cmd_revert(int argc, const char **argv, const char *prefix)
+int cmd_revert(int argc,
+	       const char **argv,
+	       const char *prefix,
+	       struct repository *repo UNUSED)
 {
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int res;
@@ -275,7 +278,10 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
 	return res;
 }
 
-int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
+int cmd_cherry_pick(int argc,
+const char **argv,
+const char *prefix,
+struct repository *repo UNUSED)
 {
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int res;
builtin/rm.c +4 -1
index 0e79cbab62b..59077efa4b4 100644
@@ -261,7 +261,10 @@ static struct option builtin_rm_options[] = {
 	OPT_END(),
 };
 
-int cmd_rm(int argc, const char **argv, const char *prefix)
+int cmd_rm(int argc,
+	   const char **argv,
+	   const char *prefix,
+	   struct repository *repo UNUSED)
 {
 	struct lock_file lock_file = LOCK_INIT;
 	int i, ret = 0;
builtin/send-pack.c +4 -1
index 17cae6bbbdf..a4925ed5fd1 100644
@@ -147,7 +147,10 @@ static int send_pack_config(const char *k, const char *v,
 	return git_default_config(k, v, ctx, cb);
 }
 
-int cmd_send_pack(int argc, const char **argv, const char *prefix)
+int cmd_send_pack(int argc,
+		  const char **argv,
+		  const char *prefix,
+		  struct repository *repo UNUSED)
 {
 	struct refspec rs = REFSPEC_INIT_PUSH;
 	const char *remote_name = NULL;
builtin/shortlog.c +4 -1
index b529608c923..70eb7890334 100644
@@ -378,7 +378,10 @@ void shortlog_finish_setup(struct shortlog *log)
 	string_list_sort(&log->trailers);
 }
 
-int cmd_shortlog(int argc, const char **argv, const char *prefix)
+int cmd_shortlog(int argc,
+		 const char **argv,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	struct shortlog log = { STRING_LIST_INIT_NODUP };
 	struct rev_info rev;
builtin/show-branch.c +4 -1
index 29237f653d8..05c10628df9 100644
@@ -632,7 +632,10 @@ static int parse_reflog_param(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_show_branch(int ac, const char **av, const char *prefix)
+int cmd_show_branch(int ac,
+		const char **av,
+		const char *prefix,
+		struct repository *repo UNUSED)
 {
 	struct commit *rev[MAX_REVS], *commit;
 	char *reflog_msg[MAX_REVS] = {0};
builtin/show-index.c +4 -1
index 540dc3dad1c..9e1f7ac9ca5 100644
@@ -11,7 +11,10 @@ static const char *const show_index_usage[] = {
 	NULL
 };
 
-int cmd_show_index(int argc, const char **argv, const char *prefix)
+int cmd_show_index(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	int i;
 	unsigned nr;
builtin/show-ref.c +4 -1
index f5899ce9ff7..6ee05f09a69 100644
@@ -287,7 +287,10 @@ static int exclude_existing_callback(const struct option *opt, const char *arg,
 	return 0;
 }
 
-int cmd_show_ref(int argc, const char **argv, const char *prefix)
+int cmd_show_ref(int argc,
+const char **argv,
+const char *prefix,
+struct repository *repo UNUSED)
 {
 	struct exclude_existing_options exclude_existing_opts = {0};
 	struct patterns_options patterns_opts = {0};
builtin/sparse-checkout.c +4 -1
index 2604ab04df5..23f1548fe54 100644
@@ -1030,7 +1030,10 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
 	return ret;
 }
 
-int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
+int cmd_sparse_checkout(int argc,
+			const char **argv,
+			const char *prefix,
+			struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option builtin_sparse_checkout_options[] = {
builtin/stash.c +4 -1
index fcfd97972a4..518d297b47b 100644
@@ -1871,7 +1871,10 @@ static int save_stash(int argc, const char **argv, const char *prefix)
 	return ret;
 }
 
-int cmd_stash(int argc, const char **argv, const char *prefix)
+int cmd_stash(int argc,
+	      const char **argv,
+	      const char *prefix,
+	      struct repository *repo UNUSED)
 {
 	pid_t pid = getpid();
 	const char *index_file;
builtin/stripspace.c +4 -1
index e5626e51266..674ef939769 100644
@@ -29,7 +29,10 @@ enum stripspace_mode {
 	COMMENT_LINES
 };
 
-int cmd_stripspace(int argc, const char **argv, const char *prefix)
+int cmd_stripspace(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	enum stripspace_mode mode = STRIP_DEFAULT;
builtin/submodule--helper.c +4 -1
index 85fb23dee84..947bd9d0f6a 100644
@@ -3528,7 +3528,10 @@ cleanup:
 	return ret;
 }
 
-int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
+int cmd_submodule__helper(int argc,
+			  const char **argv,
+			  const char *prefix,
+			  struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	const char *const usage[] = {
builtin/symbolic-ref.c +4 -1
index 81abdd170fe..9bc70229468 100644
@@ -41,7 +41,10 @@ static int check_symref(const char *HEAD, int quiet, int shorten, int recurse, i
 	return 0;
 }
 
-int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
+int cmd_symbolic_ref(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	int quiet = 0, delete = 0, shorten = 0, recurse = 1, ret = 0;
 	const char *msg = NULL;
builtin/tag.c +4 -1
index a1fb218512c..a80838eb8e0 100644
@@ -457,7 +457,10 @@ static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
 	return check_refname_format(sb->buf, 0);
 }
 
-int cmd_tag(int argc, const char **argv, const char *prefix)
+int cmd_tag(int argc,
+	    const char **argv,
+	    const char *prefix,
+	    struct repository *repo UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	struct strbuf ref = STRBUF_INIT;
builtin/unpack-file.c +4 -1
index c129e2bb6cb..97886840f8d 100644
@@ -25,7 +25,10 @@ static char *create_temp_file(struct object_id *oid)
 	return path;
 }
 
-int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_unpack_file(int argc,
+		    const char **argv,
+		    const char *prefix UNUSED,
+		    struct repository *repo UNUSED)
 {
 	struct object_id oid;
 
builtin/unpack-objects.c +4 -1
index 08fa2a7a743..3bcdaaeb5fa 100644
@@ -601,7 +601,10 @@ static void unpack_all(void)
 		die("unresolved deltas left after unpacking");
 }
 
-int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_unpack_objects(int argc,
+		       const char **argv,
+		       const char *prefix UNUSED,
+		       struct repository *repo UNUSED)
 {
 	int i;
 	struct object_id oid;
builtin/update-index.c +4 -1
index 35a1f957adc..1d1d87d08e3 100644
@@ -917,7 +917,10 @@ static enum parse_opt_result reupdate_callback(
 	return 0;
 }
 
-int cmd_update_index(int argc, const char **argv, const char *prefix)
+int cmd_update_index(int argc,
+		     const char **argv,
+		     const char *prefix,
+		     struct repository *repo UNUSED)
 {
 	int newfd, entries, has_errors = 0, nul_term_line = 0;
 	enum uc_mode untracked_cache = UC_UNSPECIFIED;
builtin/update-ref.c +4 -1
index 8f31da9a4b7..06826a90515 100644
@@ -713,7 +713,10 @@ static void update_refs_stdin(void)
 	strbuf_release(&input);
 }
 
-int cmd_update_ref(int argc, const char **argv, const char *prefix)
+int cmd_update_ref(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	const char *refname, *oldval;
 	struct object_id oid, oldoid;
builtin/update-server-info.c +4 -1
index 1dc3971edeb..a5b7d86727c 100644
@@ -9,7 +9,10 @@ static const char * const update_server_info_usage[] = {
 	NULL
 };
 
-int cmd_update_server_info(int argc, const char **argv, const char *prefix)
+int cmd_update_server_info(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo UNUSED)
 {
 	int force = 0;
 	struct option options[] = {
builtin/upload-archive.c +8 -2
index 1b09e5e1aa3..49d1bb7fb44 100644
@@ -18,7 +18,10 @@ static const char deadchild[] =
 
 #define MAX_ARGS (64)
 
-int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
+int cmd_upload_archive_writer(int argc,
+			      const char **argv,
+			      const char *prefix,
+			      struct repository *repo UNUSED)
 {
 	struct strvec sent_argv = STRVEC_INIT;
 	const char *arg_cmd = "argument ";
@@ -76,7 +79,10 @@ static ssize_t process_input(int child_fd, int band)
 	return sz;
 }
 
-int cmd_upload_archive(int argc, const char **argv, const char *prefix)
+int cmd_upload_archive(int argc,
+const char **argv,
+const char *prefix,
+struct repository *repo UNUSED)
 {
 	struct child_process writer = CHILD_PROCESS_INIT;
 
builtin/upload-pack.c +4 -1
index 46d93278d9a..3b6c83fbce3 100644
@@ -17,7 +17,10 @@ static const char * const upload_pack_usage[] = {
 	NULL
 };
 
-int cmd_upload_pack(int argc, const char **argv, const char *prefix)
+int cmd_upload_pack(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	const char *dir;
 	int strict = 0;
builtin/var.c +4 -1
index e30ff45be1c..4a5c2649d6f 100644
@@ -210,7 +210,10 @@ static int show_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
+int cmd_var(int argc,
+	    const char **argv,
+	    const char *prefix UNUSED,
+	    struct repository *repo UNUSED)
 {
 	const struct git_var *git_var;
 	char *val;
builtin/verify-commit.c +4 -1
index 0d2b9aea2ae..c5859e5b2b4 100644
@@ -51,7 +51,10 @@ static int verify_commit(const char *name, unsigned flags)
 	return run_gpg_verify((struct commit *)obj, flags);
 }
 
-int cmd_verify_commit(int argc, const char **argv, const char *prefix)
+int cmd_verify_commit(int argc,
+		      const char **argv,
+		      const char *prefix,
+		      struct repository *repo UNUSED)
 {
 	int i = 1, verbose = 0, had_error = 0;
 	unsigned flags = 0;
builtin/verify-pack.c +4 -1
index 011dddd2dc3..7ad456649d2 100644
@@ -61,7 +61,10 @@ static const char * const verify_pack_usage[] = {
 	NULL
 };
 
-int cmd_verify_pack(int argc, const char **argv, const char *prefix)
+int cmd_verify_pack(int argc,
+		    const char **argv,
+		    const char *prefix,
+		    struct repository *repo UNUSED)
 {
 	int err = 0;
 	unsigned int flags = 0;
builtin/verify-tag.c +4 -1
index c731e2f87b4..a7bef524191 100644
@@ -19,7 +19,10 @@ static const char * const verify_tag_usage[] = {
 		NULL
 };
 
-int cmd_verify_tag(int argc, const char **argv, const char *prefix)
+int cmd_verify_tag(int argc,
+		   const char **argv,
+		   const char *prefix,
+		   struct repository *repo UNUSED)
 {
 	int i = 1, verbose = 0, had_error = 0;
 	unsigned flags = 0;
builtin/worktree.c +4 -1
index 41e7f6a3271..3b47f9832fa 100644
@@ -1392,7 +1392,10 @@ static int repair(int ac, const char **av, const char *prefix)
 	return rc;
 }
 
-int cmd_worktree(int ac, const char **av, const char *prefix)
+int cmd_worktree(int ac,
+		 const char **av,
+		 const char *prefix,
+		 struct repository *repo UNUSED)
 {
 	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
builtin/write-tree.c +4 -1
index 8c75b4609b5..1b467d6ed23 100644
@@ -19,7 +19,10 @@ static const char * const write_tree_usage[] = {
 	NULL
 };
 
-int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
+int cmd_write_tree(int argc,
+		   const char **argv,
+		   const char *cmd_prefix,
+		   struct repository *repo UNUSED)
 {
 	int flags = 0, ret;
 	const char *tree_prefix = NULL;
git.c +6 -6
index 9a618a2740f..2fbea24ec92 100644
@@ -31,7 +31,7 @@
 
 struct cmd_struct {
 	const char *cmd;
-	int (*fn)(int, const char **, const char *);
+	int (*fn)(int, const char **, const char *, struct repository *);
 	unsigned int option;
 };
 
@@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
 	return ret;
 }
 
-static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
+static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
 {
 	int status, help;
 	struct stat st;
@@ -479,9 +479,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	trace_argv_printf(argv, "trace: built-in: git");
 	trace2_cmd_name(p->cmd);
 
-	validate_cache_entries(the_repository->index);
-	status = p->fn(argc, argv, prefix);
-	validate_cache_entries(the_repository->index);
+	validate_cache_entries(repo->index);
+	status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
+	validate_cache_entries(repo->index);
 
 	if (status)
 		return status;
@@ -736,7 +736,7 @@ static void handle_builtin(int argc, const char **argv)
 
 	builtin = get_builtin(cmd);
 	if (builtin)
-		exit(run_builtin(builtin, argc, argv));
+		exit(run_builtin(builtin, argc, argv, the_repository));
 	strvec_clear(&args);
 }
 
help.c +2 -1
index c03863f2265..e7cdfab6432 100644
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "prompt.h"
 #include "fsmonitor-ipc.h"
+#include "repository.h"
 
 #ifndef NO_CURL
 #include "git-curl-compat.h" /* For LIBCURL_VERSION only */
@@ -775,7 +776,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
 	}
 }
 
-int cmd_version(int argc, const char **argv, const char *prefix)
+int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
 {
 	struct strbuf buf = STRBUF_INIT;
 	int build_options = 0;
stkOs5Qh new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6ddaad1925d3a5d4c17b021e8eb54bf93966742d
GIT binary patch
Signature · 1 line
gitgitgadget
#20 lore raw

PATCH v2 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it to all the builtins that reference the_repository.

Also, remove the include statement for repository.h since it gets brought in through builtin.h.

The next step will be to migrate each builtin
from having to use the_repository.

---
 builtin.h                          | 8 --------
 builtin/add.c                      | 3 +--
 builtin/am.c                       | 2 +-
 builtin/annotate.c                 | 2 ++
 builtin/apply.c                    | 2 +-
 builtin/archive.c                  | 2 +-
 builtin/bisect.c                   | 1 +
 builtin/blame.c                    | 3 +--
 builtin/branch.c                   | 2 +-
 builtin/bugreport.c                | 1 +
 builtin/bundle.c                   | 2 +-
 builtin/cat-file.c                 | 2 +-
 builtin/check-attr.c               | 2 +-
 builtin/check-ignore.c             | 2 +-
 builtin/check-mailmap.c            | 1 +
 builtin/checkout--worker.c         | 1 +
 builtin/checkout-index.c           | 3 +--
 builtin/checkout.c                 | 1 +
 builtin/clean.c                    | 3 +--
 builtin/clone.c                    | 3 ++-
 builtin/column.c                   | 1 +
 builtin/commit-graph.c             | 2 +-
 builtin/commit-tree.c              | 3 ++-
 builtin/commit.c                   | 2 +-
 builtin/config.c                   | 2 +-
 builtin/count-objects.c            | 3 +--
 builtin/credential-cache--daemon.c | 1 +
 builtin/credential-store.c         | 1 +
 builtin/credential.c               | 2 ++
 builtin/describe.c                 | 1 +
 builtin/diff-files.c               | 2 +-
 builtin/diff-index.c               | 2 +-
 builtin/diff-tree.c                | 2 +-
 builtin/diff.c                     | 2 +-
 builtin/difftool.c                 | 3 ++-
 builtin/fast-export.c              | 1 +
 builtin/fast-import.c              | 2 +-
 builtin/fetch-pack.c               | 1 +
 builtin/fetch.c                    | 2 +-
 builtin/fmt-merge-msg.c            | 1 +
 builtin/for-each-ref.c             | 1 +
 builtin/for-each-repo.c            | 2 +-
 builtin/fsck.c                     | 2 +-
 builtin/fsmonitor--daemon.c        | 3 ++-
 builtin/gc.c                       | 3 +--
 builtin/grep.c                     | 2 +-
 builtin/hash-object.c              | 1 +
 builtin/help.c                     | 2 ++
 builtin/hook.c                     | 1 +
 builtin/index-pack.c               | 1 +
 builtin/init-db.c                  | 2 +-
 builtin/interpret-trailers.c       | 2 +-
 builtin/log.c                      | 3 ++-
 builtin/ls-files.c                 | 2 +-
 builtin/ls-remote.c                | 1 +
 builtin/ls-tree.c                  | 2 ++
 builtin/mailinfo.c                 | 1 +
 builtin/merge-base.c               | 2 +-
 builtin/merge-file.c               | 1 +
 builtin/merge-index.c              | 2 +-
 builtin/merge-ours.c               | 3 ++-
 builtin/merge-recursive.c          | 2 +-
 builtin/merge-tree.c               | 2 +-
 builtin/merge.c                    | 3 ++-
 builtin/mktag.c                    | 1 +
 builtin/mktree.c                   | 1 +
 builtin/multi-pack-index.c         | 1 +
 builtin/mv.c                       | 3 ++-
 builtin/name-rev.c                 | 2 +-
 builtin/notes.c                    | 4 ++--
 builtin/pack-objects.c             | 2 +-
 builtin/pack-redundant.c           | 3 ++-
 builtin/pack-refs.c                | 2 +-
 builtin/patch-id.c                 | 1 +
 builtin/prune.c                    | 1 +
 builtin/pull.c                     | 1 +
 builtin/push.c                     | 2 +-
 builtin/range-diff.c               | 3 ++-
 builtin/read-tree.c                | 3 +--
 builtin/rebase.c                   | 3 ++-
 builtin/receive-pack.c             | 3 ++-
 builtin/reflog.c                   | 2 +-
 builtin/refs.c                     | 2 +-
 builtin/remote.c                   | 1 +
 builtin/repack.c                   | 1 +
 builtin/replace.c                  | 3 +--
 builtin/replay.c                   | 1 +
 builtin/rerere.c                   | 3 ++-
 builtin/reset.c                    | 2 +-
 builtin/rev-list.c                 | 1 +
 builtin/rev-parse.c                | 3 ++-
 builtin/revert.c                   | 2 +-
 builtin/rm.c                       | 4 ++--
 builtin/send-pack.c                | 1 +
 builtin/shortlog.c                 | 2 +-
 builtin/show-branch.c              | 3 ++-
 builtin/show-index.c               | 2 +-
 builtin/show-ref.c                 | 1 +
 builtin/sparse-checkout.c          | 2 +-
 builtin/stash.c                    | 1 +
 builtin/stripspace.c               | 1 +
 builtin/submodule--helper.c        | 3 ++-
 builtin/symbolic-ref.c             | 1 +
 builtin/tag.c                      | 2 +-
 builtin/unpack-file.c              | 1 +
 builtin/unpack-objects.c           | 1 +
 builtin/update-index.c             | 3 +--
 builtin/update-ref.c               | 2 +-
 builtin/update-server-info.c       | 1 +
 builtin/upload-archive.c           | 2 +-
 builtin/var.c                      | 2 ++
 builtin/verify-commit.c            | 2 +-
 builtin/verify-pack.c              | 1 +
 builtin/verify-tag.c               | 1 +
 builtin/worktree.c                 | 2 +-
 builtin/write-tree.c               | 3 +--
 116 files changed, 138 insertions(+), 91 deletions(-)
builtin.h +0 -8
index fc6fc8ffed8..f7b166b3348 100644
@@ -1,14 +1,6 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
-/*
- * TODO: Almost all of our builtins access `the_repository` by necessity
- * because they do not get passed a pointer to it. We should adapt the function
- * signature of those main functions to accept a `struct repository *` and then
- * remove the macro here.
- */
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "repository.h"
 
builtin/add.c +1 -2
index ba331519cac..c893ff48d26 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Linus Torvalds
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
@@ -18,7 +18,6 @@
 #include "preload-index.h"
 #include "diff.h"
 #include "read-cache.h"
-#include "repository.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
builtin/am.c +1 -1
index 8c610eed3e6..7693891fcde 100644
@@ -4,6 +4,7 @@
  * Based on git-am.sh by Junio C Hamano.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
@@ -38,7 +39,6 @@
 #include "string-list.h"
 #include "pager.h"
 #include "path.h"
-#include "repository.h"
 #include "pretty.h"
 
 /**
builtin/annotate.c +2 -0
index 0abf89ef186..a99179fe4dd 100644
@@ -3,6 +3,8 @@
  *
  * Copyright (C) 2006 Ryan Anderson
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "strvec.h"
builtin/apply.c +1 -1
index ca0bb97df40..84f1863d3ac 100644
@@ -1,6 +1,6 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
-#include "repository.h"
 #include "hash.h"
 #include "apply.h"
 
builtin/archive.c +1 -1
index de59c3ae97a..22f7c63529f 100644
@@ -2,13 +2,13 @@
  * Copyright (c) 2006 Franck Bui-Huu
  * Copyright (c) 2006 Rene Scharfe
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "archive.h"
 #include "gettext.h"
 #include "transport.h"
 #include "parse-options.h"
 #include "pkt-line.h"
-#include "repository.h"
 
 static void create_output_file(const char *output_file)
 {
builtin/bisect.c +1 -0
index b83056df9f4..5e91c59c763 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "copy.h"
 #include "environment.h"
builtin/blame.c +1 -2
index 728a62402b5..472dd762f41 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2006, 2014 by its authors
  * See COPYING for licensing conditions
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "color.h"
@@ -12,7 +12,6 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
builtin/branch.c +1 -1
index 7980d2e83d6..7112459ebd1 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2006 Kristian Høgsberg <[email protected]>
  * Based on git-branch.sh by Junio C Hamano.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "color.h"
builtin/bugreport.c +1 -0
index aeab40c4902..7c2df035c9c 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "editor.h"
builtin/bundle.c +1 -1
index 97f7f530d0e..cabb20b44b8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
@@ -5,7 +6,6 @@
 #include "strvec.h"
 #include "parse-options.h"
 #include "pkt-line.h"
-#include "repository.h"
 #include "bundle.h"
 
 /*
builtin/cat-file.c +1 -1
index b244b5a1ab6..b9b754b354f 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "convert.h"
builtin/check-attr.c +1 -1
index ffd1067558d..7cf275b8937 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "attr.h"
@@ -5,7 +6,6 @@
 #include "gettext.h"
 #include "object-name.h"
 #include "quote.h"
-#include "repository.h"
 #include "setup.h"
 #include "parse-options.h"
 #include "write-or-die.h"
builtin/check-ignore.c +1 -1
index 70565b9f892..7b7831d13a8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
@@ -5,7 +6,6 @@
 #include "quote.h"
 #include "pathspec.h"
 #include "parse-options.h"
-#include "repository.h"
 #include "submodule.h"
 #include "write-or-die.h"
 
builtin/check-mailmap.c +1 -0
index 87cc036dd14..c0610469d40 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/checkout--worker.c +1 -0
index f53e1082690..ff6cdccc21d 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "entry.h"
builtin/checkout-index.c +1 -2
index 98247ff8236..6dd38eb05d4 100644
@@ -4,13 +4,12 @@
  * Copyright (C) 2005 Linus Torvalds
  *
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "lockfile.h"
 #include "quote.h"
-#include "repository.h"
 #include "cache-tree.h"
 #include "parse-options.h"
 #include "entry.h"
builtin/checkout.c +1 -0
index d3bc48684f9..d6defc36b2b 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "branch.h"
builtin/clean.c +1 -2
index b5887f877e0..9c48dd02711 100644
@@ -5,7 +5,7 @@
  *
  * Based on git-clean.sh by Pavel Roskin
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
@@ -14,7 +14,6 @@
 #include "parse-options.h"
 #include "path.h"
 #include "read-cache-ll.h"
-#include "repository.h"
 #include "setup.h"
 #include "string-list.h"
 #include "quote.h"
builtin/clone.c +2 -1
index 1b82310ac5b..e77339c8472 100644
@@ -7,8 +7,9 @@
  *
  * Clone a repository into a different directory that does not yet exist.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
builtin/column.c +1 -0
index 93f84beeee7..50314cc2559 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/commit-graph.c +1 -1
index 65ce98d4675..81e577c14ae 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "commit.h"
 #include "config.h"
@@ -5,7 +6,6 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
-#include "repository.h"
 #include "commit-graph.h"
 #include "object-store-ll.h"
 #include "progress.h"
builtin/commit-tree.c +2 -1
index bd8bf3296ed..2ca1a57ebbb 100644
@@ -3,13 +3,14 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
 #include "object-store-ll.h"
-#include "repository.h"
+
 #include "commit.h"
 #include "parse-options.h"
 
builtin/commit.c +1 -1
index 768d76ac461..fd1cc42c5a6 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2007 Kristian Høgsberg <[email protected]>
  * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/config.c +1 -1
index 841a5d706f4..faa0ee7d65e 100644
@@ -1,10 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "color.h"
 #include "editor.h"
 #include "environment.h"
-#include "repository.h"
 #include "gettext.h"
 #include "ident.h"
 #include "parse-options.h"
builtin/count-objects.c +1 -2
index 6b905da3c3d..3d7b289f597 100644
@@ -3,14 +3,13 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "path.h"
-#include "repository.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
builtin/credential-cache--daemon.c +1 -0
index 4caaf38b841..bc22f5c6d24 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
builtin/credential-store.c +1 -0
index 128704078e9..e669e99dbfb 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/credential.c +2 -0
index 796422c6fe7..14c8c6608b2 100644
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "credential.h"
 #include "builtin.h"
builtin/describe.c +1 -0
index 1c1c250fe0c..7929223c8b2 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
builtin/diff-files.c +1 -1
index 7f4f9bcb3eb..b8ec420f867 100644
@@ -3,13 +3,13 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
-#include "repository.h"
 #include "revision.h"
 
 static const char diff_files_usage[] =
builtin/diff-index.c +1 -1
index 8abec38592f..e87f717d86e 100644
@@ -1,10 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
-#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 
builtin/diff-tree.c +1 -1
index 841448b023f..715995c46fa 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
@@ -6,7 +7,6 @@
 #include "hex.h"
 #include "log-tree.h"
 #include "read-cache-ll.h"
-#include "repository.h"
 #include "revision.h"
 #include "tmp-objdir.h"
 #include "tree.h"
builtin/diff.c +1 -1
index 499b7872dd4..63e790b2291 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "ewah/ewok.h"
builtin/difftool.c +2 -1
index c8700d67f4d..f7dfa1fd0da 100644
@@ -11,8 +11,9 @@
  *
  * Copyright (C) 2016 Johannes Schindelin
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "abspath.h"
 #include "config.h"
 #include "copy.h"
builtin/fast-export.c +1 -0
index 1bd5949dd24..e17f262e8e4 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2007 Johannes E. Schindelin
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/fast-import.c +1 -1
index 4b9e341aa44..1e7ab67f6e5 100644
@@ -1,9 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
 #include "config.h"
 #include "lockfile.h"
 #include "object.h"
builtin/fetch-pack.c +1 -0
index fddd8a2c1cd..d2c4304d222 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/fetch.c +1 -1
index 46ecfc5bc62..9e68114b866 100644
@@ -1,13 +1,13 @@
 /*
  * "git fetch"
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "gettext.h"
 #include "environment.h"
 #include "hex.h"
-#include "repository.h"
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
builtin/fmt-merge-msg.c +1 -0
index 1fba4cf5590..324e904ac93 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "fmt-merge-msg.h"
builtin/for-each-ref.c +1 -0
index b1187587135..8085ebd8fe9 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "commit.h"
 #include "config.h"
builtin/for-each-repo.c +1 -1
index 93d82b952e9..fae7f91cf15 100644
@@ -1,9 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
-#include "repository.h"
 #include "run-command.h"
 #include "string-list.h"
 
builtin/fsck.c +1 -1
index 87068cee09d..7f4e2f04143 100644
@@ -1,7 +1,7 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
 #include "config.h"
 #include "commit.h"
 #include "tree.h"
builtin/fsmonitor--daemon.c +2 -1
index 73a4b885661..ba8a6eebe5d 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
@@ -11,7 +12,7 @@
 #include "compat/fsmonitor/fsm-health.h"
 #include "compat/fsmonitor/fsm-listen.h"
 #include "fsmonitor--daemon.h"
-#include "repository.h"
+
 #include "simple-ipc.h"
 #include "khash.h"
 #include "run-command.h"
builtin/gc.c +1 -2
index 0727de1ae8e..6bc8f7e7f81 100644
@@ -9,13 +9,12 @@
  *
  * Copyright (c) 2006 Shawn O. Pearce
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "date.h"
 #include "environment.h"
 #include "hex.h"
-#include "repository.h"
 #include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
builtin/grep.c +1 -1
index da11879c637..bc3439cabd5 100644
@@ -3,11 +3,11 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
 #include "config.h"
 #include "tag.h"
 #include "tree-walk.h"
builtin/hash-object.c +1 -0
index 090daea5cd8..a25f0403f44 100644
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  * Copyright (C) Junio C Hamano, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/help.c +2 -0
index f7723bdf5c8..9c4cfe11d9e 100644
@@ -1,6 +1,8 @@
+
 /*
  * Builtin help command
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "exec-cmd.h"
builtin/hook.c +1 -0
index f02e2421ac0..367ef3e0b89 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/index-pack.c +1 -0
index 3207130bfee..32641134e93 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "delta.h"
builtin/init-db.c +1 -1
index 94bd6075095..687cada4d7e 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
@@ -11,7 +12,6 @@
 #include "parse-options.h"
 #include "path.h"
 #include "refs.h"
-#include "repository.h"
 #include "setup.h"
 #include "strbuf.h"
 
builtin/interpret-trailers.c +1 -1
index fb93e54e5ea..44f83625c11 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013, 2014 Christian Couder <[email protected]>
  *
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
builtin/log.c +2 -1
index 67140575f4b..e4533a99fda 100644
@@ -4,6 +4,7 @@
  * (C) Copyright 2006 Linus Torvalds
  *		 2006 Junio Hamano
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
@@ -37,7 +38,7 @@
 #include "mailmap.h"
 #include "progress.h"
 #include "commit-slab.h"
-#include "repository.h"
+
 #include "commit-reach.h"
 #include "range-diff.h"
 #include "tmp-objdir.h"
builtin/ls-files.c +1 -1
index 7f45cb62cf6..6aaba08e305 100644
@@ -5,8 +5,8 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
-#include "repository.h"
 #include "config.h"
 #include "convert.h"
 #include "quote.h"
builtin/ls-remote.c +1 -0
index f2c2854d0c3..f723b3bf3bb 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/ls-tree.c +2 -0
index 363cb948d92..8542b5d53e4 100644
@@ -3,7 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
builtin/mailinfo.c +1 -0
index 00bfcd1afa0..e17dec27b1d 100644
@@ -2,6 +2,7 @@
  * Another stupid program, this one parsing the headers of an
  * email to figure out authorship and subject
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
builtin/merge-base.c +1 -1
index afeae8d8346..a20c93b11aa 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
@@ -5,7 +6,6 @@
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
-#include "repository.h"
 #include "commit-reach.h"
 
 static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
builtin/merge-file.c +1 -0
index f785813ddae..cb42865eb52 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "diff.h"
builtin/merge-index.c +1 -1
index 1309a8ff471..a5b87ee3c5e 100644
@@ -1,7 +1,7 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "hex.h"
 #include "read-cache-ll.h"
-#include "repository.h"
 #include "run-command.h"
 #include "sparse-index.h"
 
builtin/merge-ours.c +2 -1
index 62267f12dd8..1fcf53f0054 100644
@@ -7,10 +7,11 @@
  *
  * Pretend we resolved the heads, but declare our tree trumps everybody else.
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
-#include "repository.h"
+
 
 static const char builtin_merge_ours_usage[] =
 	"git merge-ours <base>... -- HEAD <remote>...";
builtin/merge-recursive.c +1 -1
index 2bd3fb0e553..1dd295558b2 100644
@@ -1,10 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "gettext.h"
 #include "hash.h"
 #include "merge-recursive.h"
 #include "object-name.h"
-#include "repository.h"
 
 static const char builtin_merge_recursive_usage[] =
 	"git %s <base>... -- <head> <remote> ...";
builtin/merge-tree.c +1 -1
index 8751d86fd0f..33f91872f9e 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
@@ -10,7 +11,6 @@
 #include "object-name.h"
 #include "object-store-ll.h"
 #include "parse-options.h"
-#include "repository.h"
 #include "blob.h"
 #include "merge-blobs.h"
 #include "quote.h"
builtin/merge.c +2 -1
index fd6dc00d6c0..c54ac7b67c6 100644
@@ -5,8 +5,9 @@
  *
  * Based on git-merge.sh by Junio C Hamano.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
builtin/mktag.c +1 -0
index 5cd8a3e6fa0..6e188dce50a 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/mktree.c +1 -0
index 72a1af1bca5..3c16faa40e3 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (c) Junio C Hamano, 2006, 2009
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
builtin/multi-pack-index.c +1 -0
index 154fc77075f..e397723fe09 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/mv.c +2 -1
index 6e2eb9cf4b8..472a2787376 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "abspath.h"
@@ -18,7 +19,7 @@
 #include "string-list.h"
 #include "parse-options.h"
 #include "read-cache-ll.h"
-#include "repository.h"
+
 #include "setup.h"
 #include "strvec.h"
 #include "submodule.h"
builtin/name-rev.c +1 -1
index 19d92fb382d..7f08c38629c 100644
@@ -1,8 +1,8 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
 #include "config.h"
 #include "commit.h"
 #include "tag.h"
builtin/notes.c +2 -2
index 49d8364af60..55ce2eb919a 100644
@@ -6,7 +6,7 @@
  * Based on git-notes.sh by Johannes Schindelin,
  * and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "editor.h"
@@ -17,7 +17,7 @@
 #include "object-name.h"
 #include "object-store-ll.h"
 #include "path.h"
-#include "repository.h"
+
 #include "pretty.h"
 #include "refs.h"
 #include "exec-cmd.h"
builtin/pack-objects.c +1 -1
index 127972f3cdf..40c64f33779 100644
@@ -1,8 +1,8 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
 #include "config.h"
 #include "attr.h"
 #include "object.h"
builtin/pack-redundant.c +2 -1
index 84f0d83affb..81f4494d466 100644
@@ -5,11 +5,12 @@
 * This file is licensed under the GPL v2.
 *
 */
+#define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
+
 #include "packfile.h"
 #include "object-store-ll.h"
 
builtin/pack-refs.c +1 -1
index 67dabb39756..2d83c1ed2ac 100644
@@ -1,9 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "refs.h"
-#include "repository.h"
 #include "revision.h"
 
 static char const * const pack_refs_usage[] = {
builtin/patch-id.c +1 -0
index fa31a1b7a60..704044c2eb9 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
builtin/prune.c +1 -0
index cbd4c38fa0a..f439d1b5bb9 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
builtin/pull.c +1 -0
index 1a926f0b0d7..149f2013205 100644
@@ -6,6 +6,7 @@
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/push.c +1 -1
index 9636ad52f4d..238cd5da829 100644
@@ -1,6 +1,7 @@
 /*
  * "git push"
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "branch.h"
@@ -13,7 +14,6 @@
 #include "transport.h"
 #include "parse-options.h"
 #include "pkt-line.h"
-#include "repository.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "send-pack.h"
builtin/range-diff.c +2 -1
index 3e67259aecc..1b33ab66a7b 100644
@@ -1,10 +1,11 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "range-diff.h"
 #include "config.h"
-#include "repository.h"
+
 
 static const char * const builtin_range_diff_usage[] = {
 N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
builtin/read-tree.c +1 -2
index 89410db6a7a..d2a807a828b 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -16,7 +16,6 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "parse-options.h"
-#include "repository.h"
 #include "resolve-undo.h"
 #include "setup.h"
 #include "sparse-index.h"
builtin/rebase.c +2 -1
index 727d9df847f..d2ad7d08631 100644
@@ -3,8 +3,9 @@
  *
  * Copyright (c) 2018 Pratik Karki
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
builtin/receive-pack.c +2 -1
index 36a6229c2a4..c4b766c6137 100644
@@ -1,6 +1,7 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
-#include "repository.h"
+
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
builtin/reflog.c +1 -1
index 6250f5ad49f..22df6834f71 100644
@@ -1,7 +1,7 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
-#include "repository.h"
 #include "revision.h"
 #include "reachable.h"
 #include "wildmatch.h"
builtin/refs.c +1 -1
index 70bca724d2a..24978a7b7b0 100644
@@ -1,9 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "fsck.h"
 #include "parse-options.h"
 #include "refs.h"
-#include "repository.h"
 #include "strbuf.h"
 
 #define REFS_MIGRATE_USAGE \
builtin/remote.c +1 -0
index 1ac7e5fbce3..61a82e515b9 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/repack.c +1 -0
index a6f2a4de1b8..1e2286d93a1 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
builtin/replace.c +1 -2
index 293ae6d327f..2daed943735 100644
@@ -7,7 +7,7 @@
  * and Carlos Rica <[email protected]> that was itself based on
  * git-tag.sh and mktag.c by Linus Torvalds.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "editor.h"
@@ -22,7 +22,6 @@
 #include "object-name.h"
 #include "object-store-ll.h"
 #include "replace-object.h"
-#include "repository.h"
 #include "tag.h"
 #include "wildmatch.h"
 
builtin/replay.c +1 -0
index c8e9098fc12..2d12a4e403f 100644
@@ -4,6 +4,7 @@
 
 #include "git-compat-util.h"
 
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "environment.h"
 #include "hex.h"
builtin/rerere.c +2 -1
index ae345155834..f7143c3f5d5 100644
@@ -1,8 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
-#include "repository.h"
+
 #include "string-list.h"
 #include "rerere.h"
 #include "xdiff/xdiff.h"
builtin/reset.c +1 -1
index 75529072606..cb054c2cc0e 100644
@@ -7,7 +7,7 @@
  *
  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/rev-list.c +1 -0
index a4186d47ce3..f62bcbf2b14 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
builtin/rev-parse.c +2 -1
index 26190aaa3ed..f2d90f69952 100644
@@ -3,8 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "abspath.h"
 #include "config.h"
 #include "commit.h"
builtin/revert.c +1 -1
index 5f2ec3ade73..55ba1092c52 100644
@@ -1,9 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
 #include "gettext.h"
-#include "repository.h"
 #include "revision.h"
 #include "rerere.h"
 #include "sequencer.h"
builtin/rm.c +2 -2
index 59077efa4b4..eaff027258d 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds 2006
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
@@ -15,7 +15,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "read-cache.h"
-#include "repository.h"
+
 #include "string-list.h"
 #include "setup.h"
 #include "sparse-index.h"
builtin/send-pack.c +1 -0
index a4925ed5fd1..4fd3cb8a357 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "hex.h"
builtin/shortlog.c +1 -1
index 70eb7890334..3ed5c460786 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
@@ -5,7 +6,6 @@
 #include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
-#include "repository.h"
 #include "revision.h"
 #include "utf8.h"
 #include "mailmap.h"
builtin/show-branch.c +2 -1
index 05c10628df9..cd6bdf63bc1 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
@@ -10,7 +11,7 @@
 #include "strvec.h"
 #include "object-name.h"
 #include "parse-options.h"
-#include "repository.h"
+
 #include "dir.h"
 #include "commit-slab.h"
 #include "date.h"
builtin/show-index.c +1 -1
index 9e1f7ac9ca5..f164c01bbea 100644
@@ -1,10 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "gettext.h"
 #include "hash.h"
 #include "hex.h"
 #include "pack.h"
 #include "parse-options.h"
-#include "repository.h"
 
 static const char *const show_index_usage[] = {
 	"git show-index [--object-format=<hash-algorithm>]",
builtin/show-ref.c +1 -0
index 6ee05f09a69..285cd3e4338 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/sparse-checkout.c +1 -1
index 23f1548fe54..5e930e5d639 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
@@ -7,7 +8,6 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "pathspec.h"
-#include "repository.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "lockfile.h"
builtin/stash.c +1 -0
index 518d297b47b..461cfaef39a 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
builtin/stripspace.c +1 -0
index 674ef939769..e147f3ff92c 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
builtin/submodule--helper.c +2 -1
index 947bd9d0f6a..b83d44ba6dc 100644
@@ -1,9 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "repository.h"
+
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
builtin/symbolic-ref.c +1 -0
index 9bc70229468..299d23d76a8 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/tag.c +1 -1
index a80838eb8e0..ca2166e7e21 100644
@@ -5,7 +5,7 @@
  *                    Carlos Rica <[email protected]>
  * Based on git-tag.sh and mktag.c by Linus Torvalds.
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
builtin/unpack-file.c +1 -0
index 97886840f8d..6da28257539 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "hex.h"
builtin/unpack-objects.c +1 -0
index 3bcdaaeb5fa..02b8d02f63f 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "bulk-checkin.h"
 #include "config.h"
builtin/update-index.c +1 -2
index 1d1d87d08e3..a1a98aa7bca 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "bulk-checkin.h"
 #include "config.h"
@@ -22,7 +22,6 @@
 #include "pathspec.h"
 #include "dir.h"
 #include "read-cache.h"
-#include "repository.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "split-index.h"
builtin/update-ref.c +1 -1
index 06826a90515..8a98615dc86 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -6,7 +7,6 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "quote.h"
-#include "repository.h"
 
 static const char * const git_update_ref_usage[] = {
 	N_("git update-ref [<options>] -d <refname> [<old-oid>]"),
builtin/update-server-info.c +1 -0
index a5b7d86727c..6769611a025 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/upload-archive.c +1 -1
index 49d1bb7fb44..6f2ddbd71c8 100644
@@ -1,12 +1,12 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "archive.h"
 #include "path.h"
 #include "pkt-line.h"
 #include "sideband.h"
-#include "repository.h"
 #include "run-command.h"
 #include "strvec.h"
 
builtin/var.c +2 -0
index 4a5c2649d6f..2ecaed51b44 100644
@@ -3,7 +3,9 @@
  *
  * Copyright (C) Eric Biederman, 2005
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+
 #include "attr.h"
 #include "config.h"
 #include "editor.h"
builtin/verify-commit.c +1 -1
index c5859e5b2b4..779b7988ca9 100644
@@ -5,11 +5,11 @@
  *
  * Based on git-verify-tag
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "object-name.h"
-#include "repository.h"
 #include "commit.h"
 #include "parse-options.h"
 #include "gpg-interface.h"
builtin/verify-pack.c +1 -0
index 7ad456649d2..34e4ed715f3 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/verify-tag.c +1 -0
index a7bef524191..f6b97048a57 100644
@@ -5,6 +5,7 @@
  *
  * Based on git-verify-tag.sh
  */
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
builtin/worktree.c +1 -1
index 3b47f9832fa..c22b2e95f50 100644
@@ -1,3 +1,4 @@
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
@@ -17,7 +18,6 @@
 #include "read-cache-ll.h"
 #include "refs.h"
 #include "remote.h"
-#include "repository.h"
 #include "run-command.h"
 #include "hook.h"
 #include "sigchain.h"
builtin/write-tree.c +1 -2
index 1b467d6ed23..de4ebf767d4 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-
+#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
@@ -12,7 +12,6 @@
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
-#include "repository.h"
 
 static const char * const write_tree_usage[] = {
 	N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
Signature · 1 line
gitgitgadget
#23 lore raw

PATCH v2 3/3 add: pass in repo variable instead of global the_repository

In reply to John Cai via GitGitGadget

From: John Cai <[email protected]>

With the repository variable available in the builtin function as an argument, pass this down into helper functions instead of using the global the_repository.

---
 builtin/add.c    | 116 +++++++++++++++++++++++++----------------------
 builtin/commit.c |   2 +-
 commit.h         |   5 +-
 3 files changed, 68 insertions(+), 55 deletions(-)
builtin/add.c +63 -53
index c893ff48d26..773b7224a49 100644
@@ -3,7 +3,6 @@
  *
  * Copyright (C) 2006 Linus Torvalds
  */
-#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
@@ -35,24 +34,27 @@ static int pathspec_file_nul;
 static int include_sparse;
 static const char *pathspec_from_file;
 
-static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
+static int chmod_pathspec(struct repository *repo,
+			  struct pathspec *pathspec,
+			  char flip,
+			  int show_only)
 {
 	int i, ret = 0;
 
-	for (i = 0; i < the_repository->index->cache_nr; i++) {
-		struct cache_entry *ce = the_repository->index->cache[i];
+	for (i = 0; i < repo->index->cache_nr; i++) {
+		struct cache_entry *ce = repo->index->cache[i];
 		int err;
 
 		if (!include_sparse &&
 		    (ce_skip_worktree(ce) ||
-		     !path_in_sparse_checkout(ce->name, the_repository->index)))
+		     !path_in_sparse_checkout(ce->name, repo->index)))
 			continue;
 
-		if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
+		if (pathspec && !ce_path_match(repo->index, ce, pathspec, NULL))
 			continue;
 
 		if (!show_only)
-			err = chmod_index_entry(the_repository->index, ce, flip);
+			err = chmod_index_entry(repo->index, ce, flip);
 		else
 			err = S_ISREG(ce->ce_mode) ? 0 : -1;
 
@@ -63,31 +65,36 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 	return ret;
 }
 
-static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
+static int renormalize_tracked_files(struct repository *repo,
+				     const struct pathspec *pathspec,
+				     int flags)
 {
 	int i, retval = 0;
 
-	for (i = 0; i < the_repository->index->cache_nr; i++) {
-		struct cache_entry *ce = the_repository->index->cache[i];
+	for (i = 0; i < repo->index->cache_nr; i++) {
+		struct cache_entry *ce = repo->index->cache[i];
 
 		if (!include_sparse &&
 		    (ce_skip_worktree(ce) ||
-		     !path_in_sparse_checkout(ce->name, the_repository->index)))
+		     !path_in_sparse_checkout(ce->name, repo->index)))
 			continue;
 		if (ce_stage(ce))
 			continue; /* do not touch unmerged paths */
 		if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
 			continue; /* do not touch non blobs */
-		if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
+		if (pathspec && !ce_path_match(repo->index, ce, pathspec, NULL))
 			continue;
-		retval |= add_file_to_index(the_repository->index, ce->name,
+		retval |= add_file_to_index(repo->index, ce->name,
 					    flags | ADD_CACHE_RENORMALIZE);
 	}
 
 	return retval;
 }
 
-static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix)
+static char *prune_directory(struct repository *repo,
+			     struct dir_struct *dir,
+			     struct pathspec *pathspec,
+			     int prefix)
 {
 	char *seen;
 	int i;
@@ -99,16 +106,16 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
 	i = dir->nr;
 	while (--i >= 0) {
 		struct dir_entry *entry = *src++;
-		if (dir_path_match(the_repository->index, entry, pathspec, prefix, seen))
+		if (dir_path_match(repo->index, entry, pathspec, prefix, seen))
 			*dst++ = entry;
 	}
 	dir->nr = dst - dir->entries;
-	add_pathspec_matches_against_index(pathspec, the_repository->index, seen,
+	add_pathspec_matches_against_index(pathspec, repo->index, seen,
 					   PS_IGNORE_SKIP_WORKTREE);
 	return seen;
 }
 
-static int refresh(int verbose, const struct pathspec *pathspec)
+static int refresh(struct repository *repo, int verbose, const struct pathspec *pathspec)
 {
 	char *seen;
 	int i, ret = 0;
@@ -118,14 +125,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)
 		    (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
 
 	seen = xcalloc(pathspec->nr, 1);
-	refresh_index(the_repository->index, flags, pathspec, seen,
+	refresh_index(repo->index, flags, pathspec, seen,
 		      _("Unstaged changes after refreshing the index:"));
 	for (i = 0; i < pathspec->nr; i++) {
 		if (!seen[i]) {
 			const char *path = pathspec->items[i].original;
 
 			if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
-			    !path_in_sparse_checkout(path, the_repository->index)) {
+			    !path_in_sparse_checkout(path, repo->index)) {
 				string_list_append(&only_match_skip_worktree,
 						   pathspec->items[i].original);
 			} else {
@@ -146,7 +153,10 @@ static int refresh(int verbose, const struct pathspec *pathspec)
 	return ret;
 }
 
-int interactive_add(const char **argv, const char *prefix, int patch)
+int interactive_add(struct repository *repo,
+		    const char **argv,
+		    const char *prefix,
+		    int patch)
 {
 	struct pathspec pathspec;
 	int ret;
@@ -158,31 +168,31 @@ int interactive_add(const char **argv, const char *prefix, int patch)
 		       prefix, argv);
 
 	if (patch)
-		ret = !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
+		ret = !!run_add_p(repo, ADD_P_ADD, NULL, &pathspec);
 	else
-		ret = !!run_add_i(the_repository, &pathspec);
+		ret = !!run_add_i(repo, &pathspec);
 
 	clear_pathspec(&pathspec);
 	return ret;
 }
 
-static int edit_patch(int argc,
+static int edit_patch(struct repository *repo,
+		      int argc,
 		      const char **argv,
-		      const char *prefix,
-		      struct repository *repo UNUSED)
+		      const char *prefix)
 {
-	char *file = git_pathdup("ADD_EDIT.patch");
+	char *file = repo_git_path(repo, "ADD_EDIT.patch");
 	struct child_process child = CHILD_PROCESS_INIT;
 	struct rev_info rev;
 	int out;
 	struct stat st;
 
-	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
+	repo_config(repo, git_diff_basic_config, NULL);
 
-	if (repo_read_index(the_repository) < 0)
+	if (repo_read_index(repo) < 0)
 		die(_("could not read the index"));
 
-	repo_init_revisions(the_repository, &rev, prefix);
+	repo_init_revisions(repo, &rev, prefix);
 	rev.diffopt.context = 7;
 
 	argc = setup_revisions(argc, argv, &rev, NULL);
@@ -320,7 +330,7 @@ static void check_embedded_repo(const char *path)
 	strbuf_release(&name);
 }
 
-static int add_files(struct dir_struct *dir, int flags)
+static int add_files(struct repository *repo, struct dir_struct *dir, int flags)
 {
 	int i, exit_status = 0;
 	struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP;
@@ -336,12 +346,12 @@ static int add_files(struct dir_struct *dir, int flags)
 
 	for (i = 0; i < dir->nr; i++) {
 		if (!include_sparse &&
-		    !path_in_sparse_checkout(dir->entries[i]->name, the_repository->index)) {
+		    !path_in_sparse_checkout(dir->entries[i]->name, repo->index)) {
 			string_list_append(&matched_sparse_paths,
 					   dir->entries[i]->name);
 			continue;
 		}
-		if (add_file_to_index(the_repository->index, dir->entries[i]->name, flags)) {
+		if (add_file_to_index(repo->index, dir->entries[i]->name, flags)) {
 			if (!ignore_add_errors)
 				die(_("adding files failed"));
 			exit_status = 1;
@@ -363,7 +373,7 @@ static int add_files(struct dir_struct *dir, int flags)
 int cmd_add(int argc,
 	    const char **argv,
 	    const char *prefix,
-	    struct repository *repo UNUSED)
+	    struct repository *repo)
 {
 	int exit_status = 0;
 	struct pathspec pathspec;
@@ -375,7 +385,7 @@ int cmd_add(int argc,
 	char *ps_matched = NULL;
 	struct lock_file lock_file = LOCK_INIT;
 
-	git_config(add_config, NULL);
+	repo_config(repo, add_config, NULL);
 
 	argc = parse_options(argc, argv, prefix, builtin_add_options,
 			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
@@ -386,13 +396,13 @@ int cmd_add(int argc,
 			die(_("options '%s' and '%s' cannot be used together"), "--dry-run", "--interactive/--patch");
 		if (pathspec_from_file)
 			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--interactive/--patch");
-		exit(interactive_add(argv + 1, prefix, patch_interactive));
+		exit(interactive_add(repo, argv + 1, prefix, patch_interactive));
 	}
 
 	if (edit_interactive) {
 		if (pathspec_from_file)
 			die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--edit");
-		return(edit_patch(argc, argv, prefix, the_repository));
+		return(edit_patch(repo, argc, argv, prefix));
 	}
 	argc--;
 	argv++;
@@ -415,10 +425,10 @@ int cmd_add(int argc,
 	add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
 	require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
 
-	prepare_repo_settings(the_repository);
-	the_repository->settings.command_requires_full_index = 0;
+	prepare_repo_settings(repo);
+	repo->settings.command_requires_full_index = 0;
 
-	repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
+	repo_hold_locked_index(repo, &lock_file, LOCK_DIE_ON_ERROR);
 
 	/*
 	 * Check the "pathspec '%s' did not match any files" block
@@ -459,11 +469,11 @@ int cmd_add(int argc,
 		 (!(addremove || take_worktree_changes)
 		  ? ADD_CACHE_IGNORE_REMOVAL : 0));
 
-	if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
+	if (repo_read_index_preload(repo, &pathspec, 0) < 0)
 		die(_("index file corrupt"));
 
-	die_in_unpopulated_submodule(the_repository->index, prefix);
-	die_path_inside_submodule(the_repository->index, &pathspec);
+	die_in_unpopulated_submodule(repo->index, prefix);
+	die_path_inside_submodule(repo->index, &pathspec);
 
 	if (add_new_files) {
 		int baselen;
@@ -475,13 +485,13 @@ int cmd_add(int argc,
 		}
 
 		/* This picks up the paths that are not tracked */
-		baselen = fill_directory(&dir, the_repository->index, &pathspec);
+		baselen = fill_directory(&dir, repo->index, &pathspec);
 		if (pathspec.nr)
-			seen = prune_directory(&dir, &pathspec, baselen);
+			seen = prune_directory(repo, &dir, &pathspec, baselen);
 	}
 
 	if (refresh_only) {
-		exit_status |= refresh(verbose, &pathspec);
+		exit_status |= refresh(repo, verbose, &pathspec);
 		goto finish;
 	}
 
@@ -492,7 +502,7 @@ int cmd_add(int argc,
 
 		if (!seen)
 			seen = find_pathspecs_matching_against_index(&pathspec,
-					the_repository->index, PS_IGNORE_SKIP_WORKTREE);
+					repo->index, PS_IGNORE_SKIP_WORKTREE);
 
 		/*
 		 * file_exists() assumes exact match
@@ -528,8 +538,8 @@ int cmd_add(int argc,
 			    !file_exists(path)) {
 				if (ignore_missing) {
 					int dtype = DT_UNKNOWN;
-					if (is_excluded(&dir, the_repository->index, path, &dtype))
-						dir_add_ignored(&dir, the_repository->index,
+					if (is_excluded(&dir, repo->index, path, &dtype))
+						dir_add_ignored(&dir, repo->index,
 								path, pathspec.items[i].len);
 				} else
 					die(_("pathspec '%s' did not match any files"),
@@ -552,9 +562,9 @@ int cmd_add(int argc,
 
 	ps_matched = xcalloc(pathspec.nr, 1);
 	if (add_renormalize)
-		exit_status |= renormalize_tracked_files(&pathspec, flags);
+		exit_status |= renormalize_tracked_files(repo, &pathspec, flags);
 	else
-		exit_status |= add_files_to_cache(the_repository, prefix,
+		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
 						  include_sparse, flags);
 
@@ -563,14 +573,14 @@ int cmd_add(int argc,
 		exit(128);
 
 	if (add_new_files)
-		exit_status |= add_files(&dir, flags);
+		exit_status |= add_files(repo, &dir, flags);
 
 	if (chmod_arg && pathspec.nr)
-		exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
+		exit_status |= chmod_pathspec(repo, &pathspec, chmod_arg[0], show_only);
 	end_odb_transaction();
 
 finish:
-	if (write_locked_index(the_repository->index, &lock_file,
+	if (write_locked_index(repo->index, &lock_file,
 			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
 		die(_("unable to write new index file"));
 
builtin/commit.c +1 -1
index fd1cc42c5a6..6c79923ee04 100644
@@ -395,7 +395,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
 		setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
 
-		if (interactive_add(argv, prefix, patch_interactive) != 0)
+		if (interactive_add(the_repository, argv, prefix, patch_interactive) != 0)
 			die(_("interactive add failed"));
 
 		the_repository->index_file = old_repo_index_file;
commit.h +4 -1
index 0e5fce543c2..c3ddaaf30f9 100644
@@ -253,7 +253,10 @@ struct oid_array;
 struct ref;
 int for_each_commit_graft(each_commit_graft_fn, void *);
 
-int interactive_add(const char **argv, const char *prefix, int patch);
+int interactive_add(struct repository *repo,
+		    const char **argv,
+		    const char *prefix,
+		    int patch);
 
 struct commit_extra_header {
 	struct commit_extra_header *next;
Signature · 1 line
gitgitgadget
#21 lore raw

Re: [PATCH v2 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to John Cai via GitGitGadget
Quoted 8 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it to all the builtins that reference the_repository.

Also, remove the include statement for repository.h since it gets brought in through builtin.h.

Can we have _all_ builtin/*.c files that include "builtin.h" to gain "#define USE_THE_REPOSITORY_VARIABLE" in this step to make it more mechanical? That way we do not have to go through this large patch manually to review it.

Then another patch can immediately remove the "#define" (and doing nothing else) from some of the files in builtin/*.c with its commit message saying "These do not need implicit or explicit accesses to the_repository as-is", which would make it trivially reviewable, because such a claim in its commit message can trivially be verified by simply compiling these files.

After that, manual work to remove implicit or explicit accesses to the_repository, which would remove the "#define" that becomes unnecessary, one-patch-per-file can build on top. Each of them would be reviewable again.

Quoted 2 lines

The next step will be to migrate each builtin
from having to use the_repository.

I am not sure what this "to migrate" refers to. Is it referring exactly the same thing as what I called "manual work" above?

Thanks.

#24 lore raw

Re: [PATCH v2 3/3] add: pass in repo variable instead of global the_repository

In reply to John Cai via GitGitGadget
Quoted 5 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

With the repository variable available in the builtin function as an argument, pass this down into helper functions instead of using the global the_repository.

Nicely done.

#14 lore raw

Re: [PATCH v2 1/3] builtin: add a repository parameter for builtin functions

In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · John Cai via GitGitGadget
 git.c                              |  12 +-
 help.c                             |   3 +-
 stkOs5Qh                           | Bin 0 -> 10485768 bytes

WTH is this file?

It turns out to be an "ar" archive full of *.o files. Perhaps creation of libgit.a was interrupted, then later somebody said "git add .", and the file somehow ended up as a part of Git.

I've applied the series after removing the cruft.

The overall thrust to pass the repository found by the setup step to builtins as a parameter is a very good one, as most of the Git commands are designed to work in a repository.

With this, can commands that are marked with RUN_SETUP_GENTLY rely on the NULL-ness of repo parameter to decide if they are in a repository or running outside a repository?

The "nongit?" status returned from setup_git_directory_gently() call made by git.c:run_builtin() is thrown away and not passed to the builtin functions at all, so some of them currently may be doing another discovery themselves, and if we can replace such a wasteful setup_git_directory_gently() call, it would be nice, and passing the discovered repository instance to builtin commands is a good first step to go there.

Thanks.

#15 lore raw

Re: [PATCH v2 1/3] builtin: add a repository parameter for builtin functions

Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · John Cai via GitGitGadget
 git.c                              |  12 +-
 help.c                             |   3 +-
 stkOs5Qh                           | Bin 0 -> 10485768 bytes
Quoted 7 lines
Quoted 1 line

WTH is this file?

It turns out to be an "ar" archive full of *.o files. Perhaps creation of libgit.a was interrupted, then later somebody said "git add .", and the file somehow ended up as a part of Git.

I've applied the series after removing the cruft.

I've noticed that something leaves behind this garbage from time to time. It's a shame that its name is just random gibberish, because that makes it impossible to set up a gitignore rule for it.

Quoted 3 lines

The overall thrust to pass the repository found by the setup step to builtins as a parameter is a very good one, as most of the Git commands are designed to work in a repository.

Yup, that's the direction we want to move into. We're basically trying to approach getting rid of the_repository both bottom-up and top-down now. My changes are bottom up, libifying the low-level subsystems as we go. And this here is the first change going top-down, getting rid of the global dependency in our builtins. Eventually the plan is to meet in the middle.

Patrick

#16 lore raw

Re: [PATCH v2 1/3] builtin: add a repository parameter for builtin functions

Quoted 9 lines · Patrick Steinhardt
Quoted 5 lines

It turns out to be an "ar" archive full of *.o files. Perhaps creation of libgit.a was interrupted, then later somebody said "git add .", and the file somehow ended up as a part of Git.

I've applied the series after removing the cruft.

I've noticed that something leaves behind this garbage from time to time. It's a shame that its name is just random gibberish, because that makes it impossible to set up a gitignore rule for it.

I've seen it once or twice, too. It's always st[A-Za-z0-9]{6}, at least on my system. Doing this:

Makefile +1 -1
index 91f65d7dc5..b58312edab 100644
@@ -2860,7 +2860,7 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
 		$(filter %.o,$^) $(LIBS)
 
 $(LIB_FILE): $(LIB_OBJS)
-	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
+	$(QUIET_AR)$(RM) $@ && ($(AR) $(ARFLAGS) $@ $^ & sleep 0.01; kill $$!) && false
 
 $(XDIFF_LIB): $(XDIFF_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^

and then running "make" several times got me:

Untracked files:
st5AOnzl
st8gTTvD
stJABM4u
stKA7riS
stLZ4yDr
stMWJCVY
stjYXpN0
stwcX3kZ

I don't think we'd want to put anything in the tracked .gitignore, since it involves system-specific details. But I think that:

/st[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]

in your .git/info/excludes (or user-level gitignore) would work if you want, and is probably not too likely to hit false positives (since it lacks an extension).

I do feel like I have only started seeing it in the last month or so. I wonder if a new version of binutils changed behavior or something.

-Peff

#17 lore raw

Re: [PATCH v2 1/3] builtin: add a repository parameter for builtin functions

Quoted 2 lines · Jeff King

I do feel like I have only started seeing it in the last month or so. I wonder if a new version of binutils changed behavior or something.

Since I had that Makefile reproduction, I ran it against an older version of binutils. And yeah, it produces the same outcome. So it is probably just some kind of Baader-Meinhof phenomenon.

-Peff

#18 lore raw

Re: [PATCH v2 1/3] builtin: add a repository parameter for builtin functions

Quoted 8 lines · Jeff King
Quoted 2 lines · Jeff King

I do feel like I have only started seeing it in the last month or so. I wonder if a new version of binutils changed behavior or something.

Since I had that Makefile reproduction, I ran it against an older version of binutils. And yeah, it produces the same outcome. So it is probably just some kind of Baader-Meinhof phenomenon.

I was also reading through recent changes in binutils and couldn't spot anything. But in any case, I also had the feeling that this only started to pop up recently. Maybe it's not a change in binutils, but in our own build instructions. I couldn't find any smoking guns there either, though.

Patrick

#19 lore raw

Re: [PATCH v2 1/3] builtin: add a repository parameter for builtin functions

Quoted 11 lines · Patrick Steinhardt
Quoted 8 lines · Jeff King
Quoted 2 lines · Jeff King

I do feel like I have only started seeing it in the last month or so. I wonder if a new version of binutils changed behavior or something.

Since I had that Makefile reproduction, I ran it against an older version of binutils. And yeah, it produces the same outcome. So it is probably just some kind of Baader-Meinhof phenomenon.

Quoted 5 lines

I was also reading through recent changes in binutils and couldn't spot anything. But in any case, I also had the feeling that this only started to pop up recently. Maybe it's not a change in binutils, but in our own build instructions. I couldn't find any smoking guns there either, though.

Sorry everyone. I totally missed that the garbage file got checked in accidentally. my apologies.

Quoted 2 lines

Patrick

#22 lore raw

Re: [PATCH v2 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

In reply to Junio C Hamano
Quoted 24 lines · Junio C Hamano
Quoted 8 lines · John Cai via GitGitGadget

From: John Cai <[email protected]>

Instead of including USE_THE_REPOSITORY_VARIABLE by default on every builtin, remove it from builtin.h and add it to all the builtins that reference the_repository.

Also, remove the include statement for repository.h since it gets brought in through builtin.h.

Can we have _all_ builtin/*.c files that include "builtin.h" to gain "#define USE_THE_REPOSITORY_VARIABLE" in this step to make it more mechanical? That way we do not have to go through this large patch manually to review it.

Then another patch can immediately remove the "#define" (and doing nothing else) from some of the files in builtin/*.c with its commit message saying "These do not need implicit or explicit accesses to the_repository as-is", which would make it trivially reviewable, because such a claim in its commit message can trivially be verified by simply compiling these files.

Quoted 4 lines

After that, manual work to remove implicit or explicit accesses to the_repository, which would remove the "#define" that becomes unnecessary, one-patch-per-file can build on top. Each of them would be reviewable again.

Okay I see what you mean. Yeah I can do that.

Quoted 6 lines
Quoted 3 lines

The next step will be to migrate each builtin
from having to use the_repository.

I am not sure what this "to migrate" refers to. Is it referring exactly the same thing as what I called "manual work" above?

Yes, by migrate I meant the process of removing #define and passing in the repository
argument through to replace the_repository global.

Quoted 1 line

Thanks.

#25 lore raw

v3 cover Add repository parameter to builtins

In reply to John Cai via GitGitGadget

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. Remove USE_THE_REPOSITORY_VARIABLE from bulitins that do not use the_repository.
4. As an example, migrate builtin/add.c to get rid of the_repository by instead passing the repository argument down into helper functions.

Changes since V2:

* Add USE_THE_REPOSITORY_VARIABLE to all builtins under builtin/ that contain builtin.h, and subsequently add a patch that removes it from builtins that do not use the_repository.
* removed random generated file

Changes since V1:

* Removed USE_THE_REPOSITORY_VARIABLE from add.c
* removed changes that conflict with existing topics in seen
* Fixed overly long lines formatting issues

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

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

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

Range-diff vs v2:

1: 9aaf9662544 ! 1: 02a4466ecc9 builtin: add a repository parameter for builtin functions
@@ builtin/fetch-pack.c: static void add_sought_entry(struct ref ***sought, int *nr
+ struct repository *repo UNUSED)
{
int i, ret;
- struct ref *ref = NULL;
+ struct ref *fetched_refs = NULL, *remote_refs = NULL;

## builtin/fetch.c ##
@@ builtin/fetch.c: static int fetch_one(struct remote *remote, int argc, const char **argv,
@@ help.c: void get_version_info(struct strbuf *buf, int show_build_options)
{
struct strbuf buf = STRBUF_INIT;
int build_options = 0;
-
- ## stkOs5Qh (new) ##
- Binary files /dev/null and stkOs5Qh differ
2: 434c8babbb1 ! 2: 7becd3751fc builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h

     @@ builtin/check-mailmap.c
       #include "config.h"
       #include "gettext.h"
      
     + ## builtin/check-ref-format.c ##
     +@@
     + /*
     +  * GIT - The information manager from hell
     +  */
     +-
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "refs.h"
     + #include "setup.h"
     +
       ## builtin/checkout--worker.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
     @@ builtin/credential-cache--daemon.c
       #include "abspath.h"
       #include "gettext.h"
      
     + ## builtin/credential-cache.c ##
     +@@
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "credential.h"
     + #include "gettext.h"
     +
       ## builtin/credential-store.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
     @@ builtin/describe.c
       #include "config.h"
       #include "environment.h"
      
     + ## builtin/diagnose.c ##
     +@@
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "abspath.h"
     + #include "gettext.h"
     +
       ## builtin/diff-files.c ##
      @@
        *
     @@ builtin/gc.c
       #include "tempfile.h"
       #include "lockfile.h"
      
     + ## builtin/get-tar-commit-id.c ##
     +@@
     + /*
     +  * Copyright (c) 2005, 2006 Rene Scharfe
     +  */
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "commit.h"
     + #include "tar.h"
     +
       ## builtin/grep.c ##
      @@
        *
     @@ builtin/mailinfo.c
       #include "abspath.h"
       #include "environment.h"
      
     + ## builtin/mailsplit.c ##
     +@@
     +  * It just splits a mbox into a list of files: "0001" "0002" ..
     +  * so you can process them further from there.
     +  */
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "gettext.h"
     + #include "string-list.h"
     +
       ## builtin/merge-base.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
     @@ builtin/patch-id.c
       #include "config.h"
       #include "diff.h"
      
     + ## builtin/prune-packed.c ##
     +@@
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "gettext.h"
     + #include "parse-options.h"
     +
       ## builtin/prune.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
     @@ builtin/refs.c
       
       #define REFS_MIGRATE_USAGE \
      
     + ## builtin/remote-ext.c ##
     +@@
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "transport.h"
     + #include "run-command.h"
     +
     + ## builtin/remote-fd.c ##
     +@@
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "transport.h"
     + 
     +
       ## builtin/remote.c ##
      @@
      +#define USE_THE_REPOSITORY_VARIABLE
     @@ builtin/upload-archive.c
       #include "strvec.h"
       
      
     + ## builtin/upload-pack.c ##
     +@@
     ++#define USE_THE_REPOSITORY_VARIABLE
     + #include "builtin.h"
     + #include "exec-cmd.h"
     + #include "gettext.h"
     +
       ## builtin/var.c ##
      @@
        *
 -:  ----------- > 3:  004283a1e5b builtin: remove USE_THE_REPOSITORY for those without the_repository
 3:  6956d3fe897 = 4:  d32f8ade1e0 add: pass in repo variable instead of global the_repository
Signature · 1 line
gitgitgadget