git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 00/16] Header cleanups
@ 2023-03-19  6:27 Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
                   ` (17 more replies)
  0 siblings, 18 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren

Maintainer note: I dropped multiple changes from this series to avoid
conflicts with other in-flight series, but two small conflicts remain. In
order to merge with next, add the following declaration to abspath.h:

    /* Likewise, but path=="-" always yields "-" */
    char *prefix_filename_except_for_dash(const char *prefix, const char *path);


(from cache.h) and remove the entire conflicted region in cache.h. There is
also a semantic conflict with seen; to fix, include abspath.h in the new
file compat/fsmonitor/fsm-path-utils-linux.c.

This series picks up where en/header-cleanups leaves off and does more
header cleanups, trying to reduce the number of files depending on cache.h.
(There are still more that could be done, but again, this is a good chunk
for now.)

Notes:

 * As I mentioned in my last series, Dscho's gitgitgadget is super helpful
   for a series like this.
 * As with my previous series (en/header-cleanup), I used the scripts at my
   header-cleanup-scripts branch
   [https://github.com/newren/git/commit/db81c8d7fb554b3edf04320e218bddeb98bb6194],
   and some tweaks thereof, repeatedly while making this series (though they
   are prone to produce both false positive and false negatives, so if you
   use them, only use them to generate hints about which files to look at).

Elijah Newren (16):
  treewide: remove unnecessary cache.h inclusion from a few headers
  treewide: be explicit about dependence on gettext.h
  treewide: remove unnecessary inclusion of gettext.h
  treewide: remove unnecessary cache.h inclusion from several sources
  environment: move comment_line_char from cache.h
  abspath.h: move absolute path functions from cache.h
  cache.h: remove expand_user_path()
  path.h: move function declarations for path.c functions from cache.h
  wrapper.h: move declarations for wrapper.c functions from cache.h
  treewide: remove unnecessary includes of cache.h
  environment.h: move declarations for environment.c functions from
    cache.h
  treewide: remove cache.h inclusion due to environment.h changes
  setup.h: move declarations for setup.c functions from cache.h
  treewide: remove cache.h inclusion due to setup.h changes
  write-or-die.h: move declarations for write-or-die.c functions from
    cache.h
  csum-file.h: remove unnecessary inclusion of cache.h

 abspath.c                                    |   4 +-
 abspath.h                                    |  30 +
 add-interactive.c                            |   1 +
 add-patch.c                                  |   2 +
 apply.c                                      |   5 +
 archive-tar.c                                |   2 +
 archive-zip.c                                |   2 +
 archive.c                                    |   4 +
 attr.c                                       |   3 +
 bisect.c                                     |   2 +
 blame.c                                      |   2 +
 branch.c                                     |   2 +
 builtin/add.c                                |   1 +
 builtin/am.c                                 |   4 +
 builtin/apply.c                              |   1 +
 builtin/archive.c                            |   1 +
 builtin/bisect.c                             |   3 +
 builtin/blame.c                              |   4 +
 builtin/branch.c                             |   3 +
 builtin/bugreport.c                          |   5 +-
 builtin/bundle.c                             |   3 +
 builtin/cat-file.c                           |   3 +
 builtin/check-attr.c                         |   4 +
 builtin/check-ignore.c                       |   2 +
 builtin/check-mailmap.c                      |   2 +
 builtin/check-ref-format.c                   |   1 +
 builtin/checkout--worker.c                   |   1 +
 builtin/checkout-index.c                     |   2 +
 builtin/checkout.c                           |   3 +
 builtin/clean.c                              |   3 +
 builtin/clone.c                              |   4 +
 builtin/column.c                             |   1 +
 builtin/commit-graph.c                       |   2 +
 builtin/commit-tree.c                        |   1 +
 builtin/commit.c                             |   2 +
 builtin/config.c                             |   5 +
 builtin/count-objects.c                      |   2 +
 builtin/credential-cache--daemon.c           |   2 +
 builtin/credential-cache.c                   |   3 +
 builtin/credential-store.c                   |   2 +
 builtin/describe.c                           |   3 +
 builtin/diagnose.c                           |   2 +
 builtin/diff-index.c                         |   1 +
 builtin/diff-tree.c                          |   1 +
 builtin/diff.c                               |   2 +
 builtin/difftool.c                           |   5 +
 builtin/fast-export.c                        |   1 +
 builtin/fast-import.c                        |   4 +
 builtin/fetch-pack.c                         |   1 +
 builtin/fetch.c                              |   2 +
 builtin/fmt-merge-msg.c                      |   2 +
 builtin/for-each-ref.c                       |   1 +
 builtin/for-each-repo.c                      |   1 +
 builtin/fsck.c                               |   1 +
 builtin/fsmonitor--daemon.c                  |   3 +
 builtin/gc.c                                 |   5 +
 builtin/get-tar-commit-id.c                  |   1 +
 builtin/grep.c                               |   3 +
 builtin/hash-object.c                        |   4 +
 builtin/help.c                               |   2 +
 builtin/hook.c                               |   1 +
 builtin/index-pack.c                         |   4 +
 builtin/init-db.c                            |   5 +
 builtin/interpret-trailers.c                 |   1 +
 builtin/log.c                                |   4 +
 builtin/ls-files.c                           |   2 +
 builtin/ls-remote.c                          |   1 +
 builtin/ls-tree.c                            |   1 +
 builtin/mailinfo.c                           |   3 +
 builtin/mailsplit.c                          |   1 +
 builtin/merge-base.c                         |   1 +
 builtin/merge-file.c                         |   3 +
 builtin/merge-recursive.c                    |   1 +
 builtin/merge-tree.c                         |   1 +
 builtin/merge.c                              |   4 +
 builtin/mktag.c                              |   1 +
 builtin/mktree.c                             |   1 +
 builtin/multi-pack-index.c                   |   3 +
 builtin/mv.c                                 |   4 +
 builtin/name-rev.c                           |   2 +
 builtin/notes.c                              |   2 +
 builtin/pack-objects.c                       |   3 +
 builtin/pack-redundant.c                     |   1 +
 builtin/pack-refs.c                          |   1 +
 builtin/patch-id.c                           |   1 +
 builtin/prune-packed.c                       |   1 +
 builtin/prune.c                              |   2 +
 builtin/pull.c                               |   1 +
 builtin/push.c                               |   2 +
 builtin/range-diff.c                         |   1 +
 builtin/read-tree.c                          |   2 +
 builtin/rebase.c                             |   4 +
 builtin/receive-pack.c                       |   4 +
 builtin/reflog.c                             |   1 +
 builtin/remote.c                             |   1 +
 builtin/repack.c                             |   2 +
 builtin/replace.c                            |   2 +
 builtin/rerere.c                             |   2 +
 builtin/reset.c                              |   3 +
 builtin/rev-list.c                           |   2 +
 builtin/rev-parse.c                          |   4 +
 builtin/revert.c                             |   1 +
 builtin/rm.c                                 |   2 +
 builtin/send-pack.c                          |   1 +
 builtin/shortlog.c                           |   3 +
 builtin/show-branch.c                        |   2 +
 builtin/show-index.c                         |   1 +
 builtin/show-ref.c                           |   1 +
 builtin/sparse-checkout.c                    |   3 +
 builtin/stash.c                              |   4 +
 builtin/stripspace.c                         |   3 +
 builtin/submodule--helper.c                  |   4 +
 builtin/symbolic-ref.c                       |   1 +
 builtin/tag.c                                |   3 +
 builtin/unpack-file.c                        |   1 +
 builtin/unpack-objects.c                     |   2 +
 builtin/update-index.c                       |   4 +
 builtin/update-ref.c                         |   1 +
 builtin/update-server-info.c                 |   1 +
 builtin/upload-pack.c                        |   1 +
 builtin/verify-commit.c                      |   1 +
 builtin/verify-pack.c                        |   1 +
 builtin/verify-tag.c                         |   1 +
 builtin/worktree.c                           |   4 +
 builtin/write-tree.c                         |   2 +
 bulk-checkin.c                               |   4 +-
 bulk-checkin.h                               |   2 +-
 bundle-uri.c                                 |   2 +
 bundle.c                                     |   3 +
 bundle.h                                     |   1 -
 cache-tree.c                                 |   3 +-
 cache.h                                      | 568 -------------------
 chdir-notify.c                               |   1 +
 chunk-format.c                               |   2 +
 color.c                                      |   1 +
 combine-diff.c                               |   1 +
 commit-graph.c                               |   4 +-
 commit.c                                     |   3 +
 common-main.c                                |   2 +
 compat/disk.h                                |   2 +
 compat/fsmonitor/fsm-health-win32.c          |   1 +
 compat/fsmonitor/fsm-listen-darwin.c         |   1 +
 compat/fsmonitor/fsm-listen-win32.c          |   1 +
 compat/fsmonitor/fsm-path-utils-darwin.c     |   1 +
 compat/fsmonitor/fsm-path-utils-win32.c      |   1 +
 compat/linux/procinfo.c                      |   2 +-
 compat/mingw.c                               |   4 +
 compat/precompose_utf8.c                     |   2 +
 compat/simple-ipc/ipc-shared.c               |   2 +-
 compat/simple-ipc/ipc-unix-socket.c          |   1 +
 compat/simple-ipc/ipc-win32.c                |   2 +
 compat/terminal.c                            |   4 +-
 config.c                                     |   7 +-
 connect.c                                    |   2 +
 connected.c                                  |   3 +-
 convert.c                                    |   2 +
 copy.c                                       |   1 +
 credential.c                                 |   2 +
 csum-file.c                                  |   3 +-
 csum-file.h                                  |   2 +-
 daemon.c                                     |   4 +
 date.c                                       |   1 +
 delta-islands.c                              |   3 +-
 diagnose.c                                   |   2 +
 diff-lib.c                                   |   1 +
 diff-no-index.c                              |   2 +
 diff.c                                       |   5 +
 dir.c                                        |   5 +
 editor.c                                     |   3 +
 entry.c                                      |   3 +
 environment.c                                |   5 +
 environment.h                                | 220 +++++++
 exec-cmd.c                                   |   3 +
 fetch-pack.c                                 |   5 +-
 fmt-merge-msg.c                              |   3 +-
 fsck.c                                       |   2 +-
 fsmonitor-ipc.c                              |   1 +
 fsmonitor.c                                  |   1 +
 gettext.c                                    |   4 +-
 git.c                                        |   3 +
 gpg-interface.c                              |   6 +-
 grep.c                                       |   3 +-
 http-backend.c                               |   5 +-
 http-fetch.c                                 |   2 +
 http-push.c                                  |   2 +
 imap-send.c                                  |   3 +
 line-log.c                                   |   2 +-
 list-objects-filter-options.h                |   1 +
 list-objects-filter.c                        |   1 +
 list-objects.c                               |   1 +
 ll-merge.c                                   |   1 +
 lockfile.c                                   |   4 +-
 log-tree.c                                   |   2 +
 ls-refs.c                                    |   4 +-
 mailmap.c                                    |   2 +
 merge-ort-wrappers.c                         |   1 +
 merge-ort.c                                  |   2 +
 merge-recursive.c                            |   3 +
 merge.c                                      |   1 +
 midx.c                                       |   4 +-
 name-hash.c                                  |   2 +
 negotiator/default.c                         |   2 +-
 negotiator/skipping.c                        |   2 +-
 notes-cache.c                                |   2 +-
 notes-merge.c                                |   2 +
 notes-utils.c                                |   4 +-
 notes.c                                      |   1 +
 object-file.c                                |   7 +-
 object-name.c                                |   3 +
 object.c                                     |   1 +
 pack-bitmap-write.c                          |   5 +-
 pack-bitmap.c                                |   3 +-
 pack-check.c                                 |   1 +
 pack-mtimes.c                                |   3 +-
 pack-revindex.c                              |   1 +
 pack-write.c                                 |   2 +
 pack.h                                       |   2 +
 packfile.c                                   |   5 +-
 packfile.h                                   |   4 +-
 parallel-checkout.c                          |   2 +
 parse-options-cb.c                           |   2 +
 parse-options.c                              |   3 +-
 parse-options.h                              |   2 +
 patch-ids.c                                  |   2 +-
 path.c                                       |   6 +-
 path.h                                       |  62 +-
 pathspec.c                                   |   4 +
 pkt-line.c                                   |   3 +
 preload-index.c                              |   2 +
 pretty.c                                     |   2 +
 progress.c                                   |   1 -
 promisor-remote.c                            |   1 +
 prompt.c                                     |   3 +-
 protocol.c                                   |   1 +
 prune-packed.c                               |   2 +
 range-diff.c                                 |   2 +
 reachable.c                                  |   3 +-
 read-cache.c                                 |   3 +
 rebase-interactive.c                         |   3 +
 ref-filter.c                                 |   4 +-
 ref-filter.h                                 |   1 +
 reflog.c                                     |   3 +-
 refs.c                                       |   6 +-
 refs.h                                       |   1 -
 refs/files-backend.c                         |   7 +-
 refs/iterator.c                              |   2 +-
 refs/packed-backend.c                        |   4 +-
 refspec.c                                    |   1 +
 remote-curl.c                                |   4 +
 remote.c                                     |   6 +-
 replace-object.c                             |   3 +-
 repository.c                                 |   2 +
 rerere.c                                     |   3 +
 rerere.h                                     |   1 +
 reset.c                                      |   1 +
 revision.c                                   |   3 +
 run-command.c                                |   2 +
 scalar.c                                     |   2 +
 send-pack.c                                  |   4 +-
 sequencer.c                                  |   4 +
 server-info.c                                |   4 +-
 setup.c                                      |   4 +
 setup.h                                      | 168 ++++++
 shallow.c                                    |   3 +-
 sideband.c                                   |   2 +
 sparse-index.c                               |   2 +
 split-index.c                                |   1 +
 strbuf.c                                     |   6 +-
 streaming.c                                  |   2 +
 streaming.h                                  |   4 +-
 submodule-config.c                           |   2 +
 submodule.c                                  |   6 +-
 symlinks.c                                   |   2 +
 t/helper/test-advise.c                       |   2 +-
 t/helper/test-bitmap.c                       |   3 +-
 t/helper/test-bloom.c                        |   4 +-
 t/helper/test-bundle-uri.c                   |   1 +
 t/helper/test-cache-tree.c                   |   2 +
 t/helper/test-config.c                       |   2 +-
 t/helper/test-delta.c                        |   2 +-
 t/helper/test-dump-cache-tree.c              |   2 +-
 t/helper/test-dump-fsmonitor.c               |   1 +
 t/helper/test-dump-split-index.c             |   1 +
 t/helper/test-dump-untracked-cache.c         |   1 +
 t/helper/test-fast-rebase.c                  |   5 +-
 t/helper/test-fsmonitor-client.c             |   2 +
 t/helper/test-hash.c                         |   1 -
 t/helper/test-lazy-init-name-hash.c          |   2 +
 t/helper/test-match-trees.c                  |   1 +
 t/helper/test-oid-array.c                    |   1 +
 t/helper/test-oidmap.c                       |   1 +
 t/helper/test-oidtree.c                      |   1 +
 t/helper/test-pack-mtimes.c                  |   2 +-
 t/helper/test-parse-pathspec-file.c          |   1 -
 t/helper/test-partial-clone.c                |   4 +-
 t/helper/test-path-utils.c                   |   3 +
 t/helper/test-pkt-line.c                     |   3 +-
 t/helper/test-proc-receive.c                 |   4 +-
 t/helper/test-progress.c                     |   1 -
 t/helper/test-reach.c                        |   3 +
 t/helper/test-read-cache.c                   |   2 +
 t/helper/test-read-graph.c                   |   2 +-
 t/helper/test-read-midx.c                    |   1 +
 t/helper/test-ref-store.c                    |   2 +-
 t/helper/test-repository.c                   |   3 +-
 t/helper/test-revision-walking.c             |   2 +-
 t/helper/test-run-command.c                  |   1 -
 t/helper/test-scrap-cache-tree.c             |   1 +
 t/helper/test-serve-v2.c                     |   3 +-
 t/helper/test-submodule-config.c             |   1 +
 t/helper/test-submodule-nested-repo-config.c |   2 +-
 t/helper/test-submodule.c                    |   2 +-
 t/helper/test-subprocess.c                   |   2 +-
 t/helper/test-trace2.c                       |   2 +-
 t/helper/test-userdiff.c                     |   2 +-
 t/helper/test-write-cache.c                  |   1 +
 tag.c                                        |   2 +
 tempfile.c                                   |   4 +-
 tmp-objdir.c                                 |   2 +
 trace.c                                      |   4 +
 trace2/tr2_cfg.c                             |   4 +-
 trace2/tr2_cmd_name.c                        |   3 +-
 trace2/tr2_dst.c                             |   4 +-
 trace2/tr2_sid.c                             |   3 +-
 trailer.c                                    |   4 +-
 transport-helper.c                           |   3 +
 transport.c                                  |   4 +-
 transport.h                                  |   1 -
 tree-walk.c                                  |   1 +
 unpack-trees.c                               |   3 +
 upload-pack.c                                |   3 +
 usage.c                                      |   4 +-
 walker.c                                     |   1 +
 worktree.c                                   |   5 +
 wrapper.c                                    |   3 +
 wrapper.h                                    |  36 ++
 write-or-die.c                               |   4 +-
 write-or-die.h                               |  78 +++
 wt-status.c                                  |   3 +
 xdiff-interface.c                            |   2 +-
 340 files changed, 1308 insertions(+), 666 deletions(-)
 create mode 100644 abspath.h
 create mode 100644 setup.h
 create mode 100644 wrapper.h
 create mode 100644 write-or-die.h


base-commit: 950264636c68591989456e3ba0a5442f93152c1a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1493%2Fnewren%2Fheader-cleanup-2-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1493/newren/header-cleanup-2-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1493
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 01/16] treewide: remove unnecessary cache.h inclusion from a few headers
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 02/16] treewide: be explicit about dependence on gettext.h Elijah Newren via GitGitGadget
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Ever since a64215b6cd ("object.h: stop depending on cache.h; make
cache.h depend on object.h", 2023-02-24), we have a few headers that
could have replaced their include of cache.h with an include of
object.h.  Make that change now.

Some C files had to start including cache.h after this change (or some
smaller header it had brought in), because the C files were depending
on things from cache.h but were only formerly implicitly getting
cache.h through one of these headers being modified in this patch.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 bulk-checkin.h              | 2 +-
 bundle.h                    | 1 -
 cache-tree.c                | 2 +-
 config.c                    | 2 +-
 fmt-merge-msg.c             | 2 +-
 fsck.c                      | 2 +-
 http-backend.c              | 2 +-
 pack-mtimes.c               | 2 +-
 packfile.h                  | 4 +++-
 prune-packed.c              | 2 +-
 ref-filter.c                | 2 +-
 refs.c                      | 2 +-
 refs.h                      | 1 -
 refs/packed-backend.c       | 2 +-
 refspec.c                   | 1 +
 remote.c                    | 2 +-
 server-info.c               | 2 +-
 shallow.c                   | 2 +-
 strbuf.c                    | 2 +-
 streaming.h                 | 4 +++-
 submodule.c                 | 2 +-
 t/helper/test-bundle-uri.c  | 1 +
 t/helper/test-fast-rebase.c | 2 +-
 t/helper/test-pack-mtimes.c | 2 +-
 t/helper/test-reach.c       | 1 +
 transport.c                 | 2 +-
 transport.h                 | 1 -
 worktree.c                  | 2 +-
 28 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/bulk-checkin.h b/bulk-checkin.h
index 8281b9cb159..48fe9a6e917 100644
--- a/bulk-checkin.h
+++ b/bulk-checkin.h
@@ -4,7 +4,7 @@
 #ifndef BULK_CHECKIN_H
 #define BULK_CHECKIN_H
 
-#include "cache.h"
+#include "object.h"
 
 void prepare_loose_object_bulk_checkin(void);
 void fsync_loose_object_bulk_checkin(int fd, const char *filename);
diff --git a/bundle.h b/bundle.h
index 9f2bd733a6a..021adbdcbb3 100644
--- a/bundle.h
+++ b/bundle.h
@@ -2,7 +2,6 @@
 #define BUNDLE_H
 
 #include "strvec.h"
-#include "cache.h"
 #include "string-list.h"
 #include "list-objects-filter-options.h"
 
diff --git a/cache-tree.c b/cache-tree.c
index 9d46ecef091..6f899beb041 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/config.c b/config.c
index d0aff55fa66..983c45fc37b 100644
--- a/config.c
+++ b/config.c
@@ -5,7 +5,7 @@
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "date.h"
 #include "branch.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 24cc44bdbc9..c870cb95b9d 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "refs.h"
diff --git a/fsck.c b/fsck.c
index 871c0a9a252..70e12497878 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/http-backend.c b/http-backend.c
index 9cfc6f25414..7e7c19e66b3 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hex.h"
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 0f9785fc5e4..cd92fc1d86c 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "pack-mtimes.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/packfile.h b/packfile.h
index a3f6723857b..648be62bf22 100644
--- a/packfile.h
+++ b/packfile.h
@@ -1,11 +1,13 @@
 #ifndef PACKFILE_H
 #define PACKFILE_H
 
-#include "cache.h"
+#include "object.h"
 #include "oidset.h"
 
 /* in object-store.h */
 struct packed_git;
+struct pack_entry;
+struct pack_window;
 struct object_info;
 
 /*
diff --git a/prune-packed.c b/prune-packed.c
index d2813f6a405..e02f466c2ee 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "object-store.h"
 #include "packfile.h"
 #include "progress.h"
diff --git a/ref-filter.c b/ref-filter.c
index ed802778da7..38141bce8db 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/refs.c b/refs.c
index 53240bcc07b..4e5cc73fb10 100644
--- a/refs.c
+++ b/refs.c
@@ -2,7 +2,7 @@
  * The backend-independent part of the reference module.
  */
 
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hashmap.h"
diff --git a/refs.h b/refs.h
index 935cdd1ece3..5741b69d0d1 100644
--- a/refs.h
+++ b/refs.h
@@ -1,7 +1,6 @@
 #ifndef REFS_H
 #define REFS_H
 
-#include "cache.h"
 #include "commit.h"
 
 struct object_id;
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index b665d0f7d9b..6f975185995 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,4 +1,4 @@
-#include "../git-compat-util.h"
+#include "../cache.h"
 #include "../alloc.h"
 #include "../config.h"
 #include "../hex.h"
diff --git a/refspec.c b/refspec.c
index 28d90911aa5..7b5c305514d 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
 #include "refs.h"
diff --git a/remote.c b/remote.c
index b04e5da3383..2daddb85cb7 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hex.h"
diff --git a/server-info.c b/server-info.c
index 40436892023..78643377057 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "dir.h"
 #include "hex.h"
diff --git a/shallow.c b/shallow.c
index 1cbb05ba0e4..c5433a4fd30 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/strbuf.c b/strbuf.c
index 1c57ac6574f..8800830ebf8 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/streaming.h b/streaming.h
index 5e4e6acfd0d..bd27f59e576 100644
--- a/streaming.h
+++ b/streaming.h
@@ -3,10 +3,12 @@
  */
 #ifndef STREAMING_H
 #define STREAMING_H 1
-#include "cache.h"
+
+#include "object.h"
 
 /* opaque */
 struct git_istream;
+struct stream_filter;
 
 struct git_istream *open_istream(struct repository *, const struct object_id *,
 				 enum object_type *, unsigned long *,
diff --git a/submodule.c b/submodule.c
index 2a057c35b74..0baf97cf770 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
diff --git a/t/helper/test-bundle-uri.c b/t/helper/test-bundle-uri.c
index b18e7603103..475058592d1 100644
--- a/t/helper/test-bundle-uri.c
+++ b/t/helper/test-bundle-uri.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "parse-options.h"
 #include "bundle-uri.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "transport.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index b1edb92a032..1e975df9041 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -12,7 +12,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-
+#include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "hex.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index f68b3761b68..0e53dee9e57 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,5 +1,5 @@
-#include "git-compat-util.h"
 #include "test-tool.h"
+#include "cache.h"
 #include "hex.h"
 #include "strbuf.h"
 #include "object-store.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index de8f26639d4..05d56267a9f 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,4 +1,5 @@
 #include "test-tool.h"
+#include "cache.h"
 #include "alloc.h"
 #include "commit.h"
 #include "commit-reach.h"
diff --git a/transport.c b/transport.c
index 906dbad5a08..80059124c0a 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hex.h"
diff --git a/transport.h b/transport.h
index 85150f504fb..6393cd9823c 100644
--- a/transport.h
+++ b/transport.h
@@ -1,7 +1,6 @@
 #ifndef TRANSPORT_H
 #define TRANSPORT_H
 
-#include "cache.h"
 #include "run-command.h"
 #include "remote.h"
 #include "list-objects-filter-options.h"
diff --git a/worktree.c b/worktree.c
index c99939a4d1f..9f8f3484ebd 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "repository.h"
 #include "refs.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 02/16] treewide: be explicit about dependence on gettext.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 03/16] treewide: remove unnecessary inclusion of gettext.h Elijah Newren via GitGitGadget
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Dozens of files made use of gettext functions, without explicitly
including gettext.h.  This made it more difficult to find which files
could remove a dependence on cache.h.  Make C files explicitly include
gettext.h if they are using it.

However, while compat/fsmonitor/fsm-ipc-darwin.c should also gain an
include of gettext.h, it was left out to avoid conflicting with an
in-flight topic.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                        | 1 +
 add-patch.c                              | 1 +
 apply.c                                  | 1 +
 archive-tar.c                            | 1 +
 archive-zip.c                            | 1 +
 archive.c                                | 1 +
 attr.c                                   | 1 +
 bisect.c                                 | 1 +
 blame.c                                  | 1 +
 branch.c                                 | 1 +
 builtin/add.c                            | 1 +
 builtin/am.c                             | 1 +
 builtin/apply.c                          | 1 +
 builtin/archive.c                        | 1 +
 builtin/bisect.c                         | 1 +
 builtin/blame.c                          | 1 +
 builtin/branch.c                         | 1 +
 builtin/bugreport.c                      | 1 +
 builtin/bundle.c                         | 1 +
 builtin/cat-file.c                       | 1 +
 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                          | 1 +
 builtin/clone.c                          | 1 +
 builtin/column.c                         | 1 +
 builtin/commit-graph.c                   | 1 +
 builtin/commit-tree.c                    | 1 +
 builtin/commit.c                         | 1 +
 builtin/config.c                         | 1 +
 builtin/count-objects.c                  | 1 +
 builtin/credential-cache--daemon.c       | 1 +
 builtin/credential-cache.c               | 1 +
 builtin/credential-store.c               | 1 +
 builtin/describe.c                       | 1 +
 builtin/diagnose.c                       | 1 +
 builtin/diff-tree.c                      | 1 +
 builtin/diff.c                           | 1 +
 builtin/difftool.c                       | 1 +
 builtin/fast-export.c                    | 1 +
 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                             | 1 +
 builtin/grep.c                           | 1 +
 builtin/hash-object.c                    | 1 +
 builtin/help.c                           | 1 +
 builtin/hook.c                           | 1 +
 builtin/index-pack.c                     | 1 +
 builtin/init-db.c                        | 1 +
 builtin/interpret-trailers.c             | 1 +
 builtin/log.c                            | 1 +
 builtin/ls-files.c                       | 1 +
 builtin/ls-remote.c                      | 1 +
 builtin/ls-tree.c                        | 1 +
 builtin/mailinfo.c                       | 1 +
 builtin/mailsplit.c                      | 1 +
 builtin/merge-base.c                     | 1 +
 builtin/merge-file.c                     | 1 +
 builtin/merge-recursive.c                | 1 +
 builtin/merge-tree.c                     | 1 +
 builtin/merge.c                          | 1 +
 builtin/mktag.c                          | 1 +
 builtin/mktree.c                         | 1 +
 builtin/multi-pack-index.c               | 1 +
 builtin/mv.c                             | 1 +
 builtin/name-rev.c                       | 1 +
 builtin/notes.c                          | 1 +
 builtin/pack-objects.c                   | 1 +
 builtin/pack-redundant.c                 | 1 +
 builtin/pack-refs.c                      | 1 +
 builtin/patch-id.c                       | 1 +
 builtin/prune-packed.c                   | 1 +
 builtin/prune.c                          | 1 +
 builtin/pull.c                           | 1 +
 builtin/push.c                           | 1 +
 builtin/range-diff.c                     | 1 +
 builtin/read-tree.c                      | 1 +
 builtin/rebase.c                         | 1 +
 builtin/receive-pack.c                   | 1 +
 builtin/reflog.c                         | 1 +
 builtin/remote.c                         | 1 +
 builtin/repack.c                         | 1 +
 builtin/replace.c                        | 1 +
 builtin/rerere.c                         | 1 +
 builtin/reset.c                          | 1 +
 builtin/rev-list.c                       | 1 +
 builtin/rev-parse.c                      | 1 +
 builtin/revert.c                         | 1 +
 builtin/rm.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                            | 1 +
 builtin/unpack-objects.c                 | 1 +
 builtin/update-index.c                   | 1 +
 builtin/update-ref.c                     | 1 +
 builtin/update-server-info.c             | 1 +
 builtin/upload-pack.c                    | 1 +
 builtin/verify-commit.c                  | 1 +
 builtin/verify-pack.c                    | 1 +
 builtin/verify-tag.c                     | 1 +
 builtin/worktree.c                       | 1 +
 builtin/write-tree.c                     | 1 +
 bulk-checkin.c                           | 1 +
 bundle-uri.c                             | 1 +
 bundle.c                                 | 1 +
 chunk-format.c                           | 1 +
 color.c                                  | 1 +
 commit-graph.c                           | 1 +
 commit.c                                 | 1 +
 common-main.c                            | 1 +
 compat/disk.h                            | 1 +
 compat/fsmonitor/fsm-health-win32.c      | 1 +
 compat/fsmonitor/fsm-listen-darwin.c     | 1 +
 compat/fsmonitor/fsm-listen-win32.c      | 1 +
 compat/fsmonitor/fsm-path-utils-darwin.c | 1 +
 compat/fsmonitor/fsm-path-utils-win32.c  | 1 +
 compat/mingw.c                           | 1 +
 compat/precompose_utf8.c                 | 1 +
 compat/simple-ipc/ipc-unix-socket.c      | 1 +
 compat/simple-ipc/ipc-win32.c            | 1 +
 compat/terminal.c                        | 1 +
 config.c                                 | 1 +
 connect.c                                | 1 +
 connected.c                              | 1 +
 convert.c                                | 1 +
 credential.c                             | 1 +
 date.c                                   | 1 +
 delta-islands.c                          | 1 +
 diagnose.c                               | 1 +
 diff-lib.c                               | 1 +
 diff-no-index.c                          | 1 +
 diff.c                                   | 1 +
 dir.c                                    | 1 +
 editor.c                                 | 1 +
 entry.c                                  | 1 +
 environment.c                            | 1 +
 exec-cmd.c                               | 1 +
 fetch-pack.c                             | 1 +
 fsmonitor-ipc.c                          | 1 +
 git.c                                    | 1 +
 gpg-interface.c                          | 1 +
 grep.c                                   | 1 +
 http-fetch.c                             | 1 +
 imap-send.c                              | 1 +
 list-objects-filter-options.h            | 1 +
 list-objects-filter.c                    | 1 +
 list-objects.c                           | 1 +
 lockfile.c                               | 1 +
 ls-refs.c                                | 1 +
 merge-ort-wrappers.c                     | 1 +
 merge-ort.c                              | 1 +
 merge-recursive.c                        | 1 +
 merge.c                                  | 1 +
 midx.c                                   | 1 +
 name-hash.c                              | 1 +
 notes-merge.c                            | 1 +
 notes-utils.c                            | 1 +
 object-file.c                            | 1 +
 object-name.c                            | 1 +
 object.c                                 | 1 +
 pack-bitmap-write.c                      | 1 +
 pack-bitmap.c                            | 1 +
 pack-mtimes.c                            | 1 +
 pack-revindex.c                          | 1 +
 pack-write.c                             | 1 +
 packfile.c                               | 1 +
 parallel-checkout.c                      | 1 +
 parse-options-cb.c                       | 1 +
 parse-options.c                          | 1 +
 parse-options.h                          | 2 ++
 path.c                                   | 1 +
 pathspec.c                               | 1 +
 pkt-line.c                               | 1 +
 preload-index.c                          | 1 +
 pretty.c                                 | 1 +
 promisor-remote.c                        | 1 +
 prune-packed.c                           | 1 +
 range-diff.c                             | 1 +
 reachable.c                              | 1 +
 read-cache.c                             | 1 +
 rebase-interactive.c                     | 1 +
 ref-filter.c                             | 1 +
 ref-filter.h                             | 1 +
 reflog.c                                 | 1 +
 refs.c                                   | 1 +
 refs/files-backend.c                     | 1 +
 refs/packed-backend.c                    | 1 +
 remote-curl.c                            | 1 +
 remote.c                                 | 1 +
 replace-object.c                         | 1 +
 rerere.c                                 | 1 +
 rerere.h                                 | 1 +
 reset.c                                  | 1 +
 revision.c                               | 1 +
 run-command.c                            | 1 +
 send-pack.c                              | 1 +
 sequencer.c                              | 1 +
 setup.c                                  | 1 +
 sideband.c                               | 1 +
 sparse-index.c                           | 1 +
 split-index.c                            | 1 +
 strbuf.c                                 | 1 +
 submodule-config.c                       | 1 +
 submodule.c                              | 1 +
 symlinks.c                               | 1 +
 t/helper/test-cache-tree.c               | 1 +
 t/helper/test-fast-rebase.c              | 1 +
 t/helper/test-reach.c                    | 1 +
 t/helper/test-serve-v2.c                 | 1 +
 trailer.c                                | 1 +
 transport-helper.c                       | 1 +
 tree-walk.c                              | 1 +
 unpack-trees.c                           | 1 +
 upload-pack.c                            | 1 +
 usage.c                                  | 2 +-
 walker.c                                 | 1 +
 worktree.c                               | 1 +
 wrapper.c                                | 1 +
 wt-status.c                              | 1 +
 235 files changed, 236 insertions(+), 1 deletion(-)

diff --git a/add-interactive.c b/add-interactive.c
index ae25ec50bce..b750543bd87 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -3,6 +3,7 @@
 #include "color.h"
 #include "config.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "refs.h"
diff --git a/add-patch.c b/add-patch.c
index c6e451c136c..7fe6b66d866 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "add-interactive.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/apply.c b/apply.c
index 8776ab939ad..e0bdd43a68e 100644
--- a/apply.c
+++ b/apply.c
@@ -15,6 +15,7 @@
 #include "delta.h"
 #include "diff.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "xdiff-interface.h"
 #include "ll-merge.h"
diff --git a/archive-tar.c b/archive-tar.c
index ee27fa0b39b..16ee133bbf5 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tar.h"
 #include "archive.h"
diff --git a/archive-zip.c b/archive-zip.c
index c5d1f72eb80..c02dc33e406 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "config.h"
 #include "archive.h"
+#include "gettext.h"
 #include "hex.h"
 #include "streaming.h"
 #include "utf8.h"
diff --git a/archive.c b/archive.c
index 1c2ca78e52a..2c3da1cff30 100644
--- a/archive.c
+++ b/archive.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/attr.c b/attr.c
index 657ee52229e..48e2d646187 100644
--- a/attr.c
+++ b/attr.c
@@ -12,6 +12,7 @@
 #include "exec-cmd.h"
 #include "attr.h"
 #include "dir.h"
+#include "gettext.h"
 #include "utf8.h"
 #include "quote.h"
 #include "revision.h"
diff --git a/bisect.c b/bisect.c
index 1409150c5c3..5a3a8182d83 100644
--- a/bisect.c
+++ b/bisect.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "refs.h"
diff --git a/blame.c b/blame.c
index e45d8a3bf92..b7cd849bb6b 100644
--- a/blame.c
+++ b/blame.c
@@ -5,6 +5,7 @@
 #include "mergesort.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "blame.h"
diff --git a/branch.c b/branch.c
index 5aaf073dce1..fced5342d5d 100644
--- a/branch.c
+++ b/branch.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "branch.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/add.c b/builtin/add.c
index 61dd386d109..f12054d9be1 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -9,6 +9,7 @@
 #include "builtin.h"
 #include "lockfile.h"
 #include "dir.h"
+#include "gettext.h"
 #include "pathspec.h"
 #include "exec-cmd.h"
 #include "cache-tree.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5e6b237c424..cc1fdf4f75d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "dir.h"
diff --git a/builtin/apply.c b/builtin/apply.c
index 555219de40f..fe72c0ec3eb 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "apply.h"
 
diff --git a/builtin/archive.c b/builtin/archive.c
index f094390ee01..e40e61b355c 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "archive.h"
+#include "gettext.h"
 #include "transport.h"
 #include "parse-options.h"
 #include "pkt-line.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index e8ee4a4dc8d..c2e614c2890 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "bisect.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index fdd9f0c0fc7..21f6b523a6d 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index f63fd45edb9..a67a8334d5c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -11,6 +11,7 @@
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "remote.h"
 #include "parse-options.h"
 #include "branch.h"
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 5bc254be80f..b61cfa9464f 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "strbuf.h"
 #include "help.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index acceef62001..4c5ac5e0849 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "strvec.h"
 #include "parse-options.h"
 #include "cache.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9e7e03ade41..9f1bf8f0e96 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "ident.h"
 #include "parse-options.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index d7a40e674ca..ad27255e2cb 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "attr.h"
+#include "gettext.h"
 #include "quote.h"
 #include "parse-options.h"
 
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index ab776061c7c..a45d001e353 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "quote.h"
 #include "pathspec.h"
 #include "parse-options.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index 96db3ddb4bb..fa86fd9423d 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "ident.h"
 #include "mailmap.h"
 #include "parse-options.h"
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index 0a7d762573c..2120dd1d300 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
+#include "gettext.h"
 #include "parallel-checkout.h"
 #include "parse-options.h"
 #include "pkt-line.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index cf6fba97ba7..828c0363f8a 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -8,6 +8,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 21a4335abb0..3c7ff60b923 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "diff.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "hook.h"
 #include "ll-merge.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 10aaa8c603f..46c51029ab4 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "quote.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 462c286274c..d605fcafa0f 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -11,6 +11,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/column.c b/builtin/column.c
index 158fdf53d9f..de623a16c2d 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index d3be7f3b318..311e0106810 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index e805da5bb1c..0ef55d83d49 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index f71ed41bf59..25575435ad7 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -16,6 +16,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "commit.h"
+#include "gettext.h"
 #include "revision.h"
 #include "wt-status.h"
 #include "run-command.h"
diff --git a/builtin/config.c b/builtin/config.c
index 49d832d4093..33b17b40b41 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "color.h"
+#include "gettext.h"
 #include "ident.h"
 #include "parse-options.h"
 #include "urlmatch.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index bb21bc43e42..48edc86c240 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "repository.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index 6e509d02c37..0f00ba4d741 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 #ifndef NO_UNIX_SOCKETS
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 78c02ad5319..25f2f71c216 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 #ifndef NO_UNIX_SOCKETS
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index 62a4f3c2653..da32cfd89e2 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "lockfile.h"
 #include "credential.h"
 #include "string-list.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 5b5930f5c8c..fcacdf8a693 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "commit.h"
diff --git a/builtin/diagnose.c b/builtin/diagnose.c
index d52015c67a4..5b12d1fb963 100644
--- a/builtin/diagnose.c
+++ b/builtin/diagnose.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "diagnose.h"
 
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index a393efa4f08..385c2d0230c 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "diff.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 26f1e532c66..20bdb6e6cec 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -11,6 +11,7 @@
 #include "color.h"
 #include "commit.h"
 #include "blob.h"
+#include "gettext.h"
 #include "tag.h"
 #include "diff.h"
 #include "diff-merges.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 01681d0fb88..f7380dd1cc7 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -17,6 +17,7 @@
 #include "builtin.h"
 #include "run-command.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "strvec.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 78493c6d2bf..9ab2e34ef05 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -6,6 +6,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index f7548ff4a35..f3635c7aefd 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 702c9a3397e..60e5a10ffc5 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pkt-line.h"
 #include "fetch-pack.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index bf627e04128..c266b6ab4dd 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 8d8fd393f89..0f9855b680e 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "fmt-merge-msg.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 static const char * const fmt_merge_msg_usage[] = {
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 6f62f40d126..7a8ff5902cf 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "object.h"
 #include "parse-options.h"
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 6aeac371488..27425c2fc9e 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "run-command.h"
 #include "string-list.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index c4a633c0329..1375e32d2a1 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index cae804a1908..215e3813d7d 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "fsmonitor.h"
 #include "fsmonitor-ipc.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index c58fe8c936c..32cabad7cf6 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -32,6 +32,7 @@
 #include "refs.h"
 #include "remote.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hook.h"
 
 #define FAILED_RUN "failed to run %s"
diff --git a/builtin/grep.c b/builtin/grep.c
index c590fcb19dd..3c9c6b38031 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 1848768b97c..f233eda7590 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -6,6 +6,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "blob.h"
diff --git a/builtin/help.c b/builtin/help.c
index 53f2812dfb1..3fde5c4fd35 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "run-command.h"
 #include "config-list.h"
diff --git a/builtin/hook.c b/builtin/hook.c
index f95b7965c58..88051795c7f 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hook.h"
 #include "parse-options.h"
 #include "strbuf.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b451755f405..bae5b054039 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "delta.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index dcaaf102eaf..e182bc7e839 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "builtin.h"
 #include "exec-cmd.h"
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
index e58627c72a9..107ac28f0e8 100644
--- a/builtin/interpret-trailers.c
+++ b/builtin/interpret-trailers.c
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "trailer.h"
diff --git a/builtin/log.c b/builtin/log.c
index b62e629ba88..7b107d254df 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -7,6 +7,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a03b559ecaa..09deb752ab3 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -11,6 +11,7 @@
 #include "quote.h"
 #include "dir.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "tree.h"
 #include "cache-tree.h"
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 2dfbd8ed9b9..11d9424804a 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "transport.h"
 #include "ref-filter.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 64d8e54318c..b4835f1d4cc 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "blob.h"
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 01d16ef9e5a..e8bb011cfb4 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -4,6 +4,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 73509f651bd..b08069ce60a 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -6,6 +6,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "strbuf.h"
 
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index be8f3b221c9..e0995f3219f 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index c923bbf2abb..ae45f523b95 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "parse-options.h"
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index b9acbf5d342..a49fab9bcb1 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "commit.h"
+#include "gettext.h"
 #include "tag.h"
 #include "merge-recursive.h"
 #include "xdiff-interface.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index e7825181648..89b807388a4 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -3,6 +3,7 @@
 #include "tree-walk.h"
 #include "xdiff-interface.h"
 #include "help.h"
+#include "gettext.h"
 #include "hex.h"
 #include "commit.h"
 #include "commit-reach.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 19c31d4ff48..a90ae5d2ddc 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "builtin.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 42c2457c705..e93aee72258 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "tag.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 848c7b47476..09a7bd5c5c2 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "quote.h"
 #include "tree.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 9a18a82b057..e6757a44470 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
 #include "trace2.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 81290503775..c02dddb72b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "pathspec.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 723ba616a88..6977a5f580b 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index 75ce7f3f574..8e9be33ddbb 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "notes.h"
 #include "object-store.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 545b8bddc8e..1ca800c7c50 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 82115c5808c..3451971b564 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -7,6 +7,7 @@
 */
 
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "packfile.h"
diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index 27c2ca06acb..9833815fb30 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "repository.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 338b15cd7b0..9d5585d3a72 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index da3273a268b..ca3578e1588 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "prune-packed.h"
 
diff --git a/builtin/prune.c b/builtin/prune.c
index 119a253a2ad..ff62a0adb8f 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "builtin.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 56f679d94a0..1a1a89af055 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
diff --git a/builtin/push.c b/builtin/push.c
index 12a402aea3d..2d76fa68376 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "branch.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "refspec.h"
 #include "run-command.h"
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index aecfae12d3a..97724fd0ed7 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "range-diff.h"
 #include "config.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 11759c415f3..ec66008d07e 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -7,6 +7,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "object.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index dd31d5ab91e..a2c68b8ff7b 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -6,6 +6,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
 #include "exec-cmd.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index fe68c79ee31..d1b6bd6eef4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "repository.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "pack.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 270681dcdf4..0879d4d2246 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 729f6f3643a..2074d6be28c 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 87f73c8923a..771ca01527d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 71d8e949e35..cf85e590d9f 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 94ffb8c21ab..24c78755723 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "rerere.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 58f567afd3e..6487cf694f5 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -10,6 +10,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tag.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 85e522dff8a..f2f6a0d3e67 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "list-objects.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index e1fa9c6348c..5a932a861b4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -8,6 +8,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 62986a7b1b0..dd6587a99d8 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -4,6 +4,7 @@
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
+#include "gettext.h"
 #include "revision.h"
 #include "rerere.h"
 #include "dir.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index dc198f79082..5982c3d8122 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -11,6 +11,7 @@
 #include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
+#include "gettext.h"
 #include "tree-walk.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 27a87167e19..d8c4379ea16 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "revision.h"
 #include "utf8.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 8342b68aef7..8d569629726 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pretty.h"
 #include "refs.h"
diff --git a/builtin/show-index.c b/builtin/show-index.c
index 98ec40ddf46..d4bbbbcd6ce 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pack.h"
 #include "parse-options.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 1f28d7fe4b9..a5df7587d51 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 8d5ae6f2a60..3976d8e86b8 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "pathspec.h"
 #include "repository.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 6a12fed2713..65817d0b763 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e34cf2bebd..d8e61459333 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "strbuf.h"
 
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index d05d1a84623..a4bdd44daa3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "cache.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index e00768a8b7e..10198a74fae 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "cache.h"
+#include "gettext.h"
 #include "refs.h"
 #include "parse-options.h"
 
diff --git a/builtin/tag.c b/builtin/tag.c
index 7cdcd4293d6..4f9047783a5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 1908dcfcffb..f7c4b531076 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "object.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 11dc1352716..ef78b2d28e1 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "quote.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index a84e7b47a20..fdf51495b51 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index d2239c9ef4d..e7bff27ae40 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 static const char * const update_server_info_usage[] = {
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index 7a3c68720f1..beb9dd08610 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "pkt-line.h"
 #include "parse-options.h"
 #include "protocol.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 7aedf10e856..22e5afc069e 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index 27d6f75fd8a..190fd695409 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
 
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5c00b0b0f77..850e1a11c7b 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 80d05e246d8..ed89b7e9725 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "strvec.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 7ad0d059453..7eec4e3cbd1 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index d64cd5c52d0..778ca1e0f4f 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "repository.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 177c1810402..2cc7d159bd6 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "bundle-uri.h"
 #include "bundle.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "refs.h"
 #include "run-command.h"
diff --git a/bundle.c b/bundle.c
index 99d7de97f6c..f5b3643b17e 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "lockfile.h"
 #include "bundle.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/chunk-format.c b/chunk-format.c
index f65e9a1e429..6d1071729df 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "chunk-format.h"
 #include "csum-file.h"
+#include "gettext.h"
 
 /*
  * When writing a chunk-based file format, collect the chunks in
diff --git a/color.c b/color.c
index 6b577ce0a75..672dcbb73a6 100644
--- a/color.c
+++ b/color.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "color.h"
+#include "gettext.h"
 #include "hex.h"
 
 static int git_use_color_default = GIT_COLOR_AUTO;
diff --git a/commit-graph.c b/commit-graph.c
index 5e6098ff356..8f21a0a0c20 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "pack.h"
diff --git a/commit.c b/commit.c
index 7b63d3b0e1c..3fdfb325117 100644
--- a/commit.c
+++ b/commit.c
@@ -2,6 +2,7 @@
 #include "tag.h"
 #include "commit.h"
 #include "commit-graph.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/common-main.c b/common-main.c
index 0a22861f1ce..184d1534d2d 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "attr.h"
 
 /*
diff --git a/compat/disk.h b/compat/disk.h
index 50a32e3d8a4..a04a8d294af 100644
--- a/compat/disk.h
+++ b/compat/disk.h
@@ -2,6 +2,7 @@
 #define COMPAT_DISK_H
 
 #include "git-compat-util.h"
+#include "gettext.h"
 
 static int get_disk_info(struct strbuf *out)
 {
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index 2ea08c1d4e8..fe11bdd9ce6 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -3,6 +3,7 @@
 #include "fsmonitor.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
+#include "gettext.h"
 
 /*
  * Every minute wake up and test our health.
diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 97a55a6f0a4..5eb6402ab82 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -28,6 +28,7 @@
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "fsmonitor-path-utils.h"
+#include "gettext.h"
 
 struct fsm_listen_data
 {
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 03df8d951b8..7b07b74ba5b 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -3,6 +3,7 @@
 #include "fsmonitor.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
+#include "gettext.h"
 
 /*
  * The documentation of ReadDirectoryChangesW() states that the maximum
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index ce5a8febe09..45eb4a9b9e7 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,5 +1,6 @@
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
+#include "gettext.h"
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c
index 0d95bbb416f..4024baafb97 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
+#include "gettext.h"
 
 /*
  * Check remote working directory protocol.
diff --git a/compat/mingw.c b/compat/mingw.c
index 3afbde78944..a9e5570288c 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -11,6 +11,7 @@
 #include "win32/lazyload.h"
 #include "../config.h"
 #include "dir.h"
+#include "gettext.h"
 #define SECURITY_WIN32
 #include <sspi.h>
 
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index cce1d57a464..56d36cdf22a 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
diff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c
index 28a79289d4f..152db60a311 100644
--- a/compat/simple-ipc/ipc-unix-socket.c
+++ b/compat/simple-ipc/ipc-unix-socket.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 20ea7b65e0b..f011e5cead8 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
diff --git a/compat/terminal.c b/compat/terminal.c
index ea490a7ced4..afebe6b2496 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "compat/terminal.h"
+#include "gettext.h"
 #include "sigchain.h"
 #include "strbuf.h"
 #include "run-command.h"
diff --git a/config.c b/config.c
index 983c45fc37b..f30a6d8e686 100644
--- a/config.c
+++ b/config.c
@@ -11,6 +11,7 @@
 #include "branch.h"
 #include "config.h"
 #include "environment.h"
+#include "gettext.h"
 #include "ident.h"
 #include "repository.h"
 #include "lockfile.h"
diff --git a/connect.c b/connect.c
index 134069574a2..1dab0d79c48 100644
--- a/connect.c
+++ b/connect.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pkt-line.h"
 #include "quote.h"
diff --git a/connected.c b/connected.c
index 39cb1e1074d..a4c0aece757 100644
--- a/connected.c
+++ b/connected.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "run-command.h"
diff --git a/convert.c b/convert.c
index 349c7e4af15..2bd54244b55 100644
--- a/convert.c
+++ b/convert.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/credential.c b/credential.c
index ea40a2a410b..5244f3c12c0 100644
--- a/credential.c
+++ b/credential.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "credential.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "url.h"
diff --git a/date.c b/date.c
index 6f45eeb3568..1fb2cd1b538 100644
--- a/date.c
+++ b/date.c
@@ -6,6 +6,7 @@
 
 #include "cache.h"
 #include "date.h"
+#include "gettext.h"
 
 /*
  * This is like mktime, but without normalization of tm_wday and tm_yday.
diff --git a/delta-islands.c b/delta-islands.c
index fe12c93005b..1222b6a6cd1 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -4,6 +4,7 @@
 #include "object.h"
 #include "blob.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "tree.h"
diff --git a/diagnose.c b/diagnose.c
index 5b398f0cffc..169a55407fd 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -4,6 +4,7 @@
 #include "archive.h"
 #include "dir.h"
 #include "help.h"
+#include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
 #include "object-store.h"
diff --git a/diff-lib.c b/diff-lib.c
index 70b3578b907..a7e04009873 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -6,6 +6,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "cache-tree.h"
diff --git a/diff-no-index.c b/diff-no-index.c
index a3cf358baf0..287a113badd 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -11,6 +11,7 @@
 #include "tag.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "parse-options.h"
diff --git a/diff.c b/diff.c
index 00d47281a1d..00746f2f86e 100644
--- a/diff.c
+++ b/diff.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "tempfile.h"
 #include "quote.h"
 #include "diff.h"
diff --git a/dir.c b/dir.c
index d5bb199f4b4..46f1bb6e5b7 100644
--- a/dir.c
+++ b/dir.c
@@ -9,6 +9,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "attr.h"
 #include "refs.h"
diff --git a/editor.c b/editor.c
index 008c04fe2f6..58e790548d2 100644
--- a/editor.c
+++ b/editor.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "strvec.h"
 #include "run-command.h"
diff --git a/entry.c b/entry.c
index c97cfa833bb..acb76a61aca 100644
--- a/entry.c
+++ b/entry.c
@@ -2,6 +2,7 @@
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "streaming.h"
 #include "submodule.h"
diff --git a/environment.c b/environment.c
index 89d89110e41..82a1fc17d0b 100644
--- a/environment.c
+++ b/environment.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "branch.h"
 #include "environment.h"
+#include "gettext.h"
 #include "repository.h"
 #include "config.h"
 #include "refs.h"
diff --git a/exec-cmd.c b/exec-cmd.c
index 0232bbc9905..282d95af081 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "quote.h"
 #include "strvec.h"
 
diff --git a/fetch-pack.c b/fetch-pack.c
index 4ddabb4ec76..359dce6afed 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "refs.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 19d772f0f3a..866828e2992 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "fsmonitor.h"
+#include "gettext.h"
 #include "simple-ipc.h"
 #include "fsmonitor-ipc.h"
 #include "run-command.h"
diff --git a/git.c b/git.c
index ae2134f29a8..22ce4f14b65 100644
--- a/git.c
+++ b/git.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "help.h"
 #include "run-command.h"
 #include "alias.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index 855970bb939..632265691e5 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "config.h"
+#include "gettext.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "dir.h"
diff --git a/grep.c b/grep.c
index 68e9328dfd4..febb076a7e6 100644
--- a/grep.c
+++ b/grep.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "grep.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/http-fetch.c b/http-fetch.c
index 8db35b9767d..454933351b2 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hex.h"
 #include "http.h"
 #include "walker.h"
diff --git a/imap-send.c b/imap-send.c
index 93e9018439c..c65a27219c6 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "credential.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
 #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index ef03b45132e..65c6119e9d3 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -1,6 +1,7 @@
 #ifndef LIST_OBJECTS_FILTER_OPTIONS_H
 #define LIST_OBJECTS_FILTER_OPTIONS_H
 
+#include "gettext.h"
 #include "object.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 5d7b3316608..298ca08711e 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "commit.h"
diff --git a/list-objects.c b/list-objects.c
index ab5745bbfe4..3906ac442dd 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tag.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/lockfile.c b/lockfile.c
index cc9a4b84283..ab6490a391d 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "gettext.h"
 #include "lockfile.h"
 
 /*
diff --git a/ls-refs.c b/ls-refs.c
index 8091b0cca8c..ae38889bf04 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index 748924a69ba..c00dfbab1cd 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 
diff --git a/merge-ort.c b/merge-ort.c
index 4c5be8ed910..a26cad5f910 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -26,6 +26,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "entry.h"
 #include "ll-merge.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 89731f40908..0b0255ebc80 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -17,6 +17,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "ll-merge.h"
 #include "lockfile.h"
diff --git a/merge.c b/merge.c
index 2c8b8456842..da7fa652c27 100644
--- a/merge.c
+++ b/merge.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "commit.h"
diff --git a/midx.c b/midx.c
index 47989f7ea70..e132ef250e4 100644
--- a/midx.c
+++ b/midx.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "csum-file.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "packfile.h"
diff --git a/name-hash.c b/name-hash.c
index cd009c7c8ae..bb9eae55aca 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2008 Linus Torvalds
  */
 #include "cache.h"
+#include "gettext.h"
 #include "thread-utils.h"
 #include "trace2.h"
 #include "sparse-index.h"
diff --git a/notes-merge.c b/notes-merge.c
index 5b1a9ff13f7..c8d0020b1a2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "gettext.h"
 #include "refs.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/notes-utils.c b/notes-utils.c
index d7d18e30f5a..da08e2e8e5c 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "refs.h"
 #include "notes-utils.h"
 #include "repository.h"
diff --git a/object-file.c b/object-file.c
index 8fab8dbe80b..39660d49dbc 100644
--- a/object-file.c
+++ b/object-file.c
@@ -9,6 +9,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "string-list.h"
 #include "lockfile.h"
diff --git a/object-name.c b/object-name.c
index 69db1ec498a..2c927bbded3 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "commit.h"
diff --git a/object.c b/object.c
index 609fed1b73d..45c9721b8c8 100644
--- a/object.c
+++ b/object.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object.h"
 #include "replace-object.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 891d9d2772e..7dc7f0ba55e 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "commit.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ca7c81b5c9f..241ac9166c1 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "strbuf.h"
 #include "tag.h"
diff --git a/pack-mtimes.c b/pack-mtimes.c
index cd92fc1d86c..afed6321906 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "pack-mtimes.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index 08dc1601679..03c7e81f9da 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "pack-revindex.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/pack-write.c b/pack-write.c
index 041e573bc16..87156f89d2b 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/packfile.c b/packfile.c
index fc2d7c2190a..b1718b93d4b 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "list.h"
 #include "pack.h"
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 2455aa356db..38c4dc665d5 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parallel-checkout.h"
 #include "pkt-line.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index d346dbe2100..fbf4b010195 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "color.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "strvec.h"
 #include "oid-array.h"
diff --git a/parse-options.c b/parse-options.c
index fd4743293fc..815c392aaec 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "commit.h"
 #include "color.h"
+#include "gettext.h"
 #include "utf8.h"
 
 static int disallow_abbreviated_options;
diff --git a/parse-options.h b/parse-options.h
index 50d852f2991..d57868eff93 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -1,6 +1,8 @@
 #ifndef PARSE_OPTIONS_H
 #define PARSE_OPTIONS_H
 
+#include "gettext.h"
+
 /**
  * Refer to Documentation/technical/api-parse-options.txt for the API doc.
  */
diff --git a/path.c b/path.c
index 632a051809a..3f2702cbe49 100644
--- a/path.c
+++ b/path.c
@@ -2,6 +2,7 @@
  * Utilities for paths and pathnames
  */
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "strbuf.h"
diff --git a/pathspec.c b/pathspec.c
index ab70fcbe613..868b4d280ca 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
 #include "strvec.h"
diff --git a/pkt-line.c b/pkt-line.c
index 1ea7f8600ec..c8b90b2242e 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pkt-line.h"
+#include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
 
diff --git a/preload-index.c b/preload-index.c
index 100f7a374dc..4b45e1d6912 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -5,6 +5,7 @@
 #include "pathspec.h"
 #include "dir.h"
 #include "fsmonitor.h"
+#include "gettext.h"
 #include "config.h"
 #include "progress.h"
 #include "thread-utils.h"
diff --git a/pretty.c b/pretty.c
index 05b557d0961..9d7922dcc60 100644
--- a/pretty.c
+++ b/pretty.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 1db566982ec..a8dbb788e8f 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "promisor-remote.h"
diff --git a/prune-packed.c b/prune-packed.c
index e02f466c2ee..cff5ad569c7 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "packfile.h"
 #include "progress.h"
diff --git a/range-diff.c b/range-diff.c
index 4bd65ab7496..1bfc612e274 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "range-diff.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/reachable.c b/reachable.c
index c9dab2a66b9..b0f85046e9c 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "tag.h"
diff --git a/read-cache.c b/read-cache.c
index 1bcf6732718..63789ea5e21 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -18,6 +18,7 @@
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
+#include "gettext.h"
 #include "resolve-undo.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 7407c593191..649c94e69a6 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "gettext.h"
 #include "sequencer.h"
 #include "rebase-interactive.h"
 #include "strbuf.h"
diff --git a/ref-filter.c b/ref-filter.c
index 38141bce8db..9a830bedef0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/ref-filter.h b/ref-filter.h
index aa0eea4ecf5..cc811c2cadd 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -1,6 +1,7 @@
 #ifndef REF_FILTER_H
 #define REF_FILTER_H
 
+#include "gettext.h"
 #include "oid-array.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/reflog.c b/reflog.c
index 04630f56ec6..d1c39374318 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "reflog.h"
 #include "refs.h"
diff --git a/refs.c b/refs.c
index 4e5cc73fb10..8684f4610f5 100644
--- a/refs.c
+++ b/refs.c
@@ -6,6 +6,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "hashmap.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "iterator.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 31bc5c45ee6..de3628ff3f1 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,5 +1,6 @@
 #include "../cache.h"
 #include "../config.h"
+#include "../gettext.h"
 #include "../hex.h"
 #include "../refs.h"
 #include "refs-internal.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 6f975185995..3334c07003c 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,6 +1,7 @@
 #include "../cache.h"
 #include "../alloc.h"
 #include "../config.h"
+#include "../gettext.h"
 #include "../hex.h"
 #include "../refs.h"
 #include "refs-internal.h"
diff --git a/remote-curl.c b/remote-curl.c
index ed7e3a043ac..943cd6fe6cd 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "remote.h"
 #include "connect.h"
diff --git a/remote.c b/remote.c
index 2daddb85cb7..edb1e07497c 100644
--- a/remote.c
+++ b/remote.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "remote.h"
 #include "urlmatch.h"
diff --git a/replace-object.c b/replace-object.c
index 0cf056c4fbf..9e30e0362ba 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
 #include "object-store.h"
diff --git a/rerere.c b/rerere.c
index a67abaab077..9428cbca7b2 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "string-list.h"
diff --git a/rerere.h b/rerere.h
index c32d79c3bd8..7899dc21747 100644
--- a/rerere.h
+++ b/rerere.h
@@ -1,6 +1,7 @@
 #ifndef RERERE_H
 #define RERERE_H
 
+#include "gettext.h"
 #include "string-list.h"
 
 struct pathspec;
diff --git a/reset.c b/reset.c
index 58b3829ff73..604d9325b78 100644
--- a/reset.c
+++ b/reset.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache-tree.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "refs.h"
diff --git a/revision.c b/revision.c
index e4c066e90b7..7423e23327b 100644
--- a/revision.c
+++ b/revision.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "tag.h"
diff --git a/run-command.c b/run-command.c
index ba617655b23..2c8b4cd9bfc 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "sigchain.h"
 #include "strvec.h"
 #include "thread-utils.h"
diff --git a/send-pack.c b/send-pack.c
index 423a5cfe22d..f531cb48212 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/sequencer.c b/sequencer.c
index fb99115be5b..bc7e72d5fef 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/setup.c b/setup.c
index cefd5f63c46..8a4ccee4c2c 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
diff --git a/sideband.c b/sideband.c
index 85bddfdcd4f..4905cf9b32a 100644
--- a/sideband.c
+++ b/sideband.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "color.h"
 #include "config.h"
+#include "gettext.h"
 #include "sideband.h"
 #include "help.h"
 #include "pkt-line.h"
diff --git a/sparse-index.c b/sparse-index.c
index 63216b3e57f..fdae9011b8e 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
diff --git a/split-index.c b/split-index.c
index 95ecfa53195..c98807c655b 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
 
diff --git a/strbuf.c b/strbuf.c
index 8800830ebf8..15209777d5a 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/submodule-config.c b/submodule-config.c
index 89a7bf0a93d..38663801aa4 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/submodule.c b/submodule.c
index 0baf97cf770..8b551e53274 100644
--- a/submodule.c
+++ b/submodule.c
@@ -7,6 +7,7 @@
 #include "dir.h"
 #include "diff.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/symlinks.c b/symlinks.c
index c667baa949b..c35c8d4408d 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 
 static int threaded_check_leading_path(struct cache_def *cache, const char *name,
 				       int len, int warn_on_lstat_err);
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 615e648e555..8b7a8fce1ee 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 1e975df9041..68bbc41b330 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -15,6 +15,7 @@
 #include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 05d56267a9f..09c711038ce 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -4,6 +4,7 @@
 #include "commit.h"
 #include "commit-reach.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "ref-filter.h"
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 824e5c0a958..497d72058de 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "serve.h"
 
diff --git a/trailer.c b/trailer.c
index 72c3fed5c6e..9eb1b761190 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
diff --git a/transport-helper.c b/transport-helper.c
index 82ac63e2609..105bb801c21 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -4,6 +4,7 @@
 #include "run-command.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "remote.h"
diff --git a/tree-walk.c b/tree-walk.c
index 0e2f5ceb71d..38b6556478d 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "alloc.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index a75fb9f05b4..84e0d2e8afe 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index 41b9362cf1b..eea9e6a6e8c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/usage.c b/usage.c
index 5a7c6c346c1..40a1c5a4339 100644
--- a/usage.c
+++ b/usage.c
@@ -3,8 +3,8 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "git-compat-util.h"
 #include "cache.h"
+#include "gettext.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
 {
diff --git a/walker.c b/walker.c
index c0469363789..b642fd2c3bc 100644
--- a/walker.c
+++ b/walker.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "walker.h"
 #include "repository.h"
diff --git a/worktree.c b/worktree.c
index 9f8f3484ebd..530dd5fbc44 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "repository.h"
 #include "refs.h"
 #include "strbuf.h"
diff --git a/wrapper.c b/wrapper.c
index 299d6489a6b..0d4ceba6fc5 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 
 static intmax_t count_fsync_writeout_only;
 static intmax_t count_fsync_hardware_flush;
diff --git a/wt-status.c b/wt-status.c
index 90525bd26fd..d15f2b0e7e8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -4,6 +4,7 @@
 #include "dir.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "diffcore.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 03/16] treewide: remove unnecessary inclusion of gettext.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 02/16] treewide: be explicit about dependence on gettext.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 04/16] treewide: remove unnecessary cache.h inclusion from several sources Elijah Newren via GitGitGadget
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Looking at things from the opposite angle of the last patch, we had a
few files that were including gettext.h and perhaps needed it at some
point in history, but no longer require it.  Remove the include.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 progress.c                          | 1 -
 t/helper/test-parse-pathspec-file.c | 1 -
 t/helper/test-progress.c            | 1 -
 t/helper/test-run-command.c         | 1 -
 4 files changed, 4 deletions(-)

diff --git a/progress.c b/progress.c
index 9b33a2df325..44c784d75f1 100644
--- a/progress.c
+++ b/progress.c
@@ -10,7 +10,6 @@
 
 #define GIT_TEST_PROGRESS_ONLY
 #include "cache.h"
-#include "gettext.h"
 #include "progress.h"
 #include "strbuf.h"
 #include "trace.h"
diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c
index b3e08cef4b3..b704690d845 100644
--- a/t/helper/test-parse-pathspec-file.c
+++ b/t/helper/test-parse-pathspec-file.c
@@ -1,7 +1,6 @@
 #include "test-tool.h"
 #include "parse-options.h"
 #include "pathspec.h"
-#include "gettext.h"
 
 int cmd__parse_pathspec_file(int argc, const char **argv)
 {
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 6cc9735b601..66acb6a06c9 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -19,7 +19,6 @@
  */
 #define GIT_TEST_PROGRESS_ONLY
 #include "test-tool.h"
-#include "gettext.h"
 #include "parse-options.h"
 #include "progress.h"
 #include "strbuf.h"
diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c
index b0d041ec5ff..c0ed8722c87 100644
--- a/t/helper/test-run-command.c
+++ b/t/helper/test-run-command.c
@@ -16,7 +16,6 @@
 #include "string-list.h"
 #include "thread-utils.h"
 #include "wildmatch.h"
-#include "gettext.h"
 
 static int number_callbacks;
 static int parallel_next(struct child_process *cp,
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 04/16] treewide: remove unnecessary cache.h inclusion from several sources
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (2 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 03/16] treewide: remove unnecessary inclusion of gettext.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 05/16] environment: move comment_line_char from cache.h Elijah Newren via GitGitGadget
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

A number of files were apparently including cache.h solely to get
gettext.h.  By making those files explicitly include gettext.h, we can
already drop the include of cache.h in these files.  Remove those now
unnecessary includes.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 compat/linux/procinfo.c        | 2 +-
 compat/simple-ipc/ipc-shared.c | 2 +-
 connected.c                    | 2 +-
 grep.c                         | 2 +-
 negotiator/default.c           | 2 +-
 negotiator/skipping.c          | 2 +-
 notes-cache.c                  | 2 +-
 patch-ids.c                    | 2 +-
 reflog.c                       | 2 +-
 refs/iterator.c                | 2 +-
 replace-object.c               | 2 +-
 t/helper/test-hash.c           | 1 -
 xdiff-interface.c              | 2 +-
 13 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/compat/linux/procinfo.c b/compat/linux/procinfo.c
index bc2f9382a17..4bb2d66227b 100644
--- a/compat/linux/procinfo.c
+++ b/compat/linux/procinfo.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 
 #include "strbuf.h"
 #include "strvec.h"
diff --git a/compat/simple-ipc/ipc-shared.c b/compat/simple-ipc/ipc-shared.c
index 1b9d359ab68..e5e1dda8ccd 100644
--- a/compat/simple-ipc/ipc-shared.c
+++ b/compat/simple-ipc/ipc-shared.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
diff --git a/connected.c b/connected.c
index a4c0aece757..669bc4e8d69 100644
--- a/connected.c
+++ b/connected.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/grep.c b/grep.c
index febb076a7e6..bb8796a829f 100644
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "gettext.h"
 #include "grep.h"
diff --git a/negotiator/default.c b/negotiator/default.c
index b7e79feaf04..5dd553a1fe3 100644
--- a/negotiator/default.c
+++ b/negotiator/default.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "default.h"
 #include "../commit.h"
 #include "../fetch-negotiator.h"
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index 264acf8bbea..4157c4d72f5 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "skipping.h"
 #include "../commit.h"
 #include "../fetch-negotiator.h"
diff --git a/notes-cache.c b/notes-cache.c
index 9dfd251a815..01a918c925e 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "notes-cache.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/patch-ids.c b/patch-ids.c
index a4473a88fa2..19af7bee984 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "commit.h"
 #include "hash-lookup.h"
diff --git a/reflog.c b/reflog.c
index d1c39374318..4e121e449d1 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "reflog.h"
diff --git a/refs/iterator.c b/refs/iterator.c
index c9fd0bcaf90..6b680f610ef 100644
--- a/refs/iterator.c
+++ b/refs/iterator.c
@@ -3,7 +3,7 @@
  * documentation about the design and use of reference iterators.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "refs.h"
 #include "refs/refs-internal.h"
 #include "iterator.h"
diff --git a/replace-object.c b/replace-object.c
index 9e30e0362ba..e98825d5852 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
index 016248106a7..45d829c908f 100644
--- a/t/helper/test-hash.c
+++ b/t/helper/test-hash.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 
 int cmd_hash_impl(int ac, const char **av, int algo)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 5baf6ceb947..356356afe71 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "hex.h"
 #include "object-store.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 05/16] environment: move comment_line_char from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (3 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 04/16] treewide: remove unnecessary cache.h inclusion from several sources Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 06/16] abspath.h: move absolute path functions " Elijah Newren via GitGitGadget
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This is one step towards making strbuf.c not depend upon cache.h.
Additional steps will follow in subsequent commits.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-patch.c      | 1 +
 builtin/branch.c | 1 +
 builtin/commit.c | 1 +
 builtin/merge.c  | 1 +
 builtin/tag.c    | 1 +
 cache.h          | 7 -------
 commit.c         | 1 +
 environment.h    | 7 +++++++
 fmt-merge-msg.c  | 1 +
 sequencer.c      | 1 +
 strbuf.c         | 1 +
 trailer.c        | 1 +
 wt-status.c      | 1 +
 13 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/add-patch.c b/add-patch.c
index 7fe6b66d866..780fb30607b 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "add-interactive.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "strbuf.h"
 #include "run-command.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index a67a8334d5c..56dbee97d20 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "color.h"
+#include "environment.h"
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 25575435ad7..42bf20f589c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -12,6 +12,7 @@
 #include "cache-tree.h"
 #include "color.h"
 #include "dir.h"
+#include "environment.h"
 #include "builtin.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index a90ae5d2ddc..2c9da4b23d1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4f9047783a5..78b3e44e993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/cache.h b/cache.h
index 0221bc6d5c9..4b4c2e17557 100644
--- a/cache.h
+++ b/cache.h
@@ -956,13 +956,6 @@ extern int sparse_expect_files_outside_of_patterns;
  */
 int use_optional_locks(void);
 
-/*
- * The character that begins a commented line in user-editable file
- * that is subject to stripspace.
- */
-extern char comment_line_char;
-extern int auto_comment_line_char;
-
 enum log_refs_config {
 	LOG_REFS_UNSET = -1,
 	LOG_REFS_NONE = 0,
diff --git a/commit.c b/commit.c
index 3fdfb325117..f88fc5e1a2c 100644
--- a/commit.c
+++ b/commit.c
@@ -2,6 +2,7 @@
 #include "tag.h"
 #include "commit.h"
 #include "commit-graph.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/environment.h b/environment.h
index d438b5c8f3a..a26931556af 100644
--- a/environment.h
+++ b/environment.h
@@ -3,6 +3,13 @@
 
 #include "strvec.h"
 
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+extern char comment_line_char;
+extern int auto_comment_line_char;
+
 /*
  * Wrapper of getenv() that returns a strdup value. This value is kept
  * in argv to be freed later.
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index c870cb95b9d..bc4e61c5b1a 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "refs.h"
 #include "object-store.h"
 #include "diff.h"
diff --git a/sequencer.c b/sequencer.c
index bc7e72d5fef..0fe00b0bcec 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/strbuf.c b/strbuf.c
index 15209777d5a..b9cd593b147 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/trailer.c b/trailer.c
index 9eb1b761190..6a5091a3c46 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/wt-status.c b/wt-status.c
index d15f2b0e7e8..106e46480a1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -4,6 +4,7 @@
 #include "dir.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 06/16] abspath.h: move absolute path functions from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (4 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 05/16] environment: move comment_line_char from cache.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 07/16] cache.h: remove expand_user_path() Elijah Newren via GitGitGadget
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This is another step towards letting us remove the include of cache.h in
strbuf.c.  It does mean that we also need to add includes of abspath.h
in a number of C files.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 abspath.c                          |  4 +++-
 abspath.h                          | 30 ++++++++++++++++++++++++++++++
 apply.c                            |  1 +
 archive.c                          |  1 +
 builtin/am.c                       |  1 +
 builtin/bugreport.c                |  1 +
 builtin/bundle.c                   |  1 +
 builtin/clean.c                    |  1 +
 builtin/clone.c                    |  1 +
 builtin/config.c                   |  1 +
 builtin/credential-cache--daemon.c |  1 +
 builtin/diagnose.c                 |  1 +
 builtin/difftool.c                 |  1 +
 builtin/fast-import.c              |  1 +
 builtin/fsmonitor--daemon.c        |  1 +
 builtin/gc.c                       |  1 +
 builtin/hash-object.c              |  1 +
 builtin/init-db.c                  |  1 +
 builtin/log.c                      |  1 +
 builtin/mailinfo.c                 |  1 +
 builtin/merge-file.c               |  1 +
 builtin/merge.c                    |  1 +
 builtin/multi-pack-index.c         |  1 +
 builtin/mv.c                       |  1 +
 builtin/rebase.c                   |  1 +
 builtin/receive-pack.c             |  1 +
 builtin/rev-parse.c                |  1 +
 builtin/stash.c                    |  1 +
 builtin/submodule--helper.c        |  1 +
 builtin/worktree.c                 |  1 +
 cache.h                            | 24 ------------------------
 chdir-notify.c                     |  1 +
 compat/disk.h                      |  1 +
 compat/mingw.c                     |  1 +
 compat/simple-ipc/ipc-win32.c      |  1 +
 config.c                           |  1 +
 credential.c                       |  1 +
 daemon.c                           |  1 +
 diff-no-index.c                    |  1 +
 diff.c                             |  1 +
 dir.c                              |  1 +
 editor.c                           |  1 +
 environment.c                      |  1 +
 exec-cmd.c                         |  1 +
 gettext.c                          |  1 +
 lockfile.c                         |  1 +
 midx.c                             |  1 +
 object-file.c                      |  1 +
 parse-options.c                    |  1 +
 path.c                             |  1 +
 pathspec.c                         |  1 +
 remote.c                           |  1 +
 repository.c                       |  1 +
 rerere.c                           |  1 +
 scalar.c                           |  1 +
 sequencer.c                        |  1 +
 setup.c                            |  1 +
 strbuf.c                           |  1 +
 submodule.c                        |  1 +
 t/helper/test-path-utils.c         |  1 +
 tmp-objdir.c                       |  1 +
 trace.c                            |  1 +
 trace2/tr2_dst.c                   |  1 +
 worktree.c                         |  1 +
 wrapper.c                          |  1 +
 65 files changed, 95 insertions(+), 25 deletions(-)
 create mode 100644 abspath.h

diff --git a/abspath.c b/abspath.c
index 39e06b58486..f72f332e5aa 100644
--- a/abspath.c
+++ b/abspath.c
@@ -1,4 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "abspath.h"
+#include "strbuf.h"
 
 /*
  * Do not use this for inspecting *tracked* content.  When path is a
diff --git a/abspath.h b/abspath.h
new file mode 100644
index 00000000000..118546db5f8
--- /dev/null
+++ b/abspath.h
@@ -0,0 +1,30 @@
+#ifndef ABSPATH_H
+#define ABSPATH_H
+
+int is_directory(const char *);
+char *strbuf_realpath(struct strbuf *resolved, const char *path,
+		      int die_on_error);
+char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path,
+				int die_on_error);
+char *real_pathdup(const char *path, int die_on_error);
+const char *absolute_path(const char *path);
+char *absolute_pathdup(const char *path);
+
+/*
+ * Concatenate "prefix" (if len is non-zero) and "path", with no
+ * connecting characters (so "prefix" should end with a "/").
+ * Unlike prefix_path, this should be used if the named file does
+ * not have to interact with index entry; i.e. name of a random file
+ * on the filesystem.
+ *
+ * The return value is always a newly allocated string (even if the
+ * prefix was empty).
+ */
+char *prefix_filename(const char *prefix, const char *path);
+
+static inline int is_absolute_path(const char *path)
+{
+	return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
+}
+
+#endif /* ABSPATH_H */
diff --git a/apply.c b/apply.c
index e0bdd43a68e..e5e11b85793 100644
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "object-store.h"
diff --git a/archive.c b/archive.c
index 2c3da1cff30..c3c45a5ebe9 100644
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/am.c b/builtin/am.c
index cc1fdf4f75d..14347ecf9aa 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -5,6 +5,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "builtin.h"
 #include "exec-cmd.h"
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index b61cfa9464f..b5dfad4e12a 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "strbuf.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 4c5ac5e0849..8ea1232dbce 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "strvec.h"
 #include "parse-options.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 46c51029ab4..fdcf62c5dfe 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index d605fcafa0f..b94324ea02c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -10,6 +10,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/config.c b/builtin/config.c
index 33b17b40b41..42e6b8d3481 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "color.h"
diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index 0f00ba4d741..62c09a271d6 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/diagnose.c b/builtin/diagnose.c
index 5b12d1fb963..0f8b64994c4 100644
--- a/builtin/diagnose.c
+++ b/builtin/diagnose.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "diagnose.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index f7380dd1cc7..ed06db12085 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -13,6 +13,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "builtin.h"
 #include "run-command.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index f3635c7aefd..7307c4657f2 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 215e3813d7d..4efb1417344 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 32cabad7cf6..ef063fc828c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "abspath.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index f233eda7590..7651a7a5f56 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -5,6 +5,7 @@
  * Copyright (C) Junio C Hamano, 2005
  */
 #include "builtin.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index e182bc7e839..6f724f694f4 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "refs.h"
diff --git a/builtin/log.c b/builtin/log.c
index 7b107d254df..639d8e90951 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
  *		 2006 Junio Hamano
  */
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index e8bb011cfb4..e14f7c0abce 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -3,6 +3,7 @@
  * email to figure out authorship and subject
  */
 #include "cache.h"
+#include "abspath.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "utf8.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index ae45f523b95..c0096ee0810 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 2c9da4b23d1..38243e55c5f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -8,6 +8,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index e6757a44470..579bc2cac0c 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index c02dddb72b5..0a49bf21b0f 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -5,6 +5,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index a2c68b8ff7b..a3f8be88882 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -6,6 +6,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index d1b6bd6eef4..5fab0aed533 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "repository.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 5a932a861b4..a4c0878bc91 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -5,6 +5,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 65817d0b763..52fa892f7eb 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1,5 +1,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a4bdd44daa3..ff1fd8c87ab 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index ed89b7e9725..ed614ffddcb 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "checkout.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/cache.h b/cache.h
index 4b4c2e17557..260203c7a62 100644
--- a/cache.h
+++ b/cache.h
@@ -598,18 +598,6 @@ const char *setup_git_directory(void);
 char *prefix_path(const char *prefix, int len, const char *path);
 char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
 
-/*
- * Concatenate "prefix" (if len is non-zero) and "path", with no
- * connecting characters (so "prefix" should end with a "/").
- * Unlike prefix_path, this should be used if the named file does
- * not have to interact with index entry; i.e. name of a random file
- * on the filesystem.
- *
- * The return value is always a newly allocated string (even if the
- * prefix was empty).
- */
-char *prefix_filename(const char *prefix, const char *path);
-
 int check_filename(const char *prefix, const char *name);
 void verify_filename(const char *prefix,
 		     const char *name,
@@ -1157,18 +1145,6 @@ char *interpolate_path(const char *path, int real_home);
 /* NEEDSWORK: remove this synonym once in-flight topics have migrated */
 #define expand_user_path interpolate_path
 const char *enter_repo(const char *path, int strict);
-static inline int is_absolute_path(const char *path)
-{
-	return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
-}
-int is_directory(const char *);
-char *strbuf_realpath(struct strbuf *resolved, const char *path,
-		      int die_on_error);
-char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path,
-				int die_on_error);
-char *real_pathdup(const char *path, int die_on_error);
-const char *absolute_path(const char *path);
-char *absolute_pathdup(const char *path);
 const char *remove_leading_path(const char *in, const char *prefix);
 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
diff --git a/chdir-notify.c b/chdir-notify.c
index 5f7f2c2ac23..929ec01b3a2 100644
--- a/chdir-notify.c
+++ b/chdir-notify.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "chdir-notify.h"
 #include "list.h"
 #include "strbuf.h"
diff --git a/compat/disk.h b/compat/disk.h
index a04a8d294af..6c979c27d89 100644
--- a/compat/disk.h
+++ b/compat/disk.h
@@ -2,6 +2,7 @@
 #define COMPAT_DISK_H
 
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "gettext.h"
 
 static int get_disk_info(struct strbuf *out)
diff --git a/compat/mingw.c b/compat/mingw.c
index a9e5570288c..cbcd03aea9b 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -7,6 +7,7 @@
 #include "../strbuf.h"
 #include "../run-command.h"
 #include "../cache.h"
+#include "../abspath.h"
 #include "../alloc.h"
 #include "win32/lazyload.h"
 #include "../config.h"
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index f011e5cead8..997f6144344 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
diff --git a/config.c b/config.c
index f30a6d8e686..6815919ec30 100644
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "date.h"
 #include "branch.h"
diff --git a/credential.c b/credential.c
index 5244f3c12c0..e6417bf8804 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "credential.h"
 #include "gettext.h"
diff --git a/daemon.c b/daemon.c
index 8908e7f8d2a..bb795ca3ca9 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "pkt-line.h"
diff --git a/diff-no-index.c b/diff-no-index.c
index 287a113badd..934a24bee58 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "color.h"
 #include "commit.h"
 #include "blob.h"
diff --git a/diff.c b/diff.c
index 00746f2f86e..1b0be99c065 100644
--- a/diff.c
+++ b/diff.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2005 Junio C Hamano
  */
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/dir.c b/dir.c
index 46f1bb6e5b7..c72481c60ee 100644
--- a/dir.c
+++ b/dir.c
@@ -6,6 +6,7 @@
  *		 Junio Hamano, 2005-2006
  */
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
diff --git a/editor.c b/editor.c
index 58e790548d2..2d3e6be64e4 100644
--- a/editor.c
+++ b/editor.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/environment.c b/environment.c
index 82a1fc17d0b..c69571f0b29 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "abspath.h"
 #include "branch.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/exec-cmd.c b/exec-cmd.c
index 282d95af081..042d9247a5b 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "quote.h"
diff --git a/gettext.c b/gettext.c
index f139008d0a3..3e7b3baabc6 100644
--- a/gettext.c
+++ b/gettext.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/lockfile.c b/lockfile.c
index ab6490a391d..673c21d17a9 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "lockfile.h"
 
diff --git a/midx.c b/midx.c
index e132ef250e4..b111665dcab 100644
--- a/midx.c
+++ b/midx.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "csum-file.h"
diff --git a/object-file.c b/object-file.c
index 39660d49dbc..bee41b30474 100644
--- a/object-file.c
+++ b/object-file.c
@@ -7,6 +7,7 @@
  * creation etc.
  */
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/parse-options.c b/parse-options.c
index 815c392aaec..99fa0440b5d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
diff --git a/path.c b/path.c
index 3f2702cbe49..3976c0d7ace 100644
--- a/path.c
+++ b/path.c
@@ -2,6 +2,7 @@
  * Utilities for paths and pathnames
  */
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/pathspec.c b/pathspec.c
index 868b4d280ca..53763e272f5 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/remote.c b/remote.c
index edb1e07497c..2bae247a0a4 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/repository.c b/repository.c
index 937fa974b38..4412f633224 100644
--- a/repository.c
+++ b/repository.c
@@ -4,6 +4,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "repository.h"
 #include "object-store.h"
 #include "config.h"
diff --git a/rerere.c b/rerere.c
index 9428cbca7b2..c3258e13902 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/scalar.c b/scalar.c
index ca19b95ce46..fe61a3ebdd7 100644
--- a/scalar.c
+++ b/scalar.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "config.h"
diff --git a/sequencer.c b/sequencer.c
index 0fe00b0bcec..f5fe0df2689 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/setup.c b/setup.c
index 8a4ccee4c2c..8f385d9f29b 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "repository.h"
 #include "config.h"
diff --git a/strbuf.c b/strbuf.c
index b9cd593b147..9633e37b62f 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/submodule.c b/submodule.c
index 8b551e53274..13ff333f68c 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index f69709d674f..d3d00dc34fa 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "abspath.h"
 #include "string-list.h"
 #include "utf8.h"
 
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 2a2012eb6d0..fff15cb6b5c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tmp-objdir.h"
+#include "abspath.h"
 #include "chdir-notify.h"
 #include "dir.h"
 #include "sigchain.h"
diff --git a/trace.c b/trace.c
index efa4e2d8e08..2b41c683fc8 100644
--- a/trace.c
+++ b/trace.c
@@ -22,6 +22,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "quote.h"
 
 struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index 8a21dd29725..273260e1f18 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "sigchain.h"
 #include "trace2/tr2_dst.h"
 #include "trace2/tr2_sid.h"
diff --git a/worktree.c b/worktree.c
index 530dd5fbc44..d87141f694e 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "repository.h"
diff --git a/wrapper.c b/wrapper.c
index 0d4ceba6fc5..df1fa6286d0 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 07/16] cache.h: remove expand_user_path()
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (5 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 06/16] abspath.h: move absolute path functions " Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 08/16] path.h: move function declarations for path.c functions from cache.h Elijah Newren via GitGitGadget
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

expand_user_path() was renamed to interpolate_path() back in mid-2021,
but reinstated with a #define and a NEEDSWORK comment that we would
eventually want to get rid of it.  Do so now.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h         | 2 --
 gpg-interface.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 260203c7a62..978aa01712b 100644
--- a/cache.h
+++ b/cache.h
@@ -1142,8 +1142,6 @@ enum scld_error safe_create_leading_directories_no_share(char *path);
 
 int mkdir_in_gitdir(const char *path);
 char *interpolate_path(const char *path, int real_home);
-/* NEEDSWORK: remove this synonym once in-flight topics have migrated */
-#define expand_user_path interpolate_path
 const char *enter_repo(const char *path, int strict);
 const char *remove_leading_path(const char *in, const char *prefix);
 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
diff --git a/gpg-interface.c b/gpg-interface.c
index 632265691e5..f9c5b6c3f53 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1049,7 +1049,7 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
 		ssh_signing_key_file = strbuf_detach(&key_file->filename, NULL);
 	} else {
 		/* We assume a file */
-		ssh_signing_key_file = expand_user_path(signing_key, 1);
+		ssh_signing_key_file = interpolate_path(signing_key, 1);
 	}
 
 	buffer_file = mks_tempfile_t(".git_signing_buffer_tmpXXXXXX");
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 08/16] path.h: move function declarations for path.c functions from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (6 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 07/16] cache.h: remove expand_user_path() Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 09/16] wrapper.h: move declarations for wrapper.c " Elijah Newren via GitGitGadget
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h | 59 ------------------------------------------------------
 path.h  | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 60 deletions(-)

diff --git a/cache.h b/cache.h
index 978aa01712b..705c41992bc 100644
--- a/cache.h
+++ b/cache.h
@@ -1105,7 +1105,6 @@ enum sharedrepo {
 	PERM_EVERYBODY      = 0664
 };
 int git_config_perm(const char *var, const char *value);
-int adjust_shared_perm(const char *path);
 
 /*
  * Create the directory containing the named path, using care to be
@@ -1141,54 +1140,6 @@ enum scld_error safe_create_leading_directories_const(const char *path);
 enum scld_error safe_create_leading_directories_no_share(char *path);
 
 int mkdir_in_gitdir(const char *path);
-char *interpolate_path(const char *path, int real_home);
-const char *enter_repo(const char *path, int strict);
-const char *remove_leading_path(const char *in, const char *prefix);
-const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
-int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
-int normalize_path_copy(char *dst, const char *src);
-int longest_ancestor_length(const char *path, struct string_list *prefixes);
-char *strip_path_suffix(const char *path, const char *suffix);
-int daemon_avoid_alias(const char *path);
-
-/*
- * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
- * details.
- */
-int is_ntfs_dotgit(const char *name);
-int is_ntfs_dotgitmodules(const char *name);
-int is_ntfs_dotgitignore(const char *name);
-int is_ntfs_dotgitattributes(const char *name);
-int is_ntfs_dotmailmap(const char *name);
-
-/*
- * Returns true iff "str" could be confused as a command-line option when
- * passed to a sub-program like "ssh". Note that this has nothing to do with
- * shell-quoting, which should be handled separately; we're assuming here that
- * the string makes it verbatim to the sub-program.
- */
-int looks_like_command_line_option(const char *str);
-
-/**
- * Return a newly allocated string with the evaluation of
- * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
- * "$HOME/.config/$subdir/$filename". Return NULL upon error.
- */
-char *xdg_config_home_for(const char *subdir, const char *filename);
-
-/**
- * Return a newly allocated string with the evaluation of
- * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
- * "$HOME/.config/git/$filename". Return NULL upon error.
- */
-char *xdg_config_home(const char *filename);
-
-/**
- * Return a newly allocated string with the evaluation of
- * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
- * "$HOME/.cache/git/$filename". Return NULL upon error.
- */
-char *xdg_cache_home(const char *filename);
 
 int git_open_cloexec(const char *name, int flags);
 #define git_open(name) git_open_cloexec(name, O_RDONLY)
@@ -1355,8 +1306,6 @@ int repo_interpret_branch_name(struct repository *r,
 #define interpret_branch_name(str, len, buf, options) \
 	repo_interpret_branch_name(the_repository, str, len, buf, options)
 
-int validate_headref(const char *ref);
-
 int base_name_compare(const char *name1, size_t len1, int mode1,
 		      const char *name2, size_t len2, int mode2);
 int df_name_compare(const char *name1, size_t len1, int mode1,
@@ -1616,14 +1565,6 @@ void stat_validity_update(struct stat_validity *sv, int fd);
 
 int versioncmp(const char *s1, const char *s2);
 
-/*
- * Create a directory and (if share is nonzero) adjust its permissions
- * according to the shared_repository setting. Only use this for
- * directories under $GIT_DIR.  Don't use it for working tree
- * directories.
- */
-void safe_create_dir(const char *dir, int share);
-
 /*
  * Should we print an ellipsis after an abbreviated SHA-1 value
  * when doing diff-raw output or indicating a detached HEAD?
diff --git a/path.h b/path.h
index 0a59c85a62e..60e83a49a98 100644
--- a/path.h
+++ b/path.h
@@ -3,6 +3,7 @@
 
 struct repository;
 struct strbuf;
+struct string_list;
 
 /*
  * The result to all functions which return statically allocated memory may be
@@ -179,7 +180,66 @@ const char *git_path_auto_merge(struct repository *r);
 const char *git_path_fetch_head(struct repository *r);
 const char *git_path_shallow(struct repository *r);
 
-
 int ends_with_path_components(const char *path, const char *components);
+int validate_headref(const char *ref);
+
+int adjust_shared_perm(const char *path);
+
+char *interpolate_path(const char *path, int real_home);
+const char *enter_repo(const char *path, int strict);
+const char *remove_leading_path(const char *in, const char *prefix);
+const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
+int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
+int normalize_path_copy(char *dst, const char *src);
+int longest_ancestor_length(const char *path, struct string_list *prefixes);
+char *strip_path_suffix(const char *path, const char *suffix);
+int daemon_avoid_alias(const char *path);
+
+/*
+ * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
+ * details.
+ */
+int is_ntfs_dotgit(const char *name);
+int is_ntfs_dotgitmodules(const char *name);
+int is_ntfs_dotgitignore(const char *name);
+int is_ntfs_dotgitattributes(const char *name);
+int is_ntfs_dotmailmap(const char *name);
+
+/*
+ * Returns true iff "str" could be confused as a command-line option when
+ * passed to a sub-program like "ssh". Note that this has nothing to do with
+ * shell-quoting, which should be handled separately; we're assuming here that
+ * the string makes it verbatim to the sub-program.
+ */
+int looks_like_command_line_option(const char *str);
+
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
+ * "$HOME/.config/$subdir/$filename". Return NULL upon error.
+ */
+char *xdg_config_home_for(const char *subdir, const char *filename);
+
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
+ * "$HOME/.config/git/$filename". Return NULL upon error.
+ */
+char *xdg_config_home(const char *filename);
+
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
+ * "$HOME/.cache/git/$filename". Return NULL upon error.
+ */
+char *xdg_cache_home(const char *filename);
+
+/*
+ * Create a directory and (if share is nonzero) adjust its permissions
+ * according to the shared_repository setting. Only use this for
+ * directories under $GIT_DIR.  Don't use it for working tree
+ * directories.
+ */
+void safe_create_dir(const char *dir, int share);
 
 #endif /* PATH_H */
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 09/16] wrapper.h: move declarations for wrapper.c functions from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (7 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 08/16] path.h: move function declarations for path.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 10/16] treewide: remove unnecessary includes of cache.h Elijah Newren via GitGitGadget
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                          |  1 +
 builtin/am.c                     |  1 +
 builtin/bisect.c                 |  1 +
 builtin/branch.c                 |  1 +
 builtin/bugreport.c              |  2 +-
 builtin/config.c                 |  1 +
 builtin/credential-cache.c       |  1 +
 builtin/difftool.c               |  1 +
 builtin/fast-import.c            |  1 +
 builtin/fmt-merge-msg.c          |  1 +
 builtin/gc.c                     |  1 +
 builtin/get-tar-commit-id.c      |  1 +
 builtin/index-pack.c             |  1 +
 builtin/init-db.c                |  1 +
 builtin/merge.c                  |  1 +
 builtin/pack-objects.c           |  1 +
 builtin/rebase.c                 |  1 +
 builtin/receive-pack.c           |  1 +
 builtin/rerere.c                 |  1 +
 builtin/unpack-file.c            |  1 +
 builtin/worktree.c               |  1 +
 cache.h                          | 32 ----------------------------
 commit-graph.c                   |  1 +
 compat/mingw.c                   |  1 +
 compat/terminal.c                |  1 +
 config.c                         |  1 +
 convert.c                        |  1 +
 copy.c                           |  1 +
 csum-file.c                      |  1 +
 daemon.c                         |  1 +
 diff.c                           |  1 +
 dir.c                            |  1 +
 entry.c                          |  1 +
 environment.c                    |  1 +
 fetch-pack.c                     |  1 +
 gpg-interface.c                  |  1 +
 http-backend.c                   |  1 +
 imap-send.c                      |  1 +
 ll-merge.c                       |  1 +
 merge-recursive.c                |  1 +
 notes-merge.c                    |  1 +
 object-file.c                    |  1 +
 packfile.c                       |  1 +
 parallel-checkout.c              |  1 +
 pkt-line.c                       |  1 +
 read-cache.c                     |  1 +
 rebase-interactive.c             |  1 +
 refs.c                           |  1 +
 refs/files-backend.c             |  3 ++-
 rerere.c                         |  1 +
 sequencer.c                      |  1 +
 server-info.c                    |  1 +
 shallow.c                        |  1 +
 strbuf.c                         |  1 +
 streaming.c                      |  1 +
 t/helper/test-delta.c            |  1 +
 t/helper/test-fsmonitor-client.c |  1 +
 t/helper/test-read-cache.c       |  1 +
 tag.c                            |  1 +
 tempfile.c                       |  1 +
 trace.c                          |  1 +
 transport-helper.c               |  1 +
 transport.c                      |  1 +
 usage.c                          |  1 +
 worktree.c                       |  1 +
 wrapper.c                        |  1 +
 wrapper.h                        | 36 ++++++++++++++++++++++++++++++++
 write-or-die.c                   |  1 +
 68 files changed, 103 insertions(+), 34 deletions(-)
 create mode 100644 wrapper.h

diff --git a/apply.c b/apply.c
index e5e11b85793..373565a7baf 100644
--- a/apply.c
+++ b/apply.c
@@ -26,6 +26,7 @@
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
+#include "wrapper.h"
 
 struct gitdiff_data {
 	struct strbuf *root;
diff --git a/builtin/am.c b/builtin/am.c
index 14347ecf9aa..37f82b3eb42 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -38,6 +38,7 @@
 #include "packfile.h"
 #include "repository.h"
 #include "pretty.h"
+#include "wrapper.h"
 
 /**
  * Returns the length of the first line of msg.
diff --git a/builtin/bisect.c b/builtin/bisect.c
index c2e614c2890..2db46b04c97 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -11,6 +11,7 @@
 #include "prompt.h"
 #include "quote.h"
 #include "revision.h"
+#include "wrapper.h"
 
 static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
 static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
diff --git a/builtin/branch.c b/builtin/branch.c
index 56dbee97d20..98475ea5325 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -26,6 +26,7 @@
 #include "worktree.h"
 #include "help.h"
 #include "commit-reach.h"
+#include "wrapper.h"
 
 static const char * const builtin_branch_usage[] = {
 	N_("git branch [<options>] [-r | -a] [--merged] [--no-merged]"),
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index b5dfad4e12a..160590e4ef6 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -8,7 +8,7 @@
 #include "hook.h"
 #include "hook-list.h"
 #include "diagnose.h"
-
+#include "wrapper.h"
 
 static void get_system_info(struct strbuf *sys_info)
 {
diff --git a/builtin/config.c b/builtin/config.c
index 42e6b8d3481..1c1e006ff3f 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -9,6 +9,7 @@
 #include "urlmatch.h"
 #include "quote.h"
 #include "worktree.h"
+#include "wrapper.h"
 
 static const char *const builtin_config_usage[] = {
 	N_("git config [<options>]"),
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 25f2f71c216..af56a44923d 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "wrapper.h"
 
 #ifndef NO_UNIX_SOCKETS
 
diff --git a/builtin/difftool.c b/builtin/difftool.c
index ed06db12085..59465c39f1d 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -27,6 +27,7 @@
 #include "object-store.h"
 #include "dir.h"
 #include "entry.h"
+#include "wrapper.h"
 
 static int trust_exit_code;
 
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 7307c4657f2..3300b7f30f0 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -23,6 +23,7 @@
 #include "commit-reach.h"
 #include "khash.h"
 #include "date.h"
+#include "wrapper.h"
 
 #define PACK_ID_BITS 16
 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 0f9855b680e..cc812416420 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -3,6 +3,7 @@
 #include "fmt-merge-msg.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "wrapper.h"
 
 static const char * const fmt_merge_msg_usage[] = {
 	N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
diff --git a/builtin/gc.c b/builtin/gc.c
index ef063fc828c..2107e3d1f2c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -35,6 +35,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hook.h"
+#include "wrapper.h"
 
 #define FAILED_RUN "failed to run %s"
 
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 491af9202dc..67457969986 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -6,6 +6,7 @@
 #include "tar.h"
 #include "builtin.h"
 #include "quote.h"
+#include "wrapper.h"
 
 static const char builtin_get_tar_commit_id_usage[] =
 "git get-tar-commit-id";
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bae5b054039..2393897cb88 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -19,6 +19,7 @@
 #include "object-store.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
+#include "wrapper.h"
 
 static const char index_pack_usage[] =
 "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 6f724f694f4..a5d4f5c8ece 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "exec-cmd.h"
 #include "parse-options.h"
 #include "worktree.h"
+#include "wrapper.h"
 
 #ifndef DEFAULT_GIT_TEMPLATE_DIR
 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
diff --git a/builtin/merge.c b/builtin/merge.c
index 38243e55c5f..f4f4a220f30 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -49,6 +49,7 @@
 #include "commit-reach.h"
 #include "wt-status.h"
 #include "commit-graph.h"
+#include "wrapper.h"
 
 #define DEFAULT_TWOHEAD (1<<0)
 #define DEFAULT_OCTOPUS (1<<1)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1ca800c7c50..8b55a088a7c 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -40,6 +40,7 @@
 #include "shallow.h"
 #include "promisor-remote.h"
 #include "pack-mtimes.h"
+#include "wrapper.h"
 
 /*
  * Objects we are going to pack are collected in the `to_pack` structure.
diff --git a/builtin/rebase.c b/builtin/rebase.c
index a3f8be88882..d2f8f703d67 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -32,6 +32,7 @@
 #include "rebase-interactive.h"
 #include "reset.h"
 #include "hook.h"
+#include "wrapper.h"
 
 static char const * const builtin_rebase_usage[] = {
 	N_("git rebase [-i] [options] [--exec <cmd>] "
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 5fab0aed533..e954c85ce3d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,6 +33,7 @@
 #include "commit-reach.h"
 #include "worktree.h"
 #include "shallow.h"
+#include "wrapper.h"
 
 static const char * const receive_pack_usage[] = {
 	N_("git receive-pack <git-dir>"),
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 24c78755723..d4a03707b1a 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -6,6 +6,7 @@
 #include "parse-options.h"
 #include "string-list.h"
 #include "rerere.h"
+#include "wrapper.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e9b105a5397..4cbb4039293 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "hex.h"
 #include "object-store.h"
+#include "wrapper.h"
 
 static char *create_temp_file(struct object_id *oid)
 {
diff --git a/builtin/worktree.c b/builtin/worktree.c
index ed614ffddcb..1533b4ab43c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -16,6 +16,7 @@
 #include "submodule.h"
 #include "utf8.h"
 #include "worktree.h"
+#include "wrapper.h"
 #include "quote.h"
 
 #define BUILTIN_WORKTREE_ADD_USAGE \
diff --git a/cache.h b/cache.h
index 705c41992bc..31c722533f9 100644
--- a/cache.h
+++ b/cache.h
@@ -1085,10 +1085,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id
 int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
 #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
-/* set default permissions by passing mode arguments to open(2) */
-int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
-int git_mkstemp_mode(char *pattern, int mode);
-
 /*
  * NOTE NOTE NOTE!!
  *
@@ -1423,31 +1419,6 @@ static inline int batch_fsync_enabled(enum fsync_component component)
 	return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
 }
 
-ssize_t read_in_full(int fd, void *buf, size_t count);
-ssize_t write_in_full(int fd, const void *buf, size_t count);
-ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
-
-static inline ssize_t write_str_in_full(int fd, const char *str)
-{
-	return write_in_full(fd, str, strlen(str));
-}
-
-/**
- * Open (and truncate) the file at path, write the contents of buf to it,
- * and close it. Dies if any errors are encountered.
- */
-void write_file_buf(const char *path, const char *buf, size_t len);
-
-/**
- * Like write_file_buf(), but format the contents into a buffer first.
- * Additionally, write_file() will append a newline if one is not already
- * present, making it convenient to write text files:
- *
- *   write_file(path, "counter: %d", ctr);
- */
-__attribute__((format (printf, 2, 3)))
-void write_file(const char *path, const char *fmt, ...);
-
 /* pager.c */
 void setup_pager(void);
 int pager_in_use(void);
@@ -1571,7 +1542,4 @@ int versioncmp(const char *s1, const char *s2);
  */
 int print_sha1_ellipsis(void);
 
-/* Return 1 if the file is empty or does not exists, 0 otherwise. */
-int is_empty_or_missing_file(const char *filename);
-
 #endif /* CACHE_H */
diff --git a/commit-graph.c b/commit-graph.c
index 8f21a0a0c20..5481736c76c 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -22,6 +22,7 @@
 #include "json-writer.h"
 #include "trace2.h"
 #include "chunk-format.h"
+#include "wrapper.h"
 
 void git_test_write_commit_graph_or_die(void)
 {
diff --git a/compat/mingw.c b/compat/mingw.c
index cbcd03aea9b..d48899bf7b4 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -11,6 +11,7 @@
 #include "../alloc.h"
 #include "win32/lazyload.h"
 #include "../config.h"
+#include "../wrapper.h"
 #include "dir.h"
 #include "gettext.h"
 #define SECURITY_WIN32
diff --git a/compat/terminal.c b/compat/terminal.c
index afebe6b2496..ed2b30b38f7 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -6,6 +6,7 @@
 #include "run-command.h"
 #include "string-list.h"
 #include "hashmap.h"
+#include "wrapper.h"
 
 #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)
 
diff --git a/config.c b/config.c
index 6815919ec30..5b1a5d52052 100644
--- a/config.c
+++ b/config.c
@@ -28,6 +28,7 @@
 #include "replace-object.h"
 #include "refs.h"
 #include "worktree.h"
+#include "wrapper.h"
 
 struct config_source {
 	struct config_source *prev;
diff --git a/convert.c b/convert.c
index 2bd54244b55..da06e2f51cb 100644
--- a/convert.c
+++ b/convert.c
@@ -11,6 +11,7 @@
 #include "sub-process.h"
 #include "utf8.h"
 #include "ll-merge.h"
+#include "wrapper.h"
 
 /*
  * convert.c - convert a file when checking it out and checking it in.
diff --git a/copy.c b/copy.c
index 4de6a110f09..c3250f08221 100644
--- a/copy.c
+++ b/copy.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "wrapper.h"
 
 int copy_fd(int ifd, int ofd)
 {
diff --git a/csum-file.c b/csum-file.c
index cce13c0f047..2d22f80d901 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "progress.h"
 #include "csum-file.h"
+#include "wrapper.h"
 
 static void verify_buffer_or_die(struct hashfile *f,
 				 const void *buf,
diff --git a/daemon.c b/daemon.c
index bb795ca3ca9..e35604e194c 100644
--- a/daemon.c
+++ b/daemon.c
@@ -6,6 +6,7 @@
 #include "run-command.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "wrapper.h"
 
 #ifdef NO_INITGROUPS
 #define initgroups(x, y) (0) /* nothing */
diff --git a/diff.c b/diff.c
index 1b0be99c065..1b0b24c21c3 100644
--- a/diff.c
+++ b/diff.c
@@ -33,6 +33,7 @@
 #include "promisor-remote.h"
 #include "dir.h"
 #include "strmap.h"
+#include "wrapper.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
diff --git a/dir.c b/dir.c
index c72481c60ee..b57c770e68b 100644
--- a/dir.c
+++ b/dir.c
@@ -21,6 +21,7 @@
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "submodule-config.h"
+#include "wrapper.h"
 
 /*
  * Tells read_directory_recursive how a file or directory should be treated.
diff --git a/entry.c b/entry.c
index acb76a61aca..70212af260b 100644
--- a/entry.c
+++ b/entry.c
@@ -10,6 +10,7 @@
 #include "fsmonitor.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "wrapper.h"
 
 static void create_directories(const char *path, int path_len,
 			       const struct checkout *state)
diff --git a/environment.c b/environment.c
index c69571f0b29..bf02f3cf487 100644
--- a/environment.c
+++ b/environment.c
@@ -23,6 +23,7 @@
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
 #include "shallow.h"
+#include "wrapper.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
diff --git a/fetch-pack.c b/fetch-pack.c
index 359dce6afed..c1190801405 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -30,6 +30,7 @@
 #include "commit-graph.h"
 #include "sigchain.h"
 #include "mergesort.h"
+#include "wrapper.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
diff --git a/gpg-interface.c b/gpg-interface.c
index f9c5b6c3f53..6644701fda0 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -10,6 +10,7 @@
 #include "sigchain.h"
 #include "tempfile.h"
 #include "alias.h"
+#include "wrapper.h"
 
 static int git_gpg_config(const char *, const char *, void *);
 
diff --git a/http-backend.c b/http-backend.c
index 7e7c19e66b3..42e6c2596e9 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -16,6 +16,7 @@
 #include "object-store.h"
 #include "protocol.h"
 #include "date.h"
+#include "wrapper.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
diff --git a/imap-send.c b/imap-send.c
index c65a27219c6..aa5b2f252d2 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -28,6 +28,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "wrapper.h"
 #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
 typedef void *SSL;
 #endif
diff --git a/ll-merge.c b/ll-merge.c
index 130d26501c6..8be38d3bd41 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -11,6 +11,7 @@
 #include "run-command.h"
 #include "ll-merge.h"
 #include "quote.h"
+#include "wrapper.h"
 
 struct ll_merge_driver;
 
diff --git a/merge-recursive.c b/merge-recursive.c
index 0b0255ebc80..f918cea4c69 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -30,6 +30,7 @@
 #include "tag.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
+#include "wrapper.h"
 #include "xdiff-interface.h"
 
 struct merge_options_internal {
diff --git a/notes-merge.c b/notes-merge.c
index c8d0020b1a2..ba2970f0702 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -15,6 +15,7 @@
 #include "strbuf.h"
 #include "notes-utils.h"
 #include "commit-reach.h"
+#include "wrapper.h"
 
 struct notes_merge_pair {
 	struct object_id obj, base, local, remote;
diff --git a/object-file.c b/object-file.c
index bee41b30474..bdf68763a50 100644
--- a/object-file.c
+++ b/object-file.c
@@ -38,6 +38,7 @@
 #include "promisor-remote.h"
 #include "submodule.h"
 #include "fsck.h"
+#include "wrapper.h"
 
 /* The maximum size for an object header. */
 #define MAX_HEADER_LEN 32
diff --git a/packfile.c b/packfile.c
index b1718b93d4b..0fe844f2075 100644
--- a/packfile.c
+++ b/packfile.c
@@ -20,6 +20,7 @@
 #include "midx.h"
 #include "commit-graph.h"
 #include "promisor-remote.h"
+#include "wrapper.h"
 
 char *odb_pack_name(struct strbuf *buf,
 		    const unsigned char *hash,
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 38c4dc665d5..50fd7fe31ef 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -12,6 +12,7 @@
 #include "streaming.h"
 #include "thread-utils.h"
 #include "trace2.h"
+#include "wrapper.h"
 
 struct pc_worker {
 	struct child_process cp;
diff --git a/pkt-line.c b/pkt-line.c
index c8b90b2242e..30469eb4d8d 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
+#include "wrapper.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
diff --git a/read-cache.c b/read-cache.c
index 63789ea5e21..9a8d5fe97ed 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -32,6 +32,7 @@
 #include "csum-file.h"
 #include "promisor-remote.h"
 #include "hook.h"
+#include "wrapper.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 649c94e69a6..7c885c35bfd 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -7,6 +7,7 @@
 #include "commit-slab.h"
 #include "config.h"
 #include "dir.h"
+#include "wrapper.h"
 
 static const char edit_todo_list_advice[] =
 N_("You can fix this with 'git rebase --edit-todo' "
diff --git a/refs.c b/refs.c
index 8684f4610f5..385051752f1 100644
--- a/refs.c
+++ b/refs.c
@@ -24,6 +24,7 @@
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
+#include "wrapper.h"
 
 /*
  * List of all available backends
diff --git a/refs/files-backend.c b/refs/files-backend.c
index de3628ff3f1..eb14d124e3f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -13,7 +13,8 @@
 #include "../object.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
-#include "worktree.h"
+#include "../worktree.h"
+#include "../wrapper.h"
 
 /*
  * This backend uses the following flags in `ref_update::flags` for
diff --git a/rerere.c b/rerere.c
index c3258e13902..b5ccbecdcd2 100644
--- a/rerere.c
+++ b/rerere.c
@@ -16,6 +16,7 @@
 #include "object-store.h"
 #include "hash-lookup.h"
 #include "strmap.h"
+#include "wrapper.h"
 
 #define RESOLVED 0
 #define PUNTED 1
diff --git a/sequencer.c b/sequencer.c
index f5fe0df2689..c1ff319cfc1 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -41,6 +41,7 @@
 #include "rebase-interactive.h"
 #include "reset.h"
 #include "branch.h"
+#include "wrapper.h"
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
diff --git a/server-info.c b/server-info.c
index 78643377057..ae96d784e53 100644
--- a/server-info.c
+++ b/server-info.c
@@ -10,6 +10,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "strbuf.h"
+#include "wrapper.h"
 
 struct update_info_ctx {
 	FILE *cur_fp;
diff --git a/shallow.c b/shallow.c
index c5433a4fd30..7fcba5f6d06 100644
--- a/shallow.c
+++ b/shallow.c
@@ -17,6 +17,7 @@
 #include "list-objects.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "wrapper.h"
 
 void set_alternate_shallow_file(struct repository *r, const char *path, int override)
 {
diff --git a/strbuf.c b/strbuf.c
index 9633e37b62f..70a83e7980e 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -8,6 +8,7 @@
 #include "string-list.h"
 #include "utf8.h"
 #include "date.h"
+#include "wrapper.h"
 
 int starts_with(const char *str, const char *prefix)
 {
diff --git a/streaming.c b/streaming.c
index 27841dc1d9e..6c69f595045 100644
--- a/streaming.c
+++ b/streaming.c
@@ -7,6 +7,7 @@
 #include "object-store.h"
 #include "replace-object.h"
 #include "packfile.h"
+#include "wrapper.h"
 
 typedef int (*open_istream_fn)(struct git_istream *,
 			       struct repository *,
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index b15481ea596..6609fcbc12e 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -12,6 +12,7 @@
 #include "git-compat-util.h"
 #include "delta.h"
 #include "cache.h"
+#include "wrapper.h"
 
 static const char usage_str[] =
 	"test-tool delta (-d|-p) <from_file> <data_file> <out_file>";
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 54a4856c48c..c43fc976b82 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -9,6 +9,7 @@
 #include "fsmonitor-ipc.h"
 #include "thread-utils.h"
 #include "trace2.h"
+#include "wrapper.h"
 
 #ifndef HAVE_FSMONITOR_DAEMON_BACKEND
 int cmd__fsmonitor_client(int argc, const char **argv)
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 23e9e27109f..84818363d5b 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "wrapper.h"
 
 int cmd__read_cache(int argc, const char **argv)
 {
diff --git a/tag.c b/tag.c
index 18b718cca66..3408bb9433f 100644
--- a/tag.c
+++ b/tag.c
@@ -8,6 +8,7 @@
 #include "gpg-interface.h"
 #include "hex.h"
 #include "packfile.h"
+#include "wrapper.h"
 
 const char *tag_type = "tag";
 
diff --git a/tempfile.c b/tempfile.c
index e27048f970b..cdd2cab3bad 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -45,6 +45,7 @@
 #include "cache.h"
 #include "tempfile.h"
 #include "sigchain.h"
+#include "wrapper.h"
 
 static VOLATILE_LIST_HEAD(tempfile_list);
 
diff --git a/trace.c b/trace.c
index 2b41c683fc8..de004f62988 100644
--- a/trace.c
+++ b/trace.c
@@ -24,6 +24,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "quote.h"
+#include "wrapper.h"
 
 struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
 struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);
diff --git a/transport-helper.c b/transport-helper.c
index 105bb801c21..09048eab484 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -16,6 +16,7 @@
 #include "refspec.h"
 #include "transport-internal.h"
 #include "protocol.h"
+#include "wrapper.h"
 
 static int debug;
 
diff --git a/transport.c b/transport.c
index 80059124c0a..c6179b801e8 100644
--- a/transport.c
+++ b/transport.c
@@ -26,6 +26,7 @@
 #include "object-store.h"
 #include "color.h"
 #include "bundle-uri.h"
+#include "wrapper.h"
 
 static int transport_use_color = -1;
 static char transport_colors[][COLOR_MAXLEN] = {
diff --git a/usage.c b/usage.c
index 40a1c5a4339..b53c99dbe5b 100644
--- a/usage.c
+++ b/usage.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "gettext.h"
+#include "wrapper.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
 {
diff --git a/worktree.c b/worktree.c
index d87141f694e..64c96605e53 100644
--- a/worktree.c
+++ b/worktree.c
@@ -9,6 +9,7 @@
 #include "dir.h"
 #include "wt-status.h"
 #include "config.h"
+#include "wrapper.h"
 
 void free_worktrees(struct worktree **worktrees)
 {
diff --git a/wrapper.c b/wrapper.c
index df1fa6286d0..ee837575902 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -5,6 +5,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "gettext.h"
+#include "wrapper.h"
 
 static intmax_t count_fsync_writeout_only;
 static intmax_t count_fsync_hardware_flush;
diff --git a/wrapper.h b/wrapper.h
new file mode 100644
index 00000000000..f0c7d0616d6
--- /dev/null
+++ b/wrapper.h
@@ -0,0 +1,36 @@
+#ifndef WRAPPER_H
+#define WRAPPER_H
+
+/* set default permissions by passing mode arguments to open(2) */
+int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
+int git_mkstemp_mode(char *pattern, int mode);
+
+ssize_t read_in_full(int fd, void *buf, size_t count);
+ssize_t write_in_full(int fd, const void *buf, size_t count);
+ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
+
+static inline ssize_t write_str_in_full(int fd, const char *str)
+{
+	return write_in_full(fd, str, strlen(str));
+}
+
+/**
+ * Open (and truncate) the file at path, write the contents of buf to it,
+ * and close it. Dies if any errors are encountered.
+ */
+void write_file_buf(const char *path, const char *buf, size_t len);
+
+/**
+ * Like write_file_buf(), but format the contents into a buffer first.
+ * Additionally, write_file() will append a newline if one is not already
+ * present, making it convenient to write text files:
+ *
+ *   write_file(path, "counter: %d", ctr);
+ */
+__attribute__((format (printf, 2, 3)))
+void write_file(const char *path, const char *fmt, ...);
+
+/* Return 1 if the file is empty or does not exists, 0 otherwise. */
+int is_empty_or_missing_file(const char *filename);
+
+#endif /* WRAPPER_H */
diff --git a/write-or-die.c b/write-or-die.c
index aaa0318e824..a7afc303db2 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "run-command.h"
+#include "wrapper.h"
 
 /*
  * Some cases use stdio, but want to flush after the write
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 10/16] treewide: remove unnecessary includes of cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (8 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 09/16] wrapper.h: move declarations for wrapper.c " Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 11/16] environment.h: move declarations for environment.c functions from cache.h Elijah Newren via GitGitGadget
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The last several commits were geared at replacing the include of cache.h
in strbuf.c with an include of git-compat-util.h.  Unfortunately, I had
to drop a patch moving some functions from cache.h to object-name.h, due
to excessive conflicts with other in-flight topics.

However, even without that patch, the series of patches so far allows us
to modify a number of C files to replace an include of cache.h with
git-compat-util.h.  Do that to reduce our dependencies.

(If we could have kept our object-name.h patch in this series, it would
have also let us reduce the includes in checkout.c and fmt-merge-msg.c
in addition to strbuf.c).

Just to ensure that nothing else was bringing in cache.h, all of the
affected files have been checked to ensure that
    gcc -E -I. $SOURCE_FILE | grep '"cache.h"'
found no hits and that
    make DEVELOPER=1 ${OBJECT_FILE_FOR_SOURCE_FILE}
successfully compiles without warnings.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 compat/terminal.c      | 2 +-
 gpg-interface.c        | 2 +-
 lockfile.c             | 2 +-
 parse-options.c        | 1 -
 t/helper/test-delta.c  | 1 -
 t/helper/test-trace2.c | 2 +-
 tempfile.c             | 3 ++-
 trace2/tr2_cfg.c       | 4 +++-
 trace2/tr2_cmd_name.c  | 3 ++-
 trace2/tr2_dst.c       | 3 ++-
 trace2/tr2_sid.c       | 3 ++-
 usage.c                | 3 ++-
 12 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/compat/terminal.c b/compat/terminal.c
index ed2b30b38f7..d87e3211892 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "compat/terminal.h"
 #include "gettext.h"
 #include "sigchain.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index 6644701fda0..aceeb083367 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "commit.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/lockfile.c b/lockfile.c
index 673c21d17a9..1d5ed016828 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2005, Junio C Hamano
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "lockfile.h"
diff --git a/parse-options.c b/parse-options.c
index 99fa0440b5d..8615367c69d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,7 +1,6 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "color.h"
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index 6609fcbc12e..e7d134ec251 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -11,7 +11,6 @@
 #include "test-tool.h"
 #include "git-compat-util.h"
 #include "delta.h"
-#include "cache.h"
 #include "wrapper.h"
 
 static const char usage_str[] =
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index f374c21ec32..a476df6c6cb 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,9 +1,9 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "strvec.h"
 #include "run-command.h"
 #include "exec-cmd.h"
 #include "config.h"
+#include "trace2.h"
 
 typedef int(fn_unit_test)(int argc, const char **argv);
 
diff --git a/tempfile.c b/tempfile.c
index cdd2cab3bad..50c377134ce 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -42,7 +42,8 @@
  * file created by its parent.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
+#include "path.h"
 #include "tempfile.h"
 #include "sigchain.h"
 #include "wrapper.h"
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index ec9ac1a6efd..78cfc15d52d 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -1,5 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
+#include "strbuf.h"
+#include "trace2.h"
 #include "trace2/tr2_cfg.h"
 #include "trace2/tr2_sysenv.h"
 
diff --git a/trace2/tr2_cmd_name.c b/trace2/tr2_cmd_name.c
index dd313204f51..b7b5a869b74 100644
--- a/trace2/tr2_cmd_name.c
+++ b/trace2/tr2_cmd_name.c
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "strbuf.h"
 #include "trace2/tr2_cmd_name.h"
 
 #define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME"
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index 273260e1f18..5be892cd5cd 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "sigchain.h"
+#include "strbuf.h"
 #include "trace2/tr2_dst.h"
 #include "trace2/tr2_sid.h"
 #include "trace2/tr2_sysenv.h"
diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c
index 5f1ce6f85cf..09c4ef0d173 100644
--- a/trace2/tr2_sid.c
+++ b/trace2/tr2_sid.c
@@ -1,5 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hex.h"
+#include "strbuf.h"
 #include "trace2/tr2_tbuf.h"
 #include "trace2/tr2_sid.h"
 
diff --git a/usage.c b/usage.c
index b53c99dbe5b..46d99f8bd43 100644
--- a/usage.c
+++ b/usage.c
@@ -3,8 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
+#include "trace2.h"
 #include "wrapper.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 11/16] environment.h: move declarations for environment.c functions from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (9 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 10/16] treewide: remove unnecessary includes of cache.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 12/16] treewide: remove cache.h inclusion due to environment.h changes Elijah Newren via GitGitGadget
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                             |   1 +
 archive.c                           |   1 +
 attr.c                              |   1 +
 bisect.c                            |   1 +
 branch.c                            |   1 +
 builtin/am.c                        |   1 +
 builtin/bisect.c                    |   1 +
 builtin/blame.c                     |   1 +
 builtin/cat-file.c                  |   1 +
 builtin/check-attr.c                |   1 +
 builtin/checkout.c                  |   1 +
 builtin/clone.c                     |   1 +
 builtin/commit-graph.c              |   1 +
 builtin/config.c                    |   1 +
 builtin/count-objects.c             |   1 +
 builtin/describe.c                  |   1 +
 builtin/difftool.c                  |   1 +
 builtin/fast-import.c               |   1 +
 builtin/fetch.c                     |   1 +
 builtin/fsmonitor--daemon.c         |   1 +
 builtin/gc.c                        |   1 +
 builtin/index-pack.c                |   1 +
 builtin/init-db.c                   |   1 +
 builtin/log.c                       |   1 +
 builtin/mailinfo.c                  |   1 +
 builtin/multi-pack-index.c          |   1 +
 builtin/mv.c                        |   1 +
 builtin/name-rev.c                  |   1 +
 builtin/pack-objects.c              |   1 +
 builtin/prune.c                     |   1 +
 builtin/push.c                      |   1 +
 builtin/rebase.c                    |   1 +
 builtin/receive-pack.c              |   1 +
 builtin/repack.c                    |   1 +
 builtin/replace.c                   |   1 +
 builtin/reset.c                     |   1 +
 builtin/rev-list.c                  |   1 +
 builtin/rev-parse.c                 |   1 +
 builtin/shortlog.c                  |   1 +
 builtin/show-branch.c               |   1 +
 builtin/sparse-checkout.c           |   1 +
 builtin/stash.c                     |   1 +
 builtin/submodule--helper.c         |   1 +
 builtin/unpack-objects.c            |   1 +
 builtin/update-index.c              |   1 +
 builtin/worktree.c                  |   1 +
 builtin/write-tree.c                |   1 +
 bulk-checkin.c                      |   1 +
 bundle-uri.c                        |   1 +
 bundle.c                            |   1 +
 cache-tree.c                        |   1 +
 cache.h                             | 207 ---------------------------
 combine-diff.c                      |   1 +
 compat/mingw.c                      |   1 +
 compat/precompose_utf8.c            |   1 +
 connect.c                           |   1 +
 daemon.c                            |   1 +
 diff.c                              |   1 +
 dir.c                               |   1 +
 editor.c                            |   1 +
 entry.c                             |   1 +
 environment.h                       | 213 ++++++++++++++++++++++++++++
 exec-cmd.c                          |   1 +
 fetch-pack.c                        |   1 +
 fsmonitor.c                         |   1 +
 gettext.c                           |   1 +
 git.c                               |   1 +
 http-backend.c                      |   1 +
 http-push.c                         |   1 +
 log-tree.c                          |   1 +
 ls-refs.c                           |   1 +
 mailmap.c                           |   1 +
 merge-ort.c                         |   1 +
 merge-recursive.c                   |   1 +
 name-hash.c                         |   1 +
 notes-utils.c                       |   1 +
 notes.c                             |   1 +
 object-file.c                       |   1 +
 object-name.c                       |   1 +
 pack-bitmap-write.c                 |   1 +
 pack-check.c                        |   1 +
 pack-write.c                        |   1 +
 packfile.c                          |   1 +
 parse-options-cb.c                  |   1 +
 path.c                              |   1 +
 pathspec.c                          |   1 +
 preload-index.c                     |   1 +
 pretty.c                            |   1 +
 prompt.c                            |   1 +
 protocol.c                          |   1 +
 prune-packed.c                      |   1 +
 range-diff.c                        |   1 +
 read-cache.c                        |   1 +
 rebase-interactive.c                |   1 +
 ref-filter.c                        |   1 +
 refs.c                              |   1 +
 refs/files-backend.c                |   1 +
 remote-curl.c                       |   1 +
 remote.c                            |   1 +
 revision.c                          |   1 +
 run-command.c                       |   1 +
 server-info.c                       |   1 +
 setup.c                             |   1 +
 sparse-index.c                      |   1 +
 streaming.c                         |   1 +
 submodule-config.c                  |   1 +
 submodule.c                         |   1 +
 t/helper/test-fast-rebase.c         |   1 +
 t/helper/test-lazy-init-name-hash.c |   1 +
 t/helper/test-path-utils.c          |   1 +
 t/helper/test-repository.c          |   1 +
 tag.c                               |   1 +
 tmp-objdir.c                        |   1 +
 trace.c                             |   1 +
 transport-helper.c                  |   1 +
 transport.c                         |   1 +
 unpack-trees.c                      |   1 +
 upload-pack.c                       |   1 +
 worktree.c                          |   1 +
 119 files changed, 330 insertions(+), 207 deletions(-)

diff --git a/apply.c b/apply.c
index 373565a7baf..a7c0bccb15c 100644
--- a/apply.c
+++ b/apply.c
@@ -16,6 +16,7 @@
 #include "delta.h"
 #include "diff.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "xdiff-interface.h"
diff --git a/archive.c b/archive.c
index c3c45a5ebe9..7aeaaf368f4 100644
--- a/archive.c
+++ b/archive.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/attr.c b/attr.c
index 48e2d646187..62127196cb1 100644
--- a/attr.c
+++ b/attr.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "attr.h"
 #include "dir.h"
diff --git a/bisect.c b/bisect.c
index 5a3a8182d83..8a4be05dc52 100644
--- a/bisect.c
+++ b/bisect.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/branch.c b/branch.c
index fced5342d5d..ebfdc18dce4 100644
--- a/branch.c
+++ b/branch.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "branch.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/am.c b/builtin/am.c
index 37f82b3eb42..192968ac300 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "builtin.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 2db46b04c97..58e6816d8e5 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 21f6b523a6d..9ec82edcbde 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9f1bf8f0e96..365d9234bdb 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "ident.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index ad27255e2cb..5870c4683ab 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "attr.h"
+#include "environment.h"
 #include "gettext.h"
 #include "quote.h"
 #include "parse-options.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 3c7ff60b923..e2daad4065c 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "diff.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "hook.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index b94324ea02c..15dc15408ed 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 311e0106810..90114269761 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/config.c b/builtin/config.c
index 1c1e006ff3f..cf994a216c0 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -3,6 +3,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "color.h"
+#include "environment.h"
 #include "gettext.h"
 #include "ident.h"
 #include "parse-options.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 48edc86c240..f3d8f1bcbb0 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "builtin.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index fcacdf8a693..27c6670e934 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 59465c39f1d..3613de6389f 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -17,6 +17,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "run-command.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 3300b7f30f0..068843a5d21 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index c266b6ab4dd..29ec2e7a81f 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 4efb1417344..a280d8bb14f 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "fsmonitor.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 2107e3d1f2c..525c5de5b27 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -12,6 +12,7 @@
 
 #include "builtin.h"
 #include "abspath.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2393897cb88..fdce8f88724 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "delta.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pack.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index a5d4f5c8ece..2ebc9023f56 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "builtin.h"
diff --git a/builtin/log.c b/builtin/log.c
index 639d8e90951..b7b6dfbd1d1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index e14f7c0abce..a032a1c3881 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
 #include "strbuf.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 579bc2cac0c..1b5083f8b26 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 0a49bf21b0f..c2dd42efbf2 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "pathspec.h"
 #include "lockfile.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 6977a5f580b..66f82ef66f4 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b55a088a7c..9829b952c2b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index ff62a0adb8f..5a381fcdf9a 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/builtin/push.c b/builtin/push.c
index 2d76fa68376..fa550b8f80a 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "branch.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index d2f8f703d67..9f3135116ed 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -7,6 +7,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e954c85ce3d..3e9c5037b19 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "repository.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 771ca01527d..ccbd5f55562 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index cf85e590d9f..dc0331defc2 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 6487cf694f5..0b62c9651e6 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -10,6 +10,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index f2f6a0d3e67..b202647f281 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index a4c0878bc91..bba49d56b9f 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -9,6 +9,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index d8c4379ea16..31f81c25ea2 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
 #include "revision.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 8d569629726..c4aa0e62f26 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pretty.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 3976d8e86b8..f6a120c7c45 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "pathspec.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 52fa892f7eb..94f81d75d03 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ff1fd8c87ab..2bf2a1a8be5 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f7c4b531076..c65ae3b2078 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ef78b2d28e1..4642afaeb77 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 1533b4ab43c..d9345efdb2b 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 7eec4e3cbd1..6085f64d100 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 778ca1e0f4f..eb6d7a2805b 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 2cc7d159bd6..1ff1cf51dad 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "bundle-uri.h"
 #include "bundle.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "refs.h"
diff --git a/bundle.c b/bundle.c
index f5b3643b17e..efeaf6f7151 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "lockfile.h"
 #include "bundle.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/cache-tree.c b/cache-tree.c
index 6f899beb041..231c3eb2ff6 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tree.h"
diff --git a/cache.h b/cache.h
index 31c722533f9..720c88f9fd6 100644
--- a/cache.h
+++ b/cache.h
@@ -452,98 +452,10 @@ static inline enum object_type object_type(unsigned int mode)
 		OBJ_BLOB;
 }
 
-/* Double-check local_repo_env below if you add to this list. */
-#define GIT_DIR_ENVIRONMENT "GIT_DIR"
-#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR"
-#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
-#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
-#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
-#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
-#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
-#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
-#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
-#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"
-#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
-#define CONFIG_ENVIRONMENT "GIT_CONFIG"
-#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
-#define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT"
-#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
-#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
-#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
-#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
-#define GITATTRIBUTES_FILE ".gitattributes"
-#define INFOATTRIBUTES_FILE "info/attributes"
-#define ATTRIBUTE_MACRO_PREFIX "[attr]"
-#define GITMODULES_FILE ".gitmodules"
-#define GITMODULES_INDEX ":.gitmodules"
-#define GITMODULES_HEAD "HEAD:.gitmodules"
-#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
-#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
-#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"
-#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF"
-#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"
-#define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS"
-#define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS"
-#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
-#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
-#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
-#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
-#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
-
-/*
- * Environment variable used in handshaking the wire protocol.
- * Contains a colon ':' separated list of keys with optional values
- * 'key[=value]'.  Presence of unknown keys and values must be
- * ignored.
- */
-#define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL"
-/* HTTP header used to handshake the wire protocol */
-#define GIT_PROTOCOL_HEADER "Git-Protocol"
-
-/*
- * This environment variable is expected to contain a boolean indicating
- * whether we should or should not treat:
- *
- *   GIT_DIR=foo.git git ...
- *
- * as if GIT_WORK_TREE=. was given. It's not expected that users will make use
- * of this, but we use it internally to communicate to sub-processes that we
- * are in a bare repo. If not set, defaults to true.
- */
-#define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE"
-
-/*
- * Repository-local GIT_* environment variables; these will be cleared
- * when git spawns a sub-process that runs inside another repository.
- * The array is NULL-terminated, which makes it easy to pass in the "env"
- * parameter of a run-command invocation, or to do a simple walk.
- */
-extern const char * const local_repo_env[];
-
-void setup_git_env(const char *git_dir);
-
-/*
- * Returns true iff we have a configured git repository (either via
- * setup_git_directory, or in the environment via $GIT_DIR).
- */
-int have_git_dir(void);
-
-extern int is_bare_repository_cfg;
-int is_bare_repository(void);
 int is_inside_git_dir(void);
-extern char *git_work_tree_cfg;
 int is_inside_work_tree(void);
-const char *get_git_dir(void);
-const char *get_git_common_dir(void);
-const char *get_object_directory(void);
-char *get_index_file(void);
-char *get_graft_file(struct repository *r);
-void set_git_dir(const char *path, int make_realpath);
 int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
 int get_common_dir(struct strbuf *sb, const char *gitdir);
-const char *get_git_namespace(void);
-const char *strip_namespace(const char *namespaced_ref);
-const char *get_git_work_tree(void);
 
 /*
  * Return true if the given path is a git directory; note that this _just_
@@ -578,10 +490,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code);
 const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
 #define resolve_gitdir(path) resolve_gitdir_gently((path), NULL)
 
-void set_git_work_tree(const char *tree);
-
-#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
-
 void setup_work_tree(void);
 /*
  * Find the commondir and gitdir of the repository that contains the current
@@ -840,39 +748,7 @@ void set_alternate_index_output(const char *);
 extern int verify_index_checksum;
 extern int verify_ce_order;
 
-/* Environment bits from configuration mechanism */
-extern int trust_executable_bit;
-extern int trust_ctime;
-extern int check_stat;
 extern int quote_path_fully;
-extern int has_symlinks;
-extern int minimum_abbrev, default_abbrev;
-extern int ignore_case;
-extern int assume_unchanged;
-extern int prefer_symlink_refs;
-extern int warn_ambiguous_refs;
-extern int warn_on_object_refname_ambiguity;
-extern char *apply_default_whitespace;
-extern char *apply_default_ignorewhitespace;
-extern const char *git_attributes_file;
-extern const char *git_hooks_path;
-extern int zlib_compression_level;
-extern int pack_compression_level;
-extern size_t packed_git_window_size;
-extern size_t packed_git_limit;
-extern size_t delta_base_cache_limit;
-extern unsigned long big_file_threshold;
-extern unsigned long pack_size_limit_cfg;
-
-/*
- * Accessors for the core.sharedrepository config which lazy-load the value
- * from the config (if not already set). The "reset" function can be
- * used to unset "set" or cached value, meaning that the value will be loaded
- * fresh from the config file on the next call to get_shared_repository().
- */
-void set_shared_repository(int value);
-int get_shared_repository(void);
-void reset_shared_repository(void);
 
 /*
  * These values are used to help identify parts of a repository to fsync.
@@ -930,57 +806,6 @@ enum fsync_method {
 };
 
 extern enum fsync_method fsync_method;
-extern int core_preload_index;
-extern int precomposed_unicode;
-extern int protect_hfs;
-extern int protect_ntfs;
-
-extern int core_apply_sparse_checkout;
-extern int core_sparse_checkout_cone;
-extern int sparse_expect_files_outside_of_patterns;
-
-/*
- * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
- */
-int use_optional_locks(void);
-
-enum log_refs_config {
-	LOG_REFS_UNSET = -1,
-	LOG_REFS_NONE = 0,
-	LOG_REFS_NORMAL,
-	LOG_REFS_ALWAYS
-};
-extern enum log_refs_config log_all_ref_updates;
-
-enum rebase_setup_type {
-	AUTOREBASE_NEVER = 0,
-	AUTOREBASE_LOCAL,
-	AUTOREBASE_REMOTE,
-	AUTOREBASE_ALWAYS
-};
-
-enum push_default_type {
-	PUSH_DEFAULT_NOTHING = 0,
-	PUSH_DEFAULT_MATCHING,
-	PUSH_DEFAULT_SIMPLE,
-	PUSH_DEFAULT_UPSTREAM,
-	PUSH_DEFAULT_CURRENT,
-	PUSH_DEFAULT_UNSPECIFIED
-};
-
-extern enum rebase_setup_type autorebase;
-extern enum push_default_type push_default;
-
-enum object_creation_mode {
-	OBJECT_CREATION_USES_HARDLINKS = 0,
-	OBJECT_CREATION_USES_RENAMES = 1
-};
-
-extern enum object_creation_mode object_creation_mode;
-
-extern char *notes_ref_name;
-
-extern int grafts_replace_parents;
 
 /*
  * GIT_REPO_VERSION is the version we write by default. The
@@ -989,8 +814,6 @@ extern int grafts_replace_parents;
  */
 #define GIT_REPO_VERSION 0
 #define GIT_REPO_VERSION_READ 1
-extern int repository_format_precious_objects;
-extern int repository_format_worktree_config;
 
 /*
  * You _have_ to initialize a `struct repository_format` using
@@ -1362,21 +1185,6 @@ struct pack_entry {
 	struct packed_git *p;
 };
 
-/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
- * usual "XXXXXX" trailer, and the resulting filename is written into the
- * "template" buffer. Returns the open descriptor.
- */
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
-
-/*
- * Create a pack .keep file named "name" (which should generally be the output
- * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
- * error.
- */
-int odb_pack_keep(const char *name);
-
 /*
  * Set this to 0 to prevent oid_object_info_extended() from fetching missing
  * blobs. This has a difference only if extensions.partialClone is set.
@@ -1388,11 +1196,6 @@ extern int fetch_if_missing;
 /* Dumb servers support */
 int update_server_info(int);
 
-const char *get_log_output_encoding(void);
-const char *get_commit_output_encoding(void);
-
-extern const char *git_commit_encoding;
-extern const char *git_log_output_encoding;
 extern const char *git_mailmap_file;
 extern const char *git_mailmap_blob;
 
@@ -1429,10 +1232,6 @@ int decimal_width(uintmax_t);
 int check_pager_config(const char *cmd);
 void prepare_pager_args(struct child_process *, const char *pager);
 
-extern const char *editor_program;
-extern const char *askpass_program;
-extern const char *excludes_file;
-
 /* base85 */
 int decode_85(char *dst, const char *line, int linelen);
 void encode_85(char *buf, const unsigned char *data, int bytes);
@@ -1536,10 +1335,4 @@ void stat_validity_update(struct stat_validity *sv, int fd);
 
 int versioncmp(const char *s1, const char *s2);
 
-/*
- * Should we print an ellipsis after an abbreviated SHA-1 value
- * when doing diff-raw output or indicating a detached HEAD?
- */
-int print_sha1_ellipsis(void);
-
 #endif /* CACHE_H */
diff --git a/combine-diff.c b/combine-diff.c
index 91051dc3258..3758e47c4f4 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -4,6 +4,7 @@
 #include "blob.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "environment.h"
 #include "hex.h"
 #include "quote.h"
 #include "xdiff-interface.h"
diff --git a/compat/mingw.c b/compat/mingw.c
index d48899bf7b4..94c5a1daa40 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -11,6 +11,7 @@
 #include "../alloc.h"
 #include "win32/lazyload.h"
 #include "../config.h"
+#include "../environment.h"
 #include "../wrapper.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 56d36cdf22a..8a9881db077 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
diff --git a/connect.c b/connect.c
index 1dab0d79c48..9fe01446bc5 100644
--- a/connect.c
+++ b/connect.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pkt-line.h"
diff --git a/daemon.c b/daemon.c
index e35604e194c..b56a8f9717d 100644
--- a/daemon.c
+++ b/daemon.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "pkt-line.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/diff.c b/diff.c
index 1b0b24c21c3..dcf1a940942 100644
--- a/diff.c
+++ b/diff.c
@@ -5,6 +5,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "tempfile.h"
 #include "quote.h"
diff --git a/dir.c b/dir.c
index b57c770e68b..06f8aa3c01b 100644
--- a/dir.c
+++ b/dir.c
@@ -10,6 +10,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/editor.c b/editor.c
index 2d3e6be64e4..d632d790660 100644
--- a/editor.c
+++ b/editor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "strbuf.h"
 #include "strvec.h"
diff --git a/entry.c b/entry.c
index 70212af260b..750c1f6b2f4 100644
--- a/entry.c
+++ b/entry.c
@@ -2,6 +2,7 @@
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "streaming.h"
diff --git a/environment.h b/environment.h
index a26931556af..a63f0c6a24f 100644
--- a/environment.h
+++ b/environment.h
@@ -3,6 +3,8 @@
 
 #include "strvec.h"
 
+struct repository;
+
 /*
  * The character that begins a commented line in user-editable file
  * that is subject to stripspace.
@@ -16,4 +18,215 @@ extern int auto_comment_line_char;
  */
 const char *getenv_safe(struct strvec *argv, const char *name);
 
+/* Double-check local_repo_env below if you add to this list. */
+#define GIT_DIR_ENVIRONMENT "GIT_DIR"
+#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR"
+#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
+#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
+#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
+#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
+#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
+#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
+#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
+#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"
+#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
+#define CONFIG_ENVIRONMENT "GIT_CONFIG"
+#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
+#define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT"
+#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
+#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
+#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
+#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
+#define GITATTRIBUTES_FILE ".gitattributes"
+#define INFOATTRIBUTES_FILE "info/attributes"
+#define ATTRIBUTE_MACRO_PREFIX "[attr]"
+#define GITMODULES_FILE ".gitmodules"
+#define GITMODULES_INDEX ":.gitmodules"
+#define GITMODULES_HEAD "HEAD:.gitmodules"
+#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
+#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
+#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"
+#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF"
+#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"
+#define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS"
+#define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS"
+#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
+#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
+#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
+#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
+#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
+
+/*
+ * Environment variable used in handshaking the wire protocol.
+ * Contains a colon ':' separated list of keys with optional values
+ * 'key[=value]'.  Presence of unknown keys and values must be
+ * ignored.
+ */
+#define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL"
+/* HTTP header used to handshake the wire protocol */
+#define GIT_PROTOCOL_HEADER "Git-Protocol"
+
+/*
+ * This environment variable is expected to contain a boolean indicating
+ * whether we should or should not treat:
+ *
+ *   GIT_DIR=foo.git git ...
+ *
+ * as if GIT_WORK_TREE=. was given. It's not expected that users will make use
+ * of this, but we use it internally to communicate to sub-processes that we
+ * are in a bare repo. If not set, defaults to true.
+ */
+#define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE"
+
+/*
+ * Repository-local GIT_* environment variables; these will be cleared
+ * when git spawns a sub-process that runs inside another repository.
+ * The array is NULL-terminated, which makes it easy to pass in the "env"
+ * parameter of a run-command invocation, or to do a simple walk.
+ */
+extern const char * const local_repo_env[];
+
+void setup_git_env(const char *git_dir);
+
+/*
+ * Returns true iff we have a configured git repository (either via
+ * setup_git_directory, or in the environment via $GIT_DIR).
+ */
+int have_git_dir(void);
+
+extern int is_bare_repository_cfg;
+int is_bare_repository(void);
+extern char *git_work_tree_cfg;
+const char *get_git_dir(void);
+const char *get_git_common_dir(void);
+const char *get_object_directory(void);
+char *get_index_file(void);
+char *get_graft_file(struct repository *r);
+void set_git_dir(const char *path, int make_realpath);
+const char *get_git_namespace(void);
+const char *strip_namespace(const char *namespaced_ref);
+const char *get_git_work_tree(void);
+void set_git_work_tree(const char *tree);
+
+#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
+
+/* Environment bits from configuration mechanism */
+extern int trust_executable_bit;
+extern int trust_ctime;
+extern int check_stat;
+extern int has_symlinks;
+extern int minimum_abbrev, default_abbrev;
+extern int ignore_case;
+extern int assume_unchanged;
+extern int prefer_symlink_refs;
+extern int warn_ambiguous_refs;
+extern int warn_on_object_refname_ambiguity;
+extern char *apply_default_whitespace;
+extern char *apply_default_ignorewhitespace;
+extern const char *git_attributes_file;
+extern const char *git_hooks_path;
+extern int zlib_compression_level;
+extern int pack_compression_level;
+extern size_t packed_git_window_size;
+extern size_t packed_git_limit;
+extern size_t delta_base_cache_limit;
+extern unsigned long big_file_threshold;
+extern unsigned long pack_size_limit_cfg;
+
+/*
+ * Accessors for the core.sharedrepository config which lazy-load the value
+ * from the config (if not already set). The "reset" function can be
+ * used to unset "set" or cached value, meaning that the value will be loaded
+ * fresh from the config file on the next call to get_shared_repository().
+ */
+void set_shared_repository(int value);
+int get_shared_repository(void);
+void reset_shared_repository(void);
+
+extern int core_preload_index;
+extern int precomposed_unicode;
+extern int protect_hfs;
+extern int protect_ntfs;
+
+extern int core_apply_sparse_checkout;
+extern int core_sparse_checkout_cone;
+extern int sparse_expect_files_outside_of_patterns;
+
+/*
+ * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
+ */
+int use_optional_locks(void);
+
+enum log_refs_config {
+	LOG_REFS_UNSET = -1,
+	LOG_REFS_NONE = 0,
+	LOG_REFS_NORMAL,
+	LOG_REFS_ALWAYS
+};
+extern enum log_refs_config log_all_ref_updates;
+
+enum rebase_setup_type {
+	AUTOREBASE_NEVER = 0,
+	AUTOREBASE_LOCAL,
+	AUTOREBASE_REMOTE,
+	AUTOREBASE_ALWAYS
+};
+
+enum push_default_type {
+	PUSH_DEFAULT_NOTHING = 0,
+	PUSH_DEFAULT_MATCHING,
+	PUSH_DEFAULT_SIMPLE,
+	PUSH_DEFAULT_UPSTREAM,
+	PUSH_DEFAULT_CURRENT,
+	PUSH_DEFAULT_UNSPECIFIED
+};
+
+extern enum rebase_setup_type autorebase;
+extern enum push_default_type push_default;
+
+enum object_creation_mode {
+	OBJECT_CREATION_USES_HARDLINKS = 0,
+	OBJECT_CREATION_USES_RENAMES = 1
+};
+
+extern enum object_creation_mode object_creation_mode;
+
+extern char *notes_ref_name;
+
+extern int grafts_replace_parents;
+
+extern int repository_format_precious_objects;
+extern int repository_format_worktree_config;
+
+/*
+ * Create a temporary file rooted in the object database directory, or
+ * die on failure. The filename is taken from "pattern", which should have the
+ * usual "XXXXXX" trailer, and the resulting filename is written into the
+ * "template" buffer. Returns the open descriptor.
+ */
+int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+
+/*
+ * Create a pack .keep file named "name" (which should generally be the output
+ * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
+ * error.
+ */
+int odb_pack_keep(const char *name);
+
+const char *get_log_output_encoding(void);
+const char *get_commit_output_encoding(void);
+
+extern const char *git_commit_encoding;
+extern const char *git_log_output_encoding;
+
+extern const char *editor_program;
+extern const char *askpass_program;
+extern const char *excludes_file;
+
+/*
+ * Should we print an ellipsis after an abbreviated SHA-1 value
+ * when doing diff-raw output or indicating a detached HEAD?
+ */
+int print_sha1_ellipsis(void);
+
 #endif
diff --git a/exec-cmd.c b/exec-cmd.c
index 042d9247a5b..fae0d4b244a 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "quote.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index c1190801405..c453a4168f9 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/fsmonitor.c b/fsmonitor.c
index a5b9e75437b..c956a347a27 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "fsmonitor-ipc.h"
diff --git a/gettext.c b/gettext.c
index 3e7b3baabc6..85d3d3424eb 100644
--- a/gettext.c
+++ b/gettext.c
@@ -4,6 +4,7 @@
 
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/git.c b/git.c
index 22ce4f14b65..b24c105e83f 100644
--- a/git.c
+++ b/git.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "help.h"
diff --git a/http-backend.c b/http-backend.c
index 42e6c2596e9..042ccf12e8c 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/http-push.c b/http-push.c
index 88aa045ecba..40373bc4863 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/log-tree.c b/log-tree.c
index 3adcb576e4c..e2bf8d6df75 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -2,6 +2,7 @@
 #include "commit-reach.h"
 #include "config.h"
 #include "diff.h"
+#include "environment.h"
 #include "hex.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/ls-refs.c b/ls-refs.c
index ae38889bf04..12cbb40a198 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/mailmap.c b/mailmap.c
index da2589b0822..2c6e9b238dd 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-store.h"
diff --git a/merge-ort.c b/merge-ort.c
index a26cad5f910..f3d7c202f52 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -26,6 +26,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "entry.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index f918cea4c69..d5f37724911 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -17,6 +17,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "ll-merge.h"
diff --git a/name-hash.c b/name-hash.c
index bb9eae55aca..2c2861efd1c 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2008 Linus Torvalds
  */
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "thread-utils.h"
 #include "trace2.h"
diff --git a/notes-utils.c b/notes-utils.c
index da08e2e8e5c..8797271faf1 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "notes-utils.h"
diff --git a/notes.c b/notes.c
index a7187236e98..9288c1a0705 100644
--- a/notes.c
+++ b/notes.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "notes.h"
 #include "object-store.h"
diff --git a/object-file.c b/object-file.c
index bdf68763a50..3da6cd68861 100644
--- a/object-file.c
+++ b/object-file.c
@@ -10,6 +10,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "string-list.h"
diff --git a/object-name.c b/object-name.c
index 2c927bbded3..3b0ce8ef05a 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tag.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7dc7f0ba55e..63f16080c9b 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/pack-check.c b/pack-check.c
index 7ed594d6679..6974e40a958 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "pack.h"
diff --git a/pack-write.c b/pack-write.c
index 87156f89d2b..f1714054951 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pack.h"
diff --git a/packfile.c b/packfile.c
index 0fe844f2075..cc3b1e242c7 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "list.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index fbf4b010195..15d008c3daf 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "color.h"
+#include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
 #include "strvec.h"
diff --git a/path.c b/path.c
index 3976c0d7ace..5d5a15c13d6 100644
--- a/path.c
+++ b/path.c
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/pathspec.c b/pathspec.c
index 53763e272f5..5fb7b5f26c9 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
diff --git a/preload-index.c b/preload-index.c
index 4b45e1d6912..52544d004e7 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "environment.h"
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "config.h"
diff --git a/pretty.c b/pretty.c
index 9d7922dcc60..2b6d0f52c9f 100644
--- a/pretty.c
+++ b/pretty.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "utf8.h"
diff --git a/prompt.c b/prompt.c
index 50df17279d1..ba10813b313 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "prompt.h"
diff --git a/protocol.c b/protocol.c
index c53f7df5be4..bdb32e1eeb6 100644
--- a/protocol.c
+++ b/protocol.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "protocol.h"
 
 static enum protocol_version parse_protocol_version(const char *value)
diff --git a/prune-packed.c b/prune-packed.c
index cff5ad569c7..5a57072a7ac 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/range-diff.c b/range-diff.c
index 1bfc612e274..815fb24c9ce 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "range-diff.h"
 #include "string-list.h"
diff --git a/read-cache.c b/read-cache.c
index 9a8d5fe97ed..34567c1d550 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -18,6 +18,7 @@
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
+#include "environment.h"
 #include "gettext.h"
 #include "resolve-undo.h"
 #include "run-command.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 7c885c35bfd..a83334dd564 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "sequencer.h"
 #include "rebase-interactive.h"
diff --git a/ref-filter.c b/ref-filter.c
index 9a830bedef0..1489fbfe4ae 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/refs.c b/refs.c
index 385051752f1..04520e5a6b8 100644
--- a/refs.c
+++ b/refs.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "hashmap.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index eb14d124e3f..0c3138ede8f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,5 +1,6 @@
 #include "../cache.h"
 #include "../config.h"
+#include "../environment.h"
 #include "../gettext.h"
 #include "../hex.h"
 #include "../refs.h"
diff --git a/remote-curl.c b/remote-curl.c
index 943cd6fe6cd..eb382a1e35d 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "remote.h"
diff --git a/remote.c b/remote.c
index 2bae247a0a4..aeca3ff8136 100644
--- a/remote.c
+++ b/remote.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "remote.h"
diff --git a/revision.c b/revision.c
index 7423e23327b..53fdeef0787 100644
--- a/revision.c
+++ b/revision.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/run-command.c b/run-command.c
index 2c8b4cd9bfc..614d48fa9a2 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "run-command.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "sigchain.h"
diff --git a/server-info.c b/server-info.c
index ae96d784e53..355b6e01a52 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/setup.c b/setup.c
index 8f385d9f29b..cfdc849a78c 100644
--- a/setup.c
+++ b/setup.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "config.h"
diff --git a/sparse-index.c b/sparse-index.c
index fdae9011b8e..886054729e5 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "sparse-index.h"
diff --git a/streaming.c b/streaming.c
index 6c69f595045..024fd796b7d 100644
--- a/streaming.c
+++ b/streaming.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2011, Google Inc.
  */
 #include "cache.h"
+#include "environment.h"
 #include "streaming.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/submodule-config.c b/submodule-config.c
index 38663801aa4..28fdfddccfb 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/submodule.c b/submodule.c
index 13ff333f68c..acf030b95e4 100644
--- a/submodule.c
+++ b/submodule.c
@@ -8,6 +8,7 @@
 #include "dir.h"
 #include "diff.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 68bbc41b330..627a6bdc3d0 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -15,6 +15,7 @@
 #include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index ab86c14c8ba..2b678a45793 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "cache.h"
+#include "environment.h"
 #include "parse-options.h"
 
 static int single;
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index d3d00dc34fa..cc266e3ec09 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "string-list.h"
 #include "utf8.h"
 
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 10a6dfc2160..c444775eb0f 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -3,6 +3,7 @@
 #include "commit-graph.h"
 #include "commit.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "object-store.h"
 #include "object.h"
diff --git a/tag.c b/tag.c
index 3408bb9433f..39434231799 100644
--- a/tag.c
+++ b/tag.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "tag.h"
 #include "object-store.h"
 #include "commit.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index fff15cb6b5c..5adad1925d1 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -3,6 +3,7 @@
 #include "abspath.h"
 #include "chdir-notify.h"
 #include "dir.h"
+#include "environment.h"
 #include "sigchain.h"
 #include "string-list.h"
 #include "strbuf.h"
diff --git a/trace.c b/trace.c
index de004f62988..9c85b71ec6a 100644
--- a/trace.c
+++ b/trace.c
@@ -23,6 +23,7 @@
 
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "quote.h"
 #include "wrapper.h"
 
diff --git a/transport-helper.c b/transport-helper.c
index 09048eab484..3313bb74099 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -4,6 +4,7 @@
 #include "run-command.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/transport.c b/transport.c
index c6179b801e8..4f06ccbee05 100644
--- a/transport.c
+++ b/transport.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "transport.h"
 #include "hook.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 84e0d2e8afe..0ff4bbc6b96 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/upload-pack.c b/upload-pack.c
index eea9e6a6e8c..1155f795382 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/worktree.c b/worktree.c
index 64c96605e53..3861ab639ca 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "refs.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 12/16] treewide: remove cache.h inclusion due to environment.h changes
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (10 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 11/16] environment.h: move declarations for environment.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:27 ` [PATCH 13/16] setup.h: move declarations for setup.c functions from cache.h Elijah Newren via GitGitGadget
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 csum-file.c            | 2 +-
 gettext.c              | 2 +-
 ls-refs.c              | 2 +-
 notes-utils.c          | 2 +-
 prompt.c               | 2 +-
 prune-packed.c         | 2 +-
 reachable.c            | 2 +-
 t/helper/test-bitmap.c | 2 +-
 trailer.c              | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/csum-file.c b/csum-file.c
index 2d22f80d901..82ae2973d30 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -7,7 +7,7 @@
  * files. Useful when you write a file that you want to be
  * able to verify hasn't been messed with afterwards.
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "progress.h"
 #include "csum-file.h"
 #include "wrapper.h"
diff --git a/gettext.c b/gettext.c
index 85d3d3424eb..5f348708300 100644
--- a/gettext.c
+++ b/gettext.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Ævar Arnfjörð Bjarmason
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/ls-refs.c b/ls-refs.c
index 12cbb40a198..b9f3e08ec3d 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/notes-utils.c b/notes-utils.c
index 8797271faf1..86552f31c4a 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
 #include "environment.h"
diff --git a/prompt.c b/prompt.c
index ba10813b313..3baa33f63d8 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
 #include "run-command.h"
diff --git a/prune-packed.c b/prune-packed.c
index 5a57072a7ac..58412b4fb91 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
diff --git a/reachable.c b/reachable.c
index b0f85046e9c..55bb1143530 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index ff35f5999b3..5bb489882da 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,5 +1,5 @@
 #include "test-tool.h"
-#include "cache.h"
+#include "git-compat-util.h"
 #include "pack-bitmap.h"
 
 static int bitmap_list_commits(void)
diff --git a/trailer.c b/trailer.c
index 6a5091a3c46..a2c3ed6f28c 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 13/16] setup.h: move declarations for setup.c functions from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (11 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 12/16] treewide: remove cache.h inclusion due to environment.h changes Elijah Newren via GitGitGadget
@ 2023-03-19  6:27 ` Elijah Newren via GitGitGadget
  2023-03-19  6:28 ` [PATCH 14/16] treewide: remove cache.h inclusion due to setup.h changes Elijah Newren via GitGitGadget
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:27 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                                      |   1 +
 archive.c                                    |   1 +
 attr.c                                       |   1 +
 blame.c                                      |   1 +
 builtin/blame.c                              |   1 +
 builtin/bugreport.c                          |   1 +
 builtin/bundle.c                             |   1 +
 builtin/check-attr.c                         |   1 +
 builtin/check-ref-format.c                   |   1 +
 builtin/checkout-index.c                     |   1 +
 builtin/checkout.c                           |   1 +
 builtin/clean.c                              |   1 +
 builtin/clone.c                              |   1 +
 builtin/config.c                             |   1 +
 builtin/describe.c                           |   1 +
 builtin/diff-index.c                         |   1 +
 builtin/diff.c                               |   1 +
 builtin/difftool.c                           |   1 +
 builtin/gc.c                                 |   1 +
 builtin/grep.c                               |   1 +
 builtin/hash-object.c                        |   1 +
 builtin/help.c                               |   1 +
 builtin/index-pack.c                         |   1 +
 builtin/init-db.c                            |   1 +
 builtin/ls-files.c                           |   1 +
 builtin/merge-file.c                         |   1 +
 builtin/mv.c                                 |   1 +
 builtin/read-tree.c                          |   1 +
 builtin/reset.c                              |   1 +
 builtin/rev-parse.c                          |   1 +
 builtin/rm.c                                 |   1 +
 builtin/shortlog.c                           |   1 +
 builtin/sparse-checkout.c                    |   1 +
 builtin/stash.c                              |   1 +
 builtin/stripspace.c                         |   1 +
 builtin/submodule--helper.c                  |   1 +
 builtin/update-index.c                       |   1 +
 cache.h                                      | 163 ------------------
 commit.c                                     |   1 +
 common-main.c                                |   1 +
 config.c                                     |   1 +
 daemon.c                                     |   1 +
 diff.c                                       |   1 +
 dir.c                                        |   1 +
 environment.c                                |   1 +
 git.c                                        |   1 +
 http-fetch.c                                 |   1 +
 http-push.c                                  |   1 +
 imap-send.c                                  |   1 +
 line-log.c                                   |   1 +
 mailmap.c                                    |   1 +
 object-file.c                                |   1 +
 object-name.c                                |   1 +
 path.c                                       |   1 +
 pathspec.c                                   |   1 +
 refs.c                                       |   1 +
 refs/files-backend.c                         |   1 +
 remote-curl.c                                |   1 +
 remote.c                                     |   1 +
 repository.c                                 |   1 +
 revision.c                                   |   1 +
 scalar.c                                     |   1 +
 setup.c                                      |   1 +
 setup.h                                      | 168 +++++++++++++++++++
 submodule.c                                  |   1 +
 symlinks.c                                   |   1 +
 t/helper/test-advise.c                       |   1 +
 t/helper/test-bitmap.c                       |   1 +
 t/helper/test-bloom.c                        |   1 +
 t/helper/test-cache-tree.c                   |   1 +
 t/helper/test-config.c                       |   1 +
 t/helper/test-dump-cache-tree.c              |   2 +-
 t/helper/test-dump-fsmonitor.c               |   1 +
 t/helper/test-dump-split-index.c             |   1 +
 t/helper/test-dump-untracked-cache.c         |   1 +
 t/helper/test-fast-rebase.c                  |   1 +
 t/helper/test-fsmonitor-client.c             |   1 +
 t/helper/test-lazy-init-name-hash.c          |   1 +
 t/helper/test-match-trees.c                  |   1 +
 t/helper/test-oid-array.c                    |   1 +
 t/helper/test-oidmap.c                       |   1 +
 t/helper/test-oidtree.c                      |   1 +
 t/helper/test-pack-mtimes.c                  |   1 +
 t/helper/test-partial-clone.c                |   1 +
 t/helper/test-path-utils.c                   |   1 +
 t/helper/test-proc-receive.c                 |   1 +
 t/helper/test-reach.c                        |   1 +
 t/helper/test-read-cache.c                   |   1 +
 t/helper/test-read-graph.c                   |   1 +
 t/helper/test-read-midx.c                    |   1 +
 t/helper/test-ref-store.c                    |   1 +
 t/helper/test-repository.c                   |   1 +
 t/helper/test-revision-walking.c             |   1 +
 t/helper/test-scrap-cache-tree.c             |   1 +
 t/helper/test-serve-v2.c                     |   1 +
 t/helper/test-submodule-config.c             |   1 +
 t/helper/test-submodule-nested-repo-config.c |   1 +
 t/helper/test-submodule.c                    |   1 +
 t/helper/test-subprocess.c                   |   1 +
 t/helper/test-userdiff.c                     |   1 +
 t/helper/test-write-cache.c                  |   1 +
 trace.c                                      |   1 +
 unpack-trees.c                               |   1 +
 worktree.c                                   |   1 +
 wt-status.c                                  |   1 +
 105 files changed, 271 insertions(+), 164 deletions(-)
 create mode 100644 setup.h

diff --git a/apply.c b/apply.c
index a7c0bccb15c..caa2e0a3bc6 100644
--- a/apply.c
+++ b/apply.c
@@ -27,6 +27,7 @@
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
+#include "setup.h"
 #include "wrapper.h"
 
 struct gitdiff_data {
diff --git a/archive.c b/archive.c
index 7aeaaf368f4..cdce5b783a7 100644
--- a/archive.c
+++ b/archive.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "setup.h"
 #include "refs.h"
 #include "object-store.h"
 #include "commit.h"
diff --git a/attr.c b/attr.c
index 62127196cb1..2d8aeb8b58c 100644
--- a/attr.c
+++ b/attr.c
@@ -18,6 +18,7 @@
 #include "quote.h"
 #include "revision.h"
 #include "object-store.h"
+#include "setup.h"
 #include "thread-utils.h"
 
 const char git_attr__true[] = "(builtin)true";
diff --git a/blame.c b/blame.c
index b7cd849bb6b..838eb128f01 100644
--- a/blame.c
+++ b/blame.c
@@ -7,6 +7,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "setup.h"
 #include "tag.h"
 #include "blame.h"
 #include "alloc.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 9ec82edcbde..fb271bae70e 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -31,6 +31,7 @@
 #include "object-store.h"
 #include "blame.h"
 #include "refs.h"
+#include "setup.h"
 #include "tag.h"
 
 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 160590e4ef6..52955e1d389 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -8,6 +8,7 @@
 #include "hook.h"
 #include "hook-list.h"
 #include "diagnose.h"
+#include "setup.h"
 #include "wrapper.h"
 
 static void get_system_info(struct strbuf *sys_info)
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 8ea1232dbce..9e4ae604580 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
+#include "setup.h"
 #include "strvec.h"
 #include "parse-options.h"
 #include "cache.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 5870c4683ab..ec37b8164af 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "quote.h"
+#include "setup.h"
 #include "parse-options.h"
 
 static int all_attrs;
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index fd0e5f86832..b0263467424 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "builtin.h"
+#include "setup.h"
 #include "strbuf.h"
 
 static const char builtin_check_ref_format_usage[] =
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 828c0363f8a..7df673e3e70 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "setup.h"
 
 #define CHECKOUT_ALL 4
 static int nul_term_line;
diff --git a/builtin/checkout.c b/builtin/checkout.c
index e2daad4065c..015011cf84d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -23,6 +23,7 @@
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "tree.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index fdcf62c5dfe..14c0d555eac 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "string-list.h"
 #include "quote.h"
 #include "column.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 15dc15408ed..34f46965b95 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -33,6 +33,7 @@
 #include "branch.h"
 #include "remote.h"
 #include "run-command.h"
+#include "setup.h"
 #include "connected.h"
 #include "packfile.h"
 #include "list-objects-filter-options.h"
diff --git a/builtin/config.c b/builtin/config.c
index cf994a216c0..fe79fb60c43 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -9,6 +9,7 @@
 #include "parse-options.h"
 #include "urlmatch.h"
 #include "quote.h"
+#include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 27c6670e934..43b62348bc7 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -15,6 +15,7 @@
 #include "revision.h"
 #include "diff.h"
 #include "hashmap.h"
+#include "setup.h"
 #include "strvec.h"
 #include "run-command.h"
 #include "object-store.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 35dc9b23eef..b9a19bb7d38 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -5,6 +5,7 @@
 #include "commit.h"
 #include "revision.h"
 #include "builtin.h"
+#include "setup.h"
 #include "submodule.h"
 
 static const char diff_cache_usage[] =
diff --git a/builtin/diff.c b/builtin/diff.c
index 20bdb6e6cec..3945683bfe4 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -19,6 +19,7 @@
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
+#include "setup.h"
 #include "submodule.h"
 #include "oid-array.h"
 
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 3613de6389f..176437d6da3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -28,6 +28,7 @@
 #include "object-store.h"
 #include "dir.h"
 #include "entry.h"
+#include "setup.h"
 #include "wrapper.h"
 
 static int trust_exit_code;
diff --git a/builtin/gc.c b/builtin/gc.c
index 525c5de5b27..a85f9e3ed3d 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -36,6 +36,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hook.h"
+#include "setup.h"
 #include "wrapper.h"
 
 #define FAILED_RUN "failed to run %s"
diff --git a/builtin/grep.c b/builtin/grep.c
index 3c9c6b38031..b8ebf014f40 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -23,6 +23,7 @@
 #include "quote.h"
 #include "dir.h"
 #include "pathspec.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "object-store.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 7651a7a5f56..a2e160db026 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -14,6 +14,7 @@
 #include "quote.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
+#include "setup.h"
 
 /*
  * This is to create corrupt objects for debugging and as such it
diff --git a/builtin/help.c b/builtin/help.c
index 3fde5c4fd35..87333a02ec4 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -11,6 +11,7 @@
 #include "config-list.h"
 #include "help.h"
 #include "alias.h"
+#include "setup.h"
 
 #ifndef DEFAULT_HELP_FORMAT
 #define DEFAULT_HELP_FORMAT "man"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index fdce8f88724..823dc5aefb5 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -20,6 +20,7 @@
 #include "object-store.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
+#include "setup.h"
 #include "wrapper.h"
 
 static const char index_pack_usage[] =
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 2ebc9023f56..ba6e0b20fa5 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "exec-cmd.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 09deb752ab3..4a8de95ddc4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -20,6 +20,7 @@
 #include "string-list.h"
 #include "pathspec.h"
 #include "run-command.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index c0096ee0810..781818d08f5 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
+#include "setup.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "parse-options.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index c2dd42efbf2..b7c5ffbd8c7 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -16,6 +16,7 @@
 #include "cache-tree.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "submodule.h"
 #include "entry.h"
 
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index ec66008d07e..5f24453dcd7 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -19,6 +19,7 @@
 #include "builtin.h"
 #include "parse-options.h"
 #include "resolve-undo.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/reset.c b/builtin/reset.c
index 0b62c9651e6..02891e35a84 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -26,6 +26,7 @@
 #include "parse-options.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "dir.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index bba49d56b9f..3a5a2ee5b2d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -18,6 +18,7 @@
 #include "parse-options.h"
 #include "diff.h"
 #include "revision.h"
+#include "setup.h"
 #include "split-index.h"
 #include "submodule.h"
 #include "commit-reach.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 5982c3d8122..97775e4c4d0 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -15,6 +15,7 @@
 #include "tree-walk.h"
 #include "parse-options.h"
 #include "string-list.h"
+#include "setup.h"
 #include "submodule.h"
 #include "pathspec.h"
 
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 31f81c25ea2..59d9c440fb5 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -9,6 +9,7 @@
 #include "revision.h"
 #include "utf8.h"
 #include "mailmap.h"
+#include "setup.h"
 #include "shortlog.h"
 #include "parse-options.h"
 #include "trailer.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index f6a120c7c45..512df0f8f54 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -16,6 +16,7 @@
 #include "unpack-trees.h"
 #include "wt-status.h"
 #include "quote.h"
+#include "setup.h"
 #include "sparse-index.h"
 #include "worktree.h"
 
diff --git a/builtin/stash.c b/builtin/stash.c
index 94f81d75d03..30d547fff1f 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -18,6 +18,7 @@
 #include "entry.h"
 #include "rerere.h"
 #include "revision.h"
+#include "setup.h"
 #include "log-tree.h"
 #include "diffcore.h"
 #include "exec-cmd.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index d8e61459333..53930458ffa 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "strbuf.h"
 
 static void comment_lines(struct strbuf *buf)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 2bf2a1a8be5..3cb4a3ce217 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -12,6 +12,7 @@
 #include "quote.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "string-list.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 4642afaeb77..f97f8d4c9d5 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -20,6 +20,7 @@
 #include "parse-options.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "setup.h"
 #include "split-index.h"
 #include "fsmonitor.h"
 
diff --git a/cache.h b/cache.h
index 720c88f9fd6..bffedd240e7 100644
--- a/cache.h
+++ b/cache.h
@@ -452,67 +452,6 @@ static inline enum object_type object_type(unsigned int mode)
 		OBJ_BLOB;
 }
 
-int is_inside_git_dir(void);
-int is_inside_work_tree(void);
-int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
-int get_common_dir(struct strbuf *sb, const char *gitdir);
-
-/*
- * Return true if the given path is a git directory; note that this _just_
- * looks at the directory itself. If you want to know whether "foo/.git"
- * is a repository, you must feed that path, not just "foo".
- */
-int is_git_directory(const char *path);
-
-/*
- * Return 1 if the given path is the root of a git repository or
- * submodule, else 0. Will not return 1 for bare repositories with the
- * exception of creating a bare repository in "foo/.git" and calling
- * is_git_repository("foo").
- *
- * If we run into read errors, we err on the side of saying "yes, it is",
- * as we usually consider sub-repos precious, and would prefer to err on the
- * side of not disrupting or deleting them.
- */
-int is_nonbare_repository_dir(struct strbuf *path);
-
-#define READ_GITFILE_ERR_STAT_FAILED 1
-#define READ_GITFILE_ERR_NOT_A_FILE 2
-#define READ_GITFILE_ERR_OPEN_FAILED 3
-#define READ_GITFILE_ERR_READ_FAILED 4
-#define READ_GITFILE_ERR_INVALID_FORMAT 5
-#define READ_GITFILE_ERR_NO_PATH 6
-#define READ_GITFILE_ERR_NOT_A_REPO 7
-#define READ_GITFILE_ERR_TOO_LARGE 8
-void read_gitfile_error_die(int error_code, const char *path, const char *dir);
-const char *read_gitfile_gently(const char *path, int *return_error_code);
-#define read_gitfile(path) read_gitfile_gently((path), NULL)
-const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
-#define resolve_gitdir(path) resolve_gitdir_gently((path), NULL)
-
-void setup_work_tree(void);
-/*
- * Find the commondir and gitdir of the repository that contains the current
- * working directory, without changing the working directory or other global
- * state. The result is appended to commondir and gitdir.  If the discovered
- * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
- * both have the same result appended to the buffer.  The return value is
- * either 0 upon success and non-zero if no repository was found.
- */
-int discover_git_directory(struct strbuf *commondir,
-			   struct strbuf *gitdir);
-const char *setup_git_directory_gently(int *);
-const char *setup_git_directory(void);
-char *prefix_path(const char *prefix, int len, const char *path);
-char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
-
-int check_filename(const char *prefix, const char *name);
-void verify_filename(const char *prefix,
-		     const char *name,
-		     int diagnose_misspelt_rev);
-void verify_non_filename(const char *prefix, const char *name);
-int path_inside_repo(const char *prefix, const char *path);
-
 #define INIT_DB_QUIET 0x0001
 #define INIT_DB_EXIST_OK 0x0002
 
@@ -521,9 +460,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *initial_branch, unsigned int flags);
 void initialize_repository_version(int hash_algo, int reinit);
 
-void sanitize_stdfds(void);
-int daemonize(void);
-
 /* Initialize and use the cache information */
 struct lock_file;
 void preload_index(struct index_state *index,
@@ -807,79 +743,6 @@ enum fsync_method {
 
 extern enum fsync_method fsync_method;
 
-/*
- * GIT_REPO_VERSION is the version we write by default. The
- * _READ variant is the highest number we know how to
- * handle.
- */
-#define GIT_REPO_VERSION 0
-#define GIT_REPO_VERSION_READ 1
-
-/*
- * You _have_ to initialize a `struct repository_format` using
- * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`.
- */
-struct repository_format {
-	int version;
-	int precious_objects;
-	char *partial_clone; /* value of extensions.partialclone */
-	int worktree_config;
-	int is_bare;
-	int hash_algo;
-	int sparse_index;
-	char *work_tree;
-	struct string_list unknown_extensions;
-	struct string_list v1_only_extensions;
-};
-
-/*
- * Always use this to initialize a `struct repository_format`
- * to a well-defined, default state before calling
- * `read_repository()`.
- */
-#define REPOSITORY_FORMAT_INIT \
-{ \
-	.version = -1, \
-	.is_bare = -1, \
-	.hash_algo = GIT_HASH_SHA1, \
-	.unknown_extensions = STRING_LIST_INIT_DUP, \
-	.v1_only_extensions = STRING_LIST_INIT_DUP, \
-}
-
-/*
- * Read the repository format characteristics from the config file "path" into
- * "format" struct. Returns the numeric version. On error, or if no version is
- * found in the configuration, -1 is returned, format->version is set to -1,
- * and all other fields in the struct are set to the default configuration
- * (REPOSITORY_FORMAT_INIT). Always initialize the struct using
- * REPOSITORY_FORMAT_INIT before calling this function.
- */
-int read_repository_format(struct repository_format *format, const char *path);
-
-/*
- * Free the memory held onto by `format`, but not the struct itself.
- * (No need to use this after `read_repository_format()` fails.)
- */
-void clear_repository_format(struct repository_format *format);
-
-/*
- * Verify that the repository described by repository_format is something we
- * can read. If it is, return 0. Otherwise, return -1, and "err" will describe
- * any errors encountered.
- */
-int verify_repository_format(const struct repository_format *format,
-			     struct strbuf *err);
-
-/*
- * Check the repository format version in the path found in get_git_dir(),
- * and die if it is a version we don't understand. Generally one would
- * set_git_dir() before calling this, and use it only for "are we in a valid
- * repo?".
- *
- * If successful and fmt is not NULL, fill fmt with data.
- */
-void check_repository_format(struct repository_format *fmt);
-
 #define MTIME_CHANGED	0x0001
 #define CTIME_CHANGED	0x0002
 #define OWNER_CHANGED	0x0004
@@ -908,23 +771,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id
 int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
 #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
-/*
- * NOTE NOTE NOTE!!
- *
- * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must
- * not be changed. Old repositories have core.sharedrepository written in
- * numeric format, and therefore these values are preserved for compatibility
- * reasons.
- */
-enum sharedrepo {
-	PERM_UMASK          = 0,
-	OLD_PERM_GROUP      = 1,
-	OLD_PERM_EVERYBODY  = 2,
-	PERM_GROUP          = 0660,
-	PERM_EVERYBODY      = 0664
-};
-int git_config_perm(const char *var, const char *value);
-
 /*
  * Create the directory containing the named path, using care to be
  * somewhat safe against races. Return one of the scld_error values to
@@ -1283,15 +1129,6 @@ int ws_blank_line(const char *line, int len);
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
 
-/* setup.c */
-struct startup_info {
-	int have_repository;
-	const char *prefix;
-	const char *original_cwd;
-};
-extern struct startup_info *startup_info;
-extern const char *tmp_original_cwd;
-
 /* merge.c */
 struct commit_list;
 int try_merge_command(struct repository *r,
diff --git a/commit.c b/commit.c
index f88fc5e1a2c..3868f047f1b 100644
--- a/commit.c
+++ b/commit.c
@@ -23,6 +23,7 @@
 #include "refs.h"
 #include "commit-reach.h"
 #include "run-command.h"
+#include "setup.h"
 #include "shallow.h"
 #include "hook.h"
 
diff --git a/common-main.c b/common-main.c
index 184d1534d2d..b83cb5cf066 100644
--- a/common-main.c
+++ b/common-main.c
@@ -2,6 +2,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "attr.h"
+#include "setup.h"
 
 /*
  * Many parts of Git have subprograms communicate via pipe, expect the
diff --git a/config.c b/config.c
index 5b1a5d52052..03a4fcaba5b 100644
--- a/config.c
+++ b/config.c
@@ -27,6 +27,7 @@
 #include "color.h"
 #include "replace-object.h"
 #include "refs.h"
+#include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/daemon.c b/daemon.c
index b56a8f9717d..db8a31a6ea2 100644
--- a/daemon.c
+++ b/daemon.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "pkt-line.h"
 #include "run-command.h"
+#include "setup.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "wrapper.h"
diff --git a/diff.c b/diff.c
index dcf1a940942..b858e59c5ae 100644
--- a/diff.c
+++ b/diff.c
@@ -33,6 +33,7 @@
 #include "help.h"
 #include "promisor-remote.h"
 #include "dir.h"
+#include "setup.h"
 #include "strmap.h"
 #include "wrapper.h"
 
diff --git a/dir.c b/dir.c
index 06f8aa3c01b..4cc2b1ead47 100644
--- a/dir.c
+++ b/dir.c
@@ -21,6 +21,7 @@
 #include "varint.h"
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "wrapper.h"
 
diff --git a/environment.c b/environment.c
index bf02f3cf487..649d16ac27c 100644
--- a/environment.c
+++ b/environment.c
@@ -22,6 +22,7 @@
 #include "replace-object.h"
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
+#include "setup.h"
 #include "shallow.h"
 #include "wrapper.h"
 
diff --git a/git.c b/git.c
index b24c105e83f..77f920a6f6f 100644
--- a/git.c
+++ b/git.c
@@ -7,6 +7,7 @@
 #include "run-command.h"
 #include "alias.h"
 #include "replace-object.h"
+#include "setup.h"
 #include "shallow.h"
 
 #define RUN_SETUP		(1<<0)
diff --git a/http-fetch.c b/http-fetch.c
index 454933351b2..c874d3402dd 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -5,6 +5,7 @@
 #include "hex.h"
 #include "http.h"
 #include "walker.h"
+#include "setup.h"
 #include "strvec.h"
 #include "urlmatch.h"
 #include "trace2.h"
diff --git a/http-push.c b/http-push.c
index 40373bc4863..e73864b51f5 100644
--- a/http-push.c
+++ b/http-push.c
@@ -12,6 +12,7 @@
 #include "exec-cmd.h"
 #include "remote.h"
 #include "list-objects.h"
+#include "setup.h"
 #include "sigchain.h"
 #include "strvec.h"
 #include "packfile.h"
diff --git a/imap-send.c b/imap-send.c
index aa5b2f252d2..a62424e90a4 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -28,6 +28,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "wrapper.h"
 #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
 typedef void *SSL;
diff --git a/line-log.c b/line-log.c
index 6e7fc4b2e0b..84c8093c517 100644
--- a/line-log.c
+++ b/line-log.c
@@ -16,6 +16,7 @@
 #include "graph.h"
 #include "userdiff.h"
 #include "line-log.h"
+#include "setup.h"
 #include "strvec.h"
 #include "bloom.h"
 
diff --git a/mailmap.c b/mailmap.c
index 2c6e9b238dd..c24a16eaf48 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -3,6 +3,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-store.h"
+#include "setup.h"
 
 #define DEBUG_MAILMAP 0
 #if DEBUG_MAILMAP
diff --git a/object-file.c b/object-file.c
index 3da6cd68861..05fff230f73 100644
--- a/object-file.c
+++ b/object-file.c
@@ -37,6 +37,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "promisor-remote.h"
+#include "setup.h"
 #include "submodule.h"
 #include "fsck.h"
 #include "wrapper.h"
diff --git a/object-name.c b/object-name.c
index 3b0ce8ef05a..ce973e01505 100644
--- a/object-name.c
+++ b/object-name.c
@@ -15,6 +15,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "repository.h"
+#include "setup.h"
 #include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
diff --git a/path.c b/path.c
index 5d5a15c13d6..a1702434979 100644
--- a/path.c
+++ b/path.c
@@ -11,6 +11,7 @@
 #include "string-list.h"
 #include "dir.h"
 #include "worktree.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "path.h"
 #include "packfile.h"
diff --git a/pathspec.c b/pathspec.c
index 5fb7b5f26c9..6972d515f0c 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
+#include "setup.h"
 #include "strvec.h"
 #include "quote.h"
 
diff --git a/refs.c b/refs.c
index 04520e5a6b8..21b317e8153 100644
--- a/refs.c
+++ b/refs.c
@@ -22,6 +22,7 @@
 #include "worktree.h"
 #include "strvec.h"
 #include "repository.h"
+#include "setup.h"
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0c3138ede8f..d2b8925ebd0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -14,6 +14,7 @@
 #include "../object.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
+#include "../setup.h"
 #include "../worktree.h"
 #include "../wrapper.h"
 
diff --git a/remote-curl.c b/remote-curl.c
index eb382a1e35d..260ea200bb0 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -18,6 +18,7 @@
 #include "credential.h"
 #include "oid-array.h"
 #include "send-pack.h"
+#include "setup.h"
 #include "protocol.h"
 #include "quote.h"
 #include "transport.h"
diff --git a/remote.c b/remote.c
index aeca3ff8136..c29e2f52981 100644
--- a/remote.c
+++ b/remote.c
@@ -15,6 +15,7 @@
 #include "revision.h"
 #include "dir.h"
 #include "tag.h"
+#include "setup.h"
 #include "string-list.h"
 #include "strvec.h"
 #include "commit-reach.h"
diff --git a/repository.c b/repository.c
index 4412f633224..f6d9f5db08e 100644
--- a/repository.c
+++ b/repository.c
@@ -11,6 +11,7 @@
 #include "object.h"
 #include "lockfile.h"
 #include "remote.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "sparse-index.h"
 #include "promisor-remote.h"
diff --git a/revision.c b/revision.c
index 53fdeef0787..f98691a3531 100644
--- a/revision.c
+++ b/revision.c
@@ -29,6 +29,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "setup.h"
 #include "strvec.h"
 #include "commit-reach.h"
 #include "commit-graph.h"
diff --git a/scalar.c b/scalar.c
index fe61a3ebdd7..27635658c01 100644
--- a/scalar.c
+++ b/scalar.c
@@ -15,6 +15,7 @@
 #include "dir.h"
 #include "packfile.h"
 #include "help.h"
+#include "setup.h"
 
 static void setup_enlistment_directory(int argc, const char **argv,
 				       const char * const *usagestr,
diff --git a/setup.c b/setup.c
index cfdc849a78c..6c5b85e96c1 100644
--- a/setup.c
+++ b/setup.c
@@ -5,6 +5,7 @@
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
+#include "setup.h"
 #include "string-list.h"
 #include "chdir-notify.h"
 #include "promisor-remote.h"
diff --git a/setup.h b/setup.h
new file mode 100644
index 00000000000..4c1ca9d0c94
--- /dev/null
+++ b/setup.h
@@ -0,0 +1,168 @@
+#ifndef SETUP_H
+#define SETUP_H
+
+#include "string-list.h"
+
+int is_inside_git_dir(void);
+int is_inside_work_tree(void);
+int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
+int get_common_dir(struct strbuf *sb, const char *gitdir);
+
+/*
+ * Return true if the given path is a git directory; note that this _just_
+ * looks at the directory itself. If you want to know whether "foo/.git"
+ * is a repository, you must feed that path, not just "foo".
+ */
+int is_git_directory(const char *path);
+
+/*
+ * Return 1 if the given path is the root of a git repository or
+ * submodule, else 0. Will not return 1 for bare repositories with the
+ * exception of creating a bare repository in "foo/.git" and calling
+ * is_git_repository("foo").
+ *
+ * If we run into read errors, we err on the side of saying "yes, it is",
+ * as we usually consider sub-repos precious, and would prefer to err on the
+ * side of not disrupting or deleting them.
+ */
+int is_nonbare_repository_dir(struct strbuf *path);
+
+#define READ_GITFILE_ERR_STAT_FAILED 1
+#define READ_GITFILE_ERR_NOT_A_FILE 2
+#define READ_GITFILE_ERR_OPEN_FAILED 3
+#define READ_GITFILE_ERR_READ_FAILED 4
+#define READ_GITFILE_ERR_INVALID_FORMAT 5
+#define READ_GITFILE_ERR_NO_PATH 6
+#define READ_GITFILE_ERR_NOT_A_REPO 7
+#define READ_GITFILE_ERR_TOO_LARGE 8
+void read_gitfile_error_die(int error_code, const char *path, const char *dir);
+const char *read_gitfile_gently(const char *path, int *return_error_code);
+#define read_gitfile(path) read_gitfile_gently((path), NULL)
+const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
+#define resolve_gitdir(path) resolve_gitdir_gently((path), NULL)
+
+void setup_work_tree(void);
+/*
+ * Find the commondir and gitdir of the repository that contains the current
+ * working directory, without changing the working directory or other global
+ * state. The result is appended to commondir and gitdir.  If the discovered
+ * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
+ * both have the same result appended to the buffer.  The return value is
+ * either 0 upon success and non-zero if no repository was found.
+ */
+int discover_git_directory(struct strbuf *commondir,
+			   struct strbuf *gitdir);
+const char *setup_git_directory_gently(int *);
+const char *setup_git_directory(void);
+char *prefix_path(const char *prefix, int len, const char *path);
+char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
+
+int check_filename(const char *prefix, const char *name);
+void verify_filename(const char *prefix,
+		     const char *name,
+		     int diagnose_misspelt_rev);
+void verify_non_filename(const char *prefix, const char *name);
+int path_inside_repo(const char *prefix, const char *path);
+
+void sanitize_stdfds(void);
+int daemonize(void);
+
+/*
+ * GIT_REPO_VERSION is the version we write by default. The
+ * _READ variant is the highest number we know how to
+ * handle.
+ */
+#define GIT_REPO_VERSION 0
+#define GIT_REPO_VERSION_READ 1
+
+/*
+ * You _have_ to initialize a `struct repository_format` using
+ * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`.
+ */
+struct repository_format {
+	int version;
+	int precious_objects;
+	char *partial_clone; /* value of extensions.partialclone */
+	int worktree_config;
+	int is_bare;
+	int hash_algo;
+	int sparse_index;
+	char *work_tree;
+	struct string_list unknown_extensions;
+	struct string_list v1_only_extensions;
+};
+
+/*
+ * Always use this to initialize a `struct repository_format`
+ * to a well-defined, default state before calling
+ * `read_repository()`.
+ */
+#define REPOSITORY_FORMAT_INIT \
+{ \
+	.version = -1, \
+	.is_bare = -1, \
+	.hash_algo = GIT_HASH_SHA1, \
+	.unknown_extensions = STRING_LIST_INIT_DUP, \
+	.v1_only_extensions = STRING_LIST_INIT_DUP, \
+}
+
+/*
+ * Read the repository format characteristics from the config file "path" into
+ * "format" struct. Returns the numeric version. On error, or if no version is
+ * found in the configuration, -1 is returned, format->version is set to -1,
+ * and all other fields in the struct are set to the default configuration
+ * (REPOSITORY_FORMAT_INIT). Always initialize the struct using
+ * REPOSITORY_FORMAT_INIT before calling this function.
+ */
+int read_repository_format(struct repository_format *format, const char *path);
+
+/*
+ * Free the memory held onto by `format`, but not the struct itself.
+ * (No need to use this after `read_repository_format()` fails.)
+ */
+void clear_repository_format(struct repository_format *format);
+
+/*
+ * Verify that the repository described by repository_format is something we
+ * can read. If it is, return 0. Otherwise, return -1, and "err" will describe
+ * any errors encountered.
+ */
+int verify_repository_format(const struct repository_format *format,
+			     struct strbuf *err);
+
+/*
+ * Check the repository format version in the path found in get_git_dir(),
+ * and die if it is a version we don't understand. Generally one would
+ * set_git_dir() before calling this, and use it only for "are we in a valid
+ * repo?".
+ *
+ * If successful and fmt is not NULL, fill fmt with data.
+ */
+void check_repository_format(struct repository_format *fmt);
+
+/*
+ * NOTE NOTE NOTE!!
+ *
+ * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must
+ * not be changed. Old repositories have core.sharedrepository written in
+ * numeric format, and therefore these values are preserved for compatibility
+ * reasons.
+ */
+enum sharedrepo {
+	PERM_UMASK          = 0,
+	OLD_PERM_GROUP      = 1,
+	OLD_PERM_EVERYBODY  = 2,
+	PERM_GROUP          = 0660,
+	PERM_EVERYBODY      = 0664
+};
+int git_config_perm(const char *var, const char *value);
+
+struct startup_info {
+	int have_repository;
+	const char *prefix;
+	const char *original_cwd;
+};
+extern struct startup_info *startup_info;
+extern const char *tmp_original_cwd;
+
+#endif /* SETUP_H */
diff --git a/submodule.c b/submodule.c
index acf030b95e4..75e0d45cbcb 100644
--- a/submodule.c
+++ b/submodule.c
@@ -26,6 +26,7 @@
 #include "parse-options.h"
 #include "object-store.h"
 #include "commit-reach.h"
+#include "setup.h"
 #include "shallow.h"
 
 static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
diff --git a/symlinks.c b/symlinks.c
index c35c8d4408d..27ecc93693b 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "gettext.h"
+#include "setup.h"
 
 static int threaded_check_leading_path(struct cache_def *cache, const char *name,
 				       int len, int warn_on_lstat_err);
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index cb881139f73..4e6ed30afa1 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "advice.h"
 #include "config.h"
+#include "setup.h"
 
 int cmd__advise_if_enabled(int argc, const char **argv)
 {
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index 5bb489882da..af43ee1cb5e 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "git-compat-util.h"
 #include "pack-bitmap.h"
+#include "setup.h"
 
 static int bitmap_list_commits(void)
 {
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 127f134a2a6..e5754b8da62 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "test-tool.h"
 #include "commit.h"
+#include "setup.h"
 
 static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
 
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 8b7a8fce1ee..cdaf5046f5a 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -6,6 +6,7 @@
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
+#include "setup.h"
 
 static char const * const test_cache_tree_usage[] = {
 	N_("test-tool cache-tree <options> (control|prime|update)"),
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 4ba9eb65606..5877188f3ad 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "setup.h"
 #include "string-list.h"
 
 /*
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 92dfc1aa8c4..715aabfbae7 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
-
+#include "setup.h"
 
 static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
 {
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 975f0ac8905..7e9de296db3 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "setup.h"
 
 int cmd__dump_fsmonitor(int ac, const char **av)
 {
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 813d0a38fae..289a01c10ac 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "hex.h"
+#include "setup.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
 
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index af953fabe87..415f55f31da 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "hex.h"
+#include "setup.h"
 
 static int compare_untracked(const void *a_, const void *b_)
 {
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 627a6bdc3d0..e402c35a702 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -23,6 +23,7 @@
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
+#include "setup.h"
 #include "strvec.h"
 #include "tree.h"
 
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index c43fc976b82..a37236cd0a6 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "parse-options.h"
 #include "fsmonitor-ipc.h"
+#include "setup.h"
 #include "thread-utils.h"
 #include "trace2.h"
 #include "wrapper.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 2b678a45793..06ce3a47ccf 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "environment.h"
 #include "parse-options.h"
+#include "setup.h"
 
 static int single;
 static int multi;
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index 04bc2563f3e..64705734dfe 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "hex.h"
+#include "setup.h"
 #include "tree.h"
 
 int cmd__match_trees(int ac, const char **av)
diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
index 0906993ad59..fd6f73ea03b 100644
--- a/t/helper/test-oid-array.c
+++ b/t/helper/test-oid-array.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "oid-array.h"
+#include "setup.h"
 
 static int print_oid(const struct object_id *oid, void *data)
 {
diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c
index 883d40efd45..f1b3dbe376b 100644
--- a/t/helper/test-oidmap.c
+++ b/t/helper/test-oidmap.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "oidmap.h"
+#include "setup.h"
 #include "strbuf.h"
 
 /* key is an oid and value is a name (could be a refname for example) */
diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
index 0b82431a70f..edcb7e9f448 100644
--- a/t/helper/test-oidtree.c
+++ b/t/helper/test-oidtree.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "oidtree.h"
+#include "setup.h"
 
 static enum cb_next print_oid(const struct object_id *oid, void *data)
 {
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 0e53dee9e57..75ca1505a37 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -5,6 +5,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pack-mtimes.h"
+#include "setup.h"
 
 static void dump_mtimes(struct packed_git *p)
 {
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index da17fd37eb1..cce496944ac 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -3,6 +3,7 @@
 #include "test-tool.h"
 #include "repository.h"
 #include "object-store.h"
+#include "setup.h"
 
 /*
  * Prints the size of the object corresponding to the given hash in a specific
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index cc266e3ec09..4f5ac2fadce 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "environment.h"
+#include "setup.h"
 #include "string-list.h"
 #include "utf8.h"
 
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index 7e12d4f9aa2..7c8de7b562a 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "parse-options.h"
 #include "pkt-line.h"
+#include "setup.h"
 #include "sigchain.h"
 #include "test-tool.h"
 
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 09c711038ce..91bb2dec1df 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -8,6 +8,7 @@
 #include "hex.h"
 #include "parse-options.h"
 #include "ref-filter.h"
+#include "setup.h"
 #include "string-list.h"
 #include "tag.h"
 
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 84818363d5b..a4c24d0e421 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "setup.h"
 #include "wrapper.h"
 
 int cmd__read_cache(int argc, const char **argv)
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 98b73bb8f25..e21b0805f3c 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -4,6 +4,7 @@
 #include "repository.h"
 #include "object-store.h"
 #include "bloom.h"
+#include "setup.h"
 
 int cmd__read_graph(int argc, const char **argv)
 {
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 0a883cdf26b..05c4f2b2625 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -5,6 +5,7 @@
 #include "repository.h"
 #include "object-store.h"
 #include "pack-bitmap.h"
+#include "setup.h"
 
 static int read_midx_file(const char *object_dir, int show_objects)
 {
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 1745b088b7c..8717b95e84f 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "refs.h"
+#include "setup.h"
 #include "worktree.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index c444775eb0f..6774f6245f0 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -8,6 +8,7 @@
 #include "object-store.h"
 #include "object.h"
 #include "repository.h"
+#include "setup.h"
 #include "tree.h"
 
 static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index 4a45d5bac2a..f2df4334063 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
+#include "setup.h"
 
 static void print_commit(struct commit *commit)
 {
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index a26107ed70a..15b7688774c 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "lockfile.h"
+#include "setup.h"
 #include "tree.h"
 #include "cache-tree.h"
 
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 497d72058de..7d590ab7227 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "serve.h"
+#include "setup.h"
 
 static char const * const serve_usage[] = {
 	N_("test-tool serve-v2 [<options>]"),
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 22a41c40926..256bfa6e9e1 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index a3848a8b668..aaffd422d6e 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "setup.h"
 #include "submodule-config.h"
 
 static void die_usage(const char **argv, const char *msg)
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index e060cc62268..f18ca46dce4 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "parse-options.h"
 #include "remote.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c
index ff22f2fa2c5..65a355cc590 100644
--- a/t/helper/test-subprocess.c
+++ b/t/helper/test-subprocess.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "run-command.h"
+#include "setup.h"
 
 int cmd__subprocess(int argc, const char **argv)
 {
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index a2b56b9cae5..0cd7ee12b7e 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "setup.h"
 #include "userdiff.h"
 #include "config.h"
 
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index 7d45cd61e82..a93417ed3a9 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "lockfile.h"
+#include "setup.h"
 
 int cmd__write_cache(int argc, const char **argv)
 {
diff --git a/trace.c b/trace.c
index 9c85b71ec6a..81318a2455d 100644
--- a/trace.c
+++ b/trace.c
@@ -25,6 +25,7 @@
 #include "abspath.h"
 #include "environment.h"
 #include "quote.h"
+#include "setup.h"
 #include "wrapper.h"
 
 struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
diff --git a/unpack-trees.c b/unpack-trees.c
index 0ff4bbc6b96..a26fda3493f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -22,6 +22,7 @@
 #include "promisor-remote.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "setup.h"
 
 /*
  * Error messages expected by scripts out of plumbing commands such as
diff --git a/worktree.c b/worktree.c
index 3861ab639ca..edef9e161dc 100644
--- a/worktree.c
+++ b/worktree.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "repository.h"
 #include "refs.h"
+#include "setup.h"
 #include "strbuf.h"
 #include "worktree.h"
 #include "dir.h"
diff --git a/wt-status.c b/wt-status.c
index 106e46480a1..16e0df5736f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -16,6 +16,7 @@
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "setup.h"
 #include "strbuf.h"
 #include "utf8.h"
 #include "worktree.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 14/16] treewide: remove cache.h inclusion due to setup.h changes
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (12 preceding siblings ...)
  2023-03-19  6:27 ` [PATCH 13/16] setup.h: move declarations for setup.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:28 ` Elijah Newren via GitGitGadget
  2023-03-19  6:28 ` [PATCH 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h Elijah Newren via GitGitGadget
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:28 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

By moving several declarations to setup.h, the previous patch made it
possible to remove the include of cache.h in several source files.  Do
so.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 line-log.c                                   | 1 -
 path.c                                       | 2 +-
 t/helper/test-advise.c                       | 1 -
 t/helper/test-bloom.c                        | 3 +--
 t/helper/test-config.c                       | 1 -
 t/helper/test-pack-mtimes.c                  | 1 -
 t/helper/test-partial-clone.c                | 3 +--
 t/helper/test-proc-receive.c                 | 3 +--
 t/helper/test-read-graph.c                   | 1 -
 t/helper/test-ref-store.c                    | 1 -
 t/helper/test-repository.c                   | 1 -
 t/helper/test-revision-walking.c             | 1 -
 t/helper/test-serve-v2.c                     | 1 -
 t/helper/test-submodule-nested-repo-config.c | 1 -
 t/helper/test-submodule.c                    | 1 -
 t/helper/test-subprocess.c                   | 1 -
 t/helper/test-userdiff.c                     | 1 -
 worktree.c                                   | 2 +-
 18 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/line-log.c b/line-log.c
index 84c8093c517..10c19daec4a 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1,7 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "line-range.h"
-#include "cache.h"
 #include "hex.h"
 #include "tag.h"
 #include "blob.h"
diff --git a/path.c b/path.c
index a1702434979..dff215ac693 100644
--- a/path.c
+++ b/path.c
@@ -1,7 +1,7 @@
 /*
  * Utilities for paths and pathnames
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index 4e6ed30afa1..8a3fd0009a0 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "advice.h"
 #include "config.h"
 #include "setup.h"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index e5754b8da62..d2b30d644da 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -1,7 +1,6 @@
-#include "cache.h"
+#include "test-tool.h"
 #include "bloom.h"
 #include "hex.h"
-#include "test-tool.h"
 #include "commit.h"
 #include "setup.h"
 
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 5877188f3ad..32d170ec303 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "config.h"
 #include "setup.h"
 #include "string-list.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 75ca1505a37..0f3fbeec532 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "strbuf.h"
 #include "object-store.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index cce496944ac..362bd64a4c2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "hex.h"
 #include "test-tool.h"
+#include "hex.h"
 #include "repository.h"
 #include "object-store.h"
 #include "setup.h"
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index 7c8de7b562a..f30022d2225 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "test-tool.h"
 #include "connect.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "pkt-line.h"
 #include "setup.h"
 #include "sigchain.h"
-#include "test-tool.h"
 
 static const char *proc_receive_usage[] = {
 	"test-tool proc-receive [<options>]",
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index e21b0805f3c..78965a6ebdc 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "commit-graph.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 8717b95e84f..d1192c8c039 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "refs.h"
 #include "setup.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 6774f6245f0..bafd2a5bf95 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "commit-graph.h"
 #include "commit.h"
 #include "config.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index f2df4334063..7750afb2866 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -9,7 +9,6 @@
  */
 
 #include "test-tool.h"
-#include "cache.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 7d590ab7227..054cbcf5d83 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "serve.h"
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index aaffd422d6e..d31f5e48ab5 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "setup.h"
 #include "submodule-config.h"
 
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index f18ca46dce4..0e34581b209 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -1,6 +1,5 @@
 #include "test-tool.h"
 #include "test-tool-utils.h"
-#include "cache.h"
 #include "parse-options.h"
 #include "remote.h"
 #include "setup.h"
diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c
index 65a355cc590..c344f1694df 100644
--- a/t/helper/test-subprocess.c
+++ b/t/helper/test-subprocess.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "run-command.h"
 #include "setup.h"
 
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index 0cd7ee12b7e..680124a6760 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "setup.h"
 #include "userdiff.h"
 #include "config.h"
diff --git a/worktree.c b/worktree.c
index edef9e161dc..f33826f0a0b 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "environment.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (13 preceding siblings ...)
  2023-03-19  6:28 ` [PATCH 14/16] treewide: remove cache.h inclusion due to setup.h changes Elijah Newren via GitGitGadget
@ 2023-03-19  6:28 ` Elijah Newren via GitGitGadget
  2023-03-19  6:28 ` [PATCH 16/16] csum-file.h: remove unnecessary inclusion of cache.h Elijah Newren via GitGitGadget
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:28 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 archive-tar.c              |  1 +
 archive-zip.c              |  1 +
 builtin/blame.c            |  1 +
 builtin/cat-file.c         |  1 +
 builtin/check-attr.c       |  1 +
 builtin/check-ignore.c     |  1 +
 builtin/check-mailmap.c    |  1 +
 builtin/credential-cache.c |  1 +
 builtin/credential-store.c |  1 +
 builtin/grep.c             |  1 +
 builtin/hash-object.c      |  1 +
 builtin/log.c              |  1 +
 builtin/notes.c            |  1 +
 builtin/send-pack.c        |  1 +
 builtin/stripspace.c       |  1 +
 builtin/tag.c              |  1 +
 builtin/update-index.c     |  1 +
 bundle.c                   |  1 +
 cache.h                    | 74 ------------------------------------
 config.c                   |  1 +
 csum-file.h                |  1 +
 diagnose.c                 |  1 +
 environment.c              |  1 +
 http-backend.c             |  1 +
 log-tree.c                 |  1 +
 pkt-line.c                 |  1 +
 refs/files-backend.c       |  1 +
 refs/packed-backend.c      |  1 +
 remote-curl.c              |  1 +
 send-pack.c                |  3 +-
 sideband.c                 |  1 +
 t/helper/test-pkt-line.c   |  3 +-
 upload-pack.c              |  1 +
 write-or-die.c             |  3 +-
 write-or-die.h             | 78 ++++++++++++++++++++++++++++++++++++++
 35 files changed, 114 insertions(+), 77 deletions(-)
 create mode 100644 write-or-die.h

diff --git a/archive-tar.c b/archive-tar.c
index 16ee133bbf5..497dad0b3af 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,6 +11,7 @@
 #include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
+#include "write-or-die.h"
 
 #define RECORDSIZE	(512)
 #define BLOCKSIZE	(RECORDSIZE * 20)
diff --git a/archive-zip.c b/archive-zip.c
index c02dc33e406..e6f5c10a14f 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -10,6 +10,7 @@
 #include "utf8.h"
 #include "object-store.h"
 #include "userdiff.h"
+#include "write-or-die.h"
 #include "xdiff-interface.h"
 #include "date.h"
 
diff --git a/builtin/blame.c b/builtin/blame.c
index fb271bae70e..0a3cc019059 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -33,6 +33,7 @@
 #include "refs.h"
 #include "setup.h"
 #include "tag.h"
+#include "write-or-die.h"
 
 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
 static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>");
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 365d9234bdb..cf73d187912 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -23,6 +23,7 @@
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
+#include "write-or-die.h"
 
 enum batch_mode {
 	BATCH_MODE_CONTENTS,
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index ec37b8164af..1dbe9d6ca88 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -8,6 +8,7 @@
 #include "quote.h"
 #include "setup.h"
 #include "parse-options.h"
+#include "write-or-die.h"
 
 static int all_attrs;
 static int cached_attrs;
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index a45d001e353..9401dad0070 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -8,6 +8,7 @@
 #include "pathspec.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "write-or-die.h"
 
 static int quiet, verbose, stdin_paths, show_non_matching, no_index;
 static const char * const check_ignore_usage[] = {
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index fa86fd9423d..002d2941e93 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -5,6 +5,7 @@
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
+#include "write-or-die.h"
 
 static int use_stdin;
 static const char * const check_mailmap_usage[] = {
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index af56a44923d..508da4c6e4d 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -2,6 +2,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 #ifndef NO_UNIX_SOCKETS
 
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index da32cfd89e2..8977604eb9d 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -5,6 +5,7 @@
 #include "credential.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "write-or-die.h"
 
 static struct lock_file credential_lock;
 
diff --git a/builtin/grep.c b/builtin/grep.c
index b8ebf014f40..d858bf0bea6 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -28,6 +28,7 @@
 #include "submodule-config.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "write-or-die.h"
 
 static const char *grep_prefix;
 
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index a2e160db026..a15fe4fd3f4 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "exec-cmd.h"
 #include "setup.h"
+#include "write-or-die.h"
 
 /*
  * This is to create corrupt objects for debugging and as such it
diff --git a/builtin/log.c b/builtin/log.c
index b7b6dfbd1d1..84ec5b504d4 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -40,6 +40,7 @@
 #include "commit-reach.h"
 #include "range-diff.h"
 #include "tmp-objdir.h"
+#include "write-or-die.h"
 
 #define MAIL_DEFAULT_WRAP 72
 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100
diff --git a/builtin/notes.c b/builtin/notes.c
index 8e9be33ddbb..26cbb564a8e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -25,6 +25,7 @@
 #include "notes-merge.h"
 #include "notes-utils.h"
 #include "worktree.h"
+#include "write-or-die.h"
 
 static const char * const git_notes_usage[] = {
 	N_("git notes [--ref <notes-ref>] [list [<object>]]"),
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index fb5b2bad2cc..2b360fee426 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -16,6 +16,7 @@
 #include "gpg-interface.h"
 #include "gettext.h"
 #include "protocol.h"
+#include "write-or-die.h"
 
 static const char * const send_pack_usage[] = {
 	N_("git send-pack [--mirror] [--dry-run] [--force]\n"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 53930458ffa..9451eb69ff4 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "setup.h"
 #include "strbuf.h"
+#include "write-or-die.h"
 
 static void comment_lines(struct strbuf *buf)
 {
diff --git a/builtin/tag.c b/builtin/tag.c
index 78b3e44e993..85afa50d724 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -24,6 +24,7 @@
 #include "column.h"
 #include "ref-filter.h"
 #include "date.h"
+#include "write-or-die.h"
 
 static const char * const git_tag_usage[] = {
 	N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index f97f8d4c9d5..03cda5e60d2 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -23,6 +23,7 @@
 #include "setup.h"
 #include "split-index.h"
 #include "fsmonitor.h"
+#include "write-or-die.h"
 
 /*
  * Default to not allowing changes to the list of files. The
diff --git a/bundle.c b/bundle.c
index efeaf6f7151..dac82e2f2d9 100644
--- a/bundle.c
+++ b/bundle.c
@@ -16,6 +16,7 @@
 #include "strvec.h"
 #include "list-objects-filter-options.h"
 #include "connected.h"
+#include "write-or-die.h"
 
 static const char v2_bundle_signature[] = "# v2 git bundle\n";
 static const char v3_bundle_signature[] = "# v3 git bundle\n";
diff --git a/cache.h b/cache.h
index bffedd240e7..c43051d7928 100644
--- a/cache.h
+++ b/cache.h
@@ -686,63 +686,6 @@ extern int verify_ce_order;
 
 extern int quote_path_fully;
 
-/*
- * These values are used to help identify parts of a repository to fsync.
- * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
- * repository and so shouldn't be fsynced.
- */
-enum fsync_component {
-	FSYNC_COMPONENT_NONE,
-	FSYNC_COMPONENT_LOOSE_OBJECT		= 1 << 0,
-	FSYNC_COMPONENT_PACK			= 1 << 1,
-	FSYNC_COMPONENT_PACK_METADATA		= 1 << 2,
-	FSYNC_COMPONENT_COMMIT_GRAPH		= 1 << 3,
-	FSYNC_COMPONENT_INDEX			= 1 << 4,
-	FSYNC_COMPONENT_REFERENCE		= 1 << 5,
-};
-
-#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
-				  FSYNC_COMPONENT_PACK)
-
-#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
-					   FSYNC_COMPONENT_COMMIT_GRAPH)
-
-#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
-				   FSYNC_COMPONENTS_DERIVED_METADATA) & \
-				  ~FSYNC_COMPONENT_LOOSE_OBJECT)
-
-#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
-				    FSYNC_COMPONENT_REFERENCE)
-
-#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
-				FSYNC_COMPONENT_INDEX)
-
-#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
-			      FSYNC_COMPONENT_PACK | \
-			      FSYNC_COMPONENT_PACK_METADATA | \
-			      FSYNC_COMPONENT_COMMIT_GRAPH | \
-			      FSYNC_COMPONENT_INDEX | \
-			      FSYNC_COMPONENT_REFERENCE)
-
-#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
-#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
-#endif
-
-/*
- * A bitmask indicating which components of the repo should be fsynced.
- */
-extern enum fsync_component fsync_components;
-extern int fsync_object_files;
-extern int use_fsync;
-
-enum fsync_method {
-	FSYNC_METHOD_FSYNC,
-	FSYNC_METHOD_WRITEOUT_ONLY,
-	FSYNC_METHOD_BATCH,
-};
-
-extern enum fsync_method fsync_method;
-
 #define MTIME_CHANGED	0x0001
 #define CTIME_CHANGED	0x0002
 #define OWNER_CHANGED	0x0004
@@ -1045,29 +988,12 @@ int update_server_info(int);
 extern const char *git_mailmap_file;
 extern const char *git_mailmap_blob;
 
-/* IO helper functions */
-void maybe_flush_or_die(FILE *, const char *);
-__attribute__((format (printf, 2, 3)))
-void fprintf_or_die(FILE *, const char *fmt, ...);
-void fwrite_or_die(FILE *f, const void *buf, size_t count);
-void fflush_or_die(FILE *f);
-
 #define COPY_READ_ERROR (-2)
 #define COPY_WRITE_ERROR (-3)
 int copy_fd(int ifd, int ofd);
 int copy_file(const char *dst, const char *src, int mode);
 int copy_file_with_time(const char *dst, const char *src, int mode);
 
-void write_or_die(int fd, const void *buf, size_t count);
-void fsync_or_die(int fd, const char *);
-int fsync_component(enum fsync_component component, int fd);
-void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
-
-static inline int batch_fsync_enabled(enum fsync_component component)
-{
-	return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
-}
-
 /* pager.c */
 void setup_pager(void);
 int pager_in_use(void);
diff --git a/config.c b/config.c
index 03a4fcaba5b..5ad9ae91436 100644
--- a/config.c
+++ b/config.c
@@ -30,6 +30,7 @@
 #include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 struct config_source {
 	struct config_source *prev;
diff --git a/csum-file.h b/csum-file.h
index 793a59da12b..4cd9014e367 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -3,6 +3,7 @@
 
 #include "cache.h"
 #include "hash.h"
+#include "write-or-die.h"
 
 struct progress;
 
diff --git a/diagnose.c b/diagnose.c
index 169a55407fd..f9a2496c7ff 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -9,6 +9,7 @@
 #include "strvec.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "write-or-die.h"
 
 struct archive_dir {
 	const char *path;
diff --git a/environment.c b/environment.c
index 649d16ac27c..63c697e7e97 100644
--- a/environment.c
+++ b/environment.c
@@ -25,6 +25,7 @@
 #include "setup.h"
 #include "shallow.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
diff --git a/http-backend.c b/http-backend.c
index 042ccf12e8c..89aad1b42c7 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,6 +18,7 @@
 #include "protocol.h"
 #include "date.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
diff --git a/log-tree.c b/log-tree.c
index e2bf8d6df75..ba7b885984f 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -23,6 +23,7 @@
 #include "help.h"
 #include "range-diff.h"
 #include "strmap.h"
+#include "write-or-die.h"
 
 static struct decoration name_decoration = { "object names" };
 static int decoration_loaded;
diff --git a/pkt-line.c b/pkt-line.c
index 30469eb4d8d..36ae0fea4a3 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -4,6 +4,7 @@
 #include "hex.h"
 #include "run-command.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d2b8925ebd0..e6a6971381e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -17,6 +17,7 @@
 #include "../setup.h"
 #include "../worktree.h"
 #include "../wrapper.h"
+#include "../write-or-die.h"
 
 /*
  * This backend uses the following flags in `ref_update::flags` for
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 3334c07003c..1eba1015dd5 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -9,6 +9,7 @@
 #include "../iterator.h"
 #include "../lockfile.h"
 #include "../chdir-notify.h"
+#include "../write-or-die.h"
 
 enum mmap_strategy {
 	/*
diff --git a/remote-curl.c b/remote-curl.c
index 260ea200bb0..0f2410da8e7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -22,6 +22,7 @@
 #include "protocol.h"
 #include "quote.h"
 #include "transport.h"
+#include "write-or-die.h"
 
 static struct remote *remote;
 /* always ends with a trailing slash */
diff --git a/send-pack.c b/send-pack.c
index f531cb48212..11f41a8d81e 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -16,8 +16,9 @@
 #include "version.h"
 #include "oid-array.h"
 #include "gpg-interface.h"
-#include "cache.h"
 #include "shallow.h"
+#include "trace2.h"
+#include "write-or-die.h"
 
 int option_parse_push_signed(const struct option *opt,
 			     const char *arg, int unset)
diff --git a/sideband.c b/sideband.c
index 4905cf9b32a..0af582858bf 100644
--- a/sideband.c
+++ b/sideband.c
@@ -5,6 +5,7 @@
 #include "sideband.h"
 #include "help.h"
 #include "pkt-line.h"
+#include "write-or-die.h"
 
 struct keyword_entry {
 	/*
diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
index c5e052e5378..f4d134a1452 100644
--- a/t/helper/test-pkt-line.c
+++ b/t/helper/test-pkt-line.c
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "test-tool.h"
 #include "pkt-line.h"
+#include "write-or-die.h"
 
 static void pack_line(const char *line)
 {
diff --git a/upload-pack.c b/upload-pack.c
index 1155f795382..eb3d0b3fa36 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -30,6 +30,7 @@
 #include "commit-graph.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "write-or-die.h"
 
 /* Remember to update object flag allocation in object.h */
 #define THEY_HAVE	(1u << 11)
diff --git a/write-or-die.c b/write-or-die.c
index a7afc303db2..cc9e0787a1d 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -1,7 +1,8 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "run-command.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 /*
  * Some cases use stdio, but want to flush after the write
diff --git a/write-or-die.h b/write-or-die.h
new file mode 100644
index 00000000000..65a5c42a47a
--- /dev/null
+++ b/write-or-die.h
@@ -0,0 +1,78 @@
+#ifndef WRITE_OR_DIE_H
+#define WRITE_OR_DIE_H
+
+void maybe_flush_or_die(FILE *, const char *);
+__attribute__((format (printf, 2, 3)))
+void fprintf_or_die(FILE *, const char *fmt, ...);
+void fwrite_or_die(FILE *f, const void *buf, size_t count);
+void fflush_or_die(FILE *f);
+void write_or_die(int fd, const void *buf, size_t count);
+
+/*
+ * These values are used to help identify parts of a repository to fsync.
+ * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
+ * repository and so shouldn't be fsynced.
+ */
+enum fsync_component {
+	FSYNC_COMPONENT_NONE,
+	FSYNC_COMPONENT_LOOSE_OBJECT		= 1 << 0,
+	FSYNC_COMPONENT_PACK			= 1 << 1,
+	FSYNC_COMPONENT_PACK_METADATA		= 1 << 2,
+	FSYNC_COMPONENT_COMMIT_GRAPH		= 1 << 3,
+	FSYNC_COMPONENT_INDEX			= 1 << 4,
+	FSYNC_COMPONENT_REFERENCE		= 1 << 5,
+};
+
+#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
+				  FSYNC_COMPONENT_PACK)
+
+#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
+					   FSYNC_COMPONENT_COMMIT_GRAPH)
+
+#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
+				   FSYNC_COMPONENTS_DERIVED_METADATA) & \
+				  ~FSYNC_COMPONENT_LOOSE_OBJECT)
+
+#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
+				    FSYNC_COMPONENT_REFERENCE)
+
+#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
+				FSYNC_COMPONENT_INDEX)
+
+#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
+			      FSYNC_COMPONENT_PACK | \
+			      FSYNC_COMPONENT_PACK_METADATA | \
+			      FSYNC_COMPONENT_COMMIT_GRAPH | \
+			      FSYNC_COMPONENT_INDEX | \
+			      FSYNC_COMPONENT_REFERENCE)
+
+#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
+#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
+#endif
+
+/* IO helper functions */
+void fsync_or_die(int fd, const char *);
+int fsync_component(enum fsync_component component, int fd);
+void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
+
+/*
+ * A bitmask indicating which components of the repo should be fsynced.
+ */
+extern enum fsync_component fsync_components;
+extern int fsync_object_files;
+extern int use_fsync;
+
+enum fsync_method {
+	FSYNC_METHOD_FSYNC,
+	FSYNC_METHOD_WRITEOUT_ONLY,
+	FSYNC_METHOD_BATCH,
+};
+
+extern enum fsync_method fsync_method;
+
+static inline int batch_fsync_enabled(enum fsync_component component)
+{
+	return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
+}
+
+#endif /* WRITE_OR_DIE_H */
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 16/16] csum-file.h: remove unnecessary inclusion of cache.h
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (14 preceding siblings ...)
  2023-03-19  6:28 ` [PATCH 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-19  6:28 ` Elijah Newren via GitGitGadget
  2023-03-20  9:58 ` [PATCH 00/16] Header cleanups Ævar Arnfjörð Bjarmason
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
  17 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-19  6:28 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

With the change in the last commit to move several functions to
write-or-die.h, csum-file.h no longer needs to include cache.h.
However, removing that include forces several other C files, which
directly or indirectly dependend upon csum-file.h's inclusion of
cache.h, to now be more explicit about their dependencies.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 bulk-checkin.c      | 2 +-
 chunk-format.c      | 1 +
 commit-graph.c      | 2 +-
 csum-file.h         | 1 -
 delta-islands.c     | 2 +-
 fetch-pack.c        | 2 +-
 midx.c              | 2 +-
 object-file.c       | 2 +-
 pack-bitmap-write.c | 3 ++-
 pack-bitmap.c       | 2 +-
 pack.h              | 2 ++
 packfile.c          | 2 +-
 12 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/bulk-checkin.c b/bulk-checkin.c
index eb6d7a2805b..d2428b86111 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2011, Google Inc.
  */
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
 #include "environment.h"
diff --git a/chunk-format.c b/chunk-format.c
index 6d1071729df..60a73c1b140 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -3,6 +3,7 @@
 #include "chunk-format.h"
 #include "csum-file.h"
 #include "gettext.h"
+#include "trace2.h"
 
 /*
  * When writing a chunk-based file format, collect the chunks in
diff --git a/commit-graph.c b/commit-graph.c
index 5481736c76c..f0cd2e7a2a3 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/csum-file.h b/csum-file.h
index 4cd9014e367..566e05cbd25 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -1,7 +1,6 @@
 #ifndef CSUM_FILE_H
 #define CSUM_FILE_H
 
-#include "cache.h"
 #include "hash.h"
 #include "write-or-die.h"
 
diff --git a/delta-islands.c b/delta-islands.c
index 1222b6a6cd1..73a01179e83 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "attr.h"
 #include "object.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index c453a4168f9..10f759532ce 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
diff --git a/midx.c b/midx.c
index b111665dcab..9af3e5de889 100644
--- a/midx.c
+++ b/midx.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/object-file.c b/object-file.c
index 05fff230f73..397596e3c8f 100644
--- a/object-file.c
+++ b/object-file.c
@@ -6,7 +6,7 @@
  * This handles basic git object files - packing, unpacking,
  * creation etc.
  */
-#include "git-compat-util.h"
+#include "cache.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 63f16080c9b..0fddeb1298b 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
@@ -17,6 +17,7 @@
 #include "pack-objects.h"
 #include "commit-reach.h"
 #include "prio-queue.h"
+#include "trace2.h"
 
 struct bitmapped_commit {
 	struct commit *commit;
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 241ac9166c1..23d87e71bd9 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "commit.h"
 #include "gettext.h"
diff --git a/pack.h b/pack.h
index 01d385903ad..3ab9e3f60c0 100644
--- a/pack.h
+++ b/pack.h
@@ -4,6 +4,8 @@
 #include "object.h"
 #include "csum-file.h"
 
+struct packed_git;
+struct pack_window;
 struct repository;
 
 /*
diff --git a/packfile.c b/packfile.c
index cc3b1e242c7..dd4b369e59f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/16] Header cleanups
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (15 preceding siblings ...)
  2023-03-19  6:28 ` [PATCH 16/16] csum-file.h: remove unnecessary inclusion of cache.h Elijah Newren via GitGitGadget
@ 2023-03-20  9:58 ` Ævar Arnfjörð Bjarmason
  2023-03-20 16:18   ` Elijah Newren
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
  17 siblings, 1 reply; 37+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2023-03-20  9:58 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget; +Cc: git, Elijah Newren


On Sun, Mar 19 2023, Elijah Newren via GitGitGadget wrote:

> This series picks up where en/header-cleanups leaves off and does more
> header cleanups, trying to reduce the number of files depending on cache.h.
> (There are still more that could be done, but again, this is a good chunk
> for now.)

> Elijah Newren (16):
>   treewide: remove unnecessary cache.h inclusion from a few headers
>   treewide: be explicit about dependence on gettext.h
>   treewide: remove unnecessary inclusion of gettext.h
>   treewide: remove unnecessary cache.h inclusion from several sources

I couldn't seem to square what you were doing in 2/16 with what 4/16
does, but I think the "issue" is that the commit message for 4/6 doesn't
match at least one change it's making, i.e.:

	By making those files explicitly include gettext.h, we can
	already drop the include of cache.h in these files.

But in fact compat/linux/procinfo.c at least (I didn't do more than skim
the others) isn't like the rest, in that it doesn't need gettext.h at
all.

I also find the ordering hard to follow, but it's ultimately correct in
the cases I looked at. E.g. for ref-filter.c your 1/16 does:

	-#include "git-compat-util.h"
	+#include "cache.h"

Then 2/16 does:

	+#include "gettext.h"

So I wondered, wait a minute, didn't we just end up over-including
cache.h because we needed gettext.h, which the later commit adds?

But no, that's not the case, because as 1/16 notes ("on things from
cache.h[...]") we need *other* things from cache.h, so this is
ultimately correct.

Still, given that, I for one would have found this easier to follow if
commits like 2/16 came before the 1/16, i.e. let's first be explicit
about e.g. gettext.h, and then change git-compat-util.h inclusions to
cache.h, to clearly note in the progression that the two are distinct.

But this is also fine with me if you don't agree, or can't be bothered
to re-roll it.

As a more general note on the direction here: I have some old WIP
patches to do similar split-ups of cache.h, but in doing those I was
trying to first identify cases where we had a function in cache.h that
was used by the low tens of our ~500 *.c source files.

E.g. advice.h is such a case[1], ditto wildmatch.h. Then we have case
like ws.c[3], base85.c[4] and pager.c[5] where there's no corresponding
header, but we should probably create one (which those WIP commits of
mine do).

Whereas this approach feels like the opposite of that, i.e. at the end
of this series we're including gettext.h in more than 250 files.

Stepping back a bit, I think our use of cache.h falls into a few broad
categories:

 A. Things to do with the index (we should probably create an index.h
    for those).
 B. Used almost everywhere, i.e. "cache.h" can be though of as "git.h",
    or "common-utils.h" or whatever.
 C. Things used almost nowhere, or only a handful of places,
    e.g. wildmatch.h and others noted above.

Part of this series is a frontal assault on the "B" part of that. I
think if we're going to include gettext.h explicitly everywhere we're
probably saying by extension that no such thing as a "common header"
should exist.

Which I'd be fine with, I just personally never thought it was much of a
practical problem, i.e. to have the gettext.h's in our tree included
"everywhere", ditto "strbuf.h", and even "enum object_file" and other
"mostly everyone wants these".

Whereas it is rather annoying that we over-include things in cache.h, or
even have cache.h include other headers, as often minor changes to
related libraries result in a full re-build.

But maybe "B" isn't sustainable at all, and I'm just fooling myself
thinking we could have such a thing.

A nice thing I hadn't considered is that after your topic e.g. removing
the gettext.h inclusion from parse-options.h will compile *most* of git,
but we'll fail e.g. in:

	t/helper/test-parse-pathspec-file.c: In function ‘cmd__parse_pathspec_file’:
	./parse-options.h:209:40: error: implicit declaration of function ‘N_’ [-Werror=implicit-function-declaration]
	  209 |                                        N_("file"), (h) }
	

So as we don't want gettext in t/helper/* it's nice to get *an* error
about that.

So, in the end I think I've convinced myself that even the "B" in that
"A..C" is a bad idea.

1. https://github.com/avar/git/commit/17366c2b7b4
2. https://github.com/avar/git/commit/ffb226fb6e6
3. https://github.com/avar/git/commit/1d023e554bf
4. https://github.com/avar/git/commit/e7d5b511090
5. https://github.com/avar/git/commit/0054eea1a1a 

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/16] Header cleanups
  2023-03-20  9:58 ` [PATCH 00/16] Header cleanups Ævar Arnfjörð Bjarmason
@ 2023-03-20 16:18   ` Elijah Newren
  0 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren @ 2023-03-20 16:18 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Elijah Newren via GitGitGadget, git

Hi Ævar,

On Mon, Mar 20, 2023 at 3:37 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
>
>
> On Sun, Mar 19 2023, Elijah Newren via GitGitGadget wrote:
>
> > This series picks up where en/header-cleanups leaves off and does more
> > header cleanups, trying to reduce the number of files depending on cache.h.
> > (There are still more that could be done, but again, this is a good chunk
> > for now.)
>
> > Elijah Newren (16):
> >   treewide: remove unnecessary cache.h inclusion from a few headers
> >   treewide: be explicit about dependence on gettext.h
> >   treewide: remove unnecessary inclusion of gettext.h
> >   treewide: remove unnecessary cache.h inclusion from several sources
>
> I couldn't seem to square what you were doing in 2/16 with what 4/16
> does, but I think the "issue" is that the commit message for 4/6 doesn't
> match at least one change it's making, i.e.:
>
>         By making those files explicitly include gettext.h, we can
>         already drop the include of cache.h in these files.
>
> But in fact compat/linux/procinfo.c at least (I didn't do more than skim
> the others) isn't like the rest, in that it doesn't need gettext.h at
> all.

Yeah, there were apparently pre-existing headers that did not need
cache.h, so my script to find the ones that "no longer need it" after
some changes identifies not only the ones that can be cleaned out due
to the gettext.h changes but the ones that could have been cleaned up
beforehand.  Maybe I should do a preliminary patch that removes
cache.h from some headers, then do the gettext changes, then this
patch becomes clearer.

Or I can tweak the commit message to just spell out we already had
some headers that didn't need cache.h, so this patch just combines
those cleanups.

> I also find the ordering hard to follow, but it's ultimately correct in
> the cases I looked at. E.g. for ref-filter.c your 1/16 does:
>
>         -#include "git-compat-util.h"
>         +#include "cache.h"
>
> Then 2/16 does:
>
>         +#include "gettext.h"
>
> So I wondered, wait a minute, didn't we just end up over-including
> cache.h because we needed gettext.h, which the later commit adds?
>
> But no, that's not the case, because as 1/16 notes ("on things from
> cache.h[...]") we need *other* things from cache.h, so this is
> ultimately correct.
>
> Still, given that, I for one would have found this easier to follow if
> commits like 2/16 came before the 1/16, i.e. let's first be explicit
> about e.g. gettext.h, and then change git-compat-util.h inclusions to
> cache.h, to clearly note in the progression that the two are distinct.
>
> But this is also fine with me if you don't agree, or can't be bothered
> to re-roll it.

In my mind, 1/16 probably belonged in en/header-cleanup that was
already merged to master and was an oversight that made other cleanups
I was trying to do harder.  The gettext stuff was new stuff I was
doing to make other things in this series easier, so I placed it right
after 1/16.

But, I can see your point of view, and I don't feel strongly about the
order of these patches.  I'm happy to switch them around.

> As a more general note on the direction here: I have some old WIP
> patches to do similar split-ups of cache.h, but in doing those I was
> trying to first identify cases where we had a function in cache.h that
> was used by the low tens of our ~500 *.c source files.
>
> E.g. advice.h is such a case[1], ditto wildmatch.h. Then we have case
> like ws.c[3], base85.c[4] and pager.c[5] where there's no corresponding
> header, but we should probably create one (which those WIP commits of
> mine do).

Here was my approach:
  * Identify a *single* file that I know that makes no sense to include cache.h.
  * Try to figure out why and fix it...but also fix *all* other files
that have the same nonsensical dependencies throughout the entire
tree.
  * (And maybe also fix a few extra things you find along the way that
repeatedly turn up).

For my first series (en/header-cleanup which is now in master), I was
looking at diffcore-rename.c.  17 patches later it was clean.

For this series, I was looking at strbuf.c.  It would have been clean
at the end, but while waiting for my first series to merge to master,
you submitted your series which conflicts.  So I dropped some of the
changes, but submitted the rest.  (And the gettext.h changes
originally weren't at the beginning of my series, but then I noticed
they repeatedly were additional squashed-in changes that made things
harder for others to review, AND harder for me to figure out (see
below), so I went back and made the gettext changes into a preliminary
big cleanup.)

Your approach also makes sense, I've considered it before and still
have it in my backlog, but this series focused on making strbuf.c
clean and was already long enough, so I'm deferring those other
changes to later.

> Whereas this approach feels like the opposite of that, i.e. at the end
> of this series we're including gettext.h in more than 250 files.

The idea to "fix all other files with the same nonsensical
dependencies" was heavily impeded by gettext.h.  I had scripts to
optimistically change "cache.h" to "git-compat-util.h" and try to
compile.  For those that only gave warnings rather than errors, I
needed to wade through pages of gettext-related undeclared warnings,
to see the other dependencies in the file.  So, making gettext
dependencies explicit just made it vastly easier to do all the
subsequent cleanups.

> Stepping back a bit, I think our use of cache.h falls into a few broad
> categories:
>
>  A. Things to do with the index (we should probably create an index.h
>     for those).
>  B. Used almost everywhere, i.e. "cache.h" can be though of as "git.h",
>     or "common-utils.h" or whatever.
>  C. Things used almost nowhere, or only a handful of places,
>     e.g. wildmatch.h and others noted above.
>
> Part of this series is a frontal assault on the "B" part of that. I
> think if we're going to include gettext.h explicitly everywhere we're
> probably saying by extension that no such thing as a "common header"
> should exist.

There might be a way to have a common header that doesn't devolve into
a dumping ground of all dependencies the way cache.h has become, but I
think we'd need to be really careful.  I think git-compat-util.h would
obviously make sense to include in such a thing.  You might be able to
convince me that gettext.h should be in such a thing, but I'm not even
sure about that: we have more C files that do not use stuff from
gettext (321) than those that do (245).

I think cache.h is really far from what we want.  It has often tripped
me up in trying to understand the code, often results in needless
compile-everything loops when making simple changes, is an impediment
to any potential libifying or code-sharing exercise (I was hoping that
e.g. merge-ort could be shared with other projects instead of being
reinvented), and makes other interesting exploratory hacking harder
(e.g. I've toyed with the idea of speeding up merge-ort or other parts
of the code by rust-rewrites for self-educational purposes and
wondered why the code depended on so many things).

The focus of this series was not B; it was just "remove the cache.h
header from strbuf.c, and from any files that depend on cache.h for
the same dumb reasons".  However, even though it wasn't the focus of
my series, I would have to say that you are right that I don't believe
in having a dumping ground of "common" includes as I think it just
gets littered with things that aren't actually common.  I may well
submit future series explicitly assaulting part "B".

> Which I'd be fine with, I just personally never thought it was much of a
> practical problem, i.e. to have the gettext.h's in our tree included
> "everywhere", ditto "strbuf.h", and even "enum object_file" and other
> "mostly everyone wants these".
>
> Whereas it is rather annoying that we over-include things in cache.h, or
> even have cache.h include other headers, as often minor changes to
> related libraries result in a full re-build.

The time to rebuild the code is one concern, but wasn't even my primary concern.

> But maybe "B" isn't sustainable at all, and I'm just fooling myself
> thinking we could have such a thing.
>
> A nice thing I hadn't considered is that after your topic e.g. removing
> the gettext.h inclusion from parse-options.h will compile *most* of git,
> but we'll fail e.g. in:
>
>         t/helper/test-parse-pathspec-file.c: In function ‘cmd__parse_pathspec_file’:
>         ./parse-options.h:209:40: error: implicit declaration of function ‘N_’ [-Werror=implicit-function-declaration]
>           209 |                                        N_("file"), (h) }
>
>
> So as we don't want gettext in t/helper/* it's nice to get *an* error
> about that.

I don't see why that's a "nice thing"; it doesn't even make sense to
me as being a useful thing to try.  parse-options.h has several macros
that explicitly call N_().  Even if the code compiled with that
proposed change (because no one used those particular macros), it'd be
a bad idea unless those macros were first deleted or modified to not
depend upon gettext.h.  Since the file clearly depends upon gettext.h,
I think it should explicitly include it.

(In general, I believe if you depend upon something, you should
explicitly include it.  I was convinced otherwise for
git-compat-util.h and header files[1], but I hold that as the only
exception until others have solid reasons for other headers being
special.  In fact, I'd like to change the coding guidelines to state
that you should directly include any headers you use, with the
exception of git-compat-util.h in other header files.  We're just too
far away from that right now for it to be realistic.)

[1] https://lore.kernel.org/git/CABPp-BHizCj2e454w3vtHrDNip3Rm-gUMT0oJiAsbkAvr_QvVA@mail.gmail.com/

> So, in the end I think I've convinced myself that even the "B" in that
> "A..C" is a bad idea.

Was this based only on the mistaken idea of removing gettext.h from
parse-options.h, or on other factors?

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 00/16] Header cleanups
  2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
                   ` (16 preceding siblings ...)
  2023-03-20  9:58 ` [PATCH 00/16] Header cleanups Ævar Arnfjörð Bjarmason
@ 2023-03-21  6:25 ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
                     ` (16 more replies)
  17 siblings, 17 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git; +Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren

Maintainer note: I dropped multiple changes from this series to avoid
conflicts with other in-flight series, but has some small conflicts with
seen: one semantic conflict with ed/fsmonitor-inotify (correct resolution:
include abspath.h in the new file compat/fsmonitor/fsm-path-utils-linux.c)
and a few conflicts with sg/parse-options-h-users (which was submitted after
my series; correct resolution: just make sure all the headers are included
from both sides).

The motivating thrust of this series was trying to remove the inclusion of
cache.h from strbuf.c. This series doesn't quite achieve that, because I
dropped some changes to avoid conflicting with ed/fsmonitor-inotify, and to
avoid conflicting with Ævar's series on the_repository cleanup.

Overview of the series:

 * Patch 1: leftover cleanup from en/header-cleanups (now in master) that
   should have been included in that series
 * Patches 2-4: cleanups around gettext.h. Without these patches, many
   gettext inclusions would have to be squashed into later patches and make
   them harder to review. Also, the implicit dependency on gettext.h was
   making it much harder to find other dependencies.
 * Patch 5: move some global var declarations from cache.h into the header
   associated with where the vars are declared
 * Patches 6-16: move header declarations from cache.h into a header named
   the same as the source file containing the actual functions (e.g. move
   declarations for abspath.c functions from cache.h into abspath.h), and
   reduce the dependencies on cache.h accordingly.

Changes since v1:

 * rebased on main (to avoid conflict with jk/bundle-use-dash-for-stdfiles;
   no more conflicts with next!)
 * cleaned up the wording in patch 4
 * added more detail to this cover letter giving an overview of the series,
   and updating about conflicts

Changes not incorporated:

 * I left patch 1 before patches 2-4, since it's purpose (leftover cleanup
   from en/header-cleanups) just means it makes more sense there for me. I
   don't know how to explain it in a way that makes sense if I move it.

Notes:

 * As I mentioned in my last series, Dscho's gitgitgadget is super helpful
   for a series like this.
 * As with my previous series (en/header-cleanup), I used the scripts at my
   header-cleanup-scripts branch
   [https://github.com/newren/git/commit/db81c8d7fb554b3edf04320e218bddeb98bb6194],
   and some tweaks thereof, repeatedly while making this series (though they
   are prone to produce both false positive and false negatives, so if you
   use them, only use them to generate hints about which files to look at).

Elijah Newren (16):
  treewide: remove unnecessary cache.h inclusion from a few headers
  treewide: be explicit about dependence on gettext.h
  treewide: remove unnecessary inclusion of gettext.h
  treewide: remove unnecessary cache.h inclusion from several sources
  environment: move comment_line_char from cache.h
  abspath.h: move absolute path functions from cache.h
  cache.h: remove expand_user_path()
  path.h: move function declarations for path.c functions from cache.h
  wrapper.h: move declarations for wrapper.c functions from cache.h
  treewide: remove unnecessary includes of cache.h
  environment.h: move declarations for environment.c functions from
    cache.h
  treewide: remove cache.h inclusion due to environment.h changes
  setup.h: move declarations for setup.c functions from cache.h
  treewide: remove cache.h inclusion due to setup.h changes
  write-or-die.h: move declarations for write-or-die.c functions from
    cache.h
  csum-file.h: remove unnecessary inclusion of cache.h

 abspath.c                                    |   4 +-
 abspath.h                                    |  33 ++
 add-interactive.c                            |   1 +
 add-patch.c                                  |   2 +
 apply.c                                      |   5 +
 archive-tar.c                                |   2 +
 archive-zip.c                                |   2 +
 archive.c                                    |   4 +
 attr.c                                       |   3 +
 bisect.c                                     |   2 +
 blame.c                                      |   2 +
 branch.c                                     |   2 +
 builtin/add.c                                |   1 +
 builtin/am.c                                 |   4 +
 builtin/apply.c                              |   1 +
 builtin/archive.c                            |   1 +
 builtin/bisect.c                             |   3 +
 builtin/blame.c                              |   4 +
 builtin/branch.c                             |   3 +
 builtin/bugreport.c                          |   5 +-
 builtin/bundle.c                             |   3 +
 builtin/cat-file.c                           |   3 +
 builtin/check-attr.c                         |   4 +
 builtin/check-ignore.c                       |   2 +
 builtin/check-mailmap.c                      |   2 +
 builtin/check-ref-format.c                   |   1 +
 builtin/checkout--worker.c                   |   1 +
 builtin/checkout-index.c                     |   2 +
 builtin/checkout.c                           |   3 +
 builtin/clean.c                              |   3 +
 builtin/clone.c                              |   4 +
 builtin/column.c                             |   1 +
 builtin/commit-graph.c                       |   2 +
 builtin/commit-tree.c                        |   1 +
 builtin/commit.c                             |   2 +
 builtin/config.c                             |   5 +
 builtin/count-objects.c                      |   2 +
 builtin/credential-cache--daemon.c           |   2 +
 builtin/credential-cache.c                   |   3 +
 builtin/credential-store.c                   |   2 +
 builtin/describe.c                           |   3 +
 builtin/diagnose.c                           |   2 +
 builtin/diff-index.c                         |   1 +
 builtin/diff-tree.c                          |   1 +
 builtin/diff.c                               |   2 +
 builtin/difftool.c                           |   5 +
 builtin/fast-export.c                        |   1 +
 builtin/fast-import.c                        |   4 +
 builtin/fetch-pack.c                         |   1 +
 builtin/fetch.c                              |   2 +
 builtin/fmt-merge-msg.c                      |   2 +
 builtin/for-each-ref.c                       |   1 +
 builtin/for-each-repo.c                      |   1 +
 builtin/fsck.c                               |   1 +
 builtin/fsmonitor--daemon.c                  |   3 +
 builtin/gc.c                                 |   5 +
 builtin/get-tar-commit-id.c                  |   1 +
 builtin/grep.c                               |   3 +
 builtin/hash-object.c                        |   4 +
 builtin/help.c                               |   2 +
 builtin/hook.c                               |   1 +
 builtin/index-pack.c                         |   4 +
 builtin/init-db.c                            |   5 +
 builtin/interpret-trailers.c                 |   1 +
 builtin/log.c                                |   4 +
 builtin/ls-files.c                           |   2 +
 builtin/ls-remote.c                          |   1 +
 builtin/ls-tree.c                            |   1 +
 builtin/mailinfo.c                           |   3 +
 builtin/mailsplit.c                          |   1 +
 builtin/merge-base.c                         |   1 +
 builtin/merge-file.c                         |   3 +
 builtin/merge-recursive.c                    |   1 +
 builtin/merge-tree.c                         |   1 +
 builtin/merge.c                              |   4 +
 builtin/mktag.c                              |   1 +
 builtin/mktree.c                             |   1 +
 builtin/multi-pack-index.c                   |   3 +
 builtin/mv.c                                 |   4 +
 builtin/name-rev.c                           |   2 +
 builtin/notes.c                              |   2 +
 builtin/pack-objects.c                       |   3 +
 builtin/pack-redundant.c                     |   1 +
 builtin/pack-refs.c                          |   1 +
 builtin/patch-id.c                           |   1 +
 builtin/prune-packed.c                       |   1 +
 builtin/prune.c                              |   2 +
 builtin/pull.c                               |   1 +
 builtin/push.c                               |   2 +
 builtin/range-diff.c                         |   1 +
 builtin/read-tree.c                          |   2 +
 builtin/rebase.c                             |   4 +
 builtin/receive-pack.c                       |   4 +
 builtin/reflog.c                             |   1 +
 builtin/remote.c                             |   1 +
 builtin/repack.c                             |   2 +
 builtin/replace.c                            |   2 +
 builtin/rerere.c                             |   2 +
 builtin/reset.c                              |   3 +
 builtin/rev-list.c                           |   2 +
 builtin/rev-parse.c                          |   4 +
 builtin/revert.c                             |   1 +
 builtin/rm.c                                 |   2 +
 builtin/send-pack.c                          |   1 +
 builtin/shortlog.c                           |   3 +
 builtin/show-branch.c                        |   2 +
 builtin/show-index.c                         |   1 +
 builtin/show-ref.c                           |   1 +
 builtin/sparse-checkout.c                    |   3 +
 builtin/stash.c                              |   4 +
 builtin/stripspace.c                         |   3 +
 builtin/submodule--helper.c                  |   4 +
 builtin/symbolic-ref.c                       |   1 +
 builtin/tag.c                                |   3 +
 builtin/unpack-file.c                        |   1 +
 builtin/unpack-objects.c                     |   2 +
 builtin/update-index.c                       |   4 +
 builtin/update-ref.c                         |   1 +
 builtin/update-server-info.c                 |   1 +
 builtin/upload-pack.c                        |   1 +
 builtin/verify-commit.c                      |   1 +
 builtin/verify-pack.c                        |   1 +
 builtin/verify-tag.c                         |   1 +
 builtin/worktree.c                           |   4 +
 builtin/write-tree.c                         |   2 +
 bulk-checkin.c                               |   4 +-
 bulk-checkin.h                               |   2 +-
 bundle-uri.c                                 |   2 +
 bundle.c                                     |   3 +
 bundle.h                                     |   1 -
 cache-tree.c                                 |   3 +-
 cache.h                                      | 571 -------------------
 chdir-notify.c                               |   1 +
 chunk-format.c                               |   2 +
 color.c                                      |   1 +
 combine-diff.c                               |   1 +
 commit-graph.c                               |   4 +-
 commit.c                                     |   3 +
 common-main.c                                |   2 +
 compat/disk.h                                |   2 +
 compat/fsmonitor/fsm-health-win32.c          |   1 +
 compat/fsmonitor/fsm-listen-darwin.c         |   1 +
 compat/fsmonitor/fsm-listen-win32.c          |   1 +
 compat/fsmonitor/fsm-path-utils-darwin.c     |   1 +
 compat/fsmonitor/fsm-path-utils-win32.c      |   1 +
 compat/linux/procinfo.c                      |   2 +-
 compat/mingw.c                               |   4 +
 compat/precompose_utf8.c                     |   2 +
 compat/simple-ipc/ipc-shared.c               |   2 +-
 compat/simple-ipc/ipc-unix-socket.c          |   1 +
 compat/simple-ipc/ipc-win32.c                |   2 +
 compat/terminal.c                            |   4 +-
 config.c                                     |   7 +-
 connect.c                                    |   2 +
 connected.c                                  |   3 +-
 convert.c                                    |   2 +
 copy.c                                       |   1 +
 credential.c                                 |   2 +
 csum-file.c                                  |   3 +-
 csum-file.h                                  |   2 +-
 daemon.c                                     |   4 +
 date.c                                       |   1 +
 delta-islands.c                              |   3 +-
 diagnose.c                                   |   2 +
 diff-lib.c                                   |   1 +
 diff-no-index.c                              |   2 +
 diff.c                                       |   5 +
 dir.c                                        |   5 +
 editor.c                                     |   3 +
 entry.c                                      |   3 +
 environment.c                                |   5 +
 environment.h                                | 220 +++++++
 exec-cmd.c                                   |   3 +
 fetch-pack.c                                 |   5 +-
 fmt-merge-msg.c                              |   3 +-
 fsck.c                                       |   2 +-
 fsmonitor-ipc.c                              |   1 +
 fsmonitor.c                                  |   1 +
 gettext.c                                    |   4 +-
 git.c                                        |   3 +
 gpg-interface.c                              |   6 +-
 grep.c                                       |   3 +-
 http-backend.c                               |   5 +-
 http-fetch.c                                 |   2 +
 http-push.c                                  |   2 +
 imap-send.c                                  |   3 +
 line-log.c                                   |   2 +-
 list-objects-filter-options.h                |   1 +
 list-objects-filter.c                        |   1 +
 list-objects.c                               |   1 +
 ll-merge.c                                   |   1 +
 lockfile.c                                   |   4 +-
 log-tree.c                                   |   2 +
 ls-refs.c                                    |   4 +-
 mailmap.c                                    |   2 +
 merge-ort-wrappers.c                         |   1 +
 merge-ort.c                                  |   2 +
 merge-recursive.c                            |   3 +
 merge.c                                      |   1 +
 midx.c                                       |   4 +-
 name-hash.c                                  |   2 +
 negotiator/default.c                         |   2 +-
 negotiator/skipping.c                        |   2 +-
 notes-cache.c                                |   2 +-
 notes-merge.c                                |   2 +
 notes-utils.c                                |   4 +-
 notes.c                                      |   1 +
 object-file.c                                |   7 +-
 object-name.c                                |   3 +
 object.c                                     |   1 +
 pack-bitmap-write.c                          |   5 +-
 pack-bitmap.c                                |   3 +-
 pack-check.c                                 |   1 +
 pack-mtimes.c                                |   3 +-
 pack-revindex.c                              |   1 +
 pack-write.c                                 |   2 +
 pack.h                                       |   2 +
 packfile.c                                   |   5 +-
 packfile.h                                   |   4 +-
 parallel-checkout.c                          |   2 +
 parse-options-cb.c                           |   2 +
 parse-options.c                              |   3 +-
 parse-options.h                              |   2 +
 patch-ids.c                                  |   2 +-
 path.c                                       |   6 +-
 path.h                                       |  62 +-
 pathspec.c                                   |   4 +
 pkt-line.c                                   |   3 +
 preload-index.c                              |   2 +
 pretty.c                                     |   2 +
 progress.c                                   |   1 -
 promisor-remote.c                            |   1 +
 prompt.c                                     |   3 +-
 protocol.c                                   |   1 +
 prune-packed.c                               |   2 +
 range-diff.c                                 |   2 +
 reachable.c                                  |   3 +-
 read-cache.c                                 |   3 +
 rebase-interactive.c                         |   3 +
 ref-filter.c                                 |   4 +-
 ref-filter.h                                 |   1 +
 reflog.c                                     |   3 +-
 refs.c                                       |   6 +-
 refs.h                                       |   1 -
 refs/files-backend.c                         |   7 +-
 refs/iterator.c                              |   2 +-
 refs/packed-backend.c                        |   4 +-
 refspec.c                                    |   1 +
 remote-curl.c                                |   4 +
 remote.c                                     |   6 +-
 replace-object.c                             |   3 +-
 repository.c                                 |   2 +
 rerere.c                                     |   3 +
 rerere.h                                     |   1 +
 reset.c                                      |   1 +
 revision.c                                   |   3 +
 run-command.c                                |   2 +
 scalar.c                                     |   2 +
 send-pack.c                                  |   4 +-
 sequencer.c                                  |   4 +
 server-info.c                                |   4 +-
 setup.c                                      |   4 +
 setup.h                                      | 168 ++++++
 shallow.c                                    |   3 +-
 sideband.c                                   |   2 +
 sparse-index.c                               |   2 +
 split-index.c                                |   1 +
 strbuf.c                                     |   6 +-
 streaming.c                                  |   2 +
 streaming.h                                  |   4 +-
 submodule-config.c                           |   2 +
 submodule.c                                  |   6 +-
 symlinks.c                                   |   2 +
 t/helper/test-advise.c                       |   2 +-
 t/helper/test-bitmap.c                       |   3 +-
 t/helper/test-bloom.c                        |   4 +-
 t/helper/test-bundle-uri.c                   |   1 +
 t/helper/test-cache-tree.c                   |   2 +
 t/helper/test-config.c                       |   2 +-
 t/helper/test-delta.c                        |   2 +-
 t/helper/test-dump-cache-tree.c              |   2 +-
 t/helper/test-dump-fsmonitor.c               |   1 +
 t/helper/test-dump-split-index.c             |   1 +
 t/helper/test-dump-untracked-cache.c         |   1 +
 t/helper/test-fast-rebase.c                  |   5 +-
 t/helper/test-fsmonitor-client.c             |   2 +
 t/helper/test-hash.c                         |   1 -
 t/helper/test-lazy-init-name-hash.c          |   2 +
 t/helper/test-match-trees.c                  |   1 +
 t/helper/test-oid-array.c                    |   1 +
 t/helper/test-oidmap.c                       |   1 +
 t/helper/test-oidtree.c                      |   1 +
 t/helper/test-pack-mtimes.c                  |   2 +-
 t/helper/test-parse-pathspec-file.c          |   1 -
 t/helper/test-partial-clone.c                |   4 +-
 t/helper/test-path-utils.c                   |   3 +
 t/helper/test-pkt-line.c                     |   3 +-
 t/helper/test-proc-receive.c                 |   4 +-
 t/helper/test-progress.c                     |   1 -
 t/helper/test-reach.c                        |   3 +
 t/helper/test-read-cache.c                   |   2 +
 t/helper/test-read-graph.c                   |   2 +-
 t/helper/test-read-midx.c                    |   1 +
 t/helper/test-ref-store.c                    |   2 +-
 t/helper/test-repository.c                   |   3 +-
 t/helper/test-revision-walking.c             |   2 +-
 t/helper/test-run-command.c                  |   1 -
 t/helper/test-scrap-cache-tree.c             |   1 +
 t/helper/test-serve-v2.c                     |   3 +-
 t/helper/test-submodule-config.c             |   1 +
 t/helper/test-submodule-nested-repo-config.c |   2 +-
 t/helper/test-submodule.c                    |   2 +-
 t/helper/test-subprocess.c                   |   2 +-
 t/helper/test-trace2.c                       |   2 +-
 t/helper/test-userdiff.c                     |   2 +-
 t/helper/test-write-cache.c                  |   1 +
 tag.c                                        |   2 +
 tempfile.c                                   |   4 +-
 tmp-objdir.c                                 |   2 +
 trace.c                                      |   4 +
 trace2/tr2_cfg.c                             |   4 +-
 trace2/tr2_cmd_name.c                        |   3 +-
 trace2/tr2_dst.c                             |   4 +-
 trace2/tr2_sid.c                             |   3 +-
 trailer.c                                    |   4 +-
 transport-helper.c                           |   3 +
 transport.c                                  |   4 +-
 transport.h                                  |   1 -
 tree-walk.c                                  |   1 +
 unpack-trees.c                               |   3 +
 upload-pack.c                                |   3 +
 usage.c                                      |   4 +-
 walker.c                                     |   1 +
 worktree.c                                   |   5 +
 wrapper.c                                    |   3 +
 wrapper.h                                    |  36 ++
 write-or-die.c                               |   4 +-
 write-or-die.h                               |  78 +++
 wt-status.c                                  |   3 +
 xdiff-interface.c                            |   2 +-
 340 files changed, 1311 insertions(+), 669 deletions(-)
 create mode 100644 abspath.h
 create mode 100644 setup.h
 create mode 100644 wrapper.h
 create mode 100644 write-or-die.h


base-commit: e25cabbf6b34e4a6e903d65102d87055cc994778
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1493%2Fnewren%2Fheader-cleanup-2-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1493/newren/header-cleanup-2-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1493

Range-diff vs v1:

  1:  88959aba6f1 =  1:  a1be63930c4 treewide: remove unnecessary cache.h inclusion from a few headers
  2:  b771199fae3 =  2:  6e80396e861 treewide: be explicit about dependence on gettext.h
  3:  a31269a26b3 =  3:  644d305c669 treewide: remove unnecessary inclusion of gettext.h
  4:  3c193bef1d0 !  4:  95b86aecb43 treewide: remove unnecessary cache.h inclusion from several sources
     @@ Commit message
      
          A number of files were apparently including cache.h solely to get
          gettext.h.  By making those files explicitly include gettext.h, we can
     -    already drop the include of cache.h in these files.  Remove those now
     -    unnecessary includes.
     +    already drop the include of cache.h in these files.  On top of that,
     +    there were some files using cache.h that didn't need to for any reason.
     +    Remove these unnecessary includes.
      
          Signed-off-by: Elijah Newren <newren@gmail.com>
      
  5:  43457e44b4e =  5:  417b2ffa999 environment: move comment_line_char from cache.h
  6:  a0bbd2c9b48 !  6:  1fbd957047d abspath.h: move absolute path functions from cache.h
     @@ abspath.h (new)
      + */
      +char *prefix_filename(const char *prefix, const char *path);
      +
     ++/* Likewise, but path=="-" always yields "-" */
     ++char *prefix_filename_except_for_dash(const char *prefix, const char *path);
     ++
      +static inline int is_absolute_path(const char *path)
      +{
      +	return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
     @@ cache.h: const char *setup_git_directory(void);
      - * prefix was empty).
      - */
      -char *prefix_filename(const char *prefix, const char *path);
     +-
     +-/* Likewise, but path=="-" always yields "-" */
     +-char *prefix_filename_except_for_dash(const char *prefix, const char *path);
      -
       int check_filename(const char *prefix, const char *name);
       void verify_filename(const char *prefix,
  7:  a0fc4aa2470 =  7:  805d0a86951 cache.h: remove expand_user_path()
  8:  0f48e561b79 =  8:  b0bfbe7f38c path.h: move function declarations for path.c functions from cache.h
  9:  66f06731cab =  9:  43a61845240 wrapper.h: move declarations for wrapper.c functions from cache.h
 10:  f4e15c9e5c2 = 10:  a6c7245219a treewide: remove unnecessary includes of cache.h
 11:  fa7449b5b99 = 11:  5ef1a4f1d6c environment.h: move declarations for environment.c functions from cache.h
 12:  4e6a4030b1e = 12:  496d36e4fd0 treewide: remove cache.h inclusion due to environment.h changes
 13:  9722988e537 = 13:  1d5cd115161 setup.h: move declarations for setup.c functions from cache.h
 14:  0e84202da90 = 14:  30b21691265 treewide: remove cache.h inclusion due to setup.h changes
 15:  626d089f10b = 15:  6e40d1d783d write-or-die.h: move declarations for write-or-die.c functions from cache.h
 16:  38af06f55bc = 16:  72d58b391a1 csum-file.h: remove unnecessary inclusion of cache.h

-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 01/16] treewide: remove unnecessary cache.h inclusion from a few headers
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 02/16] treewide: be explicit about dependence on gettext.h Elijah Newren via GitGitGadget
                     ` (15 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Ever since a64215b6cd ("object.h: stop depending on cache.h; make
cache.h depend on object.h", 2023-02-24), we have a few headers that
could have replaced their include of cache.h with an include of
object.h.  Make that change now.

Some C files had to start including cache.h after this change (or some
smaller header it had brought in), because the C files were depending
on things from cache.h but were only formerly implicitly getting
cache.h through one of these headers being modified in this patch.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 bulk-checkin.h              | 2 +-
 bundle.h                    | 1 -
 cache-tree.c                | 2 +-
 config.c                    | 2 +-
 fmt-merge-msg.c             | 2 +-
 fsck.c                      | 2 +-
 http-backend.c              | 2 +-
 pack-mtimes.c               | 2 +-
 packfile.h                  | 4 +++-
 prune-packed.c              | 2 +-
 ref-filter.c                | 2 +-
 refs.c                      | 2 +-
 refs.h                      | 1 -
 refs/packed-backend.c       | 2 +-
 refspec.c                   | 1 +
 remote.c                    | 2 +-
 server-info.c               | 2 +-
 shallow.c                   | 2 +-
 strbuf.c                    | 2 +-
 streaming.h                 | 4 +++-
 submodule.c                 | 2 +-
 t/helper/test-bundle-uri.c  | 1 +
 t/helper/test-fast-rebase.c | 2 +-
 t/helper/test-pack-mtimes.c | 2 +-
 t/helper/test-reach.c       | 1 +
 transport.c                 | 2 +-
 transport.h                 | 1 -
 worktree.c                  | 2 +-
 28 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/bulk-checkin.h b/bulk-checkin.h
index 8281b9cb159..48fe9a6e917 100644
--- a/bulk-checkin.h
+++ b/bulk-checkin.h
@@ -4,7 +4,7 @@
 #ifndef BULK_CHECKIN_H
 #define BULK_CHECKIN_H
 
-#include "cache.h"
+#include "object.h"
 
 void prepare_loose_object_bulk_checkin(void);
 void fsync_loose_object_bulk_checkin(int fd, const char *filename);
diff --git a/bundle.h b/bundle.h
index 9f2bd733a6a..021adbdcbb3 100644
--- a/bundle.h
+++ b/bundle.h
@@ -2,7 +2,6 @@
 #define BUNDLE_H
 
 #include "strvec.h"
-#include "cache.h"
 #include "string-list.h"
 #include "list-objects-filter-options.h"
 
diff --git a/cache-tree.c b/cache-tree.c
index 9d46ecef091..6f899beb041 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/config.c b/config.c
index d0aff55fa66..983c45fc37b 100644
--- a/config.c
+++ b/config.c
@@ -5,7 +5,7 @@
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "date.h"
 #include "branch.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 24cc44bdbc9..c870cb95b9d 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "refs.h"
diff --git a/fsck.c b/fsck.c
index 871c0a9a252..70e12497878 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/http-backend.c b/http-backend.c
index 9cfc6f25414..7e7c19e66b3 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hex.h"
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 0f9785fc5e4..cd92fc1d86c 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "pack-mtimes.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/packfile.h b/packfile.h
index a3f6723857b..648be62bf22 100644
--- a/packfile.h
+++ b/packfile.h
@@ -1,11 +1,13 @@
 #ifndef PACKFILE_H
 #define PACKFILE_H
 
-#include "cache.h"
+#include "object.h"
 #include "oidset.h"
 
 /* in object-store.h */
 struct packed_git;
+struct pack_entry;
+struct pack_window;
 struct object_info;
 
 /*
diff --git a/prune-packed.c b/prune-packed.c
index d2813f6a405..e02f466c2ee 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "object-store.h"
 #include "packfile.h"
 #include "progress.h"
diff --git a/ref-filter.c b/ref-filter.c
index ed802778da7..38141bce8db 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/refs.c b/refs.c
index 53240bcc07b..4e5cc73fb10 100644
--- a/refs.c
+++ b/refs.c
@@ -2,7 +2,7 @@
  * The backend-independent part of the reference module.
  */
 
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hashmap.h"
diff --git a/refs.h b/refs.h
index 935cdd1ece3..5741b69d0d1 100644
--- a/refs.h
+++ b/refs.h
@@ -1,7 +1,6 @@
 #ifndef REFS_H
 #define REFS_H
 
-#include "cache.h"
 #include "commit.h"
 
 struct object_id;
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index b665d0f7d9b..6f975185995 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,4 +1,4 @@
-#include "../git-compat-util.h"
+#include "../cache.h"
 #include "../alloc.h"
 #include "../config.h"
 #include "../hex.h"
diff --git a/refspec.c b/refspec.c
index 28d90911aa5..7b5c305514d 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
 #include "refs.h"
diff --git a/remote.c b/remote.c
index b04e5da3383..2daddb85cb7 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hex.h"
diff --git a/server-info.c b/server-info.c
index 40436892023..78643377057 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "dir.h"
 #include "hex.h"
diff --git a/shallow.c b/shallow.c
index 1cbb05ba0e4..c5433a4fd30 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/strbuf.c b/strbuf.c
index 1c57ac6574f..8800830ebf8 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/streaming.h b/streaming.h
index 5e4e6acfd0d..bd27f59e576 100644
--- a/streaming.h
+++ b/streaming.h
@@ -3,10 +3,12 @@
  */
 #ifndef STREAMING_H
 #define STREAMING_H 1
-#include "cache.h"
+
+#include "object.h"
 
 /* opaque */
 struct git_istream;
+struct stream_filter;
 
 struct git_istream *open_istream(struct repository *, const struct object_id *,
 				 enum object_type *, unsigned long *,
diff --git a/submodule.c b/submodule.c
index 2a057c35b74..0baf97cf770 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
diff --git a/t/helper/test-bundle-uri.c b/t/helper/test-bundle-uri.c
index b18e7603103..475058592d1 100644
--- a/t/helper/test-bundle-uri.c
+++ b/t/helper/test-bundle-uri.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "parse-options.h"
 #include "bundle-uri.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "transport.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index b1edb92a032..1e975df9041 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -12,7 +12,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-
+#include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "hex.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index f68b3761b68..0e53dee9e57 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,5 +1,5 @@
-#include "git-compat-util.h"
 #include "test-tool.h"
+#include "cache.h"
 #include "hex.h"
 #include "strbuf.h"
 #include "object-store.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index de8f26639d4..05d56267a9f 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,4 +1,5 @@
 #include "test-tool.h"
+#include "cache.h"
 #include "alloc.h"
 #include "commit.h"
 #include "commit-reach.h"
diff --git a/transport.c b/transport.c
index 906dbad5a08..80059124c0a 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "config.h"
 #include "hex.h"
diff --git a/transport.h b/transport.h
index 85150f504fb..6393cd9823c 100644
--- a/transport.h
+++ b/transport.h
@@ -1,7 +1,6 @@
 #ifndef TRANSPORT_H
 #define TRANSPORT_H
 
-#include "cache.h"
 #include "run-command.h"
 #include "remote.h"
 #include "list-objects-filter-options.h"
diff --git a/worktree.c b/worktree.c
index e10594ef336..cbb0db2d7cc 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "repository.h"
 #include "refs.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 02/16] treewide: be explicit about dependence on gettext.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 03/16] treewide: remove unnecessary inclusion of gettext.h Elijah Newren via GitGitGadget
                     ` (14 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Dozens of files made use of gettext functions, without explicitly
including gettext.h.  This made it more difficult to find which files
could remove a dependence on cache.h.  Make C files explicitly include
gettext.h if they are using it.

However, while compat/fsmonitor/fsm-ipc-darwin.c should also gain an
include of gettext.h, it was left out to avoid conflicting with an
in-flight topic.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                        | 1 +
 add-patch.c                              | 1 +
 apply.c                                  | 1 +
 archive-tar.c                            | 1 +
 archive-zip.c                            | 1 +
 archive.c                                | 1 +
 attr.c                                   | 1 +
 bisect.c                                 | 1 +
 blame.c                                  | 1 +
 branch.c                                 | 1 +
 builtin/add.c                            | 1 +
 builtin/am.c                             | 1 +
 builtin/apply.c                          | 1 +
 builtin/archive.c                        | 1 +
 builtin/bisect.c                         | 1 +
 builtin/blame.c                          | 1 +
 builtin/branch.c                         | 1 +
 builtin/bugreport.c                      | 1 +
 builtin/bundle.c                         | 1 +
 builtin/cat-file.c                       | 1 +
 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                          | 1 +
 builtin/clone.c                          | 1 +
 builtin/column.c                         | 1 +
 builtin/commit-graph.c                   | 1 +
 builtin/commit-tree.c                    | 1 +
 builtin/commit.c                         | 1 +
 builtin/config.c                         | 1 +
 builtin/count-objects.c                  | 1 +
 builtin/credential-cache--daemon.c       | 1 +
 builtin/credential-cache.c               | 1 +
 builtin/credential-store.c               | 1 +
 builtin/describe.c                       | 1 +
 builtin/diagnose.c                       | 1 +
 builtin/diff-tree.c                      | 1 +
 builtin/diff.c                           | 1 +
 builtin/difftool.c                       | 1 +
 builtin/fast-export.c                    | 1 +
 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                             | 1 +
 builtin/grep.c                           | 1 +
 builtin/hash-object.c                    | 1 +
 builtin/help.c                           | 1 +
 builtin/hook.c                           | 1 +
 builtin/index-pack.c                     | 1 +
 builtin/init-db.c                        | 1 +
 builtin/interpret-trailers.c             | 1 +
 builtin/log.c                            | 1 +
 builtin/ls-files.c                       | 1 +
 builtin/ls-remote.c                      | 1 +
 builtin/ls-tree.c                        | 1 +
 builtin/mailinfo.c                       | 1 +
 builtin/mailsplit.c                      | 1 +
 builtin/merge-base.c                     | 1 +
 builtin/merge-file.c                     | 1 +
 builtin/merge-recursive.c                | 1 +
 builtin/merge-tree.c                     | 1 +
 builtin/merge.c                          | 1 +
 builtin/mktag.c                          | 1 +
 builtin/mktree.c                         | 1 +
 builtin/multi-pack-index.c               | 1 +
 builtin/mv.c                             | 1 +
 builtin/name-rev.c                       | 1 +
 builtin/notes.c                          | 1 +
 builtin/pack-objects.c                   | 1 +
 builtin/pack-redundant.c                 | 1 +
 builtin/pack-refs.c                      | 1 +
 builtin/patch-id.c                       | 1 +
 builtin/prune-packed.c                   | 1 +
 builtin/prune.c                          | 1 +
 builtin/pull.c                           | 1 +
 builtin/push.c                           | 1 +
 builtin/range-diff.c                     | 1 +
 builtin/read-tree.c                      | 1 +
 builtin/rebase.c                         | 1 +
 builtin/receive-pack.c                   | 1 +
 builtin/reflog.c                         | 1 +
 builtin/remote.c                         | 1 +
 builtin/repack.c                         | 1 +
 builtin/replace.c                        | 1 +
 builtin/rerere.c                         | 1 +
 builtin/reset.c                          | 1 +
 builtin/rev-list.c                       | 1 +
 builtin/rev-parse.c                      | 1 +
 builtin/revert.c                         | 1 +
 builtin/rm.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                            | 1 +
 builtin/unpack-objects.c                 | 1 +
 builtin/update-index.c                   | 1 +
 builtin/update-ref.c                     | 1 +
 builtin/update-server-info.c             | 1 +
 builtin/upload-pack.c                    | 1 +
 builtin/verify-commit.c                  | 1 +
 builtin/verify-pack.c                    | 1 +
 builtin/verify-tag.c                     | 1 +
 builtin/worktree.c                       | 1 +
 builtin/write-tree.c                     | 1 +
 bulk-checkin.c                           | 1 +
 bundle-uri.c                             | 1 +
 bundle.c                                 | 1 +
 chunk-format.c                           | 1 +
 color.c                                  | 1 +
 commit-graph.c                           | 1 +
 commit.c                                 | 1 +
 common-main.c                            | 1 +
 compat/disk.h                            | 1 +
 compat/fsmonitor/fsm-health-win32.c      | 1 +
 compat/fsmonitor/fsm-listen-darwin.c     | 1 +
 compat/fsmonitor/fsm-listen-win32.c      | 1 +
 compat/fsmonitor/fsm-path-utils-darwin.c | 1 +
 compat/fsmonitor/fsm-path-utils-win32.c  | 1 +
 compat/mingw.c                           | 1 +
 compat/precompose_utf8.c                 | 1 +
 compat/simple-ipc/ipc-unix-socket.c      | 1 +
 compat/simple-ipc/ipc-win32.c            | 1 +
 compat/terminal.c                        | 1 +
 config.c                                 | 1 +
 connect.c                                | 1 +
 connected.c                              | 1 +
 convert.c                                | 1 +
 credential.c                             | 1 +
 date.c                                   | 1 +
 delta-islands.c                          | 1 +
 diagnose.c                               | 1 +
 diff-lib.c                               | 1 +
 diff-no-index.c                          | 1 +
 diff.c                                   | 1 +
 dir.c                                    | 1 +
 editor.c                                 | 1 +
 entry.c                                  | 1 +
 environment.c                            | 1 +
 exec-cmd.c                               | 1 +
 fetch-pack.c                             | 1 +
 fsmonitor-ipc.c                          | 1 +
 git.c                                    | 1 +
 gpg-interface.c                          | 1 +
 grep.c                                   | 1 +
 http-fetch.c                             | 1 +
 imap-send.c                              | 1 +
 list-objects-filter-options.h            | 1 +
 list-objects-filter.c                    | 1 +
 list-objects.c                           | 1 +
 lockfile.c                               | 1 +
 ls-refs.c                                | 1 +
 merge-ort-wrappers.c                     | 1 +
 merge-ort.c                              | 1 +
 merge-recursive.c                        | 1 +
 merge.c                                  | 1 +
 midx.c                                   | 1 +
 name-hash.c                              | 1 +
 notes-merge.c                            | 1 +
 notes-utils.c                            | 1 +
 object-file.c                            | 1 +
 object-name.c                            | 1 +
 object.c                                 | 1 +
 pack-bitmap-write.c                      | 1 +
 pack-bitmap.c                            | 1 +
 pack-mtimes.c                            | 1 +
 pack-revindex.c                          | 1 +
 pack-write.c                             | 1 +
 packfile.c                               | 1 +
 parallel-checkout.c                      | 1 +
 parse-options-cb.c                       | 1 +
 parse-options.c                          | 1 +
 parse-options.h                          | 2 ++
 path.c                                   | 1 +
 pathspec.c                               | 1 +
 pkt-line.c                               | 1 +
 preload-index.c                          | 1 +
 pretty.c                                 | 1 +
 promisor-remote.c                        | 1 +
 prune-packed.c                           | 1 +
 range-diff.c                             | 1 +
 reachable.c                              | 1 +
 read-cache.c                             | 1 +
 rebase-interactive.c                     | 1 +
 ref-filter.c                             | 1 +
 ref-filter.h                             | 1 +
 reflog.c                                 | 1 +
 refs.c                                   | 1 +
 refs/files-backend.c                     | 1 +
 refs/packed-backend.c                    | 1 +
 remote-curl.c                            | 1 +
 remote.c                                 | 1 +
 replace-object.c                         | 1 +
 rerere.c                                 | 1 +
 rerere.h                                 | 1 +
 reset.c                                  | 1 +
 revision.c                               | 1 +
 run-command.c                            | 1 +
 send-pack.c                              | 1 +
 sequencer.c                              | 1 +
 setup.c                                  | 1 +
 sideband.c                               | 1 +
 sparse-index.c                           | 1 +
 split-index.c                            | 1 +
 strbuf.c                                 | 1 +
 submodule-config.c                       | 1 +
 submodule.c                              | 1 +
 symlinks.c                               | 1 +
 t/helper/test-cache-tree.c               | 1 +
 t/helper/test-fast-rebase.c              | 1 +
 t/helper/test-reach.c                    | 1 +
 t/helper/test-serve-v2.c                 | 1 +
 trailer.c                                | 1 +
 transport-helper.c                       | 1 +
 tree-walk.c                              | 1 +
 unpack-trees.c                           | 1 +
 upload-pack.c                            | 1 +
 usage.c                                  | 2 +-
 walker.c                                 | 1 +
 worktree.c                               | 1 +
 wrapper.c                                | 1 +
 wt-status.c                              | 1 +
 235 files changed, 236 insertions(+), 1 deletion(-)

diff --git a/add-interactive.c b/add-interactive.c
index ae25ec50bce..b750543bd87 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -3,6 +3,7 @@
 #include "color.h"
 #include "config.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "refs.h"
diff --git a/add-patch.c b/add-patch.c
index e6c34b9c381..4c803a5f4db 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "add-interactive.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/apply.c b/apply.c
index 8776ab939ad..e0bdd43a68e 100644
--- a/apply.c
+++ b/apply.c
@@ -15,6 +15,7 @@
 #include "delta.h"
 #include "diff.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "xdiff-interface.h"
 #include "ll-merge.h"
diff --git a/archive-tar.c b/archive-tar.c
index ee27fa0b39b..16ee133bbf5 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tar.h"
 #include "archive.h"
diff --git a/archive-zip.c b/archive-zip.c
index c5d1f72eb80..c02dc33e406 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "config.h"
 #include "archive.h"
+#include "gettext.h"
 #include "hex.h"
 #include "streaming.h"
 #include "utf8.h"
diff --git a/archive.c b/archive.c
index 1c2ca78e52a..2c3da1cff30 100644
--- a/archive.c
+++ b/archive.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/attr.c b/attr.c
index 657ee52229e..48e2d646187 100644
--- a/attr.c
+++ b/attr.c
@@ -12,6 +12,7 @@
 #include "exec-cmd.h"
 #include "attr.h"
 #include "dir.h"
+#include "gettext.h"
 #include "utf8.h"
 #include "quote.h"
 #include "revision.h"
diff --git a/bisect.c b/bisect.c
index 1409150c5c3..5a3a8182d83 100644
--- a/bisect.c
+++ b/bisect.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "refs.h"
diff --git a/blame.c b/blame.c
index e45d8a3bf92..b7cd849bb6b 100644
--- a/blame.c
+++ b/blame.c
@@ -5,6 +5,7 @@
 #include "mergesort.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "blame.h"
diff --git a/branch.c b/branch.c
index eacef62b7c9..66d32c68564 100644
--- a/branch.c
+++ b/branch.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "branch.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/add.c b/builtin/add.c
index 61dd386d109..f12054d9be1 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -9,6 +9,7 @@
 #include "builtin.h"
 #include "lockfile.h"
 #include "dir.h"
+#include "gettext.h"
 #include "pathspec.h"
 #include "exec-cmd.h"
 #include "cache-tree.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5e6b237c424..cc1fdf4f75d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "dir.h"
diff --git a/builtin/apply.c b/builtin/apply.c
index 555219de40f..fe72c0ec3eb 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "apply.h"
 
diff --git a/builtin/archive.c b/builtin/archive.c
index d0a583ea958..d13934f1a80 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "archive.h"
+#include "gettext.h"
 #include "transport.h"
 #include "parse-options.h"
 #include "pkt-line.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index c64c8d715a5..09188e554b3 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "bisect.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index fdd9f0c0fc7..21f6b523a6d 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index f63fd45edb9..a67a8334d5c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -11,6 +11,7 @@
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "remote.h"
 #include "parse-options.h"
 #include "branch.h"
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 5bc254be80f..b61cfa9464f 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "strbuf.h"
 #include "help.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 666f01bccd0..de3898ffa41 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "strvec.h"
 #include "parse-options.h"
 #include "cache.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9e7e03ade41..9f1bf8f0e96 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "ident.h"
 #include "parse-options.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index d7a40e674ca..ad27255e2cb 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "attr.h"
+#include "gettext.h"
 #include "quote.h"
 #include "parse-options.h"
 
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index ab776061c7c..a45d001e353 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "quote.h"
 #include "pathspec.h"
 #include "parse-options.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index 96db3ddb4bb..fa86fd9423d 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "ident.h"
 #include "mailmap.h"
 #include "parse-options.h"
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index 0a7d762573c..2120dd1d300 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
+#include "gettext.h"
 #include "parallel-checkout.h"
 #include "parse-options.h"
 #include "pkt-line.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index cf6fba97ba7..828c0363f8a 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -8,6 +8,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 734d730980c..47d4c369a16 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "diff.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "hook.h"
 #include "ll-merge.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 10aaa8c603f..46c51029ab4 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "quote.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 462c286274c..d605fcafa0f 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -11,6 +11,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/column.c b/builtin/column.c
index 158fdf53d9f..de623a16c2d 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index d3be7f3b318..311e0106810 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index e805da5bb1c..0ef55d83d49 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index f71ed41bf59..25575435ad7 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -16,6 +16,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "commit.h"
+#include "gettext.h"
 #include "revision.h"
 #include "wt-status.h"
 #include "run-command.h"
diff --git a/builtin/config.c b/builtin/config.c
index 49d832d4093..33b17b40b41 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "color.h"
+#include "gettext.h"
 #include "ident.h"
 #include "parse-options.h"
 #include "urlmatch.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index bb21bc43e42..48edc86c240 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "repository.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index 6e509d02c37..0f00ba4d741 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 #ifndef NO_UNIX_SOCKETS
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 78c02ad5319..25f2f71c216 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 #ifndef NO_UNIX_SOCKETS
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index 62a4f3c2653..da32cfd89e2 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "lockfile.h"
 #include "credential.h"
 #include "string-list.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 5b5930f5c8c..fcacdf8a693 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "commit.h"
diff --git a/builtin/diagnose.c b/builtin/diagnose.c
index d52015c67a4..5b12d1fb963 100644
--- a/builtin/diagnose.c
+++ b/builtin/diagnose.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "diagnose.h"
 
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index a393efa4f08..385c2d0230c 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "diff.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 26f1e532c66..20bdb6e6cec 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -11,6 +11,7 @@
 #include "color.h"
 #include "commit.h"
 #include "blob.h"
+#include "gettext.h"
 #include "tag.h"
 #include "diff.h"
 #include "diff-merges.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 01681d0fb88..f7380dd1cc7 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -17,6 +17,7 @@
 #include "builtin.h"
 #include "run-command.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "strvec.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 78493c6d2bf..9ab2e34ef05 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -6,6 +6,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index f7548ff4a35..f3635c7aefd 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 702c9a3397e..60e5a10ffc5 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pkt-line.h"
 #include "fetch-pack.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 7221e57f352..990f81f6d1a 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 8d8fd393f89..0f9855b680e 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "fmt-merge-msg.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 static const char * const fmt_merge_msg_usage[] = {
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 6f62f40d126..7a8ff5902cf 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "object.h"
 #include "parse-options.h"
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 6aeac371488..27425c2fc9e 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "run-command.h"
 #include "string-list.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index c4a633c0329..1375e32d2a1 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index cae804a1908..215e3813d7d 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "fsmonitor.h"
 #include "fsmonitor-ipc.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index c58fe8c936c..32cabad7cf6 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -32,6 +32,7 @@
 #include "refs.h"
 #include "remote.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hook.h"
 
 #define FAILED_RUN "failed to run %s"
diff --git a/builtin/grep.c b/builtin/grep.c
index c590fcb19dd..3c9c6b38031 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 1848768b97c..f233eda7590 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -6,6 +6,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "blob.h"
diff --git a/builtin/help.c b/builtin/help.c
index 53f2812dfb1..3fde5c4fd35 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "run-command.h"
 #include "config-list.h"
diff --git a/builtin/hook.c b/builtin/hook.c
index f95b7965c58..88051795c7f 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hook.h"
 #include "parse-options.h"
 #include "strbuf.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b451755f405..bae5b054039 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "delta.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index dcaaf102eaf..e182bc7e839 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "builtin.h"
 #include "exec-cmd.h"
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
index e58627c72a9..107ac28f0e8 100644
--- a/builtin/interpret-trailers.c
+++ b/builtin/interpret-trailers.c
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "trailer.h"
diff --git a/builtin/log.c b/builtin/log.c
index bc204ea76ff..e702cf126e5 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -7,6 +7,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a03b559ecaa..09deb752ab3 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -11,6 +11,7 @@
 #include "quote.h"
 #include "dir.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "tree.h"
 #include "cache-tree.h"
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 2dfbd8ed9b9..11d9424804a 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "transport.h"
 #include "ref-filter.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 64d8e54318c..b4835f1d4cc 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "blob.h"
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 01d16ef9e5a..e8bb011cfb4 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -4,6 +4,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 73509f651bd..b08069ce60a 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -6,6 +6,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "strbuf.h"
 
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index be8f3b221c9..e0995f3219f 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index c923bbf2abb..ae45f523b95 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "parse-options.h"
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index b9acbf5d342..a49fab9bcb1 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "commit.h"
+#include "gettext.h"
 #include "tag.h"
 #include "merge-recursive.h"
 #include "xdiff-interface.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index e7825181648..89b807388a4 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -3,6 +3,7 @@
 #include "tree-walk.h"
 #include "xdiff-interface.h"
 #include "help.h"
+#include "gettext.h"
 #include "hex.h"
 #include "commit.h"
 #include "commit-reach.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 19c31d4ff48..a90ae5d2ddc 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "builtin.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 42c2457c705..e93aee72258 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "tag.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 848c7b47476..09a7bd5c5c2 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "quote.h"
 #include "tree.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 9a18a82b057..e6757a44470 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
 #include "trace2.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 81290503775..c02dddb72b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "pathspec.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 723ba616a88..6977a5f580b 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index 75ce7f3f574..8e9be33ddbb 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "notes.h"
 #include "object-store.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 545b8bddc8e..1ca800c7c50 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 82115c5808c..3451971b564 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -7,6 +7,7 @@
 */
 
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "packfile.h"
diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index 27c2ca06acb..9833815fb30 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "repository.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 338b15cd7b0..9d5585d3a72 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index da3273a268b..ca3578e1588 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "prune-packed.h"
 
diff --git a/builtin/prune.c b/builtin/prune.c
index 119a253a2ad..ff62a0adb8f 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "builtin.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 56f679d94a0..1a1a89af055 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
diff --git a/builtin/push.c b/builtin/push.c
index 12a402aea3d..2d76fa68376 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "branch.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "refspec.h"
 #include "run-command.h"
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index aecfae12d3a..97724fd0ed7 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "range-diff.h"
 #include "config.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 11759c415f3..ec66008d07e 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -7,6 +7,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "object.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index dd31d5ab91e..a2c68b8ff7b 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -6,6 +6,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
 #include "exec-cmd.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 6a24ab4f451..006565f8513 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "repository.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "pack.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 270681dcdf4..0879d4d2246 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 729f6f3643a..2074d6be28c 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 87f73c8923a..771ca01527d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 71d8e949e35..cf85e590d9f 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 94ffb8c21ab..24c78755723 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "rerere.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 24b04aeecb9..4335c1a6e1b 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -10,6 +10,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tag.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 85e522dff8a..f2f6a0d3e67 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "list-objects.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index e1fa9c6348c..5a932a861b4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -8,6 +8,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 62986a7b1b0..dd6587a99d8 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -4,6 +4,7 @@
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
+#include "gettext.h"
 #include "revision.h"
 #include "rerere.h"
 #include "dir.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index dc198f79082..5982c3d8122 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -11,6 +11,7 @@
 #include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
+#include "gettext.h"
 #include "tree-walk.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 27a87167e19..d8c4379ea16 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "revision.h"
 #include "utf8.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 8342b68aef7..8d569629726 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pretty.h"
 #include "refs.h"
diff --git a/builtin/show-index.c b/builtin/show-index.c
index 98ec40ddf46..d4bbbbcd6ce 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pack.h"
 #include "parse-options.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 1f28d7fe4b9..a5df7587d51 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 8d5ae6f2a60..3976d8e86b8 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "pathspec.h"
 #include "repository.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 6a12fed2713..65817d0b763 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e34cf2bebd..d8e61459333 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "strbuf.h"
 
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index d05d1a84623..a4bdd44daa3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "cache.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index e00768a8b7e..10198a74fae 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "cache.h"
+#include "gettext.h"
 #include "refs.h"
 #include "parse-options.h"
 
diff --git a/builtin/tag.c b/builtin/tag.c
index adcaa547b0d..c2ea89c4754 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 1908dcfcffb..f7c4b531076 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "object.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 11dc1352716..ef78b2d28e1 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "quote.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index a84e7b47a20..fdf51495b51 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "refs.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index d2239c9ef4d..e7bff27ae40 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "parse-options.h"
 
 static const char * const update_server_info_usage[] = {
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index 7a3c68720f1..beb9dd08610 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "pkt-line.h"
 #include "parse-options.h"
 #include "protocol.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 7aedf10e856..22e5afc069e 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index 27d6f75fd8a..190fd695409 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
 
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5c00b0b0f77..850e1a11c7b 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "gettext.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 80d05e246d8..ed89b7e9725 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "strvec.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 7ad0d059453..7eec4e3cbd1 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index d64cd5c52d0..778ca1e0f4f 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "repository.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 177c1810402..2cc7d159bd6 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "bundle-uri.h"
 #include "bundle.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "refs.h"
 #include "run-command.h"
diff --git a/bundle.c b/bundle.c
index 99d7de97f6c..f5b3643b17e 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "lockfile.h"
 #include "bundle.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/chunk-format.c b/chunk-format.c
index f65e9a1e429..6d1071729df 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "chunk-format.h"
 #include "csum-file.h"
+#include "gettext.h"
 
 /*
  * When writing a chunk-based file format, collect the chunks in
diff --git a/color.c b/color.c
index 6b577ce0a75..672dcbb73a6 100644
--- a/color.c
+++ b/color.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "color.h"
+#include "gettext.h"
 #include "hex.h"
 
 static int git_use_color_default = GIT_COLOR_AUTO;
diff --git a/commit-graph.c b/commit-graph.c
index 5e6098ff356..8f21a0a0c20 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "pack.h"
diff --git a/commit.c b/commit.c
index 7b63d3b0e1c..3fdfb325117 100644
--- a/commit.c
+++ b/commit.c
@@ -2,6 +2,7 @@
 #include "tag.h"
 #include "commit.h"
 #include "commit-graph.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/common-main.c b/common-main.c
index 0a22861f1ce..184d1534d2d 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "attr.h"
 
 /*
diff --git a/compat/disk.h b/compat/disk.h
index 50a32e3d8a4..a04a8d294af 100644
--- a/compat/disk.h
+++ b/compat/disk.h
@@ -2,6 +2,7 @@
 #define COMPAT_DISK_H
 
 #include "git-compat-util.h"
+#include "gettext.h"
 
 static int get_disk_info(struct strbuf *out)
 {
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index 2ea08c1d4e8..fe11bdd9ce6 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -3,6 +3,7 @@
 #include "fsmonitor.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
+#include "gettext.h"
 
 /*
  * Every minute wake up and test our health.
diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 97a55a6f0a4..5eb6402ab82 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -28,6 +28,7 @@
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "fsmonitor-path-utils.h"
+#include "gettext.h"
 
 struct fsm_listen_data
 {
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 03df8d951b8..7b07b74ba5b 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -3,6 +3,7 @@
 #include "fsmonitor.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
+#include "gettext.h"
 
 /*
  * The documentation of ReadDirectoryChangesW() states that the maximum
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index ce5a8febe09..45eb4a9b9e7 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,5 +1,6 @@
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
+#include "gettext.h"
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c
index 0d95bbb416f..4024baafb97 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
+#include "gettext.h"
 
 /*
  * Check remote working directory protocol.
diff --git a/compat/mingw.c b/compat/mingw.c
index 3afbde78944..a9e5570288c 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -11,6 +11,7 @@
 #include "win32/lazyload.h"
 #include "../config.h"
 #include "dir.h"
+#include "gettext.h"
 #define SECURITY_WIN32
 #include <sspi.h>
 
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index cce1d57a464..56d36cdf22a 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
diff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c
index 28a79289d4f..152db60a311 100644
--- a/compat/simple-ipc/ipc-unix-socket.c
+++ b/compat/simple-ipc/ipc-unix-socket.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 20ea7b65e0b..f011e5cead8 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
diff --git a/compat/terminal.c b/compat/terminal.c
index ea490a7ced4..afebe6b2496 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "compat/terminal.h"
+#include "gettext.h"
 #include "sigchain.h"
 #include "strbuf.h"
 #include "run-command.h"
diff --git a/config.c b/config.c
index 983c45fc37b..f30a6d8e686 100644
--- a/config.c
+++ b/config.c
@@ -11,6 +11,7 @@
 #include "branch.h"
 #include "config.h"
 #include "environment.h"
+#include "gettext.h"
 #include "ident.h"
 #include "repository.h"
 #include "lockfile.h"
diff --git a/connect.c b/connect.c
index 000865bc33e..f3b159bf441 100644
--- a/connect.c
+++ b/connect.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pkt-line.h"
 #include "quote.h"
diff --git a/connected.c b/connected.c
index 39cb1e1074d..a4c0aece757 100644
--- a/connected.c
+++ b/connected.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "run-command.h"
diff --git a/convert.c b/convert.c
index 349c7e4af15..2bd54244b55 100644
--- a/convert.c
+++ b/convert.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/credential.c b/credential.c
index ea40a2a410b..5244f3c12c0 100644
--- a/credential.c
+++ b/credential.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "credential.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "url.h"
diff --git a/date.c b/date.c
index 6f45eeb3568..1fb2cd1b538 100644
--- a/date.c
+++ b/date.c
@@ -6,6 +6,7 @@
 
 #include "cache.h"
 #include "date.h"
+#include "gettext.h"
 
 /*
  * This is like mktime, but without normalization of tm_wday and tm_yday.
diff --git a/delta-islands.c b/delta-islands.c
index fe12c93005b..1222b6a6cd1 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -4,6 +4,7 @@
 #include "object.h"
 #include "blob.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "tree.h"
diff --git a/diagnose.c b/diagnose.c
index 5b398f0cffc..169a55407fd 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -4,6 +4,7 @@
 #include "archive.h"
 #include "dir.h"
 #include "help.h"
+#include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
 #include "object-store.h"
diff --git a/diff-lib.c b/diff-lib.c
index 70b3578b907..a7e04009873 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -6,6 +6,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "cache-tree.h"
diff --git a/diff-no-index.c b/diff-no-index.c
index a3cf358baf0..287a113badd 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -11,6 +11,7 @@
 #include "tag.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "parse-options.h"
diff --git a/diff.c b/diff.c
index 00d47281a1d..00746f2f86e 100644
--- a/diff.c
+++ b/diff.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "tempfile.h"
 #include "quote.h"
 #include "diff.h"
diff --git a/dir.c b/dir.c
index d5bb199f4b4..46f1bb6e5b7 100644
--- a/dir.c
+++ b/dir.c
@@ -9,6 +9,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "attr.h"
 #include "refs.h"
diff --git a/editor.c b/editor.c
index 008c04fe2f6..58e790548d2 100644
--- a/editor.c
+++ b/editor.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "strbuf.h"
 #include "strvec.h"
 #include "run-command.h"
diff --git a/entry.c b/entry.c
index c97cfa833bb..acb76a61aca 100644
--- a/entry.c
+++ b/entry.c
@@ -2,6 +2,7 @@
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "streaming.h"
 #include "submodule.h"
diff --git a/environment.c b/environment.c
index 89d89110e41..82a1fc17d0b 100644
--- a/environment.c
+++ b/environment.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "branch.h"
 #include "environment.h"
+#include "gettext.h"
 #include "repository.h"
 #include "config.h"
 #include "refs.h"
diff --git a/exec-cmd.c b/exec-cmd.c
index 0232bbc9905..282d95af081 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "quote.h"
 #include "strvec.h"
 
diff --git a/fetch-pack.c b/fetch-pack.c
index 4ddabb4ec76..359dce6afed 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "refs.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 19d772f0f3a..866828e2992 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "fsmonitor.h"
+#include "gettext.h"
 #include "simple-ipc.h"
 #include "fsmonitor-ipc.h"
 #include "run-command.h"
diff --git a/git.c b/git.c
index ae2134f29a8..22ce4f14b65 100644
--- a/git.c
+++ b/git.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "help.h"
 #include "run-command.h"
 #include "alias.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index 855970bb939..632265691e5 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "config.h"
+#include "gettext.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "dir.h"
diff --git a/grep.c b/grep.c
index 68e9328dfd4..febb076a7e6 100644
--- a/grep.c
+++ b/grep.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "grep.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/http-fetch.c b/http-fetch.c
index 8db35b9767d..454933351b2 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "hex.h"
 #include "http.h"
 #include "walker.h"
diff --git a/imap-send.c b/imap-send.c
index 93e9018439c..c65a27219c6 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "credential.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
 #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index ef03b45132e..65c6119e9d3 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -1,6 +1,7 @@
 #ifndef LIST_OBJECTS_FILTER_OPTIONS_H
 #define LIST_OBJECTS_FILTER_OPTIONS_H
 
+#include "gettext.h"
 #include "object.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 5d7b3316608..298ca08711e 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "commit.h"
diff --git a/list-objects.c b/list-objects.c
index ab5745bbfe4..3906ac442dd 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tag.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/lockfile.c b/lockfile.c
index cc9a4b84283..ab6490a391d 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "gettext.h"
 #include "lockfile.h"
 
 /*
diff --git a/ls-refs.c b/ls-refs.c
index 8091b0cca8c..ae38889bf04 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index 748924a69ba..c00dfbab1cd 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 
diff --git a/merge-ort.c b/merge-ort.c
index 4c5be8ed910..a26cad5f910 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -26,6 +26,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "entry.h"
 #include "ll-merge.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 89731f40908..0b0255ebc80 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -17,6 +17,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "ll-merge.h"
 #include "lockfile.h"
diff --git a/merge.c b/merge.c
index 2c8b8456842..da7fa652c27 100644
--- a/merge.c
+++ b/merge.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "commit.h"
diff --git a/midx.c b/midx.c
index 47989f7ea70..e132ef250e4 100644
--- a/midx.c
+++ b/midx.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "csum-file.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "packfile.h"
diff --git a/name-hash.c b/name-hash.c
index cd009c7c8ae..bb9eae55aca 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2008 Linus Torvalds
  */
 #include "cache.h"
+#include "gettext.h"
 #include "thread-utils.h"
 #include "trace2.h"
 #include "sparse-index.h"
diff --git a/notes-merge.c b/notes-merge.c
index 5b1a9ff13f7..c8d0020b1a2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "gettext.h"
 #include "refs.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/notes-utils.c b/notes-utils.c
index d7d18e30f5a..da08e2e8e5c 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "refs.h"
 #include "notes-utils.h"
 #include "repository.h"
diff --git a/object-file.c b/object-file.c
index 8fab8dbe80b..39660d49dbc 100644
--- a/object-file.c
+++ b/object-file.c
@@ -9,6 +9,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "string-list.h"
 #include "lockfile.h"
diff --git a/object-name.c b/object-name.c
index 69db1ec498a..2c927bbded3 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tag.h"
 #include "commit.h"
diff --git a/object.c b/object.c
index 609fed1b73d..45c9721b8c8 100644
--- a/object.c
+++ b/object.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object.h"
 #include "replace-object.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 891d9d2772e..7dc7f0ba55e 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "commit.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ca7c81b5c9f..241ac9166c1 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "strbuf.h"
 #include "tag.h"
diff --git a/pack-mtimes.c b/pack-mtimes.c
index cd92fc1d86c..afed6321906 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "pack-mtimes.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index 08dc1601679..03c7e81f9da 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "pack-revindex.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/pack-write.c b/pack-write.c
index 041e573bc16..87156f89d2b 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/packfile.c b/packfile.c
index 2023df1b75b..3290fde15a1 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "list.h"
 #include "pack.h"
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 2455aa356db..38c4dc665d5 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parallel-checkout.h"
 #include "pkt-line.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index d346dbe2100..fbf4b010195 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "color.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "strvec.h"
 #include "oid-array.h"
diff --git a/parse-options.c b/parse-options.c
index 6dd4c090e03..084b4f10621 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "commit.h"
 #include "color.h"
+#include "gettext.h"
 #include "utf8.h"
 
 static int disallow_abbreviated_options;
diff --git a/parse-options.h b/parse-options.h
index 50d852f2991..d57868eff93 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -1,6 +1,8 @@
 #ifndef PARSE_OPTIONS_H
 #define PARSE_OPTIONS_H
 
+#include "gettext.h"
+
 /**
  * Refer to Documentation/technical/api-parse-options.txt for the API doc.
  */
diff --git a/path.c b/path.c
index 632a051809a..3f2702cbe49 100644
--- a/path.c
+++ b/path.c
@@ -2,6 +2,7 @@
  * Utilities for paths and pathnames
  */
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "strbuf.h"
diff --git a/pathspec.c b/pathspec.c
index ab70fcbe613..868b4d280ca 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
 #include "strvec.h"
diff --git a/pkt-line.c b/pkt-line.c
index 1ea7f8600ec..c8b90b2242e 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pkt-line.h"
+#include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
 
diff --git a/preload-index.c b/preload-index.c
index 100f7a374dc..4b45e1d6912 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -5,6 +5,7 @@
 #include "pathspec.h"
 #include "dir.h"
 #include "fsmonitor.h"
+#include "gettext.h"
 #include "config.h"
 #include "progress.h"
 #include "thread-utils.h"
diff --git a/pretty.c b/pretty.c
index 05b557d0961..9d7922dcc60 100644
--- a/pretty.c
+++ b/pretty.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 1db566982ec..a8dbb788e8f 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "promisor-remote.h"
diff --git a/prune-packed.c b/prune-packed.c
index e02f466c2ee..cff5ad569c7 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "packfile.h"
 #include "progress.h"
diff --git a/range-diff.c b/range-diff.c
index 4bd65ab7496..1bfc612e274 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "range-diff.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/reachable.c b/reachable.c
index c9dab2a66b9..b0f85046e9c 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "tag.h"
diff --git a/read-cache.c b/read-cache.c
index 1bcf6732718..63789ea5e21 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -18,6 +18,7 @@
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
+#include "gettext.h"
 #include "resolve-undo.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 7407c593191..649c94e69a6 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "gettext.h"
 #include "sequencer.h"
 #include "rebase-interactive.h"
 #include "strbuf.h"
diff --git a/ref-filter.c b/ref-filter.c
index 38141bce8db..9a830bedef0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/ref-filter.h b/ref-filter.h
index aa0eea4ecf5..cc811c2cadd 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -1,6 +1,7 @@
 #ifndef REF_FILTER_H
 #define REF_FILTER_H
 
+#include "gettext.h"
 #include "oid-array.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/reflog.c b/reflog.c
index 04630f56ec6..d1c39374318 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "object-store.h"
 #include "reflog.h"
 #include "refs.h"
diff --git a/refs.c b/refs.c
index 4e5cc73fb10..8684f4610f5 100644
--- a/refs.c
+++ b/refs.c
@@ -6,6 +6,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "hashmap.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "iterator.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 31bc5c45ee6..de3628ff3f1 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,5 +1,6 @@
 #include "../cache.h"
 #include "../config.h"
+#include "../gettext.h"
 #include "../hex.h"
 #include "../refs.h"
 #include "refs-internal.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 6f975185995..3334c07003c 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,6 +1,7 @@
 #include "../cache.h"
 #include "../alloc.h"
 #include "../config.h"
+#include "../gettext.h"
 #include "../hex.h"
 #include "../refs.h"
 #include "refs-internal.h"
diff --git a/remote-curl.c b/remote-curl.c
index ed7e3a043ac..943cd6fe6cd 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "remote.h"
 #include "connect.h"
diff --git a/remote.c b/remote.c
index 2daddb85cb7..edb1e07497c 100644
--- a/remote.c
+++ b/remote.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "remote.h"
 #include "urlmatch.h"
diff --git a/replace-object.c b/replace-object.c
index 0cf056c4fbf..9e30e0362ba 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
 #include "object-store.h"
diff --git a/rerere.c b/rerere.c
index a67abaab077..9428cbca7b2 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "string-list.h"
diff --git a/rerere.h b/rerere.h
index c32d79c3bd8..7899dc21747 100644
--- a/rerere.h
+++ b/rerere.h
@@ -1,6 +1,7 @@
 #ifndef RERERE_H
 #define RERERE_H
 
+#include "gettext.h"
 #include "string-list.h"
 
 struct pathspec;
diff --git a/reset.c b/reset.c
index 58b3829ff73..604d9325b78 100644
--- a/reset.c
+++ b/reset.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache-tree.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "refs.h"
diff --git a/revision.c b/revision.c
index e4c066e90b7..7423e23327b 100644
--- a/revision.c
+++ b/revision.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "tag.h"
diff --git a/run-command.c b/run-command.c
index ba617655b23..2c8b4cd9bfc 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "exec-cmd.h"
+#include "gettext.h"
 #include "sigchain.h"
 #include "strvec.h"
 #include "thread-utils.h"
diff --git a/send-pack.c b/send-pack.c
index 423a5cfe22d..f531cb48212 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/sequencer.c b/sequencer.c
index 3be23d7ca20..0df51726306 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/setup.c b/setup.c
index cefd5f63c46..8a4ccee4c2c 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
diff --git a/sideband.c b/sideband.c
index 85bddfdcd4f..4905cf9b32a 100644
--- a/sideband.c
+++ b/sideband.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "color.h"
 #include "config.h"
+#include "gettext.h"
 #include "sideband.h"
 #include "help.h"
 #include "pkt-line.h"
diff --git a/sparse-index.c b/sparse-index.c
index 63216b3e57f..fdae9011b8e 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
diff --git a/split-index.c b/split-index.c
index 95ecfa53195..c98807c655b 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
 
diff --git a/strbuf.c b/strbuf.c
index 8800830ebf8..15209777d5a 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/submodule-config.c b/submodule-config.c
index 89a7bf0a93d..38663801aa4 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/submodule.c b/submodule.c
index 0baf97cf770..8b551e53274 100644
--- a/submodule.c
+++ b/submodule.c
@@ -7,6 +7,7 @@
 #include "dir.h"
 #include "diff.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/symlinks.c b/symlinks.c
index c667baa949b..c35c8d4408d 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 
 static int threaded_check_leading_path(struct cache_def *cache, const char *name,
 				       int len, int warn_on_lstat_err);
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 615e648e555..8b7a8fce1ee 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 1e975df9041..68bbc41b330 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -15,6 +15,7 @@
 #include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
+#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 05d56267a9f..09c711038ce 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -4,6 +4,7 @@
 #include "commit.h"
 #include "commit-reach.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "ref-filter.h"
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 824e5c0a958..497d72058de 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "gettext.h"
 #include "parse-options.h"
 #include "serve.h"
 
diff --git a/trailer.c b/trailer.c
index 72c3fed5c6e..9eb1b761190 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "gettext.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
diff --git a/transport-helper.c b/transport-helper.c
index 82ac63e2609..105bb801c21 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -4,6 +4,7 @@
 #include "run-command.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "remote.h"
diff --git a/tree-walk.c b/tree-walk.c
index 0e2f5ceb71d..38b6556478d 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "alloc.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
 #include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index a75fb9f05b4..84e0d2e8afe 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
+#include "gettext.h"
 #include "hex.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index 41b9362cf1b..eea9e6a6e8c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 #include "hex.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/usage.c b/usage.c
index 5a7c6c346c1..40a1c5a4339 100644
--- a/usage.c
+++ b/usage.c
@@ -3,8 +3,8 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "git-compat-util.h"
 #include "cache.h"
+#include "gettext.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
 {
diff --git a/walker.c b/walker.c
index c0469363789..b642fd2c3bc 100644
--- a/walker.c
+++ b/walker.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "gettext.h"
 #include "hex.h"
 #include "walker.h"
 #include "repository.h"
diff --git a/worktree.c b/worktree.c
index cbb0db2d7cc..09eb522e5a9 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "gettext.h"
 #include "repository.h"
 #include "refs.h"
 #include "strbuf.h"
diff --git a/wrapper.c b/wrapper.c
index 299d6489a6b..0d4ceba6fc5 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "gettext.h"
 
 static intmax_t count_fsync_writeout_only;
 static intmax_t count_fsync_hardware_flush;
diff --git a/wt-status.c b/wt-status.c
index 90525bd26fd..d15f2b0e7e8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -4,6 +4,7 @@
 #include "dir.h"
 #include "commit.h"
 #include "diff.h"
+#include "gettext.h"
 #include "hex.h"
 #include "revision.h"
 #include "diffcore.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 03/16] treewide: remove unnecessary inclusion of gettext.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 02/16] treewide: be explicit about dependence on gettext.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 04/16] treewide: remove unnecessary cache.h inclusion from several sources Elijah Newren via GitGitGadget
                     ` (13 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Looking at things from the opposite angle of the last patch, we had a
few files that were including gettext.h and perhaps needed it at some
point in history, but no longer require it.  Remove the include.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 progress.c                          | 1 -
 t/helper/test-parse-pathspec-file.c | 1 -
 t/helper/test-progress.c            | 1 -
 t/helper/test-run-command.c         | 1 -
 4 files changed, 4 deletions(-)

diff --git a/progress.c b/progress.c
index 9b33a2df325..44c784d75f1 100644
--- a/progress.c
+++ b/progress.c
@@ -10,7 +10,6 @@
 
 #define GIT_TEST_PROGRESS_ONLY
 #include "cache.h"
-#include "gettext.h"
 #include "progress.h"
 #include "strbuf.h"
 #include "trace.h"
diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c
index 71d2131fbad..89ecefd1cdb 100644
--- a/t/helper/test-parse-pathspec-file.c
+++ b/t/helper/test-parse-pathspec-file.c
@@ -1,7 +1,6 @@
 #include "test-tool.h"
 #include "parse-options.h"
 #include "pathspec.h"
-#include "gettext.h"
 
 int cmd__parse_pathspec_file(int argc, const char **argv)
 {
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 6cc9735b601..66acb6a06c9 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -19,7 +19,6 @@
  */
 #define GIT_TEST_PROGRESS_ONLY
 #include "test-tool.h"
-#include "gettext.h"
 #include "parse-options.h"
 #include "progress.h"
 #include "strbuf.h"
diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c
index b0d041ec5ff..c0ed8722c87 100644
--- a/t/helper/test-run-command.c
+++ b/t/helper/test-run-command.c
@@ -16,7 +16,6 @@
 #include "string-list.h"
 #include "thread-utils.h"
 #include "wildmatch.h"
-#include "gettext.h"
 
 static int number_callbacks;
 static int parallel_next(struct child_process *cp,
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 04/16] treewide: remove unnecessary cache.h inclusion from several sources
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (2 preceding siblings ...)
  2023-03-21  6:25   ` [PATCH v2 03/16] treewide: remove unnecessary inclusion of gettext.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 05/16] environment: move comment_line_char from cache.h Elijah Newren via GitGitGadget
                     ` (12 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

A number of files were apparently including cache.h solely to get
gettext.h.  By making those files explicitly include gettext.h, we can
already drop the include of cache.h in these files.  On top of that,
there were some files using cache.h that didn't need to for any reason.
Remove these unnecessary includes.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 compat/linux/procinfo.c        | 2 +-
 compat/simple-ipc/ipc-shared.c | 2 +-
 connected.c                    | 2 +-
 grep.c                         | 2 +-
 negotiator/default.c           | 2 +-
 negotiator/skipping.c          | 2 +-
 notes-cache.c                  | 2 +-
 patch-ids.c                    | 2 +-
 reflog.c                       | 2 +-
 refs/iterator.c                | 2 +-
 replace-object.c               | 2 +-
 t/helper/test-hash.c           | 1 -
 xdiff-interface.c              | 2 +-
 13 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/compat/linux/procinfo.c b/compat/linux/procinfo.c
index bc2f9382a17..4bb2d66227b 100644
--- a/compat/linux/procinfo.c
+++ b/compat/linux/procinfo.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 
 #include "strbuf.h"
 #include "strvec.h"
diff --git a/compat/simple-ipc/ipc-shared.c b/compat/simple-ipc/ipc-shared.c
index 1b9d359ab68..e5e1dda8ccd 100644
--- a/compat/simple-ipc/ipc-shared.c
+++ b/compat/simple-ipc/ipc-shared.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
diff --git a/connected.c b/connected.c
index a4c0aece757..669bc4e8d69 100644
--- a/connected.c
+++ b/connected.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/grep.c b/grep.c
index febb076a7e6..bb8796a829f 100644
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "gettext.h"
 #include "grep.h"
diff --git a/negotiator/default.c b/negotiator/default.c
index b7e79feaf04..5dd553a1fe3 100644
--- a/negotiator/default.c
+++ b/negotiator/default.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "default.h"
 #include "../commit.h"
 #include "../fetch-negotiator.h"
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index 264acf8bbea..4157c4d72f5 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "skipping.h"
 #include "../commit.h"
 #include "../fetch-negotiator.h"
diff --git a/notes-cache.c b/notes-cache.c
index 9dfd251a815..01a918c925e 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "notes-cache.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/patch-ids.c b/patch-ids.c
index a4473a88fa2..19af7bee984 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "commit.h"
 #include "hash-lookup.h"
diff --git a/reflog.c b/reflog.c
index d1c39374318..4e121e449d1 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "reflog.h"
diff --git a/refs/iterator.c b/refs/iterator.c
index c9fd0bcaf90..6b680f610ef 100644
--- a/refs/iterator.c
+++ b/refs/iterator.c
@@ -3,7 +3,7 @@
  * documentation about the design and use of reference iterators.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "refs.h"
 #include "refs/refs-internal.h"
 #include "iterator.h"
diff --git a/replace-object.c b/replace-object.c
index 9e30e0362ba..e98825d5852 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
index 016248106a7..45d829c908f 100644
--- a/t/helper/test-hash.c
+++ b/t/helper/test-hash.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 
 int cmd_hash_impl(int ac, const char **av, int algo)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 5baf6ceb947..356356afe71 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "hex.h"
 #include "object-store.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 05/16] environment: move comment_line_char from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (3 preceding siblings ...)
  2023-03-21  6:25   ` [PATCH v2 04/16] treewide: remove unnecessary cache.h inclusion from several sources Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 06/16] abspath.h: move absolute path functions " Elijah Newren via GitGitGadget
                     ` (11 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This is one step towards making strbuf.c not depend upon cache.h.
Additional steps will follow in subsequent commits.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-patch.c      | 1 +
 builtin/branch.c | 1 +
 builtin/commit.c | 1 +
 builtin/merge.c  | 1 +
 builtin/tag.c    | 1 +
 cache.h          | 7 -------
 commit.c         | 1 +
 environment.h    | 7 +++++++
 fmt-merge-msg.c  | 1 +
 sequencer.c      | 1 +
 strbuf.c         | 1 +
 trailer.c        | 1 +
 wt-status.c      | 1 +
 13 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/add-patch.c b/add-patch.c
index 4c803a5f4db..e59830291a6 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "add-interactive.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "strbuf.h"
 #include "run-command.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index a67a8334d5c..56dbee97d20 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "color.h"
+#include "environment.h"
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 25575435ad7..42bf20f589c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -12,6 +12,7 @@
 #include "cache-tree.h"
 #include "color.h"
 #include "dir.h"
+#include "environment.h"
 #include "builtin.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index a90ae5d2ddc..2c9da4b23d1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index c2ea89c4754..0611b3bd600 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/cache.h b/cache.h
index 5a736a2b7e7..e122de6f930 100644
--- a/cache.h
+++ b/cache.h
@@ -959,13 +959,6 @@ extern int sparse_expect_files_outside_of_patterns;
  */
 int use_optional_locks(void);
 
-/*
- * The character that begins a commented line in user-editable file
- * that is subject to stripspace.
- */
-extern char comment_line_char;
-extern int auto_comment_line_char;
-
 enum log_refs_config {
 	LOG_REFS_UNSET = -1,
 	LOG_REFS_NONE = 0,
diff --git a/commit.c b/commit.c
index 3fdfb325117..f88fc5e1a2c 100644
--- a/commit.c
+++ b/commit.c
@@ -2,6 +2,7 @@
 #include "tag.h"
 #include "commit.h"
 #include "commit-graph.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/environment.h b/environment.h
index d438b5c8f3a..a26931556af 100644
--- a/environment.h
+++ b/environment.h
@@ -3,6 +3,13 @@
 
 #include "strvec.h"
 
+/*
+ * The character that begins a commented line in user-editable file
+ * that is subject to stripspace.
+ */
+extern char comment_line_char;
+extern int auto_comment_line_char;
+
 /*
  * Wrapper of getenv() that returns a strdup value. This value is kept
  * in argv to be freed later.
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index c870cb95b9d..bc4e61c5b1a 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "refs.h"
 #include "object-store.h"
 #include "diff.h"
diff --git a/sequencer.c b/sequencer.c
index 0df51726306..7fa776b0615 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/strbuf.c b/strbuf.c
index 15209777d5a..b9cd593b147 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/trailer.c b/trailer.c
index 9eb1b761190..6a5091a3c46 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/wt-status.c b/wt-status.c
index d15f2b0e7e8..106e46480a1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -4,6 +4,7 @@
 #include "dir.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 06/16] abspath.h: move absolute path functions from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (4 preceding siblings ...)
  2023-03-21  6:25   ` [PATCH v2 05/16] environment: move comment_line_char from cache.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:25   ` [PATCH v2 07/16] cache.h: remove expand_user_path() Elijah Newren via GitGitGadget
                     ` (10 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This is another step towards letting us remove the include of cache.h in
strbuf.c.  It does mean that we also need to add includes of abspath.h
in a number of C files.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 abspath.c                          |  4 +++-
 abspath.h                          | 33 ++++++++++++++++++++++++++++++
 apply.c                            |  1 +
 archive.c                          |  1 +
 builtin/am.c                       |  1 +
 builtin/bugreport.c                |  1 +
 builtin/bundle.c                   |  1 +
 builtin/clean.c                    |  1 +
 builtin/clone.c                    |  1 +
 builtin/config.c                   |  1 +
 builtin/credential-cache--daemon.c |  1 +
 builtin/diagnose.c                 |  1 +
 builtin/difftool.c                 |  1 +
 builtin/fast-import.c              |  1 +
 builtin/fsmonitor--daemon.c        |  1 +
 builtin/gc.c                       |  1 +
 builtin/hash-object.c              |  1 +
 builtin/init-db.c                  |  1 +
 builtin/log.c                      |  1 +
 builtin/mailinfo.c                 |  1 +
 builtin/merge-file.c               |  1 +
 builtin/merge.c                    |  1 +
 builtin/multi-pack-index.c         |  1 +
 builtin/mv.c                       |  1 +
 builtin/rebase.c                   |  1 +
 builtin/receive-pack.c             |  1 +
 builtin/rev-parse.c                |  1 +
 builtin/stash.c                    |  1 +
 builtin/submodule--helper.c        |  1 +
 builtin/worktree.c                 |  1 +
 cache.h                            | 27 ------------------------
 chdir-notify.c                     |  1 +
 compat/disk.h                      |  1 +
 compat/mingw.c                     |  1 +
 compat/simple-ipc/ipc-win32.c      |  1 +
 config.c                           |  1 +
 credential.c                       |  1 +
 daemon.c                           |  1 +
 diff-no-index.c                    |  1 +
 diff.c                             |  1 +
 dir.c                              |  1 +
 editor.c                           |  1 +
 environment.c                      |  1 +
 exec-cmd.c                         |  1 +
 gettext.c                          |  1 +
 lockfile.c                         |  1 +
 midx.c                             |  1 +
 object-file.c                      |  1 +
 parse-options.c                    |  1 +
 path.c                             |  1 +
 pathspec.c                         |  1 +
 remote.c                           |  1 +
 repository.c                       |  1 +
 rerere.c                           |  1 +
 scalar.c                           |  1 +
 sequencer.c                        |  1 +
 setup.c                            |  1 +
 strbuf.c                           |  1 +
 submodule.c                        |  1 +
 t/helper/test-path-utils.c         |  1 +
 tmp-objdir.c                       |  1 +
 trace.c                            |  1 +
 trace2/tr2_dst.c                   |  1 +
 worktree.c                         |  1 +
 wrapper.c                          |  1 +
 65 files changed, 98 insertions(+), 28 deletions(-)
 create mode 100644 abspath.h

diff --git a/abspath.c b/abspath.c
index 9a81c5525be..d032f5dce51 100644
--- a/abspath.c
+++ b/abspath.c
@@ -1,4 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "abspath.h"
+#include "strbuf.h"
 
 /*
  * Do not use this for inspecting *tracked* content.  When path is a
diff --git a/abspath.h b/abspath.h
new file mode 100644
index 00000000000..7cd3de5e9de
--- /dev/null
+++ b/abspath.h
@@ -0,0 +1,33 @@
+#ifndef ABSPATH_H
+#define ABSPATH_H
+
+int is_directory(const char *);
+char *strbuf_realpath(struct strbuf *resolved, const char *path,
+		      int die_on_error);
+char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path,
+				int die_on_error);
+char *real_pathdup(const char *path, int die_on_error);
+const char *absolute_path(const char *path);
+char *absolute_pathdup(const char *path);
+
+/*
+ * Concatenate "prefix" (if len is non-zero) and "path", with no
+ * connecting characters (so "prefix" should end with a "/").
+ * Unlike prefix_path, this should be used if the named file does
+ * not have to interact with index entry; i.e. name of a random file
+ * on the filesystem.
+ *
+ * The return value is always a newly allocated string (even if the
+ * prefix was empty).
+ */
+char *prefix_filename(const char *prefix, const char *path);
+
+/* Likewise, but path=="-" always yields "-" */
+char *prefix_filename_except_for_dash(const char *prefix, const char *path);
+
+static inline int is_absolute_path(const char *path)
+{
+	return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
+}
+
+#endif /* ABSPATH_H */
diff --git a/apply.c b/apply.c
index e0bdd43a68e..e5e11b85793 100644
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "object-store.h"
diff --git a/archive.c b/archive.c
index 2c3da1cff30..c3c45a5ebe9 100644
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/am.c b/builtin/am.c
index cc1fdf4f75d..14347ecf9aa 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -5,6 +5,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "builtin.h"
 #include "exec-cmd.h"
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index b61cfa9464f..b5dfad4e12a 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "strbuf.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index de3898ffa41..9e2aecadf7d 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "strvec.h"
 #include "parse-options.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 46c51029ab4..fdcf62c5dfe 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index d605fcafa0f..b94324ea02c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -10,6 +10,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/config.c b/builtin/config.c
index 33b17b40b41..42e6b8d3481 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "color.h"
diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index 0f00ba4d741..62c09a271d6 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/diagnose.c b/builtin/diagnose.c
index 5b12d1fb963..0f8b64994c4 100644
--- a/builtin/diagnose.c
+++ b/builtin/diagnose.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "diagnose.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index f7380dd1cc7..ed06db12085 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -13,6 +13,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "builtin.h"
 #include "run-command.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index f3635c7aefd..7307c4657f2 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 215e3813d7d..4efb1417344 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 32cabad7cf6..ef063fc828c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "abspath.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index f233eda7590..7651a7a5f56 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -5,6 +5,7 @@
  * Copyright (C) Junio C Hamano, 2005
  */
 #include "builtin.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index e182bc7e839..6f724f694f4 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "refs.h"
diff --git a/builtin/log.c b/builtin/log.c
index e702cf126e5..b7333b34cce 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
  *		 2006 Junio Hamano
  */
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index e8bb011cfb4..e14f7c0abce 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -3,6 +3,7 @@
  * email to figure out authorship and subject
  */
 #include "cache.h"
+#include "abspath.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "utf8.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index ae45f523b95..c0096ee0810 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 2c9da4b23d1..38243e55c5f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -8,6 +8,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index e6757a44470..579bc2cac0c 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index c02dddb72b5..0a49bf21b0f 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -5,6 +5,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index a2c68b8ff7b..a3f8be88882 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -6,6 +6,7 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 006565f8513..aec5ee930b2 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "repository.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 5a932a861b4..a4c0878bc91 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -5,6 +5,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 65817d0b763..52fa892f7eb 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1,5 +1,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a4bdd44daa3..ff1fd8c87ab 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index ed89b7e9725..ed614ffddcb 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "checkout.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/cache.h b/cache.h
index e122de6f930..260203c7a62 100644
--- a/cache.h
+++ b/cache.h
@@ -598,21 +598,6 @@ const char *setup_git_directory(void);
 char *prefix_path(const char *prefix, int len, const char *path);
 char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
 
-/*
- * Concatenate "prefix" (if len is non-zero) and "path", with no
- * connecting characters (so "prefix" should end with a "/").
- * Unlike prefix_path, this should be used if the named file does
- * not have to interact with index entry; i.e. name of a random file
- * on the filesystem.
- *
- * The return value is always a newly allocated string (even if the
- * prefix was empty).
- */
-char *prefix_filename(const char *prefix, const char *path);
-
-/* Likewise, but path=="-" always yields "-" */
-char *prefix_filename_except_for_dash(const char *prefix, const char *path);
-
 int check_filename(const char *prefix, const char *name);
 void verify_filename(const char *prefix,
 		     const char *name,
@@ -1160,18 +1145,6 @@ char *interpolate_path(const char *path, int real_home);
 /* NEEDSWORK: remove this synonym once in-flight topics have migrated */
 #define expand_user_path interpolate_path
 const char *enter_repo(const char *path, int strict);
-static inline int is_absolute_path(const char *path)
-{
-	return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
-}
-int is_directory(const char *);
-char *strbuf_realpath(struct strbuf *resolved, const char *path,
-		      int die_on_error);
-char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path,
-				int die_on_error);
-char *real_pathdup(const char *path, int die_on_error);
-const char *absolute_path(const char *path);
-char *absolute_pathdup(const char *path);
 const char *remove_leading_path(const char *in, const char *prefix);
 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
diff --git a/chdir-notify.c b/chdir-notify.c
index 5f7f2c2ac23..929ec01b3a2 100644
--- a/chdir-notify.c
+++ b/chdir-notify.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "chdir-notify.h"
 #include "list.h"
 #include "strbuf.h"
diff --git a/compat/disk.h b/compat/disk.h
index a04a8d294af..6c979c27d89 100644
--- a/compat/disk.h
+++ b/compat/disk.h
@@ -2,6 +2,7 @@
 #define COMPAT_DISK_H
 
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "gettext.h"
 
 static int get_disk_info(struct strbuf *out)
diff --git a/compat/mingw.c b/compat/mingw.c
index a9e5570288c..cbcd03aea9b 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -7,6 +7,7 @@
 #include "../strbuf.h"
 #include "../run-command.h"
 #include "../cache.h"
+#include "../abspath.h"
 #include "../alloc.h"
 #include "win32/lazyload.h"
 #include "../config.h"
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index f011e5cead8..997f6144344 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
diff --git a/config.c b/config.c
index f30a6d8e686..6815919ec30 100644
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "date.h"
 #include "branch.h"
diff --git a/credential.c b/credential.c
index 5244f3c12c0..e6417bf8804 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "credential.h"
 #include "gettext.h"
diff --git a/daemon.c b/daemon.c
index 8908e7f8d2a..bb795ca3ca9 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "pkt-line.h"
diff --git a/diff-no-index.c b/diff-no-index.c
index 287a113badd..934a24bee58 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "color.h"
 #include "commit.h"
 #include "blob.h"
diff --git a/diff.c b/diff.c
index 00746f2f86e..1b0be99c065 100644
--- a/diff.c
+++ b/diff.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2005 Junio C Hamano
  */
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/dir.c b/dir.c
index 46f1bb6e5b7..c72481c60ee 100644
--- a/dir.c
+++ b/dir.c
@@ -6,6 +6,7 @@
  *		 Junio Hamano, 2005-2006
  */
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
diff --git a/editor.c b/editor.c
index 58e790548d2..2d3e6be64e4 100644
--- a/editor.c
+++ b/editor.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/environment.c b/environment.c
index 82a1fc17d0b..c69571f0b29 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "abspath.h"
 #include "branch.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/exec-cmd.c b/exec-cmd.c
index 282d95af081..042d9247a5b 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "quote.h"
diff --git a/gettext.c b/gettext.c
index f139008d0a3..3e7b3baabc6 100644
--- a/gettext.c
+++ b/gettext.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/lockfile.c b/lockfile.c
index ab6490a391d..673c21d17a9 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "lockfile.h"
 
diff --git a/midx.c b/midx.c
index e132ef250e4..b111665dcab 100644
--- a/midx.c
+++ b/midx.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "csum-file.h"
diff --git a/object-file.c b/object-file.c
index 39660d49dbc..bee41b30474 100644
--- a/object-file.c
+++ b/object-file.c
@@ -7,6 +7,7 @@
  * creation etc.
  */
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/parse-options.c b/parse-options.c
index 084b4f10621..a577cc85f67 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
+#include "abspath.h"
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
diff --git a/path.c b/path.c
index 3f2702cbe49..3976c0d7ace 100644
--- a/path.c
+++ b/path.c
@@ -2,6 +2,7 @@
  * Utilities for paths and pathnames
  */
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/pathspec.c b/pathspec.c
index 868b4d280ca..53763e272f5 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/remote.c b/remote.c
index edb1e07497c..2bae247a0a4 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/repository.c b/repository.c
index 937fa974b38..4412f633224 100644
--- a/repository.c
+++ b/repository.c
@@ -4,6 +4,7 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "abspath.h"
 #include "repository.h"
 #include "object-store.h"
 #include "config.h"
diff --git a/rerere.c b/rerere.c
index 9428cbca7b2..c3258e13902 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/scalar.c b/scalar.c
index ca19b95ce46..fe61a3ebdd7 100644
--- a/scalar.c
+++ b/scalar.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "config.h"
diff --git a/sequencer.c b/sequencer.c
index 7fa776b0615..c61c1fc4d87 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/setup.c b/setup.c
index 8a4ccee4c2c..8f385d9f29b 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "gettext.h"
 #include "repository.h"
 #include "config.h"
diff --git a/strbuf.c b/strbuf.c
index b9cd593b147..9633e37b62f 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/submodule.c b/submodule.c
index 8b551e53274..13ff333f68c 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index f69709d674f..d3d00dc34fa 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "abspath.h"
 #include "string-list.h"
 #include "utf8.h"
 
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 2a2012eb6d0..fff15cb6b5c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tmp-objdir.h"
+#include "abspath.h"
 #include "chdir-notify.h"
 #include "dir.h"
 #include "sigchain.h"
diff --git a/trace.c b/trace.c
index efa4e2d8e08..2b41c683fc8 100644
--- a/trace.c
+++ b/trace.c
@@ -22,6 +22,7 @@
  */
 
 #include "cache.h"
+#include "abspath.h"
 #include "quote.h"
 
 struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index 8a21dd29725..273260e1f18 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "sigchain.h"
 #include "trace2/tr2_dst.h"
 #include "trace2/tr2_sid.h"
diff --git a/worktree.c b/worktree.c
index 09eb522e5a9..b7bc4c7bb7a 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "abspath.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "repository.h"
diff --git a/wrapper.c b/wrapper.c
index 0d4ceba6fc5..df1fa6286d0 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "abspath.h"
 #include "config.h"
 #include "gettext.h"
 
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 07/16] cache.h: remove expand_user_path()
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (5 preceding siblings ...)
  2023-03-21  6:25   ` [PATCH v2 06/16] abspath.h: move absolute path functions " Elijah Newren via GitGitGadget
@ 2023-03-21  6:25   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 08/16] path.h: move function declarations for path.c functions from cache.h Elijah Newren via GitGitGadget
                     ` (9 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:25 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

expand_user_path() was renamed to interpolate_path() back in mid-2021,
but reinstated with a #define and a NEEDSWORK comment that we would
eventually want to get rid of it.  Do so now.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h         | 2 --
 gpg-interface.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 260203c7a62..978aa01712b 100644
--- a/cache.h
+++ b/cache.h
@@ -1142,8 +1142,6 @@ enum scld_error safe_create_leading_directories_no_share(char *path);
 
 int mkdir_in_gitdir(const char *path);
 char *interpolate_path(const char *path, int real_home);
-/* NEEDSWORK: remove this synonym once in-flight topics have migrated */
-#define expand_user_path interpolate_path
 const char *enter_repo(const char *path, int strict);
 const char *remove_leading_path(const char *in, const char *prefix);
 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
diff --git a/gpg-interface.c b/gpg-interface.c
index 632265691e5..f9c5b6c3f53 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1049,7 +1049,7 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
 		ssh_signing_key_file = strbuf_detach(&key_file->filename, NULL);
 	} else {
 		/* We assume a file */
-		ssh_signing_key_file = expand_user_path(signing_key, 1);
+		ssh_signing_key_file = interpolate_path(signing_key, 1);
 	}
 
 	buffer_file = mks_tempfile_t(".git_signing_buffer_tmpXXXXXX");
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 08/16] path.h: move function declarations for path.c functions from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (6 preceding siblings ...)
  2023-03-21  6:25   ` [PATCH v2 07/16] cache.h: remove expand_user_path() Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 09/16] wrapper.h: move declarations for wrapper.c " Elijah Newren via GitGitGadget
                     ` (8 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h | 59 ------------------------------------------------------
 path.h  | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 60 deletions(-)

diff --git a/cache.h b/cache.h
index 978aa01712b..705c41992bc 100644
--- a/cache.h
+++ b/cache.h
@@ -1105,7 +1105,6 @@ enum sharedrepo {
 	PERM_EVERYBODY      = 0664
 };
 int git_config_perm(const char *var, const char *value);
-int adjust_shared_perm(const char *path);
 
 /*
  * Create the directory containing the named path, using care to be
@@ -1141,54 +1140,6 @@ enum scld_error safe_create_leading_directories_const(const char *path);
 enum scld_error safe_create_leading_directories_no_share(char *path);
 
 int mkdir_in_gitdir(const char *path);
-char *interpolate_path(const char *path, int real_home);
-const char *enter_repo(const char *path, int strict);
-const char *remove_leading_path(const char *in, const char *prefix);
-const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
-int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
-int normalize_path_copy(char *dst, const char *src);
-int longest_ancestor_length(const char *path, struct string_list *prefixes);
-char *strip_path_suffix(const char *path, const char *suffix);
-int daemon_avoid_alias(const char *path);
-
-/*
- * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
- * details.
- */
-int is_ntfs_dotgit(const char *name);
-int is_ntfs_dotgitmodules(const char *name);
-int is_ntfs_dotgitignore(const char *name);
-int is_ntfs_dotgitattributes(const char *name);
-int is_ntfs_dotmailmap(const char *name);
-
-/*
- * Returns true iff "str" could be confused as a command-line option when
- * passed to a sub-program like "ssh". Note that this has nothing to do with
- * shell-quoting, which should be handled separately; we're assuming here that
- * the string makes it verbatim to the sub-program.
- */
-int looks_like_command_line_option(const char *str);
-
-/**
- * Return a newly allocated string with the evaluation of
- * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
- * "$HOME/.config/$subdir/$filename". Return NULL upon error.
- */
-char *xdg_config_home_for(const char *subdir, const char *filename);
-
-/**
- * Return a newly allocated string with the evaluation of
- * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
- * "$HOME/.config/git/$filename". Return NULL upon error.
- */
-char *xdg_config_home(const char *filename);
-
-/**
- * Return a newly allocated string with the evaluation of
- * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
- * "$HOME/.cache/git/$filename". Return NULL upon error.
- */
-char *xdg_cache_home(const char *filename);
 
 int git_open_cloexec(const char *name, int flags);
 #define git_open(name) git_open_cloexec(name, O_RDONLY)
@@ -1355,8 +1306,6 @@ int repo_interpret_branch_name(struct repository *r,
 #define interpret_branch_name(str, len, buf, options) \
 	repo_interpret_branch_name(the_repository, str, len, buf, options)
 
-int validate_headref(const char *ref);
-
 int base_name_compare(const char *name1, size_t len1, int mode1,
 		      const char *name2, size_t len2, int mode2);
 int df_name_compare(const char *name1, size_t len1, int mode1,
@@ -1616,14 +1565,6 @@ void stat_validity_update(struct stat_validity *sv, int fd);
 
 int versioncmp(const char *s1, const char *s2);
 
-/*
- * Create a directory and (if share is nonzero) adjust its permissions
- * according to the shared_repository setting. Only use this for
- * directories under $GIT_DIR.  Don't use it for working tree
- * directories.
- */
-void safe_create_dir(const char *dir, int share);
-
 /*
  * Should we print an ellipsis after an abbreviated SHA-1 value
  * when doing diff-raw output or indicating a detached HEAD?
diff --git a/path.h b/path.h
index 0a59c85a62e..60e83a49a98 100644
--- a/path.h
+++ b/path.h
@@ -3,6 +3,7 @@
 
 struct repository;
 struct strbuf;
+struct string_list;
 
 /*
  * The result to all functions which return statically allocated memory may be
@@ -179,7 +180,66 @@ const char *git_path_auto_merge(struct repository *r);
 const char *git_path_fetch_head(struct repository *r);
 const char *git_path_shallow(struct repository *r);
 
-
 int ends_with_path_components(const char *path, const char *components);
+int validate_headref(const char *ref);
+
+int adjust_shared_perm(const char *path);
+
+char *interpolate_path(const char *path, int real_home);
+const char *enter_repo(const char *path, int strict);
+const char *remove_leading_path(const char *in, const char *prefix);
+const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
+int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
+int normalize_path_copy(char *dst, const char *src);
+int longest_ancestor_length(const char *path, struct string_list *prefixes);
+char *strip_path_suffix(const char *path, const char *suffix);
+int daemon_avoid_alias(const char *path);
+
+/*
+ * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
+ * details.
+ */
+int is_ntfs_dotgit(const char *name);
+int is_ntfs_dotgitmodules(const char *name);
+int is_ntfs_dotgitignore(const char *name);
+int is_ntfs_dotgitattributes(const char *name);
+int is_ntfs_dotmailmap(const char *name);
+
+/*
+ * Returns true iff "str" could be confused as a command-line option when
+ * passed to a sub-program like "ssh". Note that this has nothing to do with
+ * shell-quoting, which should be handled separately; we're assuming here that
+ * the string makes it verbatim to the sub-program.
+ */
+int looks_like_command_line_option(const char *str);
+
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
+ * "$HOME/.config/$subdir/$filename". Return NULL upon error.
+ */
+char *xdg_config_home_for(const char *subdir, const char *filename);
+
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
+ * "$HOME/.config/git/$filename". Return NULL upon error.
+ */
+char *xdg_config_home(const char *filename);
+
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
+ * "$HOME/.cache/git/$filename". Return NULL upon error.
+ */
+char *xdg_cache_home(const char *filename);
+
+/*
+ * Create a directory and (if share is nonzero) adjust its permissions
+ * according to the shared_repository setting. Only use this for
+ * directories under $GIT_DIR.  Don't use it for working tree
+ * directories.
+ */
+void safe_create_dir(const char *dir, int share);
 
 #endif /* PATH_H */
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 09/16] wrapper.h: move declarations for wrapper.c functions from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (7 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 08/16] path.h: move function declarations for path.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 10/16] treewide: remove unnecessary includes of cache.h Elijah Newren via GitGitGadget
                     ` (7 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                          |  1 +
 builtin/am.c                     |  1 +
 builtin/bisect.c                 |  1 +
 builtin/branch.c                 |  1 +
 builtin/bugreport.c              |  2 +-
 builtin/config.c                 |  1 +
 builtin/credential-cache.c       |  1 +
 builtin/difftool.c               |  1 +
 builtin/fast-import.c            |  1 +
 builtin/fmt-merge-msg.c          |  1 +
 builtin/gc.c                     |  1 +
 builtin/get-tar-commit-id.c      |  1 +
 builtin/index-pack.c             |  1 +
 builtin/init-db.c                |  1 +
 builtin/merge.c                  |  1 +
 builtin/pack-objects.c           |  1 +
 builtin/rebase.c                 |  1 +
 builtin/receive-pack.c           |  1 +
 builtin/rerere.c                 |  1 +
 builtin/unpack-file.c            |  1 +
 builtin/worktree.c               |  1 +
 cache.h                          | 32 ----------------------------
 commit-graph.c                   |  1 +
 compat/mingw.c                   |  1 +
 compat/terminal.c                |  1 +
 config.c                         |  1 +
 convert.c                        |  1 +
 copy.c                           |  1 +
 csum-file.c                      |  1 +
 daemon.c                         |  1 +
 diff.c                           |  1 +
 dir.c                            |  1 +
 entry.c                          |  1 +
 environment.c                    |  1 +
 fetch-pack.c                     |  1 +
 gpg-interface.c                  |  1 +
 http-backend.c                   |  1 +
 imap-send.c                      |  1 +
 ll-merge.c                       |  1 +
 merge-recursive.c                |  1 +
 notes-merge.c                    |  1 +
 object-file.c                    |  1 +
 packfile.c                       |  1 +
 parallel-checkout.c              |  1 +
 pkt-line.c                       |  1 +
 read-cache.c                     |  1 +
 rebase-interactive.c             |  1 +
 refs.c                           |  1 +
 refs/files-backend.c             |  3 ++-
 rerere.c                         |  1 +
 sequencer.c                      |  1 +
 server-info.c                    |  1 +
 shallow.c                        |  1 +
 strbuf.c                         |  1 +
 streaming.c                      |  1 +
 t/helper/test-delta.c            |  1 +
 t/helper/test-fsmonitor-client.c |  1 +
 t/helper/test-read-cache.c       |  1 +
 tag.c                            |  1 +
 tempfile.c                       |  1 +
 trace.c                          |  1 +
 transport-helper.c               |  1 +
 transport.c                      |  1 +
 usage.c                          |  1 +
 worktree.c                       |  1 +
 wrapper.c                        |  1 +
 wrapper.h                        | 36 ++++++++++++++++++++++++++++++++
 write-or-die.c                   |  1 +
 68 files changed, 103 insertions(+), 34 deletions(-)
 create mode 100644 wrapper.h

diff --git a/apply.c b/apply.c
index e5e11b85793..373565a7baf 100644
--- a/apply.c
+++ b/apply.c
@@ -26,6 +26,7 @@
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
+#include "wrapper.h"
 
 struct gitdiff_data {
 	struct strbuf *root;
diff --git a/builtin/am.c b/builtin/am.c
index 14347ecf9aa..37f82b3eb42 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -38,6 +38,7 @@
 #include "packfile.h"
 #include "repository.h"
 #include "pretty.h"
+#include "wrapper.h"
 
 /**
  * Returns the length of the first line of msg.
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 09188e554b3..31cc57e45ba 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -11,6 +11,7 @@
 #include "prompt.h"
 #include "quote.h"
 #include "revision.h"
+#include "wrapper.h"
 
 static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
 static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
diff --git a/builtin/branch.c b/builtin/branch.c
index 56dbee97d20..98475ea5325 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -26,6 +26,7 @@
 #include "worktree.h"
 #include "help.h"
 #include "commit-reach.h"
+#include "wrapper.h"
 
 static const char * const builtin_branch_usage[] = {
 	N_("git branch [<options>] [-r | -a] [--merged] [--no-merged]"),
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index b5dfad4e12a..160590e4ef6 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -8,7 +8,7 @@
 #include "hook.h"
 #include "hook-list.h"
 #include "diagnose.h"
-
+#include "wrapper.h"
 
 static void get_system_info(struct strbuf *sys_info)
 {
diff --git a/builtin/config.c b/builtin/config.c
index 42e6b8d3481..1c1e006ff3f 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -9,6 +9,7 @@
 #include "urlmatch.h"
 #include "quote.h"
 #include "worktree.h"
+#include "wrapper.h"
 
 static const char *const builtin_config_usage[] = {
 	N_("git config [<options>]"),
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 25f2f71c216..af56a44923d 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "wrapper.h"
 
 #ifndef NO_UNIX_SOCKETS
 
diff --git a/builtin/difftool.c b/builtin/difftool.c
index ed06db12085..59465c39f1d 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -27,6 +27,7 @@
 #include "object-store.h"
 #include "dir.h"
 #include "entry.h"
+#include "wrapper.h"
 
 static int trust_exit_code;
 
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 7307c4657f2..3300b7f30f0 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -23,6 +23,7 @@
 #include "commit-reach.h"
 #include "khash.h"
 #include "date.h"
+#include "wrapper.h"
 
 #define PACK_ID_BITS 16
 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 0f9855b680e..cc812416420 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -3,6 +3,7 @@
 #include "fmt-merge-msg.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "wrapper.h"
 
 static const char * const fmt_merge_msg_usage[] = {
 	N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
diff --git a/builtin/gc.c b/builtin/gc.c
index ef063fc828c..2107e3d1f2c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -35,6 +35,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hook.h"
+#include "wrapper.h"
 
 #define FAILED_RUN "failed to run %s"
 
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 491af9202dc..67457969986 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -6,6 +6,7 @@
 #include "tar.h"
 #include "builtin.h"
 #include "quote.h"
+#include "wrapper.h"
 
 static const char builtin_get_tar_commit_id_usage[] =
 "git get-tar-commit-id";
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bae5b054039..2393897cb88 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -19,6 +19,7 @@
 #include "object-store.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
+#include "wrapper.h"
 
 static const char index_pack_usage[] =
 "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 6f724f694f4..a5d4f5c8ece 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "exec-cmd.h"
 #include "parse-options.h"
 #include "worktree.h"
+#include "wrapper.h"
 
 #ifndef DEFAULT_GIT_TEMPLATE_DIR
 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
diff --git a/builtin/merge.c b/builtin/merge.c
index 38243e55c5f..f4f4a220f30 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -49,6 +49,7 @@
 #include "commit-reach.h"
 #include "wt-status.h"
 #include "commit-graph.h"
+#include "wrapper.h"
 
 #define DEFAULT_TWOHEAD (1<<0)
 #define DEFAULT_OCTOPUS (1<<1)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1ca800c7c50..8b55a088a7c 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -40,6 +40,7 @@
 #include "shallow.h"
 #include "promisor-remote.h"
 #include "pack-mtimes.h"
+#include "wrapper.h"
 
 /*
  * Objects we are going to pack are collected in the `to_pack` structure.
diff --git a/builtin/rebase.c b/builtin/rebase.c
index a3f8be88882..d2f8f703d67 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -32,6 +32,7 @@
 #include "rebase-interactive.h"
 #include "reset.h"
 #include "hook.h"
+#include "wrapper.h"
 
 static char const * const builtin_rebase_usage[] = {
 	N_("git rebase [-i] [options] [--exec <cmd>] "
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index aec5ee930b2..ae49ea8c2ad 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,6 +33,7 @@
 #include "commit-reach.h"
 #include "worktree.h"
 #include "shallow.h"
+#include "wrapper.h"
 
 static const char * const receive_pack_usage[] = {
 	N_("git receive-pack <git-dir>"),
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 24c78755723..d4a03707b1a 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -6,6 +6,7 @@
 #include "parse-options.h"
 #include "string-list.h"
 #include "rerere.h"
+#include "wrapper.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e9b105a5397..4cbb4039293 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "hex.h"
 #include "object-store.h"
+#include "wrapper.h"
 
 static char *create_temp_file(struct object_id *oid)
 {
diff --git a/builtin/worktree.c b/builtin/worktree.c
index ed614ffddcb..1533b4ab43c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -16,6 +16,7 @@
 #include "submodule.h"
 #include "utf8.h"
 #include "worktree.h"
+#include "wrapper.h"
 #include "quote.h"
 
 #define BUILTIN_WORKTREE_ADD_USAGE \
diff --git a/cache.h b/cache.h
index 705c41992bc..31c722533f9 100644
--- a/cache.h
+++ b/cache.h
@@ -1085,10 +1085,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id
 int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
 #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
-/* set default permissions by passing mode arguments to open(2) */
-int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
-int git_mkstemp_mode(char *pattern, int mode);
-
 /*
  * NOTE NOTE NOTE!!
  *
@@ -1423,31 +1419,6 @@ static inline int batch_fsync_enabled(enum fsync_component component)
 	return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
 }
 
-ssize_t read_in_full(int fd, void *buf, size_t count);
-ssize_t write_in_full(int fd, const void *buf, size_t count);
-ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
-
-static inline ssize_t write_str_in_full(int fd, const char *str)
-{
-	return write_in_full(fd, str, strlen(str));
-}
-
-/**
- * Open (and truncate) the file at path, write the contents of buf to it,
- * and close it. Dies if any errors are encountered.
- */
-void write_file_buf(const char *path, const char *buf, size_t len);
-
-/**
- * Like write_file_buf(), but format the contents into a buffer first.
- * Additionally, write_file() will append a newline if one is not already
- * present, making it convenient to write text files:
- *
- *   write_file(path, "counter: %d", ctr);
- */
-__attribute__((format (printf, 2, 3)))
-void write_file(const char *path, const char *fmt, ...);
-
 /* pager.c */
 void setup_pager(void);
 int pager_in_use(void);
@@ -1571,7 +1542,4 @@ int versioncmp(const char *s1, const char *s2);
  */
 int print_sha1_ellipsis(void);
 
-/* Return 1 if the file is empty or does not exists, 0 otherwise. */
-int is_empty_or_missing_file(const char *filename);
-
 #endif /* CACHE_H */
diff --git a/commit-graph.c b/commit-graph.c
index 8f21a0a0c20..5481736c76c 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -22,6 +22,7 @@
 #include "json-writer.h"
 #include "trace2.h"
 #include "chunk-format.h"
+#include "wrapper.h"
 
 void git_test_write_commit_graph_or_die(void)
 {
diff --git a/compat/mingw.c b/compat/mingw.c
index cbcd03aea9b..d48899bf7b4 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -11,6 +11,7 @@
 #include "../alloc.h"
 #include "win32/lazyload.h"
 #include "../config.h"
+#include "../wrapper.h"
 #include "dir.h"
 #include "gettext.h"
 #define SECURITY_WIN32
diff --git a/compat/terminal.c b/compat/terminal.c
index afebe6b2496..ed2b30b38f7 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -6,6 +6,7 @@
 #include "run-command.h"
 #include "string-list.h"
 #include "hashmap.h"
+#include "wrapper.h"
 
 #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)
 
diff --git a/config.c b/config.c
index 6815919ec30..5b1a5d52052 100644
--- a/config.c
+++ b/config.c
@@ -28,6 +28,7 @@
 #include "replace-object.h"
 #include "refs.h"
 #include "worktree.h"
+#include "wrapper.h"
 
 struct config_source {
 	struct config_source *prev;
diff --git a/convert.c b/convert.c
index 2bd54244b55..da06e2f51cb 100644
--- a/convert.c
+++ b/convert.c
@@ -11,6 +11,7 @@
 #include "sub-process.h"
 #include "utf8.h"
 #include "ll-merge.h"
+#include "wrapper.h"
 
 /*
  * convert.c - convert a file when checking it out and checking it in.
diff --git a/copy.c b/copy.c
index 4de6a110f09..c3250f08221 100644
--- a/copy.c
+++ b/copy.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "wrapper.h"
 
 int copy_fd(int ifd, int ofd)
 {
diff --git a/csum-file.c b/csum-file.c
index cce13c0f047..2d22f80d901 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "progress.h"
 #include "csum-file.h"
+#include "wrapper.h"
 
 static void verify_buffer_or_die(struct hashfile *f,
 				 const void *buf,
diff --git a/daemon.c b/daemon.c
index bb795ca3ca9..e35604e194c 100644
--- a/daemon.c
+++ b/daemon.c
@@ -6,6 +6,7 @@
 #include "run-command.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "wrapper.h"
 
 #ifdef NO_INITGROUPS
 #define initgroups(x, y) (0) /* nothing */
diff --git a/diff.c b/diff.c
index 1b0be99c065..1b0b24c21c3 100644
--- a/diff.c
+++ b/diff.c
@@ -33,6 +33,7 @@
 #include "promisor-remote.h"
 #include "dir.h"
 #include "strmap.h"
+#include "wrapper.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
diff --git a/dir.c b/dir.c
index c72481c60ee..b57c770e68b 100644
--- a/dir.c
+++ b/dir.c
@@ -21,6 +21,7 @@
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "submodule-config.h"
+#include "wrapper.h"
 
 /*
  * Tells read_directory_recursive how a file or directory should be treated.
diff --git a/entry.c b/entry.c
index acb76a61aca..70212af260b 100644
--- a/entry.c
+++ b/entry.c
@@ -10,6 +10,7 @@
 #include "fsmonitor.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "wrapper.h"
 
 static void create_directories(const char *path, int path_len,
 			       const struct checkout *state)
diff --git a/environment.c b/environment.c
index c69571f0b29..bf02f3cf487 100644
--- a/environment.c
+++ b/environment.c
@@ -23,6 +23,7 @@
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
 #include "shallow.h"
+#include "wrapper.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
diff --git a/fetch-pack.c b/fetch-pack.c
index 359dce6afed..c1190801405 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -30,6 +30,7 @@
 #include "commit-graph.h"
 #include "sigchain.h"
 #include "mergesort.h"
+#include "wrapper.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
diff --git a/gpg-interface.c b/gpg-interface.c
index f9c5b6c3f53..6644701fda0 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -10,6 +10,7 @@
 #include "sigchain.h"
 #include "tempfile.h"
 #include "alias.h"
+#include "wrapper.h"
 
 static int git_gpg_config(const char *, const char *, void *);
 
diff --git a/http-backend.c b/http-backend.c
index 7e7c19e66b3..42e6c2596e9 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -16,6 +16,7 @@
 #include "object-store.h"
 #include "protocol.h"
 #include "date.h"
+#include "wrapper.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
diff --git a/imap-send.c b/imap-send.c
index c65a27219c6..aa5b2f252d2 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -28,6 +28,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "wrapper.h"
 #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
 typedef void *SSL;
 #endif
diff --git a/ll-merge.c b/ll-merge.c
index 130d26501c6..8be38d3bd41 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -11,6 +11,7 @@
 #include "run-command.h"
 #include "ll-merge.h"
 #include "quote.h"
+#include "wrapper.h"
 
 struct ll_merge_driver;
 
diff --git a/merge-recursive.c b/merge-recursive.c
index 0b0255ebc80..f918cea4c69 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -30,6 +30,7 @@
 #include "tag.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
+#include "wrapper.h"
 #include "xdiff-interface.h"
 
 struct merge_options_internal {
diff --git a/notes-merge.c b/notes-merge.c
index c8d0020b1a2..ba2970f0702 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -15,6 +15,7 @@
 #include "strbuf.h"
 #include "notes-utils.h"
 #include "commit-reach.h"
+#include "wrapper.h"
 
 struct notes_merge_pair {
 	struct object_id obj, base, local, remote;
diff --git a/object-file.c b/object-file.c
index bee41b30474..bdf68763a50 100644
--- a/object-file.c
+++ b/object-file.c
@@ -38,6 +38,7 @@
 #include "promisor-remote.h"
 #include "submodule.h"
 #include "fsck.h"
+#include "wrapper.h"
 
 /* The maximum size for an object header. */
 #define MAX_HEADER_LEN 32
diff --git a/packfile.c b/packfile.c
index 3290fde15a1..8c117ccee27 100644
--- a/packfile.c
+++ b/packfile.c
@@ -20,6 +20,7 @@
 #include "midx.h"
 #include "commit-graph.h"
 #include "promisor-remote.h"
+#include "wrapper.h"
 
 char *odb_pack_name(struct strbuf *buf,
 		    const unsigned char *hash,
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 38c4dc665d5..50fd7fe31ef 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -12,6 +12,7 @@
 #include "streaming.h"
 #include "thread-utils.h"
 #include "trace2.h"
+#include "wrapper.h"
 
 struct pc_worker {
 	struct child_process cp;
diff --git a/pkt-line.c b/pkt-line.c
index c8b90b2242e..30469eb4d8d 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
+#include "wrapper.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
diff --git a/read-cache.c b/read-cache.c
index 63789ea5e21..9a8d5fe97ed 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -32,6 +32,7 @@
 #include "csum-file.h"
 #include "promisor-remote.h"
 #include "hook.h"
+#include "wrapper.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 649c94e69a6..7c885c35bfd 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -7,6 +7,7 @@
 #include "commit-slab.h"
 #include "config.h"
 #include "dir.h"
+#include "wrapper.h"
 
 static const char edit_todo_list_advice[] =
 N_("You can fix this with 'git rebase --edit-todo' "
diff --git a/refs.c b/refs.c
index 8684f4610f5..385051752f1 100644
--- a/refs.c
+++ b/refs.c
@@ -24,6 +24,7 @@
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
+#include "wrapper.h"
 
 /*
  * List of all available backends
diff --git a/refs/files-backend.c b/refs/files-backend.c
index de3628ff3f1..eb14d124e3f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -13,7 +13,8 @@
 #include "../object.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
-#include "worktree.h"
+#include "../worktree.h"
+#include "../wrapper.h"
 
 /*
  * This backend uses the following flags in `ref_update::flags` for
diff --git a/rerere.c b/rerere.c
index c3258e13902..b5ccbecdcd2 100644
--- a/rerere.c
+++ b/rerere.c
@@ -16,6 +16,7 @@
 #include "object-store.h"
 #include "hash-lookup.h"
 #include "strmap.h"
+#include "wrapper.h"
 
 #define RESOLVED 0
 #define PUNTED 1
diff --git a/sequencer.c b/sequencer.c
index c61c1fc4d87..aa7983f5b45 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -41,6 +41,7 @@
 #include "rebase-interactive.h"
 #include "reset.h"
 #include "branch.h"
+#include "wrapper.h"
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
diff --git a/server-info.c b/server-info.c
index 78643377057..ae96d784e53 100644
--- a/server-info.c
+++ b/server-info.c
@@ -10,6 +10,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "strbuf.h"
+#include "wrapper.h"
 
 struct update_info_ctx {
 	FILE *cur_fp;
diff --git a/shallow.c b/shallow.c
index c5433a4fd30..7fcba5f6d06 100644
--- a/shallow.c
+++ b/shallow.c
@@ -17,6 +17,7 @@
 #include "list-objects.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "wrapper.h"
 
 void set_alternate_shallow_file(struct repository *r, const char *path, int override)
 {
diff --git a/strbuf.c b/strbuf.c
index 9633e37b62f..70a83e7980e 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -8,6 +8,7 @@
 #include "string-list.h"
 #include "utf8.h"
 #include "date.h"
+#include "wrapper.h"
 
 int starts_with(const char *str, const char *prefix)
 {
diff --git a/streaming.c b/streaming.c
index 27841dc1d9e..6c69f595045 100644
--- a/streaming.c
+++ b/streaming.c
@@ -7,6 +7,7 @@
 #include "object-store.h"
 #include "replace-object.h"
 #include "packfile.h"
+#include "wrapper.h"
 
 typedef int (*open_istream_fn)(struct git_istream *,
 			       struct repository *,
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index b15481ea596..6609fcbc12e 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -12,6 +12,7 @@
 #include "git-compat-util.h"
 #include "delta.h"
 #include "cache.h"
+#include "wrapper.h"
 
 static const char usage_str[] =
 	"test-tool delta (-d|-p) <from_file> <data_file> <out_file>";
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 54a4856c48c..c43fc976b82 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -9,6 +9,7 @@
 #include "fsmonitor-ipc.h"
 #include "thread-utils.h"
 #include "trace2.h"
+#include "wrapper.h"
 
 #ifndef HAVE_FSMONITOR_DAEMON_BACKEND
 int cmd__fsmonitor_client(int argc, const char **argv)
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 23e9e27109f..84818363d5b 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "wrapper.h"
 
 int cmd__read_cache(int argc, const char **argv)
 {
diff --git a/tag.c b/tag.c
index 18b718cca66..3408bb9433f 100644
--- a/tag.c
+++ b/tag.c
@@ -8,6 +8,7 @@
 #include "gpg-interface.h"
 #include "hex.h"
 #include "packfile.h"
+#include "wrapper.h"
 
 const char *tag_type = "tag";
 
diff --git a/tempfile.c b/tempfile.c
index e27048f970b..cdd2cab3bad 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -45,6 +45,7 @@
 #include "cache.h"
 #include "tempfile.h"
 #include "sigchain.h"
+#include "wrapper.h"
 
 static VOLATILE_LIST_HEAD(tempfile_list);
 
diff --git a/trace.c b/trace.c
index 2b41c683fc8..de004f62988 100644
--- a/trace.c
+++ b/trace.c
@@ -24,6 +24,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "quote.h"
+#include "wrapper.h"
 
 struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
 struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);
diff --git a/transport-helper.c b/transport-helper.c
index 105bb801c21..09048eab484 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -16,6 +16,7 @@
 #include "refspec.h"
 #include "transport-internal.h"
 #include "protocol.h"
+#include "wrapper.h"
 
 static int debug;
 
diff --git a/transport.c b/transport.c
index 80059124c0a..c6179b801e8 100644
--- a/transport.c
+++ b/transport.c
@@ -26,6 +26,7 @@
 #include "object-store.h"
 #include "color.h"
 #include "bundle-uri.h"
+#include "wrapper.h"
 
 static int transport_use_color = -1;
 static char transport_colors[][COLOR_MAXLEN] = {
diff --git a/usage.c b/usage.c
index 40a1c5a4339..b53c99dbe5b 100644
--- a/usage.c
+++ b/usage.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "gettext.h"
+#include "wrapper.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
 {
diff --git a/worktree.c b/worktree.c
index b7bc4c7bb7a..fe4345012c4 100644
--- a/worktree.c
+++ b/worktree.c
@@ -9,6 +9,7 @@
 #include "dir.h"
 #include "wt-status.h"
 #include "config.h"
+#include "wrapper.h"
 
 void free_worktrees(struct worktree **worktrees)
 {
diff --git a/wrapper.c b/wrapper.c
index df1fa6286d0..ee837575902 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -5,6 +5,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "gettext.h"
+#include "wrapper.h"
 
 static intmax_t count_fsync_writeout_only;
 static intmax_t count_fsync_hardware_flush;
diff --git a/wrapper.h b/wrapper.h
new file mode 100644
index 00000000000..f0c7d0616d6
--- /dev/null
+++ b/wrapper.h
@@ -0,0 +1,36 @@
+#ifndef WRAPPER_H
+#define WRAPPER_H
+
+/* set default permissions by passing mode arguments to open(2) */
+int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
+int git_mkstemp_mode(char *pattern, int mode);
+
+ssize_t read_in_full(int fd, void *buf, size_t count);
+ssize_t write_in_full(int fd, const void *buf, size_t count);
+ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
+
+static inline ssize_t write_str_in_full(int fd, const char *str)
+{
+	return write_in_full(fd, str, strlen(str));
+}
+
+/**
+ * Open (and truncate) the file at path, write the contents of buf to it,
+ * and close it. Dies if any errors are encountered.
+ */
+void write_file_buf(const char *path, const char *buf, size_t len);
+
+/**
+ * Like write_file_buf(), but format the contents into a buffer first.
+ * Additionally, write_file() will append a newline if one is not already
+ * present, making it convenient to write text files:
+ *
+ *   write_file(path, "counter: %d", ctr);
+ */
+__attribute__((format (printf, 2, 3)))
+void write_file(const char *path, const char *fmt, ...);
+
+/* Return 1 if the file is empty or does not exists, 0 otherwise. */
+int is_empty_or_missing_file(const char *filename);
+
+#endif /* WRAPPER_H */
diff --git a/write-or-die.c b/write-or-die.c
index aaa0318e824..a7afc303db2 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "run-command.h"
+#include "wrapper.h"
 
 /*
  * Some cases use stdio, but want to flush after the write
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 10/16] treewide: remove unnecessary includes of cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (8 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 09/16] wrapper.h: move declarations for wrapper.c " Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 11/16] environment.h: move declarations for environment.c functions from cache.h Elijah Newren via GitGitGadget
                     ` (6 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The last several commits were geared at replacing the include of cache.h
in strbuf.c with an include of git-compat-util.h.  Unfortunately, I had
to drop a patch moving some functions from cache.h to object-name.h, due
to excessive conflicts with other in-flight topics.

However, even without that patch, the series of patches so far allows us
to modify a number of C files to replace an include of cache.h with
git-compat-util.h.  Do that to reduce our dependencies.

(If we could have kept our object-name.h patch in this series, it would
have also let us reduce the includes in checkout.c and fmt-merge-msg.c
in addition to strbuf.c).

Just to ensure that nothing else was bringing in cache.h, all of the
affected files have been checked to ensure that
    gcc -E -I. $SOURCE_FILE | grep '"cache.h"'
found no hits and that
    make DEVELOPER=1 ${OBJECT_FILE_FOR_SOURCE_FILE}
successfully compiles without warnings.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 compat/terminal.c      | 2 +-
 gpg-interface.c        | 2 +-
 lockfile.c             | 2 +-
 parse-options.c        | 1 -
 t/helper/test-delta.c  | 1 -
 t/helper/test-trace2.c | 2 +-
 tempfile.c             | 3 ++-
 trace2/tr2_cfg.c       | 4 +++-
 trace2/tr2_cmd_name.c  | 3 ++-
 trace2/tr2_dst.c       | 3 ++-
 trace2/tr2_sid.c       | 3 ++-
 usage.c                | 3 ++-
 12 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/compat/terminal.c b/compat/terminal.c
index ed2b30b38f7..d87e3211892 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "compat/terminal.h"
 #include "gettext.h"
 #include "sigchain.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index 6644701fda0..aceeb083367 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "commit.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/lockfile.c b/lockfile.c
index 673c21d17a9..1d5ed016828 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2005, Junio C Hamano
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "lockfile.h"
diff --git a/parse-options.c b/parse-options.c
index a577cc85f67..b6803647d0e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,7 +1,6 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "color.h"
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index 6609fcbc12e..e7d134ec251 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -11,7 +11,6 @@
 #include "test-tool.h"
 #include "git-compat-util.h"
 #include "delta.h"
-#include "cache.h"
 #include "wrapper.h"
 
 static const char usage_str[] =
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index f374c21ec32..a476df6c6cb 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,9 +1,9 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "strvec.h"
 #include "run-command.h"
 #include "exec-cmd.h"
 #include "config.h"
+#include "trace2.h"
 
 typedef int(fn_unit_test)(int argc, const char **argv);
 
diff --git a/tempfile.c b/tempfile.c
index cdd2cab3bad..50c377134ce 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -42,7 +42,8 @@
  * file created by its parent.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
+#include "path.h"
 #include "tempfile.h"
 #include "sigchain.h"
 #include "wrapper.h"
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index ec9ac1a6efd..78cfc15d52d 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -1,5 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
+#include "strbuf.h"
+#include "trace2.h"
 #include "trace2/tr2_cfg.h"
 #include "trace2/tr2_sysenv.h"
 
diff --git a/trace2/tr2_cmd_name.c b/trace2/tr2_cmd_name.c
index dd313204f51..b7b5a869b74 100644
--- a/trace2/tr2_cmd_name.c
+++ b/trace2/tr2_cmd_name.c
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "strbuf.h"
 #include "trace2/tr2_cmd_name.h"
 
 #define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME"
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index 273260e1f18..5be892cd5cd 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "sigchain.h"
+#include "strbuf.h"
 #include "trace2/tr2_dst.h"
 #include "trace2/tr2_sid.h"
 #include "trace2/tr2_sysenv.h"
diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c
index 5f1ce6f85cf..09c4ef0d173 100644
--- a/trace2/tr2_sid.c
+++ b/trace2/tr2_sid.c
@@ -1,5 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hex.h"
+#include "strbuf.h"
 #include "trace2/tr2_tbuf.h"
 #include "trace2/tr2_sid.h"
 
diff --git a/usage.c b/usage.c
index b53c99dbe5b..46d99f8bd43 100644
--- a/usage.c
+++ b/usage.c
@@ -3,8 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
+#include "trace2.h"
 #include "wrapper.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 11/16] environment.h: move declarations for environment.c functions from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (9 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 10/16] treewide: remove unnecessary includes of cache.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 12/16] treewide: remove cache.h inclusion due to environment.h changes Elijah Newren via GitGitGadget
                     ` (5 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                             |   1 +
 archive.c                           |   1 +
 attr.c                              |   1 +
 bisect.c                            |   1 +
 branch.c                            |   1 +
 builtin/am.c                        |   1 +
 builtin/bisect.c                    |   1 +
 builtin/blame.c                     |   1 +
 builtin/cat-file.c                  |   1 +
 builtin/check-attr.c                |   1 +
 builtin/checkout.c                  |   1 +
 builtin/clone.c                     |   1 +
 builtin/commit-graph.c              |   1 +
 builtin/config.c                    |   1 +
 builtin/count-objects.c             |   1 +
 builtin/describe.c                  |   1 +
 builtin/difftool.c                  |   1 +
 builtin/fast-import.c               |   1 +
 builtin/fetch.c                     |   1 +
 builtin/fsmonitor--daemon.c         |   1 +
 builtin/gc.c                        |   1 +
 builtin/index-pack.c                |   1 +
 builtin/init-db.c                   |   1 +
 builtin/log.c                       |   1 +
 builtin/mailinfo.c                  |   1 +
 builtin/multi-pack-index.c          |   1 +
 builtin/mv.c                        |   1 +
 builtin/name-rev.c                  |   1 +
 builtin/pack-objects.c              |   1 +
 builtin/prune.c                     |   1 +
 builtin/push.c                      |   1 +
 builtin/rebase.c                    |   1 +
 builtin/receive-pack.c              |   1 +
 builtin/repack.c                    |   1 +
 builtin/replace.c                   |   1 +
 builtin/reset.c                     |   1 +
 builtin/rev-list.c                  |   1 +
 builtin/rev-parse.c                 |   1 +
 builtin/shortlog.c                  |   1 +
 builtin/show-branch.c               |   1 +
 builtin/sparse-checkout.c           |   1 +
 builtin/stash.c                     |   1 +
 builtin/submodule--helper.c         |   1 +
 builtin/unpack-objects.c            |   1 +
 builtin/update-index.c              |   1 +
 builtin/worktree.c                  |   1 +
 builtin/write-tree.c                |   1 +
 bulk-checkin.c                      |   1 +
 bundle-uri.c                        |   1 +
 bundle.c                            |   1 +
 cache-tree.c                        |   1 +
 cache.h                             | 207 ---------------------------
 combine-diff.c                      |   1 +
 compat/mingw.c                      |   1 +
 compat/precompose_utf8.c            |   1 +
 connect.c                           |   1 +
 daemon.c                            |   1 +
 diff.c                              |   1 +
 dir.c                               |   1 +
 editor.c                            |   1 +
 entry.c                             |   1 +
 environment.h                       | 213 ++++++++++++++++++++++++++++
 exec-cmd.c                          |   1 +
 fetch-pack.c                        |   1 +
 fsmonitor.c                         |   1 +
 gettext.c                           |   1 +
 git.c                               |   1 +
 http-backend.c                      |   1 +
 http-push.c                         |   1 +
 log-tree.c                          |   1 +
 ls-refs.c                           |   1 +
 mailmap.c                           |   1 +
 merge-ort.c                         |   1 +
 merge-recursive.c                   |   1 +
 name-hash.c                         |   1 +
 notes-utils.c                       |   1 +
 notes.c                             |   1 +
 object-file.c                       |   1 +
 object-name.c                       |   1 +
 pack-bitmap-write.c                 |   1 +
 pack-check.c                        |   1 +
 pack-write.c                        |   1 +
 packfile.c                          |   1 +
 parse-options-cb.c                  |   1 +
 path.c                              |   1 +
 pathspec.c                          |   1 +
 preload-index.c                     |   1 +
 pretty.c                            |   1 +
 prompt.c                            |   1 +
 protocol.c                          |   1 +
 prune-packed.c                      |   1 +
 range-diff.c                        |   1 +
 read-cache.c                        |   1 +
 rebase-interactive.c                |   1 +
 ref-filter.c                        |   1 +
 refs.c                              |   1 +
 refs/files-backend.c                |   1 +
 remote-curl.c                       |   1 +
 remote.c                            |   1 +
 revision.c                          |   1 +
 run-command.c                       |   1 +
 server-info.c                       |   1 +
 setup.c                             |   1 +
 sparse-index.c                      |   1 +
 streaming.c                         |   1 +
 submodule-config.c                  |   1 +
 submodule.c                         |   1 +
 t/helper/test-fast-rebase.c         |   1 +
 t/helper/test-lazy-init-name-hash.c |   1 +
 t/helper/test-path-utils.c          |   1 +
 t/helper/test-repository.c          |   1 +
 tag.c                               |   1 +
 tmp-objdir.c                        |   1 +
 trace.c                             |   1 +
 transport-helper.c                  |   1 +
 transport.c                         |   1 +
 unpack-trees.c                      |   1 +
 upload-pack.c                       |   1 +
 worktree.c                          |   1 +
 119 files changed, 330 insertions(+), 207 deletions(-)

diff --git a/apply.c b/apply.c
index 373565a7baf..a7c0bccb15c 100644
--- a/apply.c
+++ b/apply.c
@@ -16,6 +16,7 @@
 #include "delta.h"
 #include "diff.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "xdiff-interface.h"
diff --git a/archive.c b/archive.c
index c3c45a5ebe9..7aeaaf368f4 100644
--- a/archive.c
+++ b/archive.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/attr.c b/attr.c
index 48e2d646187..62127196cb1 100644
--- a/attr.c
+++ b/attr.c
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "attr.h"
 #include "dir.h"
diff --git a/bisect.c b/bisect.c
index 5a3a8182d83..8a4be05dc52 100644
--- a/bisect.c
+++ b/bisect.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/branch.c b/branch.c
index 66d32c68564..3865bdbc87c 100644
--- a/branch.c
+++ b/branch.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "branch.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/am.c b/builtin/am.c
index 37f82b3eb42..192968ac300 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "builtin.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 31cc57e45ba..d8e92dfa16a 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 21f6b523a6d..9ec82edcbde 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9f1bf8f0e96..365d9234bdb 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "ident.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index ad27255e2cb..5870c4683ab 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "attr.h"
+#include "environment.h"
 #include "gettext.h"
 #include "quote.h"
 #include "parse-options.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 47d4c369a16..5541e76c337 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "diff.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "hook.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index b94324ea02c..15dc15408ed 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 311e0106810..90114269761 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/config.c b/builtin/config.c
index 1c1e006ff3f..cf994a216c0 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -3,6 +3,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "color.h"
+#include "environment.h"
 #include "gettext.h"
 #include "ident.h"
 #include "parse-options.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 48edc86c240..f3d8f1bcbb0 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "builtin.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index fcacdf8a693..27c6670e934 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 59465c39f1d..3613de6389f 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -17,6 +17,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "run-command.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 3300b7f30f0..068843a5d21 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 990f81f6d1a..4d883da02e6 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 4efb1417344..a280d8bb14f 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "fsmonitor.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 2107e3d1f2c..525c5de5b27 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -12,6 +12,7 @@
 
 #include "builtin.h"
 #include "abspath.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2393897cb88..fdce8f88724 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "delta.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pack.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index a5d4f5c8ece..2ebc9023f56 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "builtin.h"
diff --git a/builtin/log.c b/builtin/log.c
index b7333b34cce..1b92dee196e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index e14f7c0abce..a032a1c3881 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
 #include "strbuf.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 579bc2cac0c..1b5083f8b26 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 0a49bf21b0f..c2dd42efbf2 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "pathspec.h"
 #include "lockfile.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 6977a5f580b..66f82ef66f4 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b55a088a7c..9829b952c2b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index ff62a0adb8f..5a381fcdf9a 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/builtin/push.c b/builtin/push.c
index 2d76fa68376..fa550b8f80a 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "branch.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index d2f8f703d67..9f3135116ed 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -7,6 +7,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "run-command.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index ae49ea8c2ad..3745c0b95cd 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "repository.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 771ca01527d..ccbd5f55562 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index cf85e590d9f..dc0331defc2 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 4335c1a6e1b..b5dfce1159e 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -10,6 +10,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index f2f6a0d3e67..b202647f281 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index a4c0878bc91..bba49d56b9f 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -9,6 +9,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index d8c4379ea16..31f81c25ea2 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
 #include "revision.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 8d569629726..c4aa0e62f26 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pretty.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 3976d8e86b8..f6a120c7c45 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "pathspec.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 52fa892f7eb..94f81d75d03 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ff1fd8c87ab..2bf2a1a8be5 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f7c4b531076..c65ae3b2078 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ef78b2d28e1..4642afaeb77 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 1533b4ab43c..d9345efdb2b 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 7eec4e3cbd1..6085f64d100 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 778ca1e0f4f..eb6d7a2805b 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 2cc7d159bd6..1ff1cf51dad 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "bundle-uri.h"
 #include "bundle.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "refs.h"
diff --git a/bundle.c b/bundle.c
index f5b3643b17e..efeaf6f7151 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "lockfile.h"
 #include "bundle.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/cache-tree.c b/cache-tree.c
index 6f899beb041..231c3eb2ff6 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tree.h"
diff --git a/cache.h b/cache.h
index 31c722533f9..720c88f9fd6 100644
--- a/cache.h
+++ b/cache.h
@@ -452,98 +452,10 @@ static inline enum object_type object_type(unsigned int mode)
 		OBJ_BLOB;
 }
 
-/* Double-check local_repo_env below if you add to this list. */
-#define GIT_DIR_ENVIRONMENT "GIT_DIR"
-#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR"
-#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
-#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
-#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
-#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
-#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
-#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
-#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
-#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"
-#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
-#define CONFIG_ENVIRONMENT "GIT_CONFIG"
-#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
-#define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT"
-#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
-#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
-#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
-#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
-#define GITATTRIBUTES_FILE ".gitattributes"
-#define INFOATTRIBUTES_FILE "info/attributes"
-#define ATTRIBUTE_MACRO_PREFIX "[attr]"
-#define GITMODULES_FILE ".gitmodules"
-#define GITMODULES_INDEX ":.gitmodules"
-#define GITMODULES_HEAD "HEAD:.gitmodules"
-#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
-#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
-#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"
-#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF"
-#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"
-#define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS"
-#define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS"
-#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
-#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
-#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
-#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
-#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
-
-/*
- * Environment variable used in handshaking the wire protocol.
- * Contains a colon ':' separated list of keys with optional values
- * 'key[=value]'.  Presence of unknown keys and values must be
- * ignored.
- */
-#define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL"
-/* HTTP header used to handshake the wire protocol */
-#define GIT_PROTOCOL_HEADER "Git-Protocol"
-
-/*
- * This environment variable is expected to contain a boolean indicating
- * whether we should or should not treat:
- *
- *   GIT_DIR=foo.git git ...
- *
- * as if GIT_WORK_TREE=. was given. It's not expected that users will make use
- * of this, but we use it internally to communicate to sub-processes that we
- * are in a bare repo. If not set, defaults to true.
- */
-#define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE"
-
-/*
- * Repository-local GIT_* environment variables; these will be cleared
- * when git spawns a sub-process that runs inside another repository.
- * The array is NULL-terminated, which makes it easy to pass in the "env"
- * parameter of a run-command invocation, or to do a simple walk.
- */
-extern const char * const local_repo_env[];
-
-void setup_git_env(const char *git_dir);
-
-/*
- * Returns true iff we have a configured git repository (either via
- * setup_git_directory, or in the environment via $GIT_DIR).
- */
-int have_git_dir(void);
-
-extern int is_bare_repository_cfg;
-int is_bare_repository(void);
 int is_inside_git_dir(void);
-extern char *git_work_tree_cfg;
 int is_inside_work_tree(void);
-const char *get_git_dir(void);
-const char *get_git_common_dir(void);
-const char *get_object_directory(void);
-char *get_index_file(void);
-char *get_graft_file(struct repository *r);
-void set_git_dir(const char *path, int make_realpath);
 int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
 int get_common_dir(struct strbuf *sb, const char *gitdir);
-const char *get_git_namespace(void);
-const char *strip_namespace(const char *namespaced_ref);
-const char *get_git_work_tree(void);
 
 /*
  * Return true if the given path is a git directory; note that this _just_
@@ -578,10 +490,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code);
 const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
 #define resolve_gitdir(path) resolve_gitdir_gently((path), NULL)
 
-void set_git_work_tree(const char *tree);
-
-#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
-
 void setup_work_tree(void);
 /*
  * Find the commondir and gitdir of the repository that contains the current
@@ -840,39 +748,7 @@ void set_alternate_index_output(const char *);
 extern int verify_index_checksum;
 extern int verify_ce_order;
 
-/* Environment bits from configuration mechanism */
-extern int trust_executable_bit;
-extern int trust_ctime;
-extern int check_stat;
 extern int quote_path_fully;
-extern int has_symlinks;
-extern int minimum_abbrev, default_abbrev;
-extern int ignore_case;
-extern int assume_unchanged;
-extern int prefer_symlink_refs;
-extern int warn_ambiguous_refs;
-extern int warn_on_object_refname_ambiguity;
-extern char *apply_default_whitespace;
-extern char *apply_default_ignorewhitespace;
-extern const char *git_attributes_file;
-extern const char *git_hooks_path;
-extern int zlib_compression_level;
-extern int pack_compression_level;
-extern size_t packed_git_window_size;
-extern size_t packed_git_limit;
-extern size_t delta_base_cache_limit;
-extern unsigned long big_file_threshold;
-extern unsigned long pack_size_limit_cfg;
-
-/*
- * Accessors for the core.sharedrepository config which lazy-load the value
- * from the config (if not already set). The "reset" function can be
- * used to unset "set" or cached value, meaning that the value will be loaded
- * fresh from the config file on the next call to get_shared_repository().
- */
-void set_shared_repository(int value);
-int get_shared_repository(void);
-void reset_shared_repository(void);
 
 /*
  * These values are used to help identify parts of a repository to fsync.
@@ -930,57 +806,6 @@ enum fsync_method {
 };
 
 extern enum fsync_method fsync_method;
-extern int core_preload_index;
-extern int precomposed_unicode;
-extern int protect_hfs;
-extern int protect_ntfs;
-
-extern int core_apply_sparse_checkout;
-extern int core_sparse_checkout_cone;
-extern int sparse_expect_files_outside_of_patterns;
-
-/*
- * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
- */
-int use_optional_locks(void);
-
-enum log_refs_config {
-	LOG_REFS_UNSET = -1,
-	LOG_REFS_NONE = 0,
-	LOG_REFS_NORMAL,
-	LOG_REFS_ALWAYS
-};
-extern enum log_refs_config log_all_ref_updates;
-
-enum rebase_setup_type {
-	AUTOREBASE_NEVER = 0,
-	AUTOREBASE_LOCAL,
-	AUTOREBASE_REMOTE,
-	AUTOREBASE_ALWAYS
-};
-
-enum push_default_type {
-	PUSH_DEFAULT_NOTHING = 0,
-	PUSH_DEFAULT_MATCHING,
-	PUSH_DEFAULT_SIMPLE,
-	PUSH_DEFAULT_UPSTREAM,
-	PUSH_DEFAULT_CURRENT,
-	PUSH_DEFAULT_UNSPECIFIED
-};
-
-extern enum rebase_setup_type autorebase;
-extern enum push_default_type push_default;
-
-enum object_creation_mode {
-	OBJECT_CREATION_USES_HARDLINKS = 0,
-	OBJECT_CREATION_USES_RENAMES = 1
-};
-
-extern enum object_creation_mode object_creation_mode;
-
-extern char *notes_ref_name;
-
-extern int grafts_replace_parents;
 
 /*
  * GIT_REPO_VERSION is the version we write by default. The
@@ -989,8 +814,6 @@ extern int grafts_replace_parents;
  */
 #define GIT_REPO_VERSION 0
 #define GIT_REPO_VERSION_READ 1
-extern int repository_format_precious_objects;
-extern int repository_format_worktree_config;
 
 /*
  * You _have_ to initialize a `struct repository_format` using
@@ -1362,21 +1185,6 @@ struct pack_entry {
 	struct packed_git *p;
 };
 
-/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
- * usual "XXXXXX" trailer, and the resulting filename is written into the
- * "template" buffer. Returns the open descriptor.
- */
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
-
-/*
- * Create a pack .keep file named "name" (which should generally be the output
- * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
- * error.
- */
-int odb_pack_keep(const char *name);
-
 /*
  * Set this to 0 to prevent oid_object_info_extended() from fetching missing
  * blobs. This has a difference only if extensions.partialClone is set.
@@ -1388,11 +1196,6 @@ extern int fetch_if_missing;
 /* Dumb servers support */
 int update_server_info(int);
 
-const char *get_log_output_encoding(void);
-const char *get_commit_output_encoding(void);
-
-extern const char *git_commit_encoding;
-extern const char *git_log_output_encoding;
 extern const char *git_mailmap_file;
 extern const char *git_mailmap_blob;
 
@@ -1429,10 +1232,6 @@ int decimal_width(uintmax_t);
 int check_pager_config(const char *cmd);
 void prepare_pager_args(struct child_process *, const char *pager);
 
-extern const char *editor_program;
-extern const char *askpass_program;
-extern const char *excludes_file;
-
 /* base85 */
 int decode_85(char *dst, const char *line, int linelen);
 void encode_85(char *buf, const unsigned char *data, int bytes);
@@ -1536,10 +1335,4 @@ void stat_validity_update(struct stat_validity *sv, int fd);
 
 int versioncmp(const char *s1, const char *s2);
 
-/*
- * Should we print an ellipsis after an abbreviated SHA-1 value
- * when doing diff-raw output or indicating a detached HEAD?
- */
-int print_sha1_ellipsis(void);
-
 #endif /* CACHE_H */
diff --git a/combine-diff.c b/combine-diff.c
index 91051dc3258..3758e47c4f4 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -4,6 +4,7 @@
 #include "blob.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "environment.h"
 #include "hex.h"
 #include "quote.h"
 #include "xdiff-interface.h"
diff --git a/compat/mingw.c b/compat/mingw.c
index d48899bf7b4..94c5a1daa40 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -11,6 +11,7 @@
 #include "../alloc.h"
 #include "win32/lazyload.h"
 #include "../config.h"
+#include "../environment.h"
 #include "../wrapper.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 56d36cdf22a..8a9881db077 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
diff --git a/connect.c b/connect.c
index f3b159bf441..737dd906f72 100644
--- a/connect.c
+++ b/connect.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pkt-line.h"
diff --git a/daemon.c b/daemon.c
index e35604e194c..b56a8f9717d 100644
--- a/daemon.c
+++ b/daemon.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "pkt-line.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/diff.c b/diff.c
index 1b0b24c21c3..dcf1a940942 100644
--- a/diff.c
+++ b/diff.c
@@ -5,6 +5,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "tempfile.h"
 #include "quote.h"
diff --git a/dir.c b/dir.c
index b57c770e68b..06f8aa3c01b 100644
--- a/dir.c
+++ b/dir.c
@@ -10,6 +10,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/editor.c b/editor.c
index 2d3e6be64e4..d632d790660 100644
--- a/editor.c
+++ b/editor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "strbuf.h"
 #include "strvec.h"
diff --git a/entry.c b/entry.c
index 70212af260b..750c1f6b2f4 100644
--- a/entry.c
+++ b/entry.c
@@ -2,6 +2,7 @@
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "streaming.h"
diff --git a/environment.h b/environment.h
index a26931556af..a63f0c6a24f 100644
--- a/environment.h
+++ b/environment.h
@@ -3,6 +3,8 @@
 
 #include "strvec.h"
 
+struct repository;
+
 /*
  * The character that begins a commented line in user-editable file
  * that is subject to stripspace.
@@ -16,4 +18,215 @@ extern int auto_comment_line_char;
  */
 const char *getenv_safe(struct strvec *argv, const char *name);
 
+/* Double-check local_repo_env below if you add to this list. */
+#define GIT_DIR_ENVIRONMENT "GIT_DIR"
+#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR"
+#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
+#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
+#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
+#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
+#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
+#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
+#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
+#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"
+#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
+#define CONFIG_ENVIRONMENT "GIT_CONFIG"
+#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
+#define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT"
+#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
+#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
+#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
+#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
+#define GITATTRIBUTES_FILE ".gitattributes"
+#define INFOATTRIBUTES_FILE "info/attributes"
+#define ATTRIBUTE_MACRO_PREFIX "[attr]"
+#define GITMODULES_FILE ".gitmodules"
+#define GITMODULES_INDEX ":.gitmodules"
+#define GITMODULES_HEAD "HEAD:.gitmodules"
+#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
+#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
+#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"
+#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF"
+#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"
+#define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS"
+#define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS"
+#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
+#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
+#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
+#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
+#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
+
+/*
+ * Environment variable used in handshaking the wire protocol.
+ * Contains a colon ':' separated list of keys with optional values
+ * 'key[=value]'.  Presence of unknown keys and values must be
+ * ignored.
+ */
+#define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL"
+/* HTTP header used to handshake the wire protocol */
+#define GIT_PROTOCOL_HEADER "Git-Protocol"
+
+/*
+ * This environment variable is expected to contain a boolean indicating
+ * whether we should or should not treat:
+ *
+ *   GIT_DIR=foo.git git ...
+ *
+ * as if GIT_WORK_TREE=. was given. It's not expected that users will make use
+ * of this, but we use it internally to communicate to sub-processes that we
+ * are in a bare repo. If not set, defaults to true.
+ */
+#define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE"
+
+/*
+ * Repository-local GIT_* environment variables; these will be cleared
+ * when git spawns a sub-process that runs inside another repository.
+ * The array is NULL-terminated, which makes it easy to pass in the "env"
+ * parameter of a run-command invocation, or to do a simple walk.
+ */
+extern const char * const local_repo_env[];
+
+void setup_git_env(const char *git_dir);
+
+/*
+ * Returns true iff we have a configured git repository (either via
+ * setup_git_directory, or in the environment via $GIT_DIR).
+ */
+int have_git_dir(void);
+
+extern int is_bare_repository_cfg;
+int is_bare_repository(void);
+extern char *git_work_tree_cfg;
+const char *get_git_dir(void);
+const char *get_git_common_dir(void);
+const char *get_object_directory(void);
+char *get_index_file(void);
+char *get_graft_file(struct repository *r);
+void set_git_dir(const char *path, int make_realpath);
+const char *get_git_namespace(void);
+const char *strip_namespace(const char *namespaced_ref);
+const char *get_git_work_tree(void);
+void set_git_work_tree(const char *tree);
+
+#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
+
+/* Environment bits from configuration mechanism */
+extern int trust_executable_bit;
+extern int trust_ctime;
+extern int check_stat;
+extern int has_symlinks;
+extern int minimum_abbrev, default_abbrev;
+extern int ignore_case;
+extern int assume_unchanged;
+extern int prefer_symlink_refs;
+extern int warn_ambiguous_refs;
+extern int warn_on_object_refname_ambiguity;
+extern char *apply_default_whitespace;
+extern char *apply_default_ignorewhitespace;
+extern const char *git_attributes_file;
+extern const char *git_hooks_path;
+extern int zlib_compression_level;
+extern int pack_compression_level;
+extern size_t packed_git_window_size;
+extern size_t packed_git_limit;
+extern size_t delta_base_cache_limit;
+extern unsigned long big_file_threshold;
+extern unsigned long pack_size_limit_cfg;
+
+/*
+ * Accessors for the core.sharedrepository config which lazy-load the value
+ * from the config (if not already set). The "reset" function can be
+ * used to unset "set" or cached value, meaning that the value will be loaded
+ * fresh from the config file on the next call to get_shared_repository().
+ */
+void set_shared_repository(int value);
+int get_shared_repository(void);
+void reset_shared_repository(void);
+
+extern int core_preload_index;
+extern int precomposed_unicode;
+extern int protect_hfs;
+extern int protect_ntfs;
+
+extern int core_apply_sparse_checkout;
+extern int core_sparse_checkout_cone;
+extern int sparse_expect_files_outside_of_patterns;
+
+/*
+ * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
+ */
+int use_optional_locks(void);
+
+enum log_refs_config {
+	LOG_REFS_UNSET = -1,
+	LOG_REFS_NONE = 0,
+	LOG_REFS_NORMAL,
+	LOG_REFS_ALWAYS
+};
+extern enum log_refs_config log_all_ref_updates;
+
+enum rebase_setup_type {
+	AUTOREBASE_NEVER = 0,
+	AUTOREBASE_LOCAL,
+	AUTOREBASE_REMOTE,
+	AUTOREBASE_ALWAYS
+};
+
+enum push_default_type {
+	PUSH_DEFAULT_NOTHING = 0,
+	PUSH_DEFAULT_MATCHING,
+	PUSH_DEFAULT_SIMPLE,
+	PUSH_DEFAULT_UPSTREAM,
+	PUSH_DEFAULT_CURRENT,
+	PUSH_DEFAULT_UNSPECIFIED
+};
+
+extern enum rebase_setup_type autorebase;
+extern enum push_default_type push_default;
+
+enum object_creation_mode {
+	OBJECT_CREATION_USES_HARDLINKS = 0,
+	OBJECT_CREATION_USES_RENAMES = 1
+};
+
+extern enum object_creation_mode object_creation_mode;
+
+extern char *notes_ref_name;
+
+extern int grafts_replace_parents;
+
+extern int repository_format_precious_objects;
+extern int repository_format_worktree_config;
+
+/*
+ * Create a temporary file rooted in the object database directory, or
+ * die on failure. The filename is taken from "pattern", which should have the
+ * usual "XXXXXX" trailer, and the resulting filename is written into the
+ * "template" buffer. Returns the open descriptor.
+ */
+int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+
+/*
+ * Create a pack .keep file named "name" (which should generally be the output
+ * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
+ * error.
+ */
+int odb_pack_keep(const char *name);
+
+const char *get_log_output_encoding(void);
+const char *get_commit_output_encoding(void);
+
+extern const char *git_commit_encoding;
+extern const char *git_log_output_encoding;
+
+extern const char *editor_program;
+extern const char *askpass_program;
+extern const char *excludes_file;
+
+/*
+ * Should we print an ellipsis after an abbreviated SHA-1 value
+ * when doing diff-raw output or indicating a detached HEAD?
+ */
+int print_sha1_ellipsis(void);
+
 #endif
diff --git a/exec-cmd.c b/exec-cmd.c
index 042d9247a5b..fae0d4b244a 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "quote.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index c1190801405..c453a4168f9 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/fsmonitor.c b/fsmonitor.c
index a5b9e75437b..c956a347a27 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "fsmonitor-ipc.h"
diff --git a/gettext.c b/gettext.c
index 3e7b3baabc6..85d3d3424eb 100644
--- a/gettext.c
+++ b/gettext.c
@@ -4,6 +4,7 @@
 
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/git.c b/git.c
index 22ce4f14b65..b24c105e83f 100644
--- a/git.c
+++ b/git.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "help.h"
diff --git a/http-backend.c b/http-backend.c
index 42e6c2596e9..042ccf12e8c 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/http-push.c b/http-push.c
index 88aa045ecba..40373bc4863 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/log-tree.c b/log-tree.c
index 3adcb576e4c..e2bf8d6df75 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -2,6 +2,7 @@
 #include "commit-reach.h"
 #include "config.h"
 #include "diff.h"
+#include "environment.h"
 #include "hex.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/ls-refs.c b/ls-refs.c
index ae38889bf04..12cbb40a198 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/mailmap.c b/mailmap.c
index da2589b0822..2c6e9b238dd 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-store.h"
diff --git a/merge-ort.c b/merge-ort.c
index a26cad5f910..f3d7c202f52 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -26,6 +26,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "entry.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index f918cea4c69..d5f37724911 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -17,6 +17,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "ll-merge.h"
diff --git a/name-hash.c b/name-hash.c
index bb9eae55aca..2c2861efd1c 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2008 Linus Torvalds
  */
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "thread-utils.h"
 #include "trace2.h"
diff --git a/notes-utils.c b/notes-utils.c
index da08e2e8e5c..8797271faf1 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "notes-utils.h"
diff --git a/notes.c b/notes.c
index a7187236e98..9288c1a0705 100644
--- a/notes.c
+++ b/notes.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "notes.h"
 #include "object-store.h"
diff --git a/object-file.c b/object-file.c
index bdf68763a50..3da6cd68861 100644
--- a/object-file.c
+++ b/object-file.c
@@ -10,6 +10,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "string-list.h"
diff --git a/object-name.c b/object-name.c
index 2c927bbded3..3b0ce8ef05a 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tag.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7dc7f0ba55e..63f16080c9b 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/pack-check.c b/pack-check.c
index 7ed594d6679..6974e40a958 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "pack.h"
diff --git a/pack-write.c b/pack-write.c
index 87156f89d2b..f1714054951 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "pack.h"
diff --git a/packfile.c b/packfile.c
index 8c117ccee27..4b5b841d046 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "list.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index fbf4b010195..15d008c3daf 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "color.h"
+#include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
 #include "strvec.h"
diff --git a/path.c b/path.c
index 3976c0d7ace..5d5a15c13d6 100644
--- a/path.c
+++ b/path.c
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/pathspec.c b/pathspec.c
index 53763e272f5..5fb7b5f26c9 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
diff --git a/preload-index.c b/preload-index.c
index 4b45e1d6912..52544d004e7 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "environment.h"
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "config.h"
diff --git a/pretty.c b/pretty.c
index 9d7922dcc60..2b6d0f52c9f 100644
--- a/pretty.c
+++ b/pretty.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "utf8.h"
diff --git a/prompt.c b/prompt.c
index 50df17279d1..ba10813b313 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "prompt.h"
diff --git a/protocol.c b/protocol.c
index c53f7df5be4..bdb32e1eeb6 100644
--- a/protocol.c
+++ b/protocol.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "protocol.h"
 
 static enum protocol_version parse_protocol_version(const char *value)
diff --git a/prune-packed.c b/prune-packed.c
index cff5ad569c7..5a57072a7ac 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
 #include "packfile.h"
diff --git a/range-diff.c b/range-diff.c
index 1bfc612e274..815fb24c9ce 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "gettext.h"
 #include "range-diff.h"
 #include "string-list.h"
diff --git a/read-cache.c b/read-cache.c
index 9a8d5fe97ed..34567c1d550 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -18,6 +18,7 @@
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
+#include "environment.h"
 #include "gettext.h"
 #include "resolve-undo.h"
 #include "run-command.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 7c885c35bfd..a83334dd564 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "sequencer.h"
 #include "rebase-interactive.h"
diff --git a/ref-filter.c b/ref-filter.c
index 9a830bedef0..1489fbfe4ae 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
diff --git a/refs.c b/refs.c
index 385051752f1..04520e5a6b8 100644
--- a/refs.c
+++ b/refs.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "hashmap.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index eb14d124e3f..0c3138ede8f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,5 +1,6 @@
 #include "../cache.h"
 #include "../config.h"
+#include "../environment.h"
 #include "../gettext.h"
 #include "../hex.h"
 #include "../refs.h"
diff --git a/remote-curl.c b/remote-curl.c
index 943cd6fe6cd..eb382a1e35d 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "remote.h"
diff --git a/remote.c b/remote.c
index 2bae247a0a4..aeca3ff8136 100644
--- a/remote.c
+++ b/remote.c
@@ -2,6 +2,7 @@
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "remote.h"
diff --git a/revision.c b/revision.c
index 7423e23327b..53fdeef0787 100644
--- a/revision.c
+++ b/revision.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-store.h"
diff --git a/run-command.c b/run-command.c
index 2c8b4cd9bfc..614d48fa9a2 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "run-command.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "sigchain.h"
diff --git a/server-info.c b/server-info.c
index ae96d784e53..355b6e01a52 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "environment.h"
 #include "hex.h"
 #include "repository.h"
 #include "refs.h"
diff --git a/setup.c b/setup.c
index 8f385d9f29b..cfdc849a78c 100644
--- a/setup.c
+++ b/setup.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "config.h"
diff --git a/sparse-index.c b/sparse-index.c
index fdae9011b8e..886054729e5 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "sparse-index.h"
diff --git a/streaming.c b/streaming.c
index 6c69f595045..024fd796b7d 100644
--- a/streaming.c
+++ b/streaming.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2011, Google Inc.
  */
 #include "cache.h"
+#include "environment.h"
 #include "streaming.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/submodule-config.c b/submodule-config.c
index 38663801aa4..28fdfddccfb 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/submodule.c b/submodule.c
index 13ff333f68c..acf030b95e4 100644
--- a/submodule.c
+++ b/submodule.c
@@ -8,6 +8,7 @@
 #include "dir.h"
 #include "diff.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 68bbc41b330..627a6bdc3d0 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -15,6 +15,7 @@
 #include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index ab86c14c8ba..2b678a45793 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "cache.h"
+#include "environment.h"
 #include "parse-options.h"
 
 static int single;
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index d3d00dc34fa..cc266e3ec09 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "string-list.h"
 #include "utf8.h"
 
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 10a6dfc2160..c444775eb0f 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -3,6 +3,7 @@
 #include "commit-graph.h"
 #include "commit.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "object-store.h"
 #include "object.h"
diff --git a/tag.c b/tag.c
index 3408bb9433f..39434231799 100644
--- a/tag.c
+++ b/tag.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "environment.h"
 #include "tag.h"
 #include "object-store.h"
 #include "commit.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index fff15cb6b5c..5adad1925d1 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -3,6 +3,7 @@
 #include "abspath.h"
 #include "chdir-notify.h"
 #include "dir.h"
+#include "environment.h"
 #include "sigchain.h"
 #include "string-list.h"
 #include "strbuf.h"
diff --git a/trace.c b/trace.c
index de004f62988..9c85b71ec6a 100644
--- a/trace.c
+++ b/trace.c
@@ -23,6 +23,7 @@
 
 #include "cache.h"
 #include "abspath.h"
+#include "environment.h"
 #include "quote.h"
 #include "wrapper.h"
 
diff --git a/transport-helper.c b/transport-helper.c
index 09048eab484..3313bb74099 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -4,6 +4,7 @@
 #include "run-command.h"
 #include "commit.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
diff --git a/transport.c b/transport.c
index c6179b801e8..4f06ccbee05 100644
--- a/transport.c
+++ b/transport.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "alloc.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "transport.h"
 #include "hook.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 84e0d2e8afe..0ff4bbc6b96 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/upload-pack.c b/upload-pack.c
index eea9e6a6e8c..1155f795382 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/worktree.c b/worktree.c
index fe4345012c4..c2671b0cdf3 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "alloc.h"
+#include "environment.h"
 #include "gettext.h"
 #include "repository.h"
 #include "refs.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 12/16] treewide: remove cache.h inclusion due to environment.h changes
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (10 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 11/16] environment.h: move declarations for environment.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 13/16] setup.h: move declarations for setup.c functions from cache.h Elijah Newren via GitGitGadget
                     ` (4 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 csum-file.c            | 2 +-
 gettext.c              | 2 +-
 ls-refs.c              | 2 +-
 notes-utils.c          | 2 +-
 prompt.c               | 2 +-
 prune-packed.c         | 2 +-
 reachable.c            | 2 +-
 t/helper/test-bitmap.c | 2 +-
 trailer.c              | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/csum-file.c b/csum-file.c
index 2d22f80d901..82ae2973d30 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -7,7 +7,7 @@
  * files. Useful when you write a file that you want to be
  * able to verify hasn't been messed with afterwards.
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "progress.h"
 #include "csum-file.h"
 #include "wrapper.h"
diff --git a/gettext.c b/gettext.c
index 85d3d3424eb..5f348708300 100644
--- a/gettext.c
+++ b/gettext.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Ævar Arnfjörð Bjarmason
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/ls-refs.c b/ls-refs.c
index 12cbb40a198..b9f3e08ec3d 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/notes-utils.c b/notes-utils.c
index 8797271faf1..86552f31c4a 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
 #include "environment.h"
diff --git a/prompt.c b/prompt.c
index ba10813b313..3baa33f63d8 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
 #include "run-command.h"
diff --git a/prune-packed.c b/prune-packed.c
index 5a57072a7ac..58412b4fb91 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "object-store.h"
diff --git a/reachable.c b/reachable.c
index b0f85046e9c..55bb1143530 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index ff35f5999b3..5bb489882da 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,5 +1,5 @@
 #include "test-tool.h"
-#include "cache.h"
+#include "git-compat-util.h"
 #include "pack-bitmap.h"
 
 static int bitmap_list_commits(void)
diff --git a/trailer.c b/trailer.c
index 6a5091a3c46..a2c3ed6f28c 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 13/16] setup.h: move declarations for setup.c functions from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (11 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 12/16] treewide: remove cache.h inclusion due to environment.h changes Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 14/16] treewide: remove cache.h inclusion due to setup.h changes Elijah Newren via GitGitGadget
                     ` (3 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                                      |   1 +
 archive.c                                    |   1 +
 attr.c                                       |   1 +
 blame.c                                      |   1 +
 builtin/blame.c                              |   1 +
 builtin/bugreport.c                          |   1 +
 builtin/bundle.c                             |   1 +
 builtin/check-attr.c                         |   1 +
 builtin/check-ref-format.c                   |   1 +
 builtin/checkout-index.c                     |   1 +
 builtin/checkout.c                           |   1 +
 builtin/clean.c                              |   1 +
 builtin/clone.c                              |   1 +
 builtin/config.c                             |   1 +
 builtin/describe.c                           |   1 +
 builtin/diff-index.c                         |   1 +
 builtin/diff.c                               |   1 +
 builtin/difftool.c                           |   1 +
 builtin/gc.c                                 |   1 +
 builtin/grep.c                               |   1 +
 builtin/hash-object.c                        |   1 +
 builtin/help.c                               |   1 +
 builtin/index-pack.c                         |   1 +
 builtin/init-db.c                            |   1 +
 builtin/ls-files.c                           |   1 +
 builtin/merge-file.c                         |   1 +
 builtin/mv.c                                 |   1 +
 builtin/read-tree.c                          |   1 +
 builtin/reset.c                              |   1 +
 builtin/rev-parse.c                          |   1 +
 builtin/rm.c                                 |   1 +
 builtin/shortlog.c                           |   1 +
 builtin/sparse-checkout.c                    |   1 +
 builtin/stash.c                              |   1 +
 builtin/stripspace.c                         |   1 +
 builtin/submodule--helper.c                  |   1 +
 builtin/update-index.c                       |   1 +
 cache.h                                      | 163 ------------------
 commit.c                                     |   1 +
 common-main.c                                |   1 +
 config.c                                     |   1 +
 daemon.c                                     |   1 +
 diff.c                                       |   1 +
 dir.c                                        |   1 +
 environment.c                                |   1 +
 git.c                                        |   1 +
 http-fetch.c                                 |   1 +
 http-push.c                                  |   1 +
 imap-send.c                                  |   1 +
 line-log.c                                   |   1 +
 mailmap.c                                    |   1 +
 object-file.c                                |   1 +
 object-name.c                                |   1 +
 path.c                                       |   1 +
 pathspec.c                                   |   1 +
 refs.c                                       |   1 +
 refs/files-backend.c                         |   1 +
 remote-curl.c                                |   1 +
 remote.c                                     |   1 +
 repository.c                                 |   1 +
 revision.c                                   |   1 +
 scalar.c                                     |   1 +
 setup.c                                      |   1 +
 setup.h                                      | 168 +++++++++++++++++++
 submodule.c                                  |   1 +
 symlinks.c                                   |   1 +
 t/helper/test-advise.c                       |   1 +
 t/helper/test-bitmap.c                       |   1 +
 t/helper/test-bloom.c                        |   1 +
 t/helper/test-cache-tree.c                   |   1 +
 t/helper/test-config.c                       |   1 +
 t/helper/test-dump-cache-tree.c              |   2 +-
 t/helper/test-dump-fsmonitor.c               |   1 +
 t/helper/test-dump-split-index.c             |   1 +
 t/helper/test-dump-untracked-cache.c         |   1 +
 t/helper/test-fast-rebase.c                  |   1 +
 t/helper/test-fsmonitor-client.c             |   1 +
 t/helper/test-lazy-init-name-hash.c          |   1 +
 t/helper/test-match-trees.c                  |   1 +
 t/helper/test-oid-array.c                    |   1 +
 t/helper/test-oidmap.c                       |   1 +
 t/helper/test-oidtree.c                      |   1 +
 t/helper/test-pack-mtimes.c                  |   1 +
 t/helper/test-partial-clone.c                |   1 +
 t/helper/test-path-utils.c                   |   1 +
 t/helper/test-proc-receive.c                 |   1 +
 t/helper/test-reach.c                        |   1 +
 t/helper/test-read-cache.c                   |   1 +
 t/helper/test-read-graph.c                   |   1 +
 t/helper/test-read-midx.c                    |   1 +
 t/helper/test-ref-store.c                    |   1 +
 t/helper/test-repository.c                   |   1 +
 t/helper/test-revision-walking.c             |   1 +
 t/helper/test-scrap-cache-tree.c             |   1 +
 t/helper/test-serve-v2.c                     |   1 +
 t/helper/test-submodule-config.c             |   1 +
 t/helper/test-submodule-nested-repo-config.c |   1 +
 t/helper/test-submodule.c                    |   1 +
 t/helper/test-subprocess.c                   |   1 +
 t/helper/test-userdiff.c                     |   1 +
 t/helper/test-write-cache.c                  |   1 +
 trace.c                                      |   1 +
 unpack-trees.c                               |   1 +
 worktree.c                                   |   1 +
 wt-status.c                                  |   1 +
 105 files changed, 271 insertions(+), 164 deletions(-)
 create mode 100644 setup.h

diff --git a/apply.c b/apply.c
index a7c0bccb15c..caa2e0a3bc6 100644
--- a/apply.c
+++ b/apply.c
@@ -27,6 +27,7 @@
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
+#include "setup.h"
 #include "wrapper.h"
 
 struct gitdiff_data {
diff --git a/archive.c b/archive.c
index 7aeaaf368f4..cdce5b783a7 100644
--- a/archive.c
+++ b/archive.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "setup.h"
 #include "refs.h"
 #include "object-store.h"
 #include "commit.h"
diff --git a/attr.c b/attr.c
index 62127196cb1..2d8aeb8b58c 100644
--- a/attr.c
+++ b/attr.c
@@ -18,6 +18,7 @@
 #include "quote.h"
 #include "revision.h"
 #include "object-store.h"
+#include "setup.h"
 #include "thread-utils.h"
 
 const char git_attr__true[] = "(builtin)true";
diff --git a/blame.c b/blame.c
index b7cd849bb6b..838eb128f01 100644
--- a/blame.c
+++ b/blame.c
@@ -7,6 +7,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "setup.h"
 #include "tag.h"
 #include "blame.h"
 #include "alloc.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 9ec82edcbde..fb271bae70e 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -31,6 +31,7 @@
 #include "object-store.h"
 #include "blame.h"
 #include "refs.h"
+#include "setup.h"
 #include "tag.h"
 
 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 160590e4ef6..52955e1d389 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -8,6 +8,7 @@
 #include "hook.h"
 #include "hook-list.h"
 #include "diagnose.h"
+#include "setup.h"
 #include "wrapper.h"
 
 static void get_system_info(struct strbuf *sys_info)
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 9e2aecadf7d..e68fc83d943 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
+#include "setup.h"
 #include "strvec.h"
 #include "parse-options.h"
 #include "cache.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 5870c4683ab..ec37b8164af 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "quote.h"
+#include "setup.h"
 #include "parse-options.h"
 
 static int all_attrs;
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index fd0e5f86832..b0263467424 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -5,6 +5,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "builtin.h"
+#include "setup.h"
 #include "strbuf.h"
 
 static const char builtin_check_ref_format_usage[] =
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 828c0363f8a..7df673e3e70 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "setup.h"
 
 #define CHECKOUT_ALL 4
 static int nul_term_line;
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 5541e76c337..73b6e581f39 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -23,6 +23,7 @@
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "tree.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index fdcf62c5dfe..14c0d555eac 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "string-list.h"
 #include "quote.h"
 #include "column.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 15dc15408ed..34f46965b95 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -33,6 +33,7 @@
 #include "branch.h"
 #include "remote.h"
 #include "run-command.h"
+#include "setup.h"
 #include "connected.h"
 #include "packfile.h"
 #include "list-objects-filter-options.h"
diff --git a/builtin/config.c b/builtin/config.c
index cf994a216c0..fe79fb60c43 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -9,6 +9,7 @@
 #include "parse-options.h"
 #include "urlmatch.h"
 #include "quote.h"
+#include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 27c6670e934..43b62348bc7 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -15,6 +15,7 @@
 #include "revision.h"
 #include "diff.h"
 #include "hashmap.h"
+#include "setup.h"
 #include "strvec.h"
 #include "run-command.h"
 #include "object-store.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 35dc9b23eef..b9a19bb7d38 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -5,6 +5,7 @@
 #include "commit.h"
 #include "revision.h"
 #include "builtin.h"
+#include "setup.h"
 #include "submodule.h"
 
 static const char diff_cache_usage[] =
diff --git a/builtin/diff.c b/builtin/diff.c
index 20bdb6e6cec..3945683bfe4 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -19,6 +19,7 @@
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
+#include "setup.h"
 #include "submodule.h"
 #include "oid-array.h"
 
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 3613de6389f..176437d6da3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -28,6 +28,7 @@
 #include "object-store.h"
 #include "dir.h"
 #include "entry.h"
+#include "setup.h"
 #include "wrapper.h"
 
 static int trust_exit_code;
diff --git a/builtin/gc.c b/builtin/gc.c
index 525c5de5b27..a85f9e3ed3d 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -36,6 +36,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "hook.h"
+#include "setup.h"
 #include "wrapper.h"
 
 #define FAILED_RUN "failed to run %s"
diff --git a/builtin/grep.c b/builtin/grep.c
index 3c9c6b38031..b8ebf014f40 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -23,6 +23,7 @@
 #include "quote.h"
 #include "dir.h"
 #include "pathspec.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "object-store.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 7651a7a5f56..a2e160db026 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -14,6 +14,7 @@
 #include "quote.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
+#include "setup.h"
 
 /*
  * This is to create corrupt objects for debugging and as such it
diff --git a/builtin/help.c b/builtin/help.c
index 3fde5c4fd35..87333a02ec4 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -11,6 +11,7 @@
 #include "config-list.h"
 #include "help.h"
 #include "alias.h"
+#include "setup.h"
 
 #ifndef DEFAULT_HELP_FORMAT
 #define DEFAULT_HELP_FORMAT "man"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index fdce8f88724..823dc5aefb5 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -20,6 +20,7 @@
 #include "object-store.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
+#include "setup.h"
 #include "wrapper.h"
 
 static const char index_pack_usage[] =
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 2ebc9023f56..ba6e0b20fa5 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "exec-cmd.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 09deb752ab3..4a8de95ddc4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -20,6 +20,7 @@
 #include "string-list.h"
 #include "pathspec.h"
 #include "run-command.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index c0096ee0810..781818d08f5 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "config.h"
 #include "gettext.h"
+#include "setup.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "parse-options.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index c2dd42efbf2..b7c5ffbd8c7 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -16,6 +16,7 @@
 #include "cache-tree.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "submodule.h"
 #include "entry.h"
 
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index ec66008d07e..5f24453dcd7 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -19,6 +19,7 @@
 #include "builtin.h"
 #include "parse-options.h"
 #include "resolve-undo.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/reset.c b/builtin/reset.c
index b5dfce1159e..af2afc2c982 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -26,6 +26,7 @@
 #include "parse-options.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "dir.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index bba49d56b9f..3a5a2ee5b2d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -18,6 +18,7 @@
 #include "parse-options.h"
 #include "diff.h"
 #include "revision.h"
+#include "setup.h"
 #include "split-index.h"
 #include "submodule.h"
 #include "commit-reach.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 5982c3d8122..97775e4c4d0 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -15,6 +15,7 @@
 #include "tree-walk.h"
 #include "parse-options.h"
 #include "string-list.h"
+#include "setup.h"
 #include "submodule.h"
 #include "pathspec.h"
 
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 31f81c25ea2..59d9c440fb5 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -9,6 +9,7 @@
 #include "revision.h"
 #include "utf8.h"
 #include "mailmap.h"
+#include "setup.h"
 #include "shortlog.h"
 #include "parse-options.h"
 #include "trailer.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index f6a120c7c45..512df0f8f54 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -16,6 +16,7 @@
 #include "unpack-trees.h"
 #include "wt-status.h"
 #include "quote.h"
+#include "setup.h"
 #include "sparse-index.h"
 #include "worktree.h"
 
diff --git a/builtin/stash.c b/builtin/stash.c
index 94f81d75d03..30d547fff1f 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -18,6 +18,7 @@
 #include "entry.h"
 #include "rerere.h"
 #include "revision.h"
+#include "setup.h"
 #include "log-tree.h"
 #include "diffcore.h"
 #include "exec-cmd.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index d8e61459333..53930458ffa 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "strbuf.h"
 
 static void comment_lines(struct strbuf *buf)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 2bf2a1a8be5..3cb4a3ce217 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -12,6 +12,7 @@
 #include "quote.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "setup.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "string-list.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 4642afaeb77..f97f8d4c9d5 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -20,6 +20,7 @@
 #include "parse-options.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "setup.h"
 #include "split-index.h"
 #include "fsmonitor.h"
 
diff --git a/cache.h b/cache.h
index 720c88f9fd6..bffedd240e7 100644
--- a/cache.h
+++ b/cache.h
@@ -452,67 +452,6 @@ static inline enum object_type object_type(unsigned int mode)
 		OBJ_BLOB;
 }
 
-int is_inside_git_dir(void);
-int is_inside_work_tree(void);
-int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
-int get_common_dir(struct strbuf *sb, const char *gitdir);
-
-/*
- * Return true if the given path is a git directory; note that this _just_
- * looks at the directory itself. If you want to know whether "foo/.git"
- * is a repository, you must feed that path, not just "foo".
- */
-int is_git_directory(const char *path);
-
-/*
- * Return 1 if the given path is the root of a git repository or
- * submodule, else 0. Will not return 1 for bare repositories with the
- * exception of creating a bare repository in "foo/.git" and calling
- * is_git_repository("foo").
- *
- * If we run into read errors, we err on the side of saying "yes, it is",
- * as we usually consider sub-repos precious, and would prefer to err on the
- * side of not disrupting or deleting them.
- */
-int is_nonbare_repository_dir(struct strbuf *path);
-
-#define READ_GITFILE_ERR_STAT_FAILED 1
-#define READ_GITFILE_ERR_NOT_A_FILE 2
-#define READ_GITFILE_ERR_OPEN_FAILED 3
-#define READ_GITFILE_ERR_READ_FAILED 4
-#define READ_GITFILE_ERR_INVALID_FORMAT 5
-#define READ_GITFILE_ERR_NO_PATH 6
-#define READ_GITFILE_ERR_NOT_A_REPO 7
-#define READ_GITFILE_ERR_TOO_LARGE 8
-void read_gitfile_error_die(int error_code, const char *path, const char *dir);
-const char *read_gitfile_gently(const char *path, int *return_error_code);
-#define read_gitfile(path) read_gitfile_gently((path), NULL)
-const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
-#define resolve_gitdir(path) resolve_gitdir_gently((path), NULL)
-
-void setup_work_tree(void);
-/*
- * Find the commondir and gitdir of the repository that contains the current
- * working directory, without changing the working directory or other global
- * state. The result is appended to commondir and gitdir.  If the discovered
- * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
- * both have the same result appended to the buffer.  The return value is
- * either 0 upon success and non-zero if no repository was found.
- */
-int discover_git_directory(struct strbuf *commondir,
-			   struct strbuf *gitdir);
-const char *setup_git_directory_gently(int *);
-const char *setup_git_directory(void);
-char *prefix_path(const char *prefix, int len, const char *path);
-char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
-
-int check_filename(const char *prefix, const char *name);
-void verify_filename(const char *prefix,
-		     const char *name,
-		     int diagnose_misspelt_rev);
-void verify_non_filename(const char *prefix, const char *name);
-int path_inside_repo(const char *prefix, const char *path);
-
 #define INIT_DB_QUIET 0x0001
 #define INIT_DB_EXIST_OK 0x0002
 
@@ -521,9 +460,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *initial_branch, unsigned int flags);
 void initialize_repository_version(int hash_algo, int reinit);
 
-void sanitize_stdfds(void);
-int daemonize(void);
-
 /* Initialize and use the cache information */
 struct lock_file;
 void preload_index(struct index_state *index,
@@ -807,79 +743,6 @@ enum fsync_method {
 
 extern enum fsync_method fsync_method;
 
-/*
- * GIT_REPO_VERSION is the version we write by default. The
- * _READ variant is the highest number we know how to
- * handle.
- */
-#define GIT_REPO_VERSION 0
-#define GIT_REPO_VERSION_READ 1
-
-/*
- * You _have_ to initialize a `struct repository_format` using
- * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`.
- */
-struct repository_format {
-	int version;
-	int precious_objects;
-	char *partial_clone; /* value of extensions.partialclone */
-	int worktree_config;
-	int is_bare;
-	int hash_algo;
-	int sparse_index;
-	char *work_tree;
-	struct string_list unknown_extensions;
-	struct string_list v1_only_extensions;
-};
-
-/*
- * Always use this to initialize a `struct repository_format`
- * to a well-defined, default state before calling
- * `read_repository()`.
- */
-#define REPOSITORY_FORMAT_INIT \
-{ \
-	.version = -1, \
-	.is_bare = -1, \
-	.hash_algo = GIT_HASH_SHA1, \
-	.unknown_extensions = STRING_LIST_INIT_DUP, \
-	.v1_only_extensions = STRING_LIST_INIT_DUP, \
-}
-
-/*
- * Read the repository format characteristics from the config file "path" into
- * "format" struct. Returns the numeric version. On error, or if no version is
- * found in the configuration, -1 is returned, format->version is set to -1,
- * and all other fields in the struct are set to the default configuration
- * (REPOSITORY_FORMAT_INIT). Always initialize the struct using
- * REPOSITORY_FORMAT_INIT before calling this function.
- */
-int read_repository_format(struct repository_format *format, const char *path);
-
-/*
- * Free the memory held onto by `format`, but not the struct itself.
- * (No need to use this after `read_repository_format()` fails.)
- */
-void clear_repository_format(struct repository_format *format);
-
-/*
- * Verify that the repository described by repository_format is something we
- * can read. If it is, return 0. Otherwise, return -1, and "err" will describe
- * any errors encountered.
- */
-int verify_repository_format(const struct repository_format *format,
-			     struct strbuf *err);
-
-/*
- * Check the repository format version in the path found in get_git_dir(),
- * and die if it is a version we don't understand. Generally one would
- * set_git_dir() before calling this, and use it only for "are we in a valid
- * repo?".
- *
- * If successful and fmt is not NULL, fill fmt with data.
- */
-void check_repository_format(struct repository_format *fmt);
-
 #define MTIME_CHANGED	0x0001
 #define CTIME_CHANGED	0x0002
 #define OWNER_CHANGED	0x0004
@@ -908,23 +771,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id
 int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
 #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
-/*
- * NOTE NOTE NOTE!!
- *
- * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must
- * not be changed. Old repositories have core.sharedrepository written in
- * numeric format, and therefore these values are preserved for compatibility
- * reasons.
- */
-enum sharedrepo {
-	PERM_UMASK          = 0,
-	OLD_PERM_GROUP      = 1,
-	OLD_PERM_EVERYBODY  = 2,
-	PERM_GROUP          = 0660,
-	PERM_EVERYBODY      = 0664
-};
-int git_config_perm(const char *var, const char *value);
-
 /*
  * Create the directory containing the named path, using care to be
  * somewhat safe against races. Return one of the scld_error values to
@@ -1283,15 +1129,6 @@ int ws_blank_line(const char *line, int len);
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
 
-/* setup.c */
-struct startup_info {
-	int have_repository;
-	const char *prefix;
-	const char *original_cwd;
-};
-extern struct startup_info *startup_info;
-extern const char *tmp_original_cwd;
-
 /* merge.c */
 struct commit_list;
 int try_merge_command(struct repository *r,
diff --git a/commit.c b/commit.c
index f88fc5e1a2c..3868f047f1b 100644
--- a/commit.c
+++ b/commit.c
@@ -23,6 +23,7 @@
 #include "refs.h"
 #include "commit-reach.h"
 #include "run-command.h"
+#include "setup.h"
 #include "shallow.h"
 #include "hook.h"
 
diff --git a/common-main.c b/common-main.c
index 184d1534d2d..b83cb5cf066 100644
--- a/common-main.c
+++ b/common-main.c
@@ -2,6 +2,7 @@
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "attr.h"
+#include "setup.h"
 
 /*
  * Many parts of Git have subprograms communicate via pipe, expect the
diff --git a/config.c b/config.c
index 5b1a5d52052..03a4fcaba5b 100644
--- a/config.c
+++ b/config.c
@@ -27,6 +27,7 @@
 #include "color.h"
 #include "replace-object.h"
 #include "refs.h"
+#include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/daemon.c b/daemon.c
index b56a8f9717d..db8a31a6ea2 100644
--- a/daemon.c
+++ b/daemon.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "pkt-line.h"
 #include "run-command.h"
+#include "setup.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "wrapper.h"
diff --git a/diff.c b/diff.c
index dcf1a940942..b858e59c5ae 100644
--- a/diff.c
+++ b/diff.c
@@ -33,6 +33,7 @@
 #include "help.h"
 #include "promisor-remote.h"
 #include "dir.h"
+#include "setup.h"
 #include "strmap.h"
 #include "wrapper.h"
 
diff --git a/dir.c b/dir.c
index 06f8aa3c01b..4cc2b1ead47 100644
--- a/dir.c
+++ b/dir.c
@@ -21,6 +21,7 @@
 #include "varint.h"
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "wrapper.h"
 
diff --git a/environment.c b/environment.c
index bf02f3cf487..649d16ac27c 100644
--- a/environment.c
+++ b/environment.c
@@ -22,6 +22,7 @@
 #include "replace-object.h"
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
+#include "setup.h"
 #include "shallow.h"
 #include "wrapper.h"
 
diff --git a/git.c b/git.c
index b24c105e83f..77f920a6f6f 100644
--- a/git.c
+++ b/git.c
@@ -7,6 +7,7 @@
 #include "run-command.h"
 #include "alias.h"
 #include "replace-object.h"
+#include "setup.h"
 #include "shallow.h"
 
 #define RUN_SETUP		(1<<0)
diff --git a/http-fetch.c b/http-fetch.c
index 454933351b2..c874d3402dd 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -5,6 +5,7 @@
 #include "hex.h"
 #include "http.h"
 #include "walker.h"
+#include "setup.h"
 #include "strvec.h"
 #include "urlmatch.h"
 #include "trace2.h"
diff --git a/http-push.c b/http-push.c
index 40373bc4863..e73864b51f5 100644
--- a/http-push.c
+++ b/http-push.c
@@ -12,6 +12,7 @@
 #include "exec-cmd.h"
 #include "remote.h"
 #include "list-objects.h"
+#include "setup.h"
 #include "sigchain.h"
 #include "strvec.h"
 #include "packfile.h"
diff --git a/imap-send.c b/imap-send.c
index aa5b2f252d2..a62424e90a4 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -28,6 +28,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "setup.h"
 #include "wrapper.h"
 #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
 typedef void *SSL;
diff --git a/line-log.c b/line-log.c
index 6e7fc4b2e0b..84c8093c517 100644
--- a/line-log.c
+++ b/line-log.c
@@ -16,6 +16,7 @@
 #include "graph.h"
 #include "userdiff.h"
 #include "line-log.h"
+#include "setup.h"
 #include "strvec.h"
 #include "bloom.h"
 
diff --git a/mailmap.c b/mailmap.c
index 2c6e9b238dd..c24a16eaf48 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -3,6 +3,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-store.h"
+#include "setup.h"
 
 #define DEBUG_MAILMAP 0
 #if DEBUG_MAILMAP
diff --git a/object-file.c b/object-file.c
index 3da6cd68861..05fff230f73 100644
--- a/object-file.c
+++ b/object-file.c
@@ -37,6 +37,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "promisor-remote.h"
+#include "setup.h"
 #include "submodule.h"
 #include "fsck.h"
 #include "wrapper.h"
diff --git a/object-name.c b/object-name.c
index 3b0ce8ef05a..ce973e01505 100644
--- a/object-name.c
+++ b/object-name.c
@@ -15,6 +15,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "repository.h"
+#include "setup.h"
 #include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
diff --git a/path.c b/path.c
index 5d5a15c13d6..a1702434979 100644
--- a/path.c
+++ b/path.c
@@ -11,6 +11,7 @@
 #include "string-list.h"
 #include "dir.h"
 #include "worktree.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "path.h"
 #include "packfile.h"
diff --git a/pathspec.c b/pathspec.c
index 5fb7b5f26c9..6972d515f0c 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
+#include "setup.h"
 #include "strvec.h"
 #include "quote.h"
 
diff --git a/refs.c b/refs.c
index 04520e5a6b8..21b317e8153 100644
--- a/refs.c
+++ b/refs.c
@@ -22,6 +22,7 @@
 #include "worktree.h"
 #include "strvec.h"
 #include "repository.h"
+#include "setup.h"
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0c3138ede8f..d2b8925ebd0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -14,6 +14,7 @@
 #include "../object.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
+#include "../setup.h"
 #include "../worktree.h"
 #include "../wrapper.h"
 
diff --git a/remote-curl.c b/remote-curl.c
index eb382a1e35d..260ea200bb0 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -18,6 +18,7 @@
 #include "credential.h"
 #include "oid-array.h"
 #include "send-pack.h"
+#include "setup.h"
 #include "protocol.h"
 #include "quote.h"
 #include "transport.h"
diff --git a/remote.c b/remote.c
index aeca3ff8136..c29e2f52981 100644
--- a/remote.c
+++ b/remote.c
@@ -15,6 +15,7 @@
 #include "revision.h"
 #include "dir.h"
 #include "tag.h"
+#include "setup.h"
 #include "string-list.h"
 #include "strvec.h"
 #include "commit-reach.h"
diff --git a/repository.c b/repository.c
index 4412f633224..f6d9f5db08e 100644
--- a/repository.c
+++ b/repository.c
@@ -11,6 +11,7 @@
 #include "object.h"
 #include "lockfile.h"
 #include "remote.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "sparse-index.h"
 #include "promisor-remote.h"
diff --git a/revision.c b/revision.c
index 53fdeef0787..f98691a3531 100644
--- a/revision.c
+++ b/revision.c
@@ -29,6 +29,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "setup.h"
 #include "strvec.h"
 #include "commit-reach.h"
 #include "commit-graph.h"
diff --git a/scalar.c b/scalar.c
index fe61a3ebdd7..27635658c01 100644
--- a/scalar.c
+++ b/scalar.c
@@ -15,6 +15,7 @@
 #include "dir.h"
 #include "packfile.h"
 #include "help.h"
+#include "setup.h"
 
 static void setup_enlistment_directory(int argc, const char **argv,
 				       const char * const *usagestr,
diff --git a/setup.c b/setup.c
index cfdc849a78c..6c5b85e96c1 100644
--- a/setup.c
+++ b/setup.c
@@ -5,6 +5,7 @@
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
+#include "setup.h"
 #include "string-list.h"
 #include "chdir-notify.h"
 #include "promisor-remote.h"
diff --git a/setup.h b/setup.h
new file mode 100644
index 00000000000..4c1ca9d0c94
--- /dev/null
+++ b/setup.h
@@ -0,0 +1,168 @@
+#ifndef SETUP_H
+#define SETUP_H
+
+#include "string-list.h"
+
+int is_inside_git_dir(void);
+int is_inside_work_tree(void);
+int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
+int get_common_dir(struct strbuf *sb, const char *gitdir);
+
+/*
+ * Return true if the given path is a git directory; note that this _just_
+ * looks at the directory itself. If you want to know whether "foo/.git"
+ * is a repository, you must feed that path, not just "foo".
+ */
+int is_git_directory(const char *path);
+
+/*
+ * Return 1 if the given path is the root of a git repository or
+ * submodule, else 0. Will not return 1 for bare repositories with the
+ * exception of creating a bare repository in "foo/.git" and calling
+ * is_git_repository("foo").
+ *
+ * If we run into read errors, we err on the side of saying "yes, it is",
+ * as we usually consider sub-repos precious, and would prefer to err on the
+ * side of not disrupting or deleting them.
+ */
+int is_nonbare_repository_dir(struct strbuf *path);
+
+#define READ_GITFILE_ERR_STAT_FAILED 1
+#define READ_GITFILE_ERR_NOT_A_FILE 2
+#define READ_GITFILE_ERR_OPEN_FAILED 3
+#define READ_GITFILE_ERR_READ_FAILED 4
+#define READ_GITFILE_ERR_INVALID_FORMAT 5
+#define READ_GITFILE_ERR_NO_PATH 6
+#define READ_GITFILE_ERR_NOT_A_REPO 7
+#define READ_GITFILE_ERR_TOO_LARGE 8
+void read_gitfile_error_die(int error_code, const char *path, const char *dir);
+const char *read_gitfile_gently(const char *path, int *return_error_code);
+#define read_gitfile(path) read_gitfile_gently((path), NULL)
+const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);
+#define resolve_gitdir(path) resolve_gitdir_gently((path), NULL)
+
+void setup_work_tree(void);
+/*
+ * Find the commondir and gitdir of the repository that contains the current
+ * working directory, without changing the working directory or other global
+ * state. The result is appended to commondir and gitdir.  If the discovered
+ * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
+ * both have the same result appended to the buffer.  The return value is
+ * either 0 upon success and non-zero if no repository was found.
+ */
+int discover_git_directory(struct strbuf *commondir,
+			   struct strbuf *gitdir);
+const char *setup_git_directory_gently(int *);
+const char *setup_git_directory(void);
+char *prefix_path(const char *prefix, int len, const char *path);
+char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
+
+int check_filename(const char *prefix, const char *name);
+void verify_filename(const char *prefix,
+		     const char *name,
+		     int diagnose_misspelt_rev);
+void verify_non_filename(const char *prefix, const char *name);
+int path_inside_repo(const char *prefix, const char *path);
+
+void sanitize_stdfds(void);
+int daemonize(void);
+
+/*
+ * GIT_REPO_VERSION is the version we write by default. The
+ * _READ variant is the highest number we know how to
+ * handle.
+ */
+#define GIT_REPO_VERSION 0
+#define GIT_REPO_VERSION_READ 1
+
+/*
+ * You _have_ to initialize a `struct repository_format` using
+ * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`.
+ */
+struct repository_format {
+	int version;
+	int precious_objects;
+	char *partial_clone; /* value of extensions.partialclone */
+	int worktree_config;
+	int is_bare;
+	int hash_algo;
+	int sparse_index;
+	char *work_tree;
+	struct string_list unknown_extensions;
+	struct string_list v1_only_extensions;
+};
+
+/*
+ * Always use this to initialize a `struct repository_format`
+ * to a well-defined, default state before calling
+ * `read_repository()`.
+ */
+#define REPOSITORY_FORMAT_INIT \
+{ \
+	.version = -1, \
+	.is_bare = -1, \
+	.hash_algo = GIT_HASH_SHA1, \
+	.unknown_extensions = STRING_LIST_INIT_DUP, \
+	.v1_only_extensions = STRING_LIST_INIT_DUP, \
+}
+
+/*
+ * Read the repository format characteristics from the config file "path" into
+ * "format" struct. Returns the numeric version. On error, or if no version is
+ * found in the configuration, -1 is returned, format->version is set to -1,
+ * and all other fields in the struct are set to the default configuration
+ * (REPOSITORY_FORMAT_INIT). Always initialize the struct using
+ * REPOSITORY_FORMAT_INIT before calling this function.
+ */
+int read_repository_format(struct repository_format *format, const char *path);
+
+/*
+ * Free the memory held onto by `format`, but not the struct itself.
+ * (No need to use this after `read_repository_format()` fails.)
+ */
+void clear_repository_format(struct repository_format *format);
+
+/*
+ * Verify that the repository described by repository_format is something we
+ * can read. If it is, return 0. Otherwise, return -1, and "err" will describe
+ * any errors encountered.
+ */
+int verify_repository_format(const struct repository_format *format,
+			     struct strbuf *err);
+
+/*
+ * Check the repository format version in the path found in get_git_dir(),
+ * and die if it is a version we don't understand. Generally one would
+ * set_git_dir() before calling this, and use it only for "are we in a valid
+ * repo?".
+ *
+ * If successful and fmt is not NULL, fill fmt with data.
+ */
+void check_repository_format(struct repository_format *fmt);
+
+/*
+ * NOTE NOTE NOTE!!
+ *
+ * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must
+ * not be changed. Old repositories have core.sharedrepository written in
+ * numeric format, and therefore these values are preserved for compatibility
+ * reasons.
+ */
+enum sharedrepo {
+	PERM_UMASK          = 0,
+	OLD_PERM_GROUP      = 1,
+	OLD_PERM_EVERYBODY  = 2,
+	PERM_GROUP          = 0660,
+	PERM_EVERYBODY      = 0664
+};
+int git_config_perm(const char *var, const char *value);
+
+struct startup_info {
+	int have_repository;
+	const char *prefix;
+	const char *original_cwd;
+};
+extern struct startup_info *startup_info;
+extern const char *tmp_original_cwd;
+
+#endif /* SETUP_H */
diff --git a/submodule.c b/submodule.c
index acf030b95e4..75e0d45cbcb 100644
--- a/submodule.c
+++ b/submodule.c
@@ -26,6 +26,7 @@
 #include "parse-options.h"
 #include "object-store.h"
 #include "commit-reach.h"
+#include "setup.h"
 #include "shallow.h"
 
 static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
diff --git a/symlinks.c b/symlinks.c
index c35c8d4408d..27ecc93693b 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "gettext.h"
+#include "setup.h"
 
 static int threaded_check_leading_path(struct cache_def *cache, const char *name,
 				       int len, int warn_on_lstat_err);
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index cb881139f73..4e6ed30afa1 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "advice.h"
 #include "config.h"
+#include "setup.h"
 
 int cmd__advise_if_enabled(int argc, const char **argv)
 {
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index 5bb489882da..af43ee1cb5e 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "git-compat-util.h"
 #include "pack-bitmap.h"
+#include "setup.h"
 
 static int bitmap_list_commits(void)
 {
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 127f134a2a6..e5754b8da62 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "test-tool.h"
 #include "commit.h"
+#include "setup.h"
 
 static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
 
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 8b7a8fce1ee..cdaf5046f5a 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -6,6 +6,7 @@
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
+#include "setup.h"
 
 static char const * const test_cache_tree_usage[] = {
 	N_("test-tool cache-tree <options> (control|prime|update)"),
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 4ba9eb65606..5877188f3ad 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "setup.h"
 #include "string-list.h"
 
 /*
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 92dfc1aa8c4..715aabfbae7 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
-
+#include "setup.h"
 
 static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
 {
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 975f0ac8905..7e9de296db3 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "setup.h"
 
 int cmd__dump_fsmonitor(int ac, const char **av)
 {
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 813d0a38fae..289a01c10ac 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "hex.h"
+#include "setup.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
 
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index af953fabe87..415f55f31da 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "hex.h"
+#include "setup.h"
 
 static int compare_untracked(const void *a_, const void *b_)
 {
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 627a6bdc3d0..e402c35a702 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -23,6 +23,7 @@
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
+#include "setup.h"
 #include "strvec.h"
 #include "tree.h"
 
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index c43fc976b82..a37236cd0a6 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "parse-options.h"
 #include "fsmonitor-ipc.h"
+#include "setup.h"
 #include "thread-utils.h"
 #include "trace2.h"
 #include "wrapper.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 2b678a45793..06ce3a47ccf 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "environment.h"
 #include "parse-options.h"
+#include "setup.h"
 
 static int single;
 static int multi;
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index 04bc2563f3e..64705734dfe 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "hex.h"
+#include "setup.h"
 #include "tree.h"
 
 int cmd__match_trees(int ac, const char **av)
diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
index 0906993ad59..fd6f73ea03b 100644
--- a/t/helper/test-oid-array.c
+++ b/t/helper/test-oid-array.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "oid-array.h"
+#include "setup.h"
 
 static int print_oid(const struct object_id *oid, void *data)
 {
diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c
index 883d40efd45..f1b3dbe376b 100644
--- a/t/helper/test-oidmap.c
+++ b/t/helper/test-oidmap.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "oidmap.h"
+#include "setup.h"
 #include "strbuf.h"
 
 /* key is an oid and value is a name (could be a refname for example) */
diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
index 0b82431a70f..edcb7e9f448 100644
--- a/t/helper/test-oidtree.c
+++ b/t/helper/test-oidtree.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "oidtree.h"
+#include "setup.h"
 
 static enum cb_next print_oid(const struct object_id *oid, void *data)
 {
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 0e53dee9e57..75ca1505a37 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -5,6 +5,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pack-mtimes.h"
+#include "setup.h"
 
 static void dump_mtimes(struct packed_git *p)
 {
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index da17fd37eb1..cce496944ac 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -3,6 +3,7 @@
 #include "test-tool.h"
 #include "repository.h"
 #include "object-store.h"
+#include "setup.h"
 
 /*
  * Prints the size of the object corresponding to the given hash in a specific
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index cc266e3ec09..4f5ac2fadce 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "abspath.h"
 #include "environment.h"
+#include "setup.h"
 #include "string-list.h"
 #include "utf8.h"
 
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index 7e12d4f9aa2..7c8de7b562a 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "parse-options.h"
 #include "pkt-line.h"
+#include "setup.h"
 #include "sigchain.h"
 #include "test-tool.h"
 
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 09c711038ce..91bb2dec1df 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -8,6 +8,7 @@
 #include "hex.h"
 #include "parse-options.h"
 #include "ref-filter.h"
+#include "setup.h"
 #include "string-list.h"
 #include "tag.h"
 
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 84818363d5b..a4c24d0e421 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "setup.h"
 #include "wrapper.h"
 
 int cmd__read_cache(int argc, const char **argv)
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 98b73bb8f25..e21b0805f3c 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -4,6 +4,7 @@
 #include "repository.h"
 #include "object-store.h"
 #include "bloom.h"
+#include "setup.h"
 
 int cmd__read_graph(int argc, const char **argv)
 {
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 0a883cdf26b..05c4f2b2625 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -5,6 +5,7 @@
 #include "repository.h"
 #include "object-store.h"
 #include "pack-bitmap.h"
+#include "setup.h"
 
 static int read_midx_file(const char *object_dir, int show_objects)
 {
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 1745b088b7c..8717b95e84f 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "hex.h"
 #include "refs.h"
+#include "setup.h"
 #include "worktree.h"
 #include "object-store.h"
 #include "repository.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index c444775eb0f..6774f6245f0 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -8,6 +8,7 @@
 #include "object-store.h"
 #include "object.h"
 #include "repository.h"
+#include "setup.h"
 #include "tree.h"
 
 static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index 4a45d5bac2a..f2df4334063 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
+#include "setup.h"
 
 static void print_commit(struct commit *commit)
 {
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index a26107ed70a..15b7688774c 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "lockfile.h"
+#include "setup.h"
 #include "tree.h"
 #include "cache-tree.h"
 
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 497d72058de..7d590ab7227 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "serve.h"
+#include "setup.h"
 
 static char const * const serve_usage[] = {
 	N_("test-tool serve-v2 [<options>]"),
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 22a41c40926..256bfa6e9e1 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index a3848a8b668..aaffd422d6e 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "setup.h"
 #include "submodule-config.h"
 
 static void die_usage(const char **argv, const char *msg)
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index e060cc62268..f18ca46dce4 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "parse-options.h"
 #include "remote.h"
+#include "setup.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c
index ff22f2fa2c5..65a355cc590 100644
--- a/t/helper/test-subprocess.c
+++ b/t/helper/test-subprocess.c
@@ -1,6 +1,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "run-command.h"
+#include "setup.h"
 
 int cmd__subprocess(int argc, const char **argv)
 {
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index a2b56b9cae5..0cd7ee12b7e 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "setup.h"
 #include "userdiff.h"
 #include "config.h"
 
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index 7d45cd61e82..a93417ed3a9 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "lockfile.h"
+#include "setup.h"
 
 int cmd__write_cache(int argc, const char **argv)
 {
diff --git a/trace.c b/trace.c
index 9c85b71ec6a..81318a2455d 100644
--- a/trace.c
+++ b/trace.c
@@ -25,6 +25,7 @@
 #include "abspath.h"
 #include "environment.h"
 #include "quote.h"
+#include "setup.h"
 #include "wrapper.h"
 
 struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
diff --git a/unpack-trees.c b/unpack-trees.c
index 0ff4bbc6b96..a26fda3493f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -22,6 +22,7 @@
 #include "promisor-remote.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "setup.h"
 
 /*
  * Error messages expected by scripts out of plumbing commands such as
diff --git a/worktree.c b/worktree.c
index c2671b0cdf3..7f0f04eab56 100644
--- a/worktree.c
+++ b/worktree.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "repository.h"
 #include "refs.h"
+#include "setup.h"
 #include "strbuf.h"
 #include "worktree.h"
 #include "dir.h"
diff --git a/wt-status.c b/wt-status.c
index 106e46480a1..16e0df5736f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -16,6 +16,7 @@
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "setup.h"
 #include "strbuf.h"
 #include "utf8.h"
 #include "worktree.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 14/16] treewide: remove cache.h inclusion due to setup.h changes
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (12 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 13/16] setup.h: move declarations for setup.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h Elijah Newren via GitGitGadget
                     ` (2 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

By moving several declarations to setup.h, the previous patch made it
possible to remove the include of cache.h in several source files.  Do
so.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 line-log.c                                   | 1 -
 path.c                                       | 2 +-
 t/helper/test-advise.c                       | 1 -
 t/helper/test-bloom.c                        | 3 +--
 t/helper/test-config.c                       | 1 -
 t/helper/test-pack-mtimes.c                  | 1 -
 t/helper/test-partial-clone.c                | 3 +--
 t/helper/test-proc-receive.c                 | 3 +--
 t/helper/test-read-graph.c                   | 1 -
 t/helper/test-ref-store.c                    | 1 -
 t/helper/test-repository.c                   | 1 -
 t/helper/test-revision-walking.c             | 1 -
 t/helper/test-serve-v2.c                     | 1 -
 t/helper/test-submodule-nested-repo-config.c | 1 -
 t/helper/test-submodule.c                    | 1 -
 t/helper/test-subprocess.c                   | 1 -
 t/helper/test-userdiff.c                     | 1 -
 worktree.c                                   | 2 +-
 18 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/line-log.c b/line-log.c
index 84c8093c517..10c19daec4a 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1,7 +1,6 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "line-range.h"
-#include "cache.h"
 #include "hex.h"
 #include "tag.h"
 #include "blob.h"
diff --git a/path.c b/path.c
index a1702434979..dff215ac693 100644
--- a/path.c
+++ b/path.c
@@ -1,7 +1,7 @@
 /*
  * Utilities for paths and pathnames
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index 4e6ed30afa1..8a3fd0009a0 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "advice.h"
 #include "config.h"
 #include "setup.h"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index e5754b8da62..d2b30d644da 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -1,7 +1,6 @@
-#include "cache.h"
+#include "test-tool.h"
 #include "bloom.h"
 #include "hex.h"
-#include "test-tool.h"
 #include "commit.h"
 #include "setup.h"
 
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 5877188f3ad..32d170ec303 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "config.h"
 #include "setup.h"
 #include "string-list.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 75ca1505a37..0f3fbeec532 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "strbuf.h"
 #include "object-store.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index cce496944ac..362bd64a4c2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "hex.h"
 #include "test-tool.h"
+#include "hex.h"
 #include "repository.h"
 #include "object-store.h"
 #include "setup.h"
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index 7c8de7b562a..f30022d2225 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "test-tool.h"
 #include "connect.h"
 #include "hex.h"
 #include "parse-options.h"
 #include "pkt-line.h"
 #include "setup.h"
 #include "sigchain.h"
-#include "test-tool.h"
 
 static const char *proc_receive_usage[] = {
 	"test-tool proc-receive [<options>]",
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index e21b0805f3c..78965a6ebdc 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "commit-graph.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 8717b95e84f..d1192c8c039 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "refs.h"
 #include "setup.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 6774f6245f0..bafd2a5bf95 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "commit-graph.h"
 #include "commit.h"
 #include "config.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index f2df4334063..7750afb2866 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -9,7 +9,6 @@
  */
 
 #include "test-tool.h"
-#include "cache.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 7d590ab7227..054cbcf5d83 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "serve.h"
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index aaffd422d6e..d31f5e48ab5 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "setup.h"
 #include "submodule-config.h"
 
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index f18ca46dce4..0e34581b209 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -1,6 +1,5 @@
 #include "test-tool.h"
 #include "test-tool-utils.h"
-#include "cache.h"
 #include "parse-options.h"
 #include "remote.h"
 #include "setup.h"
diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c
index 65a355cc590..c344f1694df 100644
--- a/t/helper/test-subprocess.c
+++ b/t/helper/test-subprocess.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "run-command.h"
 #include "setup.h"
 
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index 0cd7ee12b7e..680124a6760 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "setup.h"
 #include "userdiff.h"
 #include "config.h"
diff --git a/worktree.c b/worktree.c
index 7f0f04eab56..b5ee71c5ebd 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "environment.h"
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (13 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 14/16] treewide: remove cache.h inclusion due to setup.h changes Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21  6:26   ` [PATCH v2 16/16] csum-file.h: remove unnecessary inclusion of cache.h Elijah Newren via GitGitGadget
  2023-03-21 21:56   ` [PATCH v2 00/16] Header cleanups Jonathan Tan
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 archive-tar.c              |  1 +
 archive-zip.c              |  1 +
 builtin/blame.c            |  1 +
 builtin/cat-file.c         |  1 +
 builtin/check-attr.c       |  1 +
 builtin/check-ignore.c     |  1 +
 builtin/check-mailmap.c    |  1 +
 builtin/credential-cache.c |  1 +
 builtin/credential-store.c |  1 +
 builtin/grep.c             |  1 +
 builtin/hash-object.c      |  1 +
 builtin/log.c              |  1 +
 builtin/notes.c            |  1 +
 builtin/send-pack.c        |  1 +
 builtin/stripspace.c       |  1 +
 builtin/tag.c              |  1 +
 builtin/update-index.c     |  1 +
 bundle.c                   |  1 +
 cache.h                    | 74 ------------------------------------
 config.c                   |  1 +
 csum-file.h                |  1 +
 diagnose.c                 |  1 +
 environment.c              |  1 +
 http-backend.c             |  1 +
 log-tree.c                 |  1 +
 pkt-line.c                 |  1 +
 refs/files-backend.c       |  1 +
 refs/packed-backend.c      |  1 +
 remote-curl.c              |  1 +
 send-pack.c                |  3 +-
 sideband.c                 |  1 +
 t/helper/test-pkt-line.c   |  3 +-
 upload-pack.c              |  1 +
 write-or-die.c             |  3 +-
 write-or-die.h             | 78 ++++++++++++++++++++++++++++++++++++++
 35 files changed, 114 insertions(+), 77 deletions(-)
 create mode 100644 write-or-die.h

diff --git a/archive-tar.c b/archive-tar.c
index 16ee133bbf5..497dad0b3af 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,6 +11,7 @@
 #include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
+#include "write-or-die.h"
 
 #define RECORDSIZE	(512)
 #define BLOCKSIZE	(RECORDSIZE * 20)
diff --git a/archive-zip.c b/archive-zip.c
index c02dc33e406..e6f5c10a14f 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -10,6 +10,7 @@
 #include "utf8.h"
 #include "object-store.h"
 #include "userdiff.h"
+#include "write-or-die.h"
 #include "xdiff-interface.h"
 #include "date.h"
 
diff --git a/builtin/blame.c b/builtin/blame.c
index fb271bae70e..0a3cc019059 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -33,6 +33,7 @@
 #include "refs.h"
 #include "setup.h"
 #include "tag.h"
+#include "write-or-die.h"
 
 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
 static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>");
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 365d9234bdb..cf73d187912 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -23,6 +23,7 @@
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
+#include "write-or-die.h"
 
 enum batch_mode {
 	BATCH_MODE_CONTENTS,
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index ec37b8164af..1dbe9d6ca88 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -8,6 +8,7 @@
 #include "quote.h"
 #include "setup.h"
 #include "parse-options.h"
+#include "write-or-die.h"
 
 static int all_attrs;
 static int cached_attrs;
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index a45d001e353..9401dad0070 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -8,6 +8,7 @@
 #include "pathspec.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "write-or-die.h"
 
 static int quiet, verbose, stdin_paths, show_non_matching, no_index;
 static const char * const check_ignore_usage[] = {
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index fa86fd9423d..002d2941e93 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -5,6 +5,7 @@
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
+#include "write-or-die.h"
 
 static int use_stdin;
 static const char * const check_mailmap_usage[] = {
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index af56a44923d..508da4c6e4d 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -2,6 +2,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 #ifndef NO_UNIX_SOCKETS
 
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index da32cfd89e2..8977604eb9d 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -5,6 +5,7 @@
 #include "credential.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "write-or-die.h"
 
 static struct lock_file credential_lock;
 
diff --git a/builtin/grep.c b/builtin/grep.c
index b8ebf014f40..d858bf0bea6 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -28,6 +28,7 @@
 #include "submodule-config.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "write-or-die.h"
 
 static const char *grep_prefix;
 
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index a2e160db026..a15fe4fd3f4 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "exec-cmd.h"
 #include "setup.h"
+#include "write-or-die.h"
 
 /*
  * This is to create corrupt objects for debugging and as such it
diff --git a/builtin/log.c b/builtin/log.c
index 1b92dee196e..b28a24c3093 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -40,6 +40,7 @@
 #include "commit-reach.h"
 #include "range-diff.h"
 #include "tmp-objdir.h"
+#include "write-or-die.h"
 
 #define MAIL_DEFAULT_WRAP 72
 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100
diff --git a/builtin/notes.c b/builtin/notes.c
index 8e9be33ddbb..26cbb564a8e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -25,6 +25,7 @@
 #include "notes-merge.h"
 #include "notes-utils.h"
 #include "worktree.h"
+#include "write-or-die.h"
 
 static const char * const git_notes_usage[] = {
 	N_("git notes [--ref <notes-ref>] [list [<object>]]"),
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index fb5b2bad2cc..2b360fee426 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -16,6 +16,7 @@
 #include "gpg-interface.h"
 #include "gettext.h"
 #include "protocol.h"
+#include "write-or-die.h"
 
 static const char * const send_pack_usage[] = {
 	N_("git send-pack [--mirror] [--dry-run] [--force]\n"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 53930458ffa..9451eb69ff4 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "setup.h"
 #include "strbuf.h"
+#include "write-or-die.h"
 
 static void comment_lines(struct strbuf *buf)
 {
diff --git a/builtin/tag.c b/builtin/tag.c
index 0611b3bd600..531631a36c2 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -24,6 +24,7 @@
 #include "column.h"
 #include "ref-filter.h"
 #include "date.h"
+#include "write-or-die.h"
 
 static const char * const git_tag_usage[] = {
 	N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index f97f8d4c9d5..03cda5e60d2 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -23,6 +23,7 @@
 #include "setup.h"
 #include "split-index.h"
 #include "fsmonitor.h"
+#include "write-or-die.h"
 
 /*
  * Default to not allowing changes to the list of files. The
diff --git a/bundle.c b/bundle.c
index efeaf6f7151..dac82e2f2d9 100644
--- a/bundle.c
+++ b/bundle.c
@@ -16,6 +16,7 @@
 #include "strvec.h"
 #include "list-objects-filter-options.h"
 #include "connected.h"
+#include "write-or-die.h"
 
 static const char v2_bundle_signature[] = "# v2 git bundle\n";
 static const char v3_bundle_signature[] = "# v3 git bundle\n";
diff --git a/cache.h b/cache.h
index bffedd240e7..c43051d7928 100644
--- a/cache.h
+++ b/cache.h
@@ -686,63 +686,6 @@ extern int verify_ce_order;
 
 extern int quote_path_fully;
 
-/*
- * These values are used to help identify parts of a repository to fsync.
- * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
- * repository and so shouldn't be fsynced.
- */
-enum fsync_component {
-	FSYNC_COMPONENT_NONE,
-	FSYNC_COMPONENT_LOOSE_OBJECT		= 1 << 0,
-	FSYNC_COMPONENT_PACK			= 1 << 1,
-	FSYNC_COMPONENT_PACK_METADATA		= 1 << 2,
-	FSYNC_COMPONENT_COMMIT_GRAPH		= 1 << 3,
-	FSYNC_COMPONENT_INDEX			= 1 << 4,
-	FSYNC_COMPONENT_REFERENCE		= 1 << 5,
-};
-
-#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
-				  FSYNC_COMPONENT_PACK)
-
-#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
-					   FSYNC_COMPONENT_COMMIT_GRAPH)
-
-#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
-				   FSYNC_COMPONENTS_DERIVED_METADATA) & \
-				  ~FSYNC_COMPONENT_LOOSE_OBJECT)
-
-#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
-				    FSYNC_COMPONENT_REFERENCE)
-
-#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
-				FSYNC_COMPONENT_INDEX)
-
-#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
-			      FSYNC_COMPONENT_PACK | \
-			      FSYNC_COMPONENT_PACK_METADATA | \
-			      FSYNC_COMPONENT_COMMIT_GRAPH | \
-			      FSYNC_COMPONENT_INDEX | \
-			      FSYNC_COMPONENT_REFERENCE)
-
-#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
-#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
-#endif
-
-/*
- * A bitmask indicating which components of the repo should be fsynced.
- */
-extern enum fsync_component fsync_components;
-extern int fsync_object_files;
-extern int use_fsync;
-
-enum fsync_method {
-	FSYNC_METHOD_FSYNC,
-	FSYNC_METHOD_WRITEOUT_ONLY,
-	FSYNC_METHOD_BATCH,
-};
-
-extern enum fsync_method fsync_method;
-
 #define MTIME_CHANGED	0x0001
 #define CTIME_CHANGED	0x0002
 #define OWNER_CHANGED	0x0004
@@ -1045,29 +988,12 @@ int update_server_info(int);
 extern const char *git_mailmap_file;
 extern const char *git_mailmap_blob;
 
-/* IO helper functions */
-void maybe_flush_or_die(FILE *, const char *);
-__attribute__((format (printf, 2, 3)))
-void fprintf_or_die(FILE *, const char *fmt, ...);
-void fwrite_or_die(FILE *f, const void *buf, size_t count);
-void fflush_or_die(FILE *f);
-
 #define COPY_READ_ERROR (-2)
 #define COPY_WRITE_ERROR (-3)
 int copy_fd(int ifd, int ofd);
 int copy_file(const char *dst, const char *src, int mode);
 int copy_file_with_time(const char *dst, const char *src, int mode);
 
-void write_or_die(int fd, const void *buf, size_t count);
-void fsync_or_die(int fd, const char *);
-int fsync_component(enum fsync_component component, int fd);
-void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
-
-static inline int batch_fsync_enabled(enum fsync_component component)
-{
-	return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
-}
-
 /* pager.c */
 void setup_pager(void);
 int pager_in_use(void);
diff --git a/config.c b/config.c
index 03a4fcaba5b..5ad9ae91436 100644
--- a/config.c
+++ b/config.c
@@ -30,6 +30,7 @@
 #include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 struct config_source {
 	struct config_source *prev;
diff --git a/csum-file.h b/csum-file.h
index 793a59da12b..4cd9014e367 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -3,6 +3,7 @@
 
 #include "cache.h"
 #include "hash.h"
+#include "write-or-die.h"
 
 struct progress;
 
diff --git a/diagnose.c b/diagnose.c
index 169a55407fd..f9a2496c7ff 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -9,6 +9,7 @@
 #include "strvec.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "write-or-die.h"
 
 struct archive_dir {
 	const char *path;
diff --git a/environment.c b/environment.c
index 649d16ac27c..63c697e7e97 100644
--- a/environment.c
+++ b/environment.c
@@ -25,6 +25,7 @@
 #include "setup.h"
 #include "shallow.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
diff --git a/http-backend.c b/http-backend.c
index 042ccf12e8c..89aad1b42c7 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,6 +18,7 @@
 #include "protocol.h"
 #include "date.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
diff --git a/log-tree.c b/log-tree.c
index e2bf8d6df75..ba7b885984f 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -23,6 +23,7 @@
 #include "help.h"
 #include "range-diff.h"
 #include "strmap.h"
+#include "write-or-die.h"
 
 static struct decoration name_decoration = { "object names" };
 static int decoration_loaded;
diff --git a/pkt-line.c b/pkt-line.c
index 30469eb4d8d..36ae0fea4a3 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -4,6 +4,7 @@
 #include "hex.h"
 #include "run-command.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d2b8925ebd0..e6a6971381e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -17,6 +17,7 @@
 #include "../setup.h"
 #include "../worktree.h"
 #include "../wrapper.h"
+#include "../write-or-die.h"
 
 /*
  * This backend uses the following flags in `ref_update::flags` for
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 3334c07003c..1eba1015dd5 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -9,6 +9,7 @@
 #include "../iterator.h"
 #include "../lockfile.h"
 #include "../chdir-notify.h"
+#include "../write-or-die.h"
 
 enum mmap_strategy {
 	/*
diff --git a/remote-curl.c b/remote-curl.c
index 260ea200bb0..0f2410da8e7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -22,6 +22,7 @@
 #include "protocol.h"
 #include "quote.h"
 #include "transport.h"
+#include "write-or-die.h"
 
 static struct remote *remote;
 /* always ends with a trailing slash */
diff --git a/send-pack.c b/send-pack.c
index f531cb48212..11f41a8d81e 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -16,8 +16,9 @@
 #include "version.h"
 #include "oid-array.h"
 #include "gpg-interface.h"
-#include "cache.h"
 #include "shallow.h"
+#include "trace2.h"
+#include "write-or-die.h"
 
 int option_parse_push_signed(const struct option *opt,
 			     const char *arg, int unset)
diff --git a/sideband.c b/sideband.c
index 4905cf9b32a..0af582858bf 100644
--- a/sideband.c
+++ b/sideband.c
@@ -5,6 +5,7 @@
 #include "sideband.h"
 #include "help.h"
 #include "pkt-line.h"
+#include "write-or-die.h"
 
 struct keyword_entry {
 	/*
diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
index c5e052e5378..f4d134a1452 100644
--- a/t/helper/test-pkt-line.c
+++ b/t/helper/test-pkt-line.c
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "test-tool.h"
 #include "pkt-line.h"
+#include "write-or-die.h"
 
 static void pack_line(const char *line)
 {
diff --git a/upload-pack.c b/upload-pack.c
index 1155f795382..eb3d0b3fa36 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -30,6 +30,7 @@
 #include "commit-graph.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "write-or-die.h"
 
 /* Remember to update object flag allocation in object.h */
 #define THEY_HAVE	(1u << 11)
diff --git a/write-or-die.c b/write-or-die.c
index a7afc303db2..cc9e0787a1d 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -1,7 +1,8 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "run-command.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 /*
  * Some cases use stdio, but want to flush after the write
diff --git a/write-or-die.h b/write-or-die.h
new file mode 100644
index 00000000000..65a5c42a47a
--- /dev/null
+++ b/write-or-die.h
@@ -0,0 +1,78 @@
+#ifndef WRITE_OR_DIE_H
+#define WRITE_OR_DIE_H
+
+void maybe_flush_or_die(FILE *, const char *);
+__attribute__((format (printf, 2, 3)))
+void fprintf_or_die(FILE *, const char *fmt, ...);
+void fwrite_or_die(FILE *f, const void *buf, size_t count);
+void fflush_or_die(FILE *f);
+void write_or_die(int fd, const void *buf, size_t count);
+
+/*
+ * These values are used to help identify parts of a repository to fsync.
+ * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
+ * repository and so shouldn't be fsynced.
+ */
+enum fsync_component {
+	FSYNC_COMPONENT_NONE,
+	FSYNC_COMPONENT_LOOSE_OBJECT		= 1 << 0,
+	FSYNC_COMPONENT_PACK			= 1 << 1,
+	FSYNC_COMPONENT_PACK_METADATA		= 1 << 2,
+	FSYNC_COMPONENT_COMMIT_GRAPH		= 1 << 3,
+	FSYNC_COMPONENT_INDEX			= 1 << 4,
+	FSYNC_COMPONENT_REFERENCE		= 1 << 5,
+};
+
+#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
+				  FSYNC_COMPONENT_PACK)
+
+#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
+					   FSYNC_COMPONENT_COMMIT_GRAPH)
+
+#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
+				   FSYNC_COMPONENTS_DERIVED_METADATA) & \
+				  ~FSYNC_COMPONENT_LOOSE_OBJECT)
+
+#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
+				    FSYNC_COMPONENT_REFERENCE)
+
+#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
+				FSYNC_COMPONENT_INDEX)
+
+#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
+			      FSYNC_COMPONENT_PACK | \
+			      FSYNC_COMPONENT_PACK_METADATA | \
+			      FSYNC_COMPONENT_COMMIT_GRAPH | \
+			      FSYNC_COMPONENT_INDEX | \
+			      FSYNC_COMPONENT_REFERENCE)
+
+#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
+#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
+#endif
+
+/* IO helper functions */
+void fsync_or_die(int fd, const char *);
+int fsync_component(enum fsync_component component, int fd);
+void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
+
+/*
+ * A bitmask indicating which components of the repo should be fsynced.
+ */
+extern enum fsync_component fsync_components;
+extern int fsync_object_files;
+extern int use_fsync;
+
+enum fsync_method {
+	FSYNC_METHOD_FSYNC,
+	FSYNC_METHOD_WRITEOUT_ONLY,
+	FSYNC_METHOD_BATCH,
+};
+
+extern enum fsync_method fsync_method;
+
+static inline int batch_fsync_enabled(enum fsync_component component)
+{
+	return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
+}
+
+#endif /* WRITE_OR_DIE_H */
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH v2 16/16] csum-file.h: remove unnecessary inclusion of cache.h
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (14 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h Elijah Newren via GitGitGadget
@ 2023-03-21  6:26   ` Elijah Newren via GitGitGadget
  2023-03-21 21:56   ` [PATCH v2 00/16] Header cleanups Jonathan Tan
  16 siblings, 0 replies; 37+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-03-21  6:26 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, Elijah Newren,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

With the change in the last commit to move several functions to
write-or-die.h, csum-file.h no longer needs to include cache.h.
However, removing that include forces several other C files, which
directly or indirectly dependend upon csum-file.h's inclusion of
cache.h, to now be more explicit about their dependencies.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 bulk-checkin.c      | 2 +-
 chunk-format.c      | 1 +
 commit-graph.c      | 2 +-
 csum-file.h         | 1 -
 delta-islands.c     | 2 +-
 fetch-pack.c        | 2 +-
 midx.c              | 2 +-
 object-file.c       | 2 +-
 pack-bitmap-write.c | 3 ++-
 pack-bitmap.c       | 2 +-
 pack.h              | 2 ++
 packfile.c          | 2 +-
 12 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/bulk-checkin.c b/bulk-checkin.c
index eb6d7a2805b..d2428b86111 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2011, Google Inc.
  */
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
 #include "environment.h"
diff --git a/chunk-format.c b/chunk-format.c
index 6d1071729df..60a73c1b140 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -3,6 +3,7 @@
 #include "chunk-format.h"
 #include "csum-file.h"
 #include "gettext.h"
+#include "trace2.h"
 
 /*
  * When writing a chunk-based file format, collect the chunks in
diff --git a/commit-graph.c b/commit-graph.c
index 5481736c76c..f0cd2e7a2a3 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/csum-file.h b/csum-file.h
index 4cd9014e367..566e05cbd25 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -1,7 +1,6 @@
 #ifndef CSUM_FILE_H
 #define CSUM_FILE_H
 
-#include "cache.h"
 #include "hash.h"
 #include "write-or-die.h"
 
diff --git a/delta-islands.c b/delta-islands.c
index 1222b6a6cd1..73a01179e83 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "attr.h"
 #include "object.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index c453a4168f9..10f759532ce 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "repository.h"
 #include "config.h"
diff --git a/midx.c b/midx.c
index b111665dcab..9af3e5de889 100644
--- a/midx.c
+++ b/midx.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/object-file.c b/object-file.c
index 05fff230f73..397596e3c8f 100644
--- a/object-file.c
+++ b/object-file.c
@@ -6,7 +6,7 @@
  * This handles basic git object files - packing, unpacking,
  * creation etc.
  */
-#include "git-compat-util.h"
+#include "cache.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 63f16080c9b..0fddeb1298b 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
@@ -17,6 +17,7 @@
 #include "pack-objects.h"
 #include "commit-reach.h"
 #include "prio-queue.h"
+#include "trace2.h"
 
 struct bitmapped_commit {
 	struct commit *commit;
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 241ac9166c1..23d87e71bd9 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "commit.h"
 #include "gettext.h"
diff --git a/pack.h b/pack.h
index 01d385903ad..3ab9e3f60c0 100644
--- a/pack.h
+++ b/pack.h
@@ -4,6 +4,8 @@
 #include "object.h"
 #include "csum-file.h"
 
+struct packed_git;
+struct pack_window;
 struct repository;
 
 /*
diff --git a/packfile.c b/packfile.c
index 4b5b841d046..61672d50bdf 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "cache.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [PATCH v2 00/16] Header cleanups
  2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
                     ` (15 preceding siblings ...)
  2023-03-21  6:26   ` [PATCH v2 16/16] csum-file.h: remove unnecessary inclusion of cache.h Elijah Newren via GitGitGadget
@ 2023-03-21 21:56   ` Jonathan Tan
  16 siblings, 0 replies; 37+ messages in thread
From: Jonathan Tan @ 2023-03-21 21:56 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Ævar Arnfjörð Bjarmason,
	Elijah Newren

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>  * Patch 1: leftover cleanup from en/header-cleanups (now in master) that
>    should have been included in that series
>  * Patches 2-4: cleanups around gettext.h. Without these patches, many
>    gettext inclusions would have to be squashed into later patches and make
>    them harder to review. Also, the implicit dependency on gettext.h was
>    making it much harder to find other dependencies.
>  * Patch 5: move some global var declarations from cache.h into the header
>    associated with where the vars are declared
>  * Patches 6-16: move header declarations from cache.h into a header named
>    the same as the source file containing the actual functions (e.g. move
>    declarations for abspath.c functions from cache.h into abspath.h), and
>    reduce the dependencies on cache.h accordingly.

Thanks for the effort. All the changes look good to me. (As for whether
gettext.h should go into cache.h/git-compat-util.h, I think that
individual files that use it should include it themselves, just as you
have done in this patch set. This means, among other things, that we can
reuse Git code in other projects that do not use gettext.)
 

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2023-03-21 21:59 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19  6:27 [PATCH 00/16] Header cleanups Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 02/16] treewide: be explicit about dependence on gettext.h Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 03/16] treewide: remove unnecessary inclusion of gettext.h Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 04/16] treewide: remove unnecessary cache.h inclusion from several sources Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 05/16] environment: move comment_line_char from cache.h Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 06/16] abspath.h: move absolute path functions " Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 07/16] cache.h: remove expand_user_path() Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 08/16] path.h: move function declarations for path.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 09/16] wrapper.h: move declarations for wrapper.c " Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 10/16] treewide: remove unnecessary includes of cache.h Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 11/16] environment.h: move declarations for environment.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 12/16] treewide: remove cache.h inclusion due to environment.h changes Elijah Newren via GitGitGadget
2023-03-19  6:27 ` [PATCH 13/16] setup.h: move declarations for setup.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-19  6:28 ` [PATCH 14/16] treewide: remove cache.h inclusion due to setup.h changes Elijah Newren via GitGitGadget
2023-03-19  6:28 ` [PATCH 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-19  6:28 ` [PATCH 16/16] csum-file.h: remove unnecessary inclusion of cache.h Elijah Newren via GitGitGadget
2023-03-20  9:58 ` [PATCH 00/16] Header cleanups Ævar Arnfjörð Bjarmason
2023-03-20 16:18   ` Elijah Newren
2023-03-21  6:25 ` [PATCH v2 " Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 01/16] treewide: remove unnecessary cache.h inclusion from a few headers Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 02/16] treewide: be explicit about dependence on gettext.h Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 03/16] treewide: remove unnecessary inclusion of gettext.h Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 04/16] treewide: remove unnecessary cache.h inclusion from several sources Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 05/16] environment: move comment_line_char from cache.h Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 06/16] abspath.h: move absolute path functions " Elijah Newren via GitGitGadget
2023-03-21  6:25   ` [PATCH v2 07/16] cache.h: remove expand_user_path() Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 08/16] path.h: move function declarations for path.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 09/16] wrapper.h: move declarations for wrapper.c " Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 10/16] treewide: remove unnecessary includes of cache.h Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 11/16] environment.h: move declarations for environment.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 12/16] treewide: remove cache.h inclusion due to environment.h changes Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 13/16] setup.h: move declarations for setup.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 14/16] treewide: remove cache.h inclusion due to setup.h changes Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 15/16] write-or-die.h: move declarations for write-or-die.c functions from cache.h Elijah Newren via GitGitGadget
2023-03-21  6:26   ` [PATCH v2 16/16] csum-file.h: remove unnecessary inclusion of cache.h Elijah Newren via GitGitGadget
2023-03-21 21:56   ` [PATCH v2 00/16] Header cleanups Jonathan Tan

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).