Git Mailing List Archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
@ 2023-05-07  3:45 Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug Elijah Newren via GitGitGadget
                   ` (27 more replies)
  0 siblings, 28 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren

Maintainer notes: (1) This series is built on top of a merge of
en/header-split-cache-h-part-2 into master, (2) This series has no conflicts
with next, but has three simple & small conflicts with seen:

 * a textual conflict with tl/notes-separator (affecting builtin/notes.c; to
   address, nuke the conflict region and add an include of alloc.h after
   builtin.h)
 * a textual & semantic conflict with cw/strbuf-cleanup (affecting strbuf.c;
   to address, delete the conflict region and also delete the include of
   repository.h)
 * a semantic conflict with rn/sparse-diff-index (affecting
   builtin/diff-index.c; to address, add an include of sparse-index.h).

== Summary ==

This series continues to focus on splitting declarations from cache.h to
separate headers, and also cleans up some other small header issues. By
patch 16, cache.h is gone.

== Reviewer Focus (see also "Overview" section, below) ==

While the series may look long and big, it's really mostly just (a) moving
lots of code (so --color-moved is handy), and (b) adding (or removing)
includes repeatedly throughout the code. These are just more of the same
kinds of changes from the previous series.

However, there are a few exceptions that do not fit in these two categories,
which should be reviewed more closely:

 * Patches 1, 2, & 5
 * Patch 16, the Documentation and Makefile changes
 * Patch 23, the single modified line in khash.h

Patches 10 & 24 might also merit a little closer review.

== Impact; interesting stats ==

By way of impact, I created a small script which before this series reports:

Total include depth of .c files: 18340
Total include depth of .h files: 1385


After this series, I see:

Total include depth of .c files: 16155
Total include depth of .h files: 1206


The script computes the number of files transitively included by each file
(not perfect, e.g. only does textual search so if the include if ifdef'd,
it'll be counted anyway), and then sums the results. I think these numbers
represent one rough measure of overall complexity humans face in
understanding files in our project, and/or that compilers take to operate.
(For reference, the total include depths for v2.40.0 were 23114 and 2981;
we've come a long way in improving it, most of that through nuking cache.h.)

== Overview ==

An overview:

 * Patches 1-6: move shared code between various builtin/*.c files into
   alternate shared homes (setup.c, read-cache.c).
 * Patches 7-16: continue splitting declarations from cache.h into
   alternative headers associated with the actual implementation of those
   functions.
 * Patches 17-22: remove some unnecessary includes in other header files
 * Patches 23 & 24: do some header shuffling with hashmap/khash/hash, and
   fsmonitor to reduce include depths

I would have just lumped patches 1-6 in with 7-16, but patches 1, 2, & 5 did
some preliminary changes to allow the code movement.

== Acknowledgements ==

And thanks once again to Dscho for gitgitgadget. Getting multiple platform
testing + all the special tests (sparse, cocci, hdr-check, etc.) really
helps clean out all the issues that would otherwise hit a series like this.

Elijah Newren (24):
  init-db: remove unnecessary global variable & document existing bug
  init-db, clone: change unnecessary global into passed parameter
  setup: adopt shared init-db & clone code
  read-cache: move shared commit and ls-files code
  add: modify add_files_to_cache() to avoid globals
  read-cache: move shared add/checkout/commit code
  statinfo: move stat_{data,validity} functions from cache/read-cache
  run-command.h: move declarations for run-command.c from cache.h
  name-hash.h: move declarations for name-hash.c from cache.h
  sparse-index.h: move declarations for sparse-index.c from cache.h
  preload-index.h: move declarations for preload-index.c from elsewhere
  diff.h: move declaration for global in diff.c from cache.h
  merge.h: move declarations for merge.c from cache.h
  repository.h: move declaration of the_index from cache.h
  read-cache*.h: move declarations for read-cache.c functions from
    cache.h
  cache.h: remove this no-longer-used header
  log-tree: replace include of revision.h with simple forward
    declaration
  repository: remove unnecessary include of path.h
  diff.h: remove unnecessary include of oidset.h
  list-objects-filter-options.h: remove unneccessary include
  builtin.h: remove unneccessary includes
  git-compat-util.h: remove unneccessary include of wildmatch.h
  hash-ll, hashmap: move oidhash() to hash-ll
  fsmonitor-ll.h: split this header out of fsmonitor.h

 Documentation/CodingGuidelines           |   2 +-
 Documentation/MyFirstObjectWalk.txt      |   2 +-
 Documentation/user-manual.txt            |  18 +-
 Makefile                                 |   3 +-
 add-interactive.c                        |   6 +-
 add-patch.c                              |   4 +-
 apply.c                                  |   8 +-
 archive-tar.c                            |   2 +-
 archive-zip.c                            |   2 +-
 archive.c                                |   3 +-
 attr.c                                   |   6 +-
 bisect.c                                 |   3 +-
 blame.c                                  |   6 +-
 blame.h                                  |   1 +
 branch.c                                 |   1 +
 builtin.h                                |   3 -
 builtin/add.c                            | 105 +----
 builtin/am.c                             |   5 +-
 builtin/apply.c                          |   1 -
 builtin/archive.c                        |   1 -
 builtin/bisect.c                         |   2 +-
 builtin/blame.c                          |   2 +-
 builtin/branch.c                         |   4 +-
 builtin/bundle.c                         |   1 -
 builtin/cat-file.c                       |   5 +-
 builtin/check-attr.c                     |   1 -
 builtin/check-ignore.c                   |   1 -
 builtin/check-mailmap.c                  |   1 +
 builtin/check-ref-format.c               |   3 +-
 builtin/checkout--worker.c               |   1 +
 builtin/checkout-index.c                 |   2 +
 builtin/checkout.c                       |   7 +-
 builtin/clean.c                          |   3 +-
 builtin/clone.c                          |   6 +-
 builtin/column.c                         |   1 -
 builtin/commit-graph.c                   |   3 +-
 builtin/commit-tree.c                    |   5 +-
 builtin/commit.c                         |  10 +-
 builtin/config.c                         |   1 +
 builtin/count-objects.c                  |   6 +-
 builtin/credential-cache.c               |   1 +
 builtin/describe.c                       |   7 +-
 builtin/diff-files.c                     |   5 +-
 builtin/diff-index.c                     |   5 +-
 builtin/diff-tree.c                      |   5 +-
 builtin/diff.c                           |   5 +-
 builtin/difftool.c                       |   7 +-
 builtin/fast-export.c                    |   3 +-
 builtin/fast-import.c                    |   4 +-
 builtin/fetch.c                          |   6 +-
 builtin/for-each-ref.c                   |   2 +-
 builtin/for-each-repo.c                  |   3 +-
 builtin/fsck.c                           |   6 +-
 builtin/fsmonitor--daemon.c              |   4 +-
 builtin/gc.c                             |   3 +-
 builtin/get-tar-commit-id.c              |   3 +-
 builtin/grep.c                           |   7 +-
 builtin/hash-object.c                    |   3 +-
 builtin/help.c                           |   3 +-
 builtin/hook.c                           |   1 -
 builtin/index-pack.c                     |   3 +-
 builtin/init-db.c                        | 474 +-------------------
 builtin/interpret-trailers.c             |   1 -
 builtin/log.c                            |   2 +-
 builtin/ls-files.c                       | 143 +-----
 builtin/ls-remote.c                      |   2 +-
 builtin/ls-tree.c                        |   6 +-
 builtin/mailinfo.c                       |   3 +-
 builtin/mailsplit.c                      |   1 -
 builtin/merge-base.c                     |   1 -
 builtin/merge-file.c                     |   1 -
 builtin/merge-index.c                    |   2 +
 builtin/merge-ours.c                     |   1 +
 builtin/merge-recursive.c                |   1 -
 builtin/merge-tree.c                     |   2 +-
 builtin/merge.c                          |   5 +-
 builtin/mktag.c                          |   3 +-
 builtin/mktree.c                         |   3 +-
 builtin/multi-pack-index.c               |   4 +-
 builtin/mv.c                             |   2 +
 builtin/name-rev.c                       |   1 +
 builtin/notes.c                          |   6 +-
 builtin/pack-objects.c                   |   2 +-
 builtin/pack-redundant.c                 |   2 +-
 builtin/patch-id.c                       |   2 +-
 builtin/prune.c                          |   7 +-
 builtin/pull.c                           |   6 +-
 builtin/push.c                           |   3 +-
 builtin/range-diff.c                     |   2 +-
 builtin/read-tree.c                      |   4 +-
 builtin/rebase.c                         |   1 +
 builtin/receive-pack.c                   |   3 +-
 builtin/reflog.c                         |   2 +
 builtin/remote.c                         |   3 +-
 builtin/repack.c                         |   3 +-
 builtin/replace.c                        |   7 +-
 builtin/rerere.c                         |   1 -
 builtin/reset.c                          |   3 +
 builtin/rev-list.c                       |   5 +-
 builtin/rev-parse.c                      |   6 +-
 builtin/revert.c                         |   1 +
 builtin/rm.c                             |   2 +
 builtin/shortlog.c                       |   2 +-
 builtin/show-branch.c                    |   4 +-
 builtin/show-index.c                     |   1 -
 builtin/show-ref.c                       |   3 +-
 builtin/sparse-checkout.c                |   1 -
 builtin/stash.c                          |   4 +
 builtin/stripspace.c                     |   1 -
 builtin/submodule--helper.c              |   7 +-
 builtin/symbolic-ref.c                   |   1 -
 builtin/tag.c                            |   6 +-
 builtin/unpack-file.c                    |   2 +-
 builtin/unpack-objects.c                 |   3 +-
 builtin/update-index.c                   |   5 +-
 builtin/update-ref.c                     |   3 +-
 builtin/update-server-info.c             |   3 +-
 builtin/upload-archive.c                 |   2 +-
 builtin/upload-pack.c                    |   2 +-
 builtin/verify-commit.c                  |   5 +-
 builtin/verify-pack.c                    |   2 +-
 builtin/verify-tag.c                     |   3 +-
 builtin/worktree.c                       |   5 +-
 builtin/write-tree.c                     |   1 -
 bulk-checkin.c                           |   2 +-
 bundle-uri.c                             |   2 +-
 bundle.c                                 |   2 +-
 cache-tree.c                             |   5 +-
 combine-diff.c                           |   2 +-
 commit-graph.c                           |   3 +-
 commit-graph.h                           |   2 +-
 commit.c                                 |   2 +-
 compat/fsmonitor/fsm-health-darwin.c     |   2 +-
 compat/fsmonitor/fsm-health-win32.c      |   4 +-
 compat/fsmonitor/fsm-ipc-darwin.c        |   3 +-
 compat/fsmonitor/fsm-listen-darwin.c     |   3 +-
 compat/fsmonitor/fsm-listen-win32.c      |   4 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |   4 +-
 compat/fsmonitor/fsm-path-utils-win32.c  |   5 +-
 compat/fsmonitor/fsm-settings-darwin.c   |   2 +-
 compat/fsmonitor/fsm-settings-win32.c    |   4 +-
 compat/mingw.c                           |   1 -
 compat/precompose_utf8.c                 |   3 +-
 compat/sha1-chunked.c                    |   3 +-
 compat/simple-ipc/ipc-win32.c            |   2 +-
 compat/win32/trace2_win32_process_info.c |   2 +-
 config.c                                 |   5 +-
 connect.c                                |   1 +
 connected.c                              |   2 +-
 convert.c                                |   5 +-
 decorate.c                               |   1 -
 diagnose.c                               |   2 +-
 diff-lib.c                               |   5 +-
 diff.c                                   |   5 +-
 diff.h                                   |   6 +-
 diffcore-break.c                         |   4 +-
 diffcore-order.c                         |   1 +
 diffcore-pickaxe.c                       |   1 +
 diffcore-rename.c                        |   2 +-
 dir.c                                    |   8 +-
 dir.h                                    |   1 +
 entry.c                                  |   6 +-
 environment.c                            |   5 +-
 environment.h                            |   3 +-
 exec-cmd.c                               |   3 +-
 fetch-pack.c                             |   3 +-
 fmt-merge-msg.c                          |   3 +-
 fsck.c                                   |   4 +-
 fsmonitor-ipc.c                          |   4 +-
 fsmonitor-ll.h                           |  52 +++
 fsmonitor.c                              |   2 +-
 fsmonitor.h                              |  49 +--
 git-compat-util.h                        |   2 -
 git.c                                    |   1 +
 grep.c                                   |   2 +-
 hash-ll.h                                |  19 +
 hash-lookup.c                            |   3 +-
 hashmap.h                                |  21 -
 http-backend.c                           |   3 +-
 http-push.c                              |   2 +-
 http-walker.c                            |   2 +-
 http.c                                   |   2 +-
 khash.h                                  |   3 +-
 line-log.c                               |   1 +
 list-objects-filter-options.h            |   1 -
 list-objects-filter.c                    |   2 +-
 list-objects.c                           |   2 +-
 log-tree.c                               |   4 +-
 log-tree.h                               |   2 +-
 mailmap.c                                |   2 +-
 match-trees.c                            |   3 +-
 merge-blobs.c                            |   2 +-
 merge-ort-wrappers.c                     |   3 +-
 merge-ort.c                              |   7 +-
 merge-recursive.c                        |   7 +-
 merge.c                                  |   5 +-
 merge.h                                  |  17 +
 midx.c                                   |   2 +-
 name-hash.c                              |   5 +-
 name-hash.h                              |  16 +
 notes-cache.c                            |   3 +-
 notes-merge.c                            |   3 +-
 notes.c                                  |   2 +-
 object-file.c                            |   1 +
 object-name.c                            |   5 +-
 object-store-ll.h                        | 533 +++++++++++++++++++++++
 object-store.h                           | 528 +---------------------
 object.c                                 |   3 +-
 oidmap.h                                 |   1 +
 oss-fuzz/fuzz-pack-idx.c                 |   2 +-
 pack-bitmap-write.c                      |   3 +-
 pack-bitmap.c                            |   2 +-
 pack-check.c                             |   2 +-
 pack-mtimes.c                            |   3 +-
 pack-objects.h                           |   2 +-
 pack-revindex.c                          |   3 +-
 pack-write.c                             |   2 +
 packfile.c                               |   2 +-
 parallel-checkout.c                      |   3 +-
 patch-ids.c                              |   1 +
 path.c                                   |   2 +-
 pathspec.c                               |   4 +-
 preload-index.c                          |   4 +-
 preload-index.h                          |  15 +
 pretty.c                                 |   1 +
 promisor-remote.c                        |   2 +-
 protocol-caps.c                          |   2 +-
 prune-packed.c                           |   2 +-
 range-diff.c                             |   1 +
 reachable.c                              |   2 +-
 cache.h => read-cache-ll.h               | 148 +------
 read-cache.c                             | 331 ++++++++++----
 read-cache.h                             |  45 ++
 ref-filter.c                             |   2 +-
 reflog-walk.c                            |   1 +
 reflog.c                                 |   2 +-
 refs.c                                   |   4 +-
 refs/files-backend.c                     |   3 +-
 refs/packed-backend.c                    |   3 +-
 remote.c                                 |   3 +-
 remote.h                                 |   1 +
 replace-object.c                         |   2 +-
 replace-object.h                         |   2 +-
 repository.c                             |   6 +-
 repository.h                             |   8 +-
 rerere.c                                 |   6 +-
 resolve-undo.c                           |   4 +-
 revision.c                               |   7 +-
 run-command.c                            |   2 +-
 run-command.h                            |   4 +-
 send-pack.c                              |   2 +-
 sequencer.c                              |   7 +-
 serve.c                                  |   1 +
 server-info.c                            |   3 +-
 setup.c                                  | 480 ++++++++++++++++++++
 setup.h                                  |   9 +
 shallow.c                                |   6 +-
 sparse-index.c                           |   6 +-
 sparse-index.h                           |   2 +
 split-index.c                            |   3 +-
 statinfo.c                               |  87 ++++
 statinfo.h                               |  51 +++
 strbuf.c                                 |   1 +
 strbuf.h                                 |   4 -
 streaming.c                              |   2 +-
 submodule-config.c                       |   3 +-
 submodule.c                              |   6 +-
 t/helper/test-cache-tree.c               |   2 +-
 t/helper/test-dump-cache-tree.c          |   2 +-
 t/helper/test-dump-fsmonitor.c           |   2 +-
 t/helper/test-dump-split-index.c         |   3 +-
 t/helper/test-dump-untracked-cache.c     |   2 +-
 t/helper/test-fast-rebase.c              |   3 +-
 t/helper/test-fsmonitor-client.c         |   2 +-
 t/helper/test-hash-speed.c               |   2 +-
 t/helper/test-index-version.c            |   2 +-
 t/helper/test-lazy-init-name-hash.c      |   3 +-
 t/helper/test-pack-mtimes.c              |   2 +-
 t/helper/test-partial-clone.c            |   2 +-
 t/helper/test-path-utils.c               |   2 +-
 t/helper/test-read-cache.c               |   2 +-
 t/helper/test-read-graph.c               |   2 +-
 t/helper/test-read-midx.c                |   2 +-
 t/helper/test-ref-store.c                |   4 +-
 t/helper/test-repository.c               |   2 +-
 t/helper/test-revision-walking.c         |   1 +
 t/helper/test-scrap-cache-tree.c         |   2 +-
 t/helper/test-sha1.c                     |   2 +-
 t/helper/test-sha256.c                   |   2 +-
 t/helper/test-strcmp-offset.c            |   2 +-
 t/helper/test-wildmatch.c                |   1 +
 t/helper/test-write-cache.c              |   2 +-
 t/t1301-shared-repo.sh                   |  22 +
 t/t5606-clone-options.sh                 |  10 +
 tag.c                                    |   2 +-
 tmp-objdir.c                             |   3 +-
 trace2/tr2_cfg.c                         |   1 +
 transport-helper.c                       |   1 +
 transport.c                              |   2 +-
 tree-diff.c                              |   1 +
 tree-walk.c                              |   2 +-
 tree.c                                   |   2 +-
 unpack-trees.c                           |   6 +-
 unpack-trees.h                           |   2 +-
 upload-pack.c                            |   2 +-
 walker.c                                 |   3 +-
 worktree.c                               |   1 +
 wt-status.c                              |   5 +-
 xdiff-interface.c                        |   3 +-
 309 files changed, 2149 insertions(+), 1882 deletions(-)
 create mode 100644 fsmonitor-ll.h
 create mode 100644 merge.h
 create mode 100644 name-hash.h
 create mode 100644 object-store-ll.h
 create mode 100644 preload-index.h
 rename cache.h => read-cache-ll.h (79%)
 create mode 100644 read-cache.h
 create mode 100644 statinfo.c


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

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

* [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-11 17:24   ` Calvin Wan
  2023-05-11 20:43   ` Glen Choo
  2023-05-07  3:45 ` [PATCH 02/24] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
                   ` (26 subsequent siblings)
  27 siblings, 2 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This commit was prompted by a desire to move the functions which
builtin/init-db.c and builtin/clone.c share out of the former file and
into setup.c.  One issue that made it difficult was the
init_is_bare_repository global variable.

init_is_bare_repository is actually not very useful.  It merely stores
the return value from is_bare_repository() and only for the duration of
a few additional function calls before its value is checked, and none of
those functions do anything that could change is_bare_repository()'s
return value.  So, we can simply dispense with the global by replacing
it with is_bare_repository().

However, the intervening code does talk about reading config from the
config file in the specified `--templates` directory, so touching this
code does lead to the question of whether core.bare could be set in such
a config file and thus whether the code is doing the right thing.  Long
story short is that the templates directory might have a config file
with core.bare set, but it has always been unconditionally ignored.
While fixing that might be nice, it looks to be a can of worms, and
cannot be fixed within this function anyway.  Instead of opening that
can of worms, document the problem with a TODO comment and a couple
test_expect_failure testcases.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c        | 20 ++++++++++++++++----
 t/t1301-shared-repo.sh   | 22 ++++++++++++++++++++++
 t/t5606-clone-options.sh | 10 ++++++++++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index aef40361052..18733ef05aa 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,7 +31,6 @@
 
 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
 
-static int init_is_bare_repository = 0;
 static int init_shared_repository = -1;
 
 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
@@ -231,9 +230,24 @@ static int create_default_files(const char *template_path,
 	 * We must make sure command-line options continue to override any
 	 * values we might have just re-read from the config.
 	 */
-	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
 	if (init_shared_repository != -1)
 		set_shared_repository(init_shared_repository);
+	/*
+	 * TODO: heed core.bare from config file in templates if no
+	 *       command-line override given
+	 *
+	 * Unfortunately, this location in the code is far too late to
+	 * allow this to happen; both builtin/init.db and
+	 * builtin/clone.c setup the new repository and call
+	 * set_git_work_tree() before this point.  (Note that both do
+	 * that repository setup before calling init_db(), which in
+	 * turn calls create_default_files().)  Fixing it would
+	 * require too much refactoring, and no one seems to have
+	 * wanted this behavior in 15+ years, so we'll continue
+	 * ignoring the config for now and just override
+	 * is_bare_repository_cfg unconditionally.
+	 */
+	is_bare_repository_cfg = is_bare_repository() || !work_tree;
 
 	/*
 	 * We would have created the above under user's umask -- under
@@ -422,8 +436,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
 	safe_create_dir(git_dir, 0);
 
-	init_is_bare_repository = is_bare_repository();
-
 	/* Check to see if the repository version is right.
 	 * Note that a newly created repository does not have
 	 * config file, so this will not fail.  What we are catching
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index 1b6437ec079..c02fd64793b 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -52,6 +52,28 @@ test_expect_success 'shared=all' '
 	test 2 = $(git config core.sharedrepository)
 '
 
+test_expect_failure 'template can set core.bare' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "rm -rf templates" &&
+	test_config core.bare true &&
+	umask 0022 &&
+	mkdir -p templates/ &&
+	cp .git/config templates/config &&
+	git init --template=templates subdir &&
+	test_path_exists subdir/HEAD
+'
+
+test_expect_success 'template can set core.bare but overridden by command line' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "rm -rf templates" &&
+	test_config core.bare true &&
+	umask 0022 &&
+	mkdir -p templates/ &&
+	cp .git/config templates/config &&
+	git init --no-bare --template=templates subdir &&
+	test_path_exists subdir/.git/HEAD
+'
+
 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
 	: > a1 &&
 	git add a1 &&
diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh
index 27f9f776389..5890319b97b 100755
--- a/t/t5606-clone-options.sh
+++ b/t/t5606-clone-options.sh
@@ -120,6 +120,16 @@ test_expect_success 'prefers -c config over --template config' '
 
 '
 
+test_expect_failure 'prefers --template config even for core.bare' '
+
+	template="$TRASH_DIRECTORY/template-with-bare-config" &&
+	mkdir "$template" &&
+	git config --file "$template/config" core.bare true &&
+	git clone "--template=$template" parent clone-bare-config &&
+	test "$(git -C clone-bare-config config --local core.bare)" = "true" &&
+	test_path_is_file clone-bare-config/HEAD
+'
+
 test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
 
 	test_config_global clone.defaultRemoteName from_config &&
-- 
gitgitgadget


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

* [PATCH 02/24] init-db, clone: change unnecessary global into passed parameter
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 03/24] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
                   ` (25 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Much like the former commit, this commit was prompted by a desire to
move the functions which builtin/init-db.c and builtin/clone.c share out
of the former file and into setup.c.  A secondary issue that made it
difficult was the init_shared_repository global variable; replace it
with a simple parameter that is passed to the relevant functions.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/clone.c   | 3 ++-
 builtin/init-db.c | 9 +++++----
 cache.h           | 3 ++-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 15f9912b4ca..cc34c194f5e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	int submodule_progress;
 	int filter_submodules = 0;
 	int hash_algo;
+	const int do_not_override_repo_unix_permissions = -1;
 
 	struct transport_ls_refs_options transport_ls_refs_options =
 		TRANSPORT_LS_REFS_OPTIONS_INIT;
@@ -1097,7 +1098,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	}
 
 	init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
-		INIT_DB_QUIET);
+		do_not_override_repo_unix_permissions, INIT_DB_QUIET);
 
 	if (real_git_dir) {
 		free((char *)git_dir);
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 18733ef05aa..0b30ea2d9ed 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,8 +31,6 @@
 
 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
 
-static int init_shared_repository = -1;
-
 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
 			     DIR *dir)
 {
@@ -198,6 +196,7 @@ static int create_default_files(const char *template_path,
 				const char *original_git_dir,
 				const char *initial_branch,
 				const struct repository_format *fmt,
+				int init_shared_repository,
 				int quiet)
 {
 	struct stat st1;
@@ -405,7 +404,7 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
 
 int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *template_dir, int hash, const char *initial_branch,
-	    unsigned int flags)
+	    int init_shared_repository, unsigned int flags)
 {
 	int reinit;
 	int exist_ok = flags & INIT_DB_EXIST_OK;
@@ -447,6 +446,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
 	reinit = create_default_files(template_dir, original_git_dir,
 				      initial_branch, &repo_fmt,
+				      init_shared_repository,
 				      flags & INIT_DB_QUIET);
 	if (reinit && initial_branch)
 		warning(_("re-init: ignored --initial-branch=%s"),
@@ -558,6 +558,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 	const char *object_format = NULL;
 	const char *initial_branch = NULL;
 	int hash_algo = GIT_HASH_UNKNOWN;
+	int init_shared_repository = -1;
 	const struct option init_db_options[] = {
 		OPT_STRING(0, "template", &template_dir, N_("template-directory"),
 				N_("directory from which templates will be used")),
@@ -715,5 +716,5 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 
 	flags |= INIT_DB_EXIST_OK;
 	return init_db(git_dir, real_git_dir, template_dir, hash_algo,
-		       initial_branch, flags);
+		       initial_branch, init_shared_repository, flags);
 }
diff --git a/cache.h b/cache.h
index bdedb87e83b..2bc1cd77d9b 100644
--- a/cache.h
+++ b/cache.h
@@ -327,7 +327,8 @@ extern struct index_state the_index;
 
 int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *template_dir, int hash_algo,
-	    const char *initial_branch, unsigned int flags);
+	    const char *initial_branch, int init_shared_repository,
+	    unsigned int flags);
 void initialize_repository_version(int hash_algo, int reinit);
 
 /* Initialize and use the cache information */
-- 
gitgitgadget


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

* [PATCH 03/24] setup: adopt shared init-db & clone code
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 02/24] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 04/24] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
                   ` (24 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The functions init_db() and initialize_repository_version() were shared
by builtin/init-db.c and builtin/clone.c, and declared in cache.h.

Move these functions, plus their several helpers only used by these
functions, to setup.[ch].

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c | 479 ----------------------------------------------
 cache.h           |   9 -
 setup.c           | 479 ++++++++++++++++++++++++++++++++++++++++++++++
 setup.h           |   9 +
 4 files changed, 488 insertions(+), 488 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 0b30ea2d9ed..feb019a9dea 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -6,494 +6,15 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
-#include "copy.h"
 #include "environment.h"
 #include "gettext.h"
-#include "refs.h"
 #include "builtin.h"
-#include "exec-cmd.h"
 #include "object-file.h"
 #include "parse-options.h"
 #include "path.h"
 #include "setup.h"
-#include "worktree.h"
 #include "wrapper.h"
 
-#ifndef DEFAULT_GIT_TEMPLATE_DIR
-#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
-#endif
-
-#ifdef NO_TRUSTABLE_FILEMODE
-#define TEST_FILEMODE 0
-#else
-#define TEST_FILEMODE 1
-#endif
-
-#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
-
-static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
-			     DIR *dir)
-{
-	size_t path_baselen = path->len;
-	size_t template_baselen = template_path->len;
-	struct dirent *de;
-
-	/* Note: if ".git/hooks" file exists in the repository being
-	 * re-initialized, /etc/core-git/templates/hooks/update would
-	 * cause "git init" to fail here.  I think this is sane but
-	 * it means that the set of templates we ship by default, along
-	 * with the way the namespace under .git/ is organized, should
-	 * be really carefully chosen.
-	 */
-	safe_create_dir(path->buf, 1);
-	while ((de = readdir(dir)) != NULL) {
-		struct stat st_git, st_template;
-		int exists = 0;
-
-		strbuf_setlen(path, path_baselen);
-		strbuf_setlen(template_path, template_baselen);
-
-		if (de->d_name[0] == '.')
-			continue;
-		strbuf_addstr(path, de->d_name);
-		strbuf_addstr(template_path, de->d_name);
-		if (lstat(path->buf, &st_git)) {
-			if (errno != ENOENT)
-				die_errno(_("cannot stat '%s'"), path->buf);
-		}
-		else
-			exists = 1;
-
-		if (lstat(template_path->buf, &st_template))
-			die_errno(_("cannot stat template '%s'"), template_path->buf);
-
-		if (S_ISDIR(st_template.st_mode)) {
-			DIR *subdir = opendir(template_path->buf);
-			if (!subdir)
-				die_errno(_("cannot opendir '%s'"), template_path->buf);
-			strbuf_addch(path, '/');
-			strbuf_addch(template_path, '/');
-			copy_templates_1(path, template_path, subdir);
-			closedir(subdir);
-		}
-		else if (exists)
-			continue;
-		else if (S_ISLNK(st_template.st_mode)) {
-			struct strbuf lnk = STRBUF_INIT;
-			if (strbuf_readlink(&lnk, template_path->buf,
-					    st_template.st_size) < 0)
-				die_errno(_("cannot readlink '%s'"), template_path->buf);
-			if (symlink(lnk.buf, path->buf))
-				die_errno(_("cannot symlink '%s' '%s'"),
-					  lnk.buf, path->buf);
-			strbuf_release(&lnk);
-		}
-		else if (S_ISREG(st_template.st_mode)) {
-			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
-				die_errno(_("cannot copy '%s' to '%s'"),
-					  template_path->buf, path->buf);
-		}
-		else
-			error(_("ignoring template %s"), template_path->buf);
-	}
-}
-
-static void copy_templates(const char *template_dir, const char *init_template_dir)
-{
-	struct strbuf path = STRBUF_INIT;
-	struct strbuf template_path = STRBUF_INIT;
-	size_t template_len;
-	struct repository_format template_format = REPOSITORY_FORMAT_INIT;
-	struct strbuf err = STRBUF_INIT;
-	DIR *dir;
-	char *to_free = NULL;
-
-	if (!template_dir)
-		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
-	if (!template_dir)
-		template_dir = init_template_dir;
-	if (!template_dir)
-		template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
-	if (!template_dir[0]) {
-		free(to_free);
-		return;
-	}
-
-	strbuf_addstr(&template_path, template_dir);
-	strbuf_complete(&template_path, '/');
-	template_len = template_path.len;
-
-	dir = opendir(template_path.buf);
-	if (!dir) {
-		warning(_("templates not found in %s"), template_dir);
-		goto free_return;
-	}
-
-	/* Make sure that template is from the correct vintage */
-	strbuf_addstr(&template_path, "config");
-	read_repository_format(&template_format, template_path.buf);
-	strbuf_setlen(&template_path, template_len);
-
-	/*
-	 * No mention of version at all is OK, but anything else should be
-	 * verified.
-	 */
-	if (template_format.version >= 0 &&
-	    verify_repository_format(&template_format, &err) < 0) {
-		warning(_("not copying templates from '%s': %s"),
-			  template_dir, err.buf);
-		strbuf_release(&err);
-		goto close_free_return;
-	}
-
-	strbuf_addstr(&path, get_git_common_dir());
-	strbuf_complete(&path, '/');
-	copy_templates_1(&path, &template_path, dir);
-close_free_return:
-	closedir(dir);
-free_return:
-	free(to_free);
-	strbuf_release(&path);
-	strbuf_release(&template_path);
-	clear_repository_format(&template_format);
-}
-
-/*
- * If the git_dir is not directly inside the working tree, then git will not
- * find it by default, and we need to set the worktree explicitly.
- */
-static int needs_work_tree_config(const char *git_dir, const char *work_tree)
-{
-	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
-		return 0;
-	if (skip_prefix(git_dir, work_tree, &git_dir) &&
-	    !strcmp(git_dir, "/.git"))
-		return 0;
-	return 1;
-}
-
-void initialize_repository_version(int hash_algo, int reinit)
-{
-	char repo_version_string[10];
-	int repo_version = GIT_REPO_VERSION;
-
-	if (hash_algo != GIT_HASH_SHA1)
-		repo_version = GIT_REPO_VERSION_READ;
-
-	/* This forces creation of new config file */
-	xsnprintf(repo_version_string, sizeof(repo_version_string),
-		  "%d", repo_version);
-	git_config_set("core.repositoryformatversion", repo_version_string);
-
-	if (hash_algo != GIT_HASH_SHA1)
-		git_config_set("extensions.objectformat",
-			       hash_algos[hash_algo].name);
-	else if (reinit)
-		git_config_set_gently("extensions.objectformat", NULL);
-}
-
-static int create_default_files(const char *template_path,
-				const char *original_git_dir,
-				const char *initial_branch,
-				const struct repository_format *fmt,
-				int init_shared_repository,
-				int quiet)
-{
-	struct stat st1;
-	struct strbuf buf = STRBUF_INIT;
-	char *path;
-	char junk[2];
-	int reinit;
-	int filemode;
-	struct strbuf err = STRBUF_INIT;
-	const char *init_template_dir = NULL;
-	const char *work_tree = get_git_work_tree();
-
-	/*
-	 * First copy the templates -- we might have the default
-	 * config file there, in which case we would want to read
-	 * from it after installing.
-	 *
-	 * Before reading that config, we also need to clear out any cached
-	 * values (since we've just potentially changed what's available on
-	 * disk).
-	 */
-	git_config_get_pathname("init.templatedir", &init_template_dir);
-	copy_templates(template_path, init_template_dir);
-	free((char *)init_template_dir);
-	git_config_clear();
-	reset_shared_repository();
-	git_config(git_default_config, NULL);
-
-	/*
-	 * We must make sure command-line options continue to override any
-	 * values we might have just re-read from the config.
-	 */
-	if (init_shared_repository != -1)
-		set_shared_repository(init_shared_repository);
-	/*
-	 * TODO: heed core.bare from config file in templates if no
-	 *       command-line override given
-	 *
-	 * Unfortunately, this location in the code is far too late to
-	 * allow this to happen; both builtin/init.db and
-	 * builtin/clone.c setup the new repository and call
-	 * set_git_work_tree() before this point.  (Note that both do
-	 * that repository setup before calling init_db(), which in
-	 * turn calls create_default_files().)  Fixing it would
-	 * require too much refactoring, and no one seems to have
-	 * wanted this behavior in 15+ years, so we'll continue
-	 * ignoring the config for now and just override
-	 * is_bare_repository_cfg unconditionally.
-	 */
-	is_bare_repository_cfg = is_bare_repository() || !work_tree;
-
-	/*
-	 * We would have created the above under user's umask -- under
-	 * shared-repository settings, we would need to fix them up.
-	 */
-	if (get_shared_repository()) {
-		adjust_shared_perm(get_git_dir());
-	}
-
-	/*
-	 * We need to create a "refs" dir in any case so that older
-	 * versions of git can tell that this is a repository.
-	 */
-	safe_create_dir(git_path("refs"), 1);
-	adjust_shared_perm(git_path("refs"));
-
-	if (refs_init_db(&err))
-		die("failed to set up refs db: %s", err.buf);
-
-	/*
-	 * Point the HEAD symref to the initial branch with if HEAD does
-	 * not yet exist.
-	 */
-	path = git_path_buf(&buf, "HEAD");
-	reinit = (!access(path, R_OK)
-		  || readlink(path, junk, sizeof(junk)-1) != -1);
-	if (!reinit) {
-		char *ref;
-
-		if (!initial_branch)
-			initial_branch = git_default_branch_name(quiet);
-
-		ref = xstrfmt("refs/heads/%s", initial_branch);
-		if (check_refname_format(ref, 0) < 0)
-			die(_("invalid initial branch name: '%s'"),
-			    initial_branch);
-
-		if (create_symref("HEAD", ref, NULL) < 0)
-			exit(1);
-		free(ref);
-	}
-
-	initialize_repository_version(fmt->hash_algo, 0);
-
-	/* Check filemode trustability */
-	path = git_path_buf(&buf, "config");
-	filemode = TEST_FILEMODE;
-	if (TEST_FILEMODE && !lstat(path, &st1)) {
-		struct stat st2;
-		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
-				!lstat(path, &st2) &&
-				st1.st_mode != st2.st_mode &&
-				!chmod(path, st1.st_mode));
-		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
-			filemode = 0;
-	}
-	git_config_set("core.filemode", filemode ? "true" : "false");
-
-	if (is_bare_repository())
-		git_config_set("core.bare", "true");
-	else {
-		git_config_set("core.bare", "false");
-		/* allow template config file to override the default */
-		if (log_all_ref_updates == LOG_REFS_UNSET)
-			git_config_set("core.logallrefupdates", "true");
-		if (needs_work_tree_config(original_git_dir, work_tree))
-			git_config_set("core.worktree", work_tree);
-	}
-
-	if (!reinit) {
-		/* Check if symlink is supported in the work tree */
-		path = git_path_buf(&buf, "tXXXXXX");
-		if (!close(xmkstemp(path)) &&
-		    !unlink(path) &&
-		    !symlink("testing", path) &&
-		    !lstat(path, &st1) &&
-		    S_ISLNK(st1.st_mode))
-			unlink(path); /* good */
-		else
-			git_config_set("core.symlinks", "false");
-
-		/* Check if the filesystem is case-insensitive */
-		path = git_path_buf(&buf, "CoNfIg");
-		if (!access(path, F_OK))
-			git_config_set("core.ignorecase", "true");
-		probe_utf8_pathname_composition();
-	}
-
-	strbuf_release(&buf);
-	return reinit;
-}
-
-static void create_object_directory(void)
-{
-	struct strbuf path = STRBUF_INIT;
-	size_t baselen;
-
-	strbuf_addstr(&path, get_object_directory());
-	baselen = path.len;
-
-	safe_create_dir(path.buf, 1);
-
-	strbuf_setlen(&path, baselen);
-	strbuf_addstr(&path, "/pack");
-	safe_create_dir(path.buf, 1);
-
-	strbuf_setlen(&path, baselen);
-	strbuf_addstr(&path, "/info");
-	safe_create_dir(path.buf, 1);
-
-	strbuf_release(&path);
-}
-
-static void separate_git_dir(const char *git_dir, const char *git_link)
-{
-	struct stat st;
-
-	if (!stat(git_link, &st)) {
-		const char *src;
-
-		if (S_ISREG(st.st_mode))
-			src = read_gitfile(git_link);
-		else if (S_ISDIR(st.st_mode))
-			src = git_link;
-		else
-			die(_("unable to handle file type %d"), (int)st.st_mode);
-
-		if (rename(src, git_dir))
-			die_errno(_("unable to move %s to %s"), src, git_dir);
-		repair_worktrees(NULL, NULL);
-	}
-
-	write_file(git_link, "gitdir: %s", git_dir);
-}
-
-static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
-{
-	const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
-	/*
-	 * If we already have an initialized repo, don't allow the user to
-	 * specify a different algorithm, as that could cause corruption.
-	 * Otherwise, if the user has specified one on the command line, use it.
-	 */
-	if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
-		die(_("attempt to reinitialize repository with different hash"));
-	else if (hash != GIT_HASH_UNKNOWN)
-		repo_fmt->hash_algo = hash;
-	else if (env) {
-		int env_algo = hash_algo_by_name(env);
-		if (env_algo == GIT_HASH_UNKNOWN)
-			die(_("unknown hash algorithm '%s'"), env);
-		repo_fmt->hash_algo = env_algo;
-	}
-}
-
-int init_db(const char *git_dir, const char *real_git_dir,
-	    const char *template_dir, int hash, const char *initial_branch,
-	    int init_shared_repository, unsigned int flags)
-{
-	int reinit;
-	int exist_ok = flags & INIT_DB_EXIST_OK;
-	char *original_git_dir = real_pathdup(git_dir, 1);
-	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
-
-	if (real_git_dir) {
-		struct stat st;
-
-		if (!exist_ok && !stat(git_dir, &st))
-			die(_("%s already exists"), git_dir);
-
-		if (!exist_ok && !stat(real_git_dir, &st))
-			die(_("%s already exists"), real_git_dir);
-
-		set_git_dir(real_git_dir, 1);
-		git_dir = get_git_dir();
-		separate_git_dir(git_dir, original_git_dir);
-	}
-	else {
-		set_git_dir(git_dir, 1);
-		git_dir = get_git_dir();
-	}
-	startup_info->have_repository = 1;
-
-	/* Ensure `core.hidedotfiles` is processed */
-	git_config(platform_core_config, NULL);
-
-	safe_create_dir(git_dir, 0);
-
-	/* Check to see if the repository version is right.
-	 * Note that a newly created repository does not have
-	 * config file, so this will not fail.  What we are catching
-	 * is an attempt to reinitialize new repository with an old tool.
-	 */
-	check_repository_format(&repo_fmt);
-
-	validate_hash_algorithm(&repo_fmt, hash);
-
-	reinit = create_default_files(template_dir, original_git_dir,
-				      initial_branch, &repo_fmt,
-				      init_shared_repository,
-				      flags & INIT_DB_QUIET);
-	if (reinit && initial_branch)
-		warning(_("re-init: ignored --initial-branch=%s"),
-			initial_branch);
-
-	create_object_directory();
-
-	if (get_shared_repository()) {
-		char buf[10];
-		/* We do not spell "group" and such, so that
-		 * the configuration can be read by older version
-		 * of git. Note, we use octal numbers for new share modes,
-		 * and compatibility values for PERM_GROUP and
-		 * PERM_EVERYBODY.
-		 */
-		if (get_shared_repository() < 0)
-			/* force to the mode value */
-			xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
-		else if (get_shared_repository() == PERM_GROUP)
-			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
-		else if (get_shared_repository() == PERM_EVERYBODY)
-			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
-		else
-			BUG("invalid value for shared_repository");
-		git_config_set("core.sharedrepository", buf);
-		git_config_set("receive.denyNonFastforwards", "true");
-	}
-
-	if (!(flags & INIT_DB_QUIET)) {
-		int len = strlen(git_dir);
-
-		if (reinit)
-			printf(get_shared_repository()
-			       ? _("Reinitialized existing shared Git repository in %s%s\n")
-			       : _("Reinitialized existing Git repository in %s%s\n"),
-			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
-		else
-			printf(get_shared_repository()
-			       ? _("Initialized empty shared Git repository in %s%s\n")
-			       : _("Initialized empty Git repository in %s%s\n"),
-			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
-	}
-
-	free(original_git_dir);
-	return 0;
-}
-
 static int guess_repository_type(const char *git_dir)
 {
 	const char *slash;
diff --git a/cache.h b/cache.h
index 2bc1cd77d9b..8b2eb52f04e 100644
--- a/cache.h
+++ b/cache.h
@@ -322,15 +322,6 @@ void prefetch_cache_entries(const struct index_state *istate,
 extern struct index_state the_index;
 #endif
 
-#define INIT_DB_QUIET 0x0001
-#define INIT_DB_EXIST_OK 0x0002
-
-int init_db(const char *git_dir, const char *real_git_dir,
-	    const char *template_dir, int hash_algo,
-	    const char *initial_branch, int init_shared_repository,
-	    unsigned int flags);
-void initialize_repository_version(int hash_algo, int reinit);
-
 /* Initialize and use the cache information */
 struct lock_file;
 void preload_index(struct index_state *index,
diff --git a/setup.c b/setup.c
index 59abc16ba6d..0c14a4fe765 100644
--- a/setup.c
+++ b/setup.c
@@ -1,8 +1,11 @@
 #include "git-compat-util.h"
 #include "abspath.h"
+#include "copy.h"
 #include "environment.h"
+#include "exec-cmd.h"
 #include "gettext.h"
 #include "object-name.h"
+#include "refs.h"
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
@@ -12,6 +15,7 @@
 #include "promisor-remote.h"
 #include "quote.h"
 #include "trace2.h"
+#include "worktree.h"
 #include "wrapper.h"
 
 static int inside_git_dir = -1;
@@ -1706,3 +1710,478 @@ int daemonize(void)
 	return 0;
 #endif
 }
+
+#ifndef DEFAULT_GIT_TEMPLATE_DIR
+#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
+#endif
+
+#ifdef NO_TRUSTABLE_FILEMODE
+#define TEST_FILEMODE 0
+#else
+#define TEST_FILEMODE 1
+#endif
+
+#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
+
+static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
+			     DIR *dir)
+{
+	size_t path_baselen = path->len;
+	size_t template_baselen = template_path->len;
+	struct dirent *de;
+
+	/* Note: if ".git/hooks" file exists in the repository being
+	 * re-initialized, /etc/core-git/templates/hooks/update would
+	 * cause "git init" to fail here.  I think this is sane but
+	 * it means that the set of templates we ship by default, along
+	 * with the way the namespace under .git/ is organized, should
+	 * be really carefully chosen.
+	 */
+	safe_create_dir(path->buf, 1);
+	while ((de = readdir(dir)) != NULL) {
+		struct stat st_git, st_template;
+		int exists = 0;
+
+		strbuf_setlen(path, path_baselen);
+		strbuf_setlen(template_path, template_baselen);
+
+		if (de->d_name[0] == '.')
+			continue;
+		strbuf_addstr(path, de->d_name);
+		strbuf_addstr(template_path, de->d_name);
+		if (lstat(path->buf, &st_git)) {
+			if (errno != ENOENT)
+				die_errno(_("cannot stat '%s'"), path->buf);
+		}
+		else
+			exists = 1;
+
+		if (lstat(template_path->buf, &st_template))
+			die_errno(_("cannot stat template '%s'"), template_path->buf);
+
+		if (S_ISDIR(st_template.st_mode)) {
+			DIR *subdir = opendir(template_path->buf);
+			if (!subdir)
+				die_errno(_("cannot opendir '%s'"), template_path->buf);
+			strbuf_addch(path, '/');
+			strbuf_addch(template_path, '/');
+			copy_templates_1(path, template_path, subdir);
+			closedir(subdir);
+		}
+		else if (exists)
+			continue;
+		else if (S_ISLNK(st_template.st_mode)) {
+			struct strbuf lnk = STRBUF_INIT;
+			if (strbuf_readlink(&lnk, template_path->buf,
+					    st_template.st_size) < 0)
+				die_errno(_("cannot readlink '%s'"), template_path->buf);
+			if (symlink(lnk.buf, path->buf))
+				die_errno(_("cannot symlink '%s' '%s'"),
+					  lnk.buf, path->buf);
+			strbuf_release(&lnk);
+		}
+		else if (S_ISREG(st_template.st_mode)) {
+			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
+				die_errno(_("cannot copy '%s' to '%s'"),
+					  template_path->buf, path->buf);
+		}
+		else
+			error(_("ignoring template %s"), template_path->buf);
+	}
+}
+
+static void copy_templates(const char *template_dir, const char *init_template_dir)
+{
+	struct strbuf path = STRBUF_INIT;
+	struct strbuf template_path = STRBUF_INIT;
+	size_t template_len;
+	struct repository_format template_format = REPOSITORY_FORMAT_INIT;
+	struct strbuf err = STRBUF_INIT;
+	DIR *dir;
+	char *to_free = NULL;
+
+	if (!template_dir)
+		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
+	if (!template_dir)
+		template_dir = init_template_dir;
+	if (!template_dir)
+		template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
+	if (!template_dir[0]) {
+		free(to_free);
+		return;
+	}
+
+	strbuf_addstr(&template_path, template_dir);
+	strbuf_complete(&template_path, '/');
+	template_len = template_path.len;
+
+	dir = opendir(template_path.buf);
+	if (!dir) {
+		warning(_("templates not found in %s"), template_dir);
+		goto free_return;
+	}
+
+	/* Make sure that template is from the correct vintage */
+	strbuf_addstr(&template_path, "config");
+	read_repository_format(&template_format, template_path.buf);
+	strbuf_setlen(&template_path, template_len);
+
+	/*
+	 * No mention of version at all is OK, but anything else should be
+	 * verified.
+	 */
+	if (template_format.version >= 0 &&
+	    verify_repository_format(&template_format, &err) < 0) {
+		warning(_("not copying templates from '%s': %s"),
+			  template_dir, err.buf);
+		strbuf_release(&err);
+		goto close_free_return;
+	}
+
+	strbuf_addstr(&path, get_git_common_dir());
+	strbuf_complete(&path, '/');
+	copy_templates_1(&path, &template_path, dir);
+close_free_return:
+	closedir(dir);
+free_return:
+	free(to_free);
+	strbuf_release(&path);
+	strbuf_release(&template_path);
+	clear_repository_format(&template_format);
+}
+
+/*
+ * If the git_dir is not directly inside the working tree, then git will not
+ * find it by default, and we need to set the worktree explicitly.
+ */
+static int needs_work_tree_config(const char *git_dir, const char *work_tree)
+{
+	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
+		return 0;
+	if (skip_prefix(git_dir, work_tree, &git_dir) &&
+	    !strcmp(git_dir, "/.git"))
+		return 0;
+	return 1;
+}
+
+void initialize_repository_version(int hash_algo, int reinit)
+{
+	char repo_version_string[10];
+	int repo_version = GIT_REPO_VERSION;
+
+	if (hash_algo != GIT_HASH_SHA1)
+		repo_version = GIT_REPO_VERSION_READ;
+
+	/* This forces creation of new config file */
+	xsnprintf(repo_version_string, sizeof(repo_version_string),
+		  "%d", repo_version);
+	git_config_set("core.repositoryformatversion", repo_version_string);
+
+	if (hash_algo != GIT_HASH_SHA1)
+		git_config_set("extensions.objectformat",
+			       hash_algos[hash_algo].name);
+	else if (reinit)
+		git_config_set_gently("extensions.objectformat", NULL);
+}
+
+static int create_default_files(const char *template_path,
+				const char *original_git_dir,
+				const char *initial_branch,
+				const struct repository_format *fmt,
+				int init_shared_repository,
+				int quiet)
+{
+	struct stat st1;
+	struct strbuf buf = STRBUF_INIT;
+	char *path;
+	char junk[2];
+	int reinit;
+	int filemode;
+	struct strbuf err = STRBUF_INIT;
+	const char *init_template_dir = NULL;
+	const char *work_tree = get_git_work_tree();
+
+	/*
+	 * First copy the templates -- we might have the default
+	 * config file there, in which case we would want to read
+	 * from it after installing.
+	 *
+	 * Before reading that config, we also need to clear out any cached
+	 * values (since we've just potentially changed what's available on
+	 * disk).
+	 */
+	git_config_get_pathname("init.templatedir", &init_template_dir);
+	copy_templates(template_path, init_template_dir);
+	free((char *)init_template_dir);
+	git_config_clear();
+	reset_shared_repository();
+	git_config(git_default_config, NULL);
+
+	/*
+	 * We must make sure command-line options continue to override any
+	 * values we might have just re-read from the config.
+	 */
+	if (init_shared_repository != -1)
+		set_shared_repository(init_shared_repository);
+	/*
+	 * TODO: heed core.bare from config file in templates if no
+	 *       command-line override given
+	 *
+	 * Unfortunately, this location in the code is far too late to
+	 * allow this to happen; both builtin/init.db and
+	 * builtin/clone.c setup the new repository and call
+	 * set_git_work_tree() before this point.  (Note that both do
+	 * that repository setup before calling init_db(), which in
+	 * turn calls create_default_files().)  Fixing it would
+	 * require too much refactoring, and no one seems to have
+	 * wanted this behavior in 15+ years, so we'll continue
+	 * ignoring the config for now and just override
+	 * is_bare_repository_cfg unconditionally.
+	 */
+	is_bare_repository_cfg = is_bare_repository() || !work_tree;
+
+	/*
+	 * We would have created the above under user's umask -- under
+	 * shared-repository settings, we would need to fix them up.
+	 */
+	if (get_shared_repository()) {
+		adjust_shared_perm(get_git_dir());
+	}
+
+	/*
+	 * We need to create a "refs" dir in any case so that older
+	 * versions of git can tell that this is a repository.
+	 */
+	safe_create_dir(git_path("refs"), 1);
+	adjust_shared_perm(git_path("refs"));
+
+	if (refs_init_db(&err))
+		die("failed to set up refs db: %s", err.buf);
+
+	/*
+	 * Point the HEAD symref to the initial branch with if HEAD does
+	 * not yet exist.
+	 */
+	path = git_path_buf(&buf, "HEAD");
+	reinit = (!access(path, R_OK)
+		  || readlink(path, junk, sizeof(junk)-1) != -1);
+	if (!reinit) {
+		char *ref;
+
+		if (!initial_branch)
+			initial_branch = git_default_branch_name(quiet);
+
+		ref = xstrfmt("refs/heads/%s", initial_branch);
+		if (check_refname_format(ref, 0) < 0)
+			die(_("invalid initial branch name: '%s'"),
+			    initial_branch);
+
+		if (create_symref("HEAD", ref, NULL) < 0)
+			exit(1);
+		free(ref);
+	}
+
+	initialize_repository_version(fmt->hash_algo, 0);
+
+	/* Check filemode trustability */
+	path = git_path_buf(&buf, "config");
+	filemode = TEST_FILEMODE;
+	if (TEST_FILEMODE && !lstat(path, &st1)) {
+		struct stat st2;
+		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
+				!lstat(path, &st2) &&
+				st1.st_mode != st2.st_mode &&
+				!chmod(path, st1.st_mode));
+		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
+			filemode = 0;
+	}
+	git_config_set("core.filemode", filemode ? "true" : "false");
+
+	if (is_bare_repository())
+		git_config_set("core.bare", "true");
+	else {
+		git_config_set("core.bare", "false");
+		/* allow template config file to override the default */
+		if (log_all_ref_updates == LOG_REFS_UNSET)
+			git_config_set("core.logallrefupdates", "true");
+		if (needs_work_tree_config(original_git_dir, work_tree))
+			git_config_set("core.worktree", work_tree);
+	}
+
+	if (!reinit) {
+		/* Check if symlink is supported in the work tree */
+		path = git_path_buf(&buf, "tXXXXXX");
+		if (!close(xmkstemp(path)) &&
+		    !unlink(path) &&
+		    !symlink("testing", path) &&
+		    !lstat(path, &st1) &&
+		    S_ISLNK(st1.st_mode))
+			unlink(path); /* good */
+		else
+			git_config_set("core.symlinks", "false");
+
+		/* Check if the filesystem is case-insensitive */
+		path = git_path_buf(&buf, "CoNfIg");
+		if (!access(path, F_OK))
+			git_config_set("core.ignorecase", "true");
+		probe_utf8_pathname_composition();
+	}
+
+	strbuf_release(&buf);
+	return reinit;
+}
+
+static void create_object_directory(void)
+{
+	struct strbuf path = STRBUF_INIT;
+	size_t baselen;
+
+	strbuf_addstr(&path, get_object_directory());
+	baselen = path.len;
+
+	safe_create_dir(path.buf, 1);
+
+	strbuf_setlen(&path, baselen);
+	strbuf_addstr(&path, "/pack");
+	safe_create_dir(path.buf, 1);
+
+	strbuf_setlen(&path, baselen);
+	strbuf_addstr(&path, "/info");
+	safe_create_dir(path.buf, 1);
+
+	strbuf_release(&path);
+}
+
+static void separate_git_dir(const char *git_dir, const char *git_link)
+{
+	struct stat st;
+
+	if (!stat(git_link, &st)) {
+		const char *src;
+
+		if (S_ISREG(st.st_mode))
+			src = read_gitfile(git_link);
+		else if (S_ISDIR(st.st_mode))
+			src = git_link;
+		else
+			die(_("unable to handle file type %d"), (int)st.st_mode);
+
+		if (rename(src, git_dir))
+			die_errno(_("unable to move %s to %s"), src, git_dir);
+		repair_worktrees(NULL, NULL);
+	}
+
+	write_file(git_link, "gitdir: %s", git_dir);
+}
+
+static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
+{
+	const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
+	/*
+	 * If we already have an initialized repo, don't allow the user to
+	 * specify a different algorithm, as that could cause corruption.
+	 * Otherwise, if the user has specified one on the command line, use it.
+	 */
+	if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
+		die(_("attempt to reinitialize repository with different hash"));
+	else if (hash != GIT_HASH_UNKNOWN)
+		repo_fmt->hash_algo = hash;
+	else if (env) {
+		int env_algo = hash_algo_by_name(env);
+		if (env_algo == GIT_HASH_UNKNOWN)
+			die(_("unknown hash algorithm '%s'"), env);
+		repo_fmt->hash_algo = env_algo;
+	}
+}
+
+int init_db(const char *git_dir, const char *real_git_dir,
+	    const char *template_dir, int hash, const char *initial_branch,
+	    int init_shared_repository, unsigned int flags)
+{
+	int reinit;
+	int exist_ok = flags & INIT_DB_EXIST_OK;
+	char *original_git_dir = real_pathdup(git_dir, 1);
+	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+
+	if (real_git_dir) {
+		struct stat st;
+
+		if (!exist_ok && !stat(git_dir, &st))
+			die(_("%s already exists"), git_dir);
+
+		if (!exist_ok && !stat(real_git_dir, &st))
+			die(_("%s already exists"), real_git_dir);
+
+		set_git_dir(real_git_dir, 1);
+		git_dir = get_git_dir();
+		separate_git_dir(git_dir, original_git_dir);
+	}
+	else {
+		set_git_dir(git_dir, 1);
+		git_dir = get_git_dir();
+	}
+	startup_info->have_repository = 1;
+
+	/* Ensure `core.hidedotfiles` is processed */
+	git_config(platform_core_config, NULL);
+
+	safe_create_dir(git_dir, 0);
+
+	/* Check to see if the repository version is right.
+	 * Note that a newly created repository does not have
+	 * config file, so this will not fail.  What we are catching
+	 * is an attempt to reinitialize new repository with an old tool.
+	 */
+	check_repository_format(&repo_fmt);
+
+	validate_hash_algorithm(&repo_fmt, hash);
+
+	reinit = create_default_files(template_dir, original_git_dir,
+				      initial_branch, &repo_fmt,
+				      init_shared_repository,
+				      flags & INIT_DB_QUIET);
+	if (reinit && initial_branch)
+		warning(_("re-init: ignored --initial-branch=%s"),
+			initial_branch);
+
+	create_object_directory();
+
+	if (get_shared_repository()) {
+		char buf[10];
+		/* We do not spell "group" and such, so that
+		 * the configuration can be read by older version
+		 * of git. Note, we use octal numbers for new share modes,
+		 * and compatibility values for PERM_GROUP and
+		 * PERM_EVERYBODY.
+		 */
+		if (get_shared_repository() < 0)
+			/* force to the mode value */
+			xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
+		else if (get_shared_repository() == PERM_GROUP)
+			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
+		else if (get_shared_repository() == PERM_EVERYBODY)
+			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
+		else
+			BUG("invalid value for shared_repository");
+		git_config_set("core.sharedrepository", buf);
+		git_config_set("receive.denyNonFastforwards", "true");
+	}
+
+	if (!(flags & INIT_DB_QUIET)) {
+		int len = strlen(git_dir);
+
+		if (reinit)
+			printf(get_shared_repository()
+			       ? _("Reinitialized existing shared Git repository in %s%s\n")
+			       : _("Reinitialized existing Git repository in %s%s\n"),
+			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+		else
+			printf(get_shared_repository()
+			       ? _("Initialized empty shared Git repository in %s%s\n")
+			       : _("Initialized empty Git repository in %s%s\n"),
+			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+	}
+
+	free(original_git_dir);
+	return 0;
+}
diff --git a/setup.h b/setup.h
index 4c1ca9d0c94..58fd2605dd2 100644
--- a/setup.h
+++ b/setup.h
@@ -140,6 +140,15 @@ int verify_repository_format(const struct repository_format *format,
  */
 void check_repository_format(struct repository_format *fmt);
 
+#define INIT_DB_QUIET 0x0001
+#define INIT_DB_EXIST_OK 0x0002
+
+int init_db(const char *git_dir, const char *real_git_dir,
+	    const char *template_dir, int hash_algo,
+	    const char *initial_branch, int init_shared_repository,
+	    unsigned int flags);
+void initialize_repository_version(int hash_algo, int reinit);
+
 /*
  * NOTE NOTE NOTE!!
  *
-- 
gitgitgadget


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

* [PATCH 04/24] read-cache: move shared commit and ls-files code
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (2 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 03/24] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 05/24] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
                   ` (23 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function overlay_tree_on_index(), plus associated helper functions,
were defined in builtin/ls-files.c, but also shared with
builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/ls-files.c | 137 ---------------------------------------------
 read-cache.c       | 137 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 137 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 625f48f0d61..069b28bd484 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -516,143 +516,6 @@ static int get_common_prefix_len(const char *common_prefix)
 	return common_prefix_len;
 }
 
-static int read_one_entry_opt(struct index_state *istate,
-			      const struct object_id *oid,
-			      struct strbuf *base,
-			      const char *pathname,
-			      unsigned mode, int opt)
-{
-	int len;
-	struct cache_entry *ce;
-
-	if (S_ISDIR(mode))
-		return READ_TREE_RECURSIVE;
-
-	len = strlen(pathname);
-	ce = make_empty_cache_entry(istate, base->len + len);
-
-	ce->ce_mode = create_ce_mode(mode);
-	ce->ce_flags = create_ce_flags(1);
-	ce->ce_namelen = base->len + len;
-	memcpy(ce->name, base->buf, base->len);
-	memcpy(ce->name + base->len, pathname, len+1);
-	oidcpy(&ce->oid, oid);
-	return add_index_entry(istate, ce, opt);
-}
-
-static int read_one_entry(const struct object_id *oid, struct strbuf *base,
-			  const char *pathname, unsigned mode,
-			  void *context)
-{
-	struct index_state *istate = context;
-	return read_one_entry_opt(istate, oid, base, pathname,
-				  mode,
-				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
-}
-
-/*
- * This is used when the caller knows there is no existing entries at
- * the stage that will conflict with the entry being added.
- */
-static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
-				const char *pathname, unsigned mode,
-				void *context)
-{
-	struct index_state *istate = context;
-	return read_one_entry_opt(istate, oid, base, pathname,
-				  mode, ADD_CACHE_JUST_APPEND);
-}
-
-/*
- * Read the tree specified with --with-tree option
- * (typically, HEAD) into stage #1 and then
- * squash them down to stage #0.  This is used for
- * --error-unmatch to list and check the path patterns
- * that were given from the command line.  We are not
- * going to write this index out.
- */
-void overlay_tree_on_index(struct index_state *istate,
-			   const char *tree_name, const char *prefix)
-{
-	struct tree *tree;
-	struct object_id oid;
-	struct pathspec pathspec;
-	struct cache_entry *last_stage0 = NULL;
-	int i;
-	read_tree_fn_t fn = NULL;
-	int err;
-
-	if (repo_get_oid(the_repository, tree_name, &oid))
-		die("tree-ish %s not found.", tree_name);
-	tree = parse_tree_indirect(&oid);
-	if (!tree)
-		die("bad tree-ish %s", tree_name);
-
-	/* Hoist the unmerged entries up to stage #3 to make room */
-	/* TODO: audit for interaction with sparse-index. */
-	ensure_full_index(istate);
-	for (i = 0; i < istate->cache_nr; i++) {
-		struct cache_entry *ce = istate->cache[i];
-		if (!ce_stage(ce))
-			continue;
-		ce->ce_flags |= CE_STAGEMASK;
-	}
-
-	if (prefix) {
-		static const char *(matchbuf[1]);
-		matchbuf[0] = NULL;
-		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
-			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
-	} else
-		memset(&pathspec, 0, sizeof(pathspec));
-
-	/*
-	 * See if we have cache entry at the stage.  If so,
-	 * do it the original slow way, otherwise, append and then
-	 * sort at the end.
-	 */
-	for (i = 0; !fn && i < istate->cache_nr; i++) {
-		const struct cache_entry *ce = istate->cache[i];
-		if (ce_stage(ce) == 1)
-			fn = read_one_entry;
-	}
-
-	if (!fn)
-		fn = read_one_entry_quick;
-	err = read_tree(the_repository, tree, &pathspec, fn, istate);
-	clear_pathspec(&pathspec);
-	if (err)
-		die("unable to read tree entries %s", tree_name);
-
-	/*
-	 * Sort the cache entry -- we need to nuke the cache tree, though.
-	 */
-	if (fn == read_one_entry_quick) {
-		cache_tree_free(&istate->cache_tree);
-		QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
-	}
-
-	for (i = 0; i < istate->cache_nr; i++) {
-		struct cache_entry *ce = istate->cache[i];
-		switch (ce_stage(ce)) {
-		case 0:
-			last_stage0 = ce;
-			/* fallthru */
-		default:
-			continue;
-		case 1:
-			/*
-			 * If there is stage #0 entry for this, we do not
-			 * need to show it.  We use CE_UPDATE bit to mark
-			 * such an entry.
-			 */
-			if (last_stage0 &&
-			    !strcmp(last_stage0->name, ce->name))
-				ce->ce_flags |= CE_UPDATE;
-		}
-	}
-}
-
 static const char * const ls_files_usage[] = {
 	N_("git ls-files [<options>] [<file>...]"),
 	NULL
diff --git a/read-cache.c b/read-cache.c
index f4c31a68c85..c0df4586c9b 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3806,3 +3806,140 @@ void prefetch_cache_entries(const struct index_state *istate,
 				   to_fetch.oid, to_fetch.nr);
 	oid_array_clear(&to_fetch);
 }
+
+static int read_one_entry_opt(struct index_state *istate,
+			      const struct object_id *oid,
+			      struct strbuf *base,
+			      const char *pathname,
+			      unsigned mode, int opt)
+{
+	int len;
+	struct cache_entry *ce;
+
+	if (S_ISDIR(mode))
+		return READ_TREE_RECURSIVE;
+
+	len = strlen(pathname);
+	ce = make_empty_cache_entry(istate, base->len + len);
+
+	ce->ce_mode = create_ce_mode(mode);
+	ce->ce_flags = create_ce_flags(1);
+	ce->ce_namelen = base->len + len;
+	memcpy(ce->name, base->buf, base->len);
+	memcpy(ce->name + base->len, pathname, len+1);
+	oidcpy(&ce->oid, oid);
+	return add_index_entry(istate, ce, opt);
+}
+
+static int read_one_entry(const struct object_id *oid, struct strbuf *base,
+			  const char *pathname, unsigned mode,
+			  void *context)
+{
+	struct index_state *istate = context;
+	return read_one_entry_opt(istate, oid, base, pathname,
+				  mode,
+				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
+}
+
+/*
+ * This is used when the caller knows there is no existing entries at
+ * the stage that will conflict with the entry being added.
+ */
+static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
+				const char *pathname, unsigned mode,
+				void *context)
+{
+	struct index_state *istate = context;
+	return read_one_entry_opt(istate, oid, base, pathname,
+				  mode, ADD_CACHE_JUST_APPEND);
+}
+
+/*
+ * Read the tree specified with --with-tree option
+ * (typically, HEAD) into stage #1 and then
+ * squash them down to stage #0.  This is used for
+ * --error-unmatch to list and check the path patterns
+ * that were given from the command line.  We are not
+ * going to write this index out.
+ */
+void overlay_tree_on_index(struct index_state *istate,
+			   const char *tree_name, const char *prefix)
+{
+	struct tree *tree;
+	struct object_id oid;
+	struct pathspec pathspec;
+	struct cache_entry *last_stage0 = NULL;
+	int i;
+	read_tree_fn_t fn = NULL;
+	int err;
+
+	if (repo_get_oid(the_repository, tree_name, &oid))
+		die("tree-ish %s not found.", tree_name);
+	tree = parse_tree_indirect(&oid);
+	if (!tree)
+		die("bad tree-ish %s", tree_name);
+
+	/* Hoist the unmerged entries up to stage #3 to make room */
+	/* TODO: audit for interaction with sparse-index. */
+	ensure_full_index(istate);
+	for (i = 0; i < istate->cache_nr; i++) {
+		struct cache_entry *ce = istate->cache[i];
+		if (!ce_stage(ce))
+			continue;
+		ce->ce_flags |= CE_STAGEMASK;
+	}
+
+	if (prefix) {
+		static const char *(matchbuf[1]);
+		matchbuf[0] = NULL;
+		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
+			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
+	} else
+		memset(&pathspec, 0, sizeof(pathspec));
+
+	/*
+	 * See if we have cache entry at the stage.  If so,
+	 * do it the original slow way, otherwise, append and then
+	 * sort at the end.
+	 */
+	for (i = 0; !fn && i < istate->cache_nr; i++) {
+		const struct cache_entry *ce = istate->cache[i];
+		if (ce_stage(ce) == 1)
+			fn = read_one_entry;
+	}
+
+	if (!fn)
+		fn = read_one_entry_quick;
+	err = read_tree(the_repository, tree, &pathspec, fn, istate);
+	clear_pathspec(&pathspec);
+	if (err)
+		die("unable to read tree entries %s", tree_name);
+
+	/*
+	 * Sort the cache entry -- we need to nuke the cache tree, though.
+	 */
+	if (fn == read_one_entry_quick) {
+		cache_tree_free(&istate->cache_tree);
+		QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
+	}
+
+	for (i = 0; i < istate->cache_nr; i++) {
+		struct cache_entry *ce = istate->cache[i];
+		switch (ce_stage(ce)) {
+		case 0:
+			last_stage0 = ce;
+			/* fallthru */
+		default:
+			continue;
+		case 1:
+			/*
+			 * If there is stage #0 entry for this, we do not
+			 * need to show it.  We use CE_UPDATE bit to mark
+			 * such an entry.
+			 */
+			if (last_stage0 &&
+			    !strcmp(last_stage0->name, ce->name))
+				ce->ce_flags |= CE_UPDATE;
+		}
+	}
+}
-- 
gitgitgadget


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

* [PATCH 05/24] add: modify add_files_to_cache() to avoid globals
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (3 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 04/24] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 06/24] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function add_files_to_cache() is used by all three of builtin/{add,
checkout, commit}.c.  That suggests this is common library code, and
should be moved somewhere else, like read-cache.c.  However, the
function and its helpers made use of two global variables that made
straight code movement difficult:
  * the_index
  * include_sparse
The latter was perhaps more problematic since it was only accessible in
builtin/add.c but was still affecting builtin/checkout.c and
builtin/commit.c without this fact being very clear from the code.  I'm
not sure if the other two callers would want to add a `--sparse` flag
similar to add.c to get non-default behavior, but exposing this
dependence will help if we ever decide we do want to add such a flag.

Modify add_files_to_cache() and its helpers to accept the necessary
arguments instead of relying on globals.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/add.c      | 22 +++++++++++++++-------
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  3 ++-
 cache.h            |  4 +++-
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index 76cc026a68a..a526eff734e 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -37,6 +37,8 @@ static int include_sparse;
 static const char *pathspec_from_file;
 
 struct update_callback_data {
+	struct index_state *index;
+	int include_sparse;
 	int flags;
 	int add_errors;
 };
@@ -100,7 +102,8 @@ static void update_callback(struct diff_queue_struct *q,
 		struct diff_filepair *p = q->queue[i];
 		const char *path = p->one->path;
 
-		if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
+		if (!data->include_sparse &&
+		    !path_in_sparse_checkout(path, data->index))
 			continue;
 
 		switch (fix_unmerged_status(p, data)) {
@@ -108,7 +111,7 @@ static void update_callback(struct diff_queue_struct *q,
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
 		case DIFF_STATUS_TYPE_CHANGED:
-			if (add_file_to_index(&the_index, path,	data->flags)) {
+			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
 				data->add_errors++;
@@ -118,7 +121,7 @@ static void update_callback(struct diff_queue_struct *q,
 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
 				break;
 			if (!(data->flags & ADD_CACHE_PRETEND))
-				remove_file_from_index(&the_index, path);
+				remove_file_from_index(data->index, path);
 			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
 				printf(_("remove '%s'\n"), path);
 			break;
@@ -126,16 +129,19 @@ static void update_callback(struct diff_queue_struct *q,
 	}
 }
 
-int add_files_to_cache(const char *prefix,
-		       const struct pathspec *pathspec, int flags)
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags)
 {
 	struct update_callback_data data;
 	struct rev_info rev;
 
 	memset(&data, 0, sizeof(data));
+	data.index = repo->index;
+	data.include_sparse = include_sparse;
 	data.flags = flags;
 
-	repo_init_revisions(the_repository, &rev, prefix);
+	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
 	if (pathspec)
 		copy_pathspec(&rev.prune_data, pathspec);
@@ -640,7 +646,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (add_renormalize)
 		exit_status |= renormalize_tracked_files(&pathspec, flags);
 	else
-		exit_status |= add_files_to_cache(prefix, &pathspec, flags);
+		exit_status |= add_files_to_cache(the_repository, prefix,
+						  &pathspec, include_sparse,
+						  flags);
 
 	if (add_new_files)
 		exit_status |= add_files(&dir, flags);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 715eeb5048f..d6765c9dbd9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -861,7 +861,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 * entries in the index.
 			 */
 
-			add_files_to_cache(NULL, NULL, 0);
+			add_files_to_cache(the_repository, NULL, NULL, 0, 0);
 			init_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index e67c4be2211..bd634ee6ad1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -447,7 +447,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
 	if (all || (also && pathspec.nr)) {
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
-		add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
+		add_files_to_cache(the_repository, also ? prefix : NULL,
+				   &pathspec, 0, 0);
 		refresh_cache_or_die(refresh_flags);
 		cache_tree_update(&the_index, WRITE_TREE_SILENT);
 		if (write_locked_index(&the_index, &index_lock, 0))
diff --git a/cache.h b/cache.h
index 8b2eb52f04e..02d69c24cd6 100644
--- a/cache.h
+++ b/cache.h
@@ -554,7 +554,9 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
  * return 0 if success, 1 - if addition of a file failed and
  * ADD_FILES_IGNORE_ERRORS was specified in flags
  */
-int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags);
 
 /* diff.c */
 extern int diff_auto_refresh_index;
-- 
gitgitgadget


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

* [PATCH 06/24] read-cache: move shared add/checkout/commit code
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (4 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 05/24] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 07/24] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function add_files_to_cache(), plus associated helper functions,
were defined in builtin/add.c, but also shared with builtin/checkout.c
and builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/add.c | 100 -------------------------------------------------
 read-cache.c  | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 100 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index a526eff734e..36ddbb159bf 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -36,13 +36,6 @@ static int pathspec_file_nul;
 static int include_sparse;
 static const char *pathspec_from_file;
 
-struct update_callback_data {
-	struct index_state *index;
-	int include_sparse;
-	int flags;
-	int add_errors;
-};
-
 static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 {
 	int i, ret = 0;
@@ -71,99 +64,6 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 	return ret;
 }
 
-static int fix_unmerged_status(struct diff_filepair *p,
-			       struct update_callback_data *data)
-{
-	if (p->status != DIFF_STATUS_UNMERGED)
-		return p->status;
-	if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
-		/*
-		 * This is not an explicit add request, and the
-		 * path is missing from the working tree (deleted)
-		 */
-		return DIFF_STATUS_DELETED;
-	else
-		/*
-		 * Either an explicit add request, or path exists
-		 * in the working tree.  An attempt to explicitly
-		 * add a path that does not exist in the working tree
-		 * will be caught as an error by the caller immediately.
-		 */
-		return DIFF_STATUS_MODIFIED;
-}
-
-static void update_callback(struct diff_queue_struct *q,
-			    struct diff_options *opt UNUSED, void *cbdata)
-{
-	int i;
-	struct update_callback_data *data = cbdata;
-
-	for (i = 0; i < q->nr; i++) {
-		struct diff_filepair *p = q->queue[i];
-		const char *path = p->one->path;
-
-		if (!data->include_sparse &&
-		    !path_in_sparse_checkout(path, data->index))
-			continue;
-
-		switch (fix_unmerged_status(p, data)) {
-		default:
-			die(_("unexpected diff status %c"), p->status);
-		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
-			if (add_file_to_index(data->index, path, data->flags)) {
-				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
-					die(_("updating files failed"));
-				data->add_errors++;
-			}
-			break;
-		case DIFF_STATUS_DELETED:
-			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
-				break;
-			if (!(data->flags & ADD_CACHE_PRETEND))
-				remove_file_from_index(data->index, path);
-			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
-				printf(_("remove '%s'\n"), path);
-			break;
-		}
-	}
-}
-
-int add_files_to_cache(struct repository *repo, const char *prefix,
-		       const struct pathspec *pathspec, int include_sparse,
-		       int flags)
-{
-	struct update_callback_data data;
-	struct rev_info rev;
-
-	memset(&data, 0, sizeof(data));
-	data.index = repo->index;
-	data.include_sparse = include_sparse;
-	data.flags = flags;
-
-	repo_init_revisions(repo, &rev, prefix);
-	setup_revisions(0, NULL, &rev, NULL);
-	if (pathspec)
-		copy_pathspec(&rev.prune_data, pathspec);
-	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
-	rev.diffopt.format_callback = update_callback;
-	rev.diffopt.format_callback_data = &data;
-	rev.diffopt.flags.override_submodule_config = 1;
-	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
-
-	/*
-	 * Use an ODB transaction to optimize adding multiple objects.
-	 * This function is invoked from commands other than 'add', which
-	 * may not have their own transaction active.
-	 */
-	begin_odb_transaction();
-	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
-	end_odb_transaction();
-
-	release_revisions(&rev);
-	return !!data.add_errors;
-}
-
 static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
 {
 	int i, retval = 0;
diff --git a/read-cache.c b/read-cache.c
index c0df4586c9b..bfbd531ea60 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "alloc.h"
+#include "bulk-checkin.h"
 #include "config.h"
 #include "date.h"
 #include "diff.h"
@@ -26,6 +27,7 @@
 #include "mem-pool.h"
 #include "object-name.h"
 #include "resolve-undo.h"
+#include "revision.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "trace2.h"
@@ -3943,3 +3945,103 @@ void overlay_tree_on_index(struct index_state *istate,
 		}
 	}
 }
+
+struct update_callback_data {
+	struct index_state *index;
+	int include_sparse;
+	int flags;
+	int add_errors;
+};
+
+static int fix_unmerged_status(struct diff_filepair *p,
+			       struct update_callback_data *data)
+{
+	if (p->status != DIFF_STATUS_UNMERGED)
+		return p->status;
+	if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
+		/*
+		 * This is not an explicit add request, and the
+		 * path is missing from the working tree (deleted)
+		 */
+		return DIFF_STATUS_DELETED;
+	else
+		/*
+		 * Either an explicit add request, or path exists
+		 * in the working tree.  An attempt to explicitly
+		 * add a path that does not exist in the working tree
+		 * will be caught as an error by the caller immediately.
+		 */
+		return DIFF_STATUS_MODIFIED;
+}
+
+static void update_callback(struct diff_queue_struct *q,
+			    struct diff_options *opt UNUSED, void *cbdata)
+{
+	int i;
+	struct update_callback_data *data = cbdata;
+
+	for (i = 0; i < q->nr; i++) {
+		struct diff_filepair *p = q->queue[i];
+		const char *path = p->one->path;
+
+		if (!data->include_sparse &&
+		    !path_in_sparse_checkout(path, data->index))
+			continue;
+
+		switch (fix_unmerged_status(p, data)) {
+		default:
+			die(_("unexpected diff status %c"), p->status);
+		case DIFF_STATUS_MODIFIED:
+		case DIFF_STATUS_TYPE_CHANGED:
+			if (add_file_to_index(data->index, path, data->flags)) {
+				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
+					die(_("updating files failed"));
+				data->add_errors++;
+			}
+			break;
+		case DIFF_STATUS_DELETED:
+			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
+				break;
+			if (!(data->flags & ADD_CACHE_PRETEND))
+				remove_file_from_index(data->index, path);
+			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
+				printf(_("remove '%s'\n"), path);
+			break;
+		}
+	}
+}
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags)
+{
+	struct update_callback_data data;
+	struct rev_info rev;
+
+	memset(&data, 0, sizeof(data));
+	data.index = repo->index;
+	data.include_sparse = include_sparse;
+	data.flags = flags;
+
+	repo_init_revisions(repo, &rev, prefix);
+	setup_revisions(0, NULL, &rev, NULL);
+	if (pathspec)
+		copy_pathspec(&rev.prune_data, pathspec);
+	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
+	rev.diffopt.format_callback = update_callback;
+	rev.diffopt.format_callback_data = &data;
+	rev.diffopt.flags.override_submodule_config = 1;
+	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+	/*
+	 * Use an ODB transaction to optimize adding multiple objects.
+	 * This function is invoked from commands other than 'add', which
+	 * may not have their own transaction active.
+	 */
+	begin_odb_transaction();
+	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+	end_odb_transaction();
+
+	release_revisions(&rev);
+	return !!data.add_errors;
+}
-- 
gitgitgadget


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

* [PATCH 07/24] statinfo: move stat_{data,validity} functions from cache/read-cache
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (5 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 06/24] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 08/24] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

These functions do not depend upon struct cache_entry or struct
index_state in any way, and it seems more logical to break them out into
this file, especially since statinfo.h already has the struct stat_data
declaration.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Makefile              |  1 +
 cache.h               | 48 ------------------------
 object.c              |  1 +
 read-cache.c          | 84 -----------------------------------------
 refs/packed-backend.c |  1 +
 shallow.c             |  1 +
 statinfo.c            | 87 +++++++++++++++++++++++++++++++++++++++++++
 statinfo.h            | 51 +++++++++++++++++++++++++
 8 files changed, 142 insertions(+), 132 deletions(-)
 create mode 100644 statinfo.c

diff --git a/Makefile b/Makefile
index e440728c246..cbc7f212016 100644
--- a/Makefile
+++ b/Makefile
@@ -1142,6 +1142,7 @@ LIB_OBJS += sigchain.o
 LIB_OBJS += sparse-index.o
 LIB_OBJS += split-index.o
 LIB_OBJS += stable-qsort.o
+LIB_OBJS += statinfo.o
 LIB_OBJS += strbuf.o
 LIB_OBJS += streaming.o
 LIB_OBJS += string-list.o
diff --git a/cache.h b/cache.h
index 02d69c24cd6..891e5fec744 100644
--- a/cache.h
+++ b/cache.h
@@ -488,19 +488,6 @@ int has_racy_timestamp(struct index_state *istate);
 int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
 int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
 
-/*
- * Record to sd the data from st that we use to check whether a file
- * might have changed.
- */
-void fill_stat_data(struct stat_data *sd, struct stat *st);
-
-/*
- * Return 0 if st is consistent with a file not having been changed
- * since sd was filled.  If there are differences, return a
- * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
- * INODE_CHANGED, and DATA_CHANGED.
- */
-int match_stat_data(const struct stat_data *sd, struct stat *st);
 int match_stat_data_racy(const struct index_state *istate,
 			 const struct stat_data *sd, struct stat *st);
 
@@ -539,14 +526,6 @@ void set_alternate_index_output(const char *);
 extern int verify_index_checksum;
 extern int verify_ce_order;
 
-#define MTIME_CHANGED	0x0001
-#define CTIME_CHANGED	0x0002
-#define OWNER_CHANGED	0x0004
-#define MODE_CHANGED    0x0008
-#define INODE_CHANGED   0x0010
-#define DATA_CHANGED    0x0020
-#define TYPE_CHANGED    0x0040
-
 int cmp_cache_name_compare(const void *a_, const void *b_);
 
 /* add */
@@ -579,31 +558,4 @@ int checkout_fast_forward(struct repository *r,
 
 int sane_execvp(const char *file, char *const argv[]);
 
-/*
- * A struct to encapsulate the concept of whether a file has changed
- * since we last checked it. This uses criteria similar to those used
- * for the index.
- */
-struct stat_validity {
-	struct stat_data *sd;
-};
-
-void stat_validity_clear(struct stat_validity *sv);
-
-/*
- * Returns 1 if the path is a regular file (or a symlink to a regular
- * file) and matches the saved stat_validity, 0 otherwise.  A missing
- * or inaccessible file is considered a match if the struct was just
- * initialized, or if the previous update found an inaccessible file.
- */
-int stat_validity_check(struct stat_validity *sv, const char *path);
-
-/*
- * Update the stat_validity from a file opened at descriptor fd. If
- * the file is missing, inaccessible, or not a regular file, then
- * future calls to stat_validity_check will match iff one of those
- * conditions continues to be true.
- */
-void stat_validity_update(struct stat_validity *sv, int fd);
-
 #endif /* CACHE_H */
diff --git a/object.c b/object.c
index 6d4ef1524de..333e736fb24 100644
--- a/object.c
+++ b/object.c
@@ -6,6 +6,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "blob.h"
+#include "statinfo.h"
 #include "tree.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/read-cache.c b/read-cache.c
index bfbd531ea60..b99dbfd16b0 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -177,61 +177,6 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
 		add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
 
-void fill_stat_data(struct stat_data *sd, struct stat *st)
-{
-	sd->sd_ctime.sec = (unsigned int)st->st_ctime;
-	sd->sd_mtime.sec = (unsigned int)st->st_mtime;
-	sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
-	sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
-	sd->sd_dev = st->st_dev;
-	sd->sd_ino = st->st_ino;
-	sd->sd_uid = st->st_uid;
-	sd->sd_gid = st->st_gid;
-	sd->sd_size = st->st_size;
-}
-
-int match_stat_data(const struct stat_data *sd, struct stat *st)
-{
-	int changed = 0;
-
-	if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
-		changed |= MTIME_CHANGED;
-	if (trust_ctime && check_stat &&
-	    sd->sd_ctime.sec != (unsigned int)st->st_ctime)
-		changed |= CTIME_CHANGED;
-
-#ifdef USE_NSEC
-	if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
-		changed |= MTIME_CHANGED;
-	if (trust_ctime && check_stat &&
-	    sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
-		changed |= CTIME_CHANGED;
-#endif
-
-	if (check_stat) {
-		if (sd->sd_uid != (unsigned int) st->st_uid ||
-			sd->sd_gid != (unsigned int) st->st_gid)
-			changed |= OWNER_CHANGED;
-		if (sd->sd_ino != (unsigned int) st->st_ino)
-			changed |= INODE_CHANGED;
-	}
-
-#ifdef USE_STDEV
-	/*
-	 * st_dev breaks on network filesystems where different
-	 * clients will have different views of what "device"
-	 * the filesystem is on
-	 */
-	if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
-			changed |= INODE_CHANGED;
-#endif
-
-	if (sd->sd_size != (unsigned int) st->st_size)
-		changed |= DATA_CHANGED;
-
-	return changed;
-}
-
 /*
  * This only updates the "non-critical" parts of the directory
  * cache, ie the parts that aren't tracked by GIT, and only used
@@ -3536,35 +3481,6 @@ void *read_blob_data_from_index(struct index_state *istate,
 	return data;
 }
 
-void stat_validity_clear(struct stat_validity *sv)
-{
-	FREE_AND_NULL(sv->sd);
-}
-
-int stat_validity_check(struct stat_validity *sv, const char *path)
-{
-	struct stat st;
-
-	if (stat(path, &st) < 0)
-		return sv->sd == NULL;
-	if (!sv->sd)
-		return 0;
-	return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
-}
-
-void stat_validity_update(struct stat_validity *sv, int fd)
-{
-	struct stat st;
-
-	if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
-		stat_validity_clear(sv);
-	else {
-		if (!sv->sd)
-			CALLOC_ARRAY(sv->sd, 1);
-		fill_stat_data(sv->sd, &st);
-	}
-}
-
 void move_index_extensions(struct index_state *dst, struct index_state *src)
 {
 	dst->untracked = src->untracked;
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 704424f55c0..085becf773e 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -10,6 +10,7 @@
 #include "../iterator.h"
 #include "../lockfile.h"
 #include "../chdir-notify.h"
+#include "../statinfo.h"
 #include "../wrapper.h"
 #include "../write-or-die.h"
 
diff --git a/shallow.c b/shallow.c
index 128f56179ed..a2ebf0af2ba 100644
--- a/shallow.c
+++ b/shallow.c
@@ -17,6 +17,7 @@
 #include "list-objects.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "statinfo.h"
 #include "trace.h"
 #include "wrapper.h"
 
diff --git a/statinfo.c b/statinfo.c
new file mode 100644
index 00000000000..17bb8966c33
--- /dev/null
+++ b/statinfo.c
@@ -0,0 +1,87 @@
+#include "git-compat-util.h"
+#include "environment.h"
+#include "statinfo.h"
+
+void fill_stat_data(struct stat_data *sd, struct stat *st)
+{
+	sd->sd_ctime.sec = (unsigned int)st->st_ctime;
+	sd->sd_mtime.sec = (unsigned int)st->st_mtime;
+	sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
+	sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
+	sd->sd_dev = st->st_dev;
+	sd->sd_ino = st->st_ino;
+	sd->sd_uid = st->st_uid;
+	sd->sd_gid = st->st_gid;
+	sd->sd_size = st->st_size;
+}
+
+int match_stat_data(const struct stat_data *sd, struct stat *st)
+{
+	int changed = 0;
+
+	if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
+		changed |= MTIME_CHANGED;
+	if (trust_ctime && check_stat &&
+	    sd->sd_ctime.sec != (unsigned int)st->st_ctime)
+		changed |= CTIME_CHANGED;
+
+#ifdef USE_NSEC
+	if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
+		changed |= MTIME_CHANGED;
+	if (trust_ctime && check_stat &&
+	    sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
+		changed |= CTIME_CHANGED;
+#endif
+
+	if (check_stat) {
+		if (sd->sd_uid != (unsigned int) st->st_uid ||
+			sd->sd_gid != (unsigned int) st->st_gid)
+			changed |= OWNER_CHANGED;
+		if (sd->sd_ino != (unsigned int) st->st_ino)
+			changed |= INODE_CHANGED;
+	}
+
+#ifdef USE_STDEV
+	/*
+	 * st_dev breaks on network filesystems where different
+	 * clients will have different views of what "device"
+	 * the filesystem is on
+	 */
+	if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
+			changed |= INODE_CHANGED;
+#endif
+
+	if (sd->sd_size != (unsigned int) st->st_size)
+		changed |= DATA_CHANGED;
+
+	return changed;
+}
+
+void stat_validity_clear(struct stat_validity *sv)
+{
+	FREE_AND_NULL(sv->sd);
+}
+
+int stat_validity_check(struct stat_validity *sv, const char *path)
+{
+	struct stat st;
+
+	if (stat(path, &st) < 0)
+		return sv->sd == NULL;
+	if (!sv->sd)
+		return 0;
+	return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
+}
+
+void stat_validity_update(struct stat_validity *sv, int fd)
+{
+	struct stat st;
+
+	if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
+		stat_validity_clear(sv);
+	else {
+		if (!sv->sd)
+			CALLOC_ARRAY(sv->sd, 1);
+		fill_stat_data(sv->sd, &st);
+	}
+}
diff --git a/statinfo.h b/statinfo.h
index e49e3054eaa..bb9b61bc471 100644
--- a/statinfo.h
+++ b/statinfo.h
@@ -1,6 +1,8 @@
 #ifndef STATINFO_H
 #define STATINFO_H
 
+struct index_state;
+
 /*
  * The "cache_time" is just the low 32 bits of the
  * time. It doesn't matter if it overflows - we only
@@ -21,4 +23,53 @@ struct stat_data {
 	unsigned int sd_size;
 };
 
+/*
+ * A struct to encapsulate the concept of whether a file has changed
+ * since we last checked it. This uses criteria similar to those used
+ * for the index.
+ */
+struct stat_validity {
+	struct stat_data *sd;
+};
+
+#define MTIME_CHANGED	0x0001
+#define CTIME_CHANGED	0x0002
+#define OWNER_CHANGED	0x0004
+#define MODE_CHANGED    0x0008
+#define INODE_CHANGED   0x0010
+#define DATA_CHANGED    0x0020
+#define TYPE_CHANGED    0x0040
+
+/*
+ * Record to sd the data from st that we use to check whether a file
+ * might have changed.
+ */
+void fill_stat_data(struct stat_data *sd, struct stat *st);
+
+/*
+ * Return 0 if st is consistent with a file not having been changed
+ * since sd was filled.  If there are differences, return a
+ * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
+ * INODE_CHANGED, and DATA_CHANGED.
+ */
+int match_stat_data(const struct stat_data *sd, struct stat *st);
+
+void stat_validity_clear(struct stat_validity *sv);
+
+/*
+ * Returns 1 if the path is a regular file (or a symlink to a regular
+ * file) and matches the saved stat_validity, 0 otherwise.  A missing
+ * or inaccessible file is considered a match if the struct was just
+ * initialized, or if the previous update found an inaccessible file.
+ */
+int stat_validity_check(struct stat_validity *sv, const char *path);
+
+/*
+ * Update the stat_validity from a file opened at descriptor fd. If
+ * the file is missing, inaccessible, or not a regular file, then
+ * future calls to stat_validity_check will match iff one of those
+ * conditions continues to be true.
+ */
+void stat_validity_update(struct stat_validity *sv, int fd);
+
 #endif
-- 
gitgitgadget


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

* [PATCH 08/24] run-command.h: move declarations for run-command.c from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (6 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 07/24] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 09/24] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
                   ` (19 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 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       | 3 ---
 exec-cmd.c    | 3 ++-
 run-command.c | 2 +-
 run-command.h | 2 ++
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cache.h b/cache.h
index 891e5fec744..d31b1515069 100644
--- a/cache.h
+++ b/cache.h
@@ -555,7 +555,4 @@ int checkout_fast_forward(struct repository *r,
 			  const struct object_id *to,
 			  int overwrite_ignore);
 
-
-int sane_execvp(const char *file, char *const argv[]);
-
 #endif /* CACHE_H */
diff --git a/exec-cmd.c b/exec-cmd.c
index 1e34e48c0e4..1d597e84ea7 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,10 +1,11 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "path.h"
 #include "quote.h"
+#include "run-command.h"
 #include "strvec.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/run-command.c b/run-command.c
index d4247d5fcc6..1873d0ba8e7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "run-command.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/run-command.h b/run-command.h
index 072db56a4df..9e47f91d462 100644
--- a/run-command.h
+++ b/run-command.h
@@ -564,4 +564,6 @@ enum start_bg_result start_bg_command(struct child_process *cmd,
 				      void *cb_data,
 				      unsigned int timeout_sec);
 
+int sane_execvp(const char *file, char *const argv[]);
+
 #endif
-- 
gitgitgadget


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

* [PATCH 09/24] name-hash.h: move declarations for name-hash.c from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (7 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 08/24] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 10/24] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 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/mv.c                        |  1 +
 cache.h                             |  9 ---------
 dir.c                               |  1 +
 entry.c                             |  1 +
 merge-recursive.c                   |  1 +
 name-hash.c                         |  1 +
 name-hash.h                         | 16 ++++++++++++++++
 read-cache.c                        |  1 +
 sparse-index.c                      |  1 +
 t/helper/test-lazy-init-name-hash.c |  1 +
 unpack-trees.c                      |  1 +
 12 files changed, 26 insertions(+), 9 deletions(-)
 create mode 100644 name-hash.h

diff --git a/apply.c b/apply.c
index 6212ab3a1b3..3da33bb88fd 100644
--- a/apply.c
+++ b/apply.c
@@ -23,6 +23,7 @@
 #include "xdiff-interface.h"
 #include "ll-merge.h"
 #include "lockfile.h"
+#include "name-hash.h"
 #include "object-name.h"
 #include "object-file.h"
 #include "parse-options.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 665bd274485..e058b574654 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -11,6 +11,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "pathspec.h"
 #include "lockfile.h"
diff --git a/cache.h b/cache.h
index d31b1515069..316904da392 100644
--- a/cache.h
+++ b/cache.h
@@ -245,12 +245,6 @@ struct index_state {
 void index_state_init(struct index_state *istate, struct repository *r);
 void release_index(struct index_state *istate);
 
-/* Name hashing */
-int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
-void add_name_hash(struct index_state *istate, struct cache_entry *ce);
-void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
-void free_name_hash(struct index_state *istate);
-
 /* Cache entry creation and cleanup */
 
 /*
@@ -377,9 +371,6 @@ int repo_index_has_changes(struct repository *repo,
 
 int verify_path(const char *path, unsigned mode);
 int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-int index_dir_exists(struct index_state *istate, const char *name, int namelen);
-void adjust_dirname_case(struct index_state *istate, char *name);
-struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
 
 /*
  * Searches for an entry defined by name and namelen in the given index.
diff --git a/dir.c b/dir.c
index a7469df3ac7..029aab36fe8 100644
--- a/dir.c
+++ b/dir.c
@@ -13,6 +13,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/entry.c b/entry.c
index 91a540bd29f..7791cc999cc 100644
--- a/entry.c
+++ b/entry.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "name-hash.h"
 #include "streaming.h"
 #include "submodule.h"
 #include "symlinks.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8e87b6386d9..b341ba4f38d 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -23,6 +23,7 @@
 #include "ll-merge.h"
 #include "lockfile.h"
 #include "match-trees.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/name-hash.c b/name-hash.c
index fb13716e430..52ce47ea394 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "thread-utils.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/name-hash.h b/name-hash.h
new file mode 100644
index 00000000000..b1b4b0fb337
--- /dev/null
+++ b/name-hash.h
@@ -0,0 +1,16 @@
+#ifndef NAME_HASH_H
+#define NAME_HASH_H
+
+struct cache_entry;
+struct index_state;
+
+int index_dir_exists(struct index_state *istate, const char *name, int namelen);
+void adjust_dirname_case(struct index_state *istate, char *name);
+struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
+
+int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
+void add_name_hash(struct index_state *istate, struct cache_entry *ce);
+void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
+void free_name_hash(struct index_state *istate);
+
+#endif /* NAME_HASH_H */
diff --git a/read-cache.c b/read-cache.c
index b99dbfd16b0..e1016ae0317 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -25,6 +25,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "mem-pool.h"
+#include "name-hash.h"
 #include "object-name.h"
 #include "resolve-undo.h"
 #include "revision.h"
diff --git a/sparse-index.c b/sparse-index.c
index 886054729e5..60451daae80 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index b83a75d19f6..6944b7e825f 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "environment.h"
+#include "name-hash.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index e8c32a40dcb..078c53f7a13 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -7,6 +7,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "name-hash.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
-- 
gitgitgadget


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

* [PATCH 10/24] sparse-index.h: move declarations for sparse-index.c from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (8 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 09/24] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 11/24] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Note in particular that this reverses the decision made in 118a2e8bde0
("cache: move ensure_full_index() to cache.h", 2021-04-01).

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/checkout-index.c    | 1 +
 builtin/commit.c            | 1 +
 builtin/difftool.c          | 1 +
 builtin/fsck.c              | 1 +
 builtin/ls-files.c          | 1 +
 builtin/merge-index.c       | 1 +
 builtin/read-tree.c         | 1 +
 builtin/reset.c             | 1 +
 builtin/rm.c                | 1 +
 builtin/stash.c             | 1 +
 builtin/submodule--helper.c | 1 +
 builtin/update-index.c      | 1 +
 cache.h                     | 2 --
 dir.c                       | 1 +
 entry.c                     | 1 +
 merge-ort.c                 | 1 +
 merge-recursive.c           | 1 +
 resolve-undo.c              | 1 +
 revision.c                  | 1 +
 sequencer.c                 | 1 +
 sparse-index.h              | 2 ++
 21 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 9375a05539f..b1cd8bef264 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -17,6 +17,7 @@
 #include "entry.h"
 #include "parallel-checkout.h"
 #include "setup.h"
+#include "sparse-index.h"
 
 #define CHECKOUT_ALL 4
 static int nul_term_line;
diff --git a/builtin/commit.c b/builtin/commit.c
index bd634ee6ad1..02e2ef3e307 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -38,6 +38,7 @@
 #include "gpg-interface.h"
 #include "column.h"
 #include "sequencer.h"
+#include "sparse-index.h"
 #include "mailmap.h"
 #include "help.h"
 #include "commit-reach.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 0049342f5c0..2c27a59e04a 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "strbuf.h"
 #include "lockfile.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 2cd461b84c1..7134596d218 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -25,6 +25,7 @@
 #include "replace-object.h"
 #include "resolve-undo.h"
 #include "run-command.h"
+#include "sparse-index.h"
 #include "worktree.h"
 #include "pack-revindex.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 069b28bd484..45b3b0ce5d8 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -23,6 +23,7 @@
 #include "pathspec.h"
 #include "run-command.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index ab16e70f23d..d16e8aa414b 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "run-command.h"
+#include "sparse-index.h"
 
 static const char *pgm;
 static int one_shot, quiet;
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 440f19b1b87..bd1ce1d963f 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -22,6 +22,7 @@
 #include "repository.h"
 #include "resolve-undo.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/reset.c b/builtin/reset.c
index f99f32d5802..3dc41ac3327 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -29,6 +29,7 @@
 #include "unpack-trees.h"
 #include "cache-tree.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "trace.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index b4589c824c0..377a0f66ad8 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -19,6 +19,7 @@
 #include "repository.h"
 #include "string-list.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "pathspec.h"
 
diff --git a/builtin/stash.c b/builtin/stash.c
index a7e17ffe384..8856ac6d5c7 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -20,6 +20,7 @@
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "log-tree.h"
 #include "diffcore.h"
 #include "exec-cmd.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6bf8d666ce9..c58cfbfd6d3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -13,6 +13,7 @@
 #include "pathspec.h"
 #include "dir.h"
 #include "setup.h"
+#include "sparse-index.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 5fab9ad2ec4..47dc9b626ef 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -24,6 +24,7 @@
 #include "dir.h"
 #include "repository.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "split-index.h"
 #include "symlinks.h"
 #include "fsmonitor.h"
diff --git a/cache.h b/cache.h
index 316904da392..79daaa166b1 100644
--- a/cache.h
+++ b/cache.h
@@ -327,8 +327,6 @@ int read_index_from(struct index_state *, const char *path,
 		    const char *gitdir);
 int is_index_unborn(struct index_state *);
 
-void ensure_full_index(struct index_state *istate);
-
 /* For use with `write_locked_index()`. */
 #define COMMIT_LOCK		(1 << 0)
 #define SKIP_IF_UNCHANGED	(1 << 1)
diff --git a/dir.c b/dir.c
index 029aab36fe8..1e84b1e1f28 100644
--- a/dir.c
+++ b/dir.c
@@ -25,6 +25,7 @@
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule-config.h"
 #include "symlinks.h"
 #include "trace2.h"
diff --git a/entry.c b/entry.c
index 7791cc999cc..53d00386748 100644
--- a/entry.c
+++ b/entry.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "name-hash.h"
+#include "sparse-index.h"
 #include "streaming.h"
 #include "submodule.h"
 #include "symlinks.h"
diff --git a/merge-ort.c b/merge-ort.c
index 65837db77f0..4bff685e456 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -38,6 +38,7 @@
 #include "oid-array.h"
 #include "promisor-remote.h"
 #include "revision.h"
+#include "sparse-index.h"
 #include "strmap.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index b341ba4f38d..0e16e7a06df 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -29,6 +29,7 @@
 #include "object-store.h"
 #include "repository.h"
 #include "revision.h"
+#include "sparse-index.h"
 #include "string-list.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 70a6db526d2..7ec09e89d4f 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -2,6 +2,7 @@
 #include "dir.h"
 #include "hash.h"
 #include "resolve-undo.h"
+#include "sparse-index.h"
 #include "string-list.h"
 
 /* The only error case is to run out of memory in string-list */
diff --git a/revision.c b/revision.c
index b33cc1d106a..88b2f42daa6 100644
--- a/revision.c
+++ b/revision.c
@@ -32,6 +32,7 @@
 #include "packfile.h"
 #include "worktree.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "trace2.h"
 #include "commit-reach.h"
diff --git a/sequencer.c b/sequencer.c
index ff18f7f4203..cae9c75a54e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -28,6 +28,7 @@
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "quote.h"
 #include "trailer.h"
diff --git a/sparse-index.h b/sparse-index.h
index 59a92d819ec..a16f3e67d75 100644
--- a/sparse-index.h
+++ b/sparse-index.h
@@ -37,4 +37,6 @@ struct pattern_list;
  */
 void expand_index(struct index_state *istate, struct pattern_list *pl);
 
+void ensure_full_index(struct index_state *istate);
+
 #endif
-- 
gitgitgadget


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

* [PATCH 11/24] preload-index.h: move declarations for preload-index.c from elsewhere
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (9 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 10/24] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 12/24] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

We already have a preload-index.c file; move the declarations for the
functions in that file into a new preload-index.h.  These were
previously split between cache.h and repository.h.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c           |  1 +
 builtin/add.c               |  1 +
 builtin/am.c                |  1 +
 builtin/checkout.c          |  1 +
 builtin/commit.c            |  1 +
 builtin/diff-files.c        |  1 +
 builtin/diff-index.c        |  1 +
 builtin/diff.c              |  1 +
 builtin/stash.c             |  1 +
 builtin/submodule--helper.c |  1 +
 cache.h                     |  3 ---
 preload-index.c             |  1 +
 preload-index.h             | 15 +++++++++++++++
 read-cache.c                |  1 +
 repository.h                |  3 ---
 15 files changed, 27 insertions(+), 6 deletions(-)
 create mode 100644 preload-index.h

diff --git a/add-interactive.c b/add-interactive.c
index de877ca0525..99f7dc3b0d1 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -5,6 +5,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/builtin/add.c b/builtin/add.c
index 36ddbb159bf..8397be4f8de 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -17,6 +17,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "revision.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5c83f2e003f..0d8f46f8d5a 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -29,6 +29,7 @@
 #include "unpack-trees.h"
 #include "branch.h"
 #include "object-name.h"
+#include "preload-index.h"
 #include "sequencer.h"
 #include "revision.h"
 #include "merge-recursive.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d6765c9dbd9..2d72a742d9d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,6 +20,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "refs.h"
 #include "remote.h"
 #include "resolve-undo.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 02e2ef3e307..fa769045c88 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -30,6 +30,7 @@
 #include "utf8.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "unpack-trees.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index dc991f753bb..2e6b59a8bb3 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -8,6 +8,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "builtin.h"
 #include "submodule.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index b9a19bb7d38..9b98db2e77e 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -3,6 +3,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "builtin.h"
 #include "setup.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 7b64659fe79..967550739a6 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -16,6 +16,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "diffcore.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 8856ac6d5c7..06527ee8471 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -17,6 +17,7 @@
 #include "run-command.h"
 #include "dir.h"
 #include "entry.h"
+#include "preload-index.h"
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c58cfbfd6d3..597e780a93a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
+#include "preload-index.h"
 #include "dir.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/cache.h b/cache.h
index 79daaa166b1..b79802a4639 100644
--- a/cache.h
+++ b/cache.h
@@ -318,9 +318,6 @@ extern struct index_state the_index;
 
 /* Initialize and use the cache information */
 struct lock_file;
-void preload_index(struct index_state *index,
-		   const struct pathspec *pathspec,
-		   unsigned int refresh_flags);
 int do_read_index(struct index_state *istate, const char *path,
 		  int must_exist); /* for testting only! */
 int read_index_from(struct index_state *, const char *path,
diff --git a/preload-index.c b/preload-index.c
index 7a26b08c213..c26739debf8 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -8,6 +8,7 @@
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "config.h"
+#include "preload-index.h"
 #include "progress.h"
 #include "thread-utils.h"
 #include "repository.h"
diff --git a/preload-index.h b/preload-index.h
new file mode 100644
index 00000000000..251b1ed88e9
--- /dev/null
+++ b/preload-index.h
@@ -0,0 +1,15 @@
+#ifndef PRELOAD_INDEX_H
+#define PRELOAD_INDEX_H
+
+struct index_state;
+struct pathspec;
+struct repository;
+
+void preload_index(struct index_state *index,
+		   const struct pathspec *pathspec,
+		   unsigned int refresh_flags);
+int repo_read_index_preload(struct repository *,
+			    const struct pathspec *pathspec,
+			    unsigned refresh_flags);
+
+#endif /* PRELOAD_INDEX_H */
diff --git a/read-cache.c b/read-cache.c
index e1016ae0317..3fad839fb6f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@
 #include "mem-pool.h"
 #include "name-hash.h"
 #include "object-name.h"
+#include "preload-index.h"
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/repository.h b/repository.h
index 1a13ff28677..f81228bcfb5 100644
--- a/repository.h
+++ b/repository.h
@@ -220,9 +220,6 @@ int repo_hold_locked_index(struct repository *repo,
 			   struct lock_file *lf,
 			   int flags);
 
-int repo_read_index_preload(struct repository *,
-			    const struct pathspec *pathspec,
-			    unsigned refresh_flags);
 int repo_read_index_unmerged(struct repository *);
 /*
  * Opportunistically update the index but do not complain if we can't.
-- 
gitgitgadget


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

* [PATCH 12/24] diff.h: move declaration for global in diff.c from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (10 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 11/24] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 13/24] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 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 | 3 ---
 diff.h  | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index b79802a4639..08f6fbd801d 100644
--- a/cache.h
+++ b/cache.h
@@ -523,9 +523,6 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, int include_sparse,
 		       int flags);
 
-/* diff.c */
-extern int diff_auto_refresh_index;
-
 /* ls-files */
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/diff.h b/diff.h
index 3a7a9e8b888..29a9cd217c2 100644
--- a/diff.h
+++ b/diff.h
@@ -694,4 +694,6 @@ void print_stat_summary(FILE *fp, int files,
 			int insertions, int deletions);
 void setup_diff_pager(struct diff_options *);
 
+extern int diff_auto_refresh_index;
+
 #endif /* DIFF_H */
-- 
gitgitgadget


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

* [PATCH 13/24] merge.h: move declarations for merge.c from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (11 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 12/24] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 14/24] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/merge.c |  1 +
 builtin/pull.c  |  1 +
 cache.h         | 11 -----------
 merge.c         |  1 +
 merge.h         | 17 +++++++++++++++++
 sequencer.c     |  1 +
 6 files changed, 21 insertions(+), 11 deletions(-)
 create mode 100644 merge.h

diff --git a/builtin/merge.c b/builtin/merge.c
index 8da3e46abb0..6e8f7b9bb53 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -37,6 +37,7 @@
 #include "color.h"
 #include "rerere.h"
 #include "help.h"
+#include "merge.h"
 #include "merge-recursive.h"
 #include "merge-ort-wrappers.h"
 #include "resolve-undo.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 967368ebc65..f9ddc94ba9a 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
+#include "merge.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
diff --git a/cache.h b/cache.h
index 08f6fbd801d..5b690b80a16 100644
--- a/cache.h
+++ b/cache.h
@@ -527,15 +527,4 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
 
-/* merge.c */
-struct commit_list;
-int try_merge_command(struct repository *r,
-		const char *strategy, size_t xopts_nr,
-		const char **xopts, struct commit_list *common,
-		const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(struct repository *r,
-			  const struct object_id *from,
-			  const struct object_id *to,
-			  int overwrite_ignore);
-
 #endif /* CACHE_H */
diff --git a/merge.c b/merge.c
index 10aaec3a6c1..fade6b203b3 100644
--- a/merge.c
+++ b/merge.c
@@ -4,6 +4,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
+#include "merge.h"
 #include "commit.h"
 #include "run-command.h"
 #include "resolve-undo.h"
diff --git a/merge.h b/merge.h
new file mode 100644
index 00000000000..21ac7ef2f13
--- /dev/null
+++ b/merge.h
@@ -0,0 +1,17 @@
+#ifndef MERGE_H
+#define MERGE_H
+
+struct commit_list;
+struct object_id;
+struct repository;
+
+int try_merge_command(struct repository *r,
+		const char *strategy, size_t xopts_nr,
+		const char **xopts, struct commit_list *common,
+		const char *head_arg, struct commit_list *remotes);
+int checkout_fast_forward(struct repository *r,
+			  const struct object_id *from,
+			  const struct object_id *to,
+			  int overwrite_ignore);
+
+#endif /* MERGE_H */
diff --git a/sequencer.c b/sequencer.c
index cae9c75a54e..ec4a2e80a10 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -25,6 +25,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "rerere.h"
+#include "merge.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
-- 
gitgitgadget


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

* [PATCH 14/24] repository.h: move declaration of the_index from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (12 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 13/24] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 15/24] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

the_index is a global variable defined in repository.c; as such, its
declaration feels better suited living in repository.h rather than
cache.h.  Move it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h                          | 4 ----
 repository.h                     | 3 +++
 t/helper/test-dump-split-index.c | 1 +
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cache.h b/cache.h
index 5b690b80a16..11882897741 100644
--- a/cache.h
+++ b/cache.h
@@ -312,10 +312,6 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
 void prefetch_cache_entries(const struct index_state *istate,
 			    must_prefetch_predicate must_prefetch);
 
-#ifdef USE_THE_INDEX_VARIABLE
-extern struct index_state the_index;
-#endif
-
 /* Initialize and use the cache information */
 struct lock_file;
 int do_read_index(struct index_state *istate, const char *path,
diff --git a/repository.h b/repository.h
index f81228bcfb5..763794880ed 100644
--- a/repository.h
+++ b/repository.h
@@ -169,6 +169,9 @@ struct repository {
 };
 
 extern struct repository *the_repository;
+#ifdef USE_THE_INDEX_VARIABLE
+extern struct index_state the_index;
+#endif
 
 /*
  * Define a custom repository layout. Any field can be NULL, which
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index d1badd71126..63fde9157c4 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 "repository.h"
 #include "setup.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
-- 
gitgitgadget


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

* [PATCH 15/24] read-cache*.h: move declarations for read-cache.c functions from cache.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (13 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 14/24] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 16/24] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

For the functions defined in read-cache.c, move their declarations from
cache.h to a new header, read-cache-ll.h.  Also move some related inline
functions from cache.h to read-cache.h.  The purpose of the
read-cache-ll.h/read-cache.h split is that about 70% of the sites don't
need the inline functions and the extra headers they include.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                    |   1 +
 add-patch.c                          |   1 +
 apply.c                              |   1 +
 attr.c                               |   1 +
 blame.c                              |   1 +
 builtin/add.c                        |   1 +
 builtin/checkout--worker.c           |   1 +
 builtin/checkout-index.c             |   1 +
 builtin/checkout.c                   |   1 +
 builtin/clean.c                      |   1 +
 builtin/commit.c                     |   1 +
 builtin/describe.c                   |   1 +
 builtin/diff-tree.c                  |   1 +
 builtin/diff.c                       |   1 +
 builtin/difftool.c                   |   1 +
 builtin/fsck.c                       |   1 +
 builtin/grep.c                       |   1 +
 builtin/ls-files.c                   |   1 +
 builtin/merge-index.c                |   1 +
 builtin/mv.c                         |   1 +
 builtin/pull.c                       |   1 +
 builtin/rev-parse.c                  |   1 +
 builtin/rm.c                         |   1 +
 builtin/stash.c                      |   1 +
 builtin/submodule--helper.c          |   1 +
 builtin/update-index.c               |   1 +
 builtin/worktree.c                   |   1 +
 cache-tree.c                         |   1 +
 cache.h                              | 520 ---------------------------
 compat/precompose_utf8.c             |   1 +
 compat/sha1-chunked.c                |   1 +
 config.c                             |   1 +
 convert.c                            |   1 +
 diff-lib.c                           |   1 +
 diff.c                               |   1 +
 diffcore-break.c                     |   3 +-
 environment.h                        |   3 +-
 fsmonitor.h                          |   2 +
 git.c                                |   1 +
 hash-lookup.c                        |   1 +
 merge-ort-wrappers.c                 |   1 +
 merge-ort.c                          |   1 +
 name-hash.c                          |   2 +
 object-name.c                        |   1 +
 oidmap.h                             |   1 +
 parallel-checkout.c                  |   1 +
 pathspec.c                           |   1 +
 preload-index.c                      |   1 +
 read-cache-ll.h                      | 481 +++++++++++++++++++++++++
 read-cache.c                         |   1 +
 read-cache.h                         |  45 +++
 repository.c                         |   1 +
 rerere.c                             |   1 +
 resolve-undo.c                       |   1 +
 revision.c                           |   1 +
 split-index.c                        |   1 +
 submodule.c                          |   1 +
 t/helper/test-cache-tree.c           |   1 +
 t/helper/test-dump-cache-tree.c      |   1 +
 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-hash-speed.c           |   1 +
 t/helper/test-index-version.c        |   1 +
 t/helper/test-lazy-init-name-hash.c  |   1 +
 t/helper/test-path-utils.c           |   1 +
 t/helper/test-read-cache.c           |   1 +
 t/helper/test-scrap-cache-tree.c     |   1 +
 t/helper/test-sha1.c                 |   1 +
 t/helper/test-sha256.c               |   1 +
 t/helper/test-strcmp-offset.c        |   1 +
 t/helper/test-write-cache.c          |   1 +
 unpack-trees.c                       |   1 +
 unpack-trees.h                       |   2 +-
 wt-status.c                          |   1 +
 77 files changed, 603 insertions(+), 524 deletions(-)
 create mode 100644 read-cache-ll.h
 create mode 100644 read-cache.h

diff --git a/add-interactive.c b/add-interactive.c
index 99f7dc3b0d1..a9671e33491 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "preload-index.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 8d770d203ff..7d4d298286d 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/apply.c b/apply.c
index 3da33bb88fd..f056c8f3bb9 100644
--- a/apply.c
+++ b/apply.c
@@ -28,6 +28,7 @@
 #include "object-file.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "read-cache.h"
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
diff --git a/attr.c b/attr.c
index ddf2b0cbc2e..57c813d8e77 100644
--- a/attr.c
+++ b/attr.c
@@ -16,6 +16,7 @@
 #include "gettext.h"
 #include "utf8.h"
 #include "quote.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "object-store.h"
 #include "setup.h"
diff --git a/blame.c b/blame.c
index 58dd58b6c97..a29ae7c14b2 100644
--- a/blame.c
+++ b/blame.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "tag.h"
 #include "trace2.h"
diff --git a/builtin/add.c b/builtin/add.c
index 8397be4f8de..9fe6b6ce290 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -20,6 +20,7 @@
 #include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "read-cache.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index 2120dd1d300..c655dc4b136 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -6,6 +6,7 @@
 #include "parallel-checkout.h"
 #include "parse-options.h"
 #include "pkt-line.h"
+#include "read-cache-ll.h"
 
 static void packet_to_pc_item(const char *buffer, int len,
 			      struct parallel_checkout_item *pc_item)
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index b1cd8bef264..f62f13f2b53 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "sparse-index.h"
 
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2d72a742d9d..09b84156492 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -21,6 +21,7 @@
 #include "object-store.h"
 #include "parse-options.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "refs.h"
 #include "remote.h"
 #include "resolve-undo.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 78852d28cec..49c7af45b03 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "string-list.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index fa769045c88..5be05c9d9e1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -31,6 +31,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "unpack-trees.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 55b4baaa223..f1be7c36948 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -13,6 +13,7 @@
 #include "exec-cmd.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "diff.h"
 #include "hashmap.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 0b02c62b85e..5a1e5d6df7c 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -8,6 +8,7 @@
 #include "log-tree.h"
 #include "builtin.h"
 #include "submodule.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "tree.h"
 
diff --git a/builtin/diff.c b/builtin/diff.c
index 967550739a6..a9ce701ff97 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -17,6 +17,7 @@
 #include "diff-merges.h"
 #include "diffcore.h"
 #include "preload-index.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2c27a59e04a..88809976c53 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "sparse-index.h"
 #include "strvec.h"
 #include "strbuf.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 7134596d218..e8c5fbca58f 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -22,6 +22,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "replace-object.h"
 #include "resolve-undo.h"
 #include "run-command.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index b86c754defb..0d567575890 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -31,6 +31,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pager.h"
+#include "read-cache-ll.h"
 #include "write-or-die.h"
 
 static const char *grep_prefix;
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 45b3b0ce5d8..d8c1c62bcb0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -21,6 +21,7 @@
 #include "resolve-undo.h"
 #include "string-list.h"
 #include "pathspec.h"
+#include "read-cache.h"
 #include "run-command.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index d16e8aa414b..270d5f644ac 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "hex.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "run-command.h"
 #include "sparse-index.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index e058b574654..ae462bd7d41 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -19,6 +19,7 @@
 #include "cache-tree.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index f9ddc94ba9a..8aeb5abc7fb 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -20,6 +20,7 @@
 #include "oid-array.h"
 #include "remote.h"
 #include "dir.h"
+#include "read-cache-ll.h"
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 852e49e3403..ad93e5fad88 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -18,6 +18,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "diff.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "setup.h"
 #include "split-index.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 377a0f66ad8..463eeabceaa 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -16,6 +16,7 @@
 #include "tree-walk.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "string-list.h"
 #include "setup.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 06527ee8471..d3d5bb95e26 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -18,6 +18,7 @@
 #include "dir.h"
 #include "entry.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 597e780a93a..86324b829a7 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -13,6 +13,7 @@
 #include "pathspec.h"
 #include "preload-index.h"
 #include "dir.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "submodule.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 47dc9b626ef..484a307df50 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -22,6 +22,7 @@
 #include "parse-options.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index f3180463be2..3c3d97ad5b0 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -13,6 +13,7 @@
 #include "parse-options.h"
 #include "strvec.h"
 #include "branch.h"
+#include "read-cache-ll.h"
 #include "refs.h"
 #include "repository.h"
 #include "run-command.h"
diff --git a/cache-tree.c b/cache-tree.c
index ebfe649b330..153217b47ff 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -9,6 +9,7 @@
 #include "bulk-checkin.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "sparse-index.h"
diff --git a/cache.h b/cache.h
index 11882897741..9b4e8d16874 100644
--- a/cache.h
+++ b/cache.h
@@ -2,525 +2,5 @@
 #define CACHE_H
 
 #include "git-compat-util.h"
-#include "strbuf.h"
-#include "hashmap.h"
-#include "pathspec.h"
-#include "object.h"
-#include "statinfo.h"
-
-/*
- * Basic data structures for the directory cache
- */
-
-#define CACHE_SIGNATURE 0x44495243	/* "DIRC" */
-struct cache_header {
-	uint32_t hdr_signature;
-	uint32_t hdr_version;
-	uint32_t hdr_entries;
-};
-
-#define INDEX_FORMAT_LB 2
-#define INDEX_FORMAT_UB 4
-
-struct cache_entry {
-	struct hashmap_entry ent;
-	struct stat_data ce_stat_data;
-	unsigned int ce_mode;
-	unsigned int ce_flags;
-	unsigned int mem_pool_allocated;
-	unsigned int ce_namelen;
-	unsigned int index;	/* for link extension */
-	struct object_id oid;
-	char name[FLEX_ARRAY]; /* more */
-};
-
-#define CE_STAGEMASK (0x3000)
-#define CE_EXTENDED  (0x4000)
-#define CE_VALID     (0x8000)
-#define CE_STAGESHIFT 12
-
-/*
- * Range 0xFFFF0FFF in ce_flags is divided into
- * two parts: in-memory flags and on-disk ones.
- * Flags in CE_EXTENDED_FLAGS will get saved on-disk
- * if you want to save a new flag, add it in
- * CE_EXTENDED_FLAGS
- *
- * In-memory only flags
- */
-#define CE_UPDATE            (1 << 16)
-#define CE_REMOVE            (1 << 17)
-#define CE_UPTODATE          (1 << 18)
-#define CE_ADDED             (1 << 19)
-
-#define CE_HASHED            (1 << 20)
-#define CE_FSMONITOR_VALID   (1 << 21)
-#define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
-#define CE_CONFLICTED        (1 << 23)
-
-#define CE_UNPACKED          (1 << 24)
-#define CE_NEW_SKIP_WORKTREE (1 << 25)
-
-/* used to temporarily mark paths matched by pathspecs */
-#define CE_MATCHED           (1 << 26)
-
-#define CE_UPDATE_IN_BASE    (1 << 27)
-#define CE_STRIP_NAME        (1 << 28)
-
-/*
- * Extended on-disk flags
- */
-#define CE_INTENT_TO_ADD     (1 << 29)
-#define CE_SKIP_WORKTREE     (1 << 30)
-/* CE_EXTENDED2 is for future extension */
-#define CE_EXTENDED2         (1U << 31)
-
-#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
-
-/*
- * Safeguard to avoid saving wrong flags:
- *  - CE_EXTENDED2 won't get saved until its semantic is known
- *  - Bits in 0x0000FFFF have been saved in ce_flags already
- *  - Bits in 0x003F0000 are currently in-memory flags
- */
-#if CE_EXTENDED_FLAGS & 0x803FFFFF
-#error "CE_EXTENDED_FLAGS out of range"
-#endif
-
-/* Forward structure decls */
-struct pathspec;
-struct tree;
-
-/*
- * Copy the sha1 and stat state of a cache entry from one to
- * another. But we never change the name, or the hash state!
- */
-static inline void copy_cache_entry(struct cache_entry *dst,
-				    const struct cache_entry *src)
-{
-	unsigned int state = dst->ce_flags & CE_HASHED;
-	int mem_pool_allocated = dst->mem_pool_allocated;
-
-	/* Don't copy hash chain and name */
-	memcpy(&dst->ce_stat_data, &src->ce_stat_data,
-			offsetof(struct cache_entry, name) -
-			offsetof(struct cache_entry, ce_stat_data));
-
-	/* Restore the hash state */
-	dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
-
-	/* Restore the mem_pool_allocated flag */
-	dst->mem_pool_allocated = mem_pool_allocated;
-}
-
-static inline unsigned create_ce_flags(unsigned stage)
-{
-	return (stage << CE_STAGESHIFT);
-}
-
-#define ce_namelen(ce) ((ce)->ce_namelen)
-#define ce_size(ce) cache_entry_size(ce_namelen(ce))
-#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
-#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
-#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
-#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
-#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
-
-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
-					     unsigned int mode)
-{
-	extern int trust_executable_bit, has_symlinks;
-	if (!has_symlinks && S_ISREG(mode) &&
-	    ce && S_ISLNK(ce->ce_mode))
-		return ce->ce_mode;
-	if (!trust_executable_bit && S_ISREG(mode)) {
-		if (ce && S_ISREG(ce->ce_mode))
-			return ce->ce_mode;
-		return create_ce_mode(0666);
-	}
-	return create_ce_mode(mode);
-}
-static inline int ce_to_dtype(const struct cache_entry *ce)
-{
-	unsigned ce_mode = ntohl(ce->ce_mode);
-	if (S_ISREG(ce_mode))
-		return DT_REG;
-	else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
-		return DT_DIR;
-	else if (S_ISLNK(ce_mode))
-		return DT_LNK;
-	else
-		return DT_UNKNOWN;
-}
-
-static inline int ce_path_match(struct index_state *istate,
-				const struct cache_entry *ce,
-				const struct pathspec *pathspec,
-				char *seen)
-{
-	return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
-			      S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
-}
-
-#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
-
-#define SOMETHING_CHANGED	(1 << 0) /* unclassified changes go here */
-#define CE_ENTRY_CHANGED	(1 << 1)
-#define CE_ENTRY_REMOVED	(1 << 2)
-#define CE_ENTRY_ADDED		(1 << 3)
-#define RESOLVE_UNDO_CHANGED	(1 << 4)
-#define CACHE_TREE_CHANGED	(1 << 5)
-#define SPLIT_INDEX_ORDERED	(1 << 6)
-#define UNTRACKED_CHANGED	(1 << 7)
-#define FSMONITOR_CHANGED	(1 << 8)
-
-struct split_index;
-struct untracked_cache;
-struct progress;
-struct pattern_list;
-
-enum sparse_index_mode {
-	/*
-	 * There are no sparse directories in the index at all.
-	 *
-	 * Repositories that don't use cone-mode sparse-checkout will
-	 * always have their indexes in this mode.
-	 */
-	INDEX_EXPANDED = 0,
-
-	/*
-	 * The index has already been collapsed to sparse directories
-	 * whereever possible.
-	 */
-	INDEX_COLLAPSED,
-
-	/*
-	 * The sparse directories that exist are outside the
-	 * sparse-checkout boundary, but it is possible that some file
-	 * entries could collapse to sparse directory entries.
-	 */
-	INDEX_PARTIALLY_SPARSE,
-};
-
-struct index_state {
-	struct cache_entry **cache;
-	unsigned int version;
-	unsigned int cache_nr, cache_alloc, cache_changed;
-	struct string_list *resolve_undo;
-	struct cache_tree *cache_tree;
-	struct split_index *split_index;
-	struct cache_time timestamp;
-	unsigned name_hash_initialized : 1,
-		 initialized : 1,
-		 drop_cache_tree : 1,
-		 updated_workdir : 1,
-		 updated_skipworktree : 1,
-		 fsmonitor_has_run_once : 1;
-	enum sparse_index_mode sparse_index;
-	struct hashmap name_hash;
-	struct hashmap dir_hash;
-	struct object_id oid;
-	struct untracked_cache *untracked;
-	char *fsmonitor_last_update;
-	struct ewah_bitmap *fsmonitor_dirty;
-	struct mem_pool *ce_mem_pool;
-	struct progress *progress;
-	struct repository *repo;
-	struct pattern_list *sparse_checkout_patterns;
-};
-
-/**
- * A "struct index_state istate" must be initialized with
- * INDEX_STATE_INIT or the corresponding index_state_init().
- *
- * If the variable won't be used again, use release_index() to free()
- * its resources. If it needs to be used again use discard_index(),
- * which does the same thing, but will use use index_state_init() at
- * the end. The discard_index() will use its own "istate->repo" as the
- * "r" argument to index_state_init() in that case.
- */
-#define INDEX_STATE_INIT(r) { \
-	.repo = (r), \
-}
-void index_state_init(struct index_state *istate, struct repository *r);
-void release_index(struct index_state *istate);
-
-/* Cache entry creation and cleanup */
-
-/*
- * Create cache_entry intended for use in the specified index. Caller
- * is responsible for discarding the cache_entry with
- * `discard_cache_entry`.
- */
-struct cache_entry *make_cache_entry(struct index_state *istate,
-				     unsigned int mode,
-				     const struct object_id *oid,
-				     const char *path,
-				     int stage,
-				     unsigned int refresh_options);
-
-struct cache_entry *make_empty_cache_entry(struct index_state *istate,
-					   size_t name_len);
-
-/*
- * Create a cache_entry that is not intended to be added to an index. If
- * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
- * pool. Caller is responsible for discarding "loose" entries with
- * `discard_cache_entry()` and the memory pool with
- * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
- */
-struct cache_entry *make_transient_cache_entry(unsigned int mode,
-					       const struct object_id *oid,
-					       const char *path,
-					       int stage,
-					       struct mem_pool *ce_mem_pool);
-
-struct cache_entry *make_empty_transient_cache_entry(size_t len,
-						     struct mem_pool *ce_mem_pool);
-
-/*
- * Discard cache entry.
- */
-void discard_cache_entry(struct cache_entry *ce);
-
-/*
- * Check configuration if we should perform extra validation on cache
- * entries.
- */
-int should_validate_cache_entries(void);
-
-/*
- * Duplicate a cache_entry. Allocate memory for the new entry from a
- * memory_pool. Takes into account cache_entry fields that are meant
- * for managing the underlying memory allocation of the cache_entry.
- */
-struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
-
-/*
- * Validate the cache entries in the index.  This is an internal
- * consistency check that the cache_entry structs are allocated from
- * the expected memory pool.
- */
-void validate_cache_entries(const struct index_state *istate);
-
-/*
- * Bulk prefetch all missing cache entries that are not GITLINKs and that match
- * the given predicate. This function should only be called if
- * repo_has_promisor_remote() returns true.
- */
-typedef int (*must_prefetch_predicate)(const struct cache_entry *);
-void prefetch_cache_entries(const struct index_state *istate,
-			    must_prefetch_predicate must_prefetch);
-
-/* Initialize and use the cache information */
-struct lock_file;
-int do_read_index(struct index_state *istate, const char *path,
-		  int must_exist); /* for testting only! */
-int read_index_from(struct index_state *, const char *path,
-		    const char *gitdir);
-int is_index_unborn(struct index_state *);
-
-/* For use with `write_locked_index()`. */
-#define COMMIT_LOCK		(1 << 0)
-#define SKIP_IF_UNCHANGED	(1 << 1)
-
-/*
- * Write the index while holding an already-taken lock. Close the lock,
- * and if `COMMIT_LOCK` is given, commit it.
- *
- * Unless a split index is in use, write the index into the lockfile.
- *
- * With a split index, write the shared index to a temporary file,
- * adjust its permissions and rename it into place, then write the
- * split index to the lockfile. If the temporary file for the shared
- * index cannot be created, fall back to the behavior described in
- * the previous paragraph.
- *
- * With `COMMIT_LOCK`, the lock is always committed or rolled back.
- * Without it, the lock is closed, but neither committed nor rolled
- * back.
- *
- * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
- * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
- */
-int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
-
-void discard_index(struct index_state *);
-void move_index_extensions(struct index_state *dst, struct index_state *src);
-int unmerged_index(const struct index_state *);
-
-/**
- * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
- * compares istate to HEAD.  If tree is NULL and on an unborn branch,
- * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
- * provided, the space-separated list of files that differ will be appended
- * to it.
- */
-int repo_index_has_changes(struct repository *repo,
-			   struct tree *tree,
-			   struct strbuf *sb);
-
-int verify_path(const char *path, unsigned mode);
-int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-
-/*
- * Searches for an entry defined by name and namelen in the given index.
- * If the return value is positive (including 0) it is the position of an
- * exact match. If the return value is negative, the negated value minus 1
- * is the position where the entry would be inserted.
- * Example: The current index consists of these files and its stages:
- *
- *   b#0, d#0, f#1, f#3
- *
- * index_name_pos(&index, "a", 1) -> -1
- * index_name_pos(&index, "b", 1) ->  0
- * index_name_pos(&index, "c", 1) -> -2
- * index_name_pos(&index, "d", 1) ->  1
- * index_name_pos(&index, "e", 1) -> -3
- * index_name_pos(&index, "f", 1) -> -3
- * index_name_pos(&index, "g", 1) -> -5
- */
-int index_name_pos(struct index_state *, const char *name, int namelen);
-
-/*
- * Like index_name_pos, returns the position of an entry of the given name in
- * the index if one exists, otherwise returns a negative value where the negated
- * value minus 1 is the position where the index entry would be inserted. Unlike
- * index_name_pos, however, a sparse index is not expanded to find an entry
- * inside a sparse directory.
- */
-int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
-
-/*
- * Determines whether an entry with the given name exists within the
- * given index. The return value is 1 if an exact match is found, otherwise
- * it is 0. Note that, unlike index_name_pos, this function does not expand
- * the index if it is sparse. If an item exists within the full index but it
- * is contained within a sparse directory (and not in the sparse index), 0 is
- * returned.
- */
-int index_entry_exists(struct index_state *, const char *name, int namelen);
-
-/*
- * Some functions return the negative complement of an insert position when a
- * precise match was not found but a position was found where the entry would
- * need to be inserted. This helper protects that logic from any integer
- * underflow.
- */
-static inline int index_pos_to_insert_pos(uintmax_t pos)
-{
-	if (pos > INT_MAX)
-		die("overflow: -1 - %"PRIuMAX, pos);
-	return -1 - (int)pos;
-}
-
-#define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
-#define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
-#define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
-#define ADD_CACHE_JUST_APPEND 8		/* Append only */
-#define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
-#define ADD_CACHE_KEEP_CACHE_TREE 32	/* Do not invalidate cache-tree */
-#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
-int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
-void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
-
-/* Remove entry, return true if there are more entries to go. */
-int remove_index_entry_at(struct index_state *, int pos);
-
-void remove_marked_cache_entries(struct index_state *istate, int invalidate);
-int remove_file_from_index(struct index_state *, const char *path);
-#define ADD_CACHE_VERBOSE 1
-#define ADD_CACHE_PRETEND 2
-#define ADD_CACHE_IGNORE_ERRORS	4
-#define ADD_CACHE_IGNORE_REMOVAL 8
-#define ADD_CACHE_INTENT 16
-/*
- * These two are used to add the contents of the file at path
- * to the index, marking the working tree up-to-date by storing
- * the cached stat info in the resulting cache entry.  A caller
- * that has already run lstat(2) on the path can call
- * add_to_index(), and all others can call add_file_to_index();
- * the latter will do necessary lstat(2) internally before
- * calling the former.
- */
-int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
-int add_file_to_index(struct index_state *, const char *path, int flags);
-
-int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
-int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
-void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
-int index_name_is_other(struct index_state *, const char *, int);
-void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
-
-/* do stat comparison even if CE_VALID is true */
-#define CE_MATCH_IGNORE_VALID		01
-/* do not check the contents but report dirty on racily-clean entries */
-#define CE_MATCH_RACY_IS_DIRTY		02
-/* do stat comparison even if CE_SKIP_WORKTREE is true */
-#define CE_MATCH_IGNORE_SKIP_WORKTREE	04
-/* ignore non-existent files during stat update  */
-#define CE_MATCH_IGNORE_MISSING		0x08
-/* enable stat refresh */
-#define CE_MATCH_REFRESH		0x10
-/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
-#define CE_MATCH_IGNORE_FSMONITOR 0X20
-int is_racy_timestamp(const struct index_state *istate,
-		      const struct cache_entry *ce);
-int has_racy_timestamp(struct index_state *istate);
-int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-
-int match_stat_data_racy(const struct index_state *istate,
-			 const struct stat_data *sd, struct stat *st);
-
-void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
-
-#define REFRESH_REALLY                   (1 << 0) /* ignore_valid */
-#define REFRESH_UNMERGED                 (1 << 1) /* allow unmerged */
-#define REFRESH_QUIET                    (1 << 2) /* be quiet about it */
-#define REFRESH_IGNORE_MISSING           (1 << 3) /* ignore non-existent */
-#define REFRESH_IGNORE_SUBMODULES        (1 << 4) /* ignore submodules */
-#define REFRESH_IN_PORCELAIN             (1 << 5) /* user friendly output, not "needs update" */
-#define REFRESH_PROGRESS                 (1 << 6) /* show progress bar if stderr is tty */
-#define REFRESH_IGNORE_SKIP_WORKTREE     (1 << 7) /* ignore skip_worktree entries */
-int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
-/*
- * Refresh the index and write it to disk.
- *
- * 'refresh_flags' is passed directly to 'refresh_index()', while
- * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
- * the lockfile is always either committed or rolled back.
- *
- * If 'gentle' is passed, errors locking the index are ignored.
- *
- * Return 1 if refreshing the index returns an error, -1 if writing
- * the index to disk fails, 0 on success.
- *
- * Note that if refreshing the index returns an error, we still write
- * out the index (unless locking fails).
- */
-int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg);
-
-struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
-
-void set_alternate_index_output(const char *);
-
-extern int verify_index_checksum;
-extern int verify_ce_order;
-
-int cmp_cache_name_compare(const void *a_, const void *b_);
-
-/* add */
-/*
- * return 0 if success, 1 - if addition of a file failed and
- * ADD_FILES_IGNORE_ERRORS was specified in flags
- */
-int add_files_to_cache(struct repository *repo, const char *prefix,
-		       const struct pathspec *pathspec, int include_sparse,
-		       int flags);
-
-/* ls-files */
-void overlay_tree_on_index(struct index_state *istate,
-			   const char *tree_name, const char *prefix);
 
 #endif /* CACHE_H */
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index a4d11376ba5..fb08475bc64 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -10,6 +10,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "path.h"
+#include "strbuf.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 6adfcfd5405..56729d92dcf 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "hash-ll.h"
 
 int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
 {
diff --git a/config.c b/config.c
index b79baf83e35..06e6cc6f1ec 100644
--- a/config.c
+++ b/config.c
@@ -33,6 +33,7 @@
 #include "replace-object.h"
 #include "refs.h"
 #include "setup.h"
+#include "strvec.h"
 #include "trace2.h"
 #include "worktree.h"
 #include "ws.h"
diff --git a/convert.c b/convert.c
index 7cf7bd0c883..236d5e3dc25 100644
--- a/convert.c
+++ b/convert.c
@@ -9,6 +9,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
+#include "read-cache-ll.h"
 #include "sigchain.h"
 #include "pkt-line.h"
 #include "sub-process.h"
diff --git a/diff-lib.c b/diff-lib.c
index 60e979dc1bd..36cd66ea237 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "read-cache.h"
 #include "revision.h"
 #include "cache-tree.h"
 #include "unpack-trees.h"
diff --git a/diff.c b/diff.c
index 07f140b425f..61b4dc61e1e 100644
--- a/diff.c
+++ b/diff.c
@@ -39,6 +39,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "strmap.h"
 #include "ws.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 5462420bbbe..4909dc088e6 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,9 +1,10 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "object.h"
 #include "promisor-remote.h"
 
 static int should_break(struct repository *r,
diff --git a/environment.h b/environment.h
index a63f0c6a24f..6eca4712e1e 100644
--- a/environment.h
+++ b/environment.h
@@ -1,9 +1,8 @@
 #ifndef ENVIRONMENT_H
 #define ENVIRONMENT_H
 
-#include "strvec.h"
-
 struct repository;
+struct strvec;
 
 /*
  * The character that begins a commented line in user-editable file
diff --git a/fsmonitor.h b/fsmonitor.h
index c67e0ebc09b..8b7a521552a 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -4,6 +4,8 @@
 #include "cache.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
+#include "object.h"
+#include "read-cache-ll.h"
 #include "trace.h"
 
 extern struct trace_key trace_fsmonitor;
diff --git a/git.c b/git.c
index 45899be8265..a1a538fc52e 100644
--- a/git.c
+++ b/git.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "help.h"
 #include "pager.h"
+#include "read-cache-ll.h"
 #include "run-command.h"
 #include "alias.h"
 #include "replace-object.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index bb54dfde9c7..8fec8939fd3 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "hash.h"
 #include "hash-lookup.h"
+#include "read-cache-ll.h"
 
 static uint32_t take2(const struct object_id *oid, size_t ofs)
 {
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a5507533009..a0bedcb63bb 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -3,6 +3,7 @@
 #include "hash.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
+#include "read-cache-ll.h"
 #include "tree.h"
 
 #include "commit.h"
diff --git a/merge-ort.c b/merge-ort.c
index 4bff685e456..5512f40d321 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -37,6 +37,7 @@
 #include "object-store.h"
 #include "oid-array.h"
 #include "promisor-remote.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "sparse-index.h"
 #include "strmap.h"
diff --git a/name-hash.c b/name-hash.c
index 52ce47ea394..f2f3564cb20 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -9,6 +9,8 @@
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
+#include "object.h"
+#include "read-cache-ll.h"
 #include "thread-utils.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/object-name.c b/object-name.c
index 6fc3fa595b8..1eefeef746e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -18,6 +18,7 @@
 #include "packfile.h"
 #include "pretty.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/oidmap.h b/oidmap.h
index c1642927fa6..05c673eb7c1 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,6 +1,7 @@
 #ifndef OIDMAP_H
 #define OIDMAP_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 
 /*
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 69d569f3525..2b1439c0c5f 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -8,6 +8,7 @@
 #include "parallel-checkout.h"
 #include "pkt-line.h"
 #include "progress.h"
+#include "read-cache-ll.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "streaming.h"
diff --git a/pathspec.c b/pathspec.c
index 1e57b6c667d..47d172fe414 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "setup.h"
 #include "strvec.h"
diff --git a/preload-index.c b/preload-index.c
index c26739debf8..d037a951efa 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "preload-index.h"
 #include "progress.h"
+#include "read-cache.h"
 #include "thread-utils.h"
 #include "repository.h"
 #include "symlinks.h"
diff --git a/read-cache-ll.h b/read-cache-ll.h
new file mode 100644
index 00000000000..9a1a7edc5a2
--- /dev/null
+++ b/read-cache-ll.h
@@ -0,0 +1,481 @@
+#ifndef READ_CACHE_LL_H
+#define READ_CACHE_LL_H
+
+#include "hash-ll.h"
+#include "hashmap.h"
+#include "statinfo.h"
+
+/*
+ * Basic data structures for the directory cache
+ */
+
+#define CACHE_SIGNATURE 0x44495243	/* "DIRC" */
+struct cache_header {
+	uint32_t hdr_signature;
+	uint32_t hdr_version;
+	uint32_t hdr_entries;
+};
+
+#define INDEX_FORMAT_LB 2
+#define INDEX_FORMAT_UB 4
+
+struct cache_entry {
+	struct hashmap_entry ent;
+	struct stat_data ce_stat_data;
+	unsigned int ce_mode;
+	unsigned int ce_flags;
+	unsigned int mem_pool_allocated;
+	unsigned int ce_namelen;
+	unsigned int index;	/* for link extension */
+	struct object_id oid;
+	char name[FLEX_ARRAY]; /* more */
+};
+
+#define CE_STAGEMASK (0x3000)
+#define CE_EXTENDED  (0x4000)
+#define CE_VALID     (0x8000)
+#define CE_STAGESHIFT 12
+
+/*
+ * Range 0xFFFF0FFF in ce_flags is divided into
+ * two parts: in-memory flags and on-disk ones.
+ * Flags in CE_EXTENDED_FLAGS will get saved on-disk
+ * if you want to save a new flag, add it in
+ * CE_EXTENDED_FLAGS
+ *
+ * In-memory only flags
+ */
+#define CE_UPDATE            (1 << 16)
+#define CE_REMOVE            (1 << 17)
+#define CE_UPTODATE          (1 << 18)
+#define CE_ADDED             (1 << 19)
+
+#define CE_HASHED            (1 << 20)
+#define CE_FSMONITOR_VALID   (1 << 21)
+#define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
+#define CE_CONFLICTED        (1 << 23)
+
+#define CE_UNPACKED          (1 << 24)
+#define CE_NEW_SKIP_WORKTREE (1 << 25)
+
+/* used to temporarily mark paths matched by pathspecs */
+#define CE_MATCHED           (1 << 26)
+
+#define CE_UPDATE_IN_BASE    (1 << 27)
+#define CE_STRIP_NAME        (1 << 28)
+
+/*
+ * Extended on-disk flags
+ */
+#define CE_INTENT_TO_ADD     (1 << 29)
+#define CE_SKIP_WORKTREE     (1 << 30)
+/* CE_EXTENDED2 is for future extension */
+#define CE_EXTENDED2         (1U << 31)
+
+#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
+
+/*
+ * Safeguard to avoid saving wrong flags:
+ *  - CE_EXTENDED2 won't get saved until its semantic is known
+ *  - Bits in 0x0000FFFF have been saved in ce_flags already
+ *  - Bits in 0x003F0000 are currently in-memory flags
+ */
+#if CE_EXTENDED_FLAGS & 0x803FFFFF
+#error "CE_EXTENDED_FLAGS out of range"
+#endif
+
+/* Forward structure decls */
+struct pathspec;
+struct tree;
+
+/*
+ * Copy the sha1 and stat state of a cache entry from one to
+ * another. But we never change the name, or the hash state!
+ */
+static inline void copy_cache_entry(struct cache_entry *dst,
+				    const struct cache_entry *src)
+{
+	unsigned int state = dst->ce_flags & CE_HASHED;
+	int mem_pool_allocated = dst->mem_pool_allocated;
+
+	/* Don't copy hash chain and name */
+	memcpy(&dst->ce_stat_data, &src->ce_stat_data,
+			offsetof(struct cache_entry, name) -
+			offsetof(struct cache_entry, ce_stat_data));
+
+	/* Restore the hash state */
+	dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
+
+	/* Restore the mem_pool_allocated flag */
+	dst->mem_pool_allocated = mem_pool_allocated;
+}
+
+static inline unsigned create_ce_flags(unsigned stage)
+{
+	return (stage << CE_STAGESHIFT);
+}
+
+#define ce_namelen(ce) ((ce)->ce_namelen)
+#define ce_size(ce) cache_entry_size(ce_namelen(ce))
+#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
+#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
+#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
+#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
+#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
+
+#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
+
+#define SOMETHING_CHANGED	(1 << 0) /* unclassified changes go here */
+#define CE_ENTRY_CHANGED	(1 << 1)
+#define CE_ENTRY_REMOVED	(1 << 2)
+#define CE_ENTRY_ADDED		(1 << 3)
+#define RESOLVE_UNDO_CHANGED	(1 << 4)
+#define CACHE_TREE_CHANGED	(1 << 5)
+#define SPLIT_INDEX_ORDERED	(1 << 6)
+#define UNTRACKED_CHANGED	(1 << 7)
+#define FSMONITOR_CHANGED	(1 << 8)
+
+struct split_index;
+struct untracked_cache;
+struct progress;
+struct pattern_list;
+
+enum sparse_index_mode {
+	/*
+	 * There are no sparse directories in the index at all.
+	 *
+	 * Repositories that don't use cone-mode sparse-checkout will
+	 * always have their indexes in this mode.
+	 */
+	INDEX_EXPANDED = 0,
+
+	/*
+	 * The index has already been collapsed to sparse directories
+	 * whereever possible.
+	 */
+	INDEX_COLLAPSED,
+
+	/*
+	 * The sparse directories that exist are outside the
+	 * sparse-checkout boundary, but it is possible that some file
+	 * entries could collapse to sparse directory entries.
+	 */
+	INDEX_PARTIALLY_SPARSE,
+};
+
+struct index_state {
+	struct cache_entry **cache;
+	unsigned int version;
+	unsigned int cache_nr, cache_alloc, cache_changed;
+	struct string_list *resolve_undo;
+	struct cache_tree *cache_tree;
+	struct split_index *split_index;
+	struct cache_time timestamp;
+	unsigned name_hash_initialized : 1,
+		 initialized : 1,
+		 drop_cache_tree : 1,
+		 updated_workdir : 1,
+		 updated_skipworktree : 1,
+		 fsmonitor_has_run_once : 1;
+	enum sparse_index_mode sparse_index;
+	struct hashmap name_hash;
+	struct hashmap dir_hash;
+	struct object_id oid;
+	struct untracked_cache *untracked;
+	char *fsmonitor_last_update;
+	struct ewah_bitmap *fsmonitor_dirty;
+	struct mem_pool *ce_mem_pool;
+	struct progress *progress;
+	struct repository *repo;
+	struct pattern_list *sparse_checkout_patterns;
+};
+
+/**
+ * A "struct index_state istate" must be initialized with
+ * INDEX_STATE_INIT or the corresponding index_state_init().
+ *
+ * If the variable won't be used again, use release_index() to free()
+ * its resources. If it needs to be used again use discard_index(),
+ * which does the same thing, but will use use index_state_init() at
+ * the end. The discard_index() will use its own "istate->repo" as the
+ * "r" argument to index_state_init() in that case.
+ */
+#define INDEX_STATE_INIT(r) { \
+	.repo = (r), \
+}
+void index_state_init(struct index_state *istate, struct repository *r);
+void release_index(struct index_state *istate);
+
+/* Cache entry creation and cleanup */
+
+/*
+ * Create cache_entry intended for use in the specified index. Caller
+ * is responsible for discarding the cache_entry with
+ * `discard_cache_entry`.
+ */
+struct cache_entry *make_cache_entry(struct index_state *istate,
+				     unsigned int mode,
+				     const struct object_id *oid,
+				     const char *path,
+				     int stage,
+				     unsigned int refresh_options);
+
+struct cache_entry *make_empty_cache_entry(struct index_state *istate,
+					   size_t name_len);
+
+/*
+ * Create a cache_entry that is not intended to be added to an index. If
+ * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
+ * pool. Caller is responsible for discarding "loose" entries with
+ * `discard_cache_entry()` and the memory pool with
+ * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
+ */
+struct cache_entry *make_transient_cache_entry(unsigned int mode,
+					       const struct object_id *oid,
+					       const char *path,
+					       int stage,
+					       struct mem_pool *ce_mem_pool);
+
+struct cache_entry *make_empty_transient_cache_entry(size_t len,
+						     struct mem_pool *ce_mem_pool);
+
+/*
+ * Discard cache entry.
+ */
+void discard_cache_entry(struct cache_entry *ce);
+
+/*
+ * Check configuration if we should perform extra validation on cache
+ * entries.
+ */
+int should_validate_cache_entries(void);
+
+/*
+ * Duplicate a cache_entry. Allocate memory for the new entry from a
+ * memory_pool. Takes into account cache_entry fields that are meant
+ * for managing the underlying memory allocation of the cache_entry.
+ */
+struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
+
+/*
+ * Validate the cache entries in the index.  This is an internal
+ * consistency check that the cache_entry structs are allocated from
+ * the expected memory pool.
+ */
+void validate_cache_entries(const struct index_state *istate);
+
+/*
+ * Bulk prefetch all missing cache entries that are not GITLINKs and that match
+ * the given predicate. This function should only be called if
+ * repo_has_promisor_remote() returns true.
+ */
+typedef int (*must_prefetch_predicate)(const struct cache_entry *);
+void prefetch_cache_entries(const struct index_state *istate,
+			    must_prefetch_predicate must_prefetch);
+
+/* Initialize and use the cache information */
+struct lock_file;
+int do_read_index(struct index_state *istate, const char *path,
+		  int must_exist); /* for testting only! */
+int read_index_from(struct index_state *, const char *path,
+		    const char *gitdir);
+int is_index_unborn(struct index_state *);
+
+/* For use with `write_locked_index()`. */
+#define COMMIT_LOCK		(1 << 0)
+#define SKIP_IF_UNCHANGED	(1 << 1)
+
+/*
+ * Write the index while holding an already-taken lock. Close the lock,
+ * and if `COMMIT_LOCK` is given, commit it.
+ *
+ * Unless a split index is in use, write the index into the lockfile.
+ *
+ * With a split index, write the shared index to a temporary file,
+ * adjust its permissions and rename it into place, then write the
+ * split index to the lockfile. If the temporary file for the shared
+ * index cannot be created, fall back to the behavior described in
+ * the previous paragraph.
+ *
+ * With `COMMIT_LOCK`, the lock is always committed or rolled back.
+ * Without it, the lock is closed, but neither committed nor rolled
+ * back.
+ *
+ * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
+ * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
+ */
+int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
+
+void discard_index(struct index_state *);
+void move_index_extensions(struct index_state *dst, struct index_state *src);
+int unmerged_index(const struct index_state *);
+
+/**
+ * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
+ * compares istate to HEAD.  If tree is NULL and on an unborn branch,
+ * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
+ * provided, the space-separated list of files that differ will be appended
+ * to it.
+ */
+int repo_index_has_changes(struct repository *repo,
+			   struct tree *tree,
+			   struct strbuf *sb);
+
+int verify_path(const char *path, unsigned mode);
+int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
+
+/*
+ * Searches for an entry defined by name and namelen in the given index.
+ * If the return value is positive (including 0) it is the position of an
+ * exact match. If the return value is negative, the negated value minus 1
+ * is the position where the entry would be inserted.
+ * Example: The current index consists of these files and its stages:
+ *
+ *   b#0, d#0, f#1, f#3
+ *
+ * index_name_pos(&index, "a", 1) -> -1
+ * index_name_pos(&index, "b", 1) ->  0
+ * index_name_pos(&index, "c", 1) -> -2
+ * index_name_pos(&index, "d", 1) ->  1
+ * index_name_pos(&index, "e", 1) -> -3
+ * index_name_pos(&index, "f", 1) -> -3
+ * index_name_pos(&index, "g", 1) -> -5
+ */
+int index_name_pos(struct index_state *, const char *name, int namelen);
+
+/*
+ * Like index_name_pos, returns the position of an entry of the given name in
+ * the index if one exists, otherwise returns a negative value where the negated
+ * value minus 1 is the position where the index entry would be inserted. Unlike
+ * index_name_pos, however, a sparse index is not expanded to find an entry
+ * inside a sparse directory.
+ */
+int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
+
+/*
+ * Determines whether an entry with the given name exists within the
+ * given index. The return value is 1 if an exact match is found, otherwise
+ * it is 0. Note that, unlike index_name_pos, this function does not expand
+ * the index if it is sparse. If an item exists within the full index but it
+ * is contained within a sparse directory (and not in the sparse index), 0 is
+ * returned.
+ */
+int index_entry_exists(struct index_state *, const char *name, int namelen);
+
+/*
+ * Some functions return the negative complement of an insert position when a
+ * precise match was not found but a position was found where the entry would
+ * need to be inserted. This helper protects that logic from any integer
+ * underflow.
+ */
+static inline int index_pos_to_insert_pos(uintmax_t pos)
+{
+	if (pos > INT_MAX)
+		die("overflow: -1 - %"PRIuMAX, pos);
+	return -1 - (int)pos;
+}
+
+#define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
+#define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
+#define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
+#define ADD_CACHE_JUST_APPEND 8		/* Append only */
+#define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
+#define ADD_CACHE_KEEP_CACHE_TREE 32	/* Do not invalidate cache-tree */
+#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
+int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
+void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
+
+/* Remove entry, return true if there are more entries to go. */
+int remove_index_entry_at(struct index_state *, int pos);
+
+void remove_marked_cache_entries(struct index_state *istate, int invalidate);
+int remove_file_from_index(struct index_state *, const char *path);
+#define ADD_CACHE_VERBOSE 1
+#define ADD_CACHE_PRETEND 2
+#define ADD_CACHE_IGNORE_ERRORS	4
+#define ADD_CACHE_IGNORE_REMOVAL 8
+#define ADD_CACHE_INTENT 16
+/*
+ * These two are used to add the contents of the file at path
+ * to the index, marking the working tree up-to-date by storing
+ * the cached stat info in the resulting cache entry.  A caller
+ * that has already run lstat(2) on the path can call
+ * add_to_index(), and all others can call add_file_to_index();
+ * the latter will do necessary lstat(2) internally before
+ * calling the former.
+ */
+int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
+int add_file_to_index(struct index_state *, const char *path, int flags);
+
+int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
+int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
+void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
+int index_name_is_other(struct index_state *, const char *, int);
+void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
+
+/* do stat comparison even if CE_VALID is true */
+#define CE_MATCH_IGNORE_VALID		01
+/* do not check the contents but report dirty on racily-clean entries */
+#define CE_MATCH_RACY_IS_DIRTY		02
+/* do stat comparison even if CE_SKIP_WORKTREE is true */
+#define CE_MATCH_IGNORE_SKIP_WORKTREE	04
+/* ignore non-existent files during stat update  */
+#define CE_MATCH_IGNORE_MISSING		0x08
+/* enable stat refresh */
+#define CE_MATCH_REFRESH		0x10
+/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
+#define CE_MATCH_IGNORE_FSMONITOR 0X20
+int is_racy_timestamp(const struct index_state *istate,
+		      const struct cache_entry *ce);
+int has_racy_timestamp(struct index_state *istate);
+int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
+int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
+
+int match_stat_data_racy(const struct index_state *istate,
+			 const struct stat_data *sd, struct stat *st);
+
+void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
+
+#define REFRESH_REALLY                   (1 << 0) /* ignore_valid */
+#define REFRESH_UNMERGED                 (1 << 1) /* allow unmerged */
+#define REFRESH_QUIET                    (1 << 2) /* be quiet about it */
+#define REFRESH_IGNORE_MISSING           (1 << 3) /* ignore non-existent */
+#define REFRESH_IGNORE_SUBMODULES        (1 << 4) /* ignore submodules */
+#define REFRESH_IN_PORCELAIN             (1 << 5) /* user friendly output, not "needs update" */
+#define REFRESH_PROGRESS                 (1 << 6) /* show progress bar if stderr is tty */
+#define REFRESH_IGNORE_SKIP_WORKTREE     (1 << 7) /* ignore skip_worktree entries */
+int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
+/*
+ * Refresh the index and write it to disk.
+ *
+ * 'refresh_flags' is passed directly to 'refresh_index()', while
+ * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
+ * the lockfile is always either committed or rolled back.
+ *
+ * If 'gentle' is passed, errors locking the index are ignored.
+ *
+ * Return 1 if refreshing the index returns an error, -1 if writing
+ * the index to disk fails, 0 on success.
+ *
+ * Note that if refreshing the index returns an error, we still write
+ * out the index (unless locking fails).
+ */
+int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg);
+
+struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
+
+void set_alternate_index_output(const char *);
+
+extern int verify_index_checksum;
+extern int verify_ce_order;
+
+int cmp_cache_name_compare(const void *a_, const void *b_);
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags);
+
+void overlay_tree_on_index(struct index_state *istate,
+			   const char *tree_name, const char *prefix);
+
+#endif /* READ_CACHE_LL_H */
diff --git a/read-cache.c b/read-cache.c
index 3fad839fb6f..42f27b06642 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -28,6 +28,7 @@
 #include "name-hash.h"
 #include "object-name.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/read-cache.h b/read-cache.h
new file mode 100644
index 00000000000..043da1f1aae
--- /dev/null
+++ b/read-cache.h
@@ -0,0 +1,45 @@
+#ifndef READ_CACHE_H
+#define READ_CACHE_H
+
+#include "read-cache-ll.h"
+#include "object.h"
+#include "pathspec.h"
+
+static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
+					     unsigned int mode)
+{
+	extern int trust_executable_bit, has_symlinks;
+	if (!has_symlinks && S_ISREG(mode) &&
+	    ce && S_ISLNK(ce->ce_mode))
+		return ce->ce_mode;
+	if (!trust_executable_bit && S_ISREG(mode)) {
+		if (ce && S_ISREG(ce->ce_mode))
+			return ce->ce_mode;
+		return create_ce_mode(0666);
+	}
+	return create_ce_mode(mode);
+}
+
+static inline int ce_to_dtype(const struct cache_entry *ce)
+{
+	unsigned ce_mode = ntohl(ce->ce_mode);
+	if (S_ISREG(ce_mode))
+		return DT_REG;
+	else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
+		return DT_DIR;
+	else if (S_ISLNK(ce_mode))
+		return DT_LNK;
+	else
+		return DT_UNKNOWN;
+}
+
+static inline int ce_path_match(struct index_state *istate,
+				const struct cache_entry *ce,
+				const struct pathspec *pathspec,
+				char *seen)
+{
+	return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
+			      S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
+}
+
+#endif /* READ_CACHE_H */
diff --git a/repository.c b/repository.c
index c53e480e326..ebad755c2cc 100644
--- a/repository.c
+++ b/repository.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
+#include "read-cache-ll.h"
 #include "remote.h"
 #include "setup.h"
 #include "submodule-config.h"
diff --git a/rerere.c b/rerere.c
index e968d413d65..3bc9aedc286 100644
--- a/rerere.c
+++ b/rerere.c
@@ -7,6 +7,7 @@
 #include "hex.h"
 #include "lockfile.h"
 #include "string-list.h"
+#include "read-cache-ll.h"
 #include "rerere.h"
 #include "xdiff-interface.h"
 #include "dir.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 7ec09e89d4f..59598877841 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "hash.h"
+#include "read-cache.h"
 #include "resolve-undo.h"
 #include "sparse-index.h"
 #include "string-list.h"
diff --git a/revision.c b/revision.c
index 88b2f42daa6..8d37ec9f495 100644
--- a/revision.c
+++ b/revision.c
@@ -31,6 +31,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "strvec.h"
diff --git a/split-index.c b/split-index.c
index 40e54760b35..0a8d3903d6f 100644
--- a/split-index.c
+++ b/split-index.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "hash.h"
 #include "mem-pool.h"
+#include "read-cache-ll.h"
 #include "split-index.h"
 #include "strbuf.h"
 #include "ewah/ewok.h"
diff --git a/submodule.c b/submodule.c
index 2e78f513496..e09722d6be3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -28,6 +28,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "commit-reach.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "shallow.h"
 #include "trace2.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9507b356e22..9d64422b3cc 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index f22f7bd84a9..78aa11bb194 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -5,6 +5,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 9a098a25cba..e4357d65ec5 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 63fde9157c4..59a24a842b4 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "split-index.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index df70be549fd..a1cbafd64f3 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index d1d63feaa9e..cbcf2419f9b 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -21,6 +21,7 @@
 #include "lockfile.h"
 #include "merge-ort.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 9f18c685b7f..386f4cdaee5 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "thread-utils.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index f40d9ad0c2d..c1e82d5d028 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 #define NUM_SECONDS 3
 
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index a06c45c1f84..b3cbaf6d2a8 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "read-cache-ll.h"
 
 int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
 {
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 6944b7e825f..8eb327b3b93 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "name-hash.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "trace.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 2ef53d5f7a2..90e4d29a06f 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -3,6 +3,7 @@
 #include "abspath.h"
 #include "environment.h"
 #include "path.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "string-list.h"
 #include "trace.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index c1ae2763954..0d548814e08 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "wrapper.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 6e17f50d225..7b7e2384043 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "tree.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index 71fe5c61455..dc6fb17f2a7 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 int cmd__sha1(int ac, const char **av)
 {
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 0ac6a99d5f2..f50f64f1f22 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 int cmd__sha256(int ac, const char **av)
 {
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index 96b9a5b5291..d3f39207f14 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "read-cache-ll.h"
 
 int cmd__strcmp_offset(int argc UNUSED, const char **argv)
 {
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index eace08072d7..d27125eeacf 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/unpack-trees.c b/unpack-trees.c
index 078c53f7a13..fdcc46e474f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -15,6 +15,7 @@
 #include "progress.h"
 #include "refs.h"
 #include "attr.h"
+#include "read-cache.h"
 #include "split-index.h"
 #include "sparse-index.h"
 #include "submodule.h"
diff --git a/unpack-trees.h b/unpack-trees.h
index 30622aeebff..9b827c307f6 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -1,8 +1,8 @@
 #ifndef UNPACK_TREES_H
 #define UNPACK_TREES_H
 
-#include "cache.h"
 #include "convert.h"
+#include "read-cache-ll.h"
 #include "strvec.h"
 #include "string-list.h"
 #include "tree-walk.h"
diff --git a/wt-status.c b/wt-status.c
index 068b76ef6d9..847b63c906e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -18,6 +18,7 @@
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "strbuf.h"
 #include "trace.h"
-- 
gitgitgadget


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

* [PATCH 16/24] cache.h: remove this no-longer-used header
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (14 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 15/24] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 17/24] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Since this header showed up in some places besides just #include
statements, update/clean-up/remove those other places as well.

Note that compat/fsmonitor/fsm-path-utils-darwin.c previously got
away with violating the rule that all files must start with an include
of git-compat-util.h (or a short-list of alternate headers that happen
to include it first).  This change exposed the violation and caused it
to stop building correctly; fix it by having it include
git-compat-util.h first, as per policy.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/CodingGuidelines           |  2 +-
 Documentation/MyFirstObjectWalk.txt      |  2 +-
 Documentation/user-manual.txt            | 18 ++++++++----------
 Makefile                                 |  2 +-
 add-interactive.c                        |  2 +-
 add-patch.c                              |  2 +-
 apply.c                                  |  2 +-
 attr.c                                   |  2 +-
 blame.c                                  |  2 +-
 builtin.h                                |  1 -
 builtin/add.c                            |  3 +--
 builtin/am.c                             |  3 +--
 builtin/apply.c                          |  1 -
 builtin/archive.c                        |  1 -
 builtin/bisect.c                         |  1 -
 builtin/branch.c                         |  3 +--
 builtin/bundle.c                         |  1 -
 builtin/cat-file.c                       |  3 +--
 builtin/check-attr.c                     |  1 -
 builtin/check-ignore.c                   |  1 -
 builtin/check-ref-format.c               |  3 +--
 builtin/clean.c                          |  1 -
 builtin/column.c                         |  1 -
 builtin/commit-tree.c                    |  3 +--
 builtin/commit.c                         |  3 +--
 builtin/count-objects.c                  |  3 +--
 builtin/describe.c                       |  3 +--
 builtin/diff-files.c                     |  3 +--
 builtin/diff-index.c                     |  3 +--
 builtin/diff-tree.c                      |  3 +--
 builtin/diff.c                           |  3 +--
 builtin/difftool.c                       |  3 +--
 builtin/fast-export.c                    |  1 -
 builtin/fast-import.c                    |  1 -
 builtin/fetch.c                          |  3 +--
 builtin/for-each-ref.c                   |  1 -
 builtin/for-each-repo.c                  |  3 +--
 builtin/fsck.c                           |  1 -
 builtin/get-tar-commit-id.c              |  3 +--
 builtin/grep.c                           |  3 +--
 builtin/help.c                           |  3 +--
 builtin/hook.c                           |  1 -
 builtin/init-db.c                        |  3 +--
 builtin/interpret-trailers.c             |  1 -
 builtin/ls-files.c                       |  3 +--
 builtin/ls-remote.c                      |  1 -
 builtin/ls-tree.c                        |  3 +--
 builtin/mailinfo.c                       |  3 +--
 builtin/mailsplit.c                      |  1 -
 builtin/merge-base.c                     |  1 -
 builtin/merge-file.c                     |  1 -
 builtin/merge-recursive.c                |  1 -
 builtin/merge.c                          |  3 +--
 builtin/multi-pack-index.c               |  1 -
 builtin/notes.c                          |  3 +--
 builtin/patch-id.c                       |  1 -
 builtin/prune.c                          |  3 +--
 builtin/pull.c                           |  3 +--
 builtin/push.c                           |  3 +--
 builtin/range-diff.c                     |  1 -
 builtin/read-tree.c                      |  3 +--
 builtin/replace.c                        |  3 +--
 builtin/rerere.c                         |  1 -
 builtin/rev-list.c                       |  3 +--
 builtin/rev-parse.c                      |  3 +--
 builtin/shortlog.c                       |  1 -
 builtin/show-branch.c                    |  3 +--
 builtin/show-index.c                     |  1 -
 builtin/show-ref.c                       |  1 -
 builtin/sparse-checkout.c                |  1 -
 builtin/stripspace.c                     |  1 -
 builtin/submodule--helper.c              |  1 -
 builtin/symbolic-ref.c                   |  1 -
 builtin/tag.c                            |  3 +--
 builtin/unpack-objects.c                 |  1 -
 builtin/update-index.c                   |  3 +--
 builtin/update-ref.c                     |  3 +--
 builtin/update-server-info.c             |  3 +--
 builtin/upload-archive.c                 |  1 -
 builtin/upload-pack.c                    |  1 -
 builtin/verify-commit.c                  |  3 +--
 builtin/verify-pack.c                    |  1 -
 builtin/verify-tag.c                     |  3 +--
 builtin/worktree.c                       |  3 +--
 builtin/write-tree.c                     |  1 -
 cache-tree.c                             |  2 +-
 cache.h                                  |  6 ------
 compat/fsmonitor/fsm-health-win32.c      |  2 +-
 compat/fsmonitor/fsm-listen-win32.c      |  2 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |  1 +
 compat/fsmonitor/fsm-path-utils-win32.c  |  2 +-
 compat/fsmonitor/fsm-settings-win32.c    |  2 +-
 compat/mingw.c                           |  1 -
 compat/precompose_utf8.c                 |  2 +-
 compat/sha1-chunked.c                    |  2 +-
 compat/simple-ipc/ipc-win32.c            |  2 +-
 compat/win32/trace2_win32_process_info.c |  2 +-
 convert.c                                |  2 +-
 diff-lib.c                               |  2 +-
 diff.c                                   |  2 +-
 entry.c                                  |  2 +-
 environment.c                            |  2 +-
 fsmonitor-ipc.c                          |  2 +-
 fsmonitor.c                              |  2 +-
 fsmonitor.h                              |  1 -
 hash-lookup.c                            |  2 +-
 merge-ort-wrappers.c                     |  2 +-
 merge-ort.c                              |  2 +-
 merge-recursive.c                        |  2 +-
 merge.c                                  |  2 +-
 name-hash.c                              |  2 +-
 object-name.c                            |  2 +-
 object.c                                 |  2 +-
 parallel-checkout.c                      |  2 +-
 pathspec.c                               |  2 +-
 preload-index.c                          |  2 +-
 read-cache.c                             |  2 +-
 refs/files-backend.c                     |  2 +-
 refs/packed-backend.c                    |  2 +-
 repository.c                             |  2 +-
 rerere.c                                 |  2 +-
 resolve-undo.c                           |  2 +-
 revision.c                               |  2 +-
 run-command.h                            |  2 +-
 sequencer.c                              |  2 +-
 shallow.c                                |  2 +-
 sparse-index.c                           |  2 +-
 split-index.c                            |  2 +-
 strbuf.h                                 |  4 ----
 submodule.c                              |  2 +-
 t/helper/test-cache-tree.c               |  1 -
 t/helper/test-dump-cache-tree.c          |  1 -
 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-hash-speed.c               |  1 -
 t/helper/test-index-version.c            |  1 -
 t/helper/test-lazy-init-name-hash.c      |  1 -
 t/helper/test-path-utils.c               |  1 -
 t/helper/test-read-cache.c               |  1 -
 t/helper/test-scrap-cache-tree.c         |  1 -
 t/helper/test-sha1.c                     |  1 -
 t/helper/test-sha256.c                   |  1 -
 t/helper/test-strcmp-offset.c            |  1 -
 t/helper/test-write-cache.c              |  1 -
 unpack-trees.c                           |  2 +-
 wt-status.c                              |  2 +-
 149 files changed, 99 insertions(+), 205 deletions(-)
 delete mode 100644 cache.h

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 003393ed161..2b472df29d5 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -444,7 +444,7 @@ For C programs:
  - The first #include in C files, except in platform specific compat/
    implementations and sha1dc/, must be either "git-compat-util.h" or
    one of the approved headers that includes it first for you.  (The
-   approved headers currently include "cache.h", "builtin.h",
+   approved headers currently include "builtin.h",
    "t/helper/test-tool.h", "xdiff/xinclude.h", or
    "reftable/system.h").  You do not have to include more than one of
    these.
diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index eee513e86f4..200e628e301 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -124,7 +124,7 @@ parameters provided by the user over the CLI.
 
 `nr` represents the number of `rev_cmdline_entry` present in the array.
 
-`alloc` is used by the `ALLOC_GROW` macro. Check `cache.h` - this variable is
+`alloc` is used by the `ALLOC_GROW` macro. Check `alloc.h` - this variable is
 used to track the allocated size of the list.
 
 Per entry, we find:
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index dc9c6a663a9..100630ba3d2 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -4102,13 +4102,11 @@ Note that terminology has changed since that revision.  For example, the
 README in that revision uses the word "changeset" to describe what we
 now call a <<def_commit_object,commit>>.
 
-Also, we do not call it "cache" any more, but rather "index"; however, the
-file is still called `cache.h`.  Remark: Not much reason to change it now,
-especially since there is no good single name for it anyway, because it is
-basically _the_ header file which is included by _all_ of Git's C sources.
+Also, we do not call it "cache" any more, but rather "index"; however,
+the file is still called `read-cache.h`.
 
 If you grasp the ideas in that initial commit, you should check out a
-more recent version and skim `cache.h`, `object.h` and `commit.h`.
+more recent version and skim `read-cache-ll.h`, `object.h` and `commit.h`.
 
 In the early days, Git (in the tradition of UNIX) was a bunch of programs
 which were extremely simple, and which you used in scripts, piping the
@@ -4119,11 +4117,11 @@ many of these parts have become builtins, and some of the core has been
 and to avoid code duplication.
 
 By now, you know what the index is (and find the corresponding data
-structures in `cache.h`), and that there are just a couple of object types
-(blobs, trees, commits and tags) which inherit their common structure from
-`struct object`, which is their first member (and thus, you can cast e.g.
-`(struct object *)commit` to achieve the _same_ as `&commit->object`, i.e.
-get at the object name and flags).
+structures in `read-cache-ll.h`), and that there are just a couple of
+object types (blobs, trees, commits and tags) which inherit their
+common structure from `struct object`, which is their first member
+(and thus, you can cast e.g.  `(struct object *)commit` to achieve the
+_same_ as `&commit->object`, i.e.  get at the object name and flags).
 
 Now is a good point to take a break to let this information sink in.
 
diff --git a/Makefile b/Makefile
index cbc7f212016..2d180abc5ca 100644
--- a/Makefile
+++ b/Makefile
@@ -1952,7 +1952,7 @@ endif
 	BASIC_CFLAGS += \
 		-DSHA1DC_NO_STANDARD_INCLUDES \
 		-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
-		-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
+		-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"git-compat-util.h\"" \
 		-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
 endif
 endif
diff --git a/add-interactive.c b/add-interactive.c
index a9671e33491..40f88c02051 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "add-interactive.h"
 #include "color.h"
 #include "config.h"
diff --git a/add-patch.c b/add-patch.c
index 7d4d298286d..875b96e2274 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "add-interactive.h"
 #include "advice.h"
 #include "alloc.h"
diff --git a/apply.c b/apply.c
index f056c8f3bb9..e44a5dd7c50 100644
--- a/apply.c
+++ b/apply.c
@@ -7,7 +7,7 @@
  *
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "base85.h"
diff --git a/attr.c b/attr.c
index 57c813d8e77..5a32bfadb37 100644
--- a/attr.c
+++ b/attr.c
@@ -6,7 +6,7 @@
  * an insanely large number of attributes.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/blame.c b/blame.c
index a29ae7c14b2..15bbf16057a 100644
--- a/blame.c
+++ b/blame.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "refs.h"
 #include "object-store.h"
 #include "cache-tree.h"
diff --git a/builtin.h b/builtin.h
index cb0db676814..3e6c22eef69 100644
--- a/builtin.h
+++ b/builtin.h
@@ -3,7 +3,6 @@
 
 #include "git-compat-util.h"
 #include "strbuf.h"
-#include "cache.h"
 #include "commit.h"
 
 /*
diff --git a/builtin/add.c b/builtin/add.c
index 9fe6b6ce290..50792c0d495 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,10 +4,9 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "lockfile.h"
 #include "editor.h"
 #include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 0d8f46f8d5a..2f0f2337915 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,11 +4,10 @@
  * Based on git-am.sh by Junio C Hamano.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "editor.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/builtin/apply.c b/builtin/apply.c
index e3ff02a09e3..c18b7ea5d3d 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/archive.c b/builtin/archive.c
index b0eaa3c14a3..90761fdfee0 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -2,7 +2,6 @@
  * Copyright (c) 2006 Franck Bui-Huu
  * Copyright (c) 2006 Rene Scharfe
  */
-#include "cache.h"
 #include "builtin.h"
 #include "archive.h"
 #include "gettext.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 4812450c393..bce0ee6268a 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "copy.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 501c47657c9..5e9b0e4ea44 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -5,14 +5,13 @@
  * Based on git-branch.sh by Junio C Hamano.
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "color.h"
 #include "editor.h"
 #include "environment.h"
 #include "refs.h"
 #include "commit.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "remote.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 44113389d7a..3f63631c039 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -6,7 +6,6 @@
 #include "parse-options.h"
 #include "pkt-line.h"
 #include "repository.h"
-#include "cache.h"
 #include "bundle.h"
 
 /*
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 0bafc14e6c0..9646e7209ca 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -4,11 +4,10 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "alloc.h"
 #include "config.h"
 #include "convert.h"
-#include "builtin.h"
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index b2b678847f5..869c04420d3 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "attr.h"
 #include "environment.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index e4b78782a32..906cd967536 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 57f0505070f..5eb6bdc3f69 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -2,9 +2,8 @@
  * GIT - The information manager from hell
  */
 
-#include "cache.h"
-#include "refs.h"
 #include "builtin.h"
+#include "refs.h"
 #include "setup.h"
 #include "strbuf.h"
 
diff --git a/builtin/clean.c b/builtin/clean.c
index 49c7af45b03..66b4479356d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -9,7 +9,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/column.c b/builtin/column.c
index de623a16c2d..ce13ff0baa2 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d1d251c3ded..d2121f30d45 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -12,7 +12,6 @@
 #include "repository.h"
 #include "commit.h"
 #include "tree.h"
-#include "builtin.h"
 #include "utf8.h"
 #include "gpg-interface.h"
 #include "parse-options.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 5be05c9d9e1..3b90cb748cd 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,7 +6,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "lockfile.h"
@@ -15,7 +15,6 @@
 #include "dir.h"
 #include "editor.h"
 #include "environment.h"
-#include "builtin.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "commit.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index f3d8f1bcbb0..b9e6b55a9a9 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -4,13 +4,12 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "repository.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index f1be7c36948..508e8df00ef 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,5 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -9,7 +9,6 @@
 #include "tag.h"
 #include "blob.h"
 #include "refs.h"
-#include "builtin.h"
 #include "exec-cmd.h"
 #include "object-name.h"
 #include "parse-options.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index 2e6b59a8bb3..b7036aa7c2b 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -3,14 +3,13 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
 #include "revision.h"
-#include "builtin.h"
 #include "submodule.h"
 
 static const char diff_files_usage[] =
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 9b98db2e77e..1ab8f8b6dc5 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
 #include "revision.h"
-#include "builtin.h"
 #include "setup.h"
 #include "submodule.h"
 
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 5a1e5d6df7c..3e281150473 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,12 +1,11 @@
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "gettext.h"
 #include "hex.h"
 #include "log-tree.h"
-#include "builtin.h"
 #include "submodule.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index a9ce701ff97..b19530c996c 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "ewah/ewok.h"
 #include "lockfile.h"
@@ -20,7 +20,6 @@
 #include "read-cache-ll.h"
 #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 88809976c53..4a22de3eddb 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -12,11 +12,10 @@
  * Copyright (C) 2016 Johannes Schindelin
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "copy.h"
-#include "builtin.h"
 #include "run-command.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9a95f6a1a82..5f3ffd6912f 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2007 Johannes E. Schindelin
  */
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index bbd9b2b3e71..67a2260a5eb 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4d7c2897528..cbc991086cd 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1,7 +1,7 @@
 /*
  * "git fetch"
  */
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "gettext.h"
@@ -15,7 +15,6 @@
 #include "oidset.h"
 #include "oid-array.h"
 #include "commit.h"
-#include "builtin.h"
 #include "string-list.h"
 #include "remote.h"
 #include "transport.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 695fc8f4a5e..d0d6ab0fd34 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "refs.h"
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 37daf7bec14..28186b30f54 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e8c5fbca58f..f05617ceb14 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 564cfcac4fb..9303e386cc7 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -1,10 +1,9 @@
 /*
  * Copyright (c) 2005, 2006 Rene Scharfe
  */
-#include "cache.h"
+#include "builtin.h"
 #include "commit.h"
 #include "tar.h"
-#include "builtin.h"
 #include "quote.h"
 #include "wrapper.h"
 
diff --git a/builtin/grep.c b/builtin/grep.c
index 0d567575890..7638d779000 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-#include "cache.h"
+#include "builtin.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hex.h"
@@ -14,7 +14,6 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree-walk.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/builtin/help.c b/builtin/help.c
index d3cf4af3f6e..e93533fb09e 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -1,9 +1,8 @@
 /*
  * Builtin help command
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "pager.h"
diff --git a/builtin/hook.c b/builtin/hook.c
index 88051795c7f..09b51a6487c 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index feb019a9dea..680ef7e1837 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -3,12 +3,11 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
-#include "builtin.h"
 #include "object-file.h"
 #include "parse-options.h"
 #include "path.h"
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
index 107ac28f0e8..c5e83452654 100644
--- a/builtin/interpret-trailers.c
+++ b/builtin/interpret-trailers.c
@@ -5,7 +5,6 @@
  *
  */
 
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index d8c1c62bcb0..a49c43864f7 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -5,13 +5,12 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "repository.h"
 #include "config.h"
 #include "convert.h"
 #include "quote.h"
 #include "dir.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "strbuf.h"
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index cb6cb77e086..a0aadc9b8ff 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "transport.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 077977a4610..f4331c640fc 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -13,7 +13,6 @@
 #include "tree.h"
 #include "commit.h"
 #include "quote.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "pathspec.h"
 
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index a032a1c3881..53b55dd71c0 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -2,9 +2,8 @@
  * Another stupid program, this one parsing the headers of an
  * email to figure out authorship and subject
  */
-#include "cache.h"
-#include "abspath.h"
 #include "builtin.h"
+#include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 0b6193a0915..3af9ddb8ae5 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -4,7 +4,6 @@
  * It just splits a mbox into a list of files: "0001" "0002" ..
  * so you can process them further from there.
  */
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "string-list.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 854019a32dc..e68b7fe45d7 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "gettext.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 781818d08f5..d7eb4c65401 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "setup.h"
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index b9e980384a4..3366699657c 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "advice.h"
 #include "commit.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 6e8f7b9bb53..d7ac108ce94 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,7 +7,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
 #include "alloc.h"
@@ -18,7 +18,6 @@
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
-#include "builtin.h"
 #include "lockfile.h"
 #include "run-command.h"
 #include "hook.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 1b5083f8b26..5bb71bce08d 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index d5788352b6e..efdf2451486 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -7,9 +7,8 @@
  * and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
  */
 
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "editor.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 9d5585d3a72..27952f1a6fd 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index 5dc9b207200..b3658b5b512 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
 #include "commit.h"
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
-#include "builtin.h"
 #include "reachable.h"
 #include "parse-options.h"
 #include "progress.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 8aeb5abc7fb..d4261804d76 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -6,10 +6,9 @@
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
 #include "merge.h"
diff --git a/builtin/push.c b/builtin/push.c
index 4e5780dd50d..62d44736500 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -1,7 +1,7 @@
 /*
  * "git push"
  */
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "branch.h"
 #include "config.h"
@@ -10,7 +10,6 @@
 #include "refs.h"
 #include "refspec.h"
 #include "run-command.h"
-#include "builtin.h"
 #include "remote.h"
 #include "transport.h"
 #include "parse-options.h"
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 04339a92ea5..8610390d7c5 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index bd1ce1d963f..63c92936faa 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,7 +5,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -17,7 +17,6 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "dir.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "resolve-undo.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 981f1894436..e0fbdc98ed3 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -8,9 +8,8 @@
  * git-tag.sh and mktag.c by Linus Torvalds.
  */
 
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "editor.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index d4bd52797f4..0458db9cadf 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 6dc8be492a2..8029f3de53c 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
@@ -15,7 +15,6 @@
 #include "object-store.h"
 #include "pack.h"
 #include "pack-bitmap.h"
-#include "builtin.h"
 #include "log-tree.h"
 #include "graph.h"
 #include "bisect.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index ad93e5fad88..8d8c870421d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,7 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
@@ -14,7 +14,6 @@
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
-#include "builtin.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "diff.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 46f4e0832ac..99be9dc417d 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 7ef4a642c17..cd215f89af8 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -6,7 +6,6 @@
 #include "hex.h"
 #include "pretty.h"
 #include "refs.h"
-#include "builtin.h"
 #include "color.h"
 #include "strvec.h"
 #include "object-name.h"
diff --git a/builtin/show-index.c b/builtin/show-index.c
index d839e55335d..540dc3dad1c 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hash.h"
 #include "hex.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index a2243b42195..e07e9ca862f 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 40d420f06cb..5c8ffb1f759 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 9451eb69ff4..397d7fe2dcd 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 86324b829a7..17567d91c88 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -6,7 +6,6 @@
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
-#include "cache.h"
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 10198a74fae..a61fa3c0f81 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,6 +1,5 @@
 #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 1850a6a6fdc..ce298d08945 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -6,10 +6,9 @@
  * Based on git-tag.sh and mktag.c by Linus Torvalds.
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "editor.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 2c52c3a741f..85baf6a131a 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
 #include "environment.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 484a307df50..aee3cb8cbd3 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -4,7 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "bulk-checkin.h"
 #include "config.h"
 #include "environment.h"
@@ -15,7 +15,6 @@
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
-#include "builtin.h"
 #include "object-file.h"
 #include "refs.h"
 #include "resolve-undo.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0c59b1c9eff..242102273ee 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hash.h"
 #include "refs.h"
-#include "builtin.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 19dce3c0655..1dc3971edeb 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "server-info.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index 44ad400e183..d4c7f162ff0 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -1,7 +1,6 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
-#include "cache.h"
 #include "builtin.h"
 #include "archive.h"
 #include "pkt-line.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index beb9dd08610..ba5103a9331 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "exec-cmd.h"
 #include "gettext.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 5d99b82a64f..aa34fb896ac 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -5,9 +5,8 @@
  *
  * Based on git-verify-tag
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index 190fd695409..aba92cf8af7 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "run-command.h"
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index c6019a0ad8c..d8753270ebe 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -5,9 +5,8 @@
  *
  * Based on git-verify-tag.sh
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "tag.h"
 #include "run-command.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 3c3d97ad5b0..b9a84988637 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "checkout.h"
 #include "config.h"
 #include "copy.h"
-#include "builtin.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index f98d54c1df2..5917085f429 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,7 +5,6 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/cache-tree.c b/cache-tree.c
index 153217b47ff..077932c2db5 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "environment.h"
 #include "hex.h"
diff --git a/cache.h b/cache.h
deleted file mode 100644
index 9b4e8d16874..00000000000
--- a/cache.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef CACHE_H
-#define CACHE_H
-
-#include "git-compat-util.h"
-
-#endif /* CACHE_H */
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index fe11bdd9ce6..6c81d7ee5c2 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsm-health.h"
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 677b1bbdeca..3c0df5cff8c 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsm-listen.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index 45eb4a9b9e7..ef0142e0fbf 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c
index 4024baafb97..27bb6945183 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index a8af31b71de..37288978643 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "repository.h"
 #include "fsmonitor.h"
diff --git a/compat/mingw.c b/compat/mingw.c
index d06cdc6254f..559abb1c617 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -6,7 +6,6 @@
 #include <wchar.h>
 #include "../strbuf.h"
 #include "../run-command.h"
-#include "../cache.h"
 #include "../abspath.h"
 #include "../alloc.h"
 #include "win32/lazyload.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index fb08475bc64..0bd5c24250a 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -5,7 +5,7 @@
 
 #define PRECOMPOSE_UNICODE_C
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 56729d92dcf..a4a6f930d7b 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hash-ll.h"
 
 int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 6adce3c650e..8bfe51248e5 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index a4e33768f43..a2b1506f9c9 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,4 +1,4 @@
-#include "../../cache.h"
+#include "../../git-compat-util.h"
 #include "../../json-writer.h"
 #include "../../repository.h"
 #include "../../trace2.h"
diff --git a/convert.c b/convert.c
index 236d5e3dc25..9e89f660308 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
 #include "convert.h"
diff --git a/diff-lib.c b/diff-lib.c
index 36cd66ea237..f3aa7f93c78 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "quote.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/diff.c b/diff.c
index 61b4dc61e1e..5e81dc0d02d 100644
--- a/diff.c
+++ b/diff.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "base85.h"
diff --git a/entry.c b/entry.c
index 53d00386748..041f5cf212d 100644
--- a/entry.c
+++ b/entry.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
diff --git a/environment.c b/environment.c
index 28d18eaca8e..0cdd20a1589 100644
--- a/environment.c
+++ b/environment.c
@@ -110,7 +110,7 @@ char *git_work_tree_cfg;
 static char *git_namespace;
 
 /*
- * Repository-local GIT_* environment variables; see cache.h for details.
+ * Repository-local GIT_* environment variables; see environment.h for details.
  */
 const char * const local_repo_env[] = {
 	ALTERNATE_DB_ENVIRONMENT,
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6a6a89764a6..6ace978a1b4 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/fsmonitor.c b/fsmonitor.c
index 28c083d4d84..f670c509378 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/fsmonitor.h b/fsmonitor.h
index 8b7a521552a..7702301d214 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,7 +1,6 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
-#include "cache.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
 #include "object.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 8fec8939fd3..9f0f95e2b9e 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hash.h"
 #include "hash-lookup.h"
 #include "read-cache-ll.h"
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a0bedcb63bb..4acedf3c338 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hash.h"
 #include "merge-ort.h"
diff --git a/merge-ort.c b/merge-ort.c
index 5512f40d321..c2d2ee73eaa 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,7 +14,7 @@
  * "cale", "peedy", or "ins" instead of "ort"?)
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "merge-ort.h"
 
 #include "alloc.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 0e16e7a06df..4bef9b62fa8 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,7 +3,7 @@
  * Fredrik Kuivinen.
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "merge-recursive.h"
 
 #include "advice.h"
diff --git a/merge.c b/merge.c
index fade6b203b3..83bcba6943e 100644
--- a/merge.c
+++ b/merge.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
diff --git a/name-hash.c b/name-hash.c
index f2f3564cb20..251f036eef6 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -5,7 +5,7 @@
  *
  * Copyright (C) 2008 Linus Torvalds
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
diff --git a/object-name.c b/object-name.c
index 1eefeef746e..45f4d51305b 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "object-name.h"
 #include "advice.h"
 #include "config.h"
diff --git a/object.c b/object.c
index 333e736fb24..60f954194f7 100644
--- a/object.c
+++ b/object.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object.h"
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 2b1439c0c5f..602fbf19d3c 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
diff --git a/pathspec.c b/pathspec.c
index 47d172fe414..0baa85384f8 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
diff --git a/preload-index.c b/preload-index.c
index d037a951efa..e44530c80cf 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2008 Linus Torvalds
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "pathspec.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/read-cache.c b/read-cache.c
index 42f27b06642..edab96765df 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
 #include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index bca7b851c5a..01c08207619 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
 #include "../config.h"
 #include "../copy.h"
 #include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 085becf773e..713491a9e2c 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
 #include "../alloc.h"
 #include "../config.h"
 #include "../gettext.h"
diff --git a/repository.c b/repository.c
index ebad755c2cc..67ec56a70c5 100644
--- a/repository.c
+++ b/repository.c
@@ -3,7 +3,7 @@
  * declaration matches the definition in this file.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/rerere.c b/rerere.c
index 3bc9aedc286..2fb93a51125 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 59598877841..7817f5d6db1 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "dir.h"
 #include "hash.h"
 #include "read-cache.h"
diff --git a/revision.c b/revision.c
index 8d37ec9f495..66a1fece0df 100644
--- a/revision.c
+++ b/revision.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/run-command.h b/run-command.h
index 9e47f91d462..1f22cc3827d 100644
--- a/run-command.h
+++ b/run-command.h
@@ -503,7 +503,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts);
  * exception of GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT (which cause the
  * corresponding environment variables to be unset in the subprocess) and adds
  * an environment variable pointing to new_git_dir. See local_repo_env in
- * cache.h for more information.
+ * environment.h for more information.
  */
 void prepare_other_repo_env(struct strvec *env, const char *new_git_dir);
 
diff --git a/sequencer.c b/sequencer.c
index ec4a2e80a10..08bd0e81743 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
 #include "alloc.h"
diff --git a/shallow.c b/shallow.c
index a2ebf0af2ba..f1c93e74648 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/sparse-index.c b/sparse-index.c
index 60451daae80..2c47954d933 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/split-index.c b/split-index.c
index 0a8d3903d6f..0ee3865a553 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hash.h"
diff --git a/strbuf.h b/strbuf.h
index 3dfeadb44c2..e8dfab6ecd6 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -72,10 +72,6 @@ struct strbuf {
 extern char strbuf_slopbuf[];
 #define STRBUF_INIT  { .buf = strbuf_slopbuf }
 
-/*
- * Predeclare this here, since cache.h includes this file before it defines the
- * struct.
- */
 struct object_id;
 
 /**
diff --git a/submodule.c b/submodule.c
index e09722d6be3..20aa8ed0fb8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "repository.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9d64422b3cc..e7236392c81 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 78aa11bb194..c38f546e4f0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "hash.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index e4357d65ec5..4f215fea025 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 59a24a842b4..5cf0b26dca1 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index a1cbafd64f3..b4af9712fe5 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "dir.h"
 #include "hex.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index cbcf2419f9b..62c5b5d704b 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -12,7 +12,6 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "environment.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 386f4cdaee5..58d1dc5fc83 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -4,7 +4,6 @@
  */
 
 #include "test-tool.h"
-#include "cache.h"
 #include "parse-options.h"
 #include "fsmonitor-ipc.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index c1e82d5d028..b235da594f7 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 #define NUM_SECONDS 3
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index b3cbaf6d2a8..f3c2dbe0a2c 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 
 int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 8eb327b3b93..187a115d574 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "environment.h"
 #include "name-hash.h"
 #include "parse-options.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 90e4d29a06f..70396fa3845 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "abspath.h"
 #include "environment.h"
 #include "path.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 0d548814e08..56c2d25f359 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "config.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 7b7e2384043..0a816a96e28 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index dc6fb17f2a7..dcb7f6c0032 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 int cmd__sha1(int ac, const char **av)
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index f50f64f1f22..08cf1490014 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 int cmd__sha256(int ac, const char **av)
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index d3f39207f14..d8473cf2fcf 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 
 int cmd__strcmp_offset(int argc UNUSED, const char **argv)
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index d27125eeacf..f084034d38e 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index fdcc46e474f..4b620df3031 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "strvec.h"
 #include "repository.h"
diff --git a/wt-status.c b/wt-status.c
index 847b63c906e..6ee8567ac2d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "wt-status.h"
 #include "object.h"
-- 
gitgitgadget


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

* [PATCH 17/24] log-tree: replace include of revision.h with simple forward declaration
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (15 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 16/24] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 18/24] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
                   ` (10 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/diff-tree.c | 1 +
 log-tree.c          | 1 +
 log-tree.h          | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 3e281150473..4ad55ecc3fc 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -9,6 +9,7 @@
 #include "submodule.h"
 #include "read-cache-ll.h"
 #include "repository.h"
+#include "revision.h"
 #include "tree.h"
 
 static struct rev_info log_tree_opt;
diff --git a/log-tree.c b/log-tree.c
index f4b22a60cc5..07d0b47b168 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -16,6 +16,7 @@
 #include "reflog-walk.h"
 #include "refs.h"
 #include "replace-object.h"
+#include "revision.h"
 #include "string-list.h"
 #include "color.h"
 #include "gpg-interface.h"
diff --git a/log-tree.h b/log-tree.h
index e7e4641cf83..bdb64328154 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -1,7 +1,7 @@
 #ifndef LOG_TREE_H
 #define LOG_TREE_H
 
-#include "revision.h"
+struct rev_info;
 
 struct log_info {
 	struct commit *commit, *parent;
-- 
gitgitgadget


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

* [PATCH 18/24] repository: remove unnecessary include of path.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (16 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 17/24] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 19/24] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that several .c files that depended upon path.h
were missing a #include for it; add the missing includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.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/bisect.c                  | 1 +
 builtin/branch.c                  | 1 +
 builtin/checkout.c                | 1 +
 builtin/clean.c                   | 1 +
 builtin/clone.c                   | 1 +
 builtin/commit.c                  | 1 +
 builtin/count-objects.c           | 1 +
 builtin/fast-import.c             | 1 +
 builtin/fetch.c                   | 1 +
 builtin/fsck.c                    | 1 +
 builtin/gc.c                      | 1 +
 builtin/grep.c                    | 1 +
 builtin/ls-files.c                | 1 +
 builtin/ls-tree.c                 | 1 +
 builtin/merge.c                   | 1 +
 builtin/notes.c                   | 1 +
 builtin/prune.c                   | 1 +
 builtin/pull.c                    | 1 +
 builtin/rebase.c                  | 1 +
 builtin/receive-pack.c            | 1 +
 builtin/remote.c                  | 1 +
 builtin/repack.c                  | 1 +
 builtin/replace.c                 | 1 +
 builtin/reset.c                   | 1 +
 builtin/rev-parse.c               | 1 +
 builtin/submodule--helper.c       | 1 +
 builtin/tag.c                     | 1 +
 builtin/upload-archive.c          | 1 +
 builtin/upload-pack.c             | 1 +
 builtin/worktree.c                | 1 +
 commit-graph.c                    | 1 +
 compat/fsmonitor/fsm-ipc-darwin.c | 1 +
 config.c                          | 1 +
 connect.c                         | 1 +
 dir.c                             | 1 +
 environment.c                     | 1 +
 fetch-pack.c                      | 1 +
 fsck.c                            | 1 +
 http-backend.c                    | 1 +
 merge-ort.c                       | 1 +
 merge-recursive.c                 | 1 +
 notes-merge.c                     | 1 +
 object-file.c                     | 1 +
 pack-bitmap-write.c               | 1 +
 pack-write.c                      | 1 +
 read-cache.c                      | 1 +
 refs.c                            | 1 +
 refs/files-backend.c              | 1 +
 remote.c                          | 1 +
 repository.c                      | 1 +
 repository.h                      | 2 --
 rerere.c                          | 1 +
 sequencer.c                       | 1 +
 server-info.c                     | 1 +
 setup.c                           | 1 +
 shallow.c                         | 1 +
 strbuf.c                          | 1 +
 submodule-config.c                | 1 +
 submodule.c                       | 1 +
 t/helper/test-ref-store.c         | 1 +
 tmp-objdir.c                      | 1 +
 worktree.c                        | 1 +
 wt-status.c                       | 1 +
 71 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index e44a5dd7c50..be58dc08d22 100644
--- a/apply.c
+++ b/apply.c
@@ -27,6 +27,7 @@
 #include "object-name.h"
 #include "object-file.h"
 #include "parse-options.h"
+#include "path.h"
 #include "quote.h"
 #include "read-cache.h"
 #include "rerere.h"
diff --git a/archive.c b/archive.c
index 641baad627b..802a34d6b91 100644
--- a/archive.c
+++ b/archive.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "pretty.h"
 #include "setup.h"
 #include "refs.h"
diff --git a/attr.c b/attr.c
index 5a32bfadb37..435b51e11ff 100644
--- a/attr.c
+++ b/attr.c
@@ -14,6 +14,7 @@
 #include "attr.h"
 #include "dir.h"
 #include "gettext.h"
+#include "path.h"
 #include "utf8.h"
 #include "quote.h"
 #include "read-cache-ll.h"
diff --git a/bisect.c b/bisect.c
index 8d5f8e58851..9f7cf0be073 100644
--- a/bisect.c
+++ b/bisect.c
@@ -19,6 +19,7 @@
 #include "commit-reach.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "dir.h"
 
 static struct oid_array good_revs;
diff --git a/blame.c b/blame.c
index 15bbf16057a..b74ee70decf 100644
--- a/blame.c
+++ b/blame.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "read-cache.h"
 #include "setup.h"
 #include "tag.h"
diff --git a/branch.c b/branch.c
index 9415ee3f340..1c02078e6aa 100644
--- a/branch.c
+++ b/branch.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "path.h"
 #include "refs.h"
 #include "refspec.h"
 #include "remote.h"
diff --git a/builtin/add.c b/builtin/add.c
index 50792c0d495..43183114487 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -16,6 +16,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/builtin/am.c b/builtin/am.c
index 2f0f2337915..a78daa69714 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -41,6 +41,7 @@
 #include "string-list.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "repository.h"
 #include "pretty.h"
 #include "wrapper.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index bce0ee6268a..6478df34890 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -11,6 +11,7 @@
 #include "strvec.h"
 #include "run-command.h"
 #include "oid-array.h"
+#include "path.h"
 #include "prompt.h"
 #include "quote.h"
 #include "revision.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 5e9b0e4ea44..84f13b0cc71 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -18,6 +18,7 @@
 #include "parse-options.h"
 #include "branch.h"
 #include "diff.h"
+#include "path.h"
 #include "revision.h"
 #include "string-list.h"
 #include "column.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 09b84156492..716dcd4cae1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,6 +20,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 66b4479356d..1bb6b7965c5 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -13,6 +13,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index cc34c194f5e..6c5cb33f6a9 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -39,6 +39,7 @@
 #include "setup.h"
 #include "connected.h"
 #include "packfile.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "list-objects-filter-options.h"
 #include "hook.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 3b90cb748cd..b3ab5e93844 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -29,6 +29,7 @@
 #include "utf8.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "string-list.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index b9e6b55a9a9..c9f82d0bce9 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -9,6 +9,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
+#include "path.h"
 #include "repository.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 67a2260a5eb..5698b92ae7d 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -12,6 +12,7 @@
 #include "commit.h"
 #include "delta.h"
 #include "pack.h"
+#include "path.h"
 #include "refs.h"
 #include "csum-file.h"
 #include "quote.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index cbc991086cd..4dbacd8f188 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -28,6 +28,7 @@
 #include "utf8.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "list-objects-filter-options.h"
 #include "commit-reach.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index f05617ceb14..d707ca32a61 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -21,6 +21,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "resolve-undo.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index d6e56e380cf..9ecc2513e9f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -30,6 +30,7 @@
 #include "object-store.h"
 #include "pack.h"
 #include "pack-objects.h"
+#include "path.h"
 #include "blob.h"
 #include "tree.h"
 #include "promisor-remote.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7638d779000..6bc8abcd3e1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -30,6 +30,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "write-or-die.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a49c43864f7..ab90f821e44 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -19,6 +19,7 @@
 #include "parse-options.h"
 #include "resolve-undo.h"
 #include "string-list.h"
+#include "path.h"
 #include "pathspec.h"
 #include "read-cache.h"
 #include "run-command.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index f4331c640fc..c06858de4bf 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -12,6 +12,7 @@
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
+#include "path.h"
 #include "quote.h"
 #include "parse-options.h"
 #include "pathspec.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index d7ac108ce94..420e81008ed 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -27,6 +27,7 @@
 #include "refspec.h"
 #include "commit.h"
 #include "diffcore.h"
+#include "path.h"
 #include "revision.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index efdf2451486..0a870d90836 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -15,6 +15,7 @@
 #include "notes.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "blob.h"
 #include "pretty.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index b3658b5b512..a46c5aa2b5b 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -7,6 +7,7 @@
 #include "revision.h"
 #include "reachable.h"
 #include "parse-options.h"
+#include "path.h"
 #include "progress.h"
 #include "prune-packed.h"
 #include "replace-object.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index d4261804d76..815f6135189 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -19,6 +19,7 @@
 #include "oid-array.h"
 #include "remote.h"
 #include "dir.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "rebase.h"
 #include "refs.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ace1d5e8d11..91849f920f7 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -24,6 +24,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "commit.h"
 #include "diff.h"
 #include "wt-status.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 1a31a583674..d1718a3ac90 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -31,6 +31,7 @@
 #include "packfile.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "protocol.h"
 #include "commit-reach.h"
 #include "server-info.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 1e0b137d977..3794f13330d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "transport.h"
 #include "remote.h"
 #include "string-list.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 0541c3ce157..fe8d5810d48 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "path.h"
 #include "run-command.h"
 #include "server-info.h"
 #include "sigchain.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index e0fbdc98ed3..6b266a66d30 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -16,6 +16,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "path.h"
 #include "run-command.h"
 #include "object-file.h"
 #include "object-name.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 3dc41ac3327..f947c449d14 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -26,6 +26,7 @@
 #include "branch.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
 #include "setup.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 8d8c870421d..6eb5965bee4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -16,6 +16,7 @@
 #include "quote.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "diff.h"
 #include "read-cache-ll.h"
 #include "revision.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 17567d91c88..6acba4ebb30 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "path.h"
 #include "pathspec.h"
 #include "preload-index.h"
 #include "dir.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index ce298d08945..87963d2cc0e 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -16,6 +16,7 @@
 #include "refs.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index d4c7f162ff0..1b09e5e1aa3 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -3,6 +3,7 @@
  */
 #include "builtin.h"
 #include "archive.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "repository.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index ba5103a9331..b02d479248a 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "pkt-line.h"
 #include "parse-options.h"
+#include "path.h"
 #include "protocol.h"
 #include "replace-object.h"
 #include "upload-pack.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index b9a84988637..6ba463f6965 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -10,6 +10,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "strvec.h"
 #include "branch.h"
 #include "read-cache-ll.h"
diff --git a/commit-graph.c b/commit-graph.c
index 843bdb458d0..25cbd66c33a 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -14,6 +14,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "oid-array.h"
+#include "path.h"
 #include "alloc.h"
 #include "hashmap.h"
 #include "replace-object.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 793073aaa72..964bc074db6 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "strbuf.h"
 #include "fsmonitor.h"
diff --git a/config.c b/config.c
index 06e6cc6f1ec..666ec73bab1 100644
--- a/config.c
+++ b/config.c
@@ -27,6 +27,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "pager.h"
+#include "path.h"
 #include "utf8.h"
 #include "dir.h"
 #include "color.h"
diff --git a/connect.c b/connect.c
index 3a0186280c4..37674f71122 100644
--- a/connect.c
+++ b/connect.c
@@ -12,6 +12,7 @@
 #include "url.h"
 #include "string-list.h"
 #include "oid-array.h"
+#include "path.h"
 #include "transport.h"
 #include "trace2.h"
 #include "strbuf.h"
diff --git a/dir.c b/dir.c
index 1e84b1e1f28..3cf3d428c7b 100644
--- a/dir.c
+++ b/dir.c
@@ -16,6 +16,7 @@
 #include "name-hash.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "path.h"
 #include "attr.h"
 #include "refs.h"
 #include "wildmatch.h"
diff --git a/environment.c b/environment.c
index 0cdd20a1589..56e8742ea66 100644
--- a/environment.c
+++ b/environment.c
@@ -21,6 +21,7 @@
 #include "strvec.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "path.h"
 #include "replace-object.h"
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f71054fbae..207548b3e5a 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -25,6 +25,7 @@
 #include "oidset.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "path.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
 #include "fsck.h"
diff --git a/fsck.c b/fsck.c
index 3261ef9ec28..04e729953b2 100644
--- a/fsck.c
+++ b/fsck.c
@@ -3,6 +3,7 @@
 #include "date.h"
 #include "hex.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "object.h"
 #include "attr.h"
diff --git a/http-backend.c b/http-backend.c
index ac146d85c54..ddb9549ecbc 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "git-zlib.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/merge-ort.c b/merge-ort.c
index c2d2ee73eaa..eed71b04389 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -36,6 +36,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "oid-array.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "read-cache-ll.h"
 #include "revision.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 4bef9b62fa8..527dbbd010a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -27,6 +27,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "revision.h"
 #include "sparse-index.h"
diff --git a/notes-merge.c b/notes-merge.c
index 233e49e3195..4b328d852cd 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -6,6 +6,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/object-file.c b/object-file.c
index 7c1af5c8db8..8d87720dd53 100644
--- a/object-file.c
+++ b/object-file.c
@@ -39,6 +39,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "oidtree.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index cdffe2ce47d..623ee2a8197 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -15,6 +15,7 @@
 #include "pack-bitmap.h"
 #include "hash-lookup.h"
 #include "pack-objects.h"
+#include "path.h"
 #include "commit-reach.h"
 #include "prio-queue.h"
 #include "trace2.h"
diff --git a/pack-write.c b/pack-write.c
index 3b3ce89de6e..45681e2d7db 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -10,6 +10,7 @@
 #include "oidmap.h"
 #include "pack-objects.h"
 #include "pack-revindex.h"
+#include "path.h"
 #include "wrapper.h"
 
 void reset_pack_idx_option(struct pack_idx_option *opts)
diff --git a/read-cache.c b/read-cache.c
index edab96765df..86ada403a83 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@
 #include "mem-pool.h"
 #include "name-hash.h"
 #include "object-name.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "resolve-undo.h"
diff --git a/refs.c b/refs.c
index d2a98e1c21f..3c0c95ac442 100644
--- a/refs.c
+++ b/refs.c
@@ -19,6 +19,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "object.h"
+#include "path.h"
 #include "tag.h"
 #include "submodule.h"
 #include "worktree.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 01c08207619..6fa7decec0a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -15,6 +15,7 @@
 #include "../lockfile.h"
 #include "../object.h"
 #include "../object-file.h"
+#include "../path.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
 #include "../setup.h"
diff --git a/remote.c b/remote.c
index 0764fca0db9..8550056db43 100644
--- a/remote.c
+++ b/remote.c
@@ -11,6 +11,7 @@
 #include "refspec.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/repository.c b/repository.c
index 67ec56a70c5..87a7a27b665 100644
--- a/repository.c
+++ b/repository.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "remote.h"
 #include "setup.h"
diff --git a/repository.h b/repository.h
index 763794880ed..510aa6d9a2f 100644
--- a/repository.h
+++ b/repository.h
@@ -1,8 +1,6 @@
 #ifndef REPOSITORY_H
 #define REPOSITORY_H
 
-#include "path.h"
-
 struct config_set;
 struct fsmonitor_settings;
 struct git_hash_algo;
diff --git a/rerere.c b/rerere.c
index 2fb93a51125..35b9785d573 100644
--- a/rerere.c
+++ b/rerere.c
@@ -14,6 +14,7 @@
 #include "resolve-undo.h"
 #include "ll-merge.h"
 #include "attr.h"
+#include "path.h"
 #include "pathspec.h"
 #include "object-file.h"
 #include "object-store.h"
diff --git a/sequencer.c b/sequencer.c
index 08bd0e81743..eddd38d4bed 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -23,6 +23,7 @@
 #include "utf8.h"
 #include "cache-tree.h"
 #include "diff.h"
+#include "path.h"
 #include "revision.h"
 #include "rerere.h"
 #include "merge.h"
diff --git a/server-info.c b/server-info.c
index 55aa04f00ab..85d17bbb151 100644
--- a/server-info.c
+++ b/server-info.c
@@ -9,6 +9,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "packfile.h"
+#include "path.h"
 #include "object-file.h"
 #include "object-store.h"
 #include "server-info.h"
diff --git a/setup.c b/setup.c
index 0c14a4fe765..5d0e967f3eb 100644
--- a/setup.c
+++ b/setup.c
@@ -12,6 +12,7 @@
 #include "setup.h"
 #include "string-list.h"
 #include "chdir-notify.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "quote.h"
 #include "trace2.h"
diff --git a/shallow.c b/shallow.c
index f1c93e74648..45343e6a78b 100644
--- a/shallow.c
+++ b/shallow.c
@@ -11,6 +11,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "oid-array.h"
+#include "path.h"
 #include "diff.h"
 #include "revision.h"
 #include "commit-slab.h"
diff --git a/strbuf.c b/strbuf.c
index 08eec8f1d8b..d070e007f8a 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -6,6 +6,7 @@
 #include "hex.h"
 #include "object-name.h"
 #include "refs.h"
+#include "path.h"
 #include "repository.h"
 #include "string-list.h"
 #include "utf8.h"
diff --git a/submodule-config.c b/submodule-config.c
index 58dfbde9ae5..c67260a3e11 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "config.h"
 #include "submodule-config.h"
diff --git a/submodule.c b/submodule.c
index 20aa8ed0fb8..245300596ff 100644
--- a/submodule.c
+++ b/submodule.c
@@ -20,6 +20,7 @@
 #include "strvec.h"
 #include "blob.h"
 #include "thread-utils.h"
+#include "path.h"
 #include "quote.h"
 #include "remote.h"
 #include "worktree.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 6d8f844e9c7..1b30a6cba8b 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -4,6 +4,7 @@
 #include "setup.h"
 #include "worktree.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 
 struct flag_definition {
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c33a554f921..db1f7038dae 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -5,6 +5,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "object-file.h"
+#include "path.h"
 #include "sigchain.h"
 #include "string-list.h"
 #include "strbuf.h"
diff --git a/worktree.c b/worktree.c
index b5ee71c5ebd..f9aa371ca70 100644
--- a/worktree.c
+++ b/worktree.c
@@ -3,6 +3,7 @@
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
+#include "path.h"
 #include "repository.h"
 #include "refs.h"
 #include "setup.h"
diff --git a/wt-status.c b/wt-status.c
index 6ee8567ac2d..7ada6b305f6 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "path.h"
 #include "revision.h"
 #include "diffcore.h"
 #include "quote.h"
-- 
gitgitgadget


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

* [PATCH 19/24] diff.h: remove unnecessary include of oidset.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (17 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 18/24] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 20/24] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that several .c files depended upon various
things that oidset included, but had omitted the direct #include for
those headers.  Add those now.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                | 2 ++
 add-patch.c                      | 1 +
 blame.h                          | 1 +
 builtin/add.c                    | 1 +
 builtin/diff-files.c             | 1 +
 builtin/diff-index.c             | 1 +
 builtin/merge-ours.c             | 1 +
 builtin/patch-id.c               | 1 +
 builtin/range-diff.c             | 1 +
 builtin/reflog.c                 | 1 +
 builtin/reset.c                  | 1 +
 builtin/rev-parse.c              | 1 +
 builtin/revert.c                 | 1 +
 builtin/shortlog.c               | 1 +
 builtin/stash.c                  | 1 +
 diff-lib.c                       | 2 ++
 diff.h                           | 4 +++-
 diffcore-break.c                 | 1 +
 diffcore-pickaxe.c               | 1 +
 line-log.c                       | 1 +
 merge.c                          | 2 ++
 patch-ids.c                      | 1 +
 pretty.c                         | 1 +
 range-diff.c                     | 1 +
 reflog-walk.c                    | 1 +
 t/helper/test-fast-rebase.c      | 1 +
 t/helper/test-revision-walking.c | 1 +
 transport-helper.c               | 1 +
 tree-diff.c                      | 1 +
 wt-status.c                      | 1 +
 30 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/add-interactive.c b/add-interactive.c
index 40f88c02051..add9a1ad436 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -4,9 +4,11 @@
 #include "config.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "preload-index.h"
 #include "read-cache-ll.h"
+#include "repository.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 875b96e2274..53e32482959 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -7,6 +7,7 @@
 #include "gettext.h"
 #include "object-name.h"
 #include "read-cache-ll.h"
+#include "repository.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/blame.h b/blame.h
index b60d1d81e30..31ddc85f19e 100644
--- a/blame.h
+++ b/blame.h
@@ -2,6 +2,7 @@
 #define BLAME_H
 
 #include "commit.h"
+#include "oidset.h"
 #include "xdiff-interface.h"
 #include "revision.h"
 #include "prio-queue.h"
diff --git a/builtin/add.c b/builtin/add.c
index 43183114487..e3ca3e4edbe 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -21,6 +21,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "read-cache.h"
+#include "repository.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index b7036aa7c2b..07f6dff844c 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -9,6 +9,7 @@
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
+#include "repository.h"
 #include "revision.h"
 #include "submodule.h"
 
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 1ab8f8b6dc5..a8b2c0a4b96 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -4,6 +4,7 @@
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
+#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index c2e519301e9..932924e5d0e 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -10,6 +10,7 @@
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
+#include "repository.h"
 
 static const char builtin_merge_ours_usage[] =
 	"git merge-ours <base>... -- HEAD <remote>...";
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 27952f1a6fd..b7118b290b1 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "diff.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "parse-options.h"
 
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 8610390d7c5..e455a4795cc 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -4,6 +4,7 @@
 #include "parse-options.h"
 #include "range-diff.h"
 #include "config.h"
+#include "repository.h"
 #include "revision.h"
 
 static const char * const builtin_range_diff_usage[] = {
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a1fa0c855f4..fc217748808 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
+#include "repository.h"
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index f947c449d14..dad2117c974 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -13,6 +13,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tag.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 6eb5965bee4..4a219ea93bb 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -11,6 +11,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 0240ec8593b..f6f07d9b539 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "diff.h"
 #include "gettext.h"
+#include "repository.h"
 #include "revision.h"
 #include "rerere.h"
 #include "dir.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 99be9dc417d..1307ed2b88a 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
+#include "repository.h"
 #include "revision.h"
 #include "utf8.h"
 #include "mailmap.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index d3d5bb95e26..84e83e0627f 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
diff --git a/diff-lib.c b/diff-lib.c
index f3aa7f93c78..cad18099aba 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "read-cache.h"
@@ -14,6 +15,7 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "refs.h"
+#include "repository.h"
 #include "submodule.h"
 #include "symlinks.h"
 #include "trace.h"
diff --git a/diff.h b/diff.h
index 29a9cd217c2..c2e0e63609f 100644
--- a/diff.h
+++ b/diff.h
@@ -4,10 +4,12 @@
 #ifndef DIFF_H
 #define DIFF_H
 
+#include "hash-ll.h"
 #include "pathspec.h"
-#include "oidset.h"
 #include "strbuf.h"
 
+struct oidset;
+
 /**
  * The diff API is for programs that compare two sets of files (e.g. two trees,
  * one tree and the index) and present the found difference in various ways.
diff --git a/diffcore-break.c b/diffcore-break.c
index 4909dc088e6..f57ece2757d 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "hash.h"
 #include "object.h"
 #include "promisor-remote.h"
 
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 13c98a7b5e7..b195fa4eb3c 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -7,6 +7,7 @@
 #include "diffcore.h"
 #include "xdiff-interface.h"
 #include "kwset.h"
+#include "oidset.h"
 #include "pretty.h"
 #include "quote.h"
 
diff --git a/line-log.c b/line-log.c
index 6a7ac312a43..2eff914bf36 100644
--- a/line-log.c
+++ b/line-log.c
@@ -8,6 +8,7 @@
 #include "diff.h"
 #include "commit.h"
 #include "decorate.h"
+#include "repository.h"
 #include "revision.h"
 #include "xdiff-interface.h"
 #include "strbuf.h"
diff --git a/merge.c b/merge.c
index 83bcba6943e..b60925459c2 100644
--- a/merge.c
+++ b/merge.c
@@ -2,10 +2,12 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge.h"
 #include "commit.h"
+#include "repository.h"
 #include "run-command.h"
 #include "resolve-undo.h"
 #include "tree.h"
diff --git a/patch-ids.c b/patch-ids.c
index 19af7bee984..c3e1a0dd216 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "commit.h"
+#include "hash.h"
 #include "hash-lookup.h"
 #include "hex.h"
 #include "patch-ids.h"
diff --git a/pretty.c b/pretty.c
index 0bb938021ba..2cf2cbbd038 100644
--- a/pretty.c
+++ b/pretty.c
@@ -4,6 +4,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/range-diff.c b/range-diff.c
index 6a704e6f471..2e86063491e 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "pager.h"
 #include "pretty.h"
+#include "repository.h"
 #include "userdiff.h"
 #include "apply.h"
 #include "revision.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 4ba1a10c82c..d337e64431f 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
+#include "repository.h"
 #include "revision.h"
 #include "string-list.h"
 #include "reflog-walk.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 62c5b5d704b..cac20a72b3f 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -16,6 +16,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index 0c62b9de185..f346951bc28 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -11,6 +11,7 @@
 #include "test-tool.h"
 #include "commit.h"
 #include "diff.h"
+#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 
diff --git a/transport-helper.c b/transport-helper.c
index 6b816940dc6..5c0bc6a896e 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -8,6 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "repository.h"
 #include "revision.h"
 #include "remote.h"
 #include "string-list.h"
diff --git a/tree-diff.c b/tree-diff.c
index 20bb15f38d9..966946848ae 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "hash.h"
 #include "tree.h"
 #include "tree-walk.h"
 
diff --git a/wt-status.c b/wt-status.c
index 7ada6b305f6..bcd0ef80441 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "path.h"
-- 
gitgitgadget


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

* [PATCH 20/24] list-objects-filter-options.h: remove unneccessary include
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (18 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 19/24] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 21/24] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 list-objects-filter-options.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index f6206125868..55fab8563d2 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -3,7 +3,6 @@
 
 #include "gettext.h"
 #include "object.h"
-#include "string-list.h"
 #include "strbuf.h"
 
 struct option;
-- 
gitgitgadget


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

* [PATCH 21/24] builtin.h: remove unneccessary includes
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (19 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 20/24] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 22/24] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
                   ` (6 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that a few .c files under builtin/ were
depending upon some headers but had forgotten to #include them.  Add the
missing direct includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin.h                  | 2 --
 builtin/check-mailmap.c    | 1 +
 builtin/commit-graph.c     | 1 +
 builtin/config.c           | 1 +
 builtin/credential-cache.c | 1 +
 builtin/for-each-ref.c     | 1 +
 builtin/init-db.c          | 1 +
 builtin/verify-pack.c      | 1 +
 8 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/builtin.h b/builtin.h
index 3e6c22eef69..d560baa6618 100644
--- a/builtin.h
+++ b/builtin.h
@@ -2,8 +2,6 @@
 #define BUILTIN_H
 
 #include "git-compat-util.h"
-#include "strbuf.h"
-#include "commit.h"
 
 /*
  * builtin API
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index 002d2941e93..b8a05b8e07b 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -4,6 +4,7 @@
 #include "ident.h"
 #include "mailmap.h"
 #include "parse-options.h"
+#include "strbuf.h"
 #include "string-list.h"
 #include "write-or-die.h"
 
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a3d00fa232b..96a8a677327 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "commit.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/builtin/config.c b/builtin/config.c
index ff2fe8ef125..30f6d9fe67b 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -12,6 +12,7 @@
 #include "path.h"
 #include "quote.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 0ffacfdd83c..ff3a47badbe 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -2,6 +2,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
+#include "strbuf.h"
 #include "wrapper.h"
 #include "write-or-die.h"
 
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index d0d6ab0fd34..15409337f83 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -5,6 +5,7 @@
 #include "object.h"
 #include "parse-options.h"
 #include "ref-filter.h"
+#include "strbuf.h"
 #include "strvec.h"
 #include "commit-reach.h"
 
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 680ef7e1837..0d8bd4d7219 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "parse-options.h"
 #include "path.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "wrapper.h"
 
 static int guess_repository_type(const char *git_dir)
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index aba92cf8af7..011dddd2dc3 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "strbuf.h"
 
 #define VERIFY_PACK_VERBOSE 01
 #define VERIFY_PACK_STAT_ONLY 02
-- 
gitgitgadget


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

* [PATCH 22/24] git-compat-util.h: remove unneccessary include of wildmatch.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (20 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 21/24] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-07  3:45 ` [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The include of wildmatch.h in git-compat-util.h was added in cebcab189aa
(Makefile: add USE_WILDMATCH to use wildmatch as fnmatch, 2013-01-01) as
a way to be able to compile-time force any calls to fnmatch() to instead
invoke wildmatch().  The defines and inline function were removed in
70a8fc999d9 (stop using fnmatch (either native or compat), 2014-02-15),
and this include in git-compat-util.h has been unnecessary ever since.

Remove the include from git-compat-util.h, but add it to the .c files
that had omitted the direct #include they needed.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                   | 1 +
 builtin/describe.c        | 1 +
 builtin/ls-remote.c       | 1 +
 builtin/name-rev.c        | 1 +
 builtin/reflog.c          | 1 +
 builtin/replace.c         | 1 +
 builtin/show-branch.c     | 1 +
 config.c                  | 1 +
 diffcore-order.c          | 1 +
 fmt-merge-msg.c           | 1 +
 git-compat-util.h         | 2 --
 log-tree.c                | 1 +
 pathspec.c                | 1 +
 refs.c                    | 1 +
 revision.c                | 1 +
 t/helper/test-wildmatch.c | 1 +
 trace2/tr2_cfg.c          | 1 +
 17 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index be58dc08d22..801f2bcc99c 100644
--- a/apply.c
+++ b/apply.c
@@ -35,6 +35,7 @@
 #include "entry.h"
 #include "setup.h"
 #include "symlinks.h"
+#include "wildmatch.h"
 #include "ws.h"
 #include "wrapper.h"
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 508e8df00ef..eb19ab0bbbe 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -22,6 +22,7 @@
 #include "object-store.h"
 #include "list-objects.h"
 #include "commit-slab.h"
+#include "wildmatch.h"
 
 #define MAX_TAGS	(FLAG_BITS - 1)
 
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index a0aadc9b8ff..fc765754305 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -7,6 +7,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "wildmatch.h"
 
 static const char * const ls_remote_usage[] = {
 	N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 593f0506a10..de9808e21c8 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -15,6 +15,7 @@
 #include "hash-lookup.h"
 #include "commit-slab.h"
 #include "commit-graph.h"
+#include "wildmatch.h"
 
 /*
  * One day.  See the 'name a rev shortly after epoch' test in t6120 when
diff --git a/builtin/reflog.c b/builtin/reflog.c
index fc217748808..79b4ff04aae 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -4,6 +4,7 @@
 #include "repository.h"
 #include "revision.h"
 #include "reachable.h"
+#include "wildmatch.h"
 #include "worktree.h"
 #include "reflog.h"
 #include "parse-options.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 6b266a66d30..a2f57a56b3e 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -24,6 +24,7 @@
 #include "replace-object.h"
 #include "repository.h"
 #include "tag.h"
+#include "wildmatch.h"
 
 static const char * const git_replace_usage[] = {
 	N_("git replace [-f] <object> <replacement>"),
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index cd215f89af8..a203f13cb0d 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "commit-slab.h"
 #include "date.h"
+#include "wildmatch.h"
 
 static const char* show_branch_usage[] = {
     N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
diff --git a/config.c b/config.c
index 666ec73bab1..0b2a9f1bd89 100644
--- a/config.c
+++ b/config.c
@@ -36,6 +36,7 @@
 #include "setup.h"
 #include "strvec.h"
 #include "trace2.h"
+#include "wildmatch.h"
 #include "worktree.h"
 #include "ws.h"
 #include "wrapper.h"
diff --git a/diffcore-order.c b/diffcore-order.c
index 57ccab28464..e7d20ebd2d1 100644
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "wildmatch.h"
 
 static char **order;
 static int order_cnt;
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 5af0d4715ba..f096b1ef549 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -15,6 +15,7 @@
 #include "fmt-merge-msg.h"
 #include "commit-reach.h"
 #include "gpg-interface.h"
+#include "wildmatch.h"
 
 static int use_branch_desc;
 static int suppress_dest_pattern_seen;
diff --git a/git-compat-util.h b/git-compat-util.h
index 5b2b99c17c5..1889da7986e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -625,8 +625,6 @@ static inline int git_has_dir_sep(const char *path)
 
 #include "compat/bswap.h"
 
-#include "wildmatch.h"
-
 struct strbuf;
 
 /* General helper functions */
diff --git a/log-tree.c b/log-tree.c
index 07d0b47b168..60b61597c42 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -26,6 +26,7 @@
 #include "range-diff.h"
 #include "strmap.h"
 #include "tree.h"
+#include "wildmatch.h"
 #include "write-or-die.h"
 
 static struct decoration name_decoration = { "object names" };
diff --git a/pathspec.c b/pathspec.c
index 0baa85384f8..ad9b9e7dc74 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -12,6 +12,7 @@
 #include "strvec.h"
 #include "symlinks.h"
 #include "quote.h"
+#include "wildmatch.h"
 
 /*
  * Finds which of the given pathspecs match items in the index.
diff --git a/refs.c b/refs.c
index 3c0c95ac442..5f76da35673 100644
--- a/refs.c
+++ b/refs.c
@@ -29,6 +29,7 @@
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
+#include "wildmatch.h"
 #include "wrapper.h"
 
 /*
diff --git a/revision.c b/revision.c
index 66a1fece0df..d4b4b34fd80 100644
--- a/revision.c
+++ b/revision.c
@@ -46,6 +46,7 @@
 #include "list-objects-filter-options.h"
 #include "resolve-undo.h"
 #include "parse-options.h"
+#include "wildmatch.h"
 
 volatile show_early_output_fn_t show_early_output;
 
diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c
index a95bb4da9b1..b4ff5f986ae 100644
--- a/t/helper/test-wildmatch.c
+++ b/t/helper/test-wildmatch.c
@@ -1,4 +1,5 @@
 #include "test-tool.h"
+#include "wildmatch.h"
 
 int cmd__wildmatch(int argc, const char **argv)
 {
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index 78cfc15d52d..db817a80c53 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -4,6 +4,7 @@
 #include "trace2.h"
 #include "trace2/tr2_cfg.h"
 #include "trace2/tr2_sysenv.h"
+#include "wildmatch.h"
 
 static struct strbuf **tr2_cfg_patterns;
 static int tr2_cfg_count_patterns;
-- 
gitgitgadget


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

* [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (21 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 22/24] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-11 17:24   ` Calvin Wan
  2023-05-07  3:45 ` [PATCH 24/24] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
                   ` (4 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

oidhash() was used by both hashmap and khash, which makes sense.
However, the location of this function in hashmap.[ch] meant that
khash.h had to depend upon hashmap.h, making people unfamiliar with
khash think that it was built upon hashmap.  (Or at least, I personally
was confused for a while about this in the past.)

Move this function to hash-ll, so that khash.h can stop depending upon
hashmap.h.

This has another benefit as well: it allows us to remove hashmap.h's
dependency on hash-ll.h.  While some callers of hashmap.h were making
use of oidhash, most were not, so this change provides another way to
reduce the number of includes.

Diff best viewed with `--color-moved`.  Note that there's a small but
important change to khash.h in this patch as well to allow this move,
which is easy to overlook.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                       |   2 +-
 archive-tar.c                 |   2 +-
 archive-zip.c                 |   2 +-
 archive.c                     |   2 +-
 attr.c                        |   2 +-
 bisect.c                      |   2 +-
 blame.c                       |   2 +-
 builtin/blame.c               |   2 +-
 builtin/cat-file.c            |   2 +-
 builtin/checkout.c            |   2 +-
 builtin/clone.c               |   2 +-
 builtin/commit-graph.c        |   2 +-
 builtin/commit-tree.c         |   2 +-
 builtin/count-objects.c       |   2 +-
 builtin/describe.c            |   2 +-
 builtin/difftool.c            |   2 +-
 builtin/fast-export.c         |   2 +-
 builtin/fast-import.c         |   2 +-
 builtin/fetch.c               |   2 +-
 builtin/fsck.c                |   2 +-
 builtin/gc.c                  |   2 +-
 builtin/grep.c                |   2 +-
 builtin/hash-object.c         |   3 +-
 builtin/index-pack.c          |   3 +-
 builtin/log.c                 |   2 +-
 builtin/ls-tree.c             |   2 +-
 builtin/merge-tree.c          |   2 +-
 builtin/mktag.c               |   3 +-
 builtin/mktree.c              |   3 +-
 builtin/multi-pack-index.c    |   3 +-
 builtin/notes.c               |   2 +-
 builtin/pack-objects.c        |   2 +-
 builtin/pack-redundant.c      |   2 +-
 builtin/prune.c               |   3 +-
 builtin/receive-pack.c        |   2 +-
 builtin/remote.c              |   2 +-
 builtin/repack.c              |   2 +-
 builtin/replace.c             |   2 +-
 builtin/rev-list.c            |   2 +-
 builtin/show-ref.c            |   2 +-
 builtin/submodule--helper.c   |   2 +-
 builtin/tag.c                 |   2 +-
 builtin/unpack-file.c         |   2 +-
 builtin/unpack-objects.c      |   2 +-
 builtin/verify-commit.c       |   2 +-
 bulk-checkin.c                |   2 +-
 bundle-uri.c                  |   2 +-
 bundle.c                      |   2 +-
 cache-tree.c                  |   2 +-
 combine-diff.c                |   2 +-
 commit-graph.c                |   2 +-
 commit-graph.h                |   2 +-
 commit.c                      |   2 +-
 config.c                      |   2 +-
 connected.c                   |   2 +-
 convert.c                     |   2 +-
 decorate.c                    |   1 -
 diagnose.c                    |   2 +-
 diff.c                        |   2 +-
 diffcore-rename.c             |   2 +-
 dir.c                         |   2 +-
 dir.h                         |   1 +
 entry.c                       |   2 +-
 environment.c                 |   2 +-
 fetch-pack.c                  |   2 +-
 fmt-merge-msg.c               |   2 +-
 fsck.c                        |   3 +-
 grep.c                        |   2 +-
 hash-ll.h                     |  19 ++
 hashmap.h                     |  21 --
 http-backend.c                |   2 +-
 http-push.c                   |   2 +-
 http-walker.c                 |   2 +-
 http.c                        |   2 +-
 khash.h                       |   3 +-
 list-objects-filter.c         |   2 +-
 list-objects.c                |   2 +-
 log-tree.c                    |   2 +-
 mailmap.c                     |   2 +-
 match-trees.c                 |   3 +-
 merge-blobs.c                 |   2 +-
 merge-ort.c                   |   2 +-
 merge-recursive.c             |   2 +-
 midx.c                        |   2 +-
 notes-cache.c                 |   3 +-
 notes-merge.c                 |   2 +-
 notes.c                       |   2 +-
 object-name.c                 |   2 +-
 object-store-ll.h             | 533 ++++++++++++++++++++++++++++++++++
 object-store.h                | 528 +--------------------------------
 oss-fuzz/fuzz-pack-idx.c      |   2 +-
 pack-bitmap-write.c           |   2 +-
 pack-bitmap.c                 |   2 +-
 pack-check.c                  |   2 +-
 pack-mtimes.c                 |   3 +-
 pack-objects.h                |   2 +-
 pack-revindex.c               |   3 +-
 pack-write.c                  |   1 +
 packfile.c                    |   2 +-
 path.c                        |   2 +-
 promisor-remote.c             |   2 +-
 protocol-caps.c               |   2 +-
 prune-packed.c                |   2 +-
 reachable.c                   |   2 +-
 read-cache.c                  |   2 +-
 ref-filter.c                  |   2 +-
 reflog.c                      |   2 +-
 refs.c                        |   2 +-
 remote.c                      |   2 +-
 remote.h                      |   1 +
 replace-object.c              |   2 +-
 replace-object.h              |   2 +-
 repository.c                  |   2 +-
 rerere.c                      |   2 +-
 revision.c                    |   2 +-
 send-pack.c                   |   2 +-
 sequencer.c                   |   2 +-
 serve.c                       |   1 +
 server-info.c                 |   2 +-
 shallow.c                     |   2 +-
 streaming.c                   |   2 +-
 submodule-config.c            |   2 +-
 submodule.c                   |   2 +-
 t/helper/test-pack-mtimes.c   |   2 +-
 t/helper/test-partial-clone.c |   2 +-
 t/helper/test-read-graph.c    |   2 +-
 t/helper/test-read-midx.c     |   2 +-
 t/helper/test-ref-store.c     |   3 +-
 t/helper/test-repository.c    |   2 +-
 tag.c                         |   2 +-
 tmp-objdir.c                  |   2 +-
 transport.c                   |   2 +-
 tree-walk.c                   |   2 +-
 tree.c                        |   2 +-
 unpack-trees.c                |   2 +-
 upload-pack.c                 |   2 +-
 walker.c                      |   3 +-
 xdiff-interface.c             |   3 +-
 138 files changed, 700 insertions(+), 679 deletions(-)
 create mode 100644 object-store-ll.h

diff --git a/apply.c b/apply.c
index 801f2bcc99c..64ab262f1bf 100644
--- a/apply.c
+++ b/apply.c
@@ -12,7 +12,7 @@
 #include "alloc.h"
 #include "base85.h"
 #include "config.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index 4cd81d8161e..fc06ff4c5d6 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -9,7 +9,7 @@
 #include "hex.h"
 #include "tar.h"
 #include "archive.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "streaming.h"
 #include "run-command.h"
 #include "write-or-die.h"
diff --git a/archive-zip.c b/archive-zip.c
index d0d065a312e..b4382640966 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -9,7 +9,7 @@
 #include "hex.h"
 #include "streaming.h"
 #include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "userdiff.h"
 #include "write-or-die.h"
 #include "xdiff-interface.h"
diff --git a/archive.c b/archive.c
index 802a34d6b91..0e5065fd505 100644
--- a/archive.c
+++ b/archive.c
@@ -10,7 +10,7 @@
 #include "pretty.h"
 #include "setup.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 435b51e11ff..f178190c5de 100644
--- a/attr.c
+++ b/attr.c
@@ -19,7 +19,7 @@
 #include "quote.h"
 #include "read-cache-ll.h"
 #include "revision.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index 9f7cf0be073..1be8e0a2711 100644
--- a/bisect.c
+++ b/bisect.c
@@ -18,7 +18,7 @@
 #include "commit-slab.h"
 #include "commit-reach.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "dir.h"
 
diff --git a/blame.c b/blame.c
index b74ee70decf..1d25cd29fce 100644
--- a/blame.c
+++ b/blame.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "cache-tree.h"
 #include "mergesort.h"
 #include "convert.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 2df6039a6e0..e811e7fbfb1 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -29,7 +29,7 @@
 #include "dir.h"
 #include "progress.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "blame.h"
 #include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9646e7209ca..48ccca95a1a 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -21,7 +21,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 716dcd4cae1..2fce1eb8532 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -18,7 +18,7 @@
 #include "mem-pool.h"
 #include "merge-recursive.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "path.h"
 #include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 6c5cb33f6a9..687a686269a 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -23,7 +23,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 96a8a677327..48fa9f20c97 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -9,7 +9,7 @@
 #include "parse-options.h"
 #include "repository.h"
 #include "commit-graph.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "progress.h"
 #include "replace-object.h"
 #include "tag.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d2121f30d45..02625e71761 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -8,7 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "commit.h"
 #include "tree.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index c9f82d0bce9..97cdfb0ac57 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -14,7 +14,7 @@
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static unsigned long garbage;
 static off_t size_garbage;
diff --git a/builtin/describe.c b/builtin/describe.c
index eb19ab0bbbe..7ce23e1b8e6 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
 #include "setup.h"
 #include "strvec.h"
 #include "run-command.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "list-objects.h"
 #include "commit-slab.h"
 #include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 4a22de3eddb..e2c9ab7d5d7 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -28,7 +28,7 @@
 #include "strbuf.h"
 #include "lockfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "dir.h"
 #include "entry.h"
 #include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 5f3ffd6912f..56dc69fac18 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "object.h"
 #include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 5698b92ae7d..2ee19c73733 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -21,7 +21,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "mem-pool.h"
 #include "commit-reach.h"
 #include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4dbacd8f188..86d409a6de3 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -11,7 +11,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oidset.h"
 #include "oid-array.h"
 #include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index d707ca32a61..a04c15e5e81 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -20,7 +20,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 9ecc2513e9f..7484946c506 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -27,7 +27,7 @@
 #include "commit-graph.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack.h"
 #include "pack-objects.h"
 #include "path.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 6bc8abcd3e1..72e70b3a48d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -27,7 +27,7 @@
 #include "submodule-config.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "pager.h"
 #include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index a3801211666..5ffec99dcea 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -10,12 +10,13 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "write-or-die.h"
 
 /*
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb67e166559..820860265d0 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -14,12 +14,13 @@
 #include "progress.h"
 #include "fsck.h"
 #include "exec-cmd.h"
+#include "strbuf.h"
 #include "streaming.h"
 #include "thread-utils.h"
 #include "packfile.h"
 #include "pack-revindex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
diff --git a/builtin/log.c b/builtin/log.c
index 676de107d61..d6543ba1f63 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -14,7 +14,7 @@
 #include "refs.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "color.h"
 #include "commit.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index c06858de4bf..4e17f13648e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -8,7 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index aa8040c2a6a..23d7e98db0d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -9,7 +9,7 @@
 #include "commit-reach.h"
 #include "merge-ort.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "blob.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 44fa56eff38..43e2766db49 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -2,10 +2,11 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "strbuf.h"
 #include "tag.h"
 #include "replace-object.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "fsck.h"
 #include "config.h"
 
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 09a7bd5c5c2..0eea810c7ea 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -8,9 +8,10 @@
 #include "gettext.h"
 #include "hex.h"
 #include "quote.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "parse-options.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static struct treeent {
 	unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 5bb71bce08d..a31dde1db9e 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -5,8 +5,9 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
+#include "strbuf.h"
 #include "trace2.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 #define BUILTIN_MIDX_WRITE_USAGE \
 	N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
diff --git a/builtin/notes.c b/builtin/notes.c
index 0a870d90836..0a19796f734 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -14,7 +14,7 @@
 #include "hex.h"
 #include "notes.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a5b466839ba..aa595f6a4a4 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -34,7 +34,7 @@
 #include "list.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "dir.h"
 #include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 43e9d12dfdc..4c735ba069c 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -11,7 +11,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 #define BLKSIZE 512
 
diff --git a/builtin/prune.c b/builtin/prune.c
index a46c5aa2b5b..cfb863ae848 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
+#include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
@@ -13,7 +14,7 @@
 #include "replace-object.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "shallow.h"
 
 static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index d1718a3ac90..91caaf87066 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -30,7 +30,7 @@
 #include "oidset.h"
 #include "packfile.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "protocol.h"
 #include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 3794f13330d..7d96687ec74 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -11,7 +11,7 @@
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "strvec.h"
 #include "commit-reach.h"
 #include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index fe8d5810d48..6c896c9c805 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -16,7 +16,7 @@
 #include "midx.h"
 #include "packfile.h"
 #include "prune-packed.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "shallow.h"
 #include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index a2f57a56b3e..20c67a58890 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -20,7 +20,7 @@
 #include "run-command.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "repository.h"
 #include "tag.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 8029f3de53c..ff715d6918f 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -12,7 +12,7 @@
 #include "object.h"
 #include "object-name.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack.h"
 #include "pack-bitmap.h"
 #include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index e07e9ca862f..5110814f796 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "tag.h"
 #include "string-list.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6acba4ebb30..baf6ff88c3c 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -29,7 +29,7 @@
 #include "diff.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "advice.h"
 #include "branch.h"
 #include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 87963d2cc0e..076f832802c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -15,7 +15,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "tag.h"
 #include "run-command.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b35a4b9dfee..6842a6c4996 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -2,7 +2,7 @@
 #include "config.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "wrapper.h"
 
 static char *create_temp_file(struct object_id *oid)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 85baf6a131a..b4b46ae7291 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "git-zlib.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index aa34fb896ac..9680b587013 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -9,7 +9,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "commit.h"
 #include "run-command.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index d843279715c..e2f71db0f60 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -16,7 +16,7 @@
 #include "tmp-objdir.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "wrapper.h"
 
 static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 1b62902f014..a70c8887fd1 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -4,7 +4,7 @@
 #include "copy.h"
 #include "environment.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "refs.h"
 #include "run-command.h"
 #include "hashmap.h"
diff --git a/bundle.c b/bundle.c
index a5505368de5..8d5936c4212 100644
--- a/bundle.c
+++ b/bundle.c
@@ -4,7 +4,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "object.h"
 #include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index 077932c2db5..84d7491420e 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -8,7 +8,7 @@
 #include "cache-tree.h"
 #include "bulk-checkin.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
diff --git a/combine-diff.c b/combine-diff.c
index 1e3cd7fb170..11e9d7494a1 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "convert.h"
 #include "blob.h"
diff --git a/commit-graph.c b/commit-graph.c
index 25cbd66c33a..9e989f43491 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -12,7 +12,7 @@
 #include "hash-lookup.h"
 #include "commit-graph.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "path.h"
 #include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 83aaa1dbb92..5e534f0fcc8 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
 #ifndef COMMIT_GRAPH_H
 #define COMMIT_GRAPH_H
 
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oidset.h"
 
 #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index 10676165a1d..8dfc298d6e6 100644
--- a/commit.c
+++ b/commit.c
@@ -7,7 +7,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pkt-line.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/config.c b/config.c
index 0b2a9f1bd89..e08e2332a68 100644
--- a/config.c
+++ b/config.c
@@ -25,7 +25,7 @@
 #include "hashmap.h"
 #include "string-list.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "path.h"
 #include "utf8.h"
diff --git a/connected.c b/connected.c
index d672521da41..8f89376dbcf 100644
--- a/connected.c
+++ b/connected.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "connected.h"
diff --git a/convert.c b/convert.c
index 9e89f660308..1daacbc4b2b 100644
--- a/convert.c
+++ b/convert.c
@@ -5,7 +5,7 @@
 #include "copy.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff --git a/decorate.c b/decorate.c
index 71e79daa825..a5c43c0c146 100644
--- a/decorate.c
+++ b/decorate.c
@@ -3,7 +3,6 @@
  * data.
  */
 #include "git-compat-util.h"
-#include "hashmap.h"
 #include "object.h"
 #include "decorate.h"
 
diff --git a/diagnose.c b/diagnose.c
index c8c7ebcfa39..8430064000b 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "parse-options.h"
 #include "write-or-die.h"
diff --git a/diff.c b/diff.c
index 5e81dc0d02d..c666e1fc0c8 100644
--- a/diff.c
+++ b/diff.c
@@ -20,7 +20,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "userdiff.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 8e2e7a3ad73..926b554bd59 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -6,7 +6,7 @@
 #include "alloc.h"
 #include "diff.h"
 #include "diffcore.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hashmap.h"
 #include "mem-pool.h"
 #include "oid-array.h"
diff --git a/dir.c b/dir.c
index 3cf3d428c7b..fada2713b9e 100644
--- a/dir.c
+++ b/dir.c
@@ -15,7 +15,7 @@
 #include "gettext.h"
 #include "name-hash.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "attr.h"
 #include "refs.h"
diff --git a/dir.h b/dir.h
index 79b85a01ee4..279a0660801 100644
--- a/dir.h
+++ b/dir.h
@@ -1,6 +1,7 @@
 #ifndef DIR_H
 #define DIR_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 #include "pathspec.h"
 #include "statinfo.h"
diff --git a/entry.c b/entry.c
index 041f5cf212d..f9a7c726a4d 100644
--- a/entry.c
+++ b/entry.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "blob.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/environment.c b/environment.c
index 56e8742ea66..5e9b331279f 100644
--- a/environment.c
+++ b/environment.c
@@ -20,7 +20,7 @@
 #include "commit.h"
 #include "strvec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "replace-object.h"
 #include "tmp-objdir.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 207548b3e5a..a432eacab99 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
 #include "oid-array.h"
 #include "oidset.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index f096b1ef549..4da6c7a8bda 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -4,7 +4,7 @@
 #include "environment.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "hex.h"
diff --git a/fsck.c b/fsck.c
index 04e729953b2..a219d6f2c0a 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,8 +1,9 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "date.h"
+#include "dir.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "object.h"
diff --git a/grep.c b/grep.c
index f00986c451a..ebcd6474788 100644
--- a/grep.c
+++ b/grep.c
@@ -3,7 +3,7 @@
 #include "gettext.h"
 #include "grep.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pretty.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/hash-ll.h b/hash-ll.h
index 80509251370..8d7973769fd 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -270,6 +270,25 @@ static inline void oid_set_algo(struct object_id *oid, const struct git_hash_alg
 	oid->algo = hash_algo_by_ptr(algop);
 }
 
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+	/*
+	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+	 * platforms that don't support unaligned reads.
+	 */
+	unsigned int hash;
+	memcpy(&hash, oid->hash, sizeof(hash));
+	return hash;
+}
+
 const char *empty_tree_oid_hex(void);
 const char *empty_blob_oid_hex(void);
 
diff --git a/hashmap.h b/hashmap.h
index 2695f3d3a6e..c8216e47bb2 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -1,8 +1,6 @@
 #ifndef HASHMAP_H
 #define HASHMAP_H
 
-#include "hash-ll.h"
-
 /*
  * Generic implementation of hash-based key-value mappings.
  *
@@ -120,25 +118,6 @@ unsigned int memhash(const void *buf, size_t len);
 unsigned int memihash(const void *buf, size_t len);
 unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
 
-/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
-	/*
-	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
-	 * platforms that don't support unaligned reads.
-	 */
-	unsigned int hash;
-	memcpy(&hash, oid->hash, sizeof(hash));
-	return hash;
-}
-
 /*
  * struct hashmap_entry is an opaque structure representing an entry in the
  * hash table.
diff --git a/http-backend.c b/http-backend.c
index ddb9549ecbc..e1969c05dc6 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -16,7 +16,7 @@
 #include "url.h"
 #include "strvec.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "protocol.h"
 #include "date.h"
 #include "wrapper.h"
diff --git a/http-push.c b/http-push.c
index 29cf9db34e3..9ab2383d2b4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -18,7 +18,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit-reach.h"
 
 #ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index bba306b2d5e..78d99f7c4b0 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -7,7 +7,7 @@
 #include "list.h"
 #include "transport.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct alt_base {
 	char *base;
diff --git a/http.c b/http.c
index bb58bb3e6a3..25e4c8a1ae9 100644
--- a/http.c
+++ b/http.c
@@ -18,7 +18,7 @@
 #include "protocol.h"
 #include "string-list.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
 static int trace_curl_data = 1;
diff --git a/khash.h b/khash.h
index 56241e6a5c9..ff881631778 100644
--- a/khash.h
+++ b/khash.h
@@ -26,7 +26,6 @@
 #ifndef __AC_KHASH_H
 #define __AC_KHASH_H
 
-#include "hashmap.h"
 #include "hash.h"
 
 #define AC_VERSION_KHASH_H "0.2.8"
@@ -62,7 +61,7 @@ static inline khint_t __ac_X31_hash_string(const char *s)
 static const double __ac_HASH_UPPER = 0.77;
 
 #define __KHASH_TYPE(name, khkey_t, khval_t) \
-	typedef struct { \
+	typedef struct kh_##name { \
 		khint_t n_buckets, size, n_occupied, upper_bound; \
 		khint32_t *flags; \
 		khkey_t *keys; \
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 5d270ce5987..e075a66c99d 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -16,7 +16,7 @@
 #include "oidmap.h"
 #include "oidset.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 /* Remember to update object flag allocation in object.h */
 /*
diff --git a/list-objects.c b/list-objects.c
index eecca721ac0..672a4cd5298 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -12,7 +12,7 @@
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "trace.h"
 
 struct traversal_context {
diff --git a/log-tree.c b/log-tree.c
index 60b61597c42..f807e286c88 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -5,7 +5,7 @@
 #include "environment.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "tmp-objdir.h"
 #include "commit.h"
diff --git a/mailmap.c b/mailmap.c
index 5dc5223c430..3d6a5e9400f 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -3,7 +3,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 
 const char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 6bc8eb76477..0885ac681cd 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,9 +1,10 @@
 #include "git-compat-util.h"
 #include "hex.h"
 #include "match-trees.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "tree-walk.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static int score_missing(unsigned mode)
 {
diff --git a/merge-blobs.c b/merge-blobs.c
index 5632ff6abb6..902e422d2f2 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
 #include "ll-merge.h"
 #include "blob.h"
 #include "merge-blobs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
diff --git a/merge-ort.c b/merge-ort.c
index eed71b04389..e68645bb961 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -34,7 +34,7 @@
 #include "match-trees.h"
 #include "mem-pool.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "path.h"
 #include "promisor-remote.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 527dbbd010a..69b0e36a9c6 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -26,7 +26,7 @@
 #include "name-hash.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "revision.h"
diff --git a/midx.c b/midx.c
index b500174d1f3..db459e448b7 100644
--- a/midx.c
+++ b/midx.c
@@ -9,7 +9,7 @@
 #include "lockfile.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hash-lookup.h"
 #include "midx.h"
 #include "progress.h"
diff --git a/notes-cache.c b/notes-cache.c
index 14288caf98f..0e1d5b1ac7a 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,10 +1,11 @@
 #include "git-compat-util.h"
 #include "notes-cache.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pretty.h"
 #include "repository.h"
 #include "commit.h"
 #include "refs.h"
+#include "strbuf.h"
 
 static int notes_cache_match_validity(struct repository *r,
 				      const char *ref,
diff --git a/notes-merge.c b/notes-merge.c
index 4b328d852cd..db82605309a 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -5,7 +5,7 @@
 #include "refs.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "diff.h"
diff --git a/notes.c b/notes.c
index 02f1aa39ae1..4d2836a7c76 100644
--- a/notes.c
+++ b/notes.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "notes.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "tree.h"
 #include "utf8.h"
diff --git a/object-name.c b/object-name.c
index 45f4d51305b..7e96c97051e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -17,7 +17,7 @@
 #include "oidtree.h"
 #include "packfile.h"
 #include "pretty.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/object-store-ll.h b/object-store-ll.h
new file mode 100644
index 00000000000..e8f22cdb1b5
--- /dev/null
+++ b/object-store-ll.h
@@ -0,0 +1,533 @@
+#ifndef OBJECT_STORE_LL_H
+#define OBJECT_STORE_LL_H
+
+#include "hashmap.h"
+#include "object.h"
+#include "list.h"
+#include "thread-utils.h"
+#include "oidset.h"
+
+struct oidmap;
+struct oidtree;
+struct strbuf;
+
+struct object_directory {
+	struct object_directory *next;
+
+	/*
+	 * Used to store the results of readdir(3) calls when we are OK
+	 * sacrificing accuracy due to races for speed. That includes
+	 * object existence with OBJECT_INFO_QUICK, as well as
+	 * our search for unique abbreviated hashes. Don't use it for tasks
+	 * requiring greater accuracy!
+	 *
+	 * Be sure to call odb_load_loose_cache() before using.
+	 */
+	uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
+	struct oidtree *loose_objects_cache;
+
+	/*
+	 * This is a temporary object store created by the tmp_objdir
+	 * facility. Disable ref updates since the objects in the store
+	 * might be discarded on rollback.
+	 */
+	int disable_ref_updates;
+
+	/*
+	 * This object store is ephemeral, so there is no need to fsync.
+	 */
+	int will_destroy;
+
+	/*
+	 * Path to the alternative object store. If this is a relative path,
+	 * it is relative to the current working directory.
+	 */
+	char *path;
+};
+
+struct input_stream {
+	const void *(*read)(struct input_stream *, unsigned long *len);
+	void *data;
+	int is_finished;
+};
+
+void prepare_alt_odb(struct repository *r);
+int has_alt_odb(struct repository *r);
+char *compute_alternate_path(const char *path, struct strbuf *err);
+struct object_directory *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct object_directory *, void *);
+int foreach_alt_odb(alt_odb_fn, void*);
+typedef void alternate_ref_fn(const struct object_id *oid, void *);
+void for_each_alternate_ref(alternate_ref_fn, void *);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void add_to_alternates_file(const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternates (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void add_to_alternates_memory(const char *dir);
+
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary object directory.
+ */
+struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+
+/*
+ * Restore a previous ODB replaced by set_temporary_main_odb.
+ */
+void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+
+/*
+ * Populate and return the loose object cache array corresponding to the
+ * given object ID.
+ */
+struct oidtree *odb_loose_cache(struct object_directory *odb,
+				  const struct object_id *oid);
+
+/* Empty the loose object cache for the specified object directory. */
+void odb_clear_loose_cache(struct object_directory *odb);
+
+/* Clear and free the specified object directory */
+void free_object_directory(struct object_directory *odb);
+
+struct packed_git {
+	struct hashmap_entry packmap_ent;
+	struct packed_git *next;
+	struct list_head mru;
+	struct pack_window *windows;
+	off_t pack_size;
+	const void *index_data;
+	size_t index_size;
+	uint32_t num_objects;
+	uint32_t crc_offset;
+	struct oidset bad_objects;
+	int index_version;
+	time_t mtime;
+	int pack_fd;
+	int index;              /* for builtin/pack-objects.c */
+	unsigned pack_local:1,
+		 pack_keep:1,
+		 pack_keep_in_core:1,
+		 freshened:1,
+		 do_not_close:1,
+		 pack_promisor:1,
+		 multi_pack_index:1,
+		 is_cruft:1;
+	unsigned char hash[GIT_MAX_RAWSZ];
+	struct revindex_entry *revindex;
+	const uint32_t *revindex_data;
+	const uint32_t *revindex_map;
+	size_t revindex_size;
+	/*
+	 * mtimes_map points at the beginning of the memory mapped region of
+	 * this pack's corresponding .mtimes file, and mtimes_size is the size
+	 * of that .mtimes file
+	 */
+	const uint32_t *mtimes_map;
+	size_t mtimes_size;
+	/* something like ".git/objects/pack/xxxxx.pack" */
+	char pack_name[FLEX_ARRAY]; /* more */
+};
+
+struct multi_pack_index;
+
+static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
+				     const struct hashmap_entry *entry,
+				     const struct hashmap_entry *entry2,
+				     const void *keydata)
+{
+	const char *key = keydata;
+	const struct packed_git *pg1, *pg2;
+
+	pg1 = container_of(entry, const struct packed_git, packmap_ent);
+	pg2 = container_of(entry2, const struct packed_git, packmap_ent);
+
+	return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
+}
+
+struct raw_object_store {
+	/*
+	 * Set of all object directories; the main directory is first (and
+	 * cannot be NULL after initialization). Subsequent directories are
+	 * alternates.
+	 */
+	struct object_directory *odb;
+	struct object_directory **odb_tail;
+	struct kh_odb_path_map *odb_by_path;
+
+	int loaded_alternates;
+
+	/*
+	 * A list of alternate object directories loaded from the environment;
+	 * this should not generally need to be accessed directly, but will
+	 * populate the "odb" list when prepare_alt_odb() is run.
+	 */
+	char *alternate_db;
+
+	/*
+	 * Objects that should be substituted by other objects
+	 * (see git-replace(1)).
+	 */
+	struct oidmap *replace_map;
+	unsigned replace_map_initialized : 1;
+	pthread_mutex_t replace_mutex; /* protect object replace functions */
+
+	struct commit_graph *commit_graph;
+	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
+
+	/*
+	 * private data
+	 *
+	 * should only be accessed directly by packfile.c and midx.c
+	 */
+	struct multi_pack_index *multi_pack_index;
+
+	/*
+	 * private data
+	 *
+	 * should only be accessed directly by packfile.c
+	 */
+
+	struct packed_git *packed_git;
+	/* A most-recently-used ordered version of the packed_git list. */
+	struct list_head packed_git_mru;
+
+	struct {
+		struct packed_git **packs;
+		unsigned flags;
+	} kept_pack_cache;
+
+	/*
+	 * A map of packfiles to packed_git structs for tracking which
+	 * packs have been loaded already.
+	 */
+	struct hashmap pack_map;
+
+	/*
+	 * A fast, rough count of the number of objects in the repository.
+	 * These two fields are not meant for direct access. Use
+	 * repo_approximate_object_count() instead.
+	 */
+	unsigned long approximate_object_count;
+	unsigned approximate_object_count_valid : 1;
+
+	/*
+	 * Whether packed_git has already been populated with this repository's
+	 * packs.
+	 */
+	unsigned packed_git_initialized : 1;
+};
+
+struct raw_object_store *raw_object_store_new(void);
+void raw_object_store_clear(struct raw_object_store *o);
+
+/*
+ * Put in `buf` the name of the file in the local object database that
+ * would be used to store a loose object with the specified oid.
+ */
+const char *loose_object_path(struct repository *r, struct strbuf *buf,
+			      const struct object_id *oid);
+
+void *map_loose_object(struct repository *r, const struct object_id *oid,
+		       unsigned long *size);
+
+void *repo_read_object_file(struct repository *r,
+			    const struct object_id *oid,
+			    enum object_type *type,
+			    unsigned long *size);
+
+/* Read and unpack an object file into memory, write memory to an object file */
+int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
+
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+		      unsigned long len, enum object_type type,
+		      struct object_id *oid);
+
+int write_object_file_flags(const void *buf, unsigned long len,
+			    enum object_type type, struct object_id *oid,
+			    unsigned flags);
+static inline int write_object_file(const void *buf, unsigned long len,
+				    enum object_type type, struct object_id *oid)
+{
+	return write_object_file_flags(buf, len, type, oid, 0);
+}
+
+int write_object_file_literally(const void *buf, unsigned long len,
+				const char *type, struct object_id *oid,
+				unsigned flags);
+int stream_loose_object(struct input_stream *in_stream, size_t len,
+			struct object_id *oid);
+
+/*
+ * Add an object file to the in-memory object store, without writing it
+ * to disk.
+ *
+ * Callers are responsible for calling write_object_file to record the
+ * object in persistent storage before writing any other new objects
+ * that reference it.
+ */
+int pretend_object_file(void *, unsigned long, enum object_type,
+			struct object_id *oid);
+
+int force_object_loose(const struct object_id *oid, time_t mtime);
+
+struct object_info {
+	/* Request */
+	enum object_type *typep;
+	unsigned long *sizep;
+	off_t *disk_sizep;
+	struct object_id *delta_base_oid;
+	struct strbuf *type_name;
+	void **contentp;
+
+	/* Response */
+	enum {
+		OI_CACHED,
+		OI_LOOSE,
+		OI_PACKED,
+		OI_DBCACHED
+	} whence;
+	union {
+		/*
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } cached;
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } loose;
+		 */
+		struct {
+			struct packed_git *pack;
+			off_t offset;
+			unsigned int is_delta;
+		} packed;
+	} u;
+};
+
+/*
+ * Initializer for a "struct object_info" that wants no items. You may
+ * also memset() the memory to all-zeroes.
+ */
+#define OBJECT_INFO_INIT { 0 }
+
+/* Invoke lookup_replace_object() on the given hash */
+#define OBJECT_INFO_LOOKUP_REPLACE 1
+/* Allow reading from a loose object file of unknown/bogus type */
+#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
+/* Do not retry packed storage after checking packed and loose storage */
+#define OBJECT_INFO_QUICK 8
+/*
+ * Do not attempt to fetch the object if missing (even if fetch_is_missing is
+ * nonzero).
+ */
+#define OBJECT_INFO_SKIP_FETCH_OBJECT 16
+/*
+ * This is meant for bulk prefetching of missing blobs in a partial
+ * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
+ */
+#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
+
+/* Die if object corruption (not just an object being missing) was detected. */
+#define OBJECT_INFO_DIE_IF_CORRUPT 32
+
+int oid_object_info_extended(struct repository *r,
+			     const struct object_id *,
+			     struct object_info *, unsigned flags);
+
+/*
+ * Open the loose object at path, check its hash, and return the contents,
+ * use the "oi" argument to assert things about the object, or e.g. populate its
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+		      const struct object_id *expected_oid,
+		      struct object_id *real_oid,
+		      void **contents,
+		      struct object_info *oi);
+
+/* Retry packed storage after checking packed and loose storage */
+#define HAS_OBJECT_RECHECK_PACKED 1
+
+/*
+ * Returns 1 if the object exists. This function will not lazily fetch objects
+ * in a partial clone.
+ */
+int has_object(struct repository *r, const struct object_id *oid,
+	       unsigned flags);
+
+/*
+ * These macros and functions are deprecated. If checking existence for an
+ * object that is likely to be missing and/or whose absence is relatively
+ * inconsequential (or is consequential but the caller is prepared to handle
+ * it), use has_object(), which has better defaults (no lazy fetch in a partial
+ * clone and no rechecking of packed storage). In the unlikely event that a
+ * caller needs to assert existence of an object that it fully expects to
+ * exist, and wants to trigger a lazy fetch in a partial clone, use
+ * oid_object_info_extended() with a NULL struct object_info.
+ *
+ * These functions can be removed once all callers have migrated to
+ * has_object() and/or oid_object_info_extended().
+ */
+int repo_has_object_file(struct repository *r, const struct object_id *oid);
+int repo_has_object_file_with_flags(struct repository *r,
+				    const struct object_id *oid, int flags);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name.  This function does not respect replace
+ * references.
+ */
+int has_loose_object_nonlocal(const struct object_id *);
+
+int has_loose_object(const struct object_id *);
+
+/**
+ * format_object_header() is a thin wrapper around s xsnprintf() that
+ * writes the initial "<type> <obj-len>" part of the loose object
+ * header. It returns the size that snprintf() returns + 1.
+ */
+int format_object_header(char *str, size_t size, enum object_type type,
+			 size_t objsize);
+
+void assert_oid_type(const struct object_id *oid, enum object_type expect);
+
+/*
+ * Enabling the object read lock allows multiple threads to safely call the
+ * following functions in parallel: repo_read_object_file(),
+ * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ *
+ * obj_read_lock() and obj_read_unlock() may also be used to protect other
+ * section which cannot execute in parallel with object reading. Since the used
+ * lock is a recursive mutex, these sections can even contain calls to object
+ * reading functions. However, beware that in these cases zlib inflation won't
+ * be performed in parallel, losing performance.
+ *
+ * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * any of its callees end up calling it, this recursive call won't benefit from
+ * parallel inflation.
+ */
+void enable_obj_read_lock(void);
+void disable_obj_read_lock(void);
+
+extern int obj_read_use_lock;
+extern pthread_mutex_t obj_read_mutex;
+
+static inline void obj_read_lock(void)
+{
+	if(obj_read_use_lock)
+		pthread_mutex_lock(&obj_read_mutex);
+}
+
+static inline void obj_read_unlock(void)
+{
+	if(obj_read_use_lock)
+		pthread_mutex_unlock(&obj_read_mutex);
+}
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+				 const char *path,
+				 void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+				const char *path,
+				void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+				 const char *path,
+				 void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+				struct strbuf *path,
+				each_loose_object_fn obj_cb,
+				each_loose_cruft_fn cruft_cb,
+				each_loose_subdir_fn subdir_cb,
+				void *data);
+int for_each_loose_file_in_objdir(const char *path,
+				  each_loose_object_fn obj_cb,
+				  each_loose_cruft_fn cruft_cb,
+				  each_loose_subdir_fn subdir_cb,
+				  void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+				      each_loose_object_fn obj_cb,
+				      each_loose_cruft_fn cruft_cb,
+				      each_loose_subdir_fn subdir_cb,
+				      void *data);
+
+/* Flags for for_each_*_object() below. */
+enum for_each_object_flags {
+	/* Iterate only over local objects, not alternates. */
+	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+	/* Only iterate over packs obtained from the promisor remote. */
+	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+
+	/*
+	 * Visit objects within a pack in packfile order rather than .idx order
+	 */
+	FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
+
+	/* Only iterate over packs that are not marked as kept in-core. */
+	FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
+
+	/* Only iterate over packs that do not have .keep files. */
+	FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
+};
+
+/*
+ * Iterate over all accessible loose objects without respect to
+ * reachability. By default, this includes both local and alternate objects.
+ * The order in which objects are visited is unspecified.
+ *
+ * Any flags specific to packs are ignored.
+ */
+int for_each_loose_object(each_loose_object_fn, void *,
+			  enum for_each_object_flags flags);
+
+/*
+ * Iterate over all accessible packed objects without respect to reachability.
+ * By default, this includes both local and alternate packs.
+ *
+ * Note that some objects may appear twice if they are found in multiple packs.
+ * Each pack is visited in an unspecified order. By default, objects within a
+ * pack are visited in pack-idx order (i.e., sorted by oid).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+				  struct packed_git *pack,
+				  uint32_t pos,
+				  void *data);
+int for_each_object_in_pack(struct packed_git *p,
+			    each_packed_object_fn, void *data,
+			    enum for_each_object_flags flags);
+int for_each_packed_object(each_packed_object_fn, void *,
+			   enum for_each_object_flags flags);
+
+#endif /* OBJECT_STORE_LL_H */
diff --git a/object-store.h b/object-store.h
index 12415e5ea73..1b3e3d7d014 100644
--- a/object-store.h
+++ b/object-store.h
@@ -1,537 +1,11 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
-#include "object.h"
-#include "list.h"
-#include "thread-utils.h"
 #include "khash.h"
 #include "dir.h"
-#include "oidset.h"
-
-struct oidmap;
-struct oidtree;
-struct strbuf;
-
-struct object_directory {
-	struct object_directory *next;
-
-	/*
-	 * Used to store the results of readdir(3) calls when we are OK
-	 * sacrificing accuracy due to races for speed. That includes
-	 * object existence with OBJECT_INFO_QUICK, as well as
-	 * our search for unique abbreviated hashes. Don't use it for tasks
-	 * requiring greater accuracy!
-	 *
-	 * Be sure to call odb_load_loose_cache() before using.
-	 */
-	uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
-	struct oidtree *loose_objects_cache;
-
-	/*
-	 * This is a temporary object store created by the tmp_objdir
-	 * facility. Disable ref updates since the objects in the store
-	 * might be discarded on rollback.
-	 */
-	int disable_ref_updates;
-
-	/*
-	 * This object store is ephemeral, so there is no need to fsync.
-	 */
-	int will_destroy;
-
-	/*
-	 * Path to the alternative object store. If this is a relative path,
-	 * it is relative to the current working directory.
-	 */
-	char *path;
-};
-
-struct input_stream {
-	const void *(*read)(struct input_stream *, unsigned long *len);
-	void *data;
-	int is_finished;
-};
+#include "object-store-ll.h"
 
 KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
 	struct object_directory *, 1, fspathhash, fspatheq)
 
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
-/*
- * Add the directory to the on-disk alternates file; the new entry will also
- * take effect in the current process.
- */
-void add_to_alternates_file(const char *dir);
-
-/*
- * Add the directory to the in-memory list of alternates (along with any
- * recursive alternates it points to), but do not modify the on-disk alternates
- * file.
- */
-void add_to_alternates_memory(const char *dir);
-
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
-
-/*
- * Populate and return the loose object cache array corresponding to the
- * given object ID.
- */
-struct oidtree *odb_loose_cache(struct object_directory *odb,
-				  const struct object_id *oid);
-
-/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
-
-/* Clear and free the specified object directory */
-void free_object_directory(struct object_directory *odb);
-
-struct packed_git {
-	struct hashmap_entry packmap_ent;
-	struct packed_git *next;
-	struct list_head mru;
-	struct pack_window *windows;
-	off_t pack_size;
-	const void *index_data;
-	size_t index_size;
-	uint32_t num_objects;
-	uint32_t crc_offset;
-	struct oidset bad_objects;
-	int index_version;
-	time_t mtime;
-	int pack_fd;
-	int index;              /* for builtin/pack-objects.c */
-	unsigned pack_local:1,
-		 pack_keep:1,
-		 pack_keep_in_core:1,
-		 freshened:1,
-		 do_not_close:1,
-		 pack_promisor:1,
-		 multi_pack_index:1,
-		 is_cruft:1;
-	unsigned char hash[GIT_MAX_RAWSZ];
-	struct revindex_entry *revindex;
-	const uint32_t *revindex_data;
-	const uint32_t *revindex_map;
-	size_t revindex_size;
-	/*
-	 * mtimes_map points at the beginning of the memory mapped region of
-	 * this pack's corresponding .mtimes file, and mtimes_size is the size
-	 * of that .mtimes file
-	 */
-	const uint32_t *mtimes_map;
-	size_t mtimes_size;
-	/* something like ".git/objects/pack/xxxxx.pack" */
-	char pack_name[FLEX_ARRAY]; /* more */
-};
-
-struct multi_pack_index;
-
-static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
-				     const struct hashmap_entry *entry,
-				     const struct hashmap_entry *entry2,
-				     const void *keydata)
-{
-	const char *key = keydata;
-	const struct packed_git *pg1, *pg2;
-
-	pg1 = container_of(entry, const struct packed_git, packmap_ent);
-	pg2 = container_of(entry2, const struct packed_git, packmap_ent);
-
-	return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
-}
-
-struct raw_object_store {
-	/*
-	 * Set of all object directories; the main directory is first (and
-	 * cannot be NULL after initialization). Subsequent directories are
-	 * alternates.
-	 */
-	struct object_directory *odb;
-	struct object_directory **odb_tail;
-	kh_odb_path_map_t *odb_by_path;
-
-	int loaded_alternates;
-
-	/*
-	 * A list of alternate object directories loaded from the environment;
-	 * this should not generally need to be accessed directly, but will
-	 * populate the "odb" list when prepare_alt_odb() is run.
-	 */
-	char *alternate_db;
-
-	/*
-	 * Objects that should be substituted by other objects
-	 * (see git-replace(1)).
-	 */
-	struct oidmap *replace_map;
-	unsigned replace_map_initialized : 1;
-	pthread_mutex_t replace_mutex; /* protect object replace functions */
-
-	struct commit_graph *commit_graph;
-	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
-
-	/*
-	 * private data
-	 *
-	 * should only be accessed directly by packfile.c and midx.c
-	 */
-	struct multi_pack_index *multi_pack_index;
-
-	/*
-	 * private data
-	 *
-	 * should only be accessed directly by packfile.c
-	 */
-
-	struct packed_git *packed_git;
-	/* A most-recently-used ordered version of the packed_git list. */
-	struct list_head packed_git_mru;
-
-	struct {
-		struct packed_git **packs;
-		unsigned flags;
-	} kept_pack_cache;
-
-	/*
-	 * A map of packfiles to packed_git structs for tracking which
-	 * packs have been loaded already.
-	 */
-	struct hashmap pack_map;
-
-	/*
-	 * A fast, rough count of the number of objects in the repository.
-	 * These two fields are not meant for direct access. Use
-	 * repo_approximate_object_count() instead.
-	 */
-	unsigned long approximate_object_count;
-	unsigned approximate_object_count_valid : 1;
-
-	/*
-	 * Whether packed_git has already been populated with this repository's
-	 * packs.
-	 */
-	unsigned packed_git_initialized : 1;
-};
-
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
-
-/*
- * Put in `buf` the name of the file in the local object database that
- * would be used to store a loose object with the specified oid.
- */
-const char *loose_object_path(struct repository *r, struct strbuf *buf,
-			      const struct object_id *oid);
-
-void *map_loose_object(struct repository *r, const struct object_id *oid,
-		       unsigned long *size);
-
-void *repo_read_object_file(struct repository *r,
-			    const struct object_id *oid,
-			    enum object_type *type,
-			    unsigned long *size);
-
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
-void hash_object_file(const struct git_hash_algo *algo, const void *buf,
-		      unsigned long len, enum object_type type,
-		      struct object_id *oid);
-
-int write_object_file_flags(const void *buf, unsigned long len,
-			    enum object_type type, struct object_id *oid,
-			    unsigned flags);
-static inline int write_object_file(const void *buf, unsigned long len,
-				    enum object_type type, struct object_id *oid)
-{
-	return write_object_file_flags(buf, len, type, oid, 0);
-}
-
-int write_object_file_literally(const void *buf, unsigned long len,
-				const char *type, struct object_id *oid,
-				unsigned flags);
-int stream_loose_object(struct input_stream *in_stream, size_t len,
-			struct object_id *oid);
-
-/*
- * Add an object file to the in-memory object store, without writing it
- * to disk.
- *
- * Callers are responsible for calling write_object_file to record the
- * object in persistent storage before writing any other new objects
- * that reference it.
- */
-int pretend_object_file(void *, unsigned long, enum object_type,
-			struct object_id *oid);
-
-int force_object_loose(const struct object_id *oid, time_t mtime);
-
-struct object_info {
-	/* Request */
-	enum object_type *typep;
-	unsigned long *sizep;
-	off_t *disk_sizep;
-	struct object_id *delta_base_oid;
-	struct strbuf *type_name;
-	void **contentp;
-
-	/* Response */
-	enum {
-		OI_CACHED,
-		OI_LOOSE,
-		OI_PACKED,
-		OI_DBCACHED
-	} whence;
-	union {
-		/*
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } cached;
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } loose;
-		 */
-		struct {
-			struct packed_git *pack;
-			off_t offset;
-			unsigned int is_delta;
-		} packed;
-	} u;
-};
-
-/*
- * Initializer for a "struct object_info" that wants no items. You may
- * also memset() the memory to all-zeroes.
- */
-#define OBJECT_INFO_INIT { 0 }
-
-/* Invoke lookup_replace_object() on the given hash */
-#define OBJECT_INFO_LOOKUP_REPLACE 1
-/* Allow reading from a loose object file of unknown/bogus type */
-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
-/* Do not retry packed storage after checking packed and loose storage */
-#define OBJECT_INFO_QUICK 8
-/*
- * Do not attempt to fetch the object if missing (even if fetch_is_missing is
- * nonzero).
- */
-#define OBJECT_INFO_SKIP_FETCH_OBJECT 16
-/*
- * This is meant for bulk prefetching of missing blobs in a partial
- * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
- */
-#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
-
-/* Die if object corruption (not just an object being missing) was detected. */
-#define OBJECT_INFO_DIE_IF_CORRUPT 32
-
-int oid_object_info_extended(struct repository *r,
-			     const struct object_id *,
-			     struct object_info *, unsigned flags);
-
-/*
- * Open the loose object at path, check its hash, and return the contents,
- * use the "oi" argument to assert things about the object, or e.g. populate its
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
-		      const struct object_id *expected_oid,
-		      struct object_id *real_oid,
-		      void **contents,
-		      struct object_info *oi);
-
-/* Retry packed storage after checking packed and loose storage */
-#define HAS_OBJECT_RECHECK_PACKED 1
-
-/*
- * Returns 1 if the object exists. This function will not lazily fetch objects
- * in a partial clone.
- */
-int has_object(struct repository *r, const struct object_id *oid,
-	       unsigned flags);
-
-/*
- * These macros and functions are deprecated. If checking existence for an
- * object that is likely to be missing and/or whose absence is relatively
- * inconsequential (or is consequential but the caller is prepared to handle
- * it), use has_object(), which has better defaults (no lazy fetch in a partial
- * clone and no rechecking of packed storage). In the unlikely event that a
- * caller needs to assert existence of an object that it fully expects to
- * exist, and wants to trigger a lazy fetch in a partial clone, use
- * oid_object_info_extended() with a NULL struct object_info.
- *
- * These functions can be removed once all callers have migrated to
- * has_object() and/or oid_object_info_extended().
- */
-int repo_has_object_file(struct repository *r, const struct object_id *oid);
-int repo_has_object_file_with_flags(struct repository *r,
-				    const struct object_id *oid, int flags);
-
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name.  This function does not respect replace
- * references.
- */
-int has_loose_object_nonlocal(const struct object_id *);
-
-int has_loose_object(const struct object_id *);
-
-/**
- * format_object_header() is a thin wrapper around s xsnprintf() that
- * writes the initial "<type> <obj-len>" part of the loose object
- * header. It returns the size that snprintf() returns + 1.
- */
-int format_object_header(char *str, size_t size, enum object_type type,
-			 size_t objsize);
-
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
-
-/*
- * Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
- *
- * obj_read_lock() and obj_read_unlock() may also be used to protect other
- * section which cannot execute in parallel with object reading. Since the used
- * lock is a recursive mutex, these sections can even contain calls to object
- * reading functions. However, beware that in these cases zlib inflation won't
- * be performed in parallel, losing performance.
- *
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
- * any of its callees end up calling it, this recursive call won't benefit from
- * parallel inflation.
- */
-void enable_obj_read_lock(void);
-void disable_obj_read_lock(void);
-
-extern int obj_read_use_lock;
-extern pthread_mutex_t obj_read_mutex;
-
-static inline void obj_read_lock(void)
-{
-	if(obj_read_use_lock)
-		pthread_mutex_lock(&obj_read_mutex);
-}
-
-static inline void obj_read_unlock(void)
-{
-	if(obj_read_use_lock)
-		pthread_mutex_unlock(&obj_read_mutex);
-}
-
-/*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-				 const char *path,
-				 void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-				const char *path,
-				void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-				 const char *path,
-				 void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-				struct strbuf *path,
-				each_loose_object_fn obj_cb,
-				each_loose_cruft_fn cruft_cb,
-				each_loose_subdir_fn subdir_cb,
-				void *data);
-int for_each_loose_file_in_objdir(const char *path,
-				  each_loose_object_fn obj_cb,
-				  each_loose_cruft_fn cruft_cb,
-				  each_loose_subdir_fn subdir_cb,
-				  void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-				      each_loose_object_fn obj_cb,
-				      each_loose_cruft_fn cruft_cb,
-				      each_loose_subdir_fn subdir_cb,
-				      void *data);
-
-/* Flags for for_each_*_object() below. */
-enum for_each_object_flags {
-	/* Iterate only over local objects, not alternates. */
-	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
-
-	/* Only iterate over packs obtained from the promisor remote. */
-	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
-
-	/*
-	 * Visit objects within a pack in packfile order rather than .idx order
-	 */
-	FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
-
-	/* Only iterate over packs that are not marked as kept in-core. */
-	FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
-
-	/* Only iterate over packs that do not have .keep files. */
-	FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
-};
-
-/*
- * Iterate over all accessible loose objects without respect to
- * reachability. By default, this includes both local and alternate objects.
- * The order in which objects are visited is unspecified.
- *
- * Any flags specific to packs are ignored.
- */
-int for_each_loose_object(each_loose_object_fn, void *,
-			  enum for_each_object_flags flags);
-
-/*
- * Iterate over all accessible packed objects without respect to reachability.
- * By default, this includes both local and alternate packs.
- *
- * Note that some objects may appear twice if they are found in multiple packs.
- * Each pack is visited in an unspecified order. By default, objects within a
- * pack are visited in pack-idx order (i.e., sorted by oid).
- */
-typedef int each_packed_object_fn(const struct object_id *oid,
-				  struct packed_git *pack,
-				  uint32_t pos,
-				  void *data);
-int for_each_object_in_pack(struct packed_git *p,
-			    each_packed_object_fn, void *data,
-			    enum for_each_object_flags flags);
-int for_each_packed_object(each_packed_object_fn, void *,
-			   enum for_each_object_flags flags);
-
 #endif /* OBJECT_STORE_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..3e190214d14 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 623ee2a8197..d86f4e739a4 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -3,7 +3,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tag.h"
 #include "diff.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index e0fad723bf3..3981655f3cf 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
 #include "repository.h"
 #include "trace2.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "list-objects-filter-options.h"
 #include "midx.h"
 #include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 049f2f0bfc0..977f619618e 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -7,7 +7,7 @@
 #include "progress.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct idx_entry {
 	off_t                offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 020a37f8fe3..cdf30b8d2b0 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -2,8 +2,9 @@
 #include "gettext.h"
 #include "pack-mtimes.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
+#include "strbuf.h"
 
 static char *pack_mtimes_filename(struct packed_git *p)
 {
diff --git a/pack-objects.h b/pack-objects.h
index 579476687c4..0d78db40cb2 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
 #ifndef PACK_OBJECTS_H
 #define PACK_OBJECTS_H
 
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "thread-utils.h"
 #include "pack.h"
 
diff --git a/pack-revindex.c b/pack-revindex.c
index 1f51b712e87..7fffcad9125 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -2,8 +2,9 @@
 #include "gettext.h"
 #include "pack-revindex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
+#include "strbuf.h"
 #include "trace2.h"
 #include "config.h"
 #include "midx.h"
diff --git a/pack-write.c b/pack-write.c
index 45681e2d7db..af48813a9bb 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -11,6 +11,7 @@
 #include "pack-objects.h"
 #include "pack-revindex.h"
 #include "path.h"
+#include "strbuf.h"
 #include "wrapper.h"
 
 void reset_pack_idx_option(struct pack_idx_option *opts)
diff --git a/packfile.c b/packfile.c
index fd083c86e00..c60aeb05ece 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
 #include "tree-walk.h"
 #include "tree.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "midx.h"
 #include "commit-graph.h"
 #include "pack-revindex.h"
diff --git a/path.c b/path.c
index 7c1cd8182a8..c3b6618c77b 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
 #include "submodule-config.h"
 #include "path.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "lockfile.h"
 #include "exec-cmd.h"
 #include "wrapper.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 1adcd6fb0a5..db88d2064d4 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "config.h"
 #include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index a90c48852e5..808a68c974a 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,7 +7,7 @@
 #include "hash-ll.h"
 #include "hex.h"
 #include "object.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "string-list.h"
 #include "strbuf.h"
 
diff --git a/prune-packed.c b/prune-packed.c
index 58412b4fb91..e54daf740a2 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "progress.h"
 #include "prune-packed.h"
diff --git a/reachable.c b/reachable.c
index 55bb1143530..434f09e9ebf 100644
--- a/reachable.c
+++ b/reachable.c
@@ -13,7 +13,7 @@
 #include "list-objects.h"
 #include "packfile.h"
 #include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack-bitmap.h"
 #include "pack-mtimes.h"
 
diff --git a/read-cache.c b/read-cache.c
index 86ada403a83..b9a995e5a18 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -17,7 +17,7 @@
 #include "refs.h"
 #include "dir.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 4991cd4f7a8..e0d03a9f8e9 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -8,7 +8,7 @@
 #include "refs.h"
 #include "wildmatch.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/reflog.c b/reflog.c
index ee1bf5d032c..9ad50e7d93e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "reflog.h"
 #include "refs.h"
 #include "revision.h"
diff --git a/refs.c b/refs.c
index 5f76da35673..54a827b45b3 100644
--- a/refs.c
+++ b/refs.c
@@ -17,7 +17,7 @@
 #include "run-command.h"
 #include "hook.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "path.h"
 #include "tag.h"
diff --git a/remote.c b/remote.c
index 8550056db43..6538b6037de 100644
--- a/remote.c
+++ b/remote.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/remote.h b/remote.h
index 73638cefeb1..929c7c676d3 100644
--- a/remote.h
+++ b/remote.h
@@ -1,6 +1,7 @@
 #ifndef REMOTE_H
 #define REMOTE_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 #include "refspec.h"
 
diff --git a/replace-object.c b/replace-object.c
index e98825d5852..ca4017635df 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "refs.h"
 #include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index 500482b02b3..a964db1670e 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
 
 #include "oidmap.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 /*
  * Do replace refs need to be checked this run?  This variable is
diff --git a/repository.c b/repository.c
index 87a7a27b665..8c77b7ed236 100644
--- a/repository.c
+++ b/repository.c
@@ -6,7 +6,7 @@
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 35b9785d573..4a83e388f0d 100644
--- a/rerere.c
+++ b/rerere.c
@@ -17,7 +17,7 @@
 #include "path.h"
 #include "pathspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hash-lookup.h"
 #include "strmap.h"
 #include "wrapper.h"
diff --git a/revision.c b/revision.c
index d4b4b34fd80..84768565cef 100644
--- a/revision.c
+++ b/revision.c
@@ -6,7 +6,7 @@
 #include "hex.h"
 #include "object-name.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "tag.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/send-pack.c b/send-pack.c
index 0c7ccaef680..9510bef8561 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index eddd38d4bed..1b9607da268 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -11,7 +11,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "pager.h"
 #include "commit.h"
diff --git a/serve.c b/serve.c
index 5329c91011f..a1d71134d49 100644
--- a/serve.c
+++ b/serve.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "repository.h"
 #include "config.h"
+#include "hash-ll.h"
 #include "pkt-line.h"
 #include "version.h"
 #include "ls-refs.h"
diff --git a/server-info.c b/server-info.c
index 85d17bbb151..382e481a2b0 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
 #include "packfile.h"
 #include "path.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "server-info.h"
 #include "strbuf.h"
 #include "wrapper.h"
diff --git a/shallow.c b/shallow.c
index 45343e6a78b..f3ef94d4c92 100644
--- a/shallow.c
+++ b/shallow.c
@@ -4,7 +4,7 @@
 #include "repository.h"
 #include "tempfile.h"
 #include "lockfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 21e39585e89..49791ab958d 100644
--- a/streaming.c
+++ b/streaming.c
@@ -7,7 +7,7 @@
 #include "streaming.h"
 #include "repository.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "packfile.h"
 #include "wrapper.h"
diff --git a/submodule-config.c b/submodule-config.c
index c67260a3e11..1efd5471698 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -11,7 +11,7 @@
 #include "submodule.h"
 #include "strbuf.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index 245300596ff..f0f8788d2e3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
 #include "parse-options.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit-reach.h"
 #include "read-cache-ll.h"
 #include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 0f3fbeec532..67a964ef904 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "hex.h"
 #include "strbuf.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "pack-mtimes.h"
 #include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 362bd64a4c2..910a1286144 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "hex.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 
 /*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 3ac496e27e4..8c7a83f578f 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "commit-graph.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "bloom.h"
 #include "setup.h"
 
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 211addaa005..e9a444ddba5 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -2,7 +2,7 @@
 #include "hex.h"
 #include "midx.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack-bitmap.h"
 #include "packfile.h"
 #include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 1b30a6cba8b..04d26fc2fef 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -3,9 +3,10 @@
 #include "refs.h"
 #include "setup.h"
 #include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
+#include "strbuf.h"
 
 struct flag_definition {
 	const char *name;
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index bafd2a5bf95..4cd8a952e5c 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -4,7 +4,7 @@
 #include "config.h"
 #include "environment.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/tag.c b/tag.c
index 96dbd5b2d55..c5426484b22 100644
--- a/tag.c
+++ b/tag.c
@@ -2,7 +2,7 @@
 #include "environment.h"
 #include "tag.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index db1f7038dae..5f9074ad1c0 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -11,7 +11,7 @@
 #include "strbuf.h"
 #include "strvec.h"
 #include "quote.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct tmp_objdir {
 	struct strbuf path;
diff --git a/transport.c b/transport.c
index 67afdae57c1..4dc187a3885 100644
--- a/transport.c
+++ b/transport.c
@@ -27,7 +27,7 @@
 #include "transport-internal.h"
 #include "protocol.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "color.h"
 #include "bundle-uri.h"
 #include "wrapper.h"
diff --git a/tree-walk.c b/tree-walk.c
index d3c48e06df0..42ed86ef581 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "trace2.h"
 #include "tree.h"
 #include "pathspec.h"
diff --git a/tree.c b/tree.c
index 0dd2029a8a2..e118914a76a 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 4b620df3031..87517364dc0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -23,7 +23,7 @@
 #include "symlinks.h"
 #include "trace2.h"
 #include "fsmonitor.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "entry.h"
 #include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 08633dc1216..2502dcb4699 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -7,7 +7,7 @@
 #include "pkt-line.h"
 #include "sideband.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "tag.h"
 #include "object.h"
diff --git a/walker.c b/walker.c
index 24ff7dfdc28..65002a7220a 100644
--- a/walker.c
+++ b/walker.c
@@ -3,8 +3,9 @@
 #include "hex.h"
 #include "walker.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "tag.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 0460e03f5ed..abc7275a528 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "strbuf.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
-- 
gitgitgadget


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

* [PATCH 24/24] fsmonitor-ll.h: split this header out of fsmonitor.h
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (22 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
@ 2023-05-07  3:45 ` Elijah Newren via GitGitGadget
  2023-05-08 15:29 ` [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Junio C Hamano
                   ` (3 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-07  3:45 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This creates a new fsmonitor-ll.h with most of the functions from
fsmonitor.h, though it leaves three inline functions where they were.
Two-thirds of the files that previously included fsmonitor.h did not
need those three inline functions or the six extra includes those inline
functions required, so this allows them to only include the lower level
header.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/fsmonitor--daemon.c              |  4 +-
 compat/fsmonitor/fsm-health-darwin.c     |  2 +-
 compat/fsmonitor/fsm-health-win32.c      |  2 +-
 compat/fsmonitor/fsm-ipc-darwin.c        |  2 +-
 compat/fsmonitor/fsm-listen-darwin.c     |  3 +-
 compat/fsmonitor/fsm-listen-win32.c      |  2 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |  3 +-
 compat/fsmonitor/fsm-path-utils-win32.c  |  3 +-
 compat/fsmonitor/fsm-settings-darwin.c   |  2 +-
 compat/fsmonitor/fsm-settings-win32.c    |  2 +-
 dir.c                                    |  3 +-
 fsmonitor-ipc.c                          |  2 +-
 fsmonitor-ll.h                           | 52 ++++++++++++++++++++++++
 fsmonitor.h                              | 46 +--------------------
 sparse-index.c                           |  3 +-
 15 files changed, 73 insertions(+), 58 deletions(-)
 create mode 100644 fsmonitor-ll.h

diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index f6dd9a784c1..74d1d6a585d 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -5,15 +5,17 @@
 #include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-path-utils.h"
+#include "fsmonitor-settings.h"
 #include "compat/fsmonitor/fsm-health.h"
 #include "compat/fsmonitor/fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "simple-ipc.h"
 #include "khash.h"
 #include "pkt-line.h"
+#include "trace.h"
 #include "trace2.h"
 
 static const char * const builtin_fsmonitor__daemon_usage[] = {
diff --git a/compat/fsmonitor/fsm-health-darwin.c b/compat/fsmonitor/fsm-health-darwin.c
index 4c291f8a066..5b1709d63f7 100644
--- a/compat/fsmonitor/fsm-health-darwin.c
+++ b/compat/fsmonitor/fsm-health-darwin.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
 
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index 6c81d7ee5c2..2d4e245beb1 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 964bc074db6..6f3a95410cc 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -5,7 +5,7 @@
 #include "path.h"
 #include "repository.h"
 #include "strbuf.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-path-utils.h"
 
diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 23e24b4b374..36c7e13281c 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -24,12 +24,13 @@
 #endif
 
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
 #include "string-list.h"
+#include "trace.h"
 
 struct fsm_listen_data
 {
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 3c0df5cff8c..a361a7db20e 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index ef0142e0fbf..049f97eaaf2 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
+#include "trace.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 27bb6945183..c8a3e9dcdbb 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
+#include "trace.h"
 
 /*
  * Check remote working directory protocol.
diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c
index 58b623fbb9a..a3825906351 100644
--- a/compat/fsmonitor/fsm-settings-darwin.c
+++ b/compat/fsmonitor/fsm-settings-darwin.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index 37288978643..b6f67444944 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "repository.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
 
diff --git a/dir.c b/dir.c
index fada2713b9e..3acac7beb11 100644
--- a/dir.c
+++ b/dir.c
@@ -24,7 +24,8 @@
 #include "utf8.h"
 #include "varint.h"
 #include "ewah/ewok.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "submodule-config.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6ace978a1b4..88575aa54ca 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "gettext.h"
 #include "simple-ipc.h"
 #include "fsmonitor-ipc.h"
diff --git a/fsmonitor-ll.h b/fsmonitor-ll.h
new file mode 100644
index 00000000000..0504ca07d62
--- /dev/null
+++ b/fsmonitor-ll.h
@@ -0,0 +1,52 @@
+#ifndef FSMONITOR_LL_H
+#define FSMONITOR_LL_H
+
+struct index_state;
+struct strbuf;
+
+extern struct trace_key trace_fsmonitor;
+
+/*
+ * Read the fsmonitor index extension and (if configured) restore the
+ * CE_FSMONITOR_VALID state.
+ */
+int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
+
+/*
+ * Fill the fsmonitor_dirty ewah bits with their state from the index,
+ * before it is split during writing.
+ */
+void fill_fsmonitor_bitmap(struct index_state *istate);
+
+/*
+ * Write the CE_FSMONITOR_VALID state into the fsmonitor index
+ * extension.  Reads from the fsmonitor_dirty ewah in the index.
+ */
+void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension
+ */
+void add_fsmonitor(struct index_state *istate);
+void remove_fsmonitor(struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension as necessary based on the current
+ * core.fsmonitor setting.
+ */
+void tweak_fsmonitor(struct index_state *istate);
+
+/*
+ * Run the configured fsmonitor integration script and clear the
+ * CE_FSMONITOR_VALID bit for any files returned as dirty.  Also invalidate
+ * any corresponding untracked cache directory structures. Optimized to only
+ * run the first time it is called.
+ */
+void refresh_fsmonitor(struct index_state *istate);
+
+/*
+ * Does the received result contain the "trivial" response?
+ */
+int fsmonitor_is_trivial_response(const struct strbuf *query_result);
+
+#endif /* FSMONITOR_LL_H */
diff --git a/fsmonitor.h b/fsmonitor.h
index 7702301d214..5195a8624db 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,57 +1,13 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
+#include "fsmonitor-ll.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
 #include "object.h"
 #include "read-cache-ll.h"
 #include "trace.h"
 
-extern struct trace_key trace_fsmonitor;
-
-/*
- * Read the fsmonitor index extension and (if configured) restore the
- * CE_FSMONITOR_VALID state.
- */
-int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
-
-/*
- * Fill the fsmonitor_dirty ewah bits with their state from the index,
- * before it is split during writing.
- */
-void fill_fsmonitor_bitmap(struct index_state *istate);
-
-/*
- * Write the CE_FSMONITOR_VALID state into the fsmonitor index
- * extension.  Reads from the fsmonitor_dirty ewah in the index.
- */
-void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension
- */
-void add_fsmonitor(struct index_state *istate);
-void remove_fsmonitor(struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension as necessary based on the current
- * core.fsmonitor setting.
- */
-void tweak_fsmonitor(struct index_state *istate);
-
-/*
- * Run the configured fsmonitor integration script and clear the
- * CE_FSMONITOR_VALID bit for any files returned as dirty.  Also invalidate
- * any corresponding untracked cache directory structures. Optimized to only
- * run the first time it is called.
- */
-void refresh_fsmonitor(struct index_state *istate);
-
-/*
- * Does the received result contain the "trivial" response?
- */
-int fsmonitor_is_trivial_response(const struct strbuf *query_result);
-
 /*
  * Check if refresh_fsmonitor has been called at least once.
  * refresh_fsmonitor is idempotent. Returns true if fsmonitor is
diff --git a/sparse-index.c b/sparse-index.c
index 2c47954d933..90d04622568 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -3,6 +3,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
@@ -11,7 +12,7 @@
 #include "cache-tree.h"
 #include "config.h"
 #include "dir.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 
 struct modify_index_context {
 	struct index_state *write;
-- 
gitgitgadget

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

* Re: [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (23 preceding siblings ...)
  2023-05-07  3:45 ` [PATCH 24/24] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
@ 2023-05-08 15:29 ` Junio C Hamano
  2023-05-09  1:31   ` Elijah Newren
  2023-05-08 15:55 ` Junio C Hamano
                   ` (2 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Junio C Hamano @ 2023-05-08 15:29 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget; +Cc: git, Elijah Newren

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:


>   hash-ll, hashmap: move oidhash() to hash-ll
>   fsmonitor-ll.h: split this header out of fsmonitor.h

If you are introducing a bunch of -ll suffixed files, wouldn't you
want to either rename them to ll- prefixed, or rename ll-merge to
match them to make things consistent?

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

* Re: [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (24 preceding siblings ...)
  2023-05-08 15:29 ` [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Junio C Hamano
@ 2023-05-08 15:55 ` Junio C Hamano
  2023-05-11 17:41 ` Calvin Wan
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
  27 siblings, 0 replies; 115+ messages in thread
From: Junio C Hamano @ 2023-05-08 15:55 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget; +Cc: git, Elijah Newren

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Maintainer notes: (1) This series is built on top of a merge of
> en/header-split-cache-h-part-2 into master, (2) This series has no conflicts
> with next, but has three simple & small conflicts with seen:
>
>  * a textual conflict with tl/notes-separator (affecting builtin/notes.c; to
>    address, nuke the conflict region and add an include of alloc.h after
>    builtin.h)
>  * a textual & semantic conflict with cw/strbuf-cleanup (affecting strbuf.c;
>    to address, delete the conflict region and also delete the include of
>    repository.h)
>  * a semantic conflict with rn/sparse-diff-index (affecting
>    builtin/diff-index.c; to address, add an include of sparse-index.h).

After looking at them myself, I think that the above resolution
makes sense.

> This series continues to focus on splitting declarations from cache.h to
> separate headers, and also cleans up some other small header issues. By
> patch 16, cache.h is gone.

It is a nice touch to update the part of the coding guidelines
document that names which header files other than <git-compat-util.h>
can be the first one to include.


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

* Re: [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-08 15:29 ` [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Junio C Hamano
@ 2023-05-09  1:31   ` Elijah Newren
  2023-05-09 16:03     ` Junio C Hamano
  0 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren @ 2023-05-09  1:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Elijah Newren via GitGitGadget, git

On Mon, May 8, 2023 at 8:29 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>
> >   hash-ll, hashmap: move oidhash() to hash-ll
> >   fsmonitor-ll.h: split this header out of fsmonitor.h
>
> If you are introducing a bunch of -ll suffixed files, wouldn't you
> want to either rename them to ll- prefixed, or rename ll-merge to
> match them to make things consistent?

Sure, I'm happy to rename ll-merge to merge-ll.  I prefer a suffix
since it is common to see files sorted by filename (whether by Git or
by the shell) and the suffix tends to keep similar-ish files together.

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

* Re: [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-09  1:31   ` Elijah Newren
@ 2023-05-09 16:03     ` Junio C Hamano
  0 siblings, 0 replies; 115+ messages in thread
From: Junio C Hamano @ 2023-05-09 16:03 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Elijah Newren via GitGitGadget, git

Elijah Newren <newren@gmail.com> writes:

> Sure, I'm happy to rename ll-merge to merge-ll.  I prefer a suffix
> since it is common to see files sorted by filename (whether by Git or
> by the shell) and the suffix tends to keep similar-ish files together.

It can go both ways, though.  Grouping lower-level things together
has values, too ;-).

If foo and foo-lowleve needs to be grouped and read together to be
understood, it is a sign that the conceptual separation between the
higher- and lower-level things is not done cleanly enough.

Having said that, I do not care too deeply either way, as long as
it makes it easier to locate what we need to in the end result.

Thanks.


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

* Re: [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-07  3:45 ` [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
@ 2023-05-11 17:24   ` Calvin Wan
  2023-05-11 18:31     ` Jeff King
  0 siblings, 1 reply; 115+ messages in thread
From: Calvin Wan @ 2023-05-11 17:24 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget; +Cc: Calvin Wan, git, Elijah Newren

> Note that there's a small but
> important change to khash.h in this patch as well to allow this move,
> which is easy to overlook.

Can you go into a bit more detail as to how this change allows the move?
(An example of the concatenation would probably be sufficient)

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

* Re: [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug
  2023-05-07  3:45 ` [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug Elijah Newren via GitGitGadget
@ 2023-05-11 17:24   ` Calvin Wan
  2023-05-12  1:55     ` Elijah Newren
  2023-05-11 20:43   ` Glen Choo
  1 sibling, 1 reply; 115+ messages in thread
From: Calvin Wan @ 2023-05-11 17:24 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget; +Cc: Calvin Wan, git, Elijah Newren

Splitting this patch into two would make it easier to review and follow.
Regardless I think both changes make sense and thanks for documenting a
preexisting bug.

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

* Re: [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (25 preceding siblings ...)
  2023-05-08 15:55 ` Junio C Hamano
@ 2023-05-11 17:41 ` Calvin Wan
  2023-05-12  6:58   ` Elijah Newren
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
  27 siblings, 1 reply; 115+ messages in thread
From: Calvin Wan @ 2023-05-11 17:41 UTC (permalink / raw)
  To: git, Elijah Newren via GitGitGadget; +Cc: Calvin Wan, Elijah Newren

> This series continues to focus on splitting declarations from cache.h to
> separate headers, and also cleans up some other small header issues. By
> patch 16, cache.h is gone.

Congratulations on slaying the cache.h beast! Glad I was able to follow
the entire series to see how many headers cache.h eventually splits up
into.

Most of the patches in this series LGTM, but I do have a higher level
concern. A couple of patches in this series splits files from foo.h to
foo-ll.h and foo.h with the goal of having other files only include
foo-ll.h when needed and not foo.h which has other unnecessary includes.
While I believe that having less unnecessary includes clarifies which
files have what dependencies, I also believe that we are missing
documentation for how new functions should be added to either foo.h or
foo-ll.h. What criteria are we using to separate out those functions?

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

* Re: [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-11 17:24   ` Calvin Wan
@ 2023-05-11 18:31     ` Jeff King
  2023-05-11 18:39       ` Felipe Contreras
  2023-05-12  2:08       ` Elijah Newren
  0 siblings, 2 replies; 115+ messages in thread
From: Jeff King @ 2023-05-11 18:31 UTC (permalink / raw)
  To: Calvin Wan; +Cc: Elijah Newren via GitGitGadget, git, Elijah Newren

On Thu, May 11, 2023 at 05:24:01PM +0000, Calvin Wan wrote:

> > Note that there's a small but
> > important change to khash.h in this patch as well to allow this move,
> > which is easy to overlook.
> 
> Can you go into a bit more detail as to how this change allows the move?
> (An example of the concatenation would probably be sufficient)

Even after finding the hunk, I have to admit I scratched my head at what
was going on.

The answer is that object-store-ll.h now uses "struct kh_odb_path_map"
instead of a typedef'd kh_odb_path_map. Using the typedef is the way
that the khash library intends to work (and the only way it provides),
but does not match our usual Git style. In other users of the khash
library, we just bend to their will and use the typedef typedef (which
we have to, because it does not even name the struct type directly!).

But we can't do that here, because object-store-ll.h does not include
khash.h, so must forward declare the struct (actually, we do not even do
that, but it is legal to just refer to it as a pointer). But the
compiler only understands what we are doing if the "struct" keyword is
present.

So I think the solution here is reasonable, but I actually think it
would make sense to pull it out into its own patch, with a rationale
like:

  khash.h lets you instantiate custom hash types that map between two
  types. These are defined as a struct, as you might expect, and khash
  typedef's that to kh_foo_t. But it declares the struct anonymously,
  which doesn't give a name to the struct type itself; there is no
  "struct kh_foo". This has two small downsides:

    - when using khash, we declare "kh_foo_t *the_foo".  This is
      unlike our usual naming style, which is "struct kh_foo *the_foo".

    - you can't forward-declare a typedef of an unnamed struct type in
      C. So we might do something like this in a header file:

         struct kh_foo;
         struct bar {
                 struct kh_foo *the_foo;
	 };

      to avoid having to include the header that defines the real
      kh_foo. But that doesn't work with the typedef'd name. Without the
      "struct" keyword, the compiler doesn't know we mean that kh_foo is
      a type.

   So let's always give khash structs the name that matches our
   conventions ("struct kh_foo" to match "kh_foo_t"). We'll keep doing
   the typedef to retain compatibility with existing callers.

The "you can't do this in C" is all off the top of my head. I think it's
correct, but there may be a clever way to do it that I don't know of.
Though even there is, I think "make khash more like our usual
conventions" is a good thing by itself.

-Peff

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

* Re: [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-11 18:31     ` Jeff King
@ 2023-05-11 18:39       ` Felipe Contreras
  2023-05-12  2:08       ` Elijah Newren
  1 sibling, 0 replies; 115+ messages in thread
From: Felipe Contreras @ 2023-05-11 18:39 UTC (permalink / raw)
  To: Jeff King, Calvin Wan; +Cc: Elijah Newren via GitGitGadget, git, Elijah Newren

Jeff King wrote:

>   khash.h lets you instantiate custom hash types that map between two
>   types. These are defined as a struct, as you might expect, and khash
>   typedef's that to kh_foo_t. But it declares the struct anonymously,
>   which doesn't give a name to the struct type itself; there is no
>   "struct kh_foo". This has two small downsides:
> 
>     - when using khash, we declare "kh_foo_t *the_foo".  This is
>       unlike our usual naming style, which is "struct kh_foo *the_foo".
> 
>     - you can't forward-declare a typedef of an unnamed struct type in
>       C. So we might do something like this in a header file:
> 
>          struct kh_foo;
>          struct bar {
>                  struct kh_foo *the_foo;
> 	 };
> 
>       to avoid having to include the header that defines the real
>       kh_foo. But that doesn't work with the typedef'd name. Without the
>       "struct" keyword, the compiler doesn't know we mean that kh_foo is
>       a type.

One of the reasons why Linux doesn't do typedef.

-- 
Felipe Contreras

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

* Re: [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug
  2023-05-07  3:45 ` [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug Elijah Newren via GitGitGadget
  2023-05-11 17:24   ` Calvin Wan
@ 2023-05-11 20:43   ` Glen Choo
  2023-05-12  1:21     ` Elijah Newren
  1 sibling, 1 reply; 115+ messages in thread
From: Glen Choo @ 2023-05-11 20:43 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget, git; +Cc: Elijah Newren

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Elijah Newren <newren@gmail.com>
>
> This commit was prompted by a desire to move the functions which
> builtin/init-db.c and builtin/clone.c share out of the former file and
> into setup.c.  One issue that made it difficult was the
> init_is_bare_repository global variable.
>
> init_is_bare_repository is actually not very useful.  It merely stores
> the return value from is_bare_repository() and only for the duration of
> a few additional function calls before its value is checked, and none of
> those functions do anything that could change is_bare_repository()'s
> return value.  So, we can simply dispense with the global by replacing
> it with is_bare_repository().

I think the purpose of init_is_bare_repository is something different.
But based off my different understanding, I can't reproduce any
different behavior. I don't know if I'm just confused or not, but I'll
leave some breadcrumbs here to check my understanding.

Reordering the hunks for clarity,

> @@ -422,8 +436,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
>  
>  	safe_create_dir(git_dir, 0);
>  
> -	init_is_bare_repository = is_bare_repository();
> -
>  	/* Check to see if the repository version is right.
>  	 * Note that a newly created repository does not have
>  	 * config file, so this will not fail.  What we are catching

Here, init_db() caches the value of is_bare_repository(), which itself
reads the value of is_bare_repository_cfg, which can be modified by when
we read "core.bare" via git_config(git_default_config) or similar
(basically, any config callback that uses git_default_config). It is
also modified in other places though, like setup.c.

IIUC, we haven't actually parsed "core.bare" at this point. The
git_config() call just above this calls "plaform_core_config", which is
either "mingw_core_config" (doesn't read "core.bare") or
noop_core_config (noop).

> @@ -231,9 +230,24 @@ static int create_default_files(const char *template_path,
>  	 * We must make sure command-line options continue to override any
>  	 * values we might have just re-read from the config.
>  	 */
> -	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
>  	if (init_shared_repository != -1)
>  		set_shared_repository(init_shared_repository);
> +	/*
> +	 * TODO: heed core.bare from config file in templates if no
> +	 *       command-line override given
> +	 *
> +	 * Unfortunately, this location in the code is far too late to
> +	 * allow this to happen; both builtin/init.db and
> +	 * builtin/clone.c setup the new repository and call
> +	 * set_git_work_tree() before this point.  (Note that both do
> +	 * that repository setup before calling init_db(), which in
> +	 * turn calls create_default_files().)  Fixing it would
> +	 * require too much refactoring, and no one seems to have
> +	 * wanted this behavior in 15+ years, so we'll continue
> +	 * ignoring the config for now and just override
> +	 * is_bare_repository_cfg unconditionally.
> +	 */
> +	is_bare_repository_cfg = is_bare_repository() || !work_tree;
>  
>  	/*
>  	 * We would have created the above under user's umask -- under

Now, we're in the midst of the re-init. Expanding the context a little,
we see:

	git_config(git_default_config, NULL);

	/*
	 * We must make sure command-line options continue to override any
	 * values we might have just re-read from the config.
	 */
	is_bare_repository_cfg = init_is_bare_repository || !work_tree;

So now we've read the new config of the re-inited repo, which might have
"core.bare" set to a value other than what "git init-db [--bare]"
started with, so we want to _intentionally_ ignore it. We do this by
reading out the cached value, _not_ by calling is_bare_repository()
again. So it seems to me like this patch changes the intent.

Where I struggling with is how to make this behave badly. The lines
above seem to be defensive in nature - we never use
is_bare_repository_cfg past this point, but we want to guard against
unintentional behavior in the future.

But I thought that logging this value would show a difference in
behavior, e.g.

  diff --git a/builtin/init-db.c b/builtin/init-db.c
  index ba6e0b20fa..da3579d46d 100644
  --- a/builtin/init-db.c
  +++ b/builtin/init-db.c
  @@ -229,6 +229,8 @@ static int create_default_files(const char *template_path,
    * values we might have just re-read from the config.
    */
    is_bare_repository_cfg = init_is_bare_repository || !work_tree;
  +	printf_ln("is_bare_repository_cfg is %d", is_bare_repository_cfg);
  +
    if (init_shared_repository != -1)
      set_shared_repository(init_shared_repository);

  diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
  index 1b6437ec07..e4b978992e 100755
  --- a/t/t1301-shared-repo.sh
  +++ b/t/t1301-shared-repo.sh
  @@ -15,6 +15,14 @@ TEST_PASSES_SANITIZE_LEAK=true
  # Remove a default ACL from the test dir if possible.
  setfacl -k . 2>/dev/null

  +test_expect_success 're-init respects core.bare' '
  +	git init bare.git >actual &&
  +	grep "is_bare_repository_cfg is 0" actual &&
  +	git -C bare.git config core.bare true &&
  +	git init bare.git >actual &&
  +	grep "is_bare_repository_cfg is 1" actual
  +'
  +
  # User must have read permissions to the repo -> failure on --shared=0400
  test_expect_success 'shared = 0400 (faulty permission u-w)' '
    test_when_finished "rm -rf sub" &&

But apparently this doesn't work at all. I can't get this to print
"is_bare_repository_cfg is 1" no matter what I do, before or after your
patch. Maybe there's more at play here (e.g. with setup.c), but I
haven't figured that out.

If I'm right (which I'm not sure about), we might need to keep
init_is_bare_repository around _somewhere_. Not a global, but maybe
as a param.

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

* Re: [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug
  2023-05-11 20:43   ` Glen Choo
@ 2023-05-12  1:21     ` Elijah Newren
  2023-05-12 17:26       ` Glen Choo
  0 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren @ 2023-05-12  1:21 UTC (permalink / raw)
  To: Glen Choo; +Cc: Elijah Newren via GitGitGadget, git

On Thu, May 11, 2023 at 1:43 PM Glen Choo <chooglen@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Elijah Newren <newren@gmail.com>
> >
> > This commit was prompted by a desire to move the functions which
> > builtin/init-db.c and builtin/clone.c share out of the former file and
> > into setup.c.  One issue that made it difficult was the
> > init_is_bare_repository global variable.
> >
> > init_is_bare_repository is actually not very useful.  It merely stores
> > the return value from is_bare_repository() and only for the duration of
> > a few additional function calls before its value is checked, and none of
> > those functions do anything that could change is_bare_repository()'s
> > return value.  So, we can simply dispense with the global by replacing
> > it with is_bare_repository().
>
> I think the purpose of init_is_bare_repository is something different.
> But based off my different understanding, I can't reproduce any
> different behavior. I don't know if I'm just confused or not, but I'll
> leave some breadcrumbs here to check my understanding.

So, while my patch does not change behavior under any circumstances,
my explanation was slightly wrong.  More on that below...

> Reordering the hunks for clarity,
>
> > @@ -422,8 +436,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
> >
> >       safe_create_dir(git_dir, 0);
> >
> > -     init_is_bare_repository = is_bare_repository();
> > -
> >       /* Check to see if the repository version is right.
> >        * Note that a newly created repository does not have
> >        * config file, so this will not fail.  What we are catching
>
> Here, init_db() caches the value of is_bare_repository(), which itself
> reads the value of is_bare_repository_cfg, which can be modified by when
> we read "core.bare" via git_config(git_default_config) or similar
> (basically, any config callback that uses git_default_config). It is
> also modified in other places though, like setup.c.

Close.  is_bare_repository() not only reads the value of
is_bare_repository_cfg, but it ANDs the result with
!get_git_work_tree().  This turns out to be important.

> IIUC, we haven't actually parsed "core.bare" at this point. The
> git_config() call just above this calls "plaform_core_config", which is
> either "mingw_core_config" (doesn't read "core.bare") or
> noop_core_config (noop).

I believe this is correct.

> > @@ -231,9 +230,24 @@ static int create_default_files(const char *template_path,
> >        * We must make sure command-line options continue to override any
> >        * values we might have just re-read from the config.
> >        */
> > -     is_bare_repository_cfg = init_is_bare_repository || !work_tree;
> >       if (init_shared_repository != -1)
> >               set_shared_repository(init_shared_repository);
> > +     /*
> > +      * TODO: heed core.bare from config file in templates if no
> > +      *       command-line override given
> > +      *
> > +      * Unfortunately, this location in the code is far too late to
> > +      * allow this to happen; both builtin/init.db and
> > +      * builtin/clone.c setup the new repository and call
> > +      * set_git_work_tree() before this point.  (Note that both do
> > +      * that repository setup before calling init_db(), which in
> > +      * turn calls create_default_files().)  Fixing it would
> > +      * require too much refactoring, and no one seems to have
> > +      * wanted this behavior in 15+ years, so we'll continue
> > +      * ignoring the config for now and just override
> > +      * is_bare_repository_cfg unconditionally.
> > +      */
> > +     is_bare_repository_cfg = is_bare_repository() || !work_tree;
> >
> >       /*
> >        * We would have created the above under user's umask -- under
>
> Now, we're in the midst of the re-init. Expanding the context a little,
> we see:
>
>         git_config(git_default_config, NULL);
>
>         /*
>          * We must make sure command-line options continue to override any
>          * values we might have just re-read from the config.
>          */
>         is_bare_repository_cfg = init_is_bare_repository || !work_tree;
>
> So now we've read the new config of the re-inited repo, which might have
> "core.bare" set to a value other than what "git init-db [--bare]"
> started with

Correct.

> so we want to _intentionally_ ignore it.

That's what the code does, but not what it should do.  If neither
`--bare` nor `--no-bare` is given on the command line, we ought to pay
attention to the config setting.

The fact that we do ignore the config regardless of command line flags
is the bug that this patch documents.

> We do this by
> reading out the cached value, _not_ by calling is_bare_repository()
> again.

Almost, but you missed part of the line you are commenting on.  We
read out the cached value *and* OR it with !work_tree.  The
distinction may look small, but it turns out to be critical.

> So it seems to me like this patch changes the intent.

Yeah, looks like it does.

But it doesn't change the result.  Note the critical thing here is we
changed from computing:
   init_is_bare_repository || !work_tree;
to
   is_bare_repository() || !work_tree;

Further,
   init_is_bare_repository = [cached value of] is_bare_repository_cfg
&& [cached value of] !get_git_work_tree()
   is_bare_repository() = [current value of] is_bare_repository_cfg &&
[current value of] !get_git_work_tree()

However, nothing calls repo_init() or set_git_work_tree() between any
of these calls, so
   [current value of] !get_git_work_tree() == [cached value of]
!get_git_work_tree() == !work_tree

So, both before and after what we are computing simplifies to
   <something> && !work_tree || !work_tree
which further simplifies, regardless of whether <something> is true or
false, down to
   !work_tree

So whether we are using a cached value of is_bare_repository_cfg or a
current value of is_bare_repository_cfg is irrelevant.  In fact, from
the analysis above, we can simplify this line to just
   is_bare_repository_cfg = !work_tree;
completely ignoring both is_bare_repository_cfg and
is_bare_repository(), and it won't change the behavior.  I just did
it; it passes all tests.

> Where I struggling with is how to make this behave badly. The lines
> above seem to be defensive in nature - we never use
> is_bare_repository_cfg past this point, but we want to guard against
> unintentional behavior in the future.

Not quite true; there is another call to is_bare_repository() in the
same function about 60 lines later, which does pay attention to
is_bare_repository_cfg.

[...]
> If I'm right (which I'm not sure about), we might need to keep
> init_is_bare_repository around _somewhere_. Not a global, but maybe
> as a param.

This makes sense, despite the other bugs present.  I'll make this
change, as well as split this patch into two as Calvin suggested, and
update the description to correct my errors and explain the bug
better.

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

* Re: [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug
  2023-05-11 17:24   ` Calvin Wan
@ 2023-05-12  1:55     ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-12  1:55 UTC (permalink / raw)
  To: Calvin Wan; +Cc: Elijah Newren via GitGitGadget, git

On Thu, May 11, 2023 at 10:24 AM Calvin Wan <calvinwan@google.com> wrote:
>
> Splitting this patch into two would make it easier to review and follow.
> Regardless I think both changes make sense and thanks for documenting a
> preexisting bug.

Sure, I can do that.

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

* Re: [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-11 18:31     ` Jeff King
  2023-05-11 18:39       ` Felipe Contreras
@ 2023-05-12  2:08       ` Elijah Newren
  2023-05-12  4:07         ` Jeff King
  1 sibling, 1 reply; 115+ messages in thread
From: Elijah Newren @ 2023-05-12  2:08 UTC (permalink / raw)
  To: Jeff King; +Cc: Calvin Wan, Elijah Newren via GitGitGadget, git

On Thu, May 11, 2023 at 11:31 AM Jeff King <peff@peff.net> wrote:
>
> On Thu, May 11, 2023 at 05:24:01PM +0000, Calvin Wan wrote:
>
> > > Note that there's a small but
> > > important change to khash.h in this patch as well to allow this move,
> > > which is easy to overlook.
> >
> > Can you go into a bit more detail as to how this change allows the move?
> > (An example of the concatenation would probably be sufficient)
>
> Even after finding the hunk, I have to admit I scratched my head at what
> was going on.
>
> The answer is that object-store-ll.h now uses "struct kh_odb_path_map"
> instead of a typedef'd kh_odb_path_map. Using the typedef is the way
> that the khash library intends to work (and the only way it provides),
> but does not match our usual Git style. In other users of the khash
> library, we just bend to their will and use the typedef typedef (which
> we have to, because it does not even name the struct type directly!).
>
> But we can't do that here, because object-store-ll.h does not include
> khash.h, so must forward declare the struct (actually, we do not even do
> that, but it is legal to just refer to it as a pointer). But the
> compiler only understands what we are doing if the "struct" keyword is
> present.
>
> So I think the solution here is reasonable, but I actually think it
> would make sense to pull it out into its own patch, with a rationale
> like:
>
>   khash.h lets you instantiate custom hash types that map between two
>   types. These are defined as a struct, as you might expect, and khash
>   typedef's that to kh_foo_t. But it declares the struct anonymously,
>   which doesn't give a name to the struct type itself; there is no
>   "struct kh_foo". This has two small downsides:
>
>     - when using khash, we declare "kh_foo_t *the_foo".  This is
>       unlike our usual naming style, which is "struct kh_foo *the_foo".
>
>     - you can't forward-declare a typedef of an unnamed struct type in
>       C. So we might do something like this in a header file:
>
>          struct kh_foo;
>          struct bar {
>                  struct kh_foo *the_foo;
>          };
>
>       to avoid having to include the header that defines the real
>       kh_foo. But that doesn't work with the typedef'd name. Without the
>       "struct" keyword, the compiler doesn't know we mean that kh_foo is
>       a type.
>
>    So let's always give khash structs the name that matches our
>    conventions ("struct kh_foo" to match "kh_foo_t"). We'll keep doing
>    the typedef to retain compatibility with existing callers.
>
> The "you can't do this in C" is all off the top of my head. I think it's
> correct, but there may be a clever way to do it that I don't know of.
> Though even there is, I think "make khash more like our usual
> conventions" is a good thing by itself.

Oh, wow, I was about to type up an explanation to Calvin, but you did
so in even greater detail.  Sweet.

And sure, I'd be happy to split this out into a separate patch and
steal the commit message.  I think you deserve Co-author, though,
given it's only a 1-line code change versus the 20 line commit message
you wrote...

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

* Re: [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-12  2:08       ` Elijah Newren
@ 2023-05-12  4:07         ` Jeff King
  0 siblings, 0 replies; 115+ messages in thread
From: Jeff King @ 2023-05-12  4:07 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Calvin Wan, Elijah Newren via GitGitGadget, git

On Thu, May 11, 2023 at 07:08:00PM -0700, Elijah Newren wrote:

> Oh, wow, I was about to type up an explanation to Calvin, but you did
> so in even greater detail.  Sweet.
> 
> And sure, I'd be happy to split this out into a separate patch and
> steal the commit message.  I think you deserve Co-author, though,
> given it's only a 1-line code change versus the 20 line commit message
> you wrote...

Great. I'm happy with any form of credit (or none). And the commit
message is is S-o-b: me in case that matters. :)

-Peff

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

* Re: [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-11 17:41 ` Calvin Wan
@ 2023-05-12  6:58   ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-12  6:58 UTC (permalink / raw)
  To: Calvin Wan; +Cc: git, Elijah Newren via GitGitGadget

On Thu, May 11, 2023 at 10:42 AM Calvin Wan <calvinwan@google.com> wrote:
>
> > This series continues to focus on splitting declarations from cache.h to
> > separate headers, and also cleans up some other small header issues. By
> > patch 16, cache.h is gone.
>
> Congratulations on slaying the cache.h beast! Glad I was able to follow
> the entire series to see how many headers cache.h eventually splits up
> into.

Thanks.  :-)

> Most of the patches in this series LGTM, but I do have a higher level
> concern. A couple of patches in this series splits files from foo.h to
> foo-ll.h and foo.h with the goal of having other files only include
> foo-ll.h when needed and not foo.h which has other unnecessary includes.
> While I believe that having less unnecessary includes clarifies which
> files have what dependencies, I also believe that we are missing
> documentation for how new functions should be added to either foo.h or
> foo-ll.h. What criteria are we using to separate out those functions?

Right now it's a bit loose, and focused around structs rather than
functions and function declarations.  I'd state the guidelines roughly
as:
   * The foo-ll.h variants should only #include whatever headers are
necessary for the common structs they contain to be well-defined
   * The foo.h variants should take things (particularly inline
functions) that require additional includes
   * We should prefer forward declaring structs rather than
#include'ing a header where we can (though that's a bunch of patches
in a follow-on series I've prepared)
This is even a bit murky because of my use of the word "common".  For
example, I kept odb_path_map out of object-store-ll.h and left it in
object-store.h, because there were only 2 files that used struct
odb_path_map, while there are 56 that use the structs in
object-store-ll.h, and the declaration of odb_path_map requires
multiple extra headers.

Now, you specifically asked about where function declarations and
functions should go, and I side-stepped that question.  In part, I'm
leaving that undefined precisely because I was focused only on header
cleanups and not source cleanups, and I suspect that diving into the
code will yield insights about where we want to fit the boundary for
those.  So, for the many function declarations that could go in either
header and satisfy all the above rules, I think the libification work
you and Glen are doing is likely to nail this down a bit more.  Once
we have rules for how to divide those up, or even just a few examples
that we have good arguments for, then we can happily start moving the
function declarations between these headers.

Does that sound fair?

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

* [PATCH v2 00/27] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                   ` (26 preceding siblings ...)
  2023-05-11 17:41 ` Calvin Wan
@ 2023-05-12  7:04 ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 01/27] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
                     ` (27 more replies)
  27 siblings, 28 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren

== Summary ==

This series continues to focus on splitting declarations from cache.h to
separate headers, and also cleans up some other small header issues. By
patch 17, cache.h is gone.

== Changes ==

Since v1 (thanks to Calvin, Glen, Junio, and Peff for feedback and
suggestions!)

 * Split the first patch into two, correct the explanation around existing
   bug, and tweak how global is removed
 * New patch 24 to rename ll-merge.[ch] to merge-ll.[ch]
 * Patch 25 split out of the old patch 23 to document the khash.h change in
   isolation

== Reviewer Focus (see also "Overview" section, below) ==

While the series may look long and big, it's really mostly just (a) moving
lots of code (so --color-moved is handy), and (b) adding (or removing)
includes repeatedly throughout the code. These are just more of the same
kinds of changes from the previous series.

However, there are a few exceptions that do not fit in these two categories,
which should be reviewed more closely:

 * Patches 1-3 & 6
 * Patch 17, the Documentation and Makefile changes
 * Patch 24 & 25

Patches 11 & 26 might also merit a little closer review.

== Maintainer notes from v1 ==

(1) This series is built on top of a merge of en/header-split-cache-h-part-2
into master, (2) This series has no conflicts with next, but has three
simple & small conflicts with seen:

 * a textual conflict with tl/notes-separator (affecting builtin/notes.c; to
   address, nuke the conflict region and add an include of alloc.h after
   builtin.h)
 * a textual & semantic conflict with cw/strbuf-cleanup (affecting strbuf.c;
   to address, delete the conflict region and also delete the include of
   repository.h)
 * a semantic conflict with rn/sparse-diff-index (affecting
   builtin/diff-index.c; to address, add an include of sparse-index.h).

== Impact; interesting stats ==

By way of impact, I created a small script which before this series reports:

Total include depth of .c files: 18340
Total include depth of .h files: 1385


After this series, I see:

Total include depth of .c files: 16155
Total include depth of .h files: 1206


The script computes the number of files transitively included by each file
(not perfect, e.g. only does textual search so if the include if ifdef'd,
it'll be counted anyway), and then sums the results. I think these numbers
represent one rough measure of overall complexity humans face in
understanding files in our project, and/or that compilers take to operate.
(For reference, the total include depths for v2.40.0 were 23114 and 2981;
we've come a long way in improving it, most of that through nuking cache.h.)

== Overview ==

An overview:

 * Patches 1-7: move shared code between various builtin/*.c files into
   alternate shared homes (setup.c, read-cache.c).
 * Patches 8-17: continue splitting declarations from cache.h into
   alternative headers associated with the actual implementation of those
   functions.
 * Patches 18-23: remove some unnecessary includes in other header files
 * Patch 24: rename ll-merge for consistency, and to get a better name
 * Patches 25-27: do some header shuffling with hashmap/khash/hash, and
   fsmonitor to reduce include depths

I would have just lumped patches 1-7 in with 8-17, but patches 1-3, & 6 did
some preliminary changes to allow the code movement.

== Acknowledgements ==

And thanks once again to Dscho for gitgitgadget. Getting multiple platform
testing + all the special tests (sparse, cocci, hdr-check, etc.) really
helps clean out all the issues that would otherwise hit a series like this.

Elijah Newren (27):
  init-db: document existing bug with core.bare in template config
  init-db: remove unnecessary global variable
  init-db, clone: change unnecessary global into passed parameter
  setup: adopt shared init-db & clone code
  read-cache: move shared commit and ls-files code
  add: modify add_files_to_cache() to avoid globals
  read-cache: move shared add/checkout/commit code
  statinfo: move stat_{data,validity} functions from cache/read-cache
  run-command.h: move declarations for run-command.c from cache.h
  name-hash.h: move declarations for name-hash.c from cache.h
  sparse-index.h: move declarations for sparse-index.c from cache.h
  preload-index.h: move declarations for preload-index.c from elsewhere
  diff.h: move declaration for global in diff.c from cache.h
  merge.h: move declarations for merge.c from cache.h
  repository.h: move declaration of the_index from cache.h
  read-cache*.h: move declarations for read-cache.c functions from
    cache.h
  cache.h: remove this no-longer-used header
  log-tree: replace include of revision.h with simple forward
    declaration
  repository: remove unnecessary include of path.h
  diff.h: remove unnecessary include of oidset.h
  list-objects-filter-options.h: remove unneccessary include
  builtin.h: remove unneccessary includes
  git-compat-util.h: remove unneccessary include of wildmatch.h
  merge-ll: rename from ll-merge
  khash: name the structs that khash declares
  hash-ll, hashmap: move oidhash() to hash-ll
  fsmonitor-ll.h: split this header out of fsmonitor.h

 Documentation/CodingGuidelines           |   2 +-
 Documentation/MyFirstObjectWalk.txt      |   2 +-
 Documentation/technical/api-merge.txt    |   4 +-
 Documentation/user-manual.txt            |  18 +-
 Makefile                                 |   5 +-
 add-interactive.c                        |   6 +-
 add-patch.c                              |   4 +-
 apply.c                                  |  10 +-
 archive-tar.c                            |   2 +-
 archive-zip.c                            |   2 +-
 archive.c                                |   3 +-
 attr.c                                   |   6 +-
 bisect.c                                 |   3 +-
 blame.c                                  |   6 +-
 blame.h                                  |   1 +
 branch.c                                 |   1 +
 builtin.h                                |   3 -
 builtin/add.c                            | 105 +----
 builtin/am.c                             |   5 +-
 builtin/apply.c                          |   1 -
 builtin/archive.c                        |   1 -
 builtin/bisect.c                         |   2 +-
 builtin/blame.c                          |   2 +-
 builtin/branch.c                         |   4 +-
 builtin/bundle.c                         |   1 -
 builtin/cat-file.c                       |   5 +-
 builtin/check-attr.c                     |   1 -
 builtin/check-ignore.c                   |   1 -
 builtin/check-mailmap.c                  |   1 +
 builtin/check-ref-format.c               |   3 +-
 builtin/checkout--worker.c               |   1 +
 builtin/checkout-index.c                 |   2 +
 builtin/checkout.c                       |   9 +-
 builtin/clean.c                          |   3 +-
 builtin/clone.c                          |   6 +-
 builtin/column.c                         |   1 -
 builtin/commit-graph.c                   |   3 +-
 builtin/commit-tree.c                    |   5 +-
 builtin/commit.c                         |  10 +-
 builtin/config.c                         |   1 +
 builtin/count-objects.c                  |   6 +-
 builtin/credential-cache.c               |   1 +
 builtin/describe.c                       |   7 +-
 builtin/diff-files.c                     |   5 +-
 builtin/diff-index.c                     |   5 +-
 builtin/diff-tree.c                      |   5 +-
 builtin/diff.c                           |   5 +-
 builtin/difftool.c                       |   7 +-
 builtin/fast-export.c                    |   3 +-
 builtin/fast-import.c                    |   4 +-
 builtin/fetch.c                          |   6 +-
 builtin/for-each-ref.c                   |   2 +-
 builtin/for-each-repo.c                  |   3 +-
 builtin/fsck.c                           |   6 +-
 builtin/fsmonitor--daemon.c              |   4 +-
 builtin/gc.c                             |   3 +-
 builtin/get-tar-commit-id.c              |   3 +-
 builtin/grep.c                           |   7 +-
 builtin/hash-object.c                    |   3 +-
 builtin/help.c                           |   3 +-
 builtin/hook.c                           |   1 -
 builtin/index-pack.c                     |   3 +-
 builtin/init-db.c                        | 474 +-------------------
 builtin/interpret-trailers.c             |   1 -
 builtin/log.c                            |   2 +-
 builtin/ls-files.c                       | 143 +-----
 builtin/ls-remote.c                      |   2 +-
 builtin/ls-tree.c                        |   6 +-
 builtin/mailinfo.c                       |   3 +-
 builtin/mailsplit.c                      |   1 -
 builtin/merge-base.c                     |   1 -
 builtin/merge-file.c                     |   1 -
 builtin/merge-index.c                    |   2 +
 builtin/merge-ours.c                     |   1 +
 builtin/merge-recursive.c                |   1 -
 builtin/merge-tree.c                     |   2 +-
 builtin/merge.c                          |   5 +-
 builtin/mktag.c                          |   3 +-
 builtin/mktree.c                         |   3 +-
 builtin/multi-pack-index.c               |   4 +-
 builtin/mv.c                             |   2 +
 builtin/name-rev.c                       |   1 +
 builtin/notes.c                          |   6 +-
 builtin/pack-objects.c                   |   2 +-
 builtin/pack-redundant.c                 |   2 +-
 builtin/patch-id.c                       |   2 +-
 builtin/prune.c                          |   7 +-
 builtin/pull.c                           |   6 +-
 builtin/push.c                           |   3 +-
 builtin/range-diff.c                     |   2 +-
 builtin/read-tree.c                      |   4 +-
 builtin/rebase.c                         |   1 +
 builtin/receive-pack.c                   |   3 +-
 builtin/reflog.c                         |   2 +
 builtin/remote.c                         |   3 +-
 builtin/repack.c                         |   3 +-
 builtin/replace.c                        |   7 +-
 builtin/rerere.c                         |   1 -
 builtin/reset.c                          |   3 +
 builtin/rev-list.c                       |   5 +-
 builtin/rev-parse.c                      |   6 +-
 builtin/revert.c                         |   1 +
 builtin/rm.c                             |   2 +
 builtin/shortlog.c                       |   2 +-
 builtin/show-branch.c                    |   4 +-
 builtin/show-index.c                     |   1 -
 builtin/show-ref.c                       |   3 +-
 builtin/sparse-checkout.c                |   1 -
 builtin/stash.c                          |   4 +
 builtin/stripspace.c                     |   1 -
 builtin/submodule--helper.c              |   7 +-
 builtin/symbolic-ref.c                   |   1 -
 builtin/tag.c                            |   6 +-
 builtin/unpack-file.c                    |   2 +-
 builtin/unpack-objects.c                 |   3 +-
 builtin/update-index.c                   |   5 +-
 builtin/update-ref.c                     |   3 +-
 builtin/update-server-info.c             |   3 +-
 builtin/upload-archive.c                 |   2 +-
 builtin/upload-pack.c                    |   2 +-
 builtin/verify-commit.c                  |   5 +-
 builtin/verify-pack.c                    |   2 +-
 builtin/verify-tag.c                     |   3 +-
 builtin/worktree.c                       |   5 +-
 builtin/write-tree.c                     |   1 -
 bulk-checkin.c                           |   2 +-
 bundle-uri.c                             |   2 +-
 bundle.c                                 |   2 +-
 cache-tree.c                             |   5 +-
 combine-diff.c                           |   2 +-
 commit-graph.c                           |   3 +-
 commit-graph.h                           |   2 +-
 commit.c                                 |   2 +-
 compat/fsmonitor/fsm-health-darwin.c     |   2 +-
 compat/fsmonitor/fsm-health-win32.c      |   4 +-
 compat/fsmonitor/fsm-ipc-darwin.c        |   3 +-
 compat/fsmonitor/fsm-listen-darwin.c     |   3 +-
 compat/fsmonitor/fsm-listen-win32.c      |   4 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |   4 +-
 compat/fsmonitor/fsm-path-utils-win32.c  |   5 +-
 compat/fsmonitor/fsm-settings-darwin.c   |   2 +-
 compat/fsmonitor/fsm-settings-win32.c    |   4 +-
 compat/mingw.c                           |   1 -
 compat/precompose_utf8.c                 |   3 +-
 compat/sha1-chunked.c                    |   3 +-
 compat/simple-ipc/ipc-win32.c            |   2 +-
 compat/win32/trace2_win32_process_info.c |   2 +-
 config.c                                 |   5 +-
 connect.c                                |   1 +
 connected.c                              |   2 +-
 convert.c                                |   7 +-
 decorate.c                               |   1 -
 diagnose.c                               |   2 +-
 diff-lib.c                               |   5 +-
 diff.c                                   |   7 +-
 diff.h                                   |   6 +-
 diffcore-break.c                         |   4 +-
 diffcore-order.c                         |   1 +
 diffcore-pickaxe.c                       |   1 +
 diffcore-rename.c                        |   2 +-
 dir.c                                    |   8 +-
 dir.h                                    |   1 +
 entry.c                                  |   6 +-
 environment.c                            |   5 +-
 environment.h                            |   3 +-
 exec-cmd.c                               |   3 +-
 fetch-pack.c                             |   3 +-
 fmt-merge-msg.c                          |   3 +-
 fsck.c                                   |   4 +-
 fsmonitor-ipc.c                          |   4 +-
 fsmonitor-ll.h                           |  52 +++
 fsmonitor.c                              |   2 +-
 fsmonitor.h                              |  49 +--
 git-compat-util.h                        |   2 -
 git.c                                    |   1 +
 grep.c                                   |   2 +-
 hash-ll.h                                |  19 +
 hash-lookup.c                            |   3 +-
 hashmap.h                                |  21 -
 http-backend.c                           |   3 +-
 http-push.c                              |   2 +-
 http-walker.c                            |   2 +-
 http.c                                   |   2 +-
 khash.h                                  |   3 +-
 line-log.c                               |   1 +
 list-objects-filter-options.h            |   1 -
 list-objects-filter.c                    |   2 +-
 list-objects.c                           |   2 +-
 log-tree.c                               |   4 +-
 log-tree.h                               |   2 +-
 mailmap.c                                |   2 +-
 match-trees.c                            |   3 +-
 merge-blobs.c                            |   4 +-
 ll-merge.c => merge-ll.c                 |   2 +-
 ll-merge.h => merge-ll.h                 |   0
 merge-ort-wrappers.c                     |   3 +-
 merge-ort.c                              |   9 +-
 merge-recursive.c                        |   9 +-
 merge.c                                  |   5 +-
 merge.h                                  |  17 +
 midx.c                                   |   2 +-
 name-hash.c                              |   5 +-
 name-hash.h                              |  16 +
 notes-cache.c                            |   3 +-
 notes-merge.c                            |   5 +-
 notes.c                                  |   2 +-
 object-file.c                            |   1 +
 object-name.c                            |   5 +-
 object-store-ll.h                        | 533 +++++++++++++++++++++++
 object-store.h                           | 528 +---------------------
 object.c                                 |   3 +-
 oidmap.h                                 |   1 +
 oss-fuzz/fuzz-pack-idx.c                 |   2 +-
 pack-bitmap-write.c                      |   3 +-
 pack-bitmap.c                            |   2 +-
 pack-check.c                             |   2 +-
 pack-mtimes.c                            |   3 +-
 pack-objects.h                           |   2 +-
 pack-revindex.c                          |   3 +-
 pack-write.c                             |   2 +
 packfile.c                               |   2 +-
 parallel-checkout.c                      |   3 +-
 patch-ids.c                              |   1 +
 path.c                                   |   2 +-
 pathspec.c                               |   4 +-
 preload-index.c                          |   4 +-
 preload-index.h                          |  15 +
 pretty.c                                 |   1 +
 promisor-remote.c                        |   2 +-
 protocol-caps.c                          |   2 +-
 prune-packed.c                           |   2 +-
 range-diff.c                             |   1 +
 reachable.c                              |   2 +-
 cache.h => read-cache-ll.h               | 148 +------
 read-cache.c                             | 331 ++++++++++----
 read-cache.h                             |  45 ++
 ref-filter.c                             |   2 +-
 reflog-walk.c                            |   1 +
 reflog.c                                 |   2 +-
 refs.c                                   |   4 +-
 refs/files-backend.c                     |   3 +-
 refs/packed-backend.c                    |   3 +-
 remote.c                                 |   3 +-
 remote.h                                 |   1 +
 replace-object.c                         |   2 +-
 replace-object.h                         |   2 +-
 repository.c                             |   6 +-
 repository.h                             |   8 +-
 rerere.c                                 |   8 +-
 resolve-undo.c                           |   4 +-
 revision.c                               |   7 +-
 run-command.c                            |   2 +-
 run-command.h                            |   4 +-
 send-pack.c                              |   2 +-
 sequencer.c                              |   7 +-
 serve.c                                  |   1 +
 server-info.c                            |   3 +-
 setup.c                                  | 497 +++++++++++++++++++++
 setup.h                                  |   9 +
 shallow.c                                |   6 +-
 sparse-index.c                           |   6 +-
 sparse-index.h                           |   2 +
 split-index.c                            |   3 +-
 statinfo.c                               |  87 ++++
 statinfo.h                               |  51 +++
 strbuf.c                                 |   1 +
 strbuf.h                                 |   4 -
 streaming.c                              |   2 +-
 submodule-config.c                       |   3 +-
 submodule.c                              |   6 +-
 t/helper/test-cache-tree.c               |   2 +-
 t/helper/test-dump-cache-tree.c          |   2 +-
 t/helper/test-dump-fsmonitor.c           |   2 +-
 t/helper/test-dump-split-index.c         |   3 +-
 t/helper/test-dump-untracked-cache.c     |   2 +-
 t/helper/test-fast-rebase.c              |   3 +-
 t/helper/test-fsmonitor-client.c         |   2 +-
 t/helper/test-hash-speed.c               |   2 +-
 t/helper/test-index-version.c            |   2 +-
 t/helper/test-lazy-init-name-hash.c      |   3 +-
 t/helper/test-pack-mtimes.c              |   2 +-
 t/helper/test-partial-clone.c            |   2 +-
 t/helper/test-path-utils.c               |   2 +-
 t/helper/test-read-cache.c               |   2 +-
 t/helper/test-read-graph.c               |   2 +-
 t/helper/test-read-midx.c                |   2 +-
 t/helper/test-ref-store.c                |   4 +-
 t/helper/test-repository.c               |   2 +-
 t/helper/test-revision-walking.c         |   1 +
 t/helper/test-scrap-cache-tree.c         |   2 +-
 t/helper/test-sha1.c                     |   2 +-
 t/helper/test-sha256.c                   |   2 +-
 t/helper/test-strcmp-offset.c            |   2 +-
 t/helper/test-wildmatch.c                |   1 +
 t/helper/test-write-cache.c              |   2 +-
 t/t1301-shared-repo.sh                   |  22 +
 t/t5606-clone-options.sh                 |  10 +
 tag.c                                    |   2 +-
 tmp-objdir.c                             |   3 +-
 trace2/tr2_cfg.c                         |   1 +
 transport-helper.c                       |   1 +
 transport.c                              |   2 +-
 tree-diff.c                              |   1 +
 tree-walk.c                              |   2 +-
 tree.c                                   |   2 +-
 unpack-trees.c                           |   6 +-
 unpack-trees.h                           |   2 +-
 upload-pack.c                            |   2 +-
 walker.c                                 |   3 +-
 worktree.c                               |   1 +
 wt-status.c                              |   5 +-
 xdiff-interface.c                        |   3 +-
 312 files changed, 2179 insertions(+), 1895 deletions(-)
 create mode 100644 fsmonitor-ll.h
 rename ll-merge.c => merge-ll.c (99%)
 rename ll-merge.h => merge-ll.h (100%)
 create mode 100644 merge.h
 create mode 100644 name-hash.h
 create mode 100644 object-store-ll.h
 create mode 100644 preload-index.h
 rename cache.h => read-cache-ll.h (79%)
 create mode 100644 read-cache.h
 create mode 100644 statinfo.c


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

Range-diff vs v1:

  1:  12a251f77f6 !  1:  f7ee69e7e68 init-db: remove unnecessary global variable & document existing bug
     @@ Metadata
      Author: Elijah Newren <newren@gmail.com>
      
       ## Commit message ##
     -    init-db: remove unnecessary global variable & document existing bug
     +    init-db: document existing bug with core.bare in template config
      
     -    This commit was prompted by a desire to move the functions which
     -    builtin/init-db.c and builtin/clone.c share out of the former file and
     -    into setup.c.  One issue that made it difficult was the
     -    init_is_bare_repository global variable.
     +    The comments in create_default_files() talks about reading config from
     +    the config file in the specified `--templates` directory, which leads to
     +    the question of whether core.bare could be set in such a config file and
     +    thus whether the code is doing the right thing.  It turns out, that it
     +    doesn't; it unconditionally ignores core.bare in the config file in any
     +    --templates directory.  It is not clear to me that fixing it can be done
     +    within this function; it seems to occur too late:
     +      * create_default_files() is called by init_db()
     +      * init_db() is called by both builtin/{clone.c,init-db.c}
     +      * both callers of init_db() call set_git_work_tree() before init_db()
     +    and in order to actual affect whether a repository is bear, we'd need to
     +    somewhere reset these values, not just the is_bare_repository_cfg
     +    setting.
      
     -    init_is_bare_repository is actually not very useful.  It merely stores
     -    the return value from is_bare_repository() and only for the duration of
     -    a few additional function calls before its value is checked, and none of
     -    those functions do anything that could change is_bare_repository()'s
     -    return value.  So, we can simply dispense with the global by replacing
     -    it with is_bare_repository().
     -
     -    However, the intervening code does talk about reading config from the
     -    config file in the specified `--templates` directory, so touching this
     -    code does lead to the question of whether core.bare could be set in such
     -    a config file and thus whether the code is doing the right thing.  Long
     -    story short is that the templates directory might have a config file
     -    with core.bare set, but it has always been unconditionally ignored.
     -    While fixing that might be nice, it looks to be a can of worms, and
     -    cannot be fixed within this function anyway.  Instead of opening that
     -    can of worms, document the problem with a TODO comment and a couple
     -    test_expect_failure testcases.
     +    I do not want to open this can of worms at this time; I'm trying to
     +    clean up some headers, for which I need to move some functions, for
     +    which I need to clean up some globals, and that's far enough down the
     +    rabbit hole.  So, simply document the issue with a careful TODO comment
     +    and a few testcases.
      
          Signed-off-by: Elijah Newren <newren@gmail.com>
      
       ## builtin/init-db.c ##
     -@@
     - 
     - #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
     - 
     --static int init_is_bare_repository = 0;
     - static int init_shared_repository = -1;
     - 
     - static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
      @@ builtin/init-db.c: static int create_default_files(const char *template_path,
       	 * We must make sure command-line options continue to override any
       	 * values we might have just re-read from the config.
     @@ builtin/init-db.c: static int create_default_files(const char *template_path,
      +	/*
      +	 * TODO: heed core.bare from config file in templates if no
      +	 *       command-line override given
     ++	 */
     ++	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
     ++	/* TODO (continued):
     ++	 *
     ++	 * Unfortunately, the line above is equivalent to
     ++	 *    is_bare_repository_cfg = !work_tree;
     ++	 * which ignores the config entirely even if no `--[no-]bare`
     ++	 * command line option was present.
      +	 *
     -+	 * Unfortunately, this location in the code is far too late to
     -+	 * allow this to happen; both builtin/init.db and
     -+	 * builtin/clone.c setup the new repository and call
     -+	 * set_git_work_tree() before this point.  (Note that both do
     -+	 * that repository setup before calling init_db(), which in
     -+	 * turn calls create_default_files().)  Fixing it would
     -+	 * require too much refactoring, and no one seems to have
     -+	 * wanted this behavior in 15+ years, so we'll continue
     -+	 * ignoring the config for now and just override
     -+	 * is_bare_repository_cfg unconditionally.
     ++	 * To see why, note that before this function, there was this call:
     ++	 *    init_is_bare_repository = is_bare_repository()
     ++	 * expanding the right hande side:
     ++	 *                 = is_bare_repository_cfg && !get_git_work_tree()
     ++	 *                 = is_bare_repository_cfg && !work_tree
     ++	 * note that the last simplification above is valid because nothing
     ++	 * calls repo_init() or set_git_work_tree() between any of the
     ++	 * relevant calls in the code, and thus the !get_git_work_tree()
     ++	 * calls will return the same result each time.  So, what we are
     ++	 * interested in computing is the right hand side of the line of
     ++	 * code just above this comment:
     ++	 *     init_is_bare_repository || !work_tree
     ++	 *        = is_bare_repository_cfg && !work_tree || !work_tree
     ++	 *        = !work_tree
     ++	 * because "A && !B || !B == !B" for all boolean values of A & B.
      +	 */
     -+	is_bare_repository_cfg = is_bare_repository() || !work_tree;
       
       	/*
       	 * We would have created the above under user's umask -- under
     -@@ builtin/init-db.c: int init_db(const char *git_dir, const char *real_git_dir,
     - 
     - 	safe_create_dir(git_dir, 0);
     - 
     --	init_is_bare_repository = is_bare_repository();
     --
     - 	/* Check to see if the repository version is right.
     - 	 * Note that a newly created repository does not have
     - 	 * config file, so this will not fail.  What we are catching
      
       ## t/t1301-shared-repo.sh ##
      @@ t/t1301-shared-repo.sh: test_expect_success 'shared=all' '
  -:  ----------- >  2:  5ba9d6e68ad init-db: remove unnecessary global variable
  2:  e3cc7eb145e !  3:  3bc4dfeea90 init-db, clone: change unnecessary global into passed parameter
     @@ builtin/init-db.c
       			     DIR *dir)
       {
      @@ builtin/init-db.c: static int create_default_files(const char *template_path,
     - 				const char *original_git_dir,
       				const char *initial_branch,
       				const struct repository_format *fmt,
     + 				int prev_bare_repository,
      +				int init_shared_repository,
       				int quiet)
       {
     @@ builtin/init-db.c: static void validate_hash_algorithm(struct repository_format
       	int reinit;
       	int exist_ok = flags & INIT_DB_EXIST_OK;
      @@ builtin/init-db.c: int init_db(const char *git_dir, const char *real_git_dir,
     - 
       	reinit = create_default_files(template_dir, original_git_dir,
       				      initial_branch, &repo_fmt,
     + 				      prev_bare_repository,
      +				      init_shared_repository,
       				      flags & INIT_DB_QUIET);
       	if (reinit && initial_branch)
  3:  dffbac9a494 !  4:  60d01387f41 setup: adopt shared init-db & clone code
     @@ builtin/init-db.c
      -				const char *original_git_dir,
      -				const char *initial_branch,
      -				const struct repository_format *fmt,
     +-				int prev_bare_repository,
      -				int init_shared_repository,
      -				int quiet)
      -{
     @@ builtin/init-db.c
      -	/*
      -	 * TODO: heed core.bare from config file in templates if no
      -	 *       command-line override given
     +-	 */
     +-	is_bare_repository_cfg = prev_bare_repository || !work_tree;
     +-	/* TODO (continued):
     +-	 *
     +-	 * Unfortunately, the line above is equivalent to
     +-	 *    is_bare_repository_cfg = !work_tree;
     +-	 * which ignores the config entirely even if no `--[no-]bare`
     +-	 * command line option was present.
      -	 *
     --	 * Unfortunately, this location in the code is far too late to
     --	 * allow this to happen; both builtin/init.db and
     --	 * builtin/clone.c setup the new repository and call
     --	 * set_git_work_tree() before this point.  (Note that both do
     --	 * that repository setup before calling init_db(), which in
     --	 * turn calls create_default_files().)  Fixing it would
     --	 * require too much refactoring, and no one seems to have
     --	 * wanted this behavior in 15+ years, so we'll continue
     --	 * ignoring the config for now and just override
     --	 * is_bare_repository_cfg unconditionally.
     +-	 * To see why, note that before this function, there was this call:
     +-	 *    prev_bare_repository = is_bare_repository()
     +-	 * expanding the right hande side:
     +-	 *                 = is_bare_repository_cfg && !get_git_work_tree()
     +-	 *                 = is_bare_repository_cfg && !work_tree
     +-	 * note that the last simplification above is valid because nothing
     +-	 * calls repo_init() or set_git_work_tree() between any of the
     +-	 * relevant calls in the code, and thus the !get_git_work_tree()
     +-	 * calls will return the same result each time.  So, what we are
     +-	 * interested in computing is the right hand side of the line of
     +-	 * code just above this comment:
     +-	 *     prev_bare_repository || !work_tree
     +-	 *        = is_bare_repository_cfg && !work_tree || !work_tree
     +-	 *        = !work_tree
     +-	 * because "A && !B || !B == !B" for all boolean values of A & B.
      -	 */
     --	is_bare_repository_cfg = is_bare_repository() || !work_tree;
      -
      -	/*
      -	 * We would have created the above under user's umask -- under
     @@ builtin/init-db.c
      -	int exist_ok = flags & INIT_DB_EXIST_OK;
      -	char *original_git_dir = real_pathdup(git_dir, 1);
      -	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
     +-	int prev_bare_repository;
      -
      -	if (real_git_dir) {
      -		struct stat st;
     @@ builtin/init-db.c
      -
      -	safe_create_dir(git_dir, 0);
      -
     +-	prev_bare_repository = is_bare_repository();
     +-
      -	/* Check to see if the repository version is right.
      -	 * Note that a newly created repository does not have
      -	 * config file, so this will not fail.  What we are catching
     @@ builtin/init-db.c
      -
      -	reinit = create_default_files(template_dir, original_git_dir,
      -				      initial_branch, &repo_fmt,
     +-				      prev_bare_repository,
      -				      init_shared_repository,
      -				      flags & INIT_DB_QUIET);
      -	if (reinit && initial_branch)
     @@ setup.c: int daemonize(void)
      +				const char *original_git_dir,
      +				const char *initial_branch,
      +				const struct repository_format *fmt,
     ++				int prev_bare_repository,
      +				int init_shared_repository,
      +				int quiet)
      +{
     @@ setup.c: int daemonize(void)
      +	/*
      +	 * TODO: heed core.bare from config file in templates if no
      +	 *       command-line override given
     ++	 */
     ++	is_bare_repository_cfg = prev_bare_repository || !work_tree;
     ++	/* TODO (continued):
     ++	 *
     ++	 * Unfortunately, the line above is equivalent to
     ++	 *    is_bare_repository_cfg = !work_tree;
     ++	 * which ignores the config entirely even if no `--[no-]bare`
     ++	 * command line option was present.
      +	 *
     -+	 * Unfortunately, this location in the code is far too late to
     -+	 * allow this to happen; both builtin/init.db and
     -+	 * builtin/clone.c setup the new repository and call
     -+	 * set_git_work_tree() before this point.  (Note that both do
     -+	 * that repository setup before calling init_db(), which in
     -+	 * turn calls create_default_files().)  Fixing it would
     -+	 * require too much refactoring, and no one seems to have
     -+	 * wanted this behavior in 15+ years, so we'll continue
     -+	 * ignoring the config for now and just override
     -+	 * is_bare_repository_cfg unconditionally.
     ++	 * To see why, note that before this function, there was this call:
     ++	 *    prev_bare_repository = is_bare_repository()
     ++	 * expanding the right hande side:
     ++	 *                 = is_bare_repository_cfg && !get_git_work_tree()
     ++	 *                 = is_bare_repository_cfg && !work_tree
     ++	 * note that the last simplification above is valid because nothing
     ++	 * calls repo_init() or set_git_work_tree() between any of the
     ++	 * relevant calls in the code, and thus the !get_git_work_tree()
     ++	 * calls will return the same result each time.  So, what we are
     ++	 * interested in computing is the right hand side of the line of
     ++	 * code just above this comment:
     ++	 *     prev_bare_repository || !work_tree
     ++	 *        = is_bare_repository_cfg && !work_tree || !work_tree
     ++	 *        = !work_tree
     ++	 * because "A && !B || !B == !B" for all boolean values of A & B.
      +	 */
     -+	is_bare_repository_cfg = is_bare_repository() || !work_tree;
      +
      +	/*
      +	 * We would have created the above under user's umask -- under
     @@ setup.c: int daemonize(void)
      +	int exist_ok = flags & INIT_DB_EXIST_OK;
      +	char *original_git_dir = real_pathdup(git_dir, 1);
      +	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
     ++	int prev_bare_repository;
      +
      +	if (real_git_dir) {
      +		struct stat st;
     @@ setup.c: int daemonize(void)
      +
      +	safe_create_dir(git_dir, 0);
      +
     ++	prev_bare_repository = is_bare_repository();
     ++
      +	/* Check to see if the repository version is right.
      +	 * Note that a newly created repository does not have
      +	 * config file, so this will not fail.  What we are catching
     @@ setup.c: int daemonize(void)
      +
      +	reinit = create_default_files(template_dir, original_git_dir,
      +				      initial_branch, &repo_fmt,
     ++				      prev_bare_repository,
      +				      init_shared_repository,
      +				      flags & INIT_DB_QUIET);
      +	if (reinit && initial_branch)
  4:  d5a5b511f6d =  5:  ced75f46444 read-cache: move shared commit and ls-files code
  5:  30989571ac3 =  6:  13d6dd1095c add: modify add_files_to_cache() to avoid globals
  6:  0205f716a5a =  7:  63058d44595 read-cache: move shared add/checkout/commit code
  7:  e7b5b66c10c =  8:  39e5f6ca470 statinfo: move stat_{data,validity} functions from cache/read-cache
  8:  7892ef891ed =  9:  f56714080b1 run-command.h: move declarations for run-command.c from cache.h
  9:  fe50a0d0e77 = 10:  7d48dbfe0aa name-hash.h: move declarations for name-hash.c from cache.h
 10:  a4998e88790 = 11:  f46aa5e73a1 sparse-index.h: move declarations for sparse-index.c from cache.h
 11:  c39e4bdbfaf = 12:  b16c4d3429e preload-index.h: move declarations for preload-index.c from elsewhere
 12:  41baa22c5d6 = 13:  c8f873d71f5 diff.h: move declaration for global in diff.c from cache.h
 13:  d56fc27c94b = 14:  77c3c5918b8 merge.h: move declarations for merge.c from cache.h
 14:  59dafa5eaa6 = 15:  abfb127b812 repository.h: move declaration of the_index from cache.h
 15:  986a056e580 = 16:  41183b7baed read-cache*.h: move declarations for read-cache.c functions from cache.h
 16:  2cf46f2fc8e = 17:  8f021be54e0 cache.h: remove this no-longer-used header
 17:  1786a64367a = 18:  ea21839a95a log-tree: replace include of revision.h with simple forward declaration
 18:  dfd1794592a = 19:  bd70d3fe730 repository: remove unnecessary include of path.h
 19:  69c07c6ebed = 20:  a438cfbb095 diff.h: remove unnecessary include of oidset.h
 20:  5e6ecb0256d = 21:  b8f302184fa list-objects-filter-options.h: remove unneccessary include
 21:  f0e69592be8 = 22:  1d3d33a843b builtin.h: remove unneccessary includes
 22:  7a9deb749e8 = 23:  7849fea5fa4 git-compat-util.h: remove unneccessary include of wildmatch.h
  -:  ----------- > 24:  97d04efde7b merge-ll: rename from ll-merge
  -:  ----------- > 25:  e0bfeb98556 khash: name the structs that khash declares
 23:  44a4027b240 ! 26:  41d48379b3d hash-ll, hashmap: move oidhash() to hash-ll
     @@ khash.h
       #include "hash.h"
       
       #define AC_VERSION_KHASH_H "0.2.8"
     -@@ khash.h: static inline khint_t __ac_X31_hash_string(const char *s)
     - static const double __ac_HASH_UPPER = 0.77;
     - 
     - #define __KHASH_TYPE(name, khkey_t, khval_t) \
     --	typedef struct { \
     -+	typedef struct kh_##name { \
     - 		khint_t n_buckets, size, n_occupied, upper_bound; \
     - 		khint32_t *flags; \
     - 		khkey_t *keys; \
      
       ## list-objects-filter.c ##
      @@
     @@ match-trees.c
      
       ## merge-blobs.c ##
      @@
     - #include "ll-merge.h"
     + #include "merge-ll.h"
       #include "blob.h"
       #include "merge-blobs.h"
      -#include "object-store.h"
 24:  152fb353475 = 27:  bbe64fccd52 fsmonitor-ll.h: split this header out of fsmonitor.h

-- 
gitgitgadget

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

* [PATCH v2 01/27] init-db: document existing bug with core.bare in template config
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12 21:34     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 02/27] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
                     ` (26 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

The comments in create_default_files() talks about reading config from
the config file in the specified `--templates` directory, which leads to
the question of whether core.bare could be set in such a config file and
thus whether the code is doing the right thing.  It turns out, that it
doesn't; it unconditionally ignores core.bare in the config file in any
--templates directory.  It is not clear to me that fixing it can be done
within this function; it seems to occur too late:
  * create_default_files() is called by init_db()
  * init_db() is called by both builtin/{clone.c,init-db.c}
  * both callers of init_db() call set_git_work_tree() before init_db()
and in order to actual affect whether a repository is bear, we'd need to
somewhere reset these values, not just the is_bare_repository_cfg
setting.

I do not want to open this can of worms at this time; I'm trying to
clean up some headers, for which I need to move some functions, for
which I need to clean up some globals, and that's far enough down the
rabbit hole.  So, simply document the issue with a careful TODO comment
and a few testcases.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c        | 29 ++++++++++++++++++++++++++++-
 t/t1301-shared-repo.sh   | 22 ++++++++++++++++++++++
 t/t5606-clone-options.sh | 10 ++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index aef40361052..715e94befa0 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -231,9 +231,36 @@ static int create_default_files(const char *template_path,
 	 * We must make sure command-line options continue to override any
 	 * values we might have just re-read from the config.
 	 */
-	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
 	if (init_shared_repository != -1)
 		set_shared_repository(init_shared_repository);
+	/*
+	 * TODO: heed core.bare from config file in templates if no
+	 *       command-line override given
+	 */
+	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
+	/* TODO (continued):
+	 *
+	 * Unfortunately, the line above is equivalent to
+	 *    is_bare_repository_cfg = !work_tree;
+	 * which ignores the config entirely even if no `--[no-]bare`
+	 * command line option was present.
+	 *
+	 * To see why, note that before this function, there was this call:
+	 *    init_is_bare_repository = is_bare_repository()
+	 * expanding the right hande side:
+	 *                 = is_bare_repository_cfg && !get_git_work_tree()
+	 *                 = is_bare_repository_cfg && !work_tree
+	 * note that the last simplification above is valid because nothing
+	 * calls repo_init() or set_git_work_tree() between any of the
+	 * relevant calls in the code, and thus the !get_git_work_tree()
+	 * calls will return the same result each time.  So, what we are
+	 * interested in computing is the right hand side of the line of
+	 * code just above this comment:
+	 *     init_is_bare_repository || !work_tree
+	 *        = is_bare_repository_cfg && !work_tree || !work_tree
+	 *        = !work_tree
+	 * because "A && !B || !B == !B" for all boolean values of A & B.
+	 */
 
 	/*
 	 * We would have created the above under user's umask -- under
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index 1b6437ec079..c02fd64793b 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -52,6 +52,28 @@ test_expect_success 'shared=all' '
 	test 2 = $(git config core.sharedrepository)
 '
 
+test_expect_failure 'template can set core.bare' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "rm -rf templates" &&
+	test_config core.bare true &&
+	umask 0022 &&
+	mkdir -p templates/ &&
+	cp .git/config templates/config &&
+	git init --template=templates subdir &&
+	test_path_exists subdir/HEAD
+'
+
+test_expect_success 'template can set core.bare but overridden by command line' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "rm -rf templates" &&
+	test_config core.bare true &&
+	umask 0022 &&
+	mkdir -p templates/ &&
+	cp .git/config templates/config &&
+	git init --no-bare --template=templates subdir &&
+	test_path_exists subdir/.git/HEAD
+'
+
 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
 	: > a1 &&
 	git add a1 &&
diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh
index 27f9f776389..5890319b97b 100755
--- a/t/t5606-clone-options.sh
+++ b/t/t5606-clone-options.sh
@@ -120,6 +120,16 @@ test_expect_success 'prefers -c config over --template config' '
 
 '
 
+test_expect_failure 'prefers --template config even for core.bare' '
+
+	template="$TRASH_DIRECTORY/template-with-bare-config" &&
+	mkdir "$template" &&
+	git config --file "$template/config" core.bare true &&
+	git clone "--template=$template" parent clone-bare-config &&
+	test "$(git -C clone-bare-config config --local core.bare)" = "true" &&
+	test_path_is_file clone-bare-config/HEAD
+'
+
 test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
 
 	test_config_global clone.defaultRemoteName from_config &&
-- 
gitgitgadget


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

* [PATCH v2 02/27] init-db: remove unnecessary global variable
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 01/27] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12 20:20     ` Glen Choo
  2023-05-12  7:04   ` [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
                     ` (25 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

This commit was prompted by a desire to move the functions which
builtin/init-db.c and builtin/clone.c share out of the former file and
into setup.c.  One issue that made it difficult was the
init_is_bare_repository global variable.

init_is_bare_repository's sole use in life it to cache a value in
init_db(), and then be used in create_default_files().  This is a bit
odd since init_db() directly calls create_default_files(), and is the
only caller of that function.  Convert the global to a simple function
parameter instead.

(Of course, this doesn't fix the fact that this value is then ignored by
create_default_files(), as noted in a big TODO comment in that function,
but it at least includes no behavioral change other than getting rid of
a very questionable global variable.)

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 715e94befa0..381801b9637 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,7 +31,6 @@
 
 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
 
-static int init_is_bare_repository = 0;
 static int init_shared_repository = -1;
 
 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
@@ -199,6 +198,7 @@ static int create_default_files(const char *template_path,
 				const char *original_git_dir,
 				const char *initial_branch,
 				const struct repository_format *fmt,
+				int prev_bare_repository,
 				int quiet)
 {
 	struct stat st1;
@@ -237,7 +237,7 @@ static int create_default_files(const char *template_path,
 	 * TODO: heed core.bare from config file in templates if no
 	 *       command-line override given
 	 */
-	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
+	is_bare_repository_cfg = prev_bare_repository || !work_tree;
 	/* TODO (continued):
 	 *
 	 * Unfortunately, the line above is equivalent to
@@ -246,7 +246,7 @@ static int create_default_files(const char *template_path,
 	 * command line option was present.
 	 *
 	 * To see why, note that before this function, there was this call:
-	 *    init_is_bare_repository = is_bare_repository()
+	 *    prev_bare_repository = is_bare_repository()
 	 * expanding the right hande side:
 	 *                 = is_bare_repository_cfg && !get_git_work_tree()
 	 *                 = is_bare_repository_cfg && !work_tree
@@ -256,7 +256,7 @@ static int create_default_files(const char *template_path,
 	 * calls will return the same result each time.  So, what we are
 	 * interested in computing is the right hand side of the line of
 	 * code just above this comment:
-	 *     init_is_bare_repository || !work_tree
+	 *     prev_bare_repository || !work_tree
 	 *        = is_bare_repository_cfg && !work_tree || !work_tree
 	 *        = !work_tree
 	 * because "A && !B || !B == !B" for all boolean values of A & B.
@@ -424,6 +424,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	int exist_ok = flags & INIT_DB_EXIST_OK;
 	char *original_git_dir = real_pathdup(git_dir, 1);
 	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+	int prev_bare_repository;
 
 	if (real_git_dir) {
 		struct stat st;
@@ -449,7 +450,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
 	safe_create_dir(git_dir, 0);
 
-	init_is_bare_repository = is_bare_repository();
+	prev_bare_repository = is_bare_repository();
 
 	/* Check to see if the repository version is right.
 	 * Note that a newly created repository does not have
@@ -462,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
 	reinit = create_default_files(template_dir, original_git_dir,
 				      initial_branch, &repo_fmt,
+				      prev_bare_repository,
 				      flags & INIT_DB_QUIET);
 	if (reinit && initial_branch)
 		warning(_("re-init: ignored --initial-branch=%s"),
-- 
gitgitgadget


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

* [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 01/27] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 02/27] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12 21:28     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 04/27] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
                     ` (24 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Much like the former commit, this commit was prompted by a desire to
move the functions which builtin/init-db.c and builtin/clone.c share out
of the former file and into setup.c.  A secondary issue that made it
difficult was the init_shared_repository global variable; replace it
with a simple parameter that is passed to the relevant functions.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/clone.c   | 3 ++-
 builtin/init-db.c | 9 +++++----
 cache.h           | 3 ++-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 15f9912b4ca..cc34c194f5e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	int submodule_progress;
 	int filter_submodules = 0;
 	int hash_algo;
+	const int do_not_override_repo_unix_permissions = -1;
 
 	struct transport_ls_refs_options transport_ls_refs_options =
 		TRANSPORT_LS_REFS_OPTIONS_INIT;
@@ -1097,7 +1098,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	}
 
 	init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
-		INIT_DB_QUIET);
+		do_not_override_repo_unix_permissions, INIT_DB_QUIET);
 
 	if (real_git_dir) {
 		free((char *)git_dir);
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 381801b9637..e9bbfa1e4ff 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,8 +31,6 @@
 
 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
 
-static int init_shared_repository = -1;
-
 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
 			     DIR *dir)
 {
@@ -199,6 +197,7 @@ static int create_default_files(const char *template_path,
 				const char *initial_branch,
 				const struct repository_format *fmt,
 				int prev_bare_repository,
+				int init_shared_repository,
 				int quiet)
 {
 	struct stat st1;
@@ -418,7 +417,7 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
 
 int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *template_dir, int hash, const char *initial_branch,
-	    unsigned int flags)
+	    int init_shared_repository, unsigned int flags)
 {
 	int reinit;
 	int exist_ok = flags & INIT_DB_EXIST_OK;
@@ -464,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	reinit = create_default_files(template_dir, original_git_dir,
 				      initial_branch, &repo_fmt,
 				      prev_bare_repository,
+				      init_shared_repository,
 				      flags & INIT_DB_QUIET);
 	if (reinit && initial_branch)
 		warning(_("re-init: ignored --initial-branch=%s"),
@@ -575,6 +575,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 	const char *object_format = NULL;
 	const char *initial_branch = NULL;
 	int hash_algo = GIT_HASH_UNKNOWN;
+	int init_shared_repository = -1;
 	const struct option init_db_options[] = {
 		OPT_STRING(0, "template", &template_dir, N_("template-directory"),
 				N_("directory from which templates will be used")),
@@ -732,5 +733,5 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 
 	flags |= INIT_DB_EXIST_OK;
 	return init_db(git_dir, real_git_dir, template_dir, hash_algo,
-		       initial_branch, flags);
+		       initial_branch, init_shared_repository, flags);
 }
diff --git a/cache.h b/cache.h
index bdedb87e83b..2bc1cd77d9b 100644
--- a/cache.h
+++ b/cache.h
@@ -327,7 +327,8 @@ extern struct index_state the_index;
 
 int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *template_dir, int hash_algo,
-	    const char *initial_branch, unsigned int flags);
+	    const char *initial_branch, int init_shared_repository,
+	    unsigned int flags);
 void initialize_repository_version(int hash_algo, int reinit);
 
 /* Initialize and use the cache information */
-- 
gitgitgadget


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

* [PATCH v2 04/27] setup: adopt shared init-db & clone code
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (2 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 05/27] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
                     ` (23 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

The functions init_db() and initialize_repository_version() were shared
by builtin/init-db.c and builtin/clone.c, and declared in cache.h.

Move these functions, plus their several helpers only used by these
functions, to setup.[ch].

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c | 496 ----------------------------------------------
 cache.h           |   9 -
 setup.c           | 496 ++++++++++++++++++++++++++++++++++++++++++++++
 setup.h           |   9 +
 4 files changed, 505 insertions(+), 505 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index e9bbfa1e4ff..feb019a9dea 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -6,511 +6,15 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
-#include "copy.h"
 #include "environment.h"
 #include "gettext.h"
-#include "refs.h"
 #include "builtin.h"
-#include "exec-cmd.h"
 #include "object-file.h"
 #include "parse-options.h"
 #include "path.h"
 #include "setup.h"
-#include "worktree.h"
 #include "wrapper.h"
 
-#ifndef DEFAULT_GIT_TEMPLATE_DIR
-#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
-#endif
-
-#ifdef NO_TRUSTABLE_FILEMODE
-#define TEST_FILEMODE 0
-#else
-#define TEST_FILEMODE 1
-#endif
-
-#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
-
-static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
-			     DIR *dir)
-{
-	size_t path_baselen = path->len;
-	size_t template_baselen = template_path->len;
-	struct dirent *de;
-
-	/* Note: if ".git/hooks" file exists in the repository being
-	 * re-initialized, /etc/core-git/templates/hooks/update would
-	 * cause "git init" to fail here.  I think this is sane but
-	 * it means that the set of templates we ship by default, along
-	 * with the way the namespace under .git/ is organized, should
-	 * be really carefully chosen.
-	 */
-	safe_create_dir(path->buf, 1);
-	while ((de = readdir(dir)) != NULL) {
-		struct stat st_git, st_template;
-		int exists = 0;
-
-		strbuf_setlen(path, path_baselen);
-		strbuf_setlen(template_path, template_baselen);
-
-		if (de->d_name[0] == '.')
-			continue;
-		strbuf_addstr(path, de->d_name);
-		strbuf_addstr(template_path, de->d_name);
-		if (lstat(path->buf, &st_git)) {
-			if (errno != ENOENT)
-				die_errno(_("cannot stat '%s'"), path->buf);
-		}
-		else
-			exists = 1;
-
-		if (lstat(template_path->buf, &st_template))
-			die_errno(_("cannot stat template '%s'"), template_path->buf);
-
-		if (S_ISDIR(st_template.st_mode)) {
-			DIR *subdir = opendir(template_path->buf);
-			if (!subdir)
-				die_errno(_("cannot opendir '%s'"), template_path->buf);
-			strbuf_addch(path, '/');
-			strbuf_addch(template_path, '/');
-			copy_templates_1(path, template_path, subdir);
-			closedir(subdir);
-		}
-		else if (exists)
-			continue;
-		else if (S_ISLNK(st_template.st_mode)) {
-			struct strbuf lnk = STRBUF_INIT;
-			if (strbuf_readlink(&lnk, template_path->buf,
-					    st_template.st_size) < 0)
-				die_errno(_("cannot readlink '%s'"), template_path->buf);
-			if (symlink(lnk.buf, path->buf))
-				die_errno(_("cannot symlink '%s' '%s'"),
-					  lnk.buf, path->buf);
-			strbuf_release(&lnk);
-		}
-		else if (S_ISREG(st_template.st_mode)) {
-			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
-				die_errno(_("cannot copy '%s' to '%s'"),
-					  template_path->buf, path->buf);
-		}
-		else
-			error(_("ignoring template %s"), template_path->buf);
-	}
-}
-
-static void copy_templates(const char *template_dir, const char *init_template_dir)
-{
-	struct strbuf path = STRBUF_INIT;
-	struct strbuf template_path = STRBUF_INIT;
-	size_t template_len;
-	struct repository_format template_format = REPOSITORY_FORMAT_INIT;
-	struct strbuf err = STRBUF_INIT;
-	DIR *dir;
-	char *to_free = NULL;
-
-	if (!template_dir)
-		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
-	if (!template_dir)
-		template_dir = init_template_dir;
-	if (!template_dir)
-		template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
-	if (!template_dir[0]) {
-		free(to_free);
-		return;
-	}
-
-	strbuf_addstr(&template_path, template_dir);
-	strbuf_complete(&template_path, '/');
-	template_len = template_path.len;
-
-	dir = opendir(template_path.buf);
-	if (!dir) {
-		warning(_("templates not found in %s"), template_dir);
-		goto free_return;
-	}
-
-	/* Make sure that template is from the correct vintage */
-	strbuf_addstr(&template_path, "config");
-	read_repository_format(&template_format, template_path.buf);
-	strbuf_setlen(&template_path, template_len);
-
-	/*
-	 * No mention of version at all is OK, but anything else should be
-	 * verified.
-	 */
-	if (template_format.version >= 0 &&
-	    verify_repository_format(&template_format, &err) < 0) {
-		warning(_("not copying templates from '%s': %s"),
-			  template_dir, err.buf);
-		strbuf_release(&err);
-		goto close_free_return;
-	}
-
-	strbuf_addstr(&path, get_git_common_dir());
-	strbuf_complete(&path, '/');
-	copy_templates_1(&path, &template_path, dir);
-close_free_return:
-	closedir(dir);
-free_return:
-	free(to_free);
-	strbuf_release(&path);
-	strbuf_release(&template_path);
-	clear_repository_format(&template_format);
-}
-
-/*
- * If the git_dir is not directly inside the working tree, then git will not
- * find it by default, and we need to set the worktree explicitly.
- */
-static int needs_work_tree_config(const char *git_dir, const char *work_tree)
-{
-	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
-		return 0;
-	if (skip_prefix(git_dir, work_tree, &git_dir) &&
-	    !strcmp(git_dir, "/.git"))
-		return 0;
-	return 1;
-}
-
-void initialize_repository_version(int hash_algo, int reinit)
-{
-	char repo_version_string[10];
-	int repo_version = GIT_REPO_VERSION;
-
-	if (hash_algo != GIT_HASH_SHA1)
-		repo_version = GIT_REPO_VERSION_READ;
-
-	/* This forces creation of new config file */
-	xsnprintf(repo_version_string, sizeof(repo_version_string),
-		  "%d", repo_version);
-	git_config_set("core.repositoryformatversion", repo_version_string);
-
-	if (hash_algo != GIT_HASH_SHA1)
-		git_config_set("extensions.objectformat",
-			       hash_algos[hash_algo].name);
-	else if (reinit)
-		git_config_set_gently("extensions.objectformat", NULL);
-}
-
-static int create_default_files(const char *template_path,
-				const char *original_git_dir,
-				const char *initial_branch,
-				const struct repository_format *fmt,
-				int prev_bare_repository,
-				int init_shared_repository,
-				int quiet)
-{
-	struct stat st1;
-	struct strbuf buf = STRBUF_INIT;
-	char *path;
-	char junk[2];
-	int reinit;
-	int filemode;
-	struct strbuf err = STRBUF_INIT;
-	const char *init_template_dir = NULL;
-	const char *work_tree = get_git_work_tree();
-
-	/*
-	 * First copy the templates -- we might have the default
-	 * config file there, in which case we would want to read
-	 * from it after installing.
-	 *
-	 * Before reading that config, we also need to clear out any cached
-	 * values (since we've just potentially changed what's available on
-	 * disk).
-	 */
-	git_config_get_pathname("init.templatedir", &init_template_dir);
-	copy_templates(template_path, init_template_dir);
-	free((char *)init_template_dir);
-	git_config_clear();
-	reset_shared_repository();
-	git_config(git_default_config, NULL);
-
-	/*
-	 * We must make sure command-line options continue to override any
-	 * values we might have just re-read from the config.
-	 */
-	if (init_shared_repository != -1)
-		set_shared_repository(init_shared_repository);
-	/*
-	 * TODO: heed core.bare from config file in templates if no
-	 *       command-line override given
-	 */
-	is_bare_repository_cfg = prev_bare_repository || !work_tree;
-	/* TODO (continued):
-	 *
-	 * Unfortunately, the line above is equivalent to
-	 *    is_bare_repository_cfg = !work_tree;
-	 * which ignores the config entirely even if no `--[no-]bare`
-	 * command line option was present.
-	 *
-	 * To see why, note that before this function, there was this call:
-	 *    prev_bare_repository = is_bare_repository()
-	 * expanding the right hande side:
-	 *                 = is_bare_repository_cfg && !get_git_work_tree()
-	 *                 = is_bare_repository_cfg && !work_tree
-	 * note that the last simplification above is valid because nothing
-	 * calls repo_init() or set_git_work_tree() between any of the
-	 * relevant calls in the code, and thus the !get_git_work_tree()
-	 * calls will return the same result each time.  So, what we are
-	 * interested in computing is the right hand side of the line of
-	 * code just above this comment:
-	 *     prev_bare_repository || !work_tree
-	 *        = is_bare_repository_cfg && !work_tree || !work_tree
-	 *        = !work_tree
-	 * because "A && !B || !B == !B" for all boolean values of A & B.
-	 */
-
-	/*
-	 * We would have created the above under user's umask -- under
-	 * shared-repository settings, we would need to fix them up.
-	 */
-	if (get_shared_repository()) {
-		adjust_shared_perm(get_git_dir());
-	}
-
-	/*
-	 * We need to create a "refs" dir in any case so that older
-	 * versions of git can tell that this is a repository.
-	 */
-	safe_create_dir(git_path("refs"), 1);
-	adjust_shared_perm(git_path("refs"));
-
-	if (refs_init_db(&err))
-		die("failed to set up refs db: %s", err.buf);
-
-	/*
-	 * Point the HEAD symref to the initial branch with if HEAD does
-	 * not yet exist.
-	 */
-	path = git_path_buf(&buf, "HEAD");
-	reinit = (!access(path, R_OK)
-		  || readlink(path, junk, sizeof(junk)-1) != -1);
-	if (!reinit) {
-		char *ref;
-
-		if (!initial_branch)
-			initial_branch = git_default_branch_name(quiet);
-
-		ref = xstrfmt("refs/heads/%s", initial_branch);
-		if (check_refname_format(ref, 0) < 0)
-			die(_("invalid initial branch name: '%s'"),
-			    initial_branch);
-
-		if (create_symref("HEAD", ref, NULL) < 0)
-			exit(1);
-		free(ref);
-	}
-
-	initialize_repository_version(fmt->hash_algo, 0);
-
-	/* Check filemode trustability */
-	path = git_path_buf(&buf, "config");
-	filemode = TEST_FILEMODE;
-	if (TEST_FILEMODE && !lstat(path, &st1)) {
-		struct stat st2;
-		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
-				!lstat(path, &st2) &&
-				st1.st_mode != st2.st_mode &&
-				!chmod(path, st1.st_mode));
-		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
-			filemode = 0;
-	}
-	git_config_set("core.filemode", filemode ? "true" : "false");
-
-	if (is_bare_repository())
-		git_config_set("core.bare", "true");
-	else {
-		git_config_set("core.bare", "false");
-		/* allow template config file to override the default */
-		if (log_all_ref_updates == LOG_REFS_UNSET)
-			git_config_set("core.logallrefupdates", "true");
-		if (needs_work_tree_config(original_git_dir, work_tree))
-			git_config_set("core.worktree", work_tree);
-	}
-
-	if (!reinit) {
-		/* Check if symlink is supported in the work tree */
-		path = git_path_buf(&buf, "tXXXXXX");
-		if (!close(xmkstemp(path)) &&
-		    !unlink(path) &&
-		    !symlink("testing", path) &&
-		    !lstat(path, &st1) &&
-		    S_ISLNK(st1.st_mode))
-			unlink(path); /* good */
-		else
-			git_config_set("core.symlinks", "false");
-
-		/* Check if the filesystem is case-insensitive */
-		path = git_path_buf(&buf, "CoNfIg");
-		if (!access(path, F_OK))
-			git_config_set("core.ignorecase", "true");
-		probe_utf8_pathname_composition();
-	}
-
-	strbuf_release(&buf);
-	return reinit;
-}
-
-static void create_object_directory(void)
-{
-	struct strbuf path = STRBUF_INIT;
-	size_t baselen;
-
-	strbuf_addstr(&path, get_object_directory());
-	baselen = path.len;
-
-	safe_create_dir(path.buf, 1);
-
-	strbuf_setlen(&path, baselen);
-	strbuf_addstr(&path, "/pack");
-	safe_create_dir(path.buf, 1);
-
-	strbuf_setlen(&path, baselen);
-	strbuf_addstr(&path, "/info");
-	safe_create_dir(path.buf, 1);
-
-	strbuf_release(&path);
-}
-
-static void separate_git_dir(const char *git_dir, const char *git_link)
-{
-	struct stat st;
-
-	if (!stat(git_link, &st)) {
-		const char *src;
-
-		if (S_ISREG(st.st_mode))
-			src = read_gitfile(git_link);
-		else if (S_ISDIR(st.st_mode))
-			src = git_link;
-		else
-			die(_("unable to handle file type %d"), (int)st.st_mode);
-
-		if (rename(src, git_dir))
-			die_errno(_("unable to move %s to %s"), src, git_dir);
-		repair_worktrees(NULL, NULL);
-	}
-
-	write_file(git_link, "gitdir: %s", git_dir);
-}
-
-static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
-{
-	const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
-	/*
-	 * If we already have an initialized repo, don't allow the user to
-	 * specify a different algorithm, as that could cause corruption.
-	 * Otherwise, if the user has specified one on the command line, use it.
-	 */
-	if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
-		die(_("attempt to reinitialize repository with different hash"));
-	else if (hash != GIT_HASH_UNKNOWN)
-		repo_fmt->hash_algo = hash;
-	else if (env) {
-		int env_algo = hash_algo_by_name(env);
-		if (env_algo == GIT_HASH_UNKNOWN)
-			die(_("unknown hash algorithm '%s'"), env);
-		repo_fmt->hash_algo = env_algo;
-	}
-}
-
-int init_db(const char *git_dir, const char *real_git_dir,
-	    const char *template_dir, int hash, const char *initial_branch,
-	    int init_shared_repository, unsigned int flags)
-{
-	int reinit;
-	int exist_ok = flags & INIT_DB_EXIST_OK;
-	char *original_git_dir = real_pathdup(git_dir, 1);
-	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
-	int prev_bare_repository;
-
-	if (real_git_dir) {
-		struct stat st;
-
-		if (!exist_ok && !stat(git_dir, &st))
-			die(_("%s already exists"), git_dir);
-
-		if (!exist_ok && !stat(real_git_dir, &st))
-			die(_("%s already exists"), real_git_dir);
-
-		set_git_dir(real_git_dir, 1);
-		git_dir = get_git_dir();
-		separate_git_dir(git_dir, original_git_dir);
-	}
-	else {
-		set_git_dir(git_dir, 1);
-		git_dir = get_git_dir();
-	}
-	startup_info->have_repository = 1;
-
-	/* Ensure `core.hidedotfiles` is processed */
-	git_config(platform_core_config, NULL);
-
-	safe_create_dir(git_dir, 0);
-
-	prev_bare_repository = is_bare_repository();
-
-	/* Check to see if the repository version is right.
-	 * Note that a newly created repository does not have
-	 * config file, so this will not fail.  What we are catching
-	 * is an attempt to reinitialize new repository with an old tool.
-	 */
-	check_repository_format(&repo_fmt);
-
-	validate_hash_algorithm(&repo_fmt, hash);
-
-	reinit = create_default_files(template_dir, original_git_dir,
-				      initial_branch, &repo_fmt,
-				      prev_bare_repository,
-				      init_shared_repository,
-				      flags & INIT_DB_QUIET);
-	if (reinit && initial_branch)
-		warning(_("re-init: ignored --initial-branch=%s"),
-			initial_branch);
-
-	create_object_directory();
-
-	if (get_shared_repository()) {
-		char buf[10];
-		/* We do not spell "group" and such, so that
-		 * the configuration can be read by older version
-		 * of git. Note, we use octal numbers for new share modes,
-		 * and compatibility values for PERM_GROUP and
-		 * PERM_EVERYBODY.
-		 */
-		if (get_shared_repository() < 0)
-			/* force to the mode value */
-			xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
-		else if (get_shared_repository() == PERM_GROUP)
-			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
-		else if (get_shared_repository() == PERM_EVERYBODY)
-			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
-		else
-			BUG("invalid value for shared_repository");
-		git_config_set("core.sharedrepository", buf);
-		git_config_set("receive.denyNonFastforwards", "true");
-	}
-
-	if (!(flags & INIT_DB_QUIET)) {
-		int len = strlen(git_dir);
-
-		if (reinit)
-			printf(get_shared_repository()
-			       ? _("Reinitialized existing shared Git repository in %s%s\n")
-			       : _("Reinitialized existing Git repository in %s%s\n"),
-			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
-		else
-			printf(get_shared_repository()
-			       ? _("Initialized empty shared Git repository in %s%s\n")
-			       : _("Initialized empty Git repository in %s%s\n"),
-			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
-	}
-
-	free(original_git_dir);
-	return 0;
-}
-
 static int guess_repository_type(const char *git_dir)
 {
 	const char *slash;
diff --git a/cache.h b/cache.h
index 2bc1cd77d9b..8b2eb52f04e 100644
--- a/cache.h
+++ b/cache.h
@@ -322,15 +322,6 @@ void prefetch_cache_entries(const struct index_state *istate,
 extern struct index_state the_index;
 #endif
 
-#define INIT_DB_QUIET 0x0001
-#define INIT_DB_EXIST_OK 0x0002
-
-int init_db(const char *git_dir, const char *real_git_dir,
-	    const char *template_dir, int hash_algo,
-	    const char *initial_branch, int init_shared_repository,
-	    unsigned int flags);
-void initialize_repository_version(int hash_algo, int reinit);
-
 /* Initialize and use the cache information */
 struct lock_file;
 void preload_index(struct index_state *index,
diff --git a/setup.c b/setup.c
index 59abc16ba6d..c47be7ea5ba 100644
--- a/setup.c
+++ b/setup.c
@@ -1,8 +1,11 @@
 #include "git-compat-util.h"
 #include "abspath.h"
+#include "copy.h"
 #include "environment.h"
+#include "exec-cmd.h"
 #include "gettext.h"
 #include "object-name.h"
+#include "refs.h"
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
@@ -12,6 +15,7 @@
 #include "promisor-remote.h"
 #include "quote.h"
 #include "trace2.h"
+#include "worktree.h"
 #include "wrapper.h"
 
 static int inside_git_dir = -1;
@@ -1706,3 +1710,495 @@ int daemonize(void)
 	return 0;
 #endif
 }
+
+#ifndef DEFAULT_GIT_TEMPLATE_DIR
+#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
+#endif
+
+#ifdef NO_TRUSTABLE_FILEMODE
+#define TEST_FILEMODE 0
+#else
+#define TEST_FILEMODE 1
+#endif
+
+#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
+
+static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
+			     DIR *dir)
+{
+	size_t path_baselen = path->len;
+	size_t template_baselen = template_path->len;
+	struct dirent *de;
+
+	/* Note: if ".git/hooks" file exists in the repository being
+	 * re-initialized, /etc/core-git/templates/hooks/update would
+	 * cause "git init" to fail here.  I think this is sane but
+	 * it means that the set of templates we ship by default, along
+	 * with the way the namespace under .git/ is organized, should
+	 * be really carefully chosen.
+	 */
+	safe_create_dir(path->buf, 1);
+	while ((de = readdir(dir)) != NULL) {
+		struct stat st_git, st_template;
+		int exists = 0;
+
+		strbuf_setlen(path, path_baselen);
+		strbuf_setlen(template_path, template_baselen);
+
+		if (de->d_name[0] == '.')
+			continue;
+		strbuf_addstr(path, de->d_name);
+		strbuf_addstr(template_path, de->d_name);
+		if (lstat(path->buf, &st_git)) {
+			if (errno != ENOENT)
+				die_errno(_("cannot stat '%s'"), path->buf);
+		}
+		else
+			exists = 1;
+
+		if (lstat(template_path->buf, &st_template))
+			die_errno(_("cannot stat template '%s'"), template_path->buf);
+
+		if (S_ISDIR(st_template.st_mode)) {
+			DIR *subdir = opendir(template_path->buf);
+			if (!subdir)
+				die_errno(_("cannot opendir '%s'"), template_path->buf);
+			strbuf_addch(path, '/');
+			strbuf_addch(template_path, '/');
+			copy_templates_1(path, template_path, subdir);
+			closedir(subdir);
+		}
+		else if (exists)
+			continue;
+		else if (S_ISLNK(st_template.st_mode)) {
+			struct strbuf lnk = STRBUF_INIT;
+			if (strbuf_readlink(&lnk, template_path->buf,
+					    st_template.st_size) < 0)
+				die_errno(_("cannot readlink '%s'"), template_path->buf);
+			if (symlink(lnk.buf, path->buf))
+				die_errno(_("cannot symlink '%s' '%s'"),
+					  lnk.buf, path->buf);
+			strbuf_release(&lnk);
+		}
+		else if (S_ISREG(st_template.st_mode)) {
+			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
+				die_errno(_("cannot copy '%s' to '%s'"),
+					  template_path->buf, path->buf);
+		}
+		else
+			error(_("ignoring template %s"), template_path->buf);
+	}
+}
+
+static void copy_templates(const char *template_dir, const char *init_template_dir)
+{
+	struct strbuf path = STRBUF_INIT;
+	struct strbuf template_path = STRBUF_INIT;
+	size_t template_len;
+	struct repository_format template_format = REPOSITORY_FORMAT_INIT;
+	struct strbuf err = STRBUF_INIT;
+	DIR *dir;
+	char *to_free = NULL;
+
+	if (!template_dir)
+		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
+	if (!template_dir)
+		template_dir = init_template_dir;
+	if (!template_dir)
+		template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
+	if (!template_dir[0]) {
+		free(to_free);
+		return;
+	}
+
+	strbuf_addstr(&template_path, template_dir);
+	strbuf_complete(&template_path, '/');
+	template_len = template_path.len;
+
+	dir = opendir(template_path.buf);
+	if (!dir) {
+		warning(_("templates not found in %s"), template_dir);
+		goto free_return;
+	}
+
+	/* Make sure that template is from the correct vintage */
+	strbuf_addstr(&template_path, "config");
+	read_repository_format(&template_format, template_path.buf);
+	strbuf_setlen(&template_path, template_len);
+
+	/*
+	 * No mention of version at all is OK, but anything else should be
+	 * verified.
+	 */
+	if (template_format.version >= 0 &&
+	    verify_repository_format(&template_format, &err) < 0) {
+		warning(_("not copying templates from '%s': %s"),
+			  template_dir, err.buf);
+		strbuf_release(&err);
+		goto close_free_return;
+	}
+
+	strbuf_addstr(&path, get_git_common_dir());
+	strbuf_complete(&path, '/');
+	copy_templates_1(&path, &template_path, dir);
+close_free_return:
+	closedir(dir);
+free_return:
+	free(to_free);
+	strbuf_release(&path);
+	strbuf_release(&template_path);
+	clear_repository_format(&template_format);
+}
+
+/*
+ * If the git_dir is not directly inside the working tree, then git will not
+ * find it by default, and we need to set the worktree explicitly.
+ */
+static int needs_work_tree_config(const char *git_dir, const char *work_tree)
+{
+	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
+		return 0;
+	if (skip_prefix(git_dir, work_tree, &git_dir) &&
+	    !strcmp(git_dir, "/.git"))
+		return 0;
+	return 1;
+}
+
+void initialize_repository_version(int hash_algo, int reinit)
+{
+	char repo_version_string[10];
+	int repo_version = GIT_REPO_VERSION;
+
+	if (hash_algo != GIT_HASH_SHA1)
+		repo_version = GIT_REPO_VERSION_READ;
+
+	/* This forces creation of new config file */
+	xsnprintf(repo_version_string, sizeof(repo_version_string),
+		  "%d", repo_version);
+	git_config_set("core.repositoryformatversion", repo_version_string);
+
+	if (hash_algo != GIT_HASH_SHA1)
+		git_config_set("extensions.objectformat",
+			       hash_algos[hash_algo].name);
+	else if (reinit)
+		git_config_set_gently("extensions.objectformat", NULL);
+}
+
+static int create_default_files(const char *template_path,
+				const char *original_git_dir,
+				const char *initial_branch,
+				const struct repository_format *fmt,
+				int prev_bare_repository,
+				int init_shared_repository,
+				int quiet)
+{
+	struct stat st1;
+	struct strbuf buf = STRBUF_INIT;
+	char *path;
+	char junk[2];
+	int reinit;
+	int filemode;
+	struct strbuf err = STRBUF_INIT;
+	const char *init_template_dir = NULL;
+	const char *work_tree = get_git_work_tree();
+
+	/*
+	 * First copy the templates -- we might have the default
+	 * config file there, in which case we would want to read
+	 * from it after installing.
+	 *
+	 * Before reading that config, we also need to clear out any cached
+	 * values (since we've just potentially changed what's available on
+	 * disk).
+	 */
+	git_config_get_pathname("init.templatedir", &init_template_dir);
+	copy_templates(template_path, init_template_dir);
+	free((char *)init_template_dir);
+	git_config_clear();
+	reset_shared_repository();
+	git_config(git_default_config, NULL);
+
+	/*
+	 * We must make sure command-line options continue to override any
+	 * values we might have just re-read from the config.
+	 */
+	if (init_shared_repository != -1)
+		set_shared_repository(init_shared_repository);
+	/*
+	 * TODO: heed core.bare from config file in templates if no
+	 *       command-line override given
+	 */
+	is_bare_repository_cfg = prev_bare_repository || !work_tree;
+	/* TODO (continued):
+	 *
+	 * Unfortunately, the line above is equivalent to
+	 *    is_bare_repository_cfg = !work_tree;
+	 * which ignores the config entirely even if no `--[no-]bare`
+	 * command line option was present.
+	 *
+	 * To see why, note that before this function, there was this call:
+	 *    prev_bare_repository = is_bare_repository()
+	 * expanding the right hande side:
+	 *                 = is_bare_repository_cfg && !get_git_work_tree()
+	 *                 = is_bare_repository_cfg && !work_tree
+	 * note that the last simplification above is valid because nothing
+	 * calls repo_init() or set_git_work_tree() between any of the
+	 * relevant calls in the code, and thus the !get_git_work_tree()
+	 * calls will return the same result each time.  So, what we are
+	 * interested in computing is the right hand side of the line of
+	 * code just above this comment:
+	 *     prev_bare_repository || !work_tree
+	 *        = is_bare_repository_cfg && !work_tree || !work_tree
+	 *        = !work_tree
+	 * because "A && !B || !B == !B" for all boolean values of A & B.
+	 */
+
+	/*
+	 * We would have created the above under user's umask -- under
+	 * shared-repository settings, we would need to fix them up.
+	 */
+	if (get_shared_repository()) {
+		adjust_shared_perm(get_git_dir());
+	}
+
+	/*
+	 * We need to create a "refs" dir in any case so that older
+	 * versions of git can tell that this is a repository.
+	 */
+	safe_create_dir(git_path("refs"), 1);
+	adjust_shared_perm(git_path("refs"));
+
+	if (refs_init_db(&err))
+		die("failed to set up refs db: %s", err.buf);
+
+	/*
+	 * Point the HEAD symref to the initial branch with if HEAD does
+	 * not yet exist.
+	 */
+	path = git_path_buf(&buf, "HEAD");
+	reinit = (!access(path, R_OK)
+		  || readlink(path, junk, sizeof(junk)-1) != -1);
+	if (!reinit) {
+		char *ref;
+
+		if (!initial_branch)
+			initial_branch = git_default_branch_name(quiet);
+
+		ref = xstrfmt("refs/heads/%s", initial_branch);
+		if (check_refname_format(ref, 0) < 0)
+			die(_("invalid initial branch name: '%s'"),
+			    initial_branch);
+
+		if (create_symref("HEAD", ref, NULL) < 0)
+			exit(1);
+		free(ref);
+	}
+
+	initialize_repository_version(fmt->hash_algo, 0);
+
+	/* Check filemode trustability */
+	path = git_path_buf(&buf, "config");
+	filemode = TEST_FILEMODE;
+	if (TEST_FILEMODE && !lstat(path, &st1)) {
+		struct stat st2;
+		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
+				!lstat(path, &st2) &&
+				st1.st_mode != st2.st_mode &&
+				!chmod(path, st1.st_mode));
+		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
+			filemode = 0;
+	}
+	git_config_set("core.filemode", filemode ? "true" : "false");
+
+	if (is_bare_repository())
+		git_config_set("core.bare", "true");
+	else {
+		git_config_set("core.bare", "false");
+		/* allow template config file to override the default */
+		if (log_all_ref_updates == LOG_REFS_UNSET)
+			git_config_set("core.logallrefupdates", "true");
+		if (needs_work_tree_config(original_git_dir, work_tree))
+			git_config_set("core.worktree", work_tree);
+	}
+
+	if (!reinit) {
+		/* Check if symlink is supported in the work tree */
+		path = git_path_buf(&buf, "tXXXXXX");
+		if (!close(xmkstemp(path)) &&
+		    !unlink(path) &&
+		    !symlink("testing", path) &&
+		    !lstat(path, &st1) &&
+		    S_ISLNK(st1.st_mode))
+			unlink(path); /* good */
+		else
+			git_config_set("core.symlinks", "false");
+
+		/* Check if the filesystem is case-insensitive */
+		path = git_path_buf(&buf, "CoNfIg");
+		if (!access(path, F_OK))
+			git_config_set("core.ignorecase", "true");
+		probe_utf8_pathname_composition();
+	}
+
+	strbuf_release(&buf);
+	return reinit;
+}
+
+static void create_object_directory(void)
+{
+	struct strbuf path = STRBUF_INIT;
+	size_t baselen;
+
+	strbuf_addstr(&path, get_object_directory());
+	baselen = path.len;
+
+	safe_create_dir(path.buf, 1);
+
+	strbuf_setlen(&path, baselen);
+	strbuf_addstr(&path, "/pack");
+	safe_create_dir(path.buf, 1);
+
+	strbuf_setlen(&path, baselen);
+	strbuf_addstr(&path, "/info");
+	safe_create_dir(path.buf, 1);
+
+	strbuf_release(&path);
+}
+
+static void separate_git_dir(const char *git_dir, const char *git_link)
+{
+	struct stat st;
+
+	if (!stat(git_link, &st)) {
+		const char *src;
+
+		if (S_ISREG(st.st_mode))
+			src = read_gitfile(git_link);
+		else if (S_ISDIR(st.st_mode))
+			src = git_link;
+		else
+			die(_("unable to handle file type %d"), (int)st.st_mode);
+
+		if (rename(src, git_dir))
+			die_errno(_("unable to move %s to %s"), src, git_dir);
+		repair_worktrees(NULL, NULL);
+	}
+
+	write_file(git_link, "gitdir: %s", git_dir);
+}
+
+static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
+{
+	const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
+	/*
+	 * If we already have an initialized repo, don't allow the user to
+	 * specify a different algorithm, as that could cause corruption.
+	 * Otherwise, if the user has specified one on the command line, use it.
+	 */
+	if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
+		die(_("attempt to reinitialize repository with different hash"));
+	else if (hash != GIT_HASH_UNKNOWN)
+		repo_fmt->hash_algo = hash;
+	else if (env) {
+		int env_algo = hash_algo_by_name(env);
+		if (env_algo == GIT_HASH_UNKNOWN)
+			die(_("unknown hash algorithm '%s'"), env);
+		repo_fmt->hash_algo = env_algo;
+	}
+}
+
+int init_db(const char *git_dir, const char *real_git_dir,
+	    const char *template_dir, int hash, const char *initial_branch,
+	    int init_shared_repository, unsigned int flags)
+{
+	int reinit;
+	int exist_ok = flags & INIT_DB_EXIST_OK;
+	char *original_git_dir = real_pathdup(git_dir, 1);
+	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+	int prev_bare_repository;
+
+	if (real_git_dir) {
+		struct stat st;
+
+		if (!exist_ok && !stat(git_dir, &st))
+			die(_("%s already exists"), git_dir);
+
+		if (!exist_ok && !stat(real_git_dir, &st))
+			die(_("%s already exists"), real_git_dir);
+
+		set_git_dir(real_git_dir, 1);
+		git_dir = get_git_dir();
+		separate_git_dir(git_dir, original_git_dir);
+	}
+	else {
+		set_git_dir(git_dir, 1);
+		git_dir = get_git_dir();
+	}
+	startup_info->have_repository = 1;
+
+	/* Ensure `core.hidedotfiles` is processed */
+	git_config(platform_core_config, NULL);
+
+	safe_create_dir(git_dir, 0);
+
+	prev_bare_repository = is_bare_repository();
+
+	/* Check to see if the repository version is right.
+	 * Note that a newly created repository does not have
+	 * config file, so this will not fail.  What we are catching
+	 * is an attempt to reinitialize new repository with an old tool.
+	 */
+	check_repository_format(&repo_fmt);
+
+	validate_hash_algorithm(&repo_fmt, hash);
+
+	reinit = create_default_files(template_dir, original_git_dir,
+				      initial_branch, &repo_fmt,
+				      prev_bare_repository,
+				      init_shared_repository,
+				      flags & INIT_DB_QUIET);
+	if (reinit && initial_branch)
+		warning(_("re-init: ignored --initial-branch=%s"),
+			initial_branch);
+
+	create_object_directory();
+
+	if (get_shared_repository()) {
+		char buf[10];
+		/* We do not spell "group" and such, so that
+		 * the configuration can be read by older version
+		 * of git. Note, we use octal numbers for new share modes,
+		 * and compatibility values for PERM_GROUP and
+		 * PERM_EVERYBODY.
+		 */
+		if (get_shared_repository() < 0)
+			/* force to the mode value */
+			xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
+		else if (get_shared_repository() == PERM_GROUP)
+			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
+		else if (get_shared_repository() == PERM_EVERYBODY)
+			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
+		else
+			BUG("invalid value for shared_repository");
+		git_config_set("core.sharedrepository", buf);
+		git_config_set("receive.denyNonFastforwards", "true");
+	}
+
+	if (!(flags & INIT_DB_QUIET)) {
+		int len = strlen(git_dir);
+
+		if (reinit)
+			printf(get_shared_repository()
+			       ? _("Reinitialized existing shared Git repository in %s%s\n")
+			       : _("Reinitialized existing Git repository in %s%s\n"),
+			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+		else
+			printf(get_shared_repository()
+			       ? _("Initialized empty shared Git repository in %s%s\n")
+			       : _("Initialized empty Git repository in %s%s\n"),
+			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+	}
+
+	free(original_git_dir);
+	return 0;
+}
diff --git a/setup.h b/setup.h
index 4c1ca9d0c94..58fd2605dd2 100644
--- a/setup.h
+++ b/setup.h
@@ -140,6 +140,15 @@ int verify_repository_format(const struct repository_format *format,
  */
 void check_repository_format(struct repository_format *fmt);
 
+#define INIT_DB_QUIET 0x0001
+#define INIT_DB_EXIST_OK 0x0002
+
+int init_db(const char *git_dir, const char *real_git_dir,
+	    const char *template_dir, int hash_algo,
+	    const char *initial_branch, int init_shared_repository,
+	    unsigned int flags);
+void initialize_repository_version(int hash_algo, int reinit);
+
 /*
  * NOTE NOTE NOTE!!
  *
-- 
gitgitgadget


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

* [PATCH v2 05/27] read-cache: move shared commit and ls-files code
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (3 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 04/27] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12 21:25     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
                     ` (22 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function overlay_tree_on_index(), plus associated helper functions,
were defined in builtin/ls-files.c, but also shared with
builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/ls-files.c | 137 ---------------------------------------------
 read-cache.c       | 137 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 137 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 625f48f0d61..069b28bd484 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -516,143 +516,6 @@ static int get_common_prefix_len(const char *common_prefix)
 	return common_prefix_len;
 }
 
-static int read_one_entry_opt(struct index_state *istate,
-			      const struct object_id *oid,
-			      struct strbuf *base,
-			      const char *pathname,
-			      unsigned mode, int opt)
-{
-	int len;
-	struct cache_entry *ce;
-
-	if (S_ISDIR(mode))
-		return READ_TREE_RECURSIVE;
-
-	len = strlen(pathname);
-	ce = make_empty_cache_entry(istate, base->len + len);
-
-	ce->ce_mode = create_ce_mode(mode);
-	ce->ce_flags = create_ce_flags(1);
-	ce->ce_namelen = base->len + len;
-	memcpy(ce->name, base->buf, base->len);
-	memcpy(ce->name + base->len, pathname, len+1);
-	oidcpy(&ce->oid, oid);
-	return add_index_entry(istate, ce, opt);
-}
-
-static int read_one_entry(const struct object_id *oid, struct strbuf *base,
-			  const char *pathname, unsigned mode,
-			  void *context)
-{
-	struct index_state *istate = context;
-	return read_one_entry_opt(istate, oid, base, pathname,
-				  mode,
-				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
-}
-
-/*
- * This is used when the caller knows there is no existing entries at
- * the stage that will conflict with the entry being added.
- */
-static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
-				const char *pathname, unsigned mode,
-				void *context)
-{
-	struct index_state *istate = context;
-	return read_one_entry_opt(istate, oid, base, pathname,
-				  mode, ADD_CACHE_JUST_APPEND);
-}
-
-/*
- * Read the tree specified with --with-tree option
- * (typically, HEAD) into stage #1 and then
- * squash them down to stage #0.  This is used for
- * --error-unmatch to list and check the path patterns
- * that were given from the command line.  We are not
- * going to write this index out.
- */
-void overlay_tree_on_index(struct index_state *istate,
-			   const char *tree_name, const char *prefix)
-{
-	struct tree *tree;
-	struct object_id oid;
-	struct pathspec pathspec;
-	struct cache_entry *last_stage0 = NULL;
-	int i;
-	read_tree_fn_t fn = NULL;
-	int err;
-
-	if (repo_get_oid(the_repository, tree_name, &oid))
-		die("tree-ish %s not found.", tree_name);
-	tree = parse_tree_indirect(&oid);
-	if (!tree)
-		die("bad tree-ish %s", tree_name);
-
-	/* Hoist the unmerged entries up to stage #3 to make room */
-	/* TODO: audit for interaction with sparse-index. */
-	ensure_full_index(istate);
-	for (i = 0; i < istate->cache_nr; i++) {
-		struct cache_entry *ce = istate->cache[i];
-		if (!ce_stage(ce))
-			continue;
-		ce->ce_flags |= CE_STAGEMASK;
-	}
-
-	if (prefix) {
-		static const char *(matchbuf[1]);
-		matchbuf[0] = NULL;
-		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
-			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
-	} else
-		memset(&pathspec, 0, sizeof(pathspec));
-
-	/*
-	 * See if we have cache entry at the stage.  If so,
-	 * do it the original slow way, otherwise, append and then
-	 * sort at the end.
-	 */
-	for (i = 0; !fn && i < istate->cache_nr; i++) {
-		const struct cache_entry *ce = istate->cache[i];
-		if (ce_stage(ce) == 1)
-			fn = read_one_entry;
-	}
-
-	if (!fn)
-		fn = read_one_entry_quick;
-	err = read_tree(the_repository, tree, &pathspec, fn, istate);
-	clear_pathspec(&pathspec);
-	if (err)
-		die("unable to read tree entries %s", tree_name);
-
-	/*
-	 * Sort the cache entry -- we need to nuke the cache tree, though.
-	 */
-	if (fn == read_one_entry_quick) {
-		cache_tree_free(&istate->cache_tree);
-		QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
-	}
-
-	for (i = 0; i < istate->cache_nr; i++) {
-		struct cache_entry *ce = istate->cache[i];
-		switch (ce_stage(ce)) {
-		case 0:
-			last_stage0 = ce;
-			/* fallthru */
-		default:
-			continue;
-		case 1:
-			/*
-			 * If there is stage #0 entry for this, we do not
-			 * need to show it.  We use CE_UPDATE bit to mark
-			 * such an entry.
-			 */
-			if (last_stage0 &&
-			    !strcmp(last_stage0->name, ce->name))
-				ce->ce_flags |= CE_UPDATE;
-		}
-	}
-}
-
 static const char * const ls_files_usage[] = {
 	N_("git ls-files [<options>] [<file>...]"),
 	NULL
diff --git a/read-cache.c b/read-cache.c
index f4c31a68c85..c0df4586c9b 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3806,3 +3806,140 @@ void prefetch_cache_entries(const struct index_state *istate,
 				   to_fetch.oid, to_fetch.nr);
 	oid_array_clear(&to_fetch);
 }
+
+static int read_one_entry_opt(struct index_state *istate,
+			      const struct object_id *oid,
+			      struct strbuf *base,
+			      const char *pathname,
+			      unsigned mode, int opt)
+{
+	int len;
+	struct cache_entry *ce;
+
+	if (S_ISDIR(mode))
+		return READ_TREE_RECURSIVE;
+
+	len = strlen(pathname);
+	ce = make_empty_cache_entry(istate, base->len + len);
+
+	ce->ce_mode = create_ce_mode(mode);
+	ce->ce_flags = create_ce_flags(1);
+	ce->ce_namelen = base->len + len;
+	memcpy(ce->name, base->buf, base->len);
+	memcpy(ce->name + base->len, pathname, len+1);
+	oidcpy(&ce->oid, oid);
+	return add_index_entry(istate, ce, opt);
+}
+
+static int read_one_entry(const struct object_id *oid, struct strbuf *base,
+			  const char *pathname, unsigned mode,
+			  void *context)
+{
+	struct index_state *istate = context;
+	return read_one_entry_opt(istate, oid, base, pathname,
+				  mode,
+				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
+}
+
+/*
+ * This is used when the caller knows there is no existing entries at
+ * the stage that will conflict with the entry being added.
+ */
+static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
+				const char *pathname, unsigned mode,
+				void *context)
+{
+	struct index_state *istate = context;
+	return read_one_entry_opt(istate, oid, base, pathname,
+				  mode, ADD_CACHE_JUST_APPEND);
+}
+
+/*
+ * Read the tree specified with --with-tree option
+ * (typically, HEAD) into stage #1 and then
+ * squash them down to stage #0.  This is used for
+ * --error-unmatch to list and check the path patterns
+ * that were given from the command line.  We are not
+ * going to write this index out.
+ */
+void overlay_tree_on_index(struct index_state *istate,
+			   const char *tree_name, const char *prefix)
+{
+	struct tree *tree;
+	struct object_id oid;
+	struct pathspec pathspec;
+	struct cache_entry *last_stage0 = NULL;
+	int i;
+	read_tree_fn_t fn = NULL;
+	int err;
+
+	if (repo_get_oid(the_repository, tree_name, &oid))
+		die("tree-ish %s not found.", tree_name);
+	tree = parse_tree_indirect(&oid);
+	if (!tree)
+		die("bad tree-ish %s", tree_name);
+
+	/* Hoist the unmerged entries up to stage #3 to make room */
+	/* TODO: audit for interaction with sparse-index. */
+	ensure_full_index(istate);
+	for (i = 0; i < istate->cache_nr; i++) {
+		struct cache_entry *ce = istate->cache[i];
+		if (!ce_stage(ce))
+			continue;
+		ce->ce_flags |= CE_STAGEMASK;
+	}
+
+	if (prefix) {
+		static const char *(matchbuf[1]);
+		matchbuf[0] = NULL;
+		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
+			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
+	} else
+		memset(&pathspec, 0, sizeof(pathspec));
+
+	/*
+	 * See if we have cache entry at the stage.  If so,
+	 * do it the original slow way, otherwise, append and then
+	 * sort at the end.
+	 */
+	for (i = 0; !fn && i < istate->cache_nr; i++) {
+		const struct cache_entry *ce = istate->cache[i];
+		if (ce_stage(ce) == 1)
+			fn = read_one_entry;
+	}
+
+	if (!fn)
+		fn = read_one_entry_quick;
+	err = read_tree(the_repository, tree, &pathspec, fn, istate);
+	clear_pathspec(&pathspec);
+	if (err)
+		die("unable to read tree entries %s", tree_name);
+
+	/*
+	 * Sort the cache entry -- we need to nuke the cache tree, though.
+	 */
+	if (fn == read_one_entry_quick) {
+		cache_tree_free(&istate->cache_tree);
+		QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
+	}
+
+	for (i = 0; i < istate->cache_nr; i++) {
+		struct cache_entry *ce = istate->cache[i];
+		switch (ce_stage(ce)) {
+		case 0:
+			last_stage0 = ce;
+			/* fallthru */
+		default:
+			continue;
+		case 1:
+			/*
+			 * If there is stage #0 entry for this, we do not
+			 * need to show it.  We use CE_UPDATE bit to mark
+			 * such an entry.
+			 */
+			if (last_stage0 &&
+			    !strcmp(last_stage0->name, ce->name))
+				ce->ce_flags |= CE_UPDATE;
+		}
+	}
+}
-- 
gitgitgadget


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

* [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (4 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 05/27] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-15 21:44     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 07/27] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
                     ` (21 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function add_files_to_cache() is used by all three of builtin/{add,
checkout, commit}.c.  That suggests this is common library code, and
should be moved somewhere else, like read-cache.c.  However, the
function and its helpers made use of two global variables that made
straight code movement difficult:
  * the_index
  * include_sparse
The latter was perhaps more problematic since it was only accessible in
builtin/add.c but was still affecting builtin/checkout.c and
builtin/commit.c without this fact being very clear from the code.  I'm
not sure if the other two callers would want to add a `--sparse` flag
similar to add.c to get non-default behavior, but exposing this
dependence will help if we ever decide we do want to add such a flag.

Modify add_files_to_cache() and its helpers to accept the necessary
arguments instead of relying on globals.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/add.c      | 22 +++++++++++++++-------
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  3 ++-
 cache.h            |  4 +++-
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index 76cc026a68a..a526eff734e 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -37,6 +37,8 @@ static int include_sparse;
 static const char *pathspec_from_file;
 
 struct update_callback_data {
+	struct index_state *index;
+	int include_sparse;
 	int flags;
 	int add_errors;
 };
@@ -100,7 +102,8 @@ static void update_callback(struct diff_queue_struct *q,
 		struct diff_filepair *p = q->queue[i];
 		const char *path = p->one->path;
 
-		if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
+		if (!data->include_sparse &&
+		    !path_in_sparse_checkout(path, data->index))
 			continue;
 
 		switch (fix_unmerged_status(p, data)) {
@@ -108,7 +111,7 @@ static void update_callback(struct diff_queue_struct *q,
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
 		case DIFF_STATUS_TYPE_CHANGED:
-			if (add_file_to_index(&the_index, path,	data->flags)) {
+			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
 				data->add_errors++;
@@ -118,7 +121,7 @@ static void update_callback(struct diff_queue_struct *q,
 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
 				break;
 			if (!(data->flags & ADD_CACHE_PRETEND))
-				remove_file_from_index(&the_index, path);
+				remove_file_from_index(data->index, path);
 			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
 				printf(_("remove '%s'\n"), path);
 			break;
@@ -126,16 +129,19 @@ static void update_callback(struct diff_queue_struct *q,
 	}
 }
 
-int add_files_to_cache(const char *prefix,
-		       const struct pathspec *pathspec, int flags)
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags)
 {
 	struct update_callback_data data;
 	struct rev_info rev;
 
 	memset(&data, 0, sizeof(data));
+	data.index = repo->index;
+	data.include_sparse = include_sparse;
 	data.flags = flags;
 
-	repo_init_revisions(the_repository, &rev, prefix);
+	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
 	if (pathspec)
 		copy_pathspec(&rev.prune_data, pathspec);
@@ -640,7 +646,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (add_renormalize)
 		exit_status |= renormalize_tracked_files(&pathspec, flags);
 	else
-		exit_status |= add_files_to_cache(prefix, &pathspec, flags);
+		exit_status |= add_files_to_cache(the_repository, prefix,
+						  &pathspec, include_sparse,
+						  flags);
 
 	if (add_new_files)
 		exit_status |= add_files(&dir, flags);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 715eeb5048f..d6765c9dbd9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -861,7 +861,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 * entries in the index.
 			 */
 
-			add_files_to_cache(NULL, NULL, 0);
+			add_files_to_cache(the_repository, NULL, NULL, 0, 0);
 			init_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index e67c4be2211..bd634ee6ad1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -447,7 +447,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
 	if (all || (also && pathspec.nr)) {
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
-		add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
+		add_files_to_cache(the_repository, also ? prefix : NULL,
+				   &pathspec, 0, 0);
 		refresh_cache_or_die(refresh_flags);
 		cache_tree_update(&the_index, WRITE_TREE_SILENT);
 		if (write_locked_index(&the_index, &index_lock, 0))
diff --git a/cache.h b/cache.h
index 8b2eb52f04e..02d69c24cd6 100644
--- a/cache.h
+++ b/cache.h
@@ -554,7 +554,9 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
  * return 0 if success, 1 - if addition of a file failed and
  * ADD_FILES_IGNORE_ERRORS was specified in flags
  */
-int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags);
 
 /* diff.c */
 extern int diff_auto_refresh_index;
-- 
gitgitgadget


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

* [PATCH v2 07/27] read-cache: move shared add/checkout/commit code
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (5 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 08/27] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
                     ` (20 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function add_files_to_cache(), plus associated helper functions,
were defined in builtin/add.c, but also shared with builtin/checkout.c
and builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/add.c | 100 -------------------------------------------------
 read-cache.c  | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 100 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index a526eff734e..36ddbb159bf 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -36,13 +36,6 @@ static int pathspec_file_nul;
 static int include_sparse;
 static const char *pathspec_from_file;
 
-struct update_callback_data {
-	struct index_state *index;
-	int include_sparse;
-	int flags;
-	int add_errors;
-};
-
 static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 {
 	int i, ret = 0;
@@ -71,99 +64,6 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 	return ret;
 }
 
-static int fix_unmerged_status(struct diff_filepair *p,
-			       struct update_callback_data *data)
-{
-	if (p->status != DIFF_STATUS_UNMERGED)
-		return p->status;
-	if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
-		/*
-		 * This is not an explicit add request, and the
-		 * path is missing from the working tree (deleted)
-		 */
-		return DIFF_STATUS_DELETED;
-	else
-		/*
-		 * Either an explicit add request, or path exists
-		 * in the working tree.  An attempt to explicitly
-		 * add a path that does not exist in the working tree
-		 * will be caught as an error by the caller immediately.
-		 */
-		return DIFF_STATUS_MODIFIED;
-}
-
-static void update_callback(struct diff_queue_struct *q,
-			    struct diff_options *opt UNUSED, void *cbdata)
-{
-	int i;
-	struct update_callback_data *data = cbdata;
-
-	for (i = 0; i < q->nr; i++) {
-		struct diff_filepair *p = q->queue[i];
-		const char *path = p->one->path;
-
-		if (!data->include_sparse &&
-		    !path_in_sparse_checkout(path, data->index))
-			continue;
-
-		switch (fix_unmerged_status(p, data)) {
-		default:
-			die(_("unexpected diff status %c"), p->status);
-		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
-			if (add_file_to_index(data->index, path, data->flags)) {
-				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
-					die(_("updating files failed"));
-				data->add_errors++;
-			}
-			break;
-		case DIFF_STATUS_DELETED:
-			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
-				break;
-			if (!(data->flags & ADD_CACHE_PRETEND))
-				remove_file_from_index(data->index, path);
-			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
-				printf(_("remove '%s'\n"), path);
-			break;
-		}
-	}
-}
-
-int add_files_to_cache(struct repository *repo, const char *prefix,
-		       const struct pathspec *pathspec, int include_sparse,
-		       int flags)
-{
-	struct update_callback_data data;
-	struct rev_info rev;
-
-	memset(&data, 0, sizeof(data));
-	data.index = repo->index;
-	data.include_sparse = include_sparse;
-	data.flags = flags;
-
-	repo_init_revisions(repo, &rev, prefix);
-	setup_revisions(0, NULL, &rev, NULL);
-	if (pathspec)
-		copy_pathspec(&rev.prune_data, pathspec);
-	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
-	rev.diffopt.format_callback = update_callback;
-	rev.diffopt.format_callback_data = &data;
-	rev.diffopt.flags.override_submodule_config = 1;
-	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
-
-	/*
-	 * Use an ODB transaction to optimize adding multiple objects.
-	 * This function is invoked from commands other than 'add', which
-	 * may not have their own transaction active.
-	 */
-	begin_odb_transaction();
-	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
-	end_odb_transaction();
-
-	release_revisions(&rev);
-	return !!data.add_errors;
-}
-
 static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
 {
 	int i, retval = 0;
diff --git a/read-cache.c b/read-cache.c
index c0df4586c9b..bfbd531ea60 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "alloc.h"
+#include "bulk-checkin.h"
 #include "config.h"
 #include "date.h"
 #include "diff.h"
@@ -26,6 +27,7 @@
 #include "mem-pool.h"
 #include "object-name.h"
 #include "resolve-undo.h"
+#include "revision.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "trace2.h"
@@ -3943,3 +3945,103 @@ void overlay_tree_on_index(struct index_state *istate,
 		}
 	}
 }
+
+struct update_callback_data {
+	struct index_state *index;
+	int include_sparse;
+	int flags;
+	int add_errors;
+};
+
+static int fix_unmerged_status(struct diff_filepair *p,
+			       struct update_callback_data *data)
+{
+	if (p->status != DIFF_STATUS_UNMERGED)
+		return p->status;
+	if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
+		/*
+		 * This is not an explicit add request, and the
+		 * path is missing from the working tree (deleted)
+		 */
+		return DIFF_STATUS_DELETED;
+	else
+		/*
+		 * Either an explicit add request, or path exists
+		 * in the working tree.  An attempt to explicitly
+		 * add a path that does not exist in the working tree
+		 * will be caught as an error by the caller immediately.
+		 */
+		return DIFF_STATUS_MODIFIED;
+}
+
+static void update_callback(struct diff_queue_struct *q,
+			    struct diff_options *opt UNUSED, void *cbdata)
+{
+	int i;
+	struct update_callback_data *data = cbdata;
+
+	for (i = 0; i < q->nr; i++) {
+		struct diff_filepair *p = q->queue[i];
+		const char *path = p->one->path;
+
+		if (!data->include_sparse &&
+		    !path_in_sparse_checkout(path, data->index))
+			continue;
+
+		switch (fix_unmerged_status(p, data)) {
+		default:
+			die(_("unexpected diff status %c"), p->status);
+		case DIFF_STATUS_MODIFIED:
+		case DIFF_STATUS_TYPE_CHANGED:
+			if (add_file_to_index(data->index, path, data->flags)) {
+				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
+					die(_("updating files failed"));
+				data->add_errors++;
+			}
+			break;
+		case DIFF_STATUS_DELETED:
+			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
+				break;
+			if (!(data->flags & ADD_CACHE_PRETEND))
+				remove_file_from_index(data->index, path);
+			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
+				printf(_("remove '%s'\n"), path);
+			break;
+		}
+	}
+}
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags)
+{
+	struct update_callback_data data;
+	struct rev_info rev;
+
+	memset(&data, 0, sizeof(data));
+	data.index = repo->index;
+	data.include_sparse = include_sparse;
+	data.flags = flags;
+
+	repo_init_revisions(repo, &rev, prefix);
+	setup_revisions(0, NULL, &rev, NULL);
+	if (pathspec)
+		copy_pathspec(&rev.prune_data, pathspec);
+	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
+	rev.diffopt.format_callback = update_callback;
+	rev.diffopt.format_callback_data = &data;
+	rev.diffopt.flags.override_submodule_config = 1;
+	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+	/*
+	 * Use an ODB transaction to optimize adding multiple objects.
+	 * This function is invoked from commands other than 'add', which
+	 * may not have their own transaction active.
+	 */
+	begin_odb_transaction();
+	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+	end_odb_transaction();
+
+	release_revisions(&rev);
+	return !!data.add_errors;
+}
-- 
gitgitgadget


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

* [PATCH v2 08/27] statinfo: move stat_{data,validity} functions from cache/read-cache
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (6 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 07/27] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 09/27] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
                     ` (19 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

These functions do not depend upon struct cache_entry or struct
index_state in any way, and it seems more logical to break them out into
this file, especially since statinfo.h already has the struct stat_data
declaration.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Makefile              |  1 +
 cache.h               | 48 ------------------------
 object.c              |  1 +
 read-cache.c          | 84 -----------------------------------------
 refs/packed-backend.c |  1 +
 shallow.c             |  1 +
 statinfo.c            | 87 +++++++++++++++++++++++++++++++++++++++++++
 statinfo.h            | 51 +++++++++++++++++++++++++
 8 files changed, 142 insertions(+), 132 deletions(-)
 create mode 100644 statinfo.c

diff --git a/Makefile b/Makefile
index e440728c246..cbc7f212016 100644
--- a/Makefile
+++ b/Makefile
@@ -1142,6 +1142,7 @@ LIB_OBJS += sigchain.o
 LIB_OBJS += sparse-index.o
 LIB_OBJS += split-index.o
 LIB_OBJS += stable-qsort.o
+LIB_OBJS += statinfo.o
 LIB_OBJS += strbuf.o
 LIB_OBJS += streaming.o
 LIB_OBJS += string-list.o
diff --git a/cache.h b/cache.h
index 02d69c24cd6..891e5fec744 100644
--- a/cache.h
+++ b/cache.h
@@ -488,19 +488,6 @@ int has_racy_timestamp(struct index_state *istate);
 int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
 int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
 
-/*
- * Record to sd the data from st that we use to check whether a file
- * might have changed.
- */
-void fill_stat_data(struct stat_data *sd, struct stat *st);
-
-/*
- * Return 0 if st is consistent with a file not having been changed
- * since sd was filled.  If there are differences, return a
- * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
- * INODE_CHANGED, and DATA_CHANGED.
- */
-int match_stat_data(const struct stat_data *sd, struct stat *st);
 int match_stat_data_racy(const struct index_state *istate,
 			 const struct stat_data *sd, struct stat *st);
 
@@ -539,14 +526,6 @@ void set_alternate_index_output(const char *);
 extern int verify_index_checksum;
 extern int verify_ce_order;
 
-#define MTIME_CHANGED	0x0001
-#define CTIME_CHANGED	0x0002
-#define OWNER_CHANGED	0x0004
-#define MODE_CHANGED    0x0008
-#define INODE_CHANGED   0x0010
-#define DATA_CHANGED    0x0020
-#define TYPE_CHANGED    0x0040
-
 int cmp_cache_name_compare(const void *a_, const void *b_);
 
 /* add */
@@ -579,31 +558,4 @@ int checkout_fast_forward(struct repository *r,
 
 int sane_execvp(const char *file, char *const argv[]);
 
-/*
- * A struct to encapsulate the concept of whether a file has changed
- * since we last checked it. This uses criteria similar to those used
- * for the index.
- */
-struct stat_validity {
-	struct stat_data *sd;
-};
-
-void stat_validity_clear(struct stat_validity *sv);
-
-/*
- * Returns 1 if the path is a regular file (or a symlink to a regular
- * file) and matches the saved stat_validity, 0 otherwise.  A missing
- * or inaccessible file is considered a match if the struct was just
- * initialized, or if the previous update found an inaccessible file.
- */
-int stat_validity_check(struct stat_validity *sv, const char *path);
-
-/*
- * Update the stat_validity from a file opened at descriptor fd. If
- * the file is missing, inaccessible, or not a regular file, then
- * future calls to stat_validity_check will match iff one of those
- * conditions continues to be true.
- */
-void stat_validity_update(struct stat_validity *sv, int fd);
-
 #endif /* CACHE_H */
diff --git a/object.c b/object.c
index 6d4ef1524de..333e736fb24 100644
--- a/object.c
+++ b/object.c
@@ -6,6 +6,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "blob.h"
+#include "statinfo.h"
 #include "tree.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/read-cache.c b/read-cache.c
index bfbd531ea60..b99dbfd16b0 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -177,61 +177,6 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
 		add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
 
-void fill_stat_data(struct stat_data *sd, struct stat *st)
-{
-	sd->sd_ctime.sec = (unsigned int)st->st_ctime;
-	sd->sd_mtime.sec = (unsigned int)st->st_mtime;
-	sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
-	sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
-	sd->sd_dev = st->st_dev;
-	sd->sd_ino = st->st_ino;
-	sd->sd_uid = st->st_uid;
-	sd->sd_gid = st->st_gid;
-	sd->sd_size = st->st_size;
-}
-
-int match_stat_data(const struct stat_data *sd, struct stat *st)
-{
-	int changed = 0;
-
-	if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
-		changed |= MTIME_CHANGED;
-	if (trust_ctime && check_stat &&
-	    sd->sd_ctime.sec != (unsigned int)st->st_ctime)
-		changed |= CTIME_CHANGED;
-
-#ifdef USE_NSEC
-	if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
-		changed |= MTIME_CHANGED;
-	if (trust_ctime && check_stat &&
-	    sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
-		changed |= CTIME_CHANGED;
-#endif
-
-	if (check_stat) {
-		if (sd->sd_uid != (unsigned int) st->st_uid ||
-			sd->sd_gid != (unsigned int) st->st_gid)
-			changed |= OWNER_CHANGED;
-		if (sd->sd_ino != (unsigned int) st->st_ino)
-			changed |= INODE_CHANGED;
-	}
-
-#ifdef USE_STDEV
-	/*
-	 * st_dev breaks on network filesystems where different
-	 * clients will have different views of what "device"
-	 * the filesystem is on
-	 */
-	if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
-			changed |= INODE_CHANGED;
-#endif
-
-	if (sd->sd_size != (unsigned int) st->st_size)
-		changed |= DATA_CHANGED;
-
-	return changed;
-}
-
 /*
  * This only updates the "non-critical" parts of the directory
  * cache, ie the parts that aren't tracked by GIT, and only used
@@ -3536,35 +3481,6 @@ void *read_blob_data_from_index(struct index_state *istate,
 	return data;
 }
 
-void stat_validity_clear(struct stat_validity *sv)
-{
-	FREE_AND_NULL(sv->sd);
-}
-
-int stat_validity_check(struct stat_validity *sv, const char *path)
-{
-	struct stat st;
-
-	if (stat(path, &st) < 0)
-		return sv->sd == NULL;
-	if (!sv->sd)
-		return 0;
-	return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
-}
-
-void stat_validity_update(struct stat_validity *sv, int fd)
-{
-	struct stat st;
-
-	if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
-		stat_validity_clear(sv);
-	else {
-		if (!sv->sd)
-			CALLOC_ARRAY(sv->sd, 1);
-		fill_stat_data(sv->sd, &st);
-	}
-}
-
 void move_index_extensions(struct index_state *dst, struct index_state *src)
 {
 	dst->untracked = src->untracked;
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 704424f55c0..085becf773e 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -10,6 +10,7 @@
 #include "../iterator.h"
 #include "../lockfile.h"
 #include "../chdir-notify.h"
+#include "../statinfo.h"
 #include "../wrapper.h"
 #include "../write-or-die.h"
 
diff --git a/shallow.c b/shallow.c
index 128f56179ed..a2ebf0af2ba 100644
--- a/shallow.c
+++ b/shallow.c
@@ -17,6 +17,7 @@
 #include "list-objects.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "statinfo.h"
 #include "trace.h"
 #include "wrapper.h"
 
diff --git a/statinfo.c b/statinfo.c
new file mode 100644
index 00000000000..17bb8966c33
--- /dev/null
+++ b/statinfo.c
@@ -0,0 +1,87 @@
+#include "git-compat-util.h"
+#include "environment.h"
+#include "statinfo.h"
+
+void fill_stat_data(struct stat_data *sd, struct stat *st)
+{
+	sd->sd_ctime.sec = (unsigned int)st->st_ctime;
+	sd->sd_mtime.sec = (unsigned int)st->st_mtime;
+	sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
+	sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
+	sd->sd_dev = st->st_dev;
+	sd->sd_ino = st->st_ino;
+	sd->sd_uid = st->st_uid;
+	sd->sd_gid = st->st_gid;
+	sd->sd_size = st->st_size;
+}
+
+int match_stat_data(const struct stat_data *sd, struct stat *st)
+{
+	int changed = 0;
+
+	if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
+		changed |= MTIME_CHANGED;
+	if (trust_ctime && check_stat &&
+	    sd->sd_ctime.sec != (unsigned int)st->st_ctime)
+		changed |= CTIME_CHANGED;
+
+#ifdef USE_NSEC
+	if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
+		changed |= MTIME_CHANGED;
+	if (trust_ctime && check_stat &&
+	    sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
+		changed |= CTIME_CHANGED;
+#endif
+
+	if (check_stat) {
+		if (sd->sd_uid != (unsigned int) st->st_uid ||
+			sd->sd_gid != (unsigned int) st->st_gid)
+			changed |= OWNER_CHANGED;
+		if (sd->sd_ino != (unsigned int) st->st_ino)
+			changed |= INODE_CHANGED;
+	}
+
+#ifdef USE_STDEV
+	/*
+	 * st_dev breaks on network filesystems where different
+	 * clients will have different views of what "device"
+	 * the filesystem is on
+	 */
+	if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
+			changed |= INODE_CHANGED;
+#endif
+
+	if (sd->sd_size != (unsigned int) st->st_size)
+		changed |= DATA_CHANGED;
+
+	return changed;
+}
+
+void stat_validity_clear(struct stat_validity *sv)
+{
+	FREE_AND_NULL(sv->sd);
+}
+
+int stat_validity_check(struct stat_validity *sv, const char *path)
+{
+	struct stat st;
+
+	if (stat(path, &st) < 0)
+		return sv->sd == NULL;
+	if (!sv->sd)
+		return 0;
+	return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
+}
+
+void stat_validity_update(struct stat_validity *sv, int fd)
+{
+	struct stat st;
+
+	if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
+		stat_validity_clear(sv);
+	else {
+		if (!sv->sd)
+			CALLOC_ARRAY(sv->sd, 1);
+		fill_stat_data(sv->sd, &st);
+	}
+}
diff --git a/statinfo.h b/statinfo.h
index e49e3054eaa..bb9b61bc471 100644
--- a/statinfo.h
+++ b/statinfo.h
@@ -1,6 +1,8 @@
 #ifndef STATINFO_H
 #define STATINFO_H
 
+struct index_state;
+
 /*
  * The "cache_time" is just the low 32 bits of the
  * time. It doesn't matter if it overflows - we only
@@ -21,4 +23,53 @@ struct stat_data {
 	unsigned int sd_size;
 };
 
+/*
+ * A struct to encapsulate the concept of whether a file has changed
+ * since we last checked it. This uses criteria similar to those used
+ * for the index.
+ */
+struct stat_validity {
+	struct stat_data *sd;
+};
+
+#define MTIME_CHANGED	0x0001
+#define CTIME_CHANGED	0x0002
+#define OWNER_CHANGED	0x0004
+#define MODE_CHANGED    0x0008
+#define INODE_CHANGED   0x0010
+#define DATA_CHANGED    0x0020
+#define TYPE_CHANGED    0x0040
+
+/*
+ * Record to sd the data from st that we use to check whether a file
+ * might have changed.
+ */
+void fill_stat_data(struct stat_data *sd, struct stat *st);
+
+/*
+ * Return 0 if st is consistent with a file not having been changed
+ * since sd was filled.  If there are differences, return a
+ * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
+ * INODE_CHANGED, and DATA_CHANGED.
+ */
+int match_stat_data(const struct stat_data *sd, struct stat *st);
+
+void stat_validity_clear(struct stat_validity *sv);
+
+/*
+ * Returns 1 if the path is a regular file (or a symlink to a regular
+ * file) and matches the saved stat_validity, 0 otherwise.  A missing
+ * or inaccessible file is considered a match if the struct was just
+ * initialized, or if the previous update found an inaccessible file.
+ */
+int stat_validity_check(struct stat_validity *sv, const char *path);
+
+/*
+ * Update the stat_validity from a file opened at descriptor fd. If
+ * the file is missing, inaccessible, or not a regular file, then
+ * future calls to stat_validity_check will match iff one of those
+ * conditions continues to be true.
+ */
+void stat_validity_update(struct stat_validity *sv, int fd);
+
 #endif
-- 
gitgitgadget


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

* [PATCH v2 09/27] run-command.h: move declarations for run-command.c from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (7 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 08/27] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 10/27] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
                     ` (18 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h       | 3 ---
 exec-cmd.c    | 3 ++-
 run-command.c | 2 +-
 run-command.h | 2 ++
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cache.h b/cache.h
index 891e5fec744..d31b1515069 100644
--- a/cache.h
+++ b/cache.h
@@ -555,7 +555,4 @@ int checkout_fast_forward(struct repository *r,
 			  const struct object_id *to,
 			  int overwrite_ignore);
 
-
-int sane_execvp(const char *file, char *const argv[]);
-
 #endif /* CACHE_H */
diff --git a/exec-cmd.c b/exec-cmd.c
index 1e34e48c0e4..1d597e84ea7 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,10 +1,11 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "path.h"
 #include "quote.h"
+#include "run-command.h"
 #include "strvec.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/run-command.c b/run-command.c
index d4247d5fcc6..1873d0ba8e7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "run-command.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/run-command.h b/run-command.h
index 072db56a4df..9e47f91d462 100644
--- a/run-command.h
+++ b/run-command.h
@@ -564,4 +564,6 @@ enum start_bg_result start_bg_command(struct child_process *cmd,
 				      void *cb_data,
 				      unsigned int timeout_sec);
 
+int sane_execvp(const char *file, char *const argv[]);
+
 #endif
-- 
gitgitgadget


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

* [PATCH v2 10/27] name-hash.h: move declarations for name-hash.c from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (8 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 09/27] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 11/27] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
                     ` (17 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                             |  1 +
 builtin/mv.c                        |  1 +
 cache.h                             |  9 ---------
 dir.c                               |  1 +
 entry.c                             |  1 +
 merge-recursive.c                   |  1 +
 name-hash.c                         |  1 +
 name-hash.h                         | 16 ++++++++++++++++
 read-cache.c                        |  1 +
 sparse-index.c                      |  1 +
 t/helper/test-lazy-init-name-hash.c |  1 +
 unpack-trees.c                      |  1 +
 12 files changed, 26 insertions(+), 9 deletions(-)
 create mode 100644 name-hash.h

diff --git a/apply.c b/apply.c
index 6212ab3a1b3..3da33bb88fd 100644
--- a/apply.c
+++ b/apply.c
@@ -23,6 +23,7 @@
 #include "xdiff-interface.h"
 #include "ll-merge.h"
 #include "lockfile.h"
+#include "name-hash.h"
 #include "object-name.h"
 #include "object-file.h"
 #include "parse-options.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 665bd274485..e058b574654 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -11,6 +11,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "pathspec.h"
 #include "lockfile.h"
diff --git a/cache.h b/cache.h
index d31b1515069..316904da392 100644
--- a/cache.h
+++ b/cache.h
@@ -245,12 +245,6 @@ struct index_state {
 void index_state_init(struct index_state *istate, struct repository *r);
 void release_index(struct index_state *istate);
 
-/* Name hashing */
-int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
-void add_name_hash(struct index_state *istate, struct cache_entry *ce);
-void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
-void free_name_hash(struct index_state *istate);
-
 /* Cache entry creation and cleanup */
 
 /*
@@ -377,9 +371,6 @@ int repo_index_has_changes(struct repository *repo,
 
 int verify_path(const char *path, unsigned mode);
 int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-int index_dir_exists(struct index_state *istate, const char *name, int namelen);
-void adjust_dirname_case(struct index_state *istate, char *name);
-struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
 
 /*
  * Searches for an entry defined by name and namelen in the given index.
diff --git a/dir.c b/dir.c
index a7469df3ac7..029aab36fe8 100644
--- a/dir.c
+++ b/dir.c
@@ -13,6 +13,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/entry.c b/entry.c
index 91a540bd29f..7791cc999cc 100644
--- a/entry.c
+++ b/entry.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "name-hash.h"
 #include "streaming.h"
 #include "submodule.h"
 #include "symlinks.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8e87b6386d9..b341ba4f38d 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -23,6 +23,7 @@
 #include "ll-merge.h"
 #include "lockfile.h"
 #include "match-trees.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/name-hash.c b/name-hash.c
index fb13716e430..52ce47ea394 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "thread-utils.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/name-hash.h b/name-hash.h
new file mode 100644
index 00000000000..b1b4b0fb337
--- /dev/null
+++ b/name-hash.h
@@ -0,0 +1,16 @@
+#ifndef NAME_HASH_H
+#define NAME_HASH_H
+
+struct cache_entry;
+struct index_state;
+
+int index_dir_exists(struct index_state *istate, const char *name, int namelen);
+void adjust_dirname_case(struct index_state *istate, char *name);
+struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
+
+int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
+void add_name_hash(struct index_state *istate, struct cache_entry *ce);
+void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
+void free_name_hash(struct index_state *istate);
+
+#endif /* NAME_HASH_H */
diff --git a/read-cache.c b/read-cache.c
index b99dbfd16b0..e1016ae0317 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -25,6 +25,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "mem-pool.h"
+#include "name-hash.h"
 #include "object-name.h"
 #include "resolve-undo.h"
 #include "revision.h"
diff --git a/sparse-index.c b/sparse-index.c
index 886054729e5..60451daae80 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index b83a75d19f6..6944b7e825f 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "environment.h"
+#include "name-hash.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index e8c32a40dcb..078c53f7a13 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -7,6 +7,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "name-hash.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
-- 
gitgitgadget


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

* [PATCH v2 11/27] sparse-index.h: move declarations for sparse-index.c from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (9 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 10/27] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 12/27] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
                     ` (16 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Note in particular that this reverses the decision made in 118a2e8bde0
("cache: move ensure_full_index() to cache.h", 2021-04-01).

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/checkout-index.c    | 1 +
 builtin/commit.c            | 1 +
 builtin/difftool.c          | 1 +
 builtin/fsck.c              | 1 +
 builtin/ls-files.c          | 1 +
 builtin/merge-index.c       | 1 +
 builtin/read-tree.c         | 1 +
 builtin/reset.c             | 1 +
 builtin/rm.c                | 1 +
 builtin/stash.c             | 1 +
 builtin/submodule--helper.c | 1 +
 builtin/update-index.c      | 1 +
 cache.h                     | 2 --
 dir.c                       | 1 +
 entry.c                     | 1 +
 merge-ort.c                 | 1 +
 merge-recursive.c           | 1 +
 resolve-undo.c              | 1 +
 revision.c                  | 1 +
 sequencer.c                 | 1 +
 sparse-index.h              | 2 ++
 21 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 9375a05539f..b1cd8bef264 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -17,6 +17,7 @@
 #include "entry.h"
 #include "parallel-checkout.h"
 #include "setup.h"
+#include "sparse-index.h"
 
 #define CHECKOUT_ALL 4
 static int nul_term_line;
diff --git a/builtin/commit.c b/builtin/commit.c
index bd634ee6ad1..02e2ef3e307 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -38,6 +38,7 @@
 #include "gpg-interface.h"
 #include "column.h"
 #include "sequencer.h"
+#include "sparse-index.h"
 #include "mailmap.h"
 #include "help.h"
 #include "commit-reach.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 0049342f5c0..2c27a59e04a 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "strbuf.h"
 #include "lockfile.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 2cd461b84c1..7134596d218 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -25,6 +25,7 @@
 #include "replace-object.h"
 #include "resolve-undo.h"
 #include "run-command.h"
+#include "sparse-index.h"
 #include "worktree.h"
 #include "pack-revindex.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 069b28bd484..45b3b0ce5d8 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -23,6 +23,7 @@
 #include "pathspec.h"
 #include "run-command.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index ab16e70f23d..d16e8aa414b 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "run-command.h"
+#include "sparse-index.h"
 
 static const char *pgm;
 static int one_shot, quiet;
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 440f19b1b87..bd1ce1d963f 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -22,6 +22,7 @@
 #include "repository.h"
 #include "resolve-undo.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/reset.c b/builtin/reset.c
index f99f32d5802..3dc41ac3327 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -29,6 +29,7 @@
 #include "unpack-trees.h"
 #include "cache-tree.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "trace.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index b4589c824c0..377a0f66ad8 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -19,6 +19,7 @@
 #include "repository.h"
 #include "string-list.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "pathspec.h"
 
diff --git a/builtin/stash.c b/builtin/stash.c
index a7e17ffe384..8856ac6d5c7 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -20,6 +20,7 @@
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "log-tree.h"
 #include "diffcore.h"
 #include "exec-cmd.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6bf8d666ce9..c58cfbfd6d3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -13,6 +13,7 @@
 #include "pathspec.h"
 #include "dir.h"
 #include "setup.h"
+#include "sparse-index.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 5fab9ad2ec4..47dc9b626ef 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -24,6 +24,7 @@
 #include "dir.h"
 #include "repository.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "split-index.h"
 #include "symlinks.h"
 #include "fsmonitor.h"
diff --git a/cache.h b/cache.h
index 316904da392..79daaa166b1 100644
--- a/cache.h
+++ b/cache.h
@@ -327,8 +327,6 @@ int read_index_from(struct index_state *, const char *path,
 		    const char *gitdir);
 int is_index_unborn(struct index_state *);
 
-void ensure_full_index(struct index_state *istate);
-
 /* For use with `write_locked_index()`. */
 #define COMMIT_LOCK		(1 << 0)
 #define SKIP_IF_UNCHANGED	(1 << 1)
diff --git a/dir.c b/dir.c
index 029aab36fe8..1e84b1e1f28 100644
--- a/dir.c
+++ b/dir.c
@@ -25,6 +25,7 @@
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule-config.h"
 #include "symlinks.h"
 #include "trace2.h"
diff --git a/entry.c b/entry.c
index 7791cc999cc..53d00386748 100644
--- a/entry.c
+++ b/entry.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "name-hash.h"
+#include "sparse-index.h"
 #include "streaming.h"
 #include "submodule.h"
 #include "symlinks.h"
diff --git a/merge-ort.c b/merge-ort.c
index 65837db77f0..4bff685e456 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -38,6 +38,7 @@
 #include "oid-array.h"
 #include "promisor-remote.h"
 #include "revision.h"
+#include "sparse-index.h"
 #include "strmap.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index b341ba4f38d..0e16e7a06df 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -29,6 +29,7 @@
 #include "object-store.h"
 #include "repository.h"
 #include "revision.h"
+#include "sparse-index.h"
 #include "string-list.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 70a6db526d2..7ec09e89d4f 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -2,6 +2,7 @@
 #include "dir.h"
 #include "hash.h"
 #include "resolve-undo.h"
+#include "sparse-index.h"
 #include "string-list.h"
 
 /* The only error case is to run out of memory in string-list */
diff --git a/revision.c b/revision.c
index b33cc1d106a..88b2f42daa6 100644
--- a/revision.c
+++ b/revision.c
@@ -32,6 +32,7 @@
 #include "packfile.h"
 #include "worktree.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "trace2.h"
 #include "commit-reach.h"
diff --git a/sequencer.c b/sequencer.c
index ff18f7f4203..cae9c75a54e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -28,6 +28,7 @@
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "quote.h"
 #include "trailer.h"
diff --git a/sparse-index.h b/sparse-index.h
index 59a92d819ec..a16f3e67d75 100644
--- a/sparse-index.h
+++ b/sparse-index.h
@@ -37,4 +37,6 @@ struct pattern_list;
  */
 void expand_index(struct index_state *istate, struct pattern_list *pl);
 
+void ensure_full_index(struct index_state *istate);
+
 #endif
-- 
gitgitgadget


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

* [PATCH v2 12/27] preload-index.h: move declarations for preload-index.c from elsewhere
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (10 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 11/27] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 13/27] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
                     ` (15 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

We already have a preload-index.c file; move the declarations for the
functions in that file into a new preload-index.h.  These were
previously split between cache.h and repository.h.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c           |  1 +
 builtin/add.c               |  1 +
 builtin/am.c                |  1 +
 builtin/checkout.c          |  1 +
 builtin/commit.c            |  1 +
 builtin/diff-files.c        |  1 +
 builtin/diff-index.c        |  1 +
 builtin/diff.c              |  1 +
 builtin/stash.c             |  1 +
 builtin/submodule--helper.c |  1 +
 cache.h                     |  3 ---
 preload-index.c             |  1 +
 preload-index.h             | 15 +++++++++++++++
 read-cache.c                |  1 +
 repository.h                |  3 ---
 15 files changed, 27 insertions(+), 6 deletions(-)
 create mode 100644 preload-index.h

diff --git a/add-interactive.c b/add-interactive.c
index de877ca0525..99f7dc3b0d1 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -5,6 +5,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/builtin/add.c b/builtin/add.c
index 36ddbb159bf..8397be4f8de 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -17,6 +17,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "revision.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5c83f2e003f..0d8f46f8d5a 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -29,6 +29,7 @@
 #include "unpack-trees.h"
 #include "branch.h"
 #include "object-name.h"
+#include "preload-index.h"
 #include "sequencer.h"
 #include "revision.h"
 #include "merge-recursive.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d6765c9dbd9..2d72a742d9d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,6 +20,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "refs.h"
 #include "remote.h"
 #include "resolve-undo.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 02e2ef3e307..fa769045c88 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -30,6 +30,7 @@
 #include "utf8.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "unpack-trees.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index dc991f753bb..2e6b59a8bb3 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -8,6 +8,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "builtin.h"
 #include "submodule.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index b9a19bb7d38..9b98db2e77e 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -3,6 +3,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "builtin.h"
 #include "setup.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 7b64659fe79..967550739a6 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -16,6 +16,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "diffcore.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 8856ac6d5c7..06527ee8471 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -17,6 +17,7 @@
 #include "run-command.h"
 #include "dir.h"
 #include "entry.h"
+#include "preload-index.h"
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c58cfbfd6d3..597e780a93a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
+#include "preload-index.h"
 #include "dir.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/cache.h b/cache.h
index 79daaa166b1..b79802a4639 100644
--- a/cache.h
+++ b/cache.h
@@ -318,9 +318,6 @@ extern struct index_state the_index;
 
 /* Initialize and use the cache information */
 struct lock_file;
-void preload_index(struct index_state *index,
-		   const struct pathspec *pathspec,
-		   unsigned int refresh_flags);
 int do_read_index(struct index_state *istate, const char *path,
 		  int must_exist); /* for testting only! */
 int read_index_from(struct index_state *, const char *path,
diff --git a/preload-index.c b/preload-index.c
index 7a26b08c213..c26739debf8 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -8,6 +8,7 @@
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "config.h"
+#include "preload-index.h"
 #include "progress.h"
 #include "thread-utils.h"
 #include "repository.h"
diff --git a/preload-index.h b/preload-index.h
new file mode 100644
index 00000000000..251b1ed88e9
--- /dev/null
+++ b/preload-index.h
@@ -0,0 +1,15 @@
+#ifndef PRELOAD_INDEX_H
+#define PRELOAD_INDEX_H
+
+struct index_state;
+struct pathspec;
+struct repository;
+
+void preload_index(struct index_state *index,
+		   const struct pathspec *pathspec,
+		   unsigned int refresh_flags);
+int repo_read_index_preload(struct repository *,
+			    const struct pathspec *pathspec,
+			    unsigned refresh_flags);
+
+#endif /* PRELOAD_INDEX_H */
diff --git a/read-cache.c b/read-cache.c
index e1016ae0317..3fad839fb6f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@
 #include "mem-pool.h"
 #include "name-hash.h"
 #include "object-name.h"
+#include "preload-index.h"
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/repository.h b/repository.h
index 1a13ff28677..f81228bcfb5 100644
--- a/repository.h
+++ b/repository.h
@@ -220,9 +220,6 @@ int repo_hold_locked_index(struct repository *repo,
 			   struct lock_file *lf,
 			   int flags);
 
-int repo_read_index_preload(struct repository *,
-			    const struct pathspec *pathspec,
-			    unsigned refresh_flags);
 int repo_read_index_unmerged(struct repository *);
 /*
  * Opportunistically update the index but do not complain if we can't.
-- 
gitgitgadget


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

* [PATCH v2 13/27] diff.h: move declaration for global in diff.c from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (11 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 12/27] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 14/27] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
                     ` (14 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h | 3 ---
 diff.h  | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index b79802a4639..08f6fbd801d 100644
--- a/cache.h
+++ b/cache.h
@@ -523,9 +523,6 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, int include_sparse,
 		       int flags);
 
-/* diff.c */
-extern int diff_auto_refresh_index;
-
 /* ls-files */
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/diff.h b/diff.h
index 3a7a9e8b888..29a9cd217c2 100644
--- a/diff.h
+++ b/diff.h
@@ -694,4 +694,6 @@ void print_stat_summary(FILE *fp, int files,
 			int insertions, int deletions);
 void setup_diff_pager(struct diff_options *);
 
+extern int diff_auto_refresh_index;
+
 #endif /* DIFF_H */
-- 
gitgitgadget


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

* [PATCH v2 14/27] merge.h: move declarations for merge.c from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (12 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 13/27] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 15/27] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
                     ` (13 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/merge.c |  1 +
 builtin/pull.c  |  1 +
 cache.h         | 11 -----------
 merge.c         |  1 +
 merge.h         | 17 +++++++++++++++++
 sequencer.c     |  1 +
 6 files changed, 21 insertions(+), 11 deletions(-)
 create mode 100644 merge.h

diff --git a/builtin/merge.c b/builtin/merge.c
index 8da3e46abb0..6e8f7b9bb53 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -37,6 +37,7 @@
 #include "color.h"
 #include "rerere.h"
 #include "help.h"
+#include "merge.h"
 #include "merge-recursive.h"
 #include "merge-ort-wrappers.h"
 #include "resolve-undo.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 967368ebc65..f9ddc94ba9a 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
+#include "merge.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
diff --git a/cache.h b/cache.h
index 08f6fbd801d..5b690b80a16 100644
--- a/cache.h
+++ b/cache.h
@@ -527,15 +527,4 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
 
-/* merge.c */
-struct commit_list;
-int try_merge_command(struct repository *r,
-		const char *strategy, size_t xopts_nr,
-		const char **xopts, struct commit_list *common,
-		const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(struct repository *r,
-			  const struct object_id *from,
-			  const struct object_id *to,
-			  int overwrite_ignore);
-
 #endif /* CACHE_H */
diff --git a/merge.c b/merge.c
index 10aaec3a6c1..fade6b203b3 100644
--- a/merge.c
+++ b/merge.c
@@ -4,6 +4,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
+#include "merge.h"
 #include "commit.h"
 #include "run-command.h"
 #include "resolve-undo.h"
diff --git a/merge.h b/merge.h
new file mode 100644
index 00000000000..21ac7ef2f13
--- /dev/null
+++ b/merge.h
@@ -0,0 +1,17 @@
+#ifndef MERGE_H
+#define MERGE_H
+
+struct commit_list;
+struct object_id;
+struct repository;
+
+int try_merge_command(struct repository *r,
+		const char *strategy, size_t xopts_nr,
+		const char **xopts, struct commit_list *common,
+		const char *head_arg, struct commit_list *remotes);
+int checkout_fast_forward(struct repository *r,
+			  const struct object_id *from,
+			  const struct object_id *to,
+			  int overwrite_ignore);
+
+#endif /* MERGE_H */
diff --git a/sequencer.c b/sequencer.c
index cae9c75a54e..ec4a2e80a10 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -25,6 +25,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "rerere.h"
+#include "merge.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
-- 
gitgitgadget


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

* [PATCH v2 15/27] repository.h: move declaration of the_index from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (13 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 14/27] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-15 21:50     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 16/27] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
                     ` (12 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

the_index is a global variable defined in repository.c; as such, its
declaration feels better suited living in repository.h rather than
cache.h.  Move it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h                          | 4 ----
 repository.h                     | 3 +++
 t/helper/test-dump-split-index.c | 1 +
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cache.h b/cache.h
index 5b690b80a16..11882897741 100644
--- a/cache.h
+++ b/cache.h
@@ -312,10 +312,6 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
 void prefetch_cache_entries(const struct index_state *istate,
 			    must_prefetch_predicate must_prefetch);
 
-#ifdef USE_THE_INDEX_VARIABLE
-extern struct index_state the_index;
-#endif
-
 /* Initialize and use the cache information */
 struct lock_file;
 int do_read_index(struct index_state *istate, const char *path,
diff --git a/repository.h b/repository.h
index f81228bcfb5..763794880ed 100644
--- a/repository.h
+++ b/repository.h
@@ -169,6 +169,9 @@ struct repository {
 };
 
 extern struct repository *the_repository;
+#ifdef USE_THE_INDEX_VARIABLE
+extern struct index_state the_index;
+#endif
 
 /*
  * Define a custom repository layout. Any field can be NULL, which
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index d1badd71126..63fde9157c4 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 "repository.h"
 #include "setup.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
-- 
gitgitgadget


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

* [PATCH v2 16/27] read-cache*.h: move declarations for read-cache.c functions from cache.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (14 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 15/27] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-16  0:00     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 17/27] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
                     ` (11 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

For the functions defined in read-cache.c, move their declarations from
cache.h to a new header, read-cache-ll.h.  Also move some related inline
functions from cache.h to read-cache.h.  The purpose of the
read-cache-ll.h/read-cache.h split is that about 70% of the sites don't
need the inline functions and the extra headers they include.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                    |   1 +
 add-patch.c                          |   1 +
 apply.c                              |   1 +
 attr.c                               |   1 +
 blame.c                              |   1 +
 builtin/add.c                        |   1 +
 builtin/checkout--worker.c           |   1 +
 builtin/checkout-index.c             |   1 +
 builtin/checkout.c                   |   1 +
 builtin/clean.c                      |   1 +
 builtin/commit.c                     |   1 +
 builtin/describe.c                   |   1 +
 builtin/diff-tree.c                  |   1 +
 builtin/diff.c                       |   1 +
 builtin/difftool.c                   |   1 +
 builtin/fsck.c                       |   1 +
 builtin/grep.c                       |   1 +
 builtin/ls-files.c                   |   1 +
 builtin/merge-index.c                |   1 +
 builtin/mv.c                         |   1 +
 builtin/pull.c                       |   1 +
 builtin/rev-parse.c                  |   1 +
 builtin/rm.c                         |   1 +
 builtin/stash.c                      |   1 +
 builtin/submodule--helper.c          |   1 +
 builtin/update-index.c               |   1 +
 builtin/worktree.c                   |   1 +
 cache-tree.c                         |   1 +
 cache.h                              | 520 ---------------------------
 compat/precompose_utf8.c             |   1 +
 compat/sha1-chunked.c                |   1 +
 config.c                             |   1 +
 convert.c                            |   1 +
 diff-lib.c                           |   1 +
 diff.c                               |   1 +
 diffcore-break.c                     |   3 +-
 environment.h                        |   3 +-
 fsmonitor.h                          |   2 +
 git.c                                |   1 +
 hash-lookup.c                        |   1 +
 merge-ort-wrappers.c                 |   1 +
 merge-ort.c                          |   1 +
 name-hash.c                          |   2 +
 object-name.c                        |   1 +
 oidmap.h                             |   1 +
 parallel-checkout.c                  |   1 +
 pathspec.c                           |   1 +
 preload-index.c                      |   1 +
 read-cache-ll.h                      | 481 +++++++++++++++++++++++++
 read-cache.c                         |   1 +
 read-cache.h                         |  45 +++
 repository.c                         |   1 +
 rerere.c                             |   1 +
 resolve-undo.c                       |   1 +
 revision.c                           |   1 +
 split-index.c                        |   1 +
 submodule.c                          |   1 +
 t/helper/test-cache-tree.c           |   1 +
 t/helper/test-dump-cache-tree.c      |   1 +
 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-hash-speed.c           |   1 +
 t/helper/test-index-version.c        |   1 +
 t/helper/test-lazy-init-name-hash.c  |   1 +
 t/helper/test-path-utils.c           |   1 +
 t/helper/test-read-cache.c           |   1 +
 t/helper/test-scrap-cache-tree.c     |   1 +
 t/helper/test-sha1.c                 |   1 +
 t/helper/test-sha256.c               |   1 +
 t/helper/test-strcmp-offset.c        |   1 +
 t/helper/test-write-cache.c          |   1 +
 unpack-trees.c                       |   1 +
 unpack-trees.h                       |   2 +-
 wt-status.c                          |   1 +
 77 files changed, 603 insertions(+), 524 deletions(-)
 create mode 100644 read-cache-ll.h
 create mode 100644 read-cache.h

diff --git a/add-interactive.c b/add-interactive.c
index 99f7dc3b0d1..a9671e33491 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "preload-index.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 8d770d203ff..7d4d298286d 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/apply.c b/apply.c
index 3da33bb88fd..f056c8f3bb9 100644
--- a/apply.c
+++ b/apply.c
@@ -28,6 +28,7 @@
 #include "object-file.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "read-cache.h"
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
diff --git a/attr.c b/attr.c
index ddf2b0cbc2e..57c813d8e77 100644
--- a/attr.c
+++ b/attr.c
@@ -16,6 +16,7 @@
 #include "gettext.h"
 #include "utf8.h"
 #include "quote.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "object-store.h"
 #include "setup.h"
diff --git a/blame.c b/blame.c
index 58dd58b6c97..a29ae7c14b2 100644
--- a/blame.c
+++ b/blame.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "tag.h"
 #include "trace2.h"
diff --git a/builtin/add.c b/builtin/add.c
index 8397be4f8de..9fe6b6ce290 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -20,6 +20,7 @@
 #include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "read-cache.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index 2120dd1d300..c655dc4b136 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -6,6 +6,7 @@
 #include "parallel-checkout.h"
 #include "parse-options.h"
 #include "pkt-line.h"
+#include "read-cache-ll.h"
 
 static void packet_to_pc_item(const char *buffer, int len,
 			      struct parallel_checkout_item *pc_item)
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index b1cd8bef264..f62f13f2b53 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "sparse-index.h"
 
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2d72a742d9d..09b84156492 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -21,6 +21,7 @@
 #include "object-store.h"
 #include "parse-options.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "refs.h"
 #include "remote.h"
 #include "resolve-undo.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 78852d28cec..49c7af45b03 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "string-list.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index fa769045c88..5be05c9d9e1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -31,6 +31,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "unpack-trees.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 55b4baaa223..f1be7c36948 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -13,6 +13,7 @@
 #include "exec-cmd.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "diff.h"
 #include "hashmap.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 0b02c62b85e..5a1e5d6df7c 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -8,6 +8,7 @@
 #include "log-tree.h"
 #include "builtin.h"
 #include "submodule.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "tree.h"
 
diff --git a/builtin/diff.c b/builtin/diff.c
index 967550739a6..a9ce701ff97 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -17,6 +17,7 @@
 #include "diff-merges.h"
 #include "diffcore.h"
 #include "preload-index.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2c27a59e04a..88809976c53 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "sparse-index.h"
 #include "strvec.h"
 #include "strbuf.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 7134596d218..e8c5fbca58f 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -22,6 +22,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "replace-object.h"
 #include "resolve-undo.h"
 #include "run-command.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index b86c754defb..0d567575890 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -31,6 +31,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pager.h"
+#include "read-cache-ll.h"
 #include "write-or-die.h"
 
 static const char *grep_prefix;
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 45b3b0ce5d8..d8c1c62bcb0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -21,6 +21,7 @@
 #include "resolve-undo.h"
 #include "string-list.h"
 #include "pathspec.h"
+#include "read-cache.h"
 #include "run-command.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index d16e8aa414b..270d5f644ac 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "hex.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "run-command.h"
 #include "sparse-index.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index e058b574654..ae462bd7d41 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -19,6 +19,7 @@
 #include "cache-tree.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index f9ddc94ba9a..8aeb5abc7fb 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -20,6 +20,7 @@
 #include "oid-array.h"
 #include "remote.h"
 #include "dir.h"
+#include "read-cache-ll.h"
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 852e49e3403..ad93e5fad88 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -18,6 +18,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "diff.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "setup.h"
 #include "split-index.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 377a0f66ad8..463eeabceaa 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -16,6 +16,7 @@
 #include "tree-walk.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "string-list.h"
 #include "setup.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 06527ee8471..d3d5bb95e26 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -18,6 +18,7 @@
 #include "dir.h"
 #include "entry.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 597e780a93a..86324b829a7 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -13,6 +13,7 @@
 #include "pathspec.h"
 #include "preload-index.h"
 #include "dir.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "submodule.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 47dc9b626ef..484a307df50 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -22,6 +22,7 @@
 #include "parse-options.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index f3180463be2..3c3d97ad5b0 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -13,6 +13,7 @@
 #include "parse-options.h"
 #include "strvec.h"
 #include "branch.h"
+#include "read-cache-ll.h"
 #include "refs.h"
 #include "repository.h"
 #include "run-command.h"
diff --git a/cache-tree.c b/cache-tree.c
index ebfe649b330..153217b47ff 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -9,6 +9,7 @@
 #include "bulk-checkin.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "sparse-index.h"
diff --git a/cache.h b/cache.h
index 11882897741..9b4e8d16874 100644
--- a/cache.h
+++ b/cache.h
@@ -2,525 +2,5 @@
 #define CACHE_H
 
 #include "git-compat-util.h"
-#include "strbuf.h"
-#include "hashmap.h"
-#include "pathspec.h"
-#include "object.h"
-#include "statinfo.h"
-
-/*
- * Basic data structures for the directory cache
- */
-
-#define CACHE_SIGNATURE 0x44495243	/* "DIRC" */
-struct cache_header {
-	uint32_t hdr_signature;
-	uint32_t hdr_version;
-	uint32_t hdr_entries;
-};
-
-#define INDEX_FORMAT_LB 2
-#define INDEX_FORMAT_UB 4
-
-struct cache_entry {
-	struct hashmap_entry ent;
-	struct stat_data ce_stat_data;
-	unsigned int ce_mode;
-	unsigned int ce_flags;
-	unsigned int mem_pool_allocated;
-	unsigned int ce_namelen;
-	unsigned int index;	/* for link extension */
-	struct object_id oid;
-	char name[FLEX_ARRAY]; /* more */
-};
-
-#define CE_STAGEMASK (0x3000)
-#define CE_EXTENDED  (0x4000)
-#define CE_VALID     (0x8000)
-#define CE_STAGESHIFT 12
-
-/*
- * Range 0xFFFF0FFF in ce_flags is divided into
- * two parts: in-memory flags and on-disk ones.
- * Flags in CE_EXTENDED_FLAGS will get saved on-disk
- * if you want to save a new flag, add it in
- * CE_EXTENDED_FLAGS
- *
- * In-memory only flags
- */
-#define CE_UPDATE            (1 << 16)
-#define CE_REMOVE            (1 << 17)
-#define CE_UPTODATE          (1 << 18)
-#define CE_ADDED             (1 << 19)
-
-#define CE_HASHED            (1 << 20)
-#define CE_FSMONITOR_VALID   (1 << 21)
-#define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
-#define CE_CONFLICTED        (1 << 23)
-
-#define CE_UNPACKED          (1 << 24)
-#define CE_NEW_SKIP_WORKTREE (1 << 25)
-
-/* used to temporarily mark paths matched by pathspecs */
-#define CE_MATCHED           (1 << 26)
-
-#define CE_UPDATE_IN_BASE    (1 << 27)
-#define CE_STRIP_NAME        (1 << 28)
-
-/*
- * Extended on-disk flags
- */
-#define CE_INTENT_TO_ADD     (1 << 29)
-#define CE_SKIP_WORKTREE     (1 << 30)
-/* CE_EXTENDED2 is for future extension */
-#define CE_EXTENDED2         (1U << 31)
-
-#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
-
-/*
- * Safeguard to avoid saving wrong flags:
- *  - CE_EXTENDED2 won't get saved until its semantic is known
- *  - Bits in 0x0000FFFF have been saved in ce_flags already
- *  - Bits in 0x003F0000 are currently in-memory flags
- */
-#if CE_EXTENDED_FLAGS & 0x803FFFFF
-#error "CE_EXTENDED_FLAGS out of range"
-#endif
-
-/* Forward structure decls */
-struct pathspec;
-struct tree;
-
-/*
- * Copy the sha1 and stat state of a cache entry from one to
- * another. But we never change the name, or the hash state!
- */
-static inline void copy_cache_entry(struct cache_entry *dst,
-				    const struct cache_entry *src)
-{
-	unsigned int state = dst->ce_flags & CE_HASHED;
-	int mem_pool_allocated = dst->mem_pool_allocated;
-
-	/* Don't copy hash chain and name */
-	memcpy(&dst->ce_stat_data, &src->ce_stat_data,
-			offsetof(struct cache_entry, name) -
-			offsetof(struct cache_entry, ce_stat_data));
-
-	/* Restore the hash state */
-	dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
-
-	/* Restore the mem_pool_allocated flag */
-	dst->mem_pool_allocated = mem_pool_allocated;
-}
-
-static inline unsigned create_ce_flags(unsigned stage)
-{
-	return (stage << CE_STAGESHIFT);
-}
-
-#define ce_namelen(ce) ((ce)->ce_namelen)
-#define ce_size(ce) cache_entry_size(ce_namelen(ce))
-#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
-#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
-#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
-#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
-#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
-
-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
-					     unsigned int mode)
-{
-	extern int trust_executable_bit, has_symlinks;
-	if (!has_symlinks && S_ISREG(mode) &&
-	    ce && S_ISLNK(ce->ce_mode))
-		return ce->ce_mode;
-	if (!trust_executable_bit && S_ISREG(mode)) {
-		if (ce && S_ISREG(ce->ce_mode))
-			return ce->ce_mode;
-		return create_ce_mode(0666);
-	}
-	return create_ce_mode(mode);
-}
-static inline int ce_to_dtype(const struct cache_entry *ce)
-{
-	unsigned ce_mode = ntohl(ce->ce_mode);
-	if (S_ISREG(ce_mode))
-		return DT_REG;
-	else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
-		return DT_DIR;
-	else if (S_ISLNK(ce_mode))
-		return DT_LNK;
-	else
-		return DT_UNKNOWN;
-}
-
-static inline int ce_path_match(struct index_state *istate,
-				const struct cache_entry *ce,
-				const struct pathspec *pathspec,
-				char *seen)
-{
-	return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
-			      S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
-}
-
-#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
-
-#define SOMETHING_CHANGED	(1 << 0) /* unclassified changes go here */
-#define CE_ENTRY_CHANGED	(1 << 1)
-#define CE_ENTRY_REMOVED	(1 << 2)
-#define CE_ENTRY_ADDED		(1 << 3)
-#define RESOLVE_UNDO_CHANGED	(1 << 4)
-#define CACHE_TREE_CHANGED	(1 << 5)
-#define SPLIT_INDEX_ORDERED	(1 << 6)
-#define UNTRACKED_CHANGED	(1 << 7)
-#define FSMONITOR_CHANGED	(1 << 8)
-
-struct split_index;
-struct untracked_cache;
-struct progress;
-struct pattern_list;
-
-enum sparse_index_mode {
-	/*
-	 * There are no sparse directories in the index at all.
-	 *
-	 * Repositories that don't use cone-mode sparse-checkout will
-	 * always have their indexes in this mode.
-	 */
-	INDEX_EXPANDED = 0,
-
-	/*
-	 * The index has already been collapsed to sparse directories
-	 * whereever possible.
-	 */
-	INDEX_COLLAPSED,
-
-	/*
-	 * The sparse directories that exist are outside the
-	 * sparse-checkout boundary, but it is possible that some file
-	 * entries could collapse to sparse directory entries.
-	 */
-	INDEX_PARTIALLY_SPARSE,
-};
-
-struct index_state {
-	struct cache_entry **cache;
-	unsigned int version;
-	unsigned int cache_nr, cache_alloc, cache_changed;
-	struct string_list *resolve_undo;
-	struct cache_tree *cache_tree;
-	struct split_index *split_index;
-	struct cache_time timestamp;
-	unsigned name_hash_initialized : 1,
-		 initialized : 1,
-		 drop_cache_tree : 1,
-		 updated_workdir : 1,
-		 updated_skipworktree : 1,
-		 fsmonitor_has_run_once : 1;
-	enum sparse_index_mode sparse_index;
-	struct hashmap name_hash;
-	struct hashmap dir_hash;
-	struct object_id oid;
-	struct untracked_cache *untracked;
-	char *fsmonitor_last_update;
-	struct ewah_bitmap *fsmonitor_dirty;
-	struct mem_pool *ce_mem_pool;
-	struct progress *progress;
-	struct repository *repo;
-	struct pattern_list *sparse_checkout_patterns;
-};
-
-/**
- * A "struct index_state istate" must be initialized with
- * INDEX_STATE_INIT or the corresponding index_state_init().
- *
- * If the variable won't be used again, use release_index() to free()
- * its resources. If it needs to be used again use discard_index(),
- * which does the same thing, but will use use index_state_init() at
- * the end. The discard_index() will use its own "istate->repo" as the
- * "r" argument to index_state_init() in that case.
- */
-#define INDEX_STATE_INIT(r) { \
-	.repo = (r), \
-}
-void index_state_init(struct index_state *istate, struct repository *r);
-void release_index(struct index_state *istate);
-
-/* Cache entry creation and cleanup */
-
-/*
- * Create cache_entry intended for use in the specified index. Caller
- * is responsible for discarding the cache_entry with
- * `discard_cache_entry`.
- */
-struct cache_entry *make_cache_entry(struct index_state *istate,
-				     unsigned int mode,
-				     const struct object_id *oid,
-				     const char *path,
-				     int stage,
-				     unsigned int refresh_options);
-
-struct cache_entry *make_empty_cache_entry(struct index_state *istate,
-					   size_t name_len);
-
-/*
- * Create a cache_entry that is not intended to be added to an index. If
- * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
- * pool. Caller is responsible for discarding "loose" entries with
- * `discard_cache_entry()` and the memory pool with
- * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
- */
-struct cache_entry *make_transient_cache_entry(unsigned int mode,
-					       const struct object_id *oid,
-					       const char *path,
-					       int stage,
-					       struct mem_pool *ce_mem_pool);
-
-struct cache_entry *make_empty_transient_cache_entry(size_t len,
-						     struct mem_pool *ce_mem_pool);
-
-/*
- * Discard cache entry.
- */
-void discard_cache_entry(struct cache_entry *ce);
-
-/*
- * Check configuration if we should perform extra validation on cache
- * entries.
- */
-int should_validate_cache_entries(void);
-
-/*
- * Duplicate a cache_entry. Allocate memory for the new entry from a
- * memory_pool. Takes into account cache_entry fields that are meant
- * for managing the underlying memory allocation of the cache_entry.
- */
-struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
-
-/*
- * Validate the cache entries in the index.  This is an internal
- * consistency check that the cache_entry structs are allocated from
- * the expected memory pool.
- */
-void validate_cache_entries(const struct index_state *istate);
-
-/*
- * Bulk prefetch all missing cache entries that are not GITLINKs and that match
- * the given predicate. This function should only be called if
- * repo_has_promisor_remote() returns true.
- */
-typedef int (*must_prefetch_predicate)(const struct cache_entry *);
-void prefetch_cache_entries(const struct index_state *istate,
-			    must_prefetch_predicate must_prefetch);
-
-/* Initialize and use the cache information */
-struct lock_file;
-int do_read_index(struct index_state *istate, const char *path,
-		  int must_exist); /* for testting only! */
-int read_index_from(struct index_state *, const char *path,
-		    const char *gitdir);
-int is_index_unborn(struct index_state *);
-
-/* For use with `write_locked_index()`. */
-#define COMMIT_LOCK		(1 << 0)
-#define SKIP_IF_UNCHANGED	(1 << 1)
-
-/*
- * Write the index while holding an already-taken lock. Close the lock,
- * and if `COMMIT_LOCK` is given, commit it.
- *
- * Unless a split index is in use, write the index into the lockfile.
- *
- * With a split index, write the shared index to a temporary file,
- * adjust its permissions and rename it into place, then write the
- * split index to the lockfile. If the temporary file for the shared
- * index cannot be created, fall back to the behavior described in
- * the previous paragraph.
- *
- * With `COMMIT_LOCK`, the lock is always committed or rolled back.
- * Without it, the lock is closed, but neither committed nor rolled
- * back.
- *
- * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
- * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
- */
-int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
-
-void discard_index(struct index_state *);
-void move_index_extensions(struct index_state *dst, struct index_state *src);
-int unmerged_index(const struct index_state *);
-
-/**
- * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
- * compares istate to HEAD.  If tree is NULL and on an unborn branch,
- * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
- * provided, the space-separated list of files that differ will be appended
- * to it.
- */
-int repo_index_has_changes(struct repository *repo,
-			   struct tree *tree,
-			   struct strbuf *sb);
-
-int verify_path(const char *path, unsigned mode);
-int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-
-/*
- * Searches for an entry defined by name and namelen in the given index.
- * If the return value is positive (including 0) it is the position of an
- * exact match. If the return value is negative, the negated value minus 1
- * is the position where the entry would be inserted.
- * Example: The current index consists of these files and its stages:
- *
- *   b#0, d#0, f#1, f#3
- *
- * index_name_pos(&index, "a", 1) -> -1
- * index_name_pos(&index, "b", 1) ->  0
- * index_name_pos(&index, "c", 1) -> -2
- * index_name_pos(&index, "d", 1) ->  1
- * index_name_pos(&index, "e", 1) -> -3
- * index_name_pos(&index, "f", 1) -> -3
- * index_name_pos(&index, "g", 1) -> -5
- */
-int index_name_pos(struct index_state *, const char *name, int namelen);
-
-/*
- * Like index_name_pos, returns the position of an entry of the given name in
- * the index if one exists, otherwise returns a negative value where the negated
- * value minus 1 is the position where the index entry would be inserted. Unlike
- * index_name_pos, however, a sparse index is not expanded to find an entry
- * inside a sparse directory.
- */
-int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
-
-/*
- * Determines whether an entry with the given name exists within the
- * given index. The return value is 1 if an exact match is found, otherwise
- * it is 0. Note that, unlike index_name_pos, this function does not expand
- * the index if it is sparse. If an item exists within the full index but it
- * is contained within a sparse directory (and not in the sparse index), 0 is
- * returned.
- */
-int index_entry_exists(struct index_state *, const char *name, int namelen);
-
-/*
- * Some functions return the negative complement of an insert position when a
- * precise match was not found but a position was found where the entry would
- * need to be inserted. This helper protects that logic from any integer
- * underflow.
- */
-static inline int index_pos_to_insert_pos(uintmax_t pos)
-{
-	if (pos > INT_MAX)
-		die("overflow: -1 - %"PRIuMAX, pos);
-	return -1 - (int)pos;
-}
-
-#define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
-#define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
-#define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
-#define ADD_CACHE_JUST_APPEND 8		/* Append only */
-#define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
-#define ADD_CACHE_KEEP_CACHE_TREE 32	/* Do not invalidate cache-tree */
-#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
-int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
-void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
-
-/* Remove entry, return true if there are more entries to go. */
-int remove_index_entry_at(struct index_state *, int pos);
-
-void remove_marked_cache_entries(struct index_state *istate, int invalidate);
-int remove_file_from_index(struct index_state *, const char *path);
-#define ADD_CACHE_VERBOSE 1
-#define ADD_CACHE_PRETEND 2
-#define ADD_CACHE_IGNORE_ERRORS	4
-#define ADD_CACHE_IGNORE_REMOVAL 8
-#define ADD_CACHE_INTENT 16
-/*
- * These two are used to add the contents of the file at path
- * to the index, marking the working tree up-to-date by storing
- * the cached stat info in the resulting cache entry.  A caller
- * that has already run lstat(2) on the path can call
- * add_to_index(), and all others can call add_file_to_index();
- * the latter will do necessary lstat(2) internally before
- * calling the former.
- */
-int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
-int add_file_to_index(struct index_state *, const char *path, int flags);
-
-int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
-int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
-void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
-int index_name_is_other(struct index_state *, const char *, int);
-void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
-
-/* do stat comparison even if CE_VALID is true */
-#define CE_MATCH_IGNORE_VALID		01
-/* do not check the contents but report dirty on racily-clean entries */
-#define CE_MATCH_RACY_IS_DIRTY		02
-/* do stat comparison even if CE_SKIP_WORKTREE is true */
-#define CE_MATCH_IGNORE_SKIP_WORKTREE	04
-/* ignore non-existent files during stat update  */
-#define CE_MATCH_IGNORE_MISSING		0x08
-/* enable stat refresh */
-#define CE_MATCH_REFRESH		0x10
-/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
-#define CE_MATCH_IGNORE_FSMONITOR 0X20
-int is_racy_timestamp(const struct index_state *istate,
-		      const struct cache_entry *ce);
-int has_racy_timestamp(struct index_state *istate);
-int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-
-int match_stat_data_racy(const struct index_state *istate,
-			 const struct stat_data *sd, struct stat *st);
-
-void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
-
-#define REFRESH_REALLY                   (1 << 0) /* ignore_valid */
-#define REFRESH_UNMERGED                 (1 << 1) /* allow unmerged */
-#define REFRESH_QUIET                    (1 << 2) /* be quiet about it */
-#define REFRESH_IGNORE_MISSING           (1 << 3) /* ignore non-existent */
-#define REFRESH_IGNORE_SUBMODULES        (1 << 4) /* ignore submodules */
-#define REFRESH_IN_PORCELAIN             (1 << 5) /* user friendly output, not "needs update" */
-#define REFRESH_PROGRESS                 (1 << 6) /* show progress bar if stderr is tty */
-#define REFRESH_IGNORE_SKIP_WORKTREE     (1 << 7) /* ignore skip_worktree entries */
-int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
-/*
- * Refresh the index and write it to disk.
- *
- * 'refresh_flags' is passed directly to 'refresh_index()', while
- * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
- * the lockfile is always either committed or rolled back.
- *
- * If 'gentle' is passed, errors locking the index are ignored.
- *
- * Return 1 if refreshing the index returns an error, -1 if writing
- * the index to disk fails, 0 on success.
- *
- * Note that if refreshing the index returns an error, we still write
- * out the index (unless locking fails).
- */
-int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg);
-
-struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
-
-void set_alternate_index_output(const char *);
-
-extern int verify_index_checksum;
-extern int verify_ce_order;
-
-int cmp_cache_name_compare(const void *a_, const void *b_);
-
-/* add */
-/*
- * return 0 if success, 1 - if addition of a file failed and
- * ADD_FILES_IGNORE_ERRORS was specified in flags
- */
-int add_files_to_cache(struct repository *repo, const char *prefix,
-		       const struct pathspec *pathspec, int include_sparse,
-		       int flags);
-
-/* ls-files */
-void overlay_tree_on_index(struct index_state *istate,
-			   const char *tree_name, const char *prefix);
 
 #endif /* CACHE_H */
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index a4d11376ba5..fb08475bc64 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -10,6 +10,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "path.h"
+#include "strbuf.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 6adfcfd5405..56729d92dcf 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "hash-ll.h"
 
 int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
 {
diff --git a/config.c b/config.c
index b79baf83e35..06e6cc6f1ec 100644
--- a/config.c
+++ b/config.c
@@ -33,6 +33,7 @@
 #include "replace-object.h"
 #include "refs.h"
 #include "setup.h"
+#include "strvec.h"
 #include "trace2.h"
 #include "worktree.h"
 #include "ws.h"
diff --git a/convert.c b/convert.c
index 7cf7bd0c883..236d5e3dc25 100644
--- a/convert.c
+++ b/convert.c
@@ -9,6 +9,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
+#include "read-cache-ll.h"
 #include "sigchain.h"
 #include "pkt-line.h"
 #include "sub-process.h"
diff --git a/diff-lib.c b/diff-lib.c
index 60e979dc1bd..36cd66ea237 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "read-cache.h"
 #include "revision.h"
 #include "cache-tree.h"
 #include "unpack-trees.h"
diff --git a/diff.c b/diff.c
index 07f140b425f..61b4dc61e1e 100644
--- a/diff.c
+++ b/diff.c
@@ -39,6 +39,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "strmap.h"
 #include "ws.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 5462420bbbe..4909dc088e6 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,9 +1,10 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "object.h"
 #include "promisor-remote.h"
 
 static int should_break(struct repository *r,
diff --git a/environment.h b/environment.h
index a63f0c6a24f..6eca4712e1e 100644
--- a/environment.h
+++ b/environment.h
@@ -1,9 +1,8 @@
 #ifndef ENVIRONMENT_H
 #define ENVIRONMENT_H
 
-#include "strvec.h"
-
 struct repository;
+struct strvec;
 
 /*
  * The character that begins a commented line in user-editable file
diff --git a/fsmonitor.h b/fsmonitor.h
index c67e0ebc09b..8b7a521552a 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -4,6 +4,8 @@
 #include "cache.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
+#include "object.h"
+#include "read-cache-ll.h"
 #include "trace.h"
 
 extern struct trace_key trace_fsmonitor;
diff --git a/git.c b/git.c
index 45899be8265..a1a538fc52e 100644
--- a/git.c
+++ b/git.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "help.h"
 #include "pager.h"
+#include "read-cache-ll.h"
 #include "run-command.h"
 #include "alias.h"
 #include "replace-object.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index bb54dfde9c7..8fec8939fd3 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "hash.h"
 #include "hash-lookup.h"
+#include "read-cache-ll.h"
 
 static uint32_t take2(const struct object_id *oid, size_t ofs)
 {
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a5507533009..a0bedcb63bb 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -3,6 +3,7 @@
 #include "hash.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
+#include "read-cache-ll.h"
 #include "tree.h"
 
 #include "commit.h"
diff --git a/merge-ort.c b/merge-ort.c
index 4bff685e456..5512f40d321 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -37,6 +37,7 @@
 #include "object-store.h"
 #include "oid-array.h"
 #include "promisor-remote.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "sparse-index.h"
 #include "strmap.h"
diff --git a/name-hash.c b/name-hash.c
index 52ce47ea394..f2f3564cb20 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -9,6 +9,8 @@
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
+#include "object.h"
+#include "read-cache-ll.h"
 #include "thread-utils.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/object-name.c b/object-name.c
index 6fc3fa595b8..1eefeef746e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -18,6 +18,7 @@
 #include "packfile.h"
 #include "pretty.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/oidmap.h b/oidmap.h
index c1642927fa6..05c673eb7c1 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,6 +1,7 @@
 #ifndef OIDMAP_H
 #define OIDMAP_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 
 /*
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 69d569f3525..2b1439c0c5f 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -8,6 +8,7 @@
 #include "parallel-checkout.h"
 #include "pkt-line.h"
 #include "progress.h"
+#include "read-cache-ll.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "streaming.h"
diff --git a/pathspec.c b/pathspec.c
index 1e57b6c667d..47d172fe414 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "setup.h"
 #include "strvec.h"
diff --git a/preload-index.c b/preload-index.c
index c26739debf8..d037a951efa 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "preload-index.h"
 #include "progress.h"
+#include "read-cache.h"
 #include "thread-utils.h"
 #include "repository.h"
 #include "symlinks.h"
diff --git a/read-cache-ll.h b/read-cache-ll.h
new file mode 100644
index 00000000000..9a1a7edc5a2
--- /dev/null
+++ b/read-cache-ll.h
@@ -0,0 +1,481 @@
+#ifndef READ_CACHE_LL_H
+#define READ_CACHE_LL_H
+
+#include "hash-ll.h"
+#include "hashmap.h"
+#include "statinfo.h"
+
+/*
+ * Basic data structures for the directory cache
+ */
+
+#define CACHE_SIGNATURE 0x44495243	/* "DIRC" */
+struct cache_header {
+	uint32_t hdr_signature;
+	uint32_t hdr_version;
+	uint32_t hdr_entries;
+};
+
+#define INDEX_FORMAT_LB 2
+#define INDEX_FORMAT_UB 4
+
+struct cache_entry {
+	struct hashmap_entry ent;
+	struct stat_data ce_stat_data;
+	unsigned int ce_mode;
+	unsigned int ce_flags;
+	unsigned int mem_pool_allocated;
+	unsigned int ce_namelen;
+	unsigned int index;	/* for link extension */
+	struct object_id oid;
+	char name[FLEX_ARRAY]; /* more */
+};
+
+#define CE_STAGEMASK (0x3000)
+#define CE_EXTENDED  (0x4000)
+#define CE_VALID     (0x8000)
+#define CE_STAGESHIFT 12
+
+/*
+ * Range 0xFFFF0FFF in ce_flags is divided into
+ * two parts: in-memory flags and on-disk ones.
+ * Flags in CE_EXTENDED_FLAGS will get saved on-disk
+ * if you want to save a new flag, add it in
+ * CE_EXTENDED_FLAGS
+ *
+ * In-memory only flags
+ */
+#define CE_UPDATE            (1 << 16)
+#define CE_REMOVE            (1 << 17)
+#define CE_UPTODATE          (1 << 18)
+#define CE_ADDED             (1 << 19)
+
+#define CE_HASHED            (1 << 20)
+#define CE_FSMONITOR_VALID   (1 << 21)
+#define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
+#define CE_CONFLICTED        (1 << 23)
+
+#define CE_UNPACKED          (1 << 24)
+#define CE_NEW_SKIP_WORKTREE (1 << 25)
+
+/* used to temporarily mark paths matched by pathspecs */
+#define CE_MATCHED           (1 << 26)
+
+#define CE_UPDATE_IN_BASE    (1 << 27)
+#define CE_STRIP_NAME        (1 << 28)
+
+/*
+ * Extended on-disk flags
+ */
+#define CE_INTENT_TO_ADD     (1 << 29)
+#define CE_SKIP_WORKTREE     (1 << 30)
+/* CE_EXTENDED2 is for future extension */
+#define CE_EXTENDED2         (1U << 31)
+
+#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
+
+/*
+ * Safeguard to avoid saving wrong flags:
+ *  - CE_EXTENDED2 won't get saved until its semantic is known
+ *  - Bits in 0x0000FFFF have been saved in ce_flags already
+ *  - Bits in 0x003F0000 are currently in-memory flags
+ */
+#if CE_EXTENDED_FLAGS & 0x803FFFFF
+#error "CE_EXTENDED_FLAGS out of range"
+#endif
+
+/* Forward structure decls */
+struct pathspec;
+struct tree;
+
+/*
+ * Copy the sha1 and stat state of a cache entry from one to
+ * another. But we never change the name, or the hash state!
+ */
+static inline void copy_cache_entry(struct cache_entry *dst,
+				    const struct cache_entry *src)
+{
+	unsigned int state = dst->ce_flags & CE_HASHED;
+	int mem_pool_allocated = dst->mem_pool_allocated;
+
+	/* Don't copy hash chain and name */
+	memcpy(&dst->ce_stat_data, &src->ce_stat_data,
+			offsetof(struct cache_entry, name) -
+			offsetof(struct cache_entry, ce_stat_data));
+
+	/* Restore the hash state */
+	dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
+
+	/* Restore the mem_pool_allocated flag */
+	dst->mem_pool_allocated = mem_pool_allocated;
+}
+
+static inline unsigned create_ce_flags(unsigned stage)
+{
+	return (stage << CE_STAGESHIFT);
+}
+
+#define ce_namelen(ce) ((ce)->ce_namelen)
+#define ce_size(ce) cache_entry_size(ce_namelen(ce))
+#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
+#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
+#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
+#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
+#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
+
+#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
+
+#define SOMETHING_CHANGED	(1 << 0) /* unclassified changes go here */
+#define CE_ENTRY_CHANGED	(1 << 1)
+#define CE_ENTRY_REMOVED	(1 << 2)
+#define CE_ENTRY_ADDED		(1 << 3)
+#define RESOLVE_UNDO_CHANGED	(1 << 4)
+#define CACHE_TREE_CHANGED	(1 << 5)
+#define SPLIT_INDEX_ORDERED	(1 << 6)
+#define UNTRACKED_CHANGED	(1 << 7)
+#define FSMONITOR_CHANGED	(1 << 8)
+
+struct split_index;
+struct untracked_cache;
+struct progress;
+struct pattern_list;
+
+enum sparse_index_mode {
+	/*
+	 * There are no sparse directories in the index at all.
+	 *
+	 * Repositories that don't use cone-mode sparse-checkout will
+	 * always have their indexes in this mode.
+	 */
+	INDEX_EXPANDED = 0,
+
+	/*
+	 * The index has already been collapsed to sparse directories
+	 * whereever possible.
+	 */
+	INDEX_COLLAPSED,
+
+	/*
+	 * The sparse directories that exist are outside the
+	 * sparse-checkout boundary, but it is possible that some file
+	 * entries could collapse to sparse directory entries.
+	 */
+	INDEX_PARTIALLY_SPARSE,
+};
+
+struct index_state {
+	struct cache_entry **cache;
+	unsigned int version;
+	unsigned int cache_nr, cache_alloc, cache_changed;
+	struct string_list *resolve_undo;
+	struct cache_tree *cache_tree;
+	struct split_index *split_index;
+	struct cache_time timestamp;
+	unsigned name_hash_initialized : 1,
+		 initialized : 1,
+		 drop_cache_tree : 1,
+		 updated_workdir : 1,
+		 updated_skipworktree : 1,
+		 fsmonitor_has_run_once : 1;
+	enum sparse_index_mode sparse_index;
+	struct hashmap name_hash;
+	struct hashmap dir_hash;
+	struct object_id oid;
+	struct untracked_cache *untracked;
+	char *fsmonitor_last_update;
+	struct ewah_bitmap *fsmonitor_dirty;
+	struct mem_pool *ce_mem_pool;
+	struct progress *progress;
+	struct repository *repo;
+	struct pattern_list *sparse_checkout_patterns;
+};
+
+/**
+ * A "struct index_state istate" must be initialized with
+ * INDEX_STATE_INIT or the corresponding index_state_init().
+ *
+ * If the variable won't be used again, use release_index() to free()
+ * its resources. If it needs to be used again use discard_index(),
+ * which does the same thing, but will use use index_state_init() at
+ * the end. The discard_index() will use its own "istate->repo" as the
+ * "r" argument to index_state_init() in that case.
+ */
+#define INDEX_STATE_INIT(r) { \
+	.repo = (r), \
+}
+void index_state_init(struct index_state *istate, struct repository *r);
+void release_index(struct index_state *istate);
+
+/* Cache entry creation and cleanup */
+
+/*
+ * Create cache_entry intended for use in the specified index. Caller
+ * is responsible for discarding the cache_entry with
+ * `discard_cache_entry`.
+ */
+struct cache_entry *make_cache_entry(struct index_state *istate,
+				     unsigned int mode,
+				     const struct object_id *oid,
+				     const char *path,
+				     int stage,
+				     unsigned int refresh_options);
+
+struct cache_entry *make_empty_cache_entry(struct index_state *istate,
+					   size_t name_len);
+
+/*
+ * Create a cache_entry that is not intended to be added to an index. If
+ * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
+ * pool. Caller is responsible for discarding "loose" entries with
+ * `discard_cache_entry()` and the memory pool with
+ * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
+ */
+struct cache_entry *make_transient_cache_entry(unsigned int mode,
+					       const struct object_id *oid,
+					       const char *path,
+					       int stage,
+					       struct mem_pool *ce_mem_pool);
+
+struct cache_entry *make_empty_transient_cache_entry(size_t len,
+						     struct mem_pool *ce_mem_pool);
+
+/*
+ * Discard cache entry.
+ */
+void discard_cache_entry(struct cache_entry *ce);
+
+/*
+ * Check configuration if we should perform extra validation on cache
+ * entries.
+ */
+int should_validate_cache_entries(void);
+
+/*
+ * Duplicate a cache_entry. Allocate memory for the new entry from a
+ * memory_pool. Takes into account cache_entry fields that are meant
+ * for managing the underlying memory allocation of the cache_entry.
+ */
+struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
+
+/*
+ * Validate the cache entries in the index.  This is an internal
+ * consistency check that the cache_entry structs are allocated from
+ * the expected memory pool.
+ */
+void validate_cache_entries(const struct index_state *istate);
+
+/*
+ * Bulk prefetch all missing cache entries that are not GITLINKs and that match
+ * the given predicate. This function should only be called if
+ * repo_has_promisor_remote() returns true.
+ */
+typedef int (*must_prefetch_predicate)(const struct cache_entry *);
+void prefetch_cache_entries(const struct index_state *istate,
+			    must_prefetch_predicate must_prefetch);
+
+/* Initialize and use the cache information */
+struct lock_file;
+int do_read_index(struct index_state *istate, const char *path,
+		  int must_exist); /* for testting only! */
+int read_index_from(struct index_state *, const char *path,
+		    const char *gitdir);
+int is_index_unborn(struct index_state *);
+
+/* For use with `write_locked_index()`. */
+#define COMMIT_LOCK		(1 << 0)
+#define SKIP_IF_UNCHANGED	(1 << 1)
+
+/*
+ * Write the index while holding an already-taken lock. Close the lock,
+ * and if `COMMIT_LOCK` is given, commit it.
+ *
+ * Unless a split index is in use, write the index into the lockfile.
+ *
+ * With a split index, write the shared index to a temporary file,
+ * adjust its permissions and rename it into place, then write the
+ * split index to the lockfile. If the temporary file for the shared
+ * index cannot be created, fall back to the behavior described in
+ * the previous paragraph.
+ *
+ * With `COMMIT_LOCK`, the lock is always committed or rolled back.
+ * Without it, the lock is closed, but neither committed nor rolled
+ * back.
+ *
+ * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
+ * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
+ */
+int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
+
+void discard_index(struct index_state *);
+void move_index_extensions(struct index_state *dst, struct index_state *src);
+int unmerged_index(const struct index_state *);
+
+/**
+ * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
+ * compares istate to HEAD.  If tree is NULL and on an unborn branch,
+ * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
+ * provided, the space-separated list of files that differ will be appended
+ * to it.
+ */
+int repo_index_has_changes(struct repository *repo,
+			   struct tree *tree,
+			   struct strbuf *sb);
+
+int verify_path(const char *path, unsigned mode);
+int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
+
+/*
+ * Searches for an entry defined by name and namelen in the given index.
+ * If the return value is positive (including 0) it is the position of an
+ * exact match. If the return value is negative, the negated value minus 1
+ * is the position where the entry would be inserted.
+ * Example: The current index consists of these files and its stages:
+ *
+ *   b#0, d#0, f#1, f#3
+ *
+ * index_name_pos(&index, "a", 1) -> -1
+ * index_name_pos(&index, "b", 1) ->  0
+ * index_name_pos(&index, "c", 1) -> -2
+ * index_name_pos(&index, "d", 1) ->  1
+ * index_name_pos(&index, "e", 1) -> -3
+ * index_name_pos(&index, "f", 1) -> -3
+ * index_name_pos(&index, "g", 1) -> -5
+ */
+int index_name_pos(struct index_state *, const char *name, int namelen);
+
+/*
+ * Like index_name_pos, returns the position of an entry of the given name in
+ * the index if one exists, otherwise returns a negative value where the negated
+ * value minus 1 is the position where the index entry would be inserted. Unlike
+ * index_name_pos, however, a sparse index is not expanded to find an entry
+ * inside a sparse directory.
+ */
+int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
+
+/*
+ * Determines whether an entry with the given name exists within the
+ * given index. The return value is 1 if an exact match is found, otherwise
+ * it is 0. Note that, unlike index_name_pos, this function does not expand
+ * the index if it is sparse. If an item exists within the full index but it
+ * is contained within a sparse directory (and not in the sparse index), 0 is
+ * returned.
+ */
+int index_entry_exists(struct index_state *, const char *name, int namelen);
+
+/*
+ * Some functions return the negative complement of an insert position when a
+ * precise match was not found but a position was found where the entry would
+ * need to be inserted. This helper protects that logic from any integer
+ * underflow.
+ */
+static inline int index_pos_to_insert_pos(uintmax_t pos)
+{
+	if (pos > INT_MAX)
+		die("overflow: -1 - %"PRIuMAX, pos);
+	return -1 - (int)pos;
+}
+
+#define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
+#define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
+#define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
+#define ADD_CACHE_JUST_APPEND 8		/* Append only */
+#define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
+#define ADD_CACHE_KEEP_CACHE_TREE 32	/* Do not invalidate cache-tree */
+#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
+int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
+void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
+
+/* Remove entry, return true if there are more entries to go. */
+int remove_index_entry_at(struct index_state *, int pos);
+
+void remove_marked_cache_entries(struct index_state *istate, int invalidate);
+int remove_file_from_index(struct index_state *, const char *path);
+#define ADD_CACHE_VERBOSE 1
+#define ADD_CACHE_PRETEND 2
+#define ADD_CACHE_IGNORE_ERRORS	4
+#define ADD_CACHE_IGNORE_REMOVAL 8
+#define ADD_CACHE_INTENT 16
+/*
+ * These two are used to add the contents of the file at path
+ * to the index, marking the working tree up-to-date by storing
+ * the cached stat info in the resulting cache entry.  A caller
+ * that has already run lstat(2) on the path can call
+ * add_to_index(), and all others can call add_file_to_index();
+ * the latter will do necessary lstat(2) internally before
+ * calling the former.
+ */
+int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
+int add_file_to_index(struct index_state *, const char *path, int flags);
+
+int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
+int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
+void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
+int index_name_is_other(struct index_state *, const char *, int);
+void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
+
+/* do stat comparison even if CE_VALID is true */
+#define CE_MATCH_IGNORE_VALID		01
+/* do not check the contents but report dirty on racily-clean entries */
+#define CE_MATCH_RACY_IS_DIRTY		02
+/* do stat comparison even if CE_SKIP_WORKTREE is true */
+#define CE_MATCH_IGNORE_SKIP_WORKTREE	04
+/* ignore non-existent files during stat update  */
+#define CE_MATCH_IGNORE_MISSING		0x08
+/* enable stat refresh */
+#define CE_MATCH_REFRESH		0x10
+/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
+#define CE_MATCH_IGNORE_FSMONITOR 0X20
+int is_racy_timestamp(const struct index_state *istate,
+		      const struct cache_entry *ce);
+int has_racy_timestamp(struct index_state *istate);
+int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
+int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
+
+int match_stat_data_racy(const struct index_state *istate,
+			 const struct stat_data *sd, struct stat *st);
+
+void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
+
+#define REFRESH_REALLY                   (1 << 0) /* ignore_valid */
+#define REFRESH_UNMERGED                 (1 << 1) /* allow unmerged */
+#define REFRESH_QUIET                    (1 << 2) /* be quiet about it */
+#define REFRESH_IGNORE_MISSING           (1 << 3) /* ignore non-existent */
+#define REFRESH_IGNORE_SUBMODULES        (1 << 4) /* ignore submodules */
+#define REFRESH_IN_PORCELAIN             (1 << 5) /* user friendly output, not "needs update" */
+#define REFRESH_PROGRESS                 (1 << 6) /* show progress bar if stderr is tty */
+#define REFRESH_IGNORE_SKIP_WORKTREE     (1 << 7) /* ignore skip_worktree entries */
+int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
+/*
+ * Refresh the index and write it to disk.
+ *
+ * 'refresh_flags' is passed directly to 'refresh_index()', while
+ * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
+ * the lockfile is always either committed or rolled back.
+ *
+ * If 'gentle' is passed, errors locking the index are ignored.
+ *
+ * Return 1 if refreshing the index returns an error, -1 if writing
+ * the index to disk fails, 0 on success.
+ *
+ * Note that if refreshing the index returns an error, we still write
+ * out the index (unless locking fails).
+ */
+int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg);
+
+struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
+
+void set_alternate_index_output(const char *);
+
+extern int verify_index_checksum;
+extern int verify_ce_order;
+
+int cmp_cache_name_compare(const void *a_, const void *b_);
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags);
+
+void overlay_tree_on_index(struct index_state *istate,
+			   const char *tree_name, const char *prefix);
+
+#endif /* READ_CACHE_LL_H */
diff --git a/read-cache.c b/read-cache.c
index 3fad839fb6f..42f27b06642 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -28,6 +28,7 @@
 #include "name-hash.h"
 #include "object-name.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/read-cache.h b/read-cache.h
new file mode 100644
index 00000000000..043da1f1aae
--- /dev/null
+++ b/read-cache.h
@@ -0,0 +1,45 @@
+#ifndef READ_CACHE_H
+#define READ_CACHE_H
+
+#include "read-cache-ll.h"
+#include "object.h"
+#include "pathspec.h"
+
+static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
+					     unsigned int mode)
+{
+	extern int trust_executable_bit, has_symlinks;
+	if (!has_symlinks && S_ISREG(mode) &&
+	    ce && S_ISLNK(ce->ce_mode))
+		return ce->ce_mode;
+	if (!trust_executable_bit && S_ISREG(mode)) {
+		if (ce && S_ISREG(ce->ce_mode))
+			return ce->ce_mode;
+		return create_ce_mode(0666);
+	}
+	return create_ce_mode(mode);
+}
+
+static inline int ce_to_dtype(const struct cache_entry *ce)
+{
+	unsigned ce_mode = ntohl(ce->ce_mode);
+	if (S_ISREG(ce_mode))
+		return DT_REG;
+	else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
+		return DT_DIR;
+	else if (S_ISLNK(ce_mode))
+		return DT_LNK;
+	else
+		return DT_UNKNOWN;
+}
+
+static inline int ce_path_match(struct index_state *istate,
+				const struct cache_entry *ce,
+				const struct pathspec *pathspec,
+				char *seen)
+{
+	return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
+			      S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
+}
+
+#endif /* READ_CACHE_H */
diff --git a/repository.c b/repository.c
index c53e480e326..ebad755c2cc 100644
--- a/repository.c
+++ b/repository.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
+#include "read-cache-ll.h"
 #include "remote.h"
 #include "setup.h"
 #include "submodule-config.h"
diff --git a/rerere.c b/rerere.c
index e968d413d65..3bc9aedc286 100644
--- a/rerere.c
+++ b/rerere.c
@@ -7,6 +7,7 @@
 #include "hex.h"
 #include "lockfile.h"
 #include "string-list.h"
+#include "read-cache-ll.h"
 #include "rerere.h"
 #include "xdiff-interface.h"
 #include "dir.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 7ec09e89d4f..59598877841 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "hash.h"
+#include "read-cache.h"
 #include "resolve-undo.h"
 #include "sparse-index.h"
 #include "string-list.h"
diff --git a/revision.c b/revision.c
index 88b2f42daa6..8d37ec9f495 100644
--- a/revision.c
+++ b/revision.c
@@ -31,6 +31,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "strvec.h"
diff --git a/split-index.c b/split-index.c
index 40e54760b35..0a8d3903d6f 100644
--- a/split-index.c
+++ b/split-index.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "hash.h"
 #include "mem-pool.h"
+#include "read-cache-ll.h"
 #include "split-index.h"
 #include "strbuf.h"
 #include "ewah/ewok.h"
diff --git a/submodule.c b/submodule.c
index 2e78f513496..e09722d6be3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -28,6 +28,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "commit-reach.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "shallow.h"
 #include "trace2.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9507b356e22..9d64422b3cc 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index f22f7bd84a9..78aa11bb194 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -5,6 +5,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 9a098a25cba..e4357d65ec5 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 63fde9157c4..59a24a842b4 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "split-index.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index df70be549fd..a1cbafd64f3 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index d1d63feaa9e..cbcf2419f9b 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -21,6 +21,7 @@
 #include "lockfile.h"
 #include "merge-ort.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 9f18c685b7f..386f4cdaee5 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "thread-utils.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index f40d9ad0c2d..c1e82d5d028 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 #define NUM_SECONDS 3
 
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index a06c45c1f84..b3cbaf6d2a8 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "read-cache-ll.h"
 
 int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
 {
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 6944b7e825f..8eb327b3b93 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "name-hash.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "trace.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 2ef53d5f7a2..90e4d29a06f 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -3,6 +3,7 @@
 #include "abspath.h"
 #include "environment.h"
 #include "path.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "string-list.h"
 #include "trace.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index c1ae2763954..0d548814e08 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "wrapper.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 6e17f50d225..7b7e2384043 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "tree.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index 71fe5c61455..dc6fb17f2a7 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 int cmd__sha1(int ac, const char **av)
 {
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 0ac6a99d5f2..f50f64f1f22 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 int cmd__sha256(int ac, const char **av)
 {
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index 96b9a5b5291..d3f39207f14 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "read-cache-ll.h"
 
 int cmd__strcmp_offset(int argc UNUSED, const char **argv)
 {
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index eace08072d7..d27125eeacf 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/unpack-trees.c b/unpack-trees.c
index 078c53f7a13..fdcc46e474f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -15,6 +15,7 @@
 #include "progress.h"
 #include "refs.h"
 #include "attr.h"
+#include "read-cache.h"
 #include "split-index.h"
 #include "sparse-index.h"
 #include "submodule.h"
diff --git a/unpack-trees.h b/unpack-trees.h
index 30622aeebff..9b827c307f6 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -1,8 +1,8 @@
 #ifndef UNPACK_TREES_H
 #define UNPACK_TREES_H
 
-#include "cache.h"
 #include "convert.h"
+#include "read-cache-ll.h"
 #include "strvec.h"
 #include "string-list.h"
 #include "tree-walk.h"
diff --git a/wt-status.c b/wt-status.c
index 068b76ef6d9..847b63c906e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -18,6 +18,7 @@
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "strbuf.h"
 #include "trace.h"
-- 
gitgitgadget


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

* [PATCH v2 17/27] cache.h: remove this no-longer-used header
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (15 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 16/27] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-16  0:02     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 18/27] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
                     ` (10 subsequent siblings)
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Since this header showed up in some places besides just #include
statements, update/clean-up/remove those other places as well.

Note that compat/fsmonitor/fsm-path-utils-darwin.c previously got
away with violating the rule that all files must start with an include
of git-compat-util.h (or a short-list of alternate headers that happen
to include it first).  This change exposed the violation and caused it
to stop building correctly; fix it by having it include
git-compat-util.h first, as per policy.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/CodingGuidelines           |  2 +-
 Documentation/MyFirstObjectWalk.txt      |  2 +-
 Documentation/user-manual.txt            | 18 ++++++++----------
 Makefile                                 |  2 +-
 add-interactive.c                        |  2 +-
 add-patch.c                              |  2 +-
 apply.c                                  |  2 +-
 attr.c                                   |  2 +-
 blame.c                                  |  2 +-
 builtin.h                                |  1 -
 builtin/add.c                            |  3 +--
 builtin/am.c                             |  3 +--
 builtin/apply.c                          |  1 -
 builtin/archive.c                        |  1 -
 builtin/bisect.c                         |  1 -
 builtin/branch.c                         |  3 +--
 builtin/bundle.c                         |  1 -
 builtin/cat-file.c                       |  3 +--
 builtin/check-attr.c                     |  1 -
 builtin/check-ignore.c                   |  1 -
 builtin/check-ref-format.c               |  3 +--
 builtin/clean.c                          |  1 -
 builtin/column.c                         |  1 -
 builtin/commit-tree.c                    |  3 +--
 builtin/commit.c                         |  3 +--
 builtin/count-objects.c                  |  3 +--
 builtin/describe.c                       |  3 +--
 builtin/diff-files.c                     |  3 +--
 builtin/diff-index.c                     |  3 +--
 builtin/diff-tree.c                      |  3 +--
 builtin/diff.c                           |  3 +--
 builtin/difftool.c                       |  3 +--
 builtin/fast-export.c                    |  1 -
 builtin/fast-import.c                    |  1 -
 builtin/fetch.c                          |  3 +--
 builtin/for-each-ref.c                   |  1 -
 builtin/for-each-repo.c                  |  3 +--
 builtin/fsck.c                           |  1 -
 builtin/get-tar-commit-id.c              |  3 +--
 builtin/grep.c                           |  3 +--
 builtin/help.c                           |  3 +--
 builtin/hook.c                           |  1 -
 builtin/init-db.c                        |  3 +--
 builtin/interpret-trailers.c             |  1 -
 builtin/ls-files.c                       |  3 +--
 builtin/ls-remote.c                      |  1 -
 builtin/ls-tree.c                        |  3 +--
 builtin/mailinfo.c                       |  3 +--
 builtin/mailsplit.c                      |  1 -
 builtin/merge-base.c                     |  1 -
 builtin/merge-file.c                     |  1 -
 builtin/merge-recursive.c                |  1 -
 builtin/merge.c                          |  3 +--
 builtin/multi-pack-index.c               |  1 -
 builtin/notes.c                          |  3 +--
 builtin/patch-id.c                       |  1 -
 builtin/prune.c                          |  3 +--
 builtin/pull.c                           |  3 +--
 builtin/push.c                           |  3 +--
 builtin/range-diff.c                     |  1 -
 builtin/read-tree.c                      |  3 +--
 builtin/replace.c                        |  3 +--
 builtin/rerere.c                         |  1 -
 builtin/rev-list.c                       |  3 +--
 builtin/rev-parse.c                      |  3 +--
 builtin/shortlog.c                       |  1 -
 builtin/show-branch.c                    |  3 +--
 builtin/show-index.c                     |  1 -
 builtin/show-ref.c                       |  1 -
 builtin/sparse-checkout.c                |  1 -
 builtin/stripspace.c                     |  1 -
 builtin/submodule--helper.c              |  1 -
 builtin/symbolic-ref.c                   |  1 -
 builtin/tag.c                            |  3 +--
 builtin/unpack-objects.c                 |  1 -
 builtin/update-index.c                   |  3 +--
 builtin/update-ref.c                     |  3 +--
 builtin/update-server-info.c             |  3 +--
 builtin/upload-archive.c                 |  1 -
 builtin/upload-pack.c                    |  1 -
 builtin/verify-commit.c                  |  3 +--
 builtin/verify-pack.c                    |  1 -
 builtin/verify-tag.c                     |  3 +--
 builtin/worktree.c                       |  3 +--
 builtin/write-tree.c                     |  1 -
 cache-tree.c                             |  2 +-
 cache.h                                  |  6 ------
 compat/fsmonitor/fsm-health-win32.c      |  2 +-
 compat/fsmonitor/fsm-listen-win32.c      |  2 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |  1 +
 compat/fsmonitor/fsm-path-utils-win32.c  |  2 +-
 compat/fsmonitor/fsm-settings-win32.c    |  2 +-
 compat/mingw.c                           |  1 -
 compat/precompose_utf8.c                 |  2 +-
 compat/sha1-chunked.c                    |  2 +-
 compat/simple-ipc/ipc-win32.c            |  2 +-
 compat/win32/trace2_win32_process_info.c |  2 +-
 convert.c                                |  2 +-
 diff-lib.c                               |  2 +-
 diff.c                                   |  2 +-
 entry.c                                  |  2 +-
 environment.c                            |  2 +-
 fsmonitor-ipc.c                          |  2 +-
 fsmonitor.c                              |  2 +-
 fsmonitor.h                              |  1 -
 hash-lookup.c                            |  2 +-
 merge-ort-wrappers.c                     |  2 +-
 merge-ort.c                              |  2 +-
 merge-recursive.c                        |  2 +-
 merge.c                                  |  2 +-
 name-hash.c                              |  2 +-
 object-name.c                            |  2 +-
 object.c                                 |  2 +-
 parallel-checkout.c                      |  2 +-
 pathspec.c                               |  2 +-
 preload-index.c                          |  2 +-
 read-cache.c                             |  2 +-
 refs/files-backend.c                     |  2 +-
 refs/packed-backend.c                    |  2 +-
 repository.c                             |  2 +-
 rerere.c                                 |  2 +-
 resolve-undo.c                           |  2 +-
 revision.c                               |  2 +-
 run-command.h                            |  2 +-
 sequencer.c                              |  2 +-
 shallow.c                                |  2 +-
 sparse-index.c                           |  2 +-
 split-index.c                            |  2 +-
 strbuf.h                                 |  4 ----
 submodule.c                              |  2 +-
 t/helper/test-cache-tree.c               |  1 -
 t/helper/test-dump-cache-tree.c          |  1 -
 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-hash-speed.c               |  1 -
 t/helper/test-index-version.c            |  1 -
 t/helper/test-lazy-init-name-hash.c      |  1 -
 t/helper/test-path-utils.c               |  1 -
 t/helper/test-read-cache.c               |  1 -
 t/helper/test-scrap-cache-tree.c         |  1 -
 t/helper/test-sha1.c                     |  1 -
 t/helper/test-sha256.c                   |  1 -
 t/helper/test-strcmp-offset.c            |  1 -
 t/helper/test-write-cache.c              |  1 -
 unpack-trees.c                           |  2 +-
 wt-status.c                              |  2 +-
 149 files changed, 99 insertions(+), 205 deletions(-)
 delete mode 100644 cache.h

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 003393ed161..2b472df29d5 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -444,7 +444,7 @@ For C programs:
  - The first #include in C files, except in platform specific compat/
    implementations and sha1dc/, must be either "git-compat-util.h" or
    one of the approved headers that includes it first for you.  (The
-   approved headers currently include "cache.h", "builtin.h",
+   approved headers currently include "builtin.h",
    "t/helper/test-tool.h", "xdiff/xinclude.h", or
    "reftable/system.h").  You do not have to include more than one of
    these.
diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index eee513e86f4..200e628e301 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -124,7 +124,7 @@ parameters provided by the user over the CLI.
 
 `nr` represents the number of `rev_cmdline_entry` present in the array.
 
-`alloc` is used by the `ALLOC_GROW` macro. Check `cache.h` - this variable is
+`alloc` is used by the `ALLOC_GROW` macro. Check `alloc.h` - this variable is
 used to track the allocated size of the list.
 
 Per entry, we find:
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index dc9c6a663a9..100630ba3d2 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -4102,13 +4102,11 @@ Note that terminology has changed since that revision.  For example, the
 README in that revision uses the word "changeset" to describe what we
 now call a <<def_commit_object,commit>>.
 
-Also, we do not call it "cache" any more, but rather "index"; however, the
-file is still called `cache.h`.  Remark: Not much reason to change it now,
-especially since there is no good single name for it anyway, because it is
-basically _the_ header file which is included by _all_ of Git's C sources.
+Also, we do not call it "cache" any more, but rather "index"; however,
+the file is still called `read-cache.h`.
 
 If you grasp the ideas in that initial commit, you should check out a
-more recent version and skim `cache.h`, `object.h` and `commit.h`.
+more recent version and skim `read-cache-ll.h`, `object.h` and `commit.h`.
 
 In the early days, Git (in the tradition of UNIX) was a bunch of programs
 which were extremely simple, and which you used in scripts, piping the
@@ -4119,11 +4117,11 @@ many of these parts have become builtins, and some of the core has been
 and to avoid code duplication.
 
 By now, you know what the index is (and find the corresponding data
-structures in `cache.h`), and that there are just a couple of object types
-(blobs, trees, commits and tags) which inherit their common structure from
-`struct object`, which is their first member (and thus, you can cast e.g.
-`(struct object *)commit` to achieve the _same_ as `&commit->object`, i.e.
-get at the object name and flags).
+structures in `read-cache-ll.h`), and that there are just a couple of
+object types (blobs, trees, commits and tags) which inherit their
+common structure from `struct object`, which is their first member
+(and thus, you can cast e.g.  `(struct object *)commit` to achieve the
+_same_ as `&commit->object`, i.e.  get at the object name and flags).
 
 Now is a good point to take a break to let this information sink in.
 
diff --git a/Makefile b/Makefile
index cbc7f212016..2d180abc5ca 100644
--- a/Makefile
+++ b/Makefile
@@ -1952,7 +1952,7 @@ endif
 	BASIC_CFLAGS += \
 		-DSHA1DC_NO_STANDARD_INCLUDES \
 		-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
-		-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
+		-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"git-compat-util.h\"" \
 		-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
 endif
 endif
diff --git a/add-interactive.c b/add-interactive.c
index a9671e33491..40f88c02051 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "add-interactive.h"
 #include "color.h"
 #include "config.h"
diff --git a/add-patch.c b/add-patch.c
index 7d4d298286d..875b96e2274 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "add-interactive.h"
 #include "advice.h"
 #include "alloc.h"
diff --git a/apply.c b/apply.c
index f056c8f3bb9..e44a5dd7c50 100644
--- a/apply.c
+++ b/apply.c
@@ -7,7 +7,7 @@
  *
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "base85.h"
diff --git a/attr.c b/attr.c
index 57c813d8e77..5a32bfadb37 100644
--- a/attr.c
+++ b/attr.c
@@ -6,7 +6,7 @@
  * an insanely large number of attributes.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/blame.c b/blame.c
index a29ae7c14b2..15bbf16057a 100644
--- a/blame.c
+++ b/blame.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "refs.h"
 #include "object-store.h"
 #include "cache-tree.h"
diff --git a/builtin.h b/builtin.h
index cb0db676814..3e6c22eef69 100644
--- a/builtin.h
+++ b/builtin.h
@@ -3,7 +3,6 @@
 
 #include "git-compat-util.h"
 #include "strbuf.h"
-#include "cache.h"
 #include "commit.h"
 
 /*
diff --git a/builtin/add.c b/builtin/add.c
index 9fe6b6ce290..50792c0d495 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,10 +4,9 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "lockfile.h"
 #include "editor.h"
 #include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 0d8f46f8d5a..2f0f2337915 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,11 +4,10 @@
  * Based on git-am.sh by Junio C Hamano.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "editor.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/builtin/apply.c b/builtin/apply.c
index e3ff02a09e3..c18b7ea5d3d 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/archive.c b/builtin/archive.c
index b0eaa3c14a3..90761fdfee0 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -2,7 +2,6 @@
  * Copyright (c) 2006 Franck Bui-Huu
  * Copyright (c) 2006 Rene Scharfe
  */
-#include "cache.h"
 #include "builtin.h"
 #include "archive.h"
 #include "gettext.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 4812450c393..bce0ee6268a 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "copy.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 501c47657c9..5e9b0e4ea44 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -5,14 +5,13 @@
  * Based on git-branch.sh by Junio C Hamano.
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "color.h"
 #include "editor.h"
 #include "environment.h"
 #include "refs.h"
 #include "commit.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "remote.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 44113389d7a..3f63631c039 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -6,7 +6,6 @@
 #include "parse-options.h"
 #include "pkt-line.h"
 #include "repository.h"
-#include "cache.h"
 #include "bundle.h"
 
 /*
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 0bafc14e6c0..9646e7209ca 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -4,11 +4,10 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "alloc.h"
 #include "config.h"
 #include "convert.h"
-#include "builtin.h"
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index b2b678847f5..869c04420d3 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "attr.h"
 #include "environment.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index e4b78782a32..906cd967536 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 57f0505070f..5eb6bdc3f69 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -2,9 +2,8 @@
  * GIT - The information manager from hell
  */
 
-#include "cache.h"
-#include "refs.h"
 #include "builtin.h"
+#include "refs.h"
 #include "setup.h"
 #include "strbuf.h"
 
diff --git a/builtin/clean.c b/builtin/clean.c
index 49c7af45b03..66b4479356d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -9,7 +9,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/column.c b/builtin/column.c
index de623a16c2d..ce13ff0baa2 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d1d251c3ded..d2121f30d45 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -12,7 +12,6 @@
 #include "repository.h"
 #include "commit.h"
 #include "tree.h"
-#include "builtin.h"
 #include "utf8.h"
 #include "gpg-interface.h"
 #include "parse-options.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 5be05c9d9e1..3b90cb748cd 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,7 +6,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "lockfile.h"
@@ -15,7 +15,6 @@
 #include "dir.h"
 #include "editor.h"
 #include "environment.h"
-#include "builtin.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "commit.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index f3d8f1bcbb0..b9e6b55a9a9 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -4,13 +4,12 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "repository.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index f1be7c36948..508e8df00ef 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,5 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -9,7 +9,6 @@
 #include "tag.h"
 #include "blob.h"
 #include "refs.h"
-#include "builtin.h"
 #include "exec-cmd.h"
 #include "object-name.h"
 #include "parse-options.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index 2e6b59a8bb3..b7036aa7c2b 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -3,14 +3,13 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
 #include "revision.h"
-#include "builtin.h"
 #include "submodule.h"
 
 static const char diff_files_usage[] =
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 9b98db2e77e..1ab8f8b6dc5 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
 #include "revision.h"
-#include "builtin.h"
 #include "setup.h"
 #include "submodule.h"
 
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 5a1e5d6df7c..3e281150473 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,12 +1,11 @@
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "gettext.h"
 #include "hex.h"
 #include "log-tree.h"
-#include "builtin.h"
 #include "submodule.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index a9ce701ff97..b19530c996c 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "ewah/ewok.h"
 #include "lockfile.h"
@@ -20,7 +20,6 @@
 #include "read-cache-ll.h"
 #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 88809976c53..4a22de3eddb 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -12,11 +12,10 @@
  * Copyright (C) 2016 Johannes Schindelin
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "copy.h"
-#include "builtin.h"
 #include "run-command.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9a95f6a1a82..5f3ffd6912f 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2007 Johannes E. Schindelin
  */
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index bbd9b2b3e71..67a2260a5eb 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4d7c2897528..cbc991086cd 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1,7 +1,7 @@
 /*
  * "git fetch"
  */
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "gettext.h"
@@ -15,7 +15,6 @@
 #include "oidset.h"
 #include "oid-array.h"
 #include "commit.h"
-#include "builtin.h"
 #include "string-list.h"
 #include "remote.h"
 #include "transport.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 695fc8f4a5e..d0d6ab0fd34 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "refs.h"
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 37daf7bec14..28186b30f54 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e8c5fbca58f..f05617ceb14 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 564cfcac4fb..9303e386cc7 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -1,10 +1,9 @@
 /*
  * Copyright (c) 2005, 2006 Rene Scharfe
  */
-#include "cache.h"
+#include "builtin.h"
 #include "commit.h"
 #include "tar.h"
-#include "builtin.h"
 #include "quote.h"
 #include "wrapper.h"
 
diff --git a/builtin/grep.c b/builtin/grep.c
index 0d567575890..7638d779000 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-#include "cache.h"
+#include "builtin.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hex.h"
@@ -14,7 +14,6 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree-walk.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/builtin/help.c b/builtin/help.c
index d3cf4af3f6e..e93533fb09e 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -1,9 +1,8 @@
 /*
  * Builtin help command
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "pager.h"
diff --git a/builtin/hook.c b/builtin/hook.c
index 88051795c7f..09b51a6487c 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index feb019a9dea..680ef7e1837 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -3,12 +3,11 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
-#include "builtin.h"
 #include "object-file.h"
 #include "parse-options.h"
 #include "path.h"
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
index 107ac28f0e8..c5e83452654 100644
--- a/builtin/interpret-trailers.c
+++ b/builtin/interpret-trailers.c
@@ -5,7 +5,6 @@
  *
  */
 
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index d8c1c62bcb0..a49c43864f7 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -5,13 +5,12 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "repository.h"
 #include "config.h"
 #include "convert.h"
 #include "quote.h"
 #include "dir.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "strbuf.h"
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index cb6cb77e086..a0aadc9b8ff 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "transport.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 077977a4610..f4331c640fc 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -13,7 +13,6 @@
 #include "tree.h"
 #include "commit.h"
 #include "quote.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "pathspec.h"
 
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index a032a1c3881..53b55dd71c0 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -2,9 +2,8 @@
  * Another stupid program, this one parsing the headers of an
  * email to figure out authorship and subject
  */
-#include "cache.h"
-#include "abspath.h"
 #include "builtin.h"
+#include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 0b6193a0915..3af9ddb8ae5 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -4,7 +4,6 @@
  * It just splits a mbox into a list of files: "0001" "0002" ..
  * so you can process them further from there.
  */
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "string-list.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 854019a32dc..e68b7fe45d7 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "gettext.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 781818d08f5..d7eb4c65401 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "setup.h"
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index b9e980384a4..3366699657c 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "advice.h"
 #include "commit.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 6e8f7b9bb53..d7ac108ce94 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,7 +7,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
 #include "alloc.h"
@@ -18,7 +18,6 @@
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
-#include "builtin.h"
 #include "lockfile.h"
 #include "run-command.h"
 #include "hook.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 1b5083f8b26..5bb71bce08d 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index d5788352b6e..efdf2451486 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -7,9 +7,8 @@
  * and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
  */
 
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "editor.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 9d5585d3a72..27952f1a6fd 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index 5dc9b207200..b3658b5b512 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
 #include "commit.h"
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
-#include "builtin.h"
 #include "reachable.h"
 #include "parse-options.h"
 #include "progress.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 8aeb5abc7fb..d4261804d76 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -6,10 +6,9 @@
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
 #include "merge.h"
diff --git a/builtin/push.c b/builtin/push.c
index 4e5780dd50d..62d44736500 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -1,7 +1,7 @@
 /*
  * "git push"
  */
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "branch.h"
 #include "config.h"
@@ -10,7 +10,6 @@
 #include "refs.h"
 #include "refspec.h"
 #include "run-command.h"
-#include "builtin.h"
 #include "remote.h"
 #include "transport.h"
 #include "parse-options.h"
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 04339a92ea5..8610390d7c5 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index bd1ce1d963f..63c92936faa 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,7 +5,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -17,7 +17,6 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "dir.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "resolve-undo.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 981f1894436..e0fbdc98ed3 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -8,9 +8,8 @@
  * git-tag.sh and mktag.c by Linus Torvalds.
  */
 
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "editor.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index d4bd52797f4..0458db9cadf 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 6dc8be492a2..8029f3de53c 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
@@ -15,7 +15,6 @@
 #include "object-store.h"
 #include "pack.h"
 #include "pack-bitmap.h"
-#include "builtin.h"
 #include "log-tree.h"
 #include "graph.h"
 #include "bisect.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index ad93e5fad88..8d8c870421d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,7 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
@@ -14,7 +14,6 @@
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
-#include "builtin.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "diff.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 46f4e0832ac..99be9dc417d 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 7ef4a642c17..cd215f89af8 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -6,7 +6,6 @@
 #include "hex.h"
 #include "pretty.h"
 #include "refs.h"
-#include "builtin.h"
 #include "color.h"
 #include "strvec.h"
 #include "object-name.h"
diff --git a/builtin/show-index.c b/builtin/show-index.c
index d839e55335d..540dc3dad1c 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hash.h"
 #include "hex.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index a2243b42195..e07e9ca862f 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 40d420f06cb..5c8ffb1f759 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 9451eb69ff4..397d7fe2dcd 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 86324b829a7..17567d91c88 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -6,7 +6,6 @@
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
-#include "cache.h"
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 10198a74fae..a61fa3c0f81 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,6 +1,5 @@
 #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 1850a6a6fdc..ce298d08945 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -6,10 +6,9 @@
  * Based on git-tag.sh and mktag.c by Linus Torvalds.
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "editor.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 2c52c3a741f..85baf6a131a 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
 #include "environment.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 484a307df50..aee3cb8cbd3 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -4,7 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "bulk-checkin.h"
 #include "config.h"
 #include "environment.h"
@@ -15,7 +15,6 @@
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
-#include "builtin.h"
 #include "object-file.h"
 #include "refs.h"
 #include "resolve-undo.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0c59b1c9eff..242102273ee 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hash.h"
 #include "refs.h"
-#include "builtin.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 19dce3c0655..1dc3971edeb 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "server-info.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index 44ad400e183..d4c7f162ff0 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -1,7 +1,6 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
-#include "cache.h"
 #include "builtin.h"
 #include "archive.h"
 #include "pkt-line.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index beb9dd08610..ba5103a9331 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "exec-cmd.h"
 #include "gettext.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 5d99b82a64f..aa34fb896ac 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -5,9 +5,8 @@
  *
  * Based on git-verify-tag
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index 190fd695409..aba92cf8af7 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "run-command.h"
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index c6019a0ad8c..d8753270ebe 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -5,9 +5,8 @@
  *
  * Based on git-verify-tag.sh
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "tag.h"
 #include "run-command.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 3c3d97ad5b0..b9a84988637 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "checkout.h"
 #include "config.h"
 #include "copy.h"
-#include "builtin.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index f98d54c1df2..5917085f429 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,7 +5,6 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/cache-tree.c b/cache-tree.c
index 153217b47ff..077932c2db5 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "environment.h"
 #include "hex.h"
diff --git a/cache.h b/cache.h
deleted file mode 100644
index 9b4e8d16874..00000000000
--- a/cache.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef CACHE_H
-#define CACHE_H
-
-#include "git-compat-util.h"
-
-#endif /* CACHE_H */
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index fe11bdd9ce6..6c81d7ee5c2 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsm-health.h"
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 677b1bbdeca..3c0df5cff8c 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsm-listen.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index 45eb4a9b9e7..ef0142e0fbf 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c
index 4024baafb97..27bb6945183 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index a8af31b71de..37288978643 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "repository.h"
 #include "fsmonitor.h"
diff --git a/compat/mingw.c b/compat/mingw.c
index d06cdc6254f..559abb1c617 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -6,7 +6,6 @@
 #include <wchar.h>
 #include "../strbuf.h"
 #include "../run-command.h"
-#include "../cache.h"
 #include "../abspath.h"
 #include "../alloc.h"
 #include "win32/lazyload.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index fb08475bc64..0bd5c24250a 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -5,7 +5,7 @@
 
 #define PRECOMPOSE_UNICODE_C
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 56729d92dcf..a4a6f930d7b 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hash-ll.h"
 
 int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 6adce3c650e..8bfe51248e5 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index a4e33768f43..a2b1506f9c9 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,4 +1,4 @@
-#include "../../cache.h"
+#include "../../git-compat-util.h"
 #include "../../json-writer.h"
 #include "../../repository.h"
 #include "../../trace2.h"
diff --git a/convert.c b/convert.c
index 236d5e3dc25..9e89f660308 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
 #include "convert.h"
diff --git a/diff-lib.c b/diff-lib.c
index 36cd66ea237..f3aa7f93c78 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "quote.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/diff.c b/diff.c
index 61b4dc61e1e..5e81dc0d02d 100644
--- a/diff.c
+++ b/diff.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "base85.h"
diff --git a/entry.c b/entry.c
index 53d00386748..041f5cf212d 100644
--- a/entry.c
+++ b/entry.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
diff --git a/environment.c b/environment.c
index 28d18eaca8e..0cdd20a1589 100644
--- a/environment.c
+++ b/environment.c
@@ -110,7 +110,7 @@ char *git_work_tree_cfg;
 static char *git_namespace;
 
 /*
- * Repository-local GIT_* environment variables; see cache.h for details.
+ * Repository-local GIT_* environment variables; see environment.h for details.
  */
 const char * const local_repo_env[] = {
 	ALTERNATE_DB_ENVIRONMENT,
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6a6a89764a6..6ace978a1b4 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/fsmonitor.c b/fsmonitor.c
index 28c083d4d84..f670c509378 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/fsmonitor.h b/fsmonitor.h
index 8b7a521552a..7702301d214 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,7 +1,6 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
-#include "cache.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
 #include "object.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 8fec8939fd3..9f0f95e2b9e 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hash.h"
 #include "hash-lookup.h"
 #include "read-cache-ll.h"
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a0bedcb63bb..4acedf3c338 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hash.h"
 #include "merge-ort.h"
diff --git a/merge-ort.c b/merge-ort.c
index 5512f40d321..c2d2ee73eaa 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,7 +14,7 @@
  * "cale", "peedy", or "ins" instead of "ort"?)
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "merge-ort.h"
 
 #include "alloc.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 0e16e7a06df..4bef9b62fa8 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,7 +3,7 @@
  * Fredrik Kuivinen.
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "merge-recursive.h"
 
 #include "advice.h"
diff --git a/merge.c b/merge.c
index fade6b203b3..83bcba6943e 100644
--- a/merge.c
+++ b/merge.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
diff --git a/name-hash.c b/name-hash.c
index f2f3564cb20..251f036eef6 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -5,7 +5,7 @@
  *
  * Copyright (C) 2008 Linus Torvalds
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
diff --git a/object-name.c b/object-name.c
index 1eefeef746e..45f4d51305b 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "object-name.h"
 #include "advice.h"
 #include "config.h"
diff --git a/object.c b/object.c
index 333e736fb24..60f954194f7 100644
--- a/object.c
+++ b/object.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object.h"
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 2b1439c0c5f..602fbf19d3c 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
diff --git a/pathspec.c b/pathspec.c
index 47d172fe414..0baa85384f8 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
diff --git a/preload-index.c b/preload-index.c
index d037a951efa..e44530c80cf 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2008 Linus Torvalds
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "pathspec.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/read-cache.c b/read-cache.c
index 42f27b06642..edab96765df 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
 #include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index bca7b851c5a..01c08207619 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
 #include "../config.h"
 #include "../copy.h"
 #include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 085becf773e..713491a9e2c 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
 #include "../alloc.h"
 #include "../config.h"
 #include "../gettext.h"
diff --git a/repository.c b/repository.c
index ebad755c2cc..67ec56a70c5 100644
--- a/repository.c
+++ b/repository.c
@@ -3,7 +3,7 @@
  * declaration matches the definition in this file.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/rerere.c b/rerere.c
index 3bc9aedc286..2fb93a51125 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 59598877841..7817f5d6db1 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "dir.h"
 #include "hash.h"
 #include "read-cache.h"
diff --git a/revision.c b/revision.c
index 8d37ec9f495..66a1fece0df 100644
--- a/revision.c
+++ b/revision.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/run-command.h b/run-command.h
index 9e47f91d462..1f22cc3827d 100644
--- a/run-command.h
+++ b/run-command.h
@@ -503,7 +503,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts);
  * exception of GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT (which cause the
  * corresponding environment variables to be unset in the subprocess) and adds
  * an environment variable pointing to new_git_dir. See local_repo_env in
- * cache.h for more information.
+ * environment.h for more information.
  */
 void prepare_other_repo_env(struct strvec *env, const char *new_git_dir);
 
diff --git a/sequencer.c b/sequencer.c
index ec4a2e80a10..08bd0e81743 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
 #include "alloc.h"
diff --git a/shallow.c b/shallow.c
index a2ebf0af2ba..f1c93e74648 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/sparse-index.c b/sparse-index.c
index 60451daae80..2c47954d933 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/split-index.c b/split-index.c
index 0a8d3903d6f..0ee3865a553 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hash.h"
diff --git a/strbuf.h b/strbuf.h
index 3dfeadb44c2..e8dfab6ecd6 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -72,10 +72,6 @@ struct strbuf {
 extern char strbuf_slopbuf[];
 #define STRBUF_INIT  { .buf = strbuf_slopbuf }
 
-/*
- * Predeclare this here, since cache.h includes this file before it defines the
- * struct.
- */
 struct object_id;
 
 /**
diff --git a/submodule.c b/submodule.c
index e09722d6be3..20aa8ed0fb8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "repository.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9d64422b3cc..e7236392c81 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 78aa11bb194..c38f546e4f0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "hash.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index e4357d65ec5..4f215fea025 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 59a24a842b4..5cf0b26dca1 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index a1cbafd64f3..b4af9712fe5 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "dir.h"
 #include "hex.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index cbcf2419f9b..62c5b5d704b 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -12,7 +12,6 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "environment.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 386f4cdaee5..58d1dc5fc83 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -4,7 +4,6 @@
  */
 
 #include "test-tool.h"
-#include "cache.h"
 #include "parse-options.h"
 #include "fsmonitor-ipc.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index c1e82d5d028..b235da594f7 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 #define NUM_SECONDS 3
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index b3cbaf6d2a8..f3c2dbe0a2c 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 
 int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 8eb327b3b93..187a115d574 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "environment.h"
 #include "name-hash.h"
 #include "parse-options.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 90e4d29a06f..70396fa3845 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "abspath.h"
 #include "environment.h"
 #include "path.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 0d548814e08..56c2d25f359 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "config.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 7b7e2384043..0a816a96e28 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index dc6fb17f2a7..dcb7f6c0032 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 int cmd__sha1(int ac, const char **av)
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index f50f64f1f22..08cf1490014 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 int cmd__sha256(int ac, const char **av)
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index d3f39207f14..d8473cf2fcf 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 
 int cmd__strcmp_offset(int argc UNUSED, const char **argv)
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index d27125eeacf..f084034d38e 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index fdcc46e474f..4b620df3031 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "strvec.h"
 #include "repository.h"
diff --git a/wt-status.c b/wt-status.c
index 847b63c906e..6ee8567ac2d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "wt-status.h"
 #include "object.h"
-- 
gitgitgadget


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

* [PATCH v2 18/27] log-tree: replace include of revision.h with simple forward declaration
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (16 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 17/27] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 19/27] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
                     ` (9 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/diff-tree.c | 1 +
 log-tree.c          | 1 +
 log-tree.h          | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 3e281150473..4ad55ecc3fc 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -9,6 +9,7 @@
 #include "submodule.h"
 #include "read-cache-ll.h"
 #include "repository.h"
+#include "revision.h"
 #include "tree.h"
 
 static struct rev_info log_tree_opt;
diff --git a/log-tree.c b/log-tree.c
index f4b22a60cc5..07d0b47b168 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -16,6 +16,7 @@
 #include "reflog-walk.h"
 #include "refs.h"
 #include "replace-object.h"
+#include "revision.h"
 #include "string-list.h"
 #include "color.h"
 #include "gpg-interface.h"
diff --git a/log-tree.h b/log-tree.h
index e7e4641cf83..bdb64328154 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -1,7 +1,7 @@
 #ifndef LOG_TREE_H
 #define LOG_TREE_H
 
-#include "revision.h"
+struct rev_info;
 
 struct log_info {
 	struct commit *commit, *parent;
-- 
gitgitgadget


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

* [PATCH v2 19/27] repository: remove unnecessary include of path.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (17 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 18/27] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 20/27] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
                     ` (8 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that several .c files that depended upon path.h
were missing a #include for it; add the missing includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.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/bisect.c                  | 1 +
 builtin/branch.c                  | 1 +
 builtin/checkout.c                | 1 +
 builtin/clean.c                   | 1 +
 builtin/clone.c                   | 1 +
 builtin/commit.c                  | 1 +
 builtin/count-objects.c           | 1 +
 builtin/fast-import.c             | 1 +
 builtin/fetch.c                   | 1 +
 builtin/fsck.c                    | 1 +
 builtin/gc.c                      | 1 +
 builtin/grep.c                    | 1 +
 builtin/ls-files.c                | 1 +
 builtin/ls-tree.c                 | 1 +
 builtin/merge.c                   | 1 +
 builtin/notes.c                   | 1 +
 builtin/prune.c                   | 1 +
 builtin/pull.c                    | 1 +
 builtin/rebase.c                  | 1 +
 builtin/receive-pack.c            | 1 +
 builtin/remote.c                  | 1 +
 builtin/repack.c                  | 1 +
 builtin/replace.c                 | 1 +
 builtin/reset.c                   | 1 +
 builtin/rev-parse.c               | 1 +
 builtin/submodule--helper.c       | 1 +
 builtin/tag.c                     | 1 +
 builtin/upload-archive.c          | 1 +
 builtin/upload-pack.c             | 1 +
 builtin/worktree.c                | 1 +
 commit-graph.c                    | 1 +
 compat/fsmonitor/fsm-ipc-darwin.c | 1 +
 config.c                          | 1 +
 connect.c                         | 1 +
 dir.c                             | 1 +
 environment.c                     | 1 +
 fetch-pack.c                      | 1 +
 fsck.c                            | 1 +
 http-backend.c                    | 1 +
 merge-ort.c                       | 1 +
 merge-recursive.c                 | 1 +
 notes-merge.c                     | 1 +
 object-file.c                     | 1 +
 pack-bitmap-write.c               | 1 +
 pack-write.c                      | 1 +
 read-cache.c                      | 1 +
 refs.c                            | 1 +
 refs/files-backend.c              | 1 +
 remote.c                          | 1 +
 repository.c                      | 1 +
 repository.h                      | 2 --
 rerere.c                          | 1 +
 sequencer.c                       | 1 +
 server-info.c                     | 1 +
 setup.c                           | 1 +
 shallow.c                         | 1 +
 strbuf.c                          | 1 +
 submodule-config.c                | 1 +
 submodule.c                       | 1 +
 t/helper/test-ref-store.c         | 1 +
 tmp-objdir.c                      | 1 +
 worktree.c                        | 1 +
 wt-status.c                       | 1 +
 71 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index e44a5dd7c50..be58dc08d22 100644
--- a/apply.c
+++ b/apply.c
@@ -27,6 +27,7 @@
 #include "object-name.h"
 #include "object-file.h"
 #include "parse-options.h"
+#include "path.h"
 #include "quote.h"
 #include "read-cache.h"
 #include "rerere.h"
diff --git a/archive.c b/archive.c
index 641baad627b..802a34d6b91 100644
--- a/archive.c
+++ b/archive.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "pretty.h"
 #include "setup.h"
 #include "refs.h"
diff --git a/attr.c b/attr.c
index 5a32bfadb37..435b51e11ff 100644
--- a/attr.c
+++ b/attr.c
@@ -14,6 +14,7 @@
 #include "attr.h"
 #include "dir.h"
 #include "gettext.h"
+#include "path.h"
 #include "utf8.h"
 #include "quote.h"
 #include "read-cache-ll.h"
diff --git a/bisect.c b/bisect.c
index 8d5f8e58851..9f7cf0be073 100644
--- a/bisect.c
+++ b/bisect.c
@@ -19,6 +19,7 @@
 #include "commit-reach.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "dir.h"
 
 static struct oid_array good_revs;
diff --git a/blame.c b/blame.c
index 15bbf16057a..b74ee70decf 100644
--- a/blame.c
+++ b/blame.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "read-cache.h"
 #include "setup.h"
 #include "tag.h"
diff --git a/branch.c b/branch.c
index 9415ee3f340..1c02078e6aa 100644
--- a/branch.c
+++ b/branch.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "path.h"
 #include "refs.h"
 #include "refspec.h"
 #include "remote.h"
diff --git a/builtin/add.c b/builtin/add.c
index 50792c0d495..43183114487 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -16,6 +16,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/builtin/am.c b/builtin/am.c
index 2f0f2337915..a78daa69714 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -41,6 +41,7 @@
 #include "string-list.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "repository.h"
 #include "pretty.h"
 #include "wrapper.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index bce0ee6268a..6478df34890 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -11,6 +11,7 @@
 #include "strvec.h"
 #include "run-command.h"
 #include "oid-array.h"
+#include "path.h"
 #include "prompt.h"
 #include "quote.h"
 #include "revision.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 5e9b0e4ea44..84f13b0cc71 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -18,6 +18,7 @@
 #include "parse-options.h"
 #include "branch.h"
 #include "diff.h"
+#include "path.h"
 #include "revision.h"
 #include "string-list.h"
 #include "column.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 09b84156492..716dcd4cae1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,6 +20,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 66b4479356d..1bb6b7965c5 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -13,6 +13,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index cc34c194f5e..6c5cb33f6a9 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -39,6 +39,7 @@
 #include "setup.h"
 #include "connected.h"
 #include "packfile.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "list-objects-filter-options.h"
 #include "hook.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 3b90cb748cd..b3ab5e93844 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -29,6 +29,7 @@
 #include "utf8.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "string-list.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index b9e6b55a9a9..c9f82d0bce9 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -9,6 +9,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
+#include "path.h"
 #include "repository.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 67a2260a5eb..5698b92ae7d 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -12,6 +12,7 @@
 #include "commit.h"
 #include "delta.h"
 #include "pack.h"
+#include "path.h"
 #include "refs.h"
 #include "csum-file.h"
 #include "quote.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index cbc991086cd..4dbacd8f188 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -28,6 +28,7 @@
 #include "utf8.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "list-objects-filter-options.h"
 #include "commit-reach.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index f05617ceb14..d707ca32a61 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -21,6 +21,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "resolve-undo.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index d6e56e380cf..9ecc2513e9f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -30,6 +30,7 @@
 #include "object-store.h"
 #include "pack.h"
 #include "pack-objects.h"
+#include "path.h"
 #include "blob.h"
 #include "tree.h"
 #include "promisor-remote.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7638d779000..6bc8abcd3e1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -30,6 +30,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "write-or-die.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a49c43864f7..ab90f821e44 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -19,6 +19,7 @@
 #include "parse-options.h"
 #include "resolve-undo.h"
 #include "string-list.h"
+#include "path.h"
 #include "pathspec.h"
 #include "read-cache.h"
 #include "run-command.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index f4331c640fc..c06858de4bf 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -12,6 +12,7 @@
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
+#include "path.h"
 #include "quote.h"
 #include "parse-options.h"
 #include "pathspec.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index d7ac108ce94..420e81008ed 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -27,6 +27,7 @@
 #include "refspec.h"
 #include "commit.h"
 #include "diffcore.h"
+#include "path.h"
 #include "revision.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index efdf2451486..0a870d90836 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -15,6 +15,7 @@
 #include "notes.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "blob.h"
 #include "pretty.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index b3658b5b512..a46c5aa2b5b 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -7,6 +7,7 @@
 #include "revision.h"
 #include "reachable.h"
 #include "parse-options.h"
+#include "path.h"
 #include "progress.h"
 #include "prune-packed.h"
 #include "replace-object.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index d4261804d76..815f6135189 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -19,6 +19,7 @@
 #include "oid-array.h"
 #include "remote.h"
 #include "dir.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "rebase.h"
 #include "refs.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ace1d5e8d11..91849f920f7 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -24,6 +24,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "commit.h"
 #include "diff.h"
 #include "wt-status.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 1a31a583674..d1718a3ac90 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -31,6 +31,7 @@
 #include "packfile.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "protocol.h"
 #include "commit-reach.h"
 #include "server-info.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 1e0b137d977..3794f13330d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "transport.h"
 #include "remote.h"
 #include "string-list.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 0541c3ce157..fe8d5810d48 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "path.h"
 #include "run-command.h"
 #include "server-info.h"
 #include "sigchain.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index e0fbdc98ed3..6b266a66d30 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -16,6 +16,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "path.h"
 #include "run-command.h"
 #include "object-file.h"
 #include "object-name.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 3dc41ac3327..f947c449d14 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -26,6 +26,7 @@
 #include "branch.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
 #include "setup.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 8d8c870421d..6eb5965bee4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -16,6 +16,7 @@
 #include "quote.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "diff.h"
 #include "read-cache-ll.h"
 #include "revision.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 17567d91c88..6acba4ebb30 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "path.h"
 #include "pathspec.h"
 #include "preload-index.h"
 #include "dir.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index ce298d08945..87963d2cc0e 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -16,6 +16,7 @@
 #include "refs.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index d4c7f162ff0..1b09e5e1aa3 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -3,6 +3,7 @@
  */
 #include "builtin.h"
 #include "archive.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "repository.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index ba5103a9331..b02d479248a 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "pkt-line.h"
 #include "parse-options.h"
+#include "path.h"
 #include "protocol.h"
 #include "replace-object.h"
 #include "upload-pack.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index b9a84988637..6ba463f6965 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -10,6 +10,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "strvec.h"
 #include "branch.h"
 #include "read-cache-ll.h"
diff --git a/commit-graph.c b/commit-graph.c
index 843bdb458d0..25cbd66c33a 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -14,6 +14,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "oid-array.h"
+#include "path.h"
 #include "alloc.h"
 #include "hashmap.h"
 #include "replace-object.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 793073aaa72..964bc074db6 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "strbuf.h"
 #include "fsmonitor.h"
diff --git a/config.c b/config.c
index 06e6cc6f1ec..666ec73bab1 100644
--- a/config.c
+++ b/config.c
@@ -27,6 +27,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "pager.h"
+#include "path.h"
 #include "utf8.h"
 #include "dir.h"
 #include "color.h"
diff --git a/connect.c b/connect.c
index 3a0186280c4..37674f71122 100644
--- a/connect.c
+++ b/connect.c
@@ -12,6 +12,7 @@
 #include "url.h"
 #include "string-list.h"
 #include "oid-array.h"
+#include "path.h"
 #include "transport.h"
 #include "trace2.h"
 #include "strbuf.h"
diff --git a/dir.c b/dir.c
index 1e84b1e1f28..3cf3d428c7b 100644
--- a/dir.c
+++ b/dir.c
@@ -16,6 +16,7 @@
 #include "name-hash.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "path.h"
 #include "attr.h"
 #include "refs.h"
 #include "wildmatch.h"
diff --git a/environment.c b/environment.c
index 0cdd20a1589..56e8742ea66 100644
--- a/environment.c
+++ b/environment.c
@@ -21,6 +21,7 @@
 #include "strvec.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "path.h"
 #include "replace-object.h"
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f71054fbae..207548b3e5a 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -25,6 +25,7 @@
 #include "oidset.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "path.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
 #include "fsck.h"
diff --git a/fsck.c b/fsck.c
index 3261ef9ec28..04e729953b2 100644
--- a/fsck.c
+++ b/fsck.c
@@ -3,6 +3,7 @@
 #include "date.h"
 #include "hex.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "object.h"
 #include "attr.h"
diff --git a/http-backend.c b/http-backend.c
index ac146d85c54..ddb9549ecbc 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "git-zlib.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/merge-ort.c b/merge-ort.c
index c2d2ee73eaa..eed71b04389 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -36,6 +36,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "oid-array.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "read-cache-ll.h"
 #include "revision.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 4bef9b62fa8..527dbbd010a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -27,6 +27,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "revision.h"
 #include "sparse-index.h"
diff --git a/notes-merge.c b/notes-merge.c
index 233e49e3195..4b328d852cd 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -6,6 +6,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/object-file.c b/object-file.c
index 7c1af5c8db8..8d87720dd53 100644
--- a/object-file.c
+++ b/object-file.c
@@ -39,6 +39,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "oidtree.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index cdffe2ce47d..623ee2a8197 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -15,6 +15,7 @@
 #include "pack-bitmap.h"
 #include "hash-lookup.h"
 #include "pack-objects.h"
+#include "path.h"
 #include "commit-reach.h"
 #include "prio-queue.h"
 #include "trace2.h"
diff --git a/pack-write.c b/pack-write.c
index 3b3ce89de6e..45681e2d7db 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -10,6 +10,7 @@
 #include "oidmap.h"
 #include "pack-objects.h"
 #include "pack-revindex.h"
+#include "path.h"
 #include "wrapper.h"
 
 void reset_pack_idx_option(struct pack_idx_option *opts)
diff --git a/read-cache.c b/read-cache.c
index edab96765df..86ada403a83 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@
 #include "mem-pool.h"
 #include "name-hash.h"
 #include "object-name.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "resolve-undo.h"
diff --git a/refs.c b/refs.c
index d2a98e1c21f..3c0c95ac442 100644
--- a/refs.c
+++ b/refs.c
@@ -19,6 +19,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "object.h"
+#include "path.h"
 #include "tag.h"
 #include "submodule.h"
 #include "worktree.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 01c08207619..6fa7decec0a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -15,6 +15,7 @@
 #include "../lockfile.h"
 #include "../object.h"
 #include "../object-file.h"
+#include "../path.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
 #include "../setup.h"
diff --git a/remote.c b/remote.c
index 0764fca0db9..8550056db43 100644
--- a/remote.c
+++ b/remote.c
@@ -11,6 +11,7 @@
 #include "refspec.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/repository.c b/repository.c
index 67ec56a70c5..87a7a27b665 100644
--- a/repository.c
+++ b/repository.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "remote.h"
 #include "setup.h"
diff --git a/repository.h b/repository.h
index 763794880ed..510aa6d9a2f 100644
--- a/repository.h
+++ b/repository.h
@@ -1,8 +1,6 @@
 #ifndef REPOSITORY_H
 #define REPOSITORY_H
 
-#include "path.h"
-
 struct config_set;
 struct fsmonitor_settings;
 struct git_hash_algo;
diff --git a/rerere.c b/rerere.c
index 2fb93a51125..35b9785d573 100644
--- a/rerere.c
+++ b/rerere.c
@@ -14,6 +14,7 @@
 #include "resolve-undo.h"
 #include "ll-merge.h"
 #include "attr.h"
+#include "path.h"
 #include "pathspec.h"
 #include "object-file.h"
 #include "object-store.h"
diff --git a/sequencer.c b/sequencer.c
index 08bd0e81743..eddd38d4bed 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -23,6 +23,7 @@
 #include "utf8.h"
 #include "cache-tree.h"
 #include "diff.h"
+#include "path.h"
 #include "revision.h"
 #include "rerere.h"
 #include "merge.h"
diff --git a/server-info.c b/server-info.c
index 55aa04f00ab..85d17bbb151 100644
--- a/server-info.c
+++ b/server-info.c
@@ -9,6 +9,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "packfile.h"
+#include "path.h"
 #include "object-file.h"
 #include "object-store.h"
 #include "server-info.h"
diff --git a/setup.c b/setup.c
index c47be7ea5ba..2efcc552a16 100644
--- a/setup.c
+++ b/setup.c
@@ -12,6 +12,7 @@
 #include "setup.h"
 #include "string-list.h"
 #include "chdir-notify.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "quote.h"
 #include "trace2.h"
diff --git a/shallow.c b/shallow.c
index f1c93e74648..45343e6a78b 100644
--- a/shallow.c
+++ b/shallow.c
@@ -11,6 +11,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "oid-array.h"
+#include "path.h"
 #include "diff.h"
 #include "revision.h"
 #include "commit-slab.h"
diff --git a/strbuf.c b/strbuf.c
index 08eec8f1d8b..d070e007f8a 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -6,6 +6,7 @@
 #include "hex.h"
 #include "object-name.h"
 #include "refs.h"
+#include "path.h"
 #include "repository.h"
 #include "string-list.h"
 #include "utf8.h"
diff --git a/submodule-config.c b/submodule-config.c
index 58dfbde9ae5..c67260a3e11 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "config.h"
 #include "submodule-config.h"
diff --git a/submodule.c b/submodule.c
index 20aa8ed0fb8..245300596ff 100644
--- a/submodule.c
+++ b/submodule.c
@@ -20,6 +20,7 @@
 #include "strvec.h"
 #include "blob.h"
 #include "thread-utils.h"
+#include "path.h"
 #include "quote.h"
 #include "remote.h"
 #include "worktree.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 6d8f844e9c7..1b30a6cba8b 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -4,6 +4,7 @@
 #include "setup.h"
 #include "worktree.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 
 struct flag_definition {
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c33a554f921..db1f7038dae 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -5,6 +5,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "object-file.h"
+#include "path.h"
 #include "sigchain.h"
 #include "string-list.h"
 #include "strbuf.h"
diff --git a/worktree.c b/worktree.c
index b5ee71c5ebd..f9aa371ca70 100644
--- a/worktree.c
+++ b/worktree.c
@@ -3,6 +3,7 @@
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
+#include "path.h"
 #include "repository.h"
 #include "refs.h"
 #include "setup.h"
diff --git a/wt-status.c b/wt-status.c
index 6ee8567ac2d..7ada6b305f6 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "path.h"
 #include "revision.h"
 #include "diffcore.h"
 #include "quote.h"
-- 
gitgitgadget


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

* [PATCH v2 20/27] diff.h: remove unnecessary include of oidset.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (18 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 19/27] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 21/27] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
                     ` (7 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that several .c files depended upon various
things that oidset included, but had omitted the direct #include for
those headers.  Add those now.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                | 2 ++
 add-patch.c                      | 1 +
 blame.h                          | 1 +
 builtin/add.c                    | 1 +
 builtin/diff-files.c             | 1 +
 builtin/diff-index.c             | 1 +
 builtin/merge-ours.c             | 1 +
 builtin/patch-id.c               | 1 +
 builtin/range-diff.c             | 1 +
 builtin/reflog.c                 | 1 +
 builtin/reset.c                  | 1 +
 builtin/rev-parse.c              | 1 +
 builtin/revert.c                 | 1 +
 builtin/shortlog.c               | 1 +
 builtin/stash.c                  | 1 +
 diff-lib.c                       | 2 ++
 diff.h                           | 4 +++-
 diffcore-break.c                 | 1 +
 diffcore-pickaxe.c               | 1 +
 line-log.c                       | 1 +
 merge.c                          | 2 ++
 patch-ids.c                      | 1 +
 pretty.c                         | 1 +
 range-diff.c                     | 1 +
 reflog-walk.c                    | 1 +
 t/helper/test-fast-rebase.c      | 1 +
 t/helper/test-revision-walking.c | 1 +
 transport-helper.c               | 1 +
 tree-diff.c                      | 1 +
 wt-status.c                      | 1 +
 30 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/add-interactive.c b/add-interactive.c
index 40f88c02051..add9a1ad436 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -4,9 +4,11 @@
 #include "config.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "preload-index.h"
 #include "read-cache-ll.h"
+#include "repository.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 875b96e2274..53e32482959 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -7,6 +7,7 @@
 #include "gettext.h"
 #include "object-name.h"
 #include "read-cache-ll.h"
+#include "repository.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/blame.h b/blame.h
index b60d1d81e30..31ddc85f19e 100644
--- a/blame.h
+++ b/blame.h
@@ -2,6 +2,7 @@
 #define BLAME_H
 
 #include "commit.h"
+#include "oidset.h"
 #include "xdiff-interface.h"
 #include "revision.h"
 #include "prio-queue.h"
diff --git a/builtin/add.c b/builtin/add.c
index 43183114487..e3ca3e4edbe 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -21,6 +21,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "read-cache.h"
+#include "repository.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index b7036aa7c2b..07f6dff844c 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -9,6 +9,7 @@
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
+#include "repository.h"
 #include "revision.h"
 #include "submodule.h"
 
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 1ab8f8b6dc5..a8b2c0a4b96 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -4,6 +4,7 @@
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
+#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index c2e519301e9..932924e5d0e 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -10,6 +10,7 @@
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
+#include "repository.h"
 
 static const char builtin_merge_ours_usage[] =
 	"git merge-ours <base>... -- HEAD <remote>...";
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 27952f1a6fd..b7118b290b1 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "diff.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "parse-options.h"
 
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 8610390d7c5..e455a4795cc 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -4,6 +4,7 @@
 #include "parse-options.h"
 #include "range-diff.h"
 #include "config.h"
+#include "repository.h"
 #include "revision.h"
 
 static const char * const builtin_range_diff_usage[] = {
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a1fa0c855f4..fc217748808 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
+#include "repository.h"
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index f947c449d14..dad2117c974 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -13,6 +13,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tag.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 6eb5965bee4..4a219ea93bb 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -11,6 +11,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 0240ec8593b..f6f07d9b539 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "diff.h"
 #include "gettext.h"
+#include "repository.h"
 #include "revision.h"
 #include "rerere.h"
 #include "dir.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 99be9dc417d..1307ed2b88a 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
+#include "repository.h"
 #include "revision.h"
 #include "utf8.h"
 #include "mailmap.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index d3d5bb95e26..84e83e0627f 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
diff --git a/diff-lib.c b/diff-lib.c
index f3aa7f93c78..cad18099aba 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "read-cache.h"
@@ -14,6 +15,7 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "refs.h"
+#include "repository.h"
 #include "submodule.h"
 #include "symlinks.h"
 #include "trace.h"
diff --git a/diff.h b/diff.h
index 29a9cd217c2..c2e0e63609f 100644
--- a/diff.h
+++ b/diff.h
@@ -4,10 +4,12 @@
 #ifndef DIFF_H
 #define DIFF_H
 
+#include "hash-ll.h"
 #include "pathspec.h"
-#include "oidset.h"
 #include "strbuf.h"
 
+struct oidset;
+
 /**
  * The diff API is for programs that compare two sets of files (e.g. two trees,
  * one tree and the index) and present the found difference in various ways.
diff --git a/diffcore-break.c b/diffcore-break.c
index 4909dc088e6..f57ece2757d 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "hash.h"
 #include "object.h"
 #include "promisor-remote.h"
 
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 13c98a7b5e7..b195fa4eb3c 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -7,6 +7,7 @@
 #include "diffcore.h"
 #include "xdiff-interface.h"
 #include "kwset.h"
+#include "oidset.h"
 #include "pretty.h"
 #include "quote.h"
 
diff --git a/line-log.c b/line-log.c
index 6a7ac312a43..2eff914bf36 100644
--- a/line-log.c
+++ b/line-log.c
@@ -8,6 +8,7 @@
 #include "diff.h"
 #include "commit.h"
 #include "decorate.h"
+#include "repository.h"
 #include "revision.h"
 #include "xdiff-interface.h"
 #include "strbuf.h"
diff --git a/merge.c b/merge.c
index 83bcba6943e..b60925459c2 100644
--- a/merge.c
+++ b/merge.c
@@ -2,10 +2,12 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge.h"
 #include "commit.h"
+#include "repository.h"
 #include "run-command.h"
 #include "resolve-undo.h"
 #include "tree.h"
diff --git a/patch-ids.c b/patch-ids.c
index 19af7bee984..c3e1a0dd216 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "commit.h"
+#include "hash.h"
 #include "hash-lookup.h"
 #include "hex.h"
 #include "patch-ids.h"
diff --git a/pretty.c b/pretty.c
index 0bb938021ba..2cf2cbbd038 100644
--- a/pretty.c
+++ b/pretty.c
@@ -4,6 +4,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/range-diff.c b/range-diff.c
index 6a704e6f471..2e86063491e 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "pager.h"
 #include "pretty.h"
+#include "repository.h"
 #include "userdiff.h"
 #include "apply.h"
 #include "revision.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 4ba1a10c82c..d337e64431f 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
+#include "repository.h"
 #include "revision.h"
 #include "string-list.h"
 #include "reflog-walk.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 62c5b5d704b..cac20a72b3f 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -16,6 +16,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index 0c62b9de185..f346951bc28 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -11,6 +11,7 @@
 #include "test-tool.h"
 #include "commit.h"
 #include "diff.h"
+#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 
diff --git a/transport-helper.c b/transport-helper.c
index 6b816940dc6..5c0bc6a896e 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -8,6 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "repository.h"
 #include "revision.h"
 #include "remote.h"
 #include "string-list.h"
diff --git a/tree-diff.c b/tree-diff.c
index 20bb15f38d9..966946848ae 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "hash.h"
 #include "tree.h"
 #include "tree-walk.h"
 
diff --git a/wt-status.c b/wt-status.c
index 7ada6b305f6..bcd0ef80441 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "path.h"
-- 
gitgitgadget


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

* [PATCH v2 21/27] list-objects-filter-options.h: remove unneccessary include
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (19 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 20/27] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 22/27] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
                     ` (6 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 list-objects-filter-options.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index f6206125868..55fab8563d2 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -3,7 +3,6 @@
 
 #include "gettext.h"
 #include "object.h"
-#include "string-list.h"
 #include "strbuf.h"
 
 struct option;
-- 
gitgitgadget


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

* [PATCH v2 22/27] builtin.h: remove unneccessary includes
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (20 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 21/27] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 23/27] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
                     ` (5 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that a few .c files under builtin/ were
depending upon some headers but had forgotten to #include them.  Add the
missing direct includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin.h                  | 2 --
 builtin/check-mailmap.c    | 1 +
 builtin/commit-graph.c     | 1 +
 builtin/config.c           | 1 +
 builtin/credential-cache.c | 1 +
 builtin/for-each-ref.c     | 1 +
 builtin/init-db.c          | 1 +
 builtin/verify-pack.c      | 1 +
 8 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/builtin.h b/builtin.h
index 3e6c22eef69..d560baa6618 100644
--- a/builtin.h
+++ b/builtin.h
@@ -2,8 +2,6 @@
 #define BUILTIN_H
 
 #include "git-compat-util.h"
-#include "strbuf.h"
-#include "commit.h"
 
 /*
  * builtin API
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index 002d2941e93..b8a05b8e07b 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -4,6 +4,7 @@
 #include "ident.h"
 #include "mailmap.h"
 #include "parse-options.h"
+#include "strbuf.h"
 #include "string-list.h"
 #include "write-or-die.h"
 
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a3d00fa232b..96a8a677327 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "commit.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/builtin/config.c b/builtin/config.c
index ff2fe8ef125..30f6d9fe67b 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -12,6 +12,7 @@
 #include "path.h"
 #include "quote.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 0ffacfdd83c..ff3a47badbe 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -2,6 +2,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
+#include "strbuf.h"
 #include "wrapper.h"
 #include "write-or-die.h"
 
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index d0d6ab0fd34..15409337f83 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -5,6 +5,7 @@
 #include "object.h"
 #include "parse-options.h"
 #include "ref-filter.h"
+#include "strbuf.h"
 #include "strvec.h"
 #include "commit-reach.h"
 
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 680ef7e1837..0d8bd4d7219 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "parse-options.h"
 #include "path.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "wrapper.h"
 
 static int guess_repository_type(const char *git_dir)
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index aba92cf8af7..011dddd2dc3 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "strbuf.h"
 
 #define VERIFY_PACK_VERBOSE 01
 #define VERIFY_PACK_STAT_ONLY 02
-- 
gitgitgadget


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

* [PATCH v2 23/27] git-compat-util.h: remove unneccessary include of wildmatch.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (21 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 22/27] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 24/27] merge-ll: rename from ll-merge Elijah Newren via GitGitGadget
                     ` (4 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

The include of wildmatch.h in git-compat-util.h was added in cebcab189aa
(Makefile: add USE_WILDMATCH to use wildmatch as fnmatch, 2013-01-01) as
a way to be able to compile-time force any calls to fnmatch() to instead
invoke wildmatch().  The defines and inline function were removed in
70a8fc999d9 (stop using fnmatch (either native or compat), 2014-02-15),
and this include in git-compat-util.h has been unnecessary ever since.

Remove the include from git-compat-util.h, but add it to the .c files
that had omitted the direct #include they needed.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                   | 1 +
 builtin/describe.c        | 1 +
 builtin/ls-remote.c       | 1 +
 builtin/name-rev.c        | 1 +
 builtin/reflog.c          | 1 +
 builtin/replace.c         | 1 +
 builtin/show-branch.c     | 1 +
 config.c                  | 1 +
 diffcore-order.c          | 1 +
 fmt-merge-msg.c           | 1 +
 git-compat-util.h         | 2 --
 log-tree.c                | 1 +
 pathspec.c                | 1 +
 refs.c                    | 1 +
 revision.c                | 1 +
 t/helper/test-wildmatch.c | 1 +
 trace2/tr2_cfg.c          | 1 +
 17 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index be58dc08d22..801f2bcc99c 100644
--- a/apply.c
+++ b/apply.c
@@ -35,6 +35,7 @@
 #include "entry.h"
 #include "setup.h"
 #include "symlinks.h"
+#include "wildmatch.h"
 #include "ws.h"
 #include "wrapper.h"
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 508e8df00ef..eb19ab0bbbe 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -22,6 +22,7 @@
 #include "object-store.h"
 #include "list-objects.h"
 #include "commit-slab.h"
+#include "wildmatch.h"
 
 #define MAX_TAGS	(FLAG_BITS - 1)
 
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index a0aadc9b8ff..fc765754305 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -7,6 +7,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "wildmatch.h"
 
 static const char * const ls_remote_usage[] = {
 	N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 593f0506a10..de9808e21c8 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -15,6 +15,7 @@
 #include "hash-lookup.h"
 #include "commit-slab.h"
 #include "commit-graph.h"
+#include "wildmatch.h"
 
 /*
  * One day.  See the 'name a rev shortly after epoch' test in t6120 when
diff --git a/builtin/reflog.c b/builtin/reflog.c
index fc217748808..79b4ff04aae 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -4,6 +4,7 @@
 #include "repository.h"
 #include "revision.h"
 #include "reachable.h"
+#include "wildmatch.h"
 #include "worktree.h"
 #include "reflog.h"
 #include "parse-options.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 6b266a66d30..a2f57a56b3e 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -24,6 +24,7 @@
 #include "replace-object.h"
 #include "repository.h"
 #include "tag.h"
+#include "wildmatch.h"
 
 static const char * const git_replace_usage[] = {
 	N_("git replace [-f] <object> <replacement>"),
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index cd215f89af8..a203f13cb0d 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "commit-slab.h"
 #include "date.h"
+#include "wildmatch.h"
 
 static const char* show_branch_usage[] = {
     N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
diff --git a/config.c b/config.c
index 666ec73bab1..0b2a9f1bd89 100644
--- a/config.c
+++ b/config.c
@@ -36,6 +36,7 @@
 #include "setup.h"
 #include "strvec.h"
 #include "trace2.h"
+#include "wildmatch.h"
 #include "worktree.h"
 #include "ws.h"
 #include "wrapper.h"
diff --git a/diffcore-order.c b/diffcore-order.c
index 57ccab28464..e7d20ebd2d1 100644
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "wildmatch.h"
 
 static char **order;
 static int order_cnt;
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 5af0d4715ba..f096b1ef549 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -15,6 +15,7 @@
 #include "fmt-merge-msg.h"
 #include "commit-reach.h"
 #include "gpg-interface.h"
+#include "wildmatch.h"
 
 static int use_branch_desc;
 static int suppress_dest_pattern_seen;
diff --git a/git-compat-util.h b/git-compat-util.h
index 5b2b99c17c5..1889da7986e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -625,8 +625,6 @@ static inline int git_has_dir_sep(const char *path)
 
 #include "compat/bswap.h"
 
-#include "wildmatch.h"
-
 struct strbuf;
 
 /* General helper functions */
diff --git a/log-tree.c b/log-tree.c
index 07d0b47b168..60b61597c42 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -26,6 +26,7 @@
 #include "range-diff.h"
 #include "strmap.h"
 #include "tree.h"
+#include "wildmatch.h"
 #include "write-or-die.h"
 
 static struct decoration name_decoration = { "object names" };
diff --git a/pathspec.c b/pathspec.c
index 0baa85384f8..ad9b9e7dc74 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -12,6 +12,7 @@
 #include "strvec.h"
 #include "symlinks.h"
 #include "quote.h"
+#include "wildmatch.h"
 
 /*
  * Finds which of the given pathspecs match items in the index.
diff --git a/refs.c b/refs.c
index 3c0c95ac442..5f76da35673 100644
--- a/refs.c
+++ b/refs.c
@@ -29,6 +29,7 @@
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
+#include "wildmatch.h"
 #include "wrapper.h"
 
 /*
diff --git a/revision.c b/revision.c
index 66a1fece0df..d4b4b34fd80 100644
--- a/revision.c
+++ b/revision.c
@@ -46,6 +46,7 @@
 #include "list-objects-filter-options.h"
 #include "resolve-undo.h"
 #include "parse-options.h"
+#include "wildmatch.h"
 
 volatile show_early_output_fn_t show_early_output;
 
diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c
index a95bb4da9b1..b4ff5f986ae 100644
--- a/t/helper/test-wildmatch.c
+++ b/t/helper/test-wildmatch.c
@@ -1,4 +1,5 @@
 #include "test-tool.h"
+#include "wildmatch.h"
 
 int cmd__wildmatch(int argc, const char **argv)
 {
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index 78cfc15d52d..db817a80c53 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -4,6 +4,7 @@
 #include "trace2.h"
 #include "trace2/tr2_cfg.h"
 #include "trace2/tr2_sysenv.h"
+#include "wildmatch.h"
 
 static struct strbuf **tr2_cfg_patterns;
 static int tr2_cfg_count_patterns;
-- 
gitgitgadget


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

* [PATCH v2 24/27] merge-ll: rename from ll-merge
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (22 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 23/27] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 25/27] khash: name the structs that khash declares Elijah Newren via GitGitGadget
                     ` (3 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

A long term (but rather minor) pet-peeve of mine was the name
ll-merge.[ch].  I thought it made it harder to realize what stuff was
related to merging when I was working on the merge machinery and trying
to improve it.

Further, back in d1cbe1e6d8a ("hash-ll.h: split out of hash.h to remove
dependency on repository.h", 2023-04-22), we have split the portions of
hash.h that do not depend upon repository.h into a "hash-ll.h" (due to
the recommendation to use "ll" for "low-level" in its name[1], but which
I used as a suffix precisely because of my distaste for "ll-merge").
When we discussed adding additional "*-ll.h" files, a request was made
that we use "ll" consistently as either a prefix or a suffix.  Since it
is already in use as both a prefix and a suffix, the only way to do so
is to rename some files.

Besides my distaste for the ll-merge.[ch] name, let me also note that
the files
  ll-fsmonitor.h, ll-hash.h, ll-merge.h, ll-object-store.h, ll-read-cache.h
would have essentially nothing to do with each other and make no sense
to group.  But giving them the common "ll-" prefix would group them.  Using
"-ll" as a suffix thus seems just much more logical to me.  Rename
ll-merge.[ch] to merge-ll.[ch] to achieve this consistency, and to
ensure we get a more logical grouping of files.

[1] https://lore.kernel.org/git/kl6lsfcu1g8w.fsf@chooglen-macbookpro.roam.corp.google.com/

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/technical/api-merge.txt | 4 ++--
 Makefile                              | 2 +-
 apply.c                               | 2 +-
 builtin/checkout.c                    | 2 +-
 convert.c                             | 2 +-
 diff.c                                | 2 +-
 merge-blobs.c                         | 2 +-
 ll-merge.c => merge-ll.c              | 2 +-
 ll-merge.h => merge-ll.h              | 0
 merge-ort.c                           | 2 +-
 merge-recursive.c                     | 2 +-
 notes-merge.c                         | 2 +-
 rerere.c                              | 2 +-
 13 files changed, 13 insertions(+), 13 deletions(-)
 rename ll-merge.c => merge-ll.c (99%)
 rename ll-merge.h => merge-ll.h (100%)

diff --git a/Documentation/technical/api-merge.txt b/Documentation/technical/api-merge.txt
index 487d4d83fff..c2ba01828c6 100644
--- a/Documentation/technical/api-merge.txt
+++ b/Documentation/technical/api-merge.txt
@@ -28,9 +28,9 @@ and `diff.c` for examples.
 
 * `struct ll_merge_options`
 
-Check ll-merge.h for details.
+Check merge-ll.h for details.
 
 Low-level (single file) merge
 -----------------------------
 
-Check ll-merge.h for details.
+Check merge-ll.h for details.
diff --git a/Makefile b/Makefile
index 2d180abc5ca..045e2187c41 100644
--- a/Makefile
+++ b/Makefile
@@ -1051,7 +1051,6 @@ LIB_OBJS += linear-assignment.o
 LIB_OBJS += list-objects-filter-options.o
 LIB_OBJS += list-objects-filter.o
 LIB_OBJS += list-objects.o
-LIB_OBJS += ll-merge.o
 LIB_OBJS += lockfile.o
 LIB_OBJS += log-tree.o
 LIB_OBJS += ls-refs.o
@@ -1060,6 +1059,7 @@ LIB_OBJS += mailmap.o
 LIB_OBJS += match-trees.o
 LIB_OBJS += mem-pool.o
 LIB_OBJS += merge-blobs.o
+LIB_OBJS += merge-ll.o
 LIB_OBJS += merge-ort.o
 LIB_OBJS += merge-ort-wrappers.o
 LIB_OBJS += merge-recursive.o
diff --git a/apply.c b/apply.c
index 801f2bcc99c..2f66f93fec5 100644
--- a/apply.c
+++ b/apply.c
@@ -21,7 +21,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "lockfile.h"
 #include "name-hash.h"
 #include "object-name.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 716dcd4cae1..11e2359c548 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -13,7 +13,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "hook.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "lockfile.h"
 #include "mem-pool.h"
 #include "merge-recursive.h"
diff --git a/convert.c b/convert.c
index 9e89f660308..1f2cfc5f457 100644
--- a/convert.c
+++ b/convert.c
@@ -15,7 +15,7 @@
 #include "sub-process.h"
 #include "trace.h"
 #include "utf8.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "wrapper.h"
 
 /*
diff --git a/diff.c b/diff.c
index 5e81dc0d02d..9d6b88ece90 100644
--- a/diff.c
+++ b/diff.c
@@ -26,7 +26,7 @@
 #include "submodule.h"
 #include "hashmap.h"
 #include "mem-pool.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "string-list.h"
 #include "strvec.h"
 #include "graph.h"
diff --git a/merge-blobs.c b/merge-blobs.c
index 5632ff6abb6..40c48e3eba6 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "run-command.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "blob.h"
 #include "merge-blobs.h"
 #include "object-store.h"
diff --git a/ll-merge.c b/merge-ll.c
similarity index 99%
rename from ll-merge.c
rename to merge-ll.c
index 1993530688e..c076d048407 100644
--- a/ll-merge.c
+++ b/merge-ll.c
@@ -10,7 +10,7 @@
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "quote.h"
 #include "strbuf.h"
 #include "wrapper.h"
diff --git a/ll-merge.h b/merge-ll.h
similarity index 100%
rename from ll-merge.h
rename to merge-ll.h
diff --git a/merge-ort.c b/merge-ort.c
index eed71b04389..f4522951323 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -30,7 +30,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "entry.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "match-trees.h"
 #include "mem-pool.h"
 #include "object-name.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 527dbbd010a..35e1e7e1bef 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -20,7 +20,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "lockfile.h"
 #include "match-trees.h"
 #include "name-hash.h"
diff --git a/notes-merge.c b/notes-merge.c
index 4b328d852cd..4be11a01550 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -12,7 +12,7 @@
 #include "diffcore.h"
 #include "hex.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "dir.h"
 #include "notes.h"
 #include "notes-merge.h"
diff --git a/rerere.c b/rerere.c
index 35b9785d573..3584fecb07c 100644
--- a/rerere.c
+++ b/rerere.c
@@ -12,7 +12,7 @@
 #include "xdiff-interface.h"
 #include "dir.h"
 #include "resolve-undo.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "attr.h"
 #include "path.h"
 #include "pathspec.h"
-- 
gitgitgadget


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

* [PATCH v2 25/27] khash: name the structs that khash declares
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (23 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 24/27] merge-ll: rename from ll-merge Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-12  7:04   ` [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
                     ` (2 subsequent siblings)
  27 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

khash.h lets you instantiate custom hash types that map between two
types. These are defined as a struct, as you might expect, and khash
typedef's that to kh_foo_t. But it declares the struct anonymously,
which doesn't give a name to the struct type itself; there is no
"struct kh_foo". This has two small downsides:

  - when using khash, we declare "kh_foo_t *the_foo".  This is
    unlike our usual naming style, which is "struct kh_foo *the_foo".

  - you can't forward-declare a typedef of an unnamed struct type in
    C. So we might do something like this in a header file:

        struct kh_foo;
        struct bar {
                struct kh_foo *the_foo;
        };

    to avoid having to include the header that defines the real
    kh_foo. But that doesn't work with the typedef'd name. Without the
    "struct" keyword, the compiler doesn't know we mean that kh_foo is
    a type.

So let's always give khash structs the name that matches our
conventions ("struct kh_foo" to match "kh_foo_t"). We'll keep doing
the typedef to retain compatibility with existing callers.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 khash.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/khash.h b/khash.h
index 56241e6a5c9..a0a08dad8b7 100644
--- a/khash.h
+++ b/khash.h
@@ -62,7 +62,7 @@ static inline khint_t __ac_X31_hash_string(const char *s)
 static const double __ac_HASH_UPPER = 0.77;
 
 #define __KHASH_TYPE(name, khkey_t, khval_t) \
-	typedef struct { \
+	typedef struct kh_##name { \
 		khint_t n_buckets, size, n_occupied, upper_bound; \
 		khint32_t *flags; \
 		khkey_t *keys; \
-- 
gitgitgadget


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

* [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (24 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 25/27] khash: name the structs that khash declares Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-16  0:16     ` Jonathan Tan
  2023-05-12  7:04   ` [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

oidhash() was used by both hashmap and khash, which makes sense.
However, the location of this function in hashmap.[ch] meant that
khash.h had to depend upon hashmap.h, making people unfamiliar with
khash think that it was built upon hashmap.  (Or at least, I personally
was confused for a while about this in the past.)

Move this function to hash-ll, so that khash.h can stop depending upon
hashmap.h.

This has another benefit as well: it allows us to remove hashmap.h's
dependency on hash-ll.h.  While some callers of hashmap.h were making
use of oidhash, most were not, so this change provides another way to
reduce the number of includes.

Diff best viewed with `--color-moved`.  Note that there's a small but
important change to khash.h in this patch as well to allow this move,
which is easy to overlook.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                       |   2 +-
 archive-tar.c                 |   2 +-
 archive-zip.c                 |   2 +-
 archive.c                     |   2 +-
 attr.c                        |   2 +-
 bisect.c                      |   2 +-
 blame.c                       |   2 +-
 builtin/blame.c               |   2 +-
 builtin/cat-file.c            |   2 +-
 builtin/checkout.c            |   2 +-
 builtin/clone.c               |   2 +-
 builtin/commit-graph.c        |   2 +-
 builtin/commit-tree.c         |   2 +-
 builtin/count-objects.c       |   2 +-
 builtin/describe.c            |   2 +-
 builtin/difftool.c            |   2 +-
 builtin/fast-export.c         |   2 +-
 builtin/fast-import.c         |   2 +-
 builtin/fetch.c               |   2 +-
 builtin/fsck.c                |   2 +-
 builtin/gc.c                  |   2 +-
 builtin/grep.c                |   2 +-
 builtin/hash-object.c         |   3 +-
 builtin/index-pack.c          |   3 +-
 builtin/log.c                 |   2 +-
 builtin/ls-tree.c             |   2 +-
 builtin/merge-tree.c          |   2 +-
 builtin/mktag.c               |   3 +-
 builtin/mktree.c              |   3 +-
 builtin/multi-pack-index.c    |   3 +-
 builtin/notes.c               |   2 +-
 builtin/pack-objects.c        |   2 +-
 builtin/pack-redundant.c      |   2 +-
 builtin/prune.c               |   3 +-
 builtin/receive-pack.c        |   2 +-
 builtin/remote.c              |   2 +-
 builtin/repack.c              |   2 +-
 builtin/replace.c             |   2 +-
 builtin/rev-list.c            |   2 +-
 builtin/show-ref.c            |   2 +-
 builtin/submodule--helper.c   |   2 +-
 builtin/tag.c                 |   2 +-
 builtin/unpack-file.c         |   2 +-
 builtin/unpack-objects.c      |   2 +-
 builtin/verify-commit.c       |   2 +-
 bulk-checkin.c                |   2 +-
 bundle-uri.c                  |   2 +-
 bundle.c                      |   2 +-
 cache-tree.c                  |   2 +-
 combine-diff.c                |   2 +-
 commit-graph.c                |   2 +-
 commit-graph.h                |   2 +-
 commit.c                      |   2 +-
 config.c                      |   2 +-
 connected.c                   |   2 +-
 convert.c                     |   2 +-
 decorate.c                    |   1 -
 diagnose.c                    |   2 +-
 diff.c                        |   2 +-
 diffcore-rename.c             |   2 +-
 dir.c                         |   2 +-
 dir.h                         |   1 +
 entry.c                       |   2 +-
 environment.c                 |   2 +-
 fetch-pack.c                  |   2 +-
 fmt-merge-msg.c               |   2 +-
 fsck.c                        |   3 +-
 grep.c                        |   2 +-
 hash-ll.h                     |  19 ++
 hashmap.h                     |  21 --
 http-backend.c                |   2 +-
 http-push.c                   |   2 +-
 http-walker.c                 |   2 +-
 http.c                        |   2 +-
 khash.h                       |   1 -
 list-objects-filter.c         |   2 +-
 list-objects.c                |   2 +-
 log-tree.c                    |   2 +-
 mailmap.c                     |   2 +-
 match-trees.c                 |   3 +-
 merge-blobs.c                 |   2 +-
 merge-ort.c                   |   2 +-
 merge-recursive.c             |   2 +-
 midx.c                        |   2 +-
 notes-cache.c                 |   3 +-
 notes-merge.c                 |   2 +-
 notes.c                       |   2 +-
 object-name.c                 |   2 +-
 object-store-ll.h             | 533 ++++++++++++++++++++++++++++++++++
 object-store.h                | 528 +--------------------------------
 oss-fuzz/fuzz-pack-idx.c      |   2 +-
 pack-bitmap-write.c           |   2 +-
 pack-bitmap.c                 |   2 +-
 pack-check.c                  |   2 +-
 pack-mtimes.c                 |   3 +-
 pack-objects.h                |   2 +-
 pack-revindex.c               |   3 +-
 pack-write.c                  |   1 +
 packfile.c                    |   2 +-
 path.c                        |   2 +-
 promisor-remote.c             |   2 +-
 protocol-caps.c               |   2 +-
 prune-packed.c                |   2 +-
 reachable.c                   |   2 +-
 read-cache.c                  |   2 +-
 ref-filter.c                  |   2 +-
 reflog.c                      |   2 +-
 refs.c                        |   2 +-
 remote.c                      |   2 +-
 remote.h                      |   1 +
 replace-object.c              |   2 +-
 replace-object.h              |   2 +-
 repository.c                  |   2 +-
 rerere.c                      |   2 +-
 revision.c                    |   2 +-
 send-pack.c                   |   2 +-
 sequencer.c                   |   2 +-
 serve.c                       |   1 +
 server-info.c                 |   2 +-
 shallow.c                     |   2 +-
 streaming.c                   |   2 +-
 submodule-config.c            |   2 +-
 submodule.c                   |   2 +-
 t/helper/test-pack-mtimes.c   |   2 +-
 t/helper/test-partial-clone.c |   2 +-
 t/helper/test-read-graph.c    |   2 +-
 t/helper/test-read-midx.c     |   2 +-
 t/helper/test-ref-store.c     |   3 +-
 t/helper/test-repository.c    |   2 +-
 tag.c                         |   2 +-
 tmp-objdir.c                  |   2 +-
 transport.c                   |   2 +-
 tree-walk.c                   |   2 +-
 tree.c                        |   2 +-
 unpack-trees.c                |   2 +-
 upload-pack.c                 |   2 +-
 walker.c                      |   3 +-
 xdiff-interface.c             |   3 +-
 138 files changed, 699 insertions(+), 678 deletions(-)
 create mode 100644 object-store-ll.h

diff --git a/apply.c b/apply.c
index 2f66f93fec5..8bd0109fcc8 100644
--- a/apply.c
+++ b/apply.c
@@ -12,7 +12,7 @@
 #include "alloc.h"
 #include "base85.h"
 #include "config.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index 4cd81d8161e..fc06ff4c5d6 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -9,7 +9,7 @@
 #include "hex.h"
 #include "tar.h"
 #include "archive.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "streaming.h"
 #include "run-command.h"
 #include "write-or-die.h"
diff --git a/archive-zip.c b/archive-zip.c
index d0d065a312e..b4382640966 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -9,7 +9,7 @@
 #include "hex.h"
 #include "streaming.h"
 #include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "userdiff.h"
 #include "write-or-die.h"
 #include "xdiff-interface.h"
diff --git a/archive.c b/archive.c
index 802a34d6b91..0e5065fd505 100644
--- a/archive.c
+++ b/archive.c
@@ -10,7 +10,7 @@
 #include "pretty.h"
 #include "setup.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 435b51e11ff..f178190c5de 100644
--- a/attr.c
+++ b/attr.c
@@ -19,7 +19,7 @@
 #include "quote.h"
 #include "read-cache-ll.h"
 #include "revision.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index 9f7cf0be073..1be8e0a2711 100644
--- a/bisect.c
+++ b/bisect.c
@@ -18,7 +18,7 @@
 #include "commit-slab.h"
 #include "commit-reach.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "dir.h"
 
diff --git a/blame.c b/blame.c
index b74ee70decf..1d25cd29fce 100644
--- a/blame.c
+++ b/blame.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "cache-tree.h"
 #include "mergesort.h"
 #include "convert.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 2df6039a6e0..e811e7fbfb1 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -29,7 +29,7 @@
 #include "dir.h"
 #include "progress.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "blame.h"
 #include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9646e7209ca..48ccca95a1a 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -21,7 +21,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 11e2359c548..fd6ee8c2723 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -18,7 +18,7 @@
 #include "mem-pool.h"
 #include "merge-recursive.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "path.h"
 #include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 6c5cb33f6a9..687a686269a 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -23,7 +23,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 96a8a677327..48fa9f20c97 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -9,7 +9,7 @@
 #include "parse-options.h"
 #include "repository.h"
 #include "commit-graph.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "progress.h"
 #include "replace-object.h"
 #include "tag.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d2121f30d45..02625e71761 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -8,7 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "commit.h"
 #include "tree.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index c9f82d0bce9..97cdfb0ac57 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -14,7 +14,7 @@
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static unsigned long garbage;
 static off_t size_garbage;
diff --git a/builtin/describe.c b/builtin/describe.c
index eb19ab0bbbe..7ce23e1b8e6 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
 #include "setup.h"
 #include "strvec.h"
 #include "run-command.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "list-objects.h"
 #include "commit-slab.h"
 #include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 4a22de3eddb..e2c9ab7d5d7 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -28,7 +28,7 @@
 #include "strbuf.h"
 #include "lockfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "dir.h"
 #include "entry.h"
 #include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 5f3ffd6912f..56dc69fac18 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "object.h"
 #include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 5698b92ae7d..2ee19c73733 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -21,7 +21,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "mem-pool.h"
 #include "commit-reach.h"
 #include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4dbacd8f188..86d409a6de3 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -11,7 +11,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oidset.h"
 #include "oid-array.h"
 #include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index d707ca32a61..a04c15e5e81 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -20,7 +20,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 9ecc2513e9f..7484946c506 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -27,7 +27,7 @@
 #include "commit-graph.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack.h"
 #include "pack-objects.h"
 #include "path.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 6bc8abcd3e1..72e70b3a48d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -27,7 +27,7 @@
 #include "submodule-config.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "pager.h"
 #include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index a3801211666..5ffec99dcea 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -10,12 +10,13 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "write-or-die.h"
 
 /*
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb67e166559..820860265d0 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -14,12 +14,13 @@
 #include "progress.h"
 #include "fsck.h"
 #include "exec-cmd.h"
+#include "strbuf.h"
 #include "streaming.h"
 #include "thread-utils.h"
 #include "packfile.h"
 #include "pack-revindex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
diff --git a/builtin/log.c b/builtin/log.c
index 676de107d61..d6543ba1f63 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -14,7 +14,7 @@
 #include "refs.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "color.h"
 #include "commit.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index c06858de4bf..4e17f13648e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -8,7 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index aa8040c2a6a..23d7e98db0d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -9,7 +9,7 @@
 #include "commit-reach.h"
 #include "merge-ort.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "blob.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 44fa56eff38..43e2766db49 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -2,10 +2,11 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "strbuf.h"
 #include "tag.h"
 #include "replace-object.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "fsck.h"
 #include "config.h"
 
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 09a7bd5c5c2..0eea810c7ea 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -8,9 +8,10 @@
 #include "gettext.h"
 #include "hex.h"
 #include "quote.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "parse-options.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static struct treeent {
 	unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 5bb71bce08d..a31dde1db9e 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -5,8 +5,9 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
+#include "strbuf.h"
 #include "trace2.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 #define BUILTIN_MIDX_WRITE_USAGE \
 	N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
diff --git a/builtin/notes.c b/builtin/notes.c
index 0a870d90836..0a19796f734 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -14,7 +14,7 @@
 #include "hex.h"
 #include "notes.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a5b466839ba..aa595f6a4a4 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -34,7 +34,7 @@
 #include "list.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "dir.h"
 #include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 43e9d12dfdc..4c735ba069c 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -11,7 +11,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 #define BLKSIZE 512
 
diff --git a/builtin/prune.c b/builtin/prune.c
index a46c5aa2b5b..cfb863ae848 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
+#include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
@@ -13,7 +14,7 @@
 #include "replace-object.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "shallow.h"
 
 static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index d1718a3ac90..91caaf87066 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -30,7 +30,7 @@
 #include "oidset.h"
 #include "packfile.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "protocol.h"
 #include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 3794f13330d..7d96687ec74 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -11,7 +11,7 @@
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "strvec.h"
 #include "commit-reach.h"
 #include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index fe8d5810d48..6c896c9c805 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -16,7 +16,7 @@
 #include "midx.h"
 #include "packfile.h"
 #include "prune-packed.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "shallow.h"
 #include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index a2f57a56b3e..20c67a58890 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -20,7 +20,7 @@
 #include "run-command.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "repository.h"
 #include "tag.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 8029f3de53c..ff715d6918f 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -12,7 +12,7 @@
 #include "object.h"
 #include "object-name.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack.h"
 #include "pack-bitmap.h"
 #include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index e07e9ca862f..5110814f796 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "tag.h"
 #include "string-list.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6acba4ebb30..baf6ff88c3c 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -29,7 +29,7 @@
 #include "diff.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "advice.h"
 #include "branch.h"
 #include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 87963d2cc0e..076f832802c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -15,7 +15,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "tag.h"
 #include "run-command.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b35a4b9dfee..6842a6c4996 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -2,7 +2,7 @@
 #include "config.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "wrapper.h"
 
 static char *create_temp_file(struct object_id *oid)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 85baf6a131a..b4b46ae7291 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "git-zlib.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index aa34fb896ac..9680b587013 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -9,7 +9,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "commit.h"
 #include "run-command.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index d843279715c..e2f71db0f60 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -16,7 +16,7 @@
 #include "tmp-objdir.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "wrapper.h"
 
 static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 1b62902f014..a70c8887fd1 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -4,7 +4,7 @@
 #include "copy.h"
 #include "environment.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "refs.h"
 #include "run-command.h"
 #include "hashmap.h"
diff --git a/bundle.c b/bundle.c
index a5505368de5..8d5936c4212 100644
--- a/bundle.c
+++ b/bundle.c
@@ -4,7 +4,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "object.h"
 #include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index 077932c2db5..84d7491420e 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -8,7 +8,7 @@
 #include "cache-tree.h"
 #include "bulk-checkin.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
diff --git a/combine-diff.c b/combine-diff.c
index 1e3cd7fb170..11e9d7494a1 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "convert.h"
 #include "blob.h"
diff --git a/commit-graph.c b/commit-graph.c
index 25cbd66c33a..9e989f43491 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -12,7 +12,7 @@
 #include "hash-lookup.h"
 #include "commit-graph.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "path.h"
 #include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 83aaa1dbb92..5e534f0fcc8 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
 #ifndef COMMIT_GRAPH_H
 #define COMMIT_GRAPH_H
 
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oidset.h"
 
 #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index 10676165a1d..8dfc298d6e6 100644
--- a/commit.c
+++ b/commit.c
@@ -7,7 +7,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pkt-line.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/config.c b/config.c
index 0b2a9f1bd89..e08e2332a68 100644
--- a/config.c
+++ b/config.c
@@ -25,7 +25,7 @@
 #include "hashmap.h"
 #include "string-list.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "path.h"
 #include "utf8.h"
diff --git a/connected.c b/connected.c
index d672521da41..8f89376dbcf 100644
--- a/connected.c
+++ b/connected.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "connected.h"
diff --git a/convert.c b/convert.c
index 1f2cfc5f457..0010828386f 100644
--- a/convert.c
+++ b/convert.c
@@ -5,7 +5,7 @@
 #include "copy.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff --git a/decorate.c b/decorate.c
index 71e79daa825..a5c43c0c146 100644
--- a/decorate.c
+++ b/decorate.c
@@ -3,7 +3,6 @@
  * data.
  */
 #include "git-compat-util.h"
-#include "hashmap.h"
 #include "object.h"
 #include "decorate.h"
 
diff --git a/diagnose.c b/diagnose.c
index c8c7ebcfa39..8430064000b 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "parse-options.h"
 #include "write-or-die.h"
diff --git a/diff.c b/diff.c
index 9d6b88ece90..36451b444b8 100644
--- a/diff.c
+++ b/diff.c
@@ -20,7 +20,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "userdiff.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 8e2e7a3ad73..926b554bd59 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -6,7 +6,7 @@
 #include "alloc.h"
 #include "diff.h"
 #include "diffcore.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hashmap.h"
 #include "mem-pool.h"
 #include "oid-array.h"
diff --git a/dir.c b/dir.c
index 3cf3d428c7b..fada2713b9e 100644
--- a/dir.c
+++ b/dir.c
@@ -15,7 +15,7 @@
 #include "gettext.h"
 #include "name-hash.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "attr.h"
 #include "refs.h"
diff --git a/dir.h b/dir.h
index 79b85a01ee4..279a0660801 100644
--- a/dir.h
+++ b/dir.h
@@ -1,6 +1,7 @@
 #ifndef DIR_H
 #define DIR_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 #include "pathspec.h"
 #include "statinfo.h"
diff --git a/entry.c b/entry.c
index 041f5cf212d..f9a7c726a4d 100644
--- a/entry.c
+++ b/entry.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "blob.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/environment.c b/environment.c
index 56e8742ea66..5e9b331279f 100644
--- a/environment.c
+++ b/environment.c
@@ -20,7 +20,7 @@
 #include "commit.h"
 #include "strvec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "replace-object.h"
 #include "tmp-objdir.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 207548b3e5a..a432eacab99 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
 #include "oid-array.h"
 #include "oidset.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index f096b1ef549..4da6c7a8bda 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -4,7 +4,7 @@
 #include "environment.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "hex.h"
diff --git a/fsck.c b/fsck.c
index 04e729953b2..a219d6f2c0a 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,8 +1,9 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "date.h"
+#include "dir.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "object.h"
diff --git a/grep.c b/grep.c
index f00986c451a..ebcd6474788 100644
--- a/grep.c
+++ b/grep.c
@@ -3,7 +3,7 @@
 #include "gettext.h"
 #include "grep.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pretty.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/hash-ll.h b/hash-ll.h
index 80509251370..8d7973769fd 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -270,6 +270,25 @@ static inline void oid_set_algo(struct object_id *oid, const struct git_hash_alg
 	oid->algo = hash_algo_by_ptr(algop);
 }
 
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+	/*
+	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+	 * platforms that don't support unaligned reads.
+	 */
+	unsigned int hash;
+	memcpy(&hash, oid->hash, sizeof(hash));
+	return hash;
+}
+
 const char *empty_tree_oid_hex(void);
 const char *empty_blob_oid_hex(void);
 
diff --git a/hashmap.h b/hashmap.h
index 2695f3d3a6e..c8216e47bb2 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -1,8 +1,6 @@
 #ifndef HASHMAP_H
 #define HASHMAP_H
 
-#include "hash-ll.h"
-
 /*
  * Generic implementation of hash-based key-value mappings.
  *
@@ -120,25 +118,6 @@ unsigned int memhash(const void *buf, size_t len);
 unsigned int memihash(const void *buf, size_t len);
 unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
 
-/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
-	/*
-	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
-	 * platforms that don't support unaligned reads.
-	 */
-	unsigned int hash;
-	memcpy(&hash, oid->hash, sizeof(hash));
-	return hash;
-}
-
 /*
  * struct hashmap_entry is an opaque structure representing an entry in the
  * hash table.
diff --git a/http-backend.c b/http-backend.c
index ddb9549ecbc..e1969c05dc6 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -16,7 +16,7 @@
 #include "url.h"
 #include "strvec.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "protocol.h"
 #include "date.h"
 #include "wrapper.h"
diff --git a/http-push.c b/http-push.c
index 29cf9db34e3..9ab2383d2b4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -18,7 +18,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit-reach.h"
 
 #ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index bba306b2d5e..78d99f7c4b0 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -7,7 +7,7 @@
 #include "list.h"
 #include "transport.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct alt_base {
 	char *base;
diff --git a/http.c b/http.c
index bb58bb3e6a3..25e4c8a1ae9 100644
--- a/http.c
+++ b/http.c
@@ -18,7 +18,7 @@
 #include "protocol.h"
 #include "string-list.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
 static int trace_curl_data = 1;
diff --git a/khash.h b/khash.h
index a0a08dad8b7..ff881631778 100644
--- a/khash.h
+++ b/khash.h
@@ -26,7 +26,6 @@
 #ifndef __AC_KHASH_H
 #define __AC_KHASH_H
 
-#include "hashmap.h"
 #include "hash.h"
 
 #define AC_VERSION_KHASH_H "0.2.8"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 5d270ce5987..e075a66c99d 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -16,7 +16,7 @@
 #include "oidmap.h"
 #include "oidset.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 /* Remember to update object flag allocation in object.h */
 /*
diff --git a/list-objects.c b/list-objects.c
index eecca721ac0..672a4cd5298 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -12,7 +12,7 @@
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "trace.h"
 
 struct traversal_context {
diff --git a/log-tree.c b/log-tree.c
index 60b61597c42..f807e286c88 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -5,7 +5,7 @@
 #include "environment.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "tmp-objdir.h"
 #include "commit.h"
diff --git a/mailmap.c b/mailmap.c
index 5dc5223c430..3d6a5e9400f 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -3,7 +3,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 
 const char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 6bc8eb76477..0885ac681cd 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,9 +1,10 @@
 #include "git-compat-util.h"
 #include "hex.h"
 #include "match-trees.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "tree-walk.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static int score_missing(unsigned mode)
 {
diff --git a/merge-blobs.c b/merge-blobs.c
index 40c48e3eba6..9293cbf75c8 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
 #include "merge-ll.h"
 #include "blob.h"
 #include "merge-blobs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
diff --git a/merge-ort.c b/merge-ort.c
index f4522951323..63786c81ece 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -34,7 +34,7 @@
 #include "match-trees.h"
 #include "mem-pool.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "path.h"
 #include "promisor-remote.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 35e1e7e1bef..43f6b2d0364 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -26,7 +26,7 @@
 #include "name-hash.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "revision.h"
diff --git a/midx.c b/midx.c
index b500174d1f3..db459e448b7 100644
--- a/midx.c
+++ b/midx.c
@@ -9,7 +9,7 @@
 #include "lockfile.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hash-lookup.h"
 #include "midx.h"
 #include "progress.h"
diff --git a/notes-cache.c b/notes-cache.c
index 14288caf98f..0e1d5b1ac7a 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,10 +1,11 @@
 #include "git-compat-util.h"
 #include "notes-cache.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pretty.h"
 #include "repository.h"
 #include "commit.h"
 #include "refs.h"
+#include "strbuf.h"
 
 static int notes_cache_match_validity(struct repository *r,
 				      const char *ref,
diff --git a/notes-merge.c b/notes-merge.c
index 4be11a01550..071947894ed 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -5,7 +5,7 @@
 #include "refs.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "diff.h"
diff --git a/notes.c b/notes.c
index 02f1aa39ae1..4d2836a7c76 100644
--- a/notes.c
+++ b/notes.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "notes.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "tree.h"
 #include "utf8.h"
diff --git a/object-name.c b/object-name.c
index 45f4d51305b..7e96c97051e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -17,7 +17,7 @@
 #include "oidtree.h"
 #include "packfile.h"
 #include "pretty.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/object-store-ll.h b/object-store-ll.h
new file mode 100644
index 00000000000..e8f22cdb1b5
--- /dev/null
+++ b/object-store-ll.h
@@ -0,0 +1,533 @@
+#ifndef OBJECT_STORE_LL_H
+#define OBJECT_STORE_LL_H
+
+#include "hashmap.h"
+#include "object.h"
+#include "list.h"
+#include "thread-utils.h"
+#include "oidset.h"
+
+struct oidmap;
+struct oidtree;
+struct strbuf;
+
+struct object_directory {
+	struct object_directory *next;
+
+	/*
+	 * Used to store the results of readdir(3) calls when we are OK
+	 * sacrificing accuracy due to races for speed. That includes
+	 * object existence with OBJECT_INFO_QUICK, as well as
+	 * our search for unique abbreviated hashes. Don't use it for tasks
+	 * requiring greater accuracy!
+	 *
+	 * Be sure to call odb_load_loose_cache() before using.
+	 */
+	uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
+	struct oidtree *loose_objects_cache;
+
+	/*
+	 * This is a temporary object store created by the tmp_objdir
+	 * facility. Disable ref updates since the objects in the store
+	 * might be discarded on rollback.
+	 */
+	int disable_ref_updates;
+
+	/*
+	 * This object store is ephemeral, so there is no need to fsync.
+	 */
+	int will_destroy;
+
+	/*
+	 * Path to the alternative object store. If this is a relative path,
+	 * it is relative to the current working directory.
+	 */
+	char *path;
+};
+
+struct input_stream {
+	const void *(*read)(struct input_stream *, unsigned long *len);
+	void *data;
+	int is_finished;
+};
+
+void prepare_alt_odb(struct repository *r);
+int has_alt_odb(struct repository *r);
+char *compute_alternate_path(const char *path, struct strbuf *err);
+struct object_directory *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct object_directory *, void *);
+int foreach_alt_odb(alt_odb_fn, void*);
+typedef void alternate_ref_fn(const struct object_id *oid, void *);
+void for_each_alternate_ref(alternate_ref_fn, void *);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void add_to_alternates_file(const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternates (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void add_to_alternates_memory(const char *dir);
+
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary object directory.
+ */
+struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+
+/*
+ * Restore a previous ODB replaced by set_temporary_main_odb.
+ */
+void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+
+/*
+ * Populate and return the loose object cache array corresponding to the
+ * given object ID.
+ */
+struct oidtree *odb_loose_cache(struct object_directory *odb,
+				  const struct object_id *oid);
+
+/* Empty the loose object cache for the specified object directory. */
+void odb_clear_loose_cache(struct object_directory *odb);
+
+/* Clear and free the specified object directory */
+void free_object_directory(struct object_directory *odb);
+
+struct packed_git {
+	struct hashmap_entry packmap_ent;
+	struct packed_git *next;
+	struct list_head mru;
+	struct pack_window *windows;
+	off_t pack_size;
+	const void *index_data;
+	size_t index_size;
+	uint32_t num_objects;
+	uint32_t crc_offset;
+	struct oidset bad_objects;
+	int index_version;
+	time_t mtime;
+	int pack_fd;
+	int index;              /* for builtin/pack-objects.c */
+	unsigned pack_local:1,
+		 pack_keep:1,
+		 pack_keep_in_core:1,
+		 freshened:1,
+		 do_not_close:1,
+		 pack_promisor:1,
+		 multi_pack_index:1,
+		 is_cruft:1;
+	unsigned char hash[GIT_MAX_RAWSZ];
+	struct revindex_entry *revindex;
+	const uint32_t *revindex_data;
+	const uint32_t *revindex_map;
+	size_t revindex_size;
+	/*
+	 * mtimes_map points at the beginning of the memory mapped region of
+	 * this pack's corresponding .mtimes file, and mtimes_size is the size
+	 * of that .mtimes file
+	 */
+	const uint32_t *mtimes_map;
+	size_t mtimes_size;
+	/* something like ".git/objects/pack/xxxxx.pack" */
+	char pack_name[FLEX_ARRAY]; /* more */
+};
+
+struct multi_pack_index;
+
+static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
+				     const struct hashmap_entry *entry,
+				     const struct hashmap_entry *entry2,
+				     const void *keydata)
+{
+	const char *key = keydata;
+	const struct packed_git *pg1, *pg2;
+
+	pg1 = container_of(entry, const struct packed_git, packmap_ent);
+	pg2 = container_of(entry2, const struct packed_git, packmap_ent);
+
+	return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
+}
+
+struct raw_object_store {
+	/*
+	 * Set of all object directories; the main directory is first (and
+	 * cannot be NULL after initialization). Subsequent directories are
+	 * alternates.
+	 */
+	struct object_directory *odb;
+	struct object_directory **odb_tail;
+	struct kh_odb_path_map *odb_by_path;
+
+	int loaded_alternates;
+
+	/*
+	 * A list of alternate object directories loaded from the environment;
+	 * this should not generally need to be accessed directly, but will
+	 * populate the "odb" list when prepare_alt_odb() is run.
+	 */
+	char *alternate_db;
+
+	/*
+	 * Objects that should be substituted by other objects
+	 * (see git-replace(1)).
+	 */
+	struct oidmap *replace_map;
+	unsigned replace_map_initialized : 1;
+	pthread_mutex_t replace_mutex; /* protect object replace functions */
+
+	struct commit_graph *commit_graph;
+	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
+
+	/*
+	 * private data
+	 *
+	 * should only be accessed directly by packfile.c and midx.c
+	 */
+	struct multi_pack_index *multi_pack_index;
+
+	/*
+	 * private data
+	 *
+	 * should only be accessed directly by packfile.c
+	 */
+
+	struct packed_git *packed_git;
+	/* A most-recently-used ordered version of the packed_git list. */
+	struct list_head packed_git_mru;
+
+	struct {
+		struct packed_git **packs;
+		unsigned flags;
+	} kept_pack_cache;
+
+	/*
+	 * A map of packfiles to packed_git structs for tracking which
+	 * packs have been loaded already.
+	 */
+	struct hashmap pack_map;
+
+	/*
+	 * A fast, rough count of the number of objects in the repository.
+	 * These two fields are not meant for direct access. Use
+	 * repo_approximate_object_count() instead.
+	 */
+	unsigned long approximate_object_count;
+	unsigned approximate_object_count_valid : 1;
+
+	/*
+	 * Whether packed_git has already been populated with this repository's
+	 * packs.
+	 */
+	unsigned packed_git_initialized : 1;
+};
+
+struct raw_object_store *raw_object_store_new(void);
+void raw_object_store_clear(struct raw_object_store *o);
+
+/*
+ * Put in `buf` the name of the file in the local object database that
+ * would be used to store a loose object with the specified oid.
+ */
+const char *loose_object_path(struct repository *r, struct strbuf *buf,
+			      const struct object_id *oid);
+
+void *map_loose_object(struct repository *r, const struct object_id *oid,
+		       unsigned long *size);
+
+void *repo_read_object_file(struct repository *r,
+			    const struct object_id *oid,
+			    enum object_type *type,
+			    unsigned long *size);
+
+/* Read and unpack an object file into memory, write memory to an object file */
+int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
+
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+		      unsigned long len, enum object_type type,
+		      struct object_id *oid);
+
+int write_object_file_flags(const void *buf, unsigned long len,
+			    enum object_type type, struct object_id *oid,
+			    unsigned flags);
+static inline int write_object_file(const void *buf, unsigned long len,
+				    enum object_type type, struct object_id *oid)
+{
+	return write_object_file_flags(buf, len, type, oid, 0);
+}
+
+int write_object_file_literally(const void *buf, unsigned long len,
+				const char *type, struct object_id *oid,
+				unsigned flags);
+int stream_loose_object(struct input_stream *in_stream, size_t len,
+			struct object_id *oid);
+
+/*
+ * Add an object file to the in-memory object store, without writing it
+ * to disk.
+ *
+ * Callers are responsible for calling write_object_file to record the
+ * object in persistent storage before writing any other new objects
+ * that reference it.
+ */
+int pretend_object_file(void *, unsigned long, enum object_type,
+			struct object_id *oid);
+
+int force_object_loose(const struct object_id *oid, time_t mtime);
+
+struct object_info {
+	/* Request */
+	enum object_type *typep;
+	unsigned long *sizep;
+	off_t *disk_sizep;
+	struct object_id *delta_base_oid;
+	struct strbuf *type_name;
+	void **contentp;
+
+	/* Response */
+	enum {
+		OI_CACHED,
+		OI_LOOSE,
+		OI_PACKED,
+		OI_DBCACHED
+	} whence;
+	union {
+		/*
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } cached;
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } loose;
+		 */
+		struct {
+			struct packed_git *pack;
+			off_t offset;
+			unsigned int is_delta;
+		} packed;
+	} u;
+};
+
+/*
+ * Initializer for a "struct object_info" that wants no items. You may
+ * also memset() the memory to all-zeroes.
+ */
+#define OBJECT_INFO_INIT { 0 }
+
+/* Invoke lookup_replace_object() on the given hash */
+#define OBJECT_INFO_LOOKUP_REPLACE 1
+/* Allow reading from a loose object file of unknown/bogus type */
+#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
+/* Do not retry packed storage after checking packed and loose storage */
+#define OBJECT_INFO_QUICK 8
+/*
+ * Do not attempt to fetch the object if missing (even if fetch_is_missing is
+ * nonzero).
+ */
+#define OBJECT_INFO_SKIP_FETCH_OBJECT 16
+/*
+ * This is meant for bulk prefetching of missing blobs in a partial
+ * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
+ */
+#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
+
+/* Die if object corruption (not just an object being missing) was detected. */
+#define OBJECT_INFO_DIE_IF_CORRUPT 32
+
+int oid_object_info_extended(struct repository *r,
+			     const struct object_id *,
+			     struct object_info *, unsigned flags);
+
+/*
+ * Open the loose object at path, check its hash, and return the contents,
+ * use the "oi" argument to assert things about the object, or e.g. populate its
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+		      const struct object_id *expected_oid,
+		      struct object_id *real_oid,
+		      void **contents,
+		      struct object_info *oi);
+
+/* Retry packed storage after checking packed and loose storage */
+#define HAS_OBJECT_RECHECK_PACKED 1
+
+/*
+ * Returns 1 if the object exists. This function will not lazily fetch objects
+ * in a partial clone.
+ */
+int has_object(struct repository *r, const struct object_id *oid,
+	       unsigned flags);
+
+/*
+ * These macros and functions are deprecated. If checking existence for an
+ * object that is likely to be missing and/or whose absence is relatively
+ * inconsequential (or is consequential but the caller is prepared to handle
+ * it), use has_object(), which has better defaults (no lazy fetch in a partial
+ * clone and no rechecking of packed storage). In the unlikely event that a
+ * caller needs to assert existence of an object that it fully expects to
+ * exist, and wants to trigger a lazy fetch in a partial clone, use
+ * oid_object_info_extended() with a NULL struct object_info.
+ *
+ * These functions can be removed once all callers have migrated to
+ * has_object() and/or oid_object_info_extended().
+ */
+int repo_has_object_file(struct repository *r, const struct object_id *oid);
+int repo_has_object_file_with_flags(struct repository *r,
+				    const struct object_id *oid, int flags);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name.  This function does not respect replace
+ * references.
+ */
+int has_loose_object_nonlocal(const struct object_id *);
+
+int has_loose_object(const struct object_id *);
+
+/**
+ * format_object_header() is a thin wrapper around s xsnprintf() that
+ * writes the initial "<type> <obj-len>" part of the loose object
+ * header. It returns the size that snprintf() returns + 1.
+ */
+int format_object_header(char *str, size_t size, enum object_type type,
+			 size_t objsize);
+
+void assert_oid_type(const struct object_id *oid, enum object_type expect);
+
+/*
+ * Enabling the object read lock allows multiple threads to safely call the
+ * following functions in parallel: repo_read_object_file(),
+ * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ *
+ * obj_read_lock() and obj_read_unlock() may also be used to protect other
+ * section which cannot execute in parallel with object reading. Since the used
+ * lock is a recursive mutex, these sections can even contain calls to object
+ * reading functions. However, beware that in these cases zlib inflation won't
+ * be performed in parallel, losing performance.
+ *
+ * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * any of its callees end up calling it, this recursive call won't benefit from
+ * parallel inflation.
+ */
+void enable_obj_read_lock(void);
+void disable_obj_read_lock(void);
+
+extern int obj_read_use_lock;
+extern pthread_mutex_t obj_read_mutex;
+
+static inline void obj_read_lock(void)
+{
+	if(obj_read_use_lock)
+		pthread_mutex_lock(&obj_read_mutex);
+}
+
+static inline void obj_read_unlock(void)
+{
+	if(obj_read_use_lock)
+		pthread_mutex_unlock(&obj_read_mutex);
+}
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+				 const char *path,
+				 void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+				const char *path,
+				void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+				 const char *path,
+				 void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+				struct strbuf *path,
+				each_loose_object_fn obj_cb,
+				each_loose_cruft_fn cruft_cb,
+				each_loose_subdir_fn subdir_cb,
+				void *data);
+int for_each_loose_file_in_objdir(const char *path,
+				  each_loose_object_fn obj_cb,
+				  each_loose_cruft_fn cruft_cb,
+				  each_loose_subdir_fn subdir_cb,
+				  void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+				      each_loose_object_fn obj_cb,
+				      each_loose_cruft_fn cruft_cb,
+				      each_loose_subdir_fn subdir_cb,
+				      void *data);
+
+/* Flags for for_each_*_object() below. */
+enum for_each_object_flags {
+	/* Iterate only over local objects, not alternates. */
+	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+	/* Only iterate over packs obtained from the promisor remote. */
+	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+
+	/*
+	 * Visit objects within a pack in packfile order rather than .idx order
+	 */
+	FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
+
+	/* Only iterate over packs that are not marked as kept in-core. */
+	FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
+
+	/* Only iterate over packs that do not have .keep files. */
+	FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
+};
+
+/*
+ * Iterate over all accessible loose objects without respect to
+ * reachability. By default, this includes both local and alternate objects.
+ * The order in which objects are visited is unspecified.
+ *
+ * Any flags specific to packs are ignored.
+ */
+int for_each_loose_object(each_loose_object_fn, void *,
+			  enum for_each_object_flags flags);
+
+/*
+ * Iterate over all accessible packed objects without respect to reachability.
+ * By default, this includes both local and alternate packs.
+ *
+ * Note that some objects may appear twice if they are found in multiple packs.
+ * Each pack is visited in an unspecified order. By default, objects within a
+ * pack are visited in pack-idx order (i.e., sorted by oid).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+				  struct packed_git *pack,
+				  uint32_t pos,
+				  void *data);
+int for_each_object_in_pack(struct packed_git *p,
+			    each_packed_object_fn, void *data,
+			    enum for_each_object_flags flags);
+int for_each_packed_object(each_packed_object_fn, void *,
+			   enum for_each_object_flags flags);
+
+#endif /* OBJECT_STORE_LL_H */
diff --git a/object-store.h b/object-store.h
index 12415e5ea73..1b3e3d7d014 100644
--- a/object-store.h
+++ b/object-store.h
@@ -1,537 +1,11 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
-#include "object.h"
-#include "list.h"
-#include "thread-utils.h"
 #include "khash.h"
 #include "dir.h"
-#include "oidset.h"
-
-struct oidmap;
-struct oidtree;
-struct strbuf;
-
-struct object_directory {
-	struct object_directory *next;
-
-	/*
-	 * Used to store the results of readdir(3) calls when we are OK
-	 * sacrificing accuracy due to races for speed. That includes
-	 * object existence with OBJECT_INFO_QUICK, as well as
-	 * our search for unique abbreviated hashes. Don't use it for tasks
-	 * requiring greater accuracy!
-	 *
-	 * Be sure to call odb_load_loose_cache() before using.
-	 */
-	uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
-	struct oidtree *loose_objects_cache;
-
-	/*
-	 * This is a temporary object store created by the tmp_objdir
-	 * facility. Disable ref updates since the objects in the store
-	 * might be discarded on rollback.
-	 */
-	int disable_ref_updates;
-
-	/*
-	 * This object store is ephemeral, so there is no need to fsync.
-	 */
-	int will_destroy;
-
-	/*
-	 * Path to the alternative object store. If this is a relative path,
-	 * it is relative to the current working directory.
-	 */
-	char *path;
-};
-
-struct input_stream {
-	const void *(*read)(struct input_stream *, unsigned long *len);
-	void *data;
-	int is_finished;
-};
+#include "object-store-ll.h"
 
 KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
 	struct object_directory *, 1, fspathhash, fspatheq)
 
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
-/*
- * Add the directory to the on-disk alternates file; the new entry will also
- * take effect in the current process.
- */
-void add_to_alternates_file(const char *dir);
-
-/*
- * Add the directory to the in-memory list of alternates (along with any
- * recursive alternates it points to), but do not modify the on-disk alternates
- * file.
- */
-void add_to_alternates_memory(const char *dir);
-
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
-
-/*
- * Populate and return the loose object cache array corresponding to the
- * given object ID.
- */
-struct oidtree *odb_loose_cache(struct object_directory *odb,
-				  const struct object_id *oid);
-
-/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
-
-/* Clear and free the specified object directory */
-void free_object_directory(struct object_directory *odb);
-
-struct packed_git {
-	struct hashmap_entry packmap_ent;
-	struct packed_git *next;
-	struct list_head mru;
-	struct pack_window *windows;
-	off_t pack_size;
-	const void *index_data;
-	size_t index_size;
-	uint32_t num_objects;
-	uint32_t crc_offset;
-	struct oidset bad_objects;
-	int index_version;
-	time_t mtime;
-	int pack_fd;
-	int index;              /* for builtin/pack-objects.c */
-	unsigned pack_local:1,
-		 pack_keep:1,
-		 pack_keep_in_core:1,
-		 freshened:1,
-		 do_not_close:1,
-		 pack_promisor:1,
-		 multi_pack_index:1,
-		 is_cruft:1;
-	unsigned char hash[GIT_MAX_RAWSZ];
-	struct revindex_entry *revindex;
-	const uint32_t *revindex_data;
-	const uint32_t *revindex_map;
-	size_t revindex_size;
-	/*
-	 * mtimes_map points at the beginning of the memory mapped region of
-	 * this pack's corresponding .mtimes file, and mtimes_size is the size
-	 * of that .mtimes file
-	 */
-	const uint32_t *mtimes_map;
-	size_t mtimes_size;
-	/* something like ".git/objects/pack/xxxxx.pack" */
-	char pack_name[FLEX_ARRAY]; /* more */
-};
-
-struct multi_pack_index;
-
-static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
-				     const struct hashmap_entry *entry,
-				     const struct hashmap_entry *entry2,
-				     const void *keydata)
-{
-	const char *key = keydata;
-	const struct packed_git *pg1, *pg2;
-
-	pg1 = container_of(entry, const struct packed_git, packmap_ent);
-	pg2 = container_of(entry2, const struct packed_git, packmap_ent);
-
-	return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
-}
-
-struct raw_object_store {
-	/*
-	 * Set of all object directories; the main directory is first (and
-	 * cannot be NULL after initialization). Subsequent directories are
-	 * alternates.
-	 */
-	struct object_directory *odb;
-	struct object_directory **odb_tail;
-	kh_odb_path_map_t *odb_by_path;
-
-	int loaded_alternates;
-
-	/*
-	 * A list of alternate object directories loaded from the environment;
-	 * this should not generally need to be accessed directly, but will
-	 * populate the "odb" list when prepare_alt_odb() is run.
-	 */
-	char *alternate_db;
-
-	/*
-	 * Objects that should be substituted by other objects
-	 * (see git-replace(1)).
-	 */
-	struct oidmap *replace_map;
-	unsigned replace_map_initialized : 1;
-	pthread_mutex_t replace_mutex; /* protect object replace functions */
-
-	struct commit_graph *commit_graph;
-	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
-
-	/*
-	 * private data
-	 *
-	 * should only be accessed directly by packfile.c and midx.c
-	 */
-	struct multi_pack_index *multi_pack_index;
-
-	/*
-	 * private data
-	 *
-	 * should only be accessed directly by packfile.c
-	 */
-
-	struct packed_git *packed_git;
-	/* A most-recently-used ordered version of the packed_git list. */
-	struct list_head packed_git_mru;
-
-	struct {
-		struct packed_git **packs;
-		unsigned flags;
-	} kept_pack_cache;
-
-	/*
-	 * A map of packfiles to packed_git structs for tracking which
-	 * packs have been loaded already.
-	 */
-	struct hashmap pack_map;
-
-	/*
-	 * A fast, rough count of the number of objects in the repository.
-	 * These two fields are not meant for direct access. Use
-	 * repo_approximate_object_count() instead.
-	 */
-	unsigned long approximate_object_count;
-	unsigned approximate_object_count_valid : 1;
-
-	/*
-	 * Whether packed_git has already been populated with this repository's
-	 * packs.
-	 */
-	unsigned packed_git_initialized : 1;
-};
-
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
-
-/*
- * Put in `buf` the name of the file in the local object database that
- * would be used to store a loose object with the specified oid.
- */
-const char *loose_object_path(struct repository *r, struct strbuf *buf,
-			      const struct object_id *oid);
-
-void *map_loose_object(struct repository *r, const struct object_id *oid,
-		       unsigned long *size);
-
-void *repo_read_object_file(struct repository *r,
-			    const struct object_id *oid,
-			    enum object_type *type,
-			    unsigned long *size);
-
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
-void hash_object_file(const struct git_hash_algo *algo, const void *buf,
-		      unsigned long len, enum object_type type,
-		      struct object_id *oid);
-
-int write_object_file_flags(const void *buf, unsigned long len,
-			    enum object_type type, struct object_id *oid,
-			    unsigned flags);
-static inline int write_object_file(const void *buf, unsigned long len,
-				    enum object_type type, struct object_id *oid)
-{
-	return write_object_file_flags(buf, len, type, oid, 0);
-}
-
-int write_object_file_literally(const void *buf, unsigned long len,
-				const char *type, struct object_id *oid,
-				unsigned flags);
-int stream_loose_object(struct input_stream *in_stream, size_t len,
-			struct object_id *oid);
-
-/*
- * Add an object file to the in-memory object store, without writing it
- * to disk.
- *
- * Callers are responsible for calling write_object_file to record the
- * object in persistent storage before writing any other new objects
- * that reference it.
- */
-int pretend_object_file(void *, unsigned long, enum object_type,
-			struct object_id *oid);
-
-int force_object_loose(const struct object_id *oid, time_t mtime);
-
-struct object_info {
-	/* Request */
-	enum object_type *typep;
-	unsigned long *sizep;
-	off_t *disk_sizep;
-	struct object_id *delta_base_oid;
-	struct strbuf *type_name;
-	void **contentp;
-
-	/* Response */
-	enum {
-		OI_CACHED,
-		OI_LOOSE,
-		OI_PACKED,
-		OI_DBCACHED
-	} whence;
-	union {
-		/*
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } cached;
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } loose;
-		 */
-		struct {
-			struct packed_git *pack;
-			off_t offset;
-			unsigned int is_delta;
-		} packed;
-	} u;
-};
-
-/*
- * Initializer for a "struct object_info" that wants no items. You may
- * also memset() the memory to all-zeroes.
- */
-#define OBJECT_INFO_INIT { 0 }
-
-/* Invoke lookup_replace_object() on the given hash */
-#define OBJECT_INFO_LOOKUP_REPLACE 1
-/* Allow reading from a loose object file of unknown/bogus type */
-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
-/* Do not retry packed storage after checking packed and loose storage */
-#define OBJECT_INFO_QUICK 8
-/*
- * Do not attempt to fetch the object if missing (even if fetch_is_missing is
- * nonzero).
- */
-#define OBJECT_INFO_SKIP_FETCH_OBJECT 16
-/*
- * This is meant for bulk prefetching of missing blobs in a partial
- * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
- */
-#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
-
-/* Die if object corruption (not just an object being missing) was detected. */
-#define OBJECT_INFO_DIE_IF_CORRUPT 32
-
-int oid_object_info_extended(struct repository *r,
-			     const struct object_id *,
-			     struct object_info *, unsigned flags);
-
-/*
- * Open the loose object at path, check its hash, and return the contents,
- * use the "oi" argument to assert things about the object, or e.g. populate its
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
-		      const struct object_id *expected_oid,
-		      struct object_id *real_oid,
-		      void **contents,
-		      struct object_info *oi);
-
-/* Retry packed storage after checking packed and loose storage */
-#define HAS_OBJECT_RECHECK_PACKED 1
-
-/*
- * Returns 1 if the object exists. This function will not lazily fetch objects
- * in a partial clone.
- */
-int has_object(struct repository *r, const struct object_id *oid,
-	       unsigned flags);
-
-/*
- * These macros and functions are deprecated. If checking existence for an
- * object that is likely to be missing and/or whose absence is relatively
- * inconsequential (or is consequential but the caller is prepared to handle
- * it), use has_object(), which has better defaults (no lazy fetch in a partial
- * clone and no rechecking of packed storage). In the unlikely event that a
- * caller needs to assert existence of an object that it fully expects to
- * exist, and wants to trigger a lazy fetch in a partial clone, use
- * oid_object_info_extended() with a NULL struct object_info.
- *
- * These functions can be removed once all callers have migrated to
- * has_object() and/or oid_object_info_extended().
- */
-int repo_has_object_file(struct repository *r, const struct object_id *oid);
-int repo_has_object_file_with_flags(struct repository *r,
-				    const struct object_id *oid, int flags);
-
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name.  This function does not respect replace
- * references.
- */
-int has_loose_object_nonlocal(const struct object_id *);
-
-int has_loose_object(const struct object_id *);
-
-/**
- * format_object_header() is a thin wrapper around s xsnprintf() that
- * writes the initial "<type> <obj-len>" part of the loose object
- * header. It returns the size that snprintf() returns + 1.
- */
-int format_object_header(char *str, size_t size, enum object_type type,
-			 size_t objsize);
-
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
-
-/*
- * Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
- *
- * obj_read_lock() and obj_read_unlock() may also be used to protect other
- * section which cannot execute in parallel with object reading. Since the used
- * lock is a recursive mutex, these sections can even contain calls to object
- * reading functions. However, beware that in these cases zlib inflation won't
- * be performed in parallel, losing performance.
- *
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
- * any of its callees end up calling it, this recursive call won't benefit from
- * parallel inflation.
- */
-void enable_obj_read_lock(void);
-void disable_obj_read_lock(void);
-
-extern int obj_read_use_lock;
-extern pthread_mutex_t obj_read_mutex;
-
-static inline void obj_read_lock(void)
-{
-	if(obj_read_use_lock)
-		pthread_mutex_lock(&obj_read_mutex);
-}
-
-static inline void obj_read_unlock(void)
-{
-	if(obj_read_use_lock)
-		pthread_mutex_unlock(&obj_read_mutex);
-}
-
-/*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-				 const char *path,
-				 void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-				const char *path,
-				void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-				 const char *path,
-				 void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-				struct strbuf *path,
-				each_loose_object_fn obj_cb,
-				each_loose_cruft_fn cruft_cb,
-				each_loose_subdir_fn subdir_cb,
-				void *data);
-int for_each_loose_file_in_objdir(const char *path,
-				  each_loose_object_fn obj_cb,
-				  each_loose_cruft_fn cruft_cb,
-				  each_loose_subdir_fn subdir_cb,
-				  void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-				      each_loose_object_fn obj_cb,
-				      each_loose_cruft_fn cruft_cb,
-				      each_loose_subdir_fn subdir_cb,
-				      void *data);
-
-/* Flags for for_each_*_object() below. */
-enum for_each_object_flags {
-	/* Iterate only over local objects, not alternates. */
-	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
-
-	/* Only iterate over packs obtained from the promisor remote. */
-	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
-
-	/*
-	 * Visit objects within a pack in packfile order rather than .idx order
-	 */
-	FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
-
-	/* Only iterate over packs that are not marked as kept in-core. */
-	FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
-
-	/* Only iterate over packs that do not have .keep files. */
-	FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
-};
-
-/*
- * Iterate over all accessible loose objects without respect to
- * reachability. By default, this includes both local and alternate objects.
- * The order in which objects are visited is unspecified.
- *
- * Any flags specific to packs are ignored.
- */
-int for_each_loose_object(each_loose_object_fn, void *,
-			  enum for_each_object_flags flags);
-
-/*
- * Iterate over all accessible packed objects without respect to reachability.
- * By default, this includes both local and alternate packs.
- *
- * Note that some objects may appear twice if they are found in multiple packs.
- * Each pack is visited in an unspecified order. By default, objects within a
- * pack are visited in pack-idx order (i.e., sorted by oid).
- */
-typedef int each_packed_object_fn(const struct object_id *oid,
-				  struct packed_git *pack,
-				  uint32_t pos,
-				  void *data);
-int for_each_object_in_pack(struct packed_git *p,
-			    each_packed_object_fn, void *data,
-			    enum for_each_object_flags flags);
-int for_each_packed_object(each_packed_object_fn, void *,
-			   enum for_each_object_flags flags);
-
 #endif /* OBJECT_STORE_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..3e190214d14 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 623ee2a8197..d86f4e739a4 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -3,7 +3,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tag.h"
 #include "diff.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index e0fad723bf3..3981655f3cf 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
 #include "repository.h"
 #include "trace2.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "list-objects-filter-options.h"
 #include "midx.h"
 #include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 049f2f0bfc0..977f619618e 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -7,7 +7,7 @@
 #include "progress.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct idx_entry {
 	off_t                offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 020a37f8fe3..cdf30b8d2b0 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -2,8 +2,9 @@
 #include "gettext.h"
 #include "pack-mtimes.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
+#include "strbuf.h"
 
 static char *pack_mtimes_filename(struct packed_git *p)
 {
diff --git a/pack-objects.h b/pack-objects.h
index 579476687c4..0d78db40cb2 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
 #ifndef PACK_OBJECTS_H
 #define PACK_OBJECTS_H
 
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "thread-utils.h"
 #include "pack.h"
 
diff --git a/pack-revindex.c b/pack-revindex.c
index 1f51b712e87..7fffcad9125 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -2,8 +2,9 @@
 #include "gettext.h"
 #include "pack-revindex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
+#include "strbuf.h"
 #include "trace2.h"
 #include "config.h"
 #include "midx.h"
diff --git a/pack-write.c b/pack-write.c
index 45681e2d7db..af48813a9bb 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -11,6 +11,7 @@
 #include "pack-objects.h"
 #include "pack-revindex.h"
 #include "path.h"
+#include "strbuf.h"
 #include "wrapper.h"
 
 void reset_pack_idx_option(struct pack_idx_option *opts)
diff --git a/packfile.c b/packfile.c
index fd083c86e00..c60aeb05ece 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
 #include "tree-walk.h"
 #include "tree.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "midx.h"
 #include "commit-graph.h"
 #include "pack-revindex.h"
diff --git a/path.c b/path.c
index 7c1cd8182a8..c3b6618c77b 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
 #include "submodule-config.h"
 #include "path.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "lockfile.h"
 #include "exec-cmd.h"
 #include "wrapper.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 1adcd6fb0a5..db88d2064d4 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "config.h"
 #include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index a90c48852e5..808a68c974a 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,7 +7,7 @@
 #include "hash-ll.h"
 #include "hex.h"
 #include "object.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "string-list.h"
 #include "strbuf.h"
 
diff --git a/prune-packed.c b/prune-packed.c
index 58412b4fb91..e54daf740a2 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "progress.h"
 #include "prune-packed.h"
diff --git a/reachable.c b/reachable.c
index 55bb1143530..434f09e9ebf 100644
--- a/reachable.c
+++ b/reachable.c
@@ -13,7 +13,7 @@
 #include "list-objects.h"
 #include "packfile.h"
 #include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack-bitmap.h"
 #include "pack-mtimes.h"
 
diff --git a/read-cache.c b/read-cache.c
index 86ada403a83..b9a995e5a18 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -17,7 +17,7 @@
 #include "refs.h"
 #include "dir.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 4991cd4f7a8..e0d03a9f8e9 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -8,7 +8,7 @@
 #include "refs.h"
 #include "wildmatch.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/reflog.c b/reflog.c
index ee1bf5d032c..9ad50e7d93e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "reflog.h"
 #include "refs.h"
 #include "revision.h"
diff --git a/refs.c b/refs.c
index 5f76da35673..54a827b45b3 100644
--- a/refs.c
+++ b/refs.c
@@ -17,7 +17,7 @@
 #include "run-command.h"
 #include "hook.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "path.h"
 #include "tag.h"
diff --git a/remote.c b/remote.c
index 8550056db43..6538b6037de 100644
--- a/remote.c
+++ b/remote.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/remote.h b/remote.h
index 73638cefeb1..929c7c676d3 100644
--- a/remote.h
+++ b/remote.h
@@ -1,6 +1,7 @@
 #ifndef REMOTE_H
 #define REMOTE_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 #include "refspec.h"
 
diff --git a/replace-object.c b/replace-object.c
index e98825d5852..ca4017635df 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "refs.h"
 #include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index 500482b02b3..a964db1670e 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
 
 #include "oidmap.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 /*
  * Do replace refs need to be checked this run?  This variable is
diff --git a/repository.c b/repository.c
index 87a7a27b665..8c77b7ed236 100644
--- a/repository.c
+++ b/repository.c
@@ -6,7 +6,7 @@
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3584fecb07c..e2b8597f88c 100644
--- a/rerere.c
+++ b/rerere.c
@@ -17,7 +17,7 @@
 #include "path.h"
 #include "pathspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hash-lookup.h"
 #include "strmap.h"
 #include "wrapper.h"
diff --git a/revision.c b/revision.c
index d4b4b34fd80..84768565cef 100644
--- a/revision.c
+++ b/revision.c
@@ -6,7 +6,7 @@
 #include "hex.h"
 #include "object-name.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "tag.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/send-pack.c b/send-pack.c
index 0c7ccaef680..9510bef8561 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index eddd38d4bed..1b9607da268 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -11,7 +11,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "pager.h"
 #include "commit.h"
diff --git a/serve.c b/serve.c
index 5329c91011f..a1d71134d49 100644
--- a/serve.c
+++ b/serve.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "repository.h"
 #include "config.h"
+#include "hash-ll.h"
 #include "pkt-line.h"
 #include "version.h"
 #include "ls-refs.h"
diff --git a/server-info.c b/server-info.c
index 85d17bbb151..382e481a2b0 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
 #include "packfile.h"
 #include "path.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "server-info.h"
 #include "strbuf.h"
 #include "wrapper.h"
diff --git a/shallow.c b/shallow.c
index 45343e6a78b..f3ef94d4c92 100644
--- a/shallow.c
+++ b/shallow.c
@@ -4,7 +4,7 @@
 #include "repository.h"
 #include "tempfile.h"
 #include "lockfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 21e39585e89..49791ab958d 100644
--- a/streaming.c
+++ b/streaming.c
@@ -7,7 +7,7 @@
 #include "streaming.h"
 #include "repository.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "packfile.h"
 #include "wrapper.h"
diff --git a/submodule-config.c b/submodule-config.c
index c67260a3e11..1efd5471698 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -11,7 +11,7 @@
 #include "submodule.h"
 #include "strbuf.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index 245300596ff..f0f8788d2e3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
 #include "parse-options.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit-reach.h"
 #include "read-cache-ll.h"
 #include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 0f3fbeec532..67a964ef904 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "hex.h"
 #include "strbuf.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "pack-mtimes.h"
 #include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 362bd64a4c2..910a1286144 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "hex.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 
 /*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 3ac496e27e4..8c7a83f578f 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "commit-graph.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "bloom.h"
 #include "setup.h"
 
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 211addaa005..e9a444ddba5 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -2,7 +2,7 @@
 #include "hex.h"
 #include "midx.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack-bitmap.h"
 #include "packfile.h"
 #include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 1b30a6cba8b..04d26fc2fef 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -3,9 +3,10 @@
 #include "refs.h"
 #include "setup.h"
 #include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
+#include "strbuf.h"
 
 struct flag_definition {
 	const char *name;
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index bafd2a5bf95..4cd8a952e5c 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -4,7 +4,7 @@
 #include "config.h"
 #include "environment.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/tag.c b/tag.c
index 96dbd5b2d55..c5426484b22 100644
--- a/tag.c
+++ b/tag.c
@@ -2,7 +2,7 @@
 #include "environment.h"
 #include "tag.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index db1f7038dae..5f9074ad1c0 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -11,7 +11,7 @@
 #include "strbuf.h"
 #include "strvec.h"
 #include "quote.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct tmp_objdir {
 	struct strbuf path;
diff --git a/transport.c b/transport.c
index 67afdae57c1..4dc187a3885 100644
--- a/transport.c
+++ b/transport.c
@@ -27,7 +27,7 @@
 #include "transport-internal.h"
 #include "protocol.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "color.h"
 #include "bundle-uri.h"
 #include "wrapper.h"
diff --git a/tree-walk.c b/tree-walk.c
index d3c48e06df0..42ed86ef581 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "trace2.h"
 #include "tree.h"
 #include "pathspec.h"
diff --git a/tree.c b/tree.c
index 0dd2029a8a2..e118914a76a 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 4b620df3031..87517364dc0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -23,7 +23,7 @@
 #include "symlinks.h"
 #include "trace2.h"
 #include "fsmonitor.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "entry.h"
 #include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 08633dc1216..2502dcb4699 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -7,7 +7,7 @@
 #include "pkt-line.h"
 #include "sideband.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "tag.h"
 #include "object.h"
diff --git a/walker.c b/walker.c
index 24ff7dfdc28..65002a7220a 100644
--- a/walker.c
+++ b/walker.c
@@ -3,8 +3,9 @@
 #include "hex.h"
 #include "walker.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "tag.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 0460e03f5ed..abc7275a528 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "strbuf.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
-- 
gitgitgadget


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

* [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (25 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
@ 2023-05-12  7:04   ` Elijah Newren via GitGitGadget
  2023-05-16  0:17     ` Jonathan Tan
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
  27 siblings, 1 reply; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-12  7:04 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Elijah Newren,
	Elijah Newren

From: Elijah Newren <newren@gmail.com>

This creates a new fsmonitor-ll.h with most of the functions from
fsmonitor.h, though it leaves three inline functions where they were.
Two-thirds of the files that previously included fsmonitor.h did not
need those three inline functions or the six extra includes those inline
functions required, so this allows them to only include the lower level
header.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/fsmonitor--daemon.c              |  4 +-
 compat/fsmonitor/fsm-health-darwin.c     |  2 +-
 compat/fsmonitor/fsm-health-win32.c      |  2 +-
 compat/fsmonitor/fsm-ipc-darwin.c        |  2 +-
 compat/fsmonitor/fsm-listen-darwin.c     |  3 +-
 compat/fsmonitor/fsm-listen-win32.c      |  2 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |  3 +-
 compat/fsmonitor/fsm-path-utils-win32.c  |  3 +-
 compat/fsmonitor/fsm-settings-darwin.c   |  2 +-
 compat/fsmonitor/fsm-settings-win32.c    |  2 +-
 dir.c                                    |  3 +-
 fsmonitor-ipc.c                          |  2 +-
 fsmonitor-ll.h                           | 52 ++++++++++++++++++++++++
 fsmonitor.h                              | 46 +--------------------
 sparse-index.c                           |  3 +-
 15 files changed, 73 insertions(+), 58 deletions(-)
 create mode 100644 fsmonitor-ll.h

diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index f6dd9a784c1..74d1d6a585d 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -5,15 +5,17 @@
 #include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-path-utils.h"
+#include "fsmonitor-settings.h"
 #include "compat/fsmonitor/fsm-health.h"
 #include "compat/fsmonitor/fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "simple-ipc.h"
 #include "khash.h"
 #include "pkt-line.h"
+#include "trace.h"
 #include "trace2.h"
 
 static const char * const builtin_fsmonitor__daemon_usage[] = {
diff --git a/compat/fsmonitor/fsm-health-darwin.c b/compat/fsmonitor/fsm-health-darwin.c
index 4c291f8a066..5b1709d63f7 100644
--- a/compat/fsmonitor/fsm-health-darwin.c
+++ b/compat/fsmonitor/fsm-health-darwin.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
 
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index 6c81d7ee5c2..2d4e245beb1 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 964bc074db6..6f3a95410cc 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -5,7 +5,7 @@
 #include "path.h"
 #include "repository.h"
 #include "strbuf.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-path-utils.h"
 
diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 23e24b4b374..36c7e13281c 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -24,12 +24,13 @@
 #endif
 
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
 #include "string-list.h"
+#include "trace.h"
 
 struct fsm_listen_data
 {
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 3c0df5cff8c..a361a7db20e 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index ef0142e0fbf..049f97eaaf2 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
+#include "trace.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 27bb6945183..c8a3e9dcdbb 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
+#include "trace.h"
 
 /*
  * Check remote working directory protocol.
diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c
index 58b623fbb9a..a3825906351 100644
--- a/compat/fsmonitor/fsm-settings-darwin.c
+++ b/compat/fsmonitor/fsm-settings-darwin.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index 37288978643..b6f67444944 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "repository.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
 
diff --git a/dir.c b/dir.c
index fada2713b9e..3acac7beb11 100644
--- a/dir.c
+++ b/dir.c
@@ -24,7 +24,8 @@
 #include "utf8.h"
 #include "varint.h"
 #include "ewah/ewok.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "submodule-config.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6ace978a1b4..88575aa54ca 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "gettext.h"
 #include "simple-ipc.h"
 #include "fsmonitor-ipc.h"
diff --git a/fsmonitor-ll.h b/fsmonitor-ll.h
new file mode 100644
index 00000000000..0504ca07d62
--- /dev/null
+++ b/fsmonitor-ll.h
@@ -0,0 +1,52 @@
+#ifndef FSMONITOR_LL_H
+#define FSMONITOR_LL_H
+
+struct index_state;
+struct strbuf;
+
+extern struct trace_key trace_fsmonitor;
+
+/*
+ * Read the fsmonitor index extension and (if configured) restore the
+ * CE_FSMONITOR_VALID state.
+ */
+int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
+
+/*
+ * Fill the fsmonitor_dirty ewah bits with their state from the index,
+ * before it is split during writing.
+ */
+void fill_fsmonitor_bitmap(struct index_state *istate);
+
+/*
+ * Write the CE_FSMONITOR_VALID state into the fsmonitor index
+ * extension.  Reads from the fsmonitor_dirty ewah in the index.
+ */
+void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension
+ */
+void add_fsmonitor(struct index_state *istate);
+void remove_fsmonitor(struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension as necessary based on the current
+ * core.fsmonitor setting.
+ */
+void tweak_fsmonitor(struct index_state *istate);
+
+/*
+ * Run the configured fsmonitor integration script and clear the
+ * CE_FSMONITOR_VALID bit for any files returned as dirty.  Also invalidate
+ * any corresponding untracked cache directory structures. Optimized to only
+ * run the first time it is called.
+ */
+void refresh_fsmonitor(struct index_state *istate);
+
+/*
+ * Does the received result contain the "trivial" response?
+ */
+int fsmonitor_is_trivial_response(const struct strbuf *query_result);
+
+#endif /* FSMONITOR_LL_H */
diff --git a/fsmonitor.h b/fsmonitor.h
index 7702301d214..5195a8624db 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,57 +1,13 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
+#include "fsmonitor-ll.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
 #include "object.h"
 #include "read-cache-ll.h"
 #include "trace.h"
 
-extern struct trace_key trace_fsmonitor;
-
-/*
- * Read the fsmonitor index extension and (if configured) restore the
- * CE_FSMONITOR_VALID state.
- */
-int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
-
-/*
- * Fill the fsmonitor_dirty ewah bits with their state from the index,
- * before it is split during writing.
- */
-void fill_fsmonitor_bitmap(struct index_state *istate);
-
-/*
- * Write the CE_FSMONITOR_VALID state into the fsmonitor index
- * extension.  Reads from the fsmonitor_dirty ewah in the index.
- */
-void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension
- */
-void add_fsmonitor(struct index_state *istate);
-void remove_fsmonitor(struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension as necessary based on the current
- * core.fsmonitor setting.
- */
-void tweak_fsmonitor(struct index_state *istate);
-
-/*
- * Run the configured fsmonitor integration script and clear the
- * CE_FSMONITOR_VALID bit for any files returned as dirty.  Also invalidate
- * any corresponding untracked cache directory structures. Optimized to only
- * run the first time it is called.
- */
-void refresh_fsmonitor(struct index_state *istate);
-
-/*
- * Does the received result contain the "trivial" response?
- */
-int fsmonitor_is_trivial_response(const struct strbuf *query_result);
-
 /*
  * Check if refresh_fsmonitor has been called at least once.
  * refresh_fsmonitor is idempotent. Returns true if fsmonitor is
diff --git a/sparse-index.c b/sparse-index.c
index 2c47954d933..90d04622568 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -3,6 +3,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
@@ -11,7 +12,7 @@
 #include "cache-tree.h"
 #include "config.h"
 #include "dir.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 
 struct modify_index_context {
 	struct index_state *write;
-- 
gitgitgadget

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

* Re: [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug
  2023-05-12  1:21     ` Elijah Newren
@ 2023-05-12 17:26       ` Glen Choo
  0 siblings, 0 replies; 115+ messages in thread
From: Glen Choo @ 2023-05-12 17:26 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Elijah Newren via GitGitGadget, git

Thanks for the response. I realized where my misunderstanding was.

Once again reordering slightly..

Elijah Newren <newren@gmail.com> writes:

>> Where I struggling with is how to make this behave badly. The lines
>> above seem to be defensive in nature - we never use
>> is_bare_repository_cfg past this point, but we want to guard against
>> unintentional behavior in the future.
>
> Not quite true; there is another call to is_bare_repository() in the
> same function about 60 lines later, which does pay attention to
> is_bare_repository_cfg.

Ah thanks. I didn't realize that the "is_bare_repository_cfg" that holds
the value of the CLI option is actually the global variable that also
stores cached value of "core.bare" (I thought it was a local variable).

This may not be in scope for your series, but if we want to preserve the
CLI option like we say we do...

>> Now, we're in the midst of the re-init. Expanding the context a little,
>> we see:
>>
>>         git_config(git_default_config, NULL);
>>
>>         /*
>>          * We must make sure command-line options continue to override any
>>          * values we might have just re-read from the config.
>>          */
>>         is_bare_repository_cfg = init_is_bare_repository || !work_tree;
>>
>> So now we've read the new config of the re-inited repo, which might have
>> "core.bare" set to a value other than what "git init-db [--bare]"
>> started with
>
> Correct.
>
>> so we want to _intentionally_ ignore it.
>
> That's what the code does, but not what it should do.  If neither
> `--bare` nor `--no-bare` is given on the command line, we ought to pay
> attention to the config setting.
>
> The fact that we do ignore the config regardless of command line flags
> is the bug that this patch documents.

wouldn't be a lot easier to parse the option into a local variable
instead of reusing the config one? Then we always have the original CLI
value available to us and can restore it back to
"is_bare_repository_cfg" if we really wanted to.

I'm not sure if this means we can/should drop the "|| !work_tree" in the
hunk above. It would nice if we could, I find it very confusing.

> So, both before and after what we are computing simplifies to
>    <something> && !work_tree || !work_tree
> which further simplifies, regardless of whether <something> is true or
> false, down to
>    !work_tree
>
> So whether we are using a cached value of is_bare_repository_cfg or a
> current value of is_bare_repository_cfg is irrelevant.  In fact, from
> the analysis above, we can simplify this line to just
>    is_bare_repository_cfg = !work_tree;
> completely ignoring both is_bare_repository_cfg and
> is_bare_repository(), and it won't change the behavior.  I just did
> it; it passes all tests.

Hm.. that doesn't sound intended, and fixing this is probably isn't in
scope for this series either.

>> If I'm right (which I'm not sure about), we might need to keep
>> init_is_bare_repository around _somewhere_. Not a global, but maybe
>> as a param.
>
> This makes sense, despite the other bugs present.  I'll make this
> change, as well as split this patch into two as Calvin suggested, and
> update the description to correct my errors and explain the bug
> better.

Yeah, I think this might be the smallest obviously correct thing. We can
clean up all of the other bits outside of a big refactor series.

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

* Re: [PATCH v2 02/27] init-db: remove unnecessary global variable
  2023-05-12  7:04   ` [PATCH v2 02/27] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
@ 2023-05-12 20:20     ` Glen Choo
  0 siblings, 0 replies; 115+ messages in thread
From: Glen Choo @ 2023-05-12 20:20 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget, git; +Cc: Elijah Newren, Calvin Wan, Jeff King

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> init_is_bare_repository's sole use in life it to cache a value in
> init_db(), and then be used in create_default_files().  This is a bit
> odd since init_db() directly calls create_default_files(), and is the
> only caller of that function.  Convert the global to a simple function
> parameter instead.
>
> (Of course, this doesn't fix the fact that this value is then ignored by
> create_default_files(), as noted in a big TODO comment in that function,
> but it at least includes no behavioral change other than getting rid of
> a very questionable global variable.)

Ah, I didn't spot v2 when I typed my earlier reply. Yeah this makes a
lot of sense within this series.

> @@ -31,7 +31,6 @@
>  
>  #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
>  
> -static int init_is_bare_repository = 0;
>  static int init_shared_repository = -1;
>  
>  static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
> @@ -199,6 +198,7 @@ static int create_default_files(const char *template_path,
>  				const char *original_git_dir,
>  				const char *initial_branch,
>  				const struct repository_format *fmt,
> +				int prev_bare_repository,
>  				int quiet)
>  {
>  	struct stat st1;
> @@ -237,7 +237,7 @@ static int create_default_files(const char *template_path,
>  	 * TODO: heed core.bare from config file in templates if no
>  	 *       command-line override given
>  	 */
> -	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
> +	is_bare_repository_cfg = prev_bare_repository || !work_tree;
>  	/* TODO (continued):
>  	 *
>  	 * Unfortunately, the line above is equivalent to
> @@ -246,7 +246,7 @@ static int create_default_files(const char *template_path,
>  	 * command line option was present.
>  	 *
>  	 * To see why, note that before this function, there was this call:
> -	 *    init_is_bare_repository = is_bare_repository()
> +	 *    prev_bare_repository = is_bare_repository()
>  	 * expanding the right hande side:
>  	 *                 = is_bare_repository_cfg && !get_git_work_tree()
>  	 *                 = is_bare_repository_cfg && !work_tree
> @@ -256,7 +256,7 @@ static int create_default_files(const char *template_path,
>  	 * calls will return the same result each time.  So, what we are
>  	 * interested in computing is the right hand side of the line of
>  	 * code just above this comment:
> -	 *     init_is_bare_repository || !work_tree
> +	 *     prev_bare_repository || !work_tree
>  	 *        = is_bare_repository_cfg && !work_tree || !work_tree
>  	 *        = !work_tree
>  	 * because "A && !B || !B == !B" for all boolean values of A & B.
> @@ -424,6 +424,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
>  	int exist_ok = flags & INIT_DB_EXIST_OK;
>  	char *original_git_dir = real_pathdup(git_dir, 1);
>  	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
> +	int prev_bare_repository;
>  
>  	if (real_git_dir) {
>  		struct stat st;
> @@ -449,7 +450,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
>  
>  	safe_create_dir(git_dir, 0);
>  
> -	init_is_bare_repository = is_bare_repository();
> +	prev_bare_repository = is_bare_repository();
>  
>  	/* Check to see if the repository version is right.
>  	 * Note that a newly created repository does not have
> @@ -462,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
>  
>  	reinit = create_default_files(template_dir, original_git_dir,
>  				      initial_branch, &repo_fmt,
> +				      prev_bare_repository,
>  				      flags & INIT_DB_QUIET);
>  	if (reinit && initial_branch)
>  		warning(_("re-init: ignored --initial-branch=%s"),

The patch looks trivially correct.

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

* Re: [PATCH v2 05/27] read-cache: move shared commit and ls-files code
  2023-05-12  7:04   ` [PATCH v2 05/27] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
@ 2023-05-12 21:25     ` Jonathan Tan
  0 siblings, 0 replies; 115+ messages in thread
From: Jonathan Tan @ 2023-05-12 21:25 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> -void overlay_tree_on_index(struct index_state *istate,
> -			   const char *tree_name, const char *prefix)
 
Thanks for moving the code in such a way that it's easy to see with
--color-moved. I saw that there was no corresponding .h change (unlike
the parent), but this function is declared in cache.h, so that makes
sense. (I think this will be dealt later on in this series anyway.)

Up to here looks good.

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

* Re: [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter
  2023-05-12  7:04   ` [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
@ 2023-05-12 21:28     ` Jonathan Tan
  2023-05-16  2:57       ` Elijah Newren
  0 siblings, 1 reply; 115+ messages in thread
From: Jonathan Tan @ 2023-05-12 21:28 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
> 
> Much like the former commit, this commit was prompted by a desire to

Could we have s/former/parent? I'm not used to "former" with this
meaning (but if it's understood by others, then that's fine).

> diff --git a/builtin/clone.c b/builtin/clone.c
> index 15f9912b4ca..cc34c194f5e 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  	int submodule_progress;
>  	int filter_submodules = 0;
>  	int hash_algo;
> +	const int do_not_override_repo_unix_permissions = -1;

I don't really like this name, but init_db() is undocumented so an
anonymous -1 at the call site is not much better. For the purposes of
this patch set (getting rid of cache.h), this should be fine for now.

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

* Re: [PATCH v2 01/27] init-db: document existing bug with core.bare in template config
  2023-05-12  7:04   ` [PATCH v2 01/27] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
@ 2023-05-12 21:34     ` Jonathan Tan
  2023-05-16  3:08       ` Elijah Newren
  0 siblings, 1 reply; 115+ messages in thread
From: Jonathan Tan @ 2023-05-12 21:34 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> -	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
>  	if (init_shared_repository != -1)
>  		set_shared_repository(init_shared_repository);
> +	/*
> +	 * TODO: heed core.bare from config file in templates if no
> +	 *       command-line override given
> +	 */
> +	is_bare_repository_cfg = init_is_bare_repository || !work_tree;

This patch moves this line down a few lines, but that's fine because
set_shared_repository() doesn't modify any of the relevant variables.

> +	/* TODO (continued):
> +	 *
> +	 * Unfortunately, the line above is equivalent to
> +	 *    is_bare_repository_cfg = !work_tree;
> +	 * which ignores the config entirely even if no `--[no-]bare`
> +	 * command line option was present.
> +	 *
> +	 * To see why, note that before this function, there was this call:
> +	 *    init_is_bare_repository = is_bare_repository()

This is in init_db(), indeed.

> +	 * expanding the right hande side:

s/hande/hand/

> +	 *                 = is_bare_repository_cfg && !get_git_work_tree()
> +	 *                 = is_bare_repository_cfg && !work_tree
> +	 * note that the last simplification above is valid because nothing
> +	 * calls repo_init() or set_git_work_tree() between any of the
> +	 * relevant calls in the code,

Yes, the only calls are check_repository_format() and
validate_hash_algorithm() (as can be seen in init_db()) before
get_git_work_tree() is called at the start of create_default_files().

> diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
> index 1b6437ec079..c02fd64793b 100755
> --- a/t/t1301-shared-repo.sh
> +++ b/t/t1301-shared-repo.sh
> @@ -52,6 +52,28 @@ test_expect_success 'shared=all' '
>  	test 2 = $(git config core.sharedrepository)
>  '
>  
> +test_expect_failure 'template can set core.bare' '

I would have preferred a test_expect_success with the exact failing line
documented and prepended with test_must_fail, but I can see why someone
would prefer test_expect_failure.

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

* Re: [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals
  2023-05-12  7:04   ` [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
@ 2023-05-15 21:44     ` Jonathan Tan
  0 siblings, 0 replies; 115+ messages in thread
From: Jonathan Tan @ 2023-05-15 21:44 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
> 
> The function add_files_to_cache() is used by all three of builtin/{add,
> checkout, commit}.c.  That suggests this is common library code, and
> should be moved somewhere else, like read-cache.c.  However, the
> function and its helpers made use of two global variables that made
> straight code movement difficult:
>   * the_index
>   * include_sparse

I was checking that add_filer_to_cache() did not inadvertently use these
global variables even after the refactoring, and it looks good. It's a
pity that we can't remove the USE_THE_INDEX_VARIABLE #define even after
this patch (other parts in builtin/add.c use it), but I couldn't see
any more usages of the_index in that function. There is no more usage
of include_sparse, indeed, as can be seen from the next patch (when the
function is moved to another file that has no access to include_sparse
declared in builtin/add.c).
 

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

* Re: [PATCH v2 15/27] repository.h: move declaration of the_index from cache.h
  2023-05-12  7:04   ` [PATCH v2 15/27] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
@ 2023-05-15 21:50     ` Jonathan Tan
  0 siblings, 0 replies; 115+ messages in thread
From: Jonathan Tan @ 2023-05-15 21:50 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
> 
> the_index is a global variable defined in repository.c; as such, its
> declaration feels better suited living in repository.h rather than
> cache.h.  Move it.
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>

Up to here looks good. Now to look at the read-cache-ll/read-cache split
in patch 16...
 

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

* Re: [PATCH v2 16/27] read-cache*.h: move declarations for read-cache.c functions from cache.h
  2023-05-12  7:04   ` [PATCH v2 16/27] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
@ 2023-05-16  0:00     ` Jonathan Tan
  0 siblings, 0 replies; 115+ messages in thread
From: Jonathan Tan @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
> 
> For the functions defined in read-cache.c, move their declarations from
> cache.h to a new header, read-cache-ll.h.  Also move some related inline
> functions from cache.h to read-cache.h.  The purpose of the
> read-cache-ll.h/read-cache.h split is that about 70% of the sites don't
> need the inline functions and the extra headers they include.

Ah, the 70% is not something I would have expected, but since this is
the case, the split into -ll and without makes sense. Up to here looks
good.
 

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

* Re: [PATCH v2 17/27] cache.h: remove this no-longer-used header
  2023-05-12  7:04   ` [PATCH v2 17/27] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
@ 2023-05-16  0:02     ` Jonathan Tan
  2023-05-16  3:02       ` Elijah Newren
  0 siblings, 1 reply; 115+ messages in thread
From: Jonathan Tan @ 2023-05-16  0:02 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
> 
> Since this header showed up in some places besides just #include
> statements, update/clean-up/remove those other places as well.
> 
> Note that compat/fsmonitor/fsm-path-utils-darwin.c previously got
> away with violating the rule that all files must start with an include
> of git-compat-util.h (or a short-list of alternate headers that happen
> to include it first).  This change exposed the violation and caused it
> to stop building correctly; fix it by having it include
> git-compat-util.h first, as per policy.
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>

Ah, a monumental effort indeed (to finally remove cache.h). This patch
was one of a few called out in the cover letter [1] as needing reviewer
focus, but this patch seemed straightforward to me (changing the text
wherever cache.h is mentioned in relatively obvious ways) so hopefully
I'm not missing anything.
 

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

* Re: [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-12  7:04   ` [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
@ 2023-05-16  0:16     ` Jonathan Tan
  2023-05-16  3:06       ` Elijah Newren
  0 siblings, 1 reply; 115+ messages in thread
From: Jonathan Tan @ 2023-05-16  0:16 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
 
> Move this function to hash-ll, so that khash.h can stop depending upon
> hashmap.h.

[snip]

> Diff best viewed with `--color-moved`.  Note that there's a small but
> important change to khash.h in this patch as well to allow this move,
> which is easy to overlook.

[snip]

> diff --git a/khash.h b/khash.h
> index a0a08dad8b7..ff881631778 100644
> --- a/khash.h
> +++ b/khash.h
> @@ -26,7 +26,6 @@
>  #ifndef __AC_KHASH_H
>  #define __AC_KHASH_H
>  
> -#include "hashmap.h"
>  #include "hash.h"

Is this the small but important change to khash.h? I thought that this
is the reason for the change, not what "allow[ed]" this move.

> diff --git a/object-name.c b/object-name.c
> index 45f4d51305b..7e96c97051e 100644
> --- a/object-name.c
> +++ b/object-name.c

[snip]

> +struct raw_object_store {
> +	/*
> +	 * Set of all object directories; the main directory is first (and
> +	 * cannot be NULL after initialization). Subsequent directories are
> +	 * alternates.
> +	 */
> +	struct object_directory *odb;
> +	struct object_directory **odb_tail;
> +	struct kh_odb_path_map *odb_by_path;

This is not present as a minus line (that line uses kh_odb_path_map_t).
I thought this was so that we could forward declare "struct
kh_odb_path_map", but I don't see such a forward declaration. (Was it
declared elsewhere?)

Everything else looks good.

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

* Re: [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h
  2023-05-12  7:04   ` [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
@ 2023-05-16  0:17     ` Jonathan Tan
  2023-05-16  3:07       ` Elijah Newren
  0 siblings, 1 reply; 115+ messages in thread
From: Jonathan Tan @ 2023-05-16  0:17 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Jonathan Tan, git, Elijah Newren, Calvin Wan, Jeff King,
	Glen Choo

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
> 
> This creates a new fsmonitor-ll.h with most of the functions from
> fsmonitor.h, though it leaves three inline functions where they were.
> Two-thirds of the files that previously included fsmonitor.h did not
> need those three inline functions or the six extra includes those inline
> functions required, so this allows them to only include the lower level
> header.
> 
> Diff best viewed with `--color-moved`.
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>

Looks good. Thanks for this significant effort.
 

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

* Re: [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter
  2023-05-12 21:28     ` Jonathan Tan
@ 2023-05-16  2:57       ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-16  2:57 UTC (permalink / raw)
  To: Jonathan Tan
  Cc: Elijah Newren via GitGitGadget, git, Calvin Wan, Jeff King,
	Glen Choo

On Fri, May 12, 2023 at 2:28 PM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > From: Elijah Newren <newren@gmail.com>
> >
> > Much like the former commit, this commit was prompted by a desire to
>
> Could we have s/former/parent? I'm not used to "former" with this
> meaning (but if it's understood by others, then that's fine).

Sure, I'll make the switch.

> > diff --git a/builtin/clone.c b/builtin/clone.c
> > index 15f9912b4ca..cc34c194f5e 100644
> > --- a/builtin/clone.c
> > +++ b/builtin/clone.c
> > @@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
> >       int submodule_progress;
> >       int filter_submodules = 0;
> >       int hash_algo;
> > +     const int do_not_override_repo_unix_permissions = -1;
>
> I don't really like this name, but init_db() is undocumented so an
> anonymous -1 at the call site is not much better. For the purposes of
> this patch set (getting rid of cache.h), this should be fine for now.

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

* Re: [PATCH v2 17/27] cache.h: remove this no-longer-used header
  2023-05-16  0:02     ` Jonathan Tan
@ 2023-05-16  3:02       ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-16  3:02 UTC (permalink / raw)
  To: Jonathan Tan
  Cc: Elijah Newren via GitGitGadget, git, Calvin Wan, Jeff King,
	Glen Choo

On Mon, May 15, 2023 at 5:02 PM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > From: Elijah Newren <newren@gmail.com>
> >
> > Since this header showed up in some places besides just #include
> > statements, update/clean-up/remove those other places as well.
> >
> > Note that compat/fsmonitor/fsm-path-utils-darwin.c previously got
> > away with violating the rule that all files must start with an include
> > of git-compat-util.h (or a short-list of alternate headers that happen
> > to include it first).  This change exposed the violation and caused it
> > to stop building correctly; fix it by having it include
> > git-compat-util.h first, as per policy.
> >
> > Signed-off-by: Elijah Newren <newren@gmail.com>
>
> Ah, a monumental effort indeed (to finally remove cache.h). This patch
> was one of a few called out in the cover letter [1] as needing reviewer
> focus, but this patch seemed straightforward to me (changing the text
> wherever cache.h is mentioned in relatively obvious ways) so hopefully
> I'm not missing anything.

I mostly called it out simply because this patch was different than
all the other ones, due to the Makefile and Documentation changes.  I
figured that those who wanted to "spot check" deserved an easy way to
find the different kinds of changes involved.

Although, I was a bit curious after the patch what the purpose of the
SHA1DC_CUSTOM_INCLUDE_SHA1_C and SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C
defines were and why there were two different ones.  I tried to do a
little history spelunking to find out, but it didn't shed any light on
the issue for me.  Setting them both to git-compat-util.h works just
fine, so...*shrug*.

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

* Re: [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-16  0:16     ` Jonathan Tan
@ 2023-05-16  3:06       ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-16  3:06 UTC (permalink / raw)
  To: Jonathan Tan
  Cc: Elijah Newren via GitGitGadget, git, Calvin Wan, Jeff King,
	Glen Choo

On Mon, May 15, 2023 at 5:16 PM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > Move this function to hash-ll, so that khash.h can stop depending upon
> > hashmap.h.
>
> [snip]
>
> > Diff best viewed with `--color-moved`.  Note that there's a small but
> > important change to khash.h in this patch as well to allow this move,
> > which is easy to overlook.
>
> [snip]
>
> > diff --git a/khash.h b/khash.h
> > index a0a08dad8b7..ff881631778 100644
> > --- a/khash.h
> > +++ b/khash.h
> > @@ -26,7 +26,6 @@
> >  #ifndef __AC_KHASH_H
> >  #define __AC_KHASH_H
> >
> > -#include "hashmap.h"
> >  #include "hash.h"
>
> Is this the small but important change to khash.h? I thought that this
> is the reason for the change, not what "allow[ed]" this move.

No, the small but important change to khash.h was only in v1, and was
split out into a separate patch based on feedback.  I just forgot to
update this commit's message when I did so.  Sorry about that; I'll
fix it up.

>
> > diff --git a/object-name.c b/object-name.c
> > index 45f4d51305b..7e96c97051e 100644
> > --- a/object-name.c
> > +++ b/object-name.c
>
> [snip]
>
> > +struct raw_object_store {
> > +     /*
> > +      * Set of all object directories; the main directory is first (and
> > +      * cannot be NULL after initialization). Subsequent directories are
> > +      * alternates.
> > +      */
> > +     struct object_directory *odb;
> > +     struct object_directory **odb_tail;
> > +     struct kh_odb_path_map *odb_by_path;
>
> This is not present as a minus line (that line uses kh_odb_path_map_t).
> I thought this was so that we could forward declare "struct
> kh_odb_path_map", but I don't see such a forward declaration. (Was it
> declared elsewhere?)

I think this hunk probably should have been part of the khash.h patch
that was separated out, to make it more clear.  I'll fix that up.

> Everything else looks good.

Thanks, but I realized some point on Saturday that this patch was an
accidental squash of two patches -- one splitting object-store-ll.h
out of object-store.h (the majority of the patch), and the other about
the hash-ll/hashmap/khash changes.  I'll split it back out in my
re-roll.  There won't be any code changes, just splitting the patch
into its individual parts.

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

* Re: [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h
  2023-05-16  0:17     ` Jonathan Tan
@ 2023-05-16  3:07       ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-16  3:07 UTC (permalink / raw)
  To: Jonathan Tan
  Cc: Elijah Newren via GitGitGadget, git, Calvin Wan, Jeff King,
	Glen Choo

On Mon, May 15, 2023 at 5:17 PM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > From: Elijah Newren <newren@gmail.com>
> >
> > This creates a new fsmonitor-ll.h with most of the functions from
> > fsmonitor.h, though it leaves three inline functions where they were.
> > Two-thirds of the files that previously included fsmonitor.h did not
> > need those three inline functions or the six extra includes those inline
> > functions required, so this allows them to only include the lower level
> > header.
> >
> > Diff best viewed with `--color-moved`.
> >
> > Signed-off-by: Elijah Newren <newren@gmail.com>
>
> Looks good. Thanks for this significant effort.

Thanks for the review!

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

* Re: [PATCH v2 01/27] init-db: document existing bug with core.bare in template config
  2023-05-12 21:34     ` Jonathan Tan
@ 2023-05-16  3:08       ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-16  3:08 UTC (permalink / raw)
  To: Jonathan Tan
  Cc: Elijah Newren via GitGitGadget, git, Calvin Wan, Jeff King,
	Glen Choo

On Fri, May 12, 2023 at 2:34 PM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > -     is_bare_repository_cfg = init_is_bare_repository || !work_tree;
> >       if (init_shared_repository != -1)
> >               set_shared_repository(init_shared_repository);
> > +     /*
> > +      * TODO: heed core.bare from config file in templates if no
> > +      *       command-line override given
> > +      */
> > +     is_bare_repository_cfg = init_is_bare_repository || !work_tree;
>
> This patch moves this line down a few lines, but that's fine because
> set_shared_repository() doesn't modify any of the relevant variables.
>
> > +     /* TODO (continued):
> > +      *
> > +      * Unfortunately, the line above is equivalent to
> > +      *    is_bare_repository_cfg = !work_tree;
> > +      * which ignores the config entirely even if no `--[no-]bare`
> > +      * command line option was present.
> > +      *
> > +      * To see why, note that before this function, there was this call:
> > +      *    init_is_bare_repository = is_bare_repository()
>
> This is in init_db(), indeed.
>
> > +      * expanding the right hande side:
>
> s/hande/hand/

Thanks; will fix.

> > +      *                 = is_bare_repository_cfg && !get_git_work_tree()
> > +      *                 = is_bare_repository_cfg && !work_tree
> > +      * note that the last simplification above is valid because nothing
> > +      * calls repo_init() or set_git_work_tree() between any of the
> > +      * relevant calls in the code,
>
> Yes, the only calls are check_repository_format() and
> validate_hash_algorithm() (as can be seen in init_db()) before
> get_git_work_tree() is called at the start of create_default_files().
>
> > diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
> > index 1b6437ec079..c02fd64793b 100755
> > --- a/t/t1301-shared-repo.sh
> > +++ b/t/t1301-shared-repo.sh
> > @@ -52,6 +52,28 @@ test_expect_success 'shared=all' '
> >       test 2 = $(git config core.sharedrepository)
> >  '
> >
> > +test_expect_failure 'template can set core.bare' '
>
> I would have preferred a test_expect_success with the exact failing line
> documented and prepended with test_must_fail, but I can see why someone
> would prefer test_expect_failure.

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

* [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
                     ` (26 preceding siblings ...)
  2023-05-12  7:04   ` [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:33   ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 01/28] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
                       ` (28 more replies)
  27 siblings, 29 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren

== Summary ==

This series continues to focus on splitting declarations from cache.h to
separate headers, and also cleans up some other small header issues. By
patch 17, cache.h is gone.

== Changes ==

Since v2 (thanks to Jonathan Tan for feedback and suggestions!)

 * Wording fixes & improvements suggested by Jonathan
 * Pulled another line from the oidhash() patch (27) into the khash patch
   (25) to make it easier to review
 * Split the old patch 26 into two. Somehow my object-ll and hash-ll changes
   got smashed into the same patch (before v1), and I didn't notice until
   after v2 was sent out. Split them out two separate patches to make them
   easier to review.

Since v1 (thanks to Calvin, Glen, Junio, and Peff for feedback and
suggestions!)

 * Split the first patch into two, correct the explanation around existing
   bug, and tweak how global is removed
 * New patch 24 to rename ll-merge.[ch] to merge-ll.[ch]
 * Patch 25 split out of the old patch 23 to document the khash.h change in
   isolation

== Reviewer Focus (see also "Overview" section, below) ==

While the series may look long and big, it's really mostly just (a) moving
lots of code (so --color-moved is handy), and (b) adding (or removing)
includes repeatedly throughout the code. These are just more of the same
kinds of changes from the previous series.

However, there are a few exceptions that do not fit in these two categories,
which should be reviewed more closely:

 * Patches 1-3 & 6
 * Patch 17, the Documentation and Makefile changes
 * Patch 24 & 27

Patches 11 & 28 might also merit a little closer review.

== Maintainer notes from v1 ==

(1) This series is built on top of a merge of en/header-split-cache-h-part-2
into master, (2) This series has no conflicts with next, but has three
simple & small conflicts with seen:

 * a textual conflict with tl/notes-separator (affecting builtin/notes.c; to
   address, nuke the conflict region and add an include of alloc.h after
   builtin.h)
 * a textual & semantic conflict with cw/strbuf-cleanup (affecting strbuf.c;
   to address, delete the conflict region and also delete the include of
   repository.h)
 * a semantic conflict with rn/sparse-diff-index (affecting
   builtin/diff-index.c; to address, add an include of sparse-index.h).

== Impact; interesting stats ==

By way of impact, I created a small script which before this series reports:

Total include depth of .c files: 18340
Total include depth of .h files: 1385


After this series, I see:

Total include depth of .c files: 16155
Total include depth of .h files: 1206


The script computes the number of files transitively included by each file
(not perfect, e.g. only does textual search so if the include if ifdef'd,
it'll be counted anyway), and then sums the results. I think these numbers
represent one rough measure of overall complexity humans face in
understanding files in our project, and/or that compilers take to operate.
(For reference, the total include depths for v2.40.0 were 23114 and 2981;
we've come a long way in improving it, most of that through nuking cache.h.)

== Overview ==

An overview:

 * Patches 1-7: move shared code between various builtin/*.c files into
   alternate shared homes (setup.c, read-cache.c).
 * Patches 8-17: continue splitting declarations from cache.h into
   alternative headers associated with the actual implementation of those
   functions.
 * Patches 18-23: remove some unnecessary includes in other header files
 * Patch 24: rename ll-merge for consistency, and to get a better name
 * Patches 25-28: do some header shuffling with hashmap/khash/hash, and
   fsmonitor to reduce include depths

I would have just lumped patches 1-7 in with 8-17, but patches 1-3, & 6 did
some preliminary changes to allow the code movement.

== Acknowledgements ==

And thanks once again to Dscho for gitgitgadget. Getting multiple platform
testing + all the special tests (sparse, cocci, hdr-check, etc.) really
helps clean out all the issues that would otherwise hit a series like this.

Elijah Newren (28):
  init-db: document existing bug with core.bare in template config
  init-db: remove unnecessary global variable
  init-db, clone: change unnecessary global into passed parameter
  setup: adopt shared init-db & clone code
  read-cache: move shared commit and ls-files code
  add: modify add_files_to_cache() to avoid globals
  read-cache: move shared add/checkout/commit code
  statinfo: move stat_{data,validity} functions from cache/read-cache
  run-command.h: move declarations for run-command.c from cache.h
  name-hash.h: move declarations for name-hash.c from cache.h
  sparse-index.h: move declarations for sparse-index.c from cache.h
  preload-index.h: move declarations for preload-index.c from elsewhere
  diff.h: move declaration for global in diff.c from cache.h
  merge.h: move declarations for merge.c from cache.h
  repository.h: move declaration of the_index from cache.h
  read-cache*.h: move declarations for read-cache.c functions from
    cache.h
  cache.h: remove this no-longer-used header
  log-tree: replace include of revision.h with simple forward
    declaration
  repository: remove unnecessary include of path.h
  diff.h: remove unnecessary include of oidset.h
  list-objects-filter-options.h: remove unneccessary include
  builtin.h: remove unneccessary includes
  git-compat-util.h: remove unneccessary include of wildmatch.h
  merge-ll: rename from ll-merge
  khash: name the structs that khash declares
  object-store-ll.h: split this header out of object-store.h
  hash-ll, hashmap: move oidhash() to hash-ll
  fsmonitor-ll.h: split this header out of fsmonitor.h

 Documentation/CodingGuidelines           |   2 +-
 Documentation/MyFirstObjectWalk.txt      |   2 +-
 Documentation/technical/api-merge.txt    |   4 +-
 Documentation/user-manual.txt            |  18 +-
 Makefile                                 |   5 +-
 add-interactive.c                        |   6 +-
 add-patch.c                              |   4 +-
 apply.c                                  |  10 +-
 archive-tar.c                            |   2 +-
 archive-zip.c                            |   2 +-
 archive.c                                |   3 +-
 attr.c                                   |   6 +-
 bisect.c                                 |   3 +-
 blame.c                                  |   6 +-
 blame.h                                  |   1 +
 branch.c                                 |   1 +
 builtin.h                                |   3 -
 builtin/add.c                            | 105 +----
 builtin/am.c                             |   5 +-
 builtin/apply.c                          |   1 -
 builtin/archive.c                        |   1 -
 builtin/bisect.c                         |   2 +-
 builtin/blame.c                          |   2 +-
 builtin/branch.c                         |   4 +-
 builtin/bundle.c                         |   1 -
 builtin/cat-file.c                       |   5 +-
 builtin/check-attr.c                     |   1 -
 builtin/check-ignore.c                   |   1 -
 builtin/check-mailmap.c                  |   1 +
 builtin/check-ref-format.c               |   3 +-
 builtin/checkout--worker.c               |   1 +
 builtin/checkout-index.c                 |   2 +
 builtin/checkout.c                       |   9 +-
 builtin/clean.c                          |   3 +-
 builtin/clone.c                          |   6 +-
 builtin/column.c                         |   1 -
 builtin/commit-graph.c                   |   3 +-
 builtin/commit-tree.c                    |   5 +-
 builtin/commit.c                         |  10 +-
 builtin/config.c                         |   1 +
 builtin/count-objects.c                  |   6 +-
 builtin/credential-cache.c               |   1 +
 builtin/describe.c                       |   7 +-
 builtin/diff-files.c                     |   5 +-
 builtin/diff-index.c                     |   5 +-
 builtin/diff-tree.c                      |   5 +-
 builtin/diff.c                           |   5 +-
 builtin/difftool.c                       |   7 +-
 builtin/fast-export.c                    |   3 +-
 builtin/fast-import.c                    |   4 +-
 builtin/fetch.c                          |   6 +-
 builtin/for-each-ref.c                   |   2 +-
 builtin/for-each-repo.c                  |   3 +-
 builtin/fsck.c                           |   6 +-
 builtin/fsmonitor--daemon.c              |   4 +-
 builtin/gc.c                             |   3 +-
 builtin/get-tar-commit-id.c              |   3 +-
 builtin/grep.c                           |   7 +-
 builtin/hash-object.c                    |   3 +-
 builtin/help.c                           |   3 +-
 builtin/hook.c                           |   1 -
 builtin/index-pack.c                     |   3 +-
 builtin/init-db.c                        | 474 +-------------------
 builtin/interpret-trailers.c             |   1 -
 builtin/log.c                            |   2 +-
 builtin/ls-files.c                       | 143 +-----
 builtin/ls-remote.c                      |   2 +-
 builtin/ls-tree.c                        |   6 +-
 builtin/mailinfo.c                       |   3 +-
 builtin/mailsplit.c                      |   1 -
 builtin/merge-base.c                     |   1 -
 builtin/merge-file.c                     |   1 -
 builtin/merge-index.c                    |   2 +
 builtin/merge-ours.c                     |   1 +
 builtin/merge-recursive.c                |   1 -
 builtin/merge-tree.c                     |   2 +-
 builtin/merge.c                          |   5 +-
 builtin/mktag.c                          |   3 +-
 builtin/mktree.c                         |   3 +-
 builtin/multi-pack-index.c               |   4 +-
 builtin/mv.c                             |   2 +
 builtin/name-rev.c                       |   1 +
 builtin/notes.c                          |   6 +-
 builtin/pack-objects.c                   |   2 +-
 builtin/pack-redundant.c                 |   2 +-
 builtin/patch-id.c                       |   2 +-
 builtin/prune.c                          |   7 +-
 builtin/pull.c                           |   6 +-
 builtin/push.c                           |   3 +-
 builtin/range-diff.c                     |   2 +-
 builtin/read-tree.c                      |   4 +-
 builtin/rebase.c                         |   1 +
 builtin/receive-pack.c                   |   3 +-
 builtin/reflog.c                         |   2 +
 builtin/remote.c                         |   3 +-
 builtin/repack.c                         |   3 +-
 builtin/replace.c                        |   7 +-
 builtin/rerere.c                         |   1 -
 builtin/reset.c                          |   3 +
 builtin/rev-list.c                       |   5 +-
 builtin/rev-parse.c                      |   6 +-
 builtin/revert.c                         |   1 +
 builtin/rm.c                             |   2 +
 builtin/shortlog.c                       |   2 +-
 builtin/show-branch.c                    |   4 +-
 builtin/show-index.c                     |   1 -
 builtin/show-ref.c                       |   3 +-
 builtin/sparse-checkout.c                |   1 -
 builtin/stash.c                          |   4 +
 builtin/stripspace.c                     |   1 -
 builtin/submodule--helper.c              |   7 +-
 builtin/symbolic-ref.c                   |   1 -
 builtin/tag.c                            |   6 +-
 builtin/unpack-file.c                    |   2 +-
 builtin/unpack-objects.c                 |   3 +-
 builtin/update-index.c                   |   5 +-
 builtin/update-ref.c                     |   3 +-
 builtin/update-server-info.c             |   3 +-
 builtin/upload-archive.c                 |   2 +-
 builtin/upload-pack.c                    |   2 +-
 builtin/verify-commit.c                  |   5 +-
 builtin/verify-pack.c                    |   2 +-
 builtin/verify-tag.c                     |   3 +-
 builtin/worktree.c                       |   5 +-
 builtin/write-tree.c                     |   1 -
 bulk-checkin.c                           |   2 +-
 bundle-uri.c                             |   2 +-
 bundle.c                                 |   2 +-
 cache-tree.c                             |   5 +-
 combine-diff.c                           |   2 +-
 commit-graph.c                           |   3 +-
 commit-graph.h                           |   2 +-
 commit.c                                 |   2 +-
 compat/fsmonitor/fsm-health-darwin.c     |   2 +-
 compat/fsmonitor/fsm-health-win32.c      |   4 +-
 compat/fsmonitor/fsm-ipc-darwin.c        |   3 +-
 compat/fsmonitor/fsm-listen-darwin.c     |   3 +-
 compat/fsmonitor/fsm-listen-win32.c      |   4 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |   4 +-
 compat/fsmonitor/fsm-path-utils-win32.c  |   5 +-
 compat/fsmonitor/fsm-settings-darwin.c   |   2 +-
 compat/fsmonitor/fsm-settings-win32.c    |   4 +-
 compat/mingw.c                           |   1 -
 compat/precompose_utf8.c                 |   3 +-
 compat/sha1-chunked.c                    |   3 +-
 compat/simple-ipc/ipc-win32.c            |   2 +-
 compat/win32/trace2_win32_process_info.c |   2 +-
 config.c                                 |   5 +-
 connect.c                                |   1 +
 connected.c                              |   2 +-
 convert.c                                |   7 +-
 decorate.c                               |   1 -
 diagnose.c                               |   2 +-
 diff-lib.c                               |   5 +-
 diff.c                                   |   7 +-
 diff.h                                   |   6 +-
 diffcore-break.c                         |   4 +-
 diffcore-order.c                         |   1 +
 diffcore-pickaxe.c                       |   1 +
 diffcore-rename.c                        |   2 +-
 dir.c                                    |   8 +-
 dir.h                                    |   1 +
 entry.c                                  |   6 +-
 environment.c                            |   5 +-
 environment.h                            |   3 +-
 exec-cmd.c                               |   3 +-
 fetch-pack.c                             |   3 +-
 fmt-merge-msg.c                          |   3 +-
 fsck.c                                   |   4 +-
 fsmonitor-ipc.c                          |   4 +-
 fsmonitor-ll.h                           |  52 +++
 fsmonitor.c                              |   2 +-
 fsmonitor.h                              |  49 +--
 git-compat-util.h                        |   2 -
 git.c                                    |   1 +
 grep.c                                   |   2 +-
 hash-ll.h                                |  19 +
 hash-lookup.c                            |   3 +-
 hashmap.h                                |  21 -
 http-backend.c                           |   3 +-
 http-push.c                              |   2 +-
 http-walker.c                            |   2 +-
 http.c                                   |   2 +-
 khash.h                                  |   3 +-
 line-log.c                               |   1 +
 list-objects-filter-options.h            |   1 -
 list-objects-filter.c                    |   2 +-
 list-objects.c                           |   2 +-
 log-tree.c                               |   4 +-
 log-tree.h                               |   2 +-
 mailmap.c                                |   2 +-
 match-trees.c                            |   3 +-
 merge-blobs.c                            |   4 +-
 ll-merge.c => merge-ll.c                 |   2 +-
 ll-merge.h => merge-ll.h                 |   0
 merge-ort-wrappers.c                     |   3 +-
 merge-ort.c                              |   9 +-
 merge-recursive.c                        |   9 +-
 merge.c                                  |   5 +-
 merge.h                                  |  17 +
 midx.c                                   |   2 +-
 name-hash.c                              |   5 +-
 name-hash.h                              |  16 +
 notes-cache.c                            |   3 +-
 notes-merge.c                            |   5 +-
 notes.c                                  |   2 +-
 object-file.c                            |   1 +
 object-name.c                            |   5 +-
 object-store-ll.h                        | 533 +++++++++++++++++++++++
 object-store.h                           | 528 +---------------------
 object.c                                 |   3 +-
 oidmap.h                                 |   1 +
 oss-fuzz/fuzz-pack-idx.c                 |   2 +-
 pack-bitmap-write.c                      |   3 +-
 pack-bitmap.c                            |   2 +-
 pack-check.c                             |   2 +-
 pack-mtimes.c                            |   3 +-
 pack-objects.h                           |   2 +-
 pack-revindex.c                          |   3 +-
 pack-write.c                             |   2 +
 packfile.c                               |   2 +-
 parallel-checkout.c                      |   3 +-
 patch-ids.c                              |   1 +
 path.c                                   |   2 +-
 pathspec.c                               |   4 +-
 preload-index.c                          |   4 +-
 preload-index.h                          |  15 +
 pretty.c                                 |   1 +
 promisor-remote.c                        |   2 +-
 protocol-caps.c                          |   2 +-
 prune-packed.c                           |   2 +-
 range-diff.c                             |   1 +
 reachable.c                              |   2 +-
 cache.h => read-cache-ll.h               | 148 +------
 read-cache.c                             | 331 ++++++++++----
 read-cache.h                             |  45 ++
 ref-filter.c                             |   2 +-
 reflog-walk.c                            |   1 +
 reflog.c                                 |   2 +-
 refs.c                                   |   4 +-
 refs/files-backend.c                     |   3 +-
 refs/packed-backend.c                    |   3 +-
 remote.c                                 |   3 +-
 remote.h                                 |   1 +
 replace-object.c                         |   2 +-
 replace-object.h                         |   2 +-
 repository.c                             |   6 +-
 repository.h                             |   8 +-
 rerere.c                                 |   8 +-
 resolve-undo.c                           |   4 +-
 revision.c                               |   7 +-
 run-command.c                            |   2 +-
 run-command.h                            |   4 +-
 send-pack.c                              |   2 +-
 sequencer.c                              |   7 +-
 serve.c                                  |   1 +
 server-info.c                            |   3 +-
 setup.c                                  | 497 +++++++++++++++++++++
 setup.h                                  |   9 +
 shallow.c                                |   6 +-
 sparse-index.c                           |   6 +-
 sparse-index.h                           |   2 +
 split-index.c                            |   3 +-
 statinfo.c                               |  87 ++++
 statinfo.h                               |  51 +++
 strbuf.c                                 |   1 +
 strbuf.h                                 |   4 -
 streaming.c                              |   2 +-
 submodule-config.c                       |   3 +-
 submodule.c                              |   6 +-
 t/helper/test-cache-tree.c               |   2 +-
 t/helper/test-dump-cache-tree.c          |   2 +-
 t/helper/test-dump-fsmonitor.c           |   2 +-
 t/helper/test-dump-split-index.c         |   3 +-
 t/helper/test-dump-untracked-cache.c     |   2 +-
 t/helper/test-fast-rebase.c              |   3 +-
 t/helper/test-fsmonitor-client.c         |   2 +-
 t/helper/test-hash-speed.c               |   2 +-
 t/helper/test-index-version.c            |   2 +-
 t/helper/test-lazy-init-name-hash.c      |   3 +-
 t/helper/test-pack-mtimes.c              |   2 +-
 t/helper/test-partial-clone.c            |   2 +-
 t/helper/test-path-utils.c               |   2 +-
 t/helper/test-read-cache.c               |   2 +-
 t/helper/test-read-graph.c               |   2 +-
 t/helper/test-read-midx.c                |   2 +-
 t/helper/test-ref-store.c                |   4 +-
 t/helper/test-repository.c               |   2 +-
 t/helper/test-revision-walking.c         |   1 +
 t/helper/test-scrap-cache-tree.c         |   2 +-
 t/helper/test-sha1.c                     |   2 +-
 t/helper/test-sha256.c                   |   2 +-
 t/helper/test-strcmp-offset.c            |   2 +-
 t/helper/test-wildmatch.c                |   1 +
 t/helper/test-write-cache.c              |   2 +-
 t/t1301-shared-repo.sh                   |  22 +
 t/t5606-clone-options.sh                 |  10 +
 tag.c                                    |   2 +-
 tmp-objdir.c                             |   3 +-
 trace2/tr2_cfg.c                         |   1 +
 transport-helper.c                       |   1 +
 transport.c                              |   2 +-
 tree-diff.c                              |   1 +
 tree-walk.c                              |   2 +-
 tree.c                                   |   2 +-
 unpack-trees.c                           |   6 +-
 unpack-trees.h                           |   2 +-
 upload-pack.c                            |   2 +-
 walker.c                                 |   3 +-
 worktree.c                               |   1 +
 wt-status.c                              |   5 +-
 xdiff-interface.c                        |   3 +-
 312 files changed, 2179 insertions(+), 1895 deletions(-)
 create mode 100644 fsmonitor-ll.h
 rename ll-merge.c => merge-ll.c (99%)
 rename ll-merge.h => merge-ll.h (100%)
 create mode 100644 merge.h
 create mode 100644 name-hash.h
 create mode 100644 object-store-ll.h
 create mode 100644 preload-index.h
 rename cache.h => read-cache-ll.h (79%)
 create mode 100644 read-cache.h
 create mode 100644 statinfo.c


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

Range-diff vs v2:

  1:  f7ee69e7e68 !  1:  5b39c530f2a init-db: document existing bug with core.bare in template config
     @@ builtin/init-db.c: static int create_default_files(const char *template_path,
      +	 *
      +	 * To see why, note that before this function, there was this call:
      +	 *    init_is_bare_repository = is_bare_repository()
     -+	 * expanding the right hande side:
     ++	 * expanding the right hand side:
      +	 *                 = is_bare_repository_cfg && !get_git_work_tree()
      +	 *                 = is_bare_repository_cfg && !work_tree
      +	 * note that the last simplification above is valid because nothing
  2:  5ba9d6e68ad !  2:  93067838fb2 init-db: remove unnecessary global variable
     @@ builtin/init-db.c: static int create_default_files(const char *template_path,
       	 * To see why, note that before this function, there was this call:
      -	 *    init_is_bare_repository = is_bare_repository()
      +	 *    prev_bare_repository = is_bare_repository()
     - 	 * expanding the right hande side:
     + 	 * expanding the right hand side:
       	 *                 = is_bare_repository_cfg && !get_git_work_tree()
       	 *                 = is_bare_repository_cfg && !work_tree
      @@ builtin/init-db.c: static int create_default_files(const char *template_path,
  3:  3bc4dfeea90 !  3:  28c8f4a29a8 init-db, clone: change unnecessary global into passed parameter
     @@ Metadata
       ## Commit message ##
          init-db, clone: change unnecessary global into passed parameter
      
     -    Much like the former commit, this commit was prompted by a desire to
     +    Much like the parent commit, this commit was prompted by a desire to
          move the functions which builtin/init-db.c and builtin/clone.c share out
          of the former file and into setup.c.  A secondary issue that made it
          difficult was the init_shared_repository global variable; replace it
  4:  60d01387f41 !  4:  fc1272c981e setup: adopt shared init-db & clone code
     @@ builtin/init-db.c
      -	 *
      -	 * To see why, note that before this function, there was this call:
      -	 *    prev_bare_repository = is_bare_repository()
     --	 * expanding the right hande side:
     +-	 * expanding the right hand side:
      -	 *                 = is_bare_repository_cfg && !get_git_work_tree()
      -	 *                 = is_bare_repository_cfg && !work_tree
      -	 * note that the last simplification above is valid because nothing
     @@ setup.c: int daemonize(void)
      +	 *
      +	 * To see why, note that before this function, there was this call:
      +	 *    prev_bare_repository = is_bare_repository()
     -+	 * expanding the right hande side:
     ++	 * expanding the right hand side:
      +	 *                 = is_bare_repository_cfg && !get_git_work_tree()
      +	 *                 = is_bare_repository_cfg && !work_tree
      +	 * note that the last simplification above is valid because nothing
  5:  ced75f46444 =  5:  1979b5dbfd7 read-cache: move shared commit and ls-files code
  6:  13d6dd1095c =  6:  8f7d82ce1c8 add: modify add_files_to_cache() to avoid globals
  7:  63058d44595 =  7:  f95d5aebd4a read-cache: move shared add/checkout/commit code
  8:  39e5f6ca470 =  8:  fc6286718d4 statinfo: move stat_{data,validity} functions from cache/read-cache
  9:  f56714080b1 =  9:  706e02727fc run-command.h: move declarations for run-command.c from cache.h
 10:  7d48dbfe0aa = 10:  d8b396bd633 name-hash.h: move declarations for name-hash.c from cache.h
 11:  f46aa5e73a1 = 11:  18cdefc5667 sparse-index.h: move declarations for sparse-index.c from cache.h
 12:  b16c4d3429e = 12:  19226c30cdf preload-index.h: move declarations for preload-index.c from elsewhere
 13:  c8f873d71f5 = 13:  2be96fbbe56 diff.h: move declaration for global in diff.c from cache.h
 14:  77c3c5918b8 = 14:  8a940282299 merge.h: move declarations for merge.c from cache.h
 15:  abfb127b812 = 15:  c8d8032c75c repository.h: move declaration of the_index from cache.h
 16:  41183b7baed = 16:  117706f63d2 read-cache*.h: move declarations for read-cache.c functions from cache.h
 17:  8f021be54e0 = 17:  a9ceb3a122a cache.h: remove this no-longer-used header
 18:  ea21839a95a = 18:  beb4287dd65 log-tree: replace include of revision.h with simple forward declaration
 19:  bd70d3fe730 = 19:  3e8ae022927 repository: remove unnecessary include of path.h
 20:  a438cfbb095 = 20:  127f4fca309 diff.h: remove unnecessary include of oidset.h
 21:  b8f302184fa = 21:  b9231a414f2 list-objects-filter-options.h: remove unneccessary include
 22:  1d3d33a843b = 22:  452254dbce0 builtin.h: remove unneccessary includes
 23:  7849fea5fa4 = 23:  fe631d90b4f git-compat-util.h: remove unneccessary include of wildmatch.h
 24:  97d04efde7b = 24:  35703377580 merge-ll: rename from ll-merge
 25:  e0bfeb98556 ! 25:  6de1eebfea6 khash: name the structs that khash declares
     @@ khash.h: static inline khint_t __ac_X31_hash_string(const char *s)
       		khint_t n_buckets, size, n_occupied, upper_bound; \
       		khint32_t *flags; \
       		khkey_t *keys; \
     +
     + ## object-store.h ##
     +@@ object-store.h: struct raw_object_store {
     + 	 */
     + 	struct object_directory *odb;
     + 	struct object_directory **odb_tail;
     +-	kh_odb_path_map_t *odb_by_path;
     ++	struct kh_odb_path_map *odb_by_path;
     + 
     + 	int loaded_alternates;
     + 
 26:  41d48379b3d ! 26:  264d64011bd hash-ll, hashmap: move oidhash() to hash-ll
     @@ Metadata
      Author: Elijah Newren <newren@gmail.com>
      
       ## Commit message ##
     -    hash-ll, hashmap: move oidhash() to hash-ll
     +    object-store-ll.h: split this header out of object-store.h
      
     -    oidhash() was used by both hashmap and khash, which makes sense.
     -    However, the location of this function in hashmap.[ch] meant that
     -    khash.h had to depend upon hashmap.h, making people unfamiliar with
     -    khash think that it was built upon hashmap.  (Or at least, I personally
     -    was confused for a while about this in the past.)
     +    The vast majority of files including object-store.h did not need dir.h
     +    nor khash.h.  Split the header into two files, and let most just depend
     +    upon object-store-ll.h, while letting the two callers that need it
     +    depend on the full object-store.h.
      
     -    Move this function to hash-ll, so that khash.h can stop depending upon
     -    hashmap.h.
     +    After this patch:
     +        $ git grep -h include..object-store | sort | uniq -c
     +              2 #include "object-store.h"
     +            129 #include "object-store-ll.h"
      
     -    This has another benefit as well: it allows us to remove hashmap.h's
     -    dependency on hash-ll.h.  While some callers of hashmap.h were making
     -    use of oidhash, most were not, so this change provides another way to
     -    reduce the number of includes.
     -
     -    Diff best viewed with `--color-moved`.  Note that there's a small but
     -    important change to khash.h in this patch as well to allow this move,
     -    which is easy to overlook.
     +    Diff best viewed with `--color-moved`.
      
          Signed-off-by: Elijah Newren <newren@gmail.com>
      
     @@ convert.c
       #include "run-command.h"
       #include "quote.h"
      
     - ## decorate.c ##
     -@@
     -  * data.
     -  */
     - #include "git-compat-util.h"
     --#include "hashmap.h"
     - #include "object.h"
     - #include "decorate.h"
     - 
     -
       ## diagnose.c ##
      @@
       #include "gettext.h"
     @@ dir.c
       #include "attr.h"
       #include "refs.h"
      
     - ## dir.h ##
     -@@
     - #ifndef DIR_H
     - #define DIR_H
     - 
     -+#include "hash-ll.h"
     - #include "hashmap.h"
     - #include "pathspec.h"
     - #include "statinfo.h"
     -
       ## entry.c ##
      @@
       #include "git-compat-util.h"
     @@ grep.c
       #include "userdiff.h"
       #include "xdiff-interface.h"
      
     - ## hash-ll.h ##
     -@@ hash-ll.h: static inline void oid_set_algo(struct object_id *oid, const struct git_hash_alg
     - 	oid->algo = hash_algo_by_ptr(algop);
     - }
     - 
     -+/*
     -+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
     -+ * for use in hash tables. Cryptographic hashes are supposed to have
     -+ * uniform distribution, so in contrast to `memhash()`, this just copies
     -+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
     -+ * the results will be different on big-endian and little-endian
     -+ * platforms, so they should not be stored or transferred over the net.
     -+ */
     -+static inline unsigned int oidhash(const struct object_id *oid)
     -+{
     -+	/*
     -+	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
     -+	 * platforms that don't support unaligned reads.
     -+	 */
     -+	unsigned int hash;
     -+	memcpy(&hash, oid->hash, sizeof(hash));
     -+	return hash;
     -+}
     -+
     - const char *empty_tree_oid_hex(void);
     - const char *empty_blob_oid_hex(void);
     - 
     -
     - ## hashmap.h ##
     -@@
     - #ifndef HASHMAP_H
     - #define HASHMAP_H
     - 
     --#include "hash-ll.h"
     --
     - /*
     -  * Generic implementation of hash-based key-value mappings.
     -  *
     -@@ hashmap.h: unsigned int memhash(const void *buf, size_t len);
     - unsigned int memihash(const void *buf, size_t len);
     - unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
     - 
     --/*
     -- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
     -- * for use in hash tables. Cryptographic hashes are supposed to have
     -- * uniform distribution, so in contrast to `memhash()`, this just copies
     -- * the first `sizeof(int)` bytes without shuffling any bits. Note that
     -- * the results will be different on big-endian and little-endian
     -- * platforms, so they should not be stored or transferred over the net.
     -- */
     --static inline unsigned int oidhash(const struct object_id *oid)
     --{
     --	/*
     --	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
     --	 * platforms that don't support unaligned reads.
     --	 */
     --	unsigned int hash;
     --	memcpy(&hash, oid->hash, sizeof(hash));
     --	return hash;
     --}
     --
     - /*
     -  * struct hashmap_entry is an opaque structure representing an entry in the
     -  * hash table.
     -
       ## http-backend.c ##
      @@
       #include "url.h"
     @@ http.c
       static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
       static int trace_curl_data = 1;
      
     - ## khash.h ##
     -@@
     - #ifndef __AC_KHASH_H
     - #define __AC_KHASH_H
     - 
     --#include "hashmap.h"
     - #include "hash.h"
     - 
     - #define AC_VERSION_KHASH_H "0.2.8"
     -
       ## list-objects-filter.c ##
      @@
       #include "oidmap.h"
     @@ object-store.h
      -	 */
      -	struct object_directory *odb;
      -	struct object_directory **odb_tail;
     --	kh_odb_path_map_t *odb_by_path;
     +-	struct kh_odb_path_map *odb_by_path;
      -
      -	int loaded_alternates;
      -
     @@ remote.c
       #include "commit.h"
       #include "diff.h"
      
     - ## remote.h ##
     -@@
     - #ifndef REMOTE_H
     - #define REMOTE_H
     - 
     -+#include "hash-ll.h"
     - #include "hashmap.h"
     - #include "refspec.h"
     - 
     -
       ## replace-object.c ##
      @@
       #include "gettext.h"
     @@ sequencer.c
       #include "pager.h"
       #include "commit.h"
      
     - ## serve.c ##
     -@@
     - #include "git-compat-util.h"
     - #include "repository.h"
     - #include "config.h"
     -+#include "hash-ll.h"
     - #include "pkt-line.h"
     - #include "version.h"
     - #include "ls-refs.h"
     -
       ## server-info.c ##
      @@
       #include "packfile.h"
  -:  ----------- > 27:  d6057718fde hash-ll, hashmap: move oidhash() to hash-ll
 27:  bbe64fccd52 = 28:  7b853c9e440 fsmonitor-ll.h: split this header out of fsmonitor.h

-- 
gitgitgadget

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

* [PATCH v3 01/28] init-db: document existing bug with core.bare in template config
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 02/28] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
                       ` (27 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The comments in create_default_files() talks about reading config from
the config file in the specified `--templates` directory, which leads to
the question of whether core.bare could be set in such a config file and
thus whether the code is doing the right thing.  It turns out, that it
doesn't; it unconditionally ignores core.bare in the config file in any
--templates directory.  It is not clear to me that fixing it can be done
within this function; it seems to occur too late:
  * create_default_files() is called by init_db()
  * init_db() is called by both builtin/{clone.c,init-db.c}
  * both callers of init_db() call set_git_work_tree() before init_db()
and in order to actual affect whether a repository is bear, we'd need to
somewhere reset these values, not just the is_bare_repository_cfg
setting.

I do not want to open this can of worms at this time; I'm trying to
clean up some headers, for which I need to move some functions, for
which I need to clean up some globals, and that's far enough down the
rabbit hole.  So, simply document the issue with a careful TODO comment
and a few testcases.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c        | 29 ++++++++++++++++++++++++++++-
 t/t1301-shared-repo.sh   | 22 ++++++++++++++++++++++
 t/t5606-clone-options.sh | 10 ++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index aef40361052..87a7021c3ca 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -231,9 +231,36 @@ static int create_default_files(const char *template_path,
 	 * We must make sure command-line options continue to override any
 	 * values we might have just re-read from the config.
 	 */
-	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
 	if (init_shared_repository != -1)
 		set_shared_repository(init_shared_repository);
+	/*
+	 * TODO: heed core.bare from config file in templates if no
+	 *       command-line override given
+	 */
+	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
+	/* TODO (continued):
+	 *
+	 * Unfortunately, the line above is equivalent to
+	 *    is_bare_repository_cfg = !work_tree;
+	 * which ignores the config entirely even if no `--[no-]bare`
+	 * command line option was present.
+	 *
+	 * To see why, note that before this function, there was this call:
+	 *    init_is_bare_repository = is_bare_repository()
+	 * expanding the right hand side:
+	 *                 = is_bare_repository_cfg && !get_git_work_tree()
+	 *                 = is_bare_repository_cfg && !work_tree
+	 * note that the last simplification above is valid because nothing
+	 * calls repo_init() or set_git_work_tree() between any of the
+	 * relevant calls in the code, and thus the !get_git_work_tree()
+	 * calls will return the same result each time.  So, what we are
+	 * interested in computing is the right hand side of the line of
+	 * code just above this comment:
+	 *     init_is_bare_repository || !work_tree
+	 *        = is_bare_repository_cfg && !work_tree || !work_tree
+	 *        = !work_tree
+	 * because "A && !B || !B == !B" for all boolean values of A & B.
+	 */
 
 	/*
 	 * We would have created the above under user's umask -- under
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index 1b6437ec079..c02fd64793b 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -52,6 +52,28 @@ test_expect_success 'shared=all' '
 	test 2 = $(git config core.sharedrepository)
 '
 
+test_expect_failure 'template can set core.bare' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "rm -rf templates" &&
+	test_config core.bare true &&
+	umask 0022 &&
+	mkdir -p templates/ &&
+	cp .git/config templates/config &&
+	git init --template=templates subdir &&
+	test_path_exists subdir/HEAD
+'
+
+test_expect_success 'template can set core.bare but overridden by command line' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "rm -rf templates" &&
+	test_config core.bare true &&
+	umask 0022 &&
+	mkdir -p templates/ &&
+	cp .git/config templates/config &&
+	git init --no-bare --template=templates subdir &&
+	test_path_exists subdir/.git/HEAD
+'
+
 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
 	: > a1 &&
 	git add a1 &&
diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh
index 27f9f776389..5890319b97b 100755
--- a/t/t5606-clone-options.sh
+++ b/t/t5606-clone-options.sh
@@ -120,6 +120,16 @@ test_expect_success 'prefers -c config over --template config' '
 
 '
 
+test_expect_failure 'prefers --template config even for core.bare' '
+
+	template="$TRASH_DIRECTORY/template-with-bare-config" &&
+	mkdir "$template" &&
+	git config --file "$template/config" core.bare true &&
+	git clone "--template=$template" parent clone-bare-config &&
+	test "$(git -C clone-bare-config config --local core.bare)" = "true" &&
+	test_path_is_file clone-bare-config/HEAD
+'
+
 test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
 
 	test_config_global clone.defaultRemoteName from_config &&
-- 
gitgitgadget


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

* [PATCH v3 02/28] init-db: remove unnecessary global variable
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 01/28] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 03/28] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
                       ` (26 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This commit was prompted by a desire to move the functions which
builtin/init-db.c and builtin/clone.c share out of the former file and
into setup.c.  One issue that made it difficult was the
init_is_bare_repository global variable.

init_is_bare_repository's sole use in life it to cache a value in
init_db(), and then be used in create_default_files().  This is a bit
odd since init_db() directly calls create_default_files(), and is the
only caller of that function.  Convert the global to a simple function
parameter instead.

(Of course, this doesn't fix the fact that this value is then ignored by
create_default_files(), as noted in a big TODO comment in that function,
but it at least includes no behavioral change other than getting rid of
a very questionable global variable.)

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 87a7021c3ca..32ab0a13e09 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,7 +31,6 @@
 
 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
 
-static int init_is_bare_repository = 0;
 static int init_shared_repository = -1;
 
 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
@@ -199,6 +198,7 @@ static int create_default_files(const char *template_path,
 				const char *original_git_dir,
 				const char *initial_branch,
 				const struct repository_format *fmt,
+				int prev_bare_repository,
 				int quiet)
 {
 	struct stat st1;
@@ -237,7 +237,7 @@ static int create_default_files(const char *template_path,
 	 * TODO: heed core.bare from config file in templates if no
 	 *       command-line override given
 	 */
-	is_bare_repository_cfg = init_is_bare_repository || !work_tree;
+	is_bare_repository_cfg = prev_bare_repository || !work_tree;
 	/* TODO (continued):
 	 *
 	 * Unfortunately, the line above is equivalent to
@@ -246,7 +246,7 @@ static int create_default_files(const char *template_path,
 	 * command line option was present.
 	 *
 	 * To see why, note that before this function, there was this call:
-	 *    init_is_bare_repository = is_bare_repository()
+	 *    prev_bare_repository = is_bare_repository()
 	 * expanding the right hand side:
 	 *                 = is_bare_repository_cfg && !get_git_work_tree()
 	 *                 = is_bare_repository_cfg && !work_tree
@@ -256,7 +256,7 @@ static int create_default_files(const char *template_path,
 	 * calls will return the same result each time.  So, what we are
 	 * interested in computing is the right hand side of the line of
 	 * code just above this comment:
-	 *     init_is_bare_repository || !work_tree
+	 *     prev_bare_repository || !work_tree
 	 *        = is_bare_repository_cfg && !work_tree || !work_tree
 	 *        = !work_tree
 	 * because "A && !B || !B == !B" for all boolean values of A & B.
@@ -424,6 +424,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	int exist_ok = flags & INIT_DB_EXIST_OK;
 	char *original_git_dir = real_pathdup(git_dir, 1);
 	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+	int prev_bare_repository;
 
 	if (real_git_dir) {
 		struct stat st;
@@ -449,7 +450,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
 	safe_create_dir(git_dir, 0);
 
-	init_is_bare_repository = is_bare_repository();
+	prev_bare_repository = is_bare_repository();
 
 	/* Check to see if the repository version is right.
 	 * Note that a newly created repository does not have
@@ -462,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 
 	reinit = create_default_files(template_dir, original_git_dir,
 				      initial_branch, &repo_fmt,
+				      prev_bare_repository,
 				      flags & INIT_DB_QUIET);
 	if (reinit && initial_branch)
 		warning(_("re-init: ignored --initial-branch=%s"),
-- 
gitgitgadget


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

* [PATCH v3 03/28] init-db, clone: change unnecessary global into passed parameter
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 01/28] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 02/28] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 04/28] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
                       ` (25 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Much like the parent commit, this commit was prompted by a desire to
move the functions which builtin/init-db.c and builtin/clone.c share out
of the former file and into setup.c.  A secondary issue that made it
difficult was the init_shared_repository global variable; replace it
with a simple parameter that is passed to the relevant functions.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/clone.c   | 3 ++-
 builtin/init-db.c | 9 +++++----
 cache.h           | 3 ++-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 15f9912b4ca..cc34c194f5e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	int submodule_progress;
 	int filter_submodules = 0;
 	int hash_algo;
+	const int do_not_override_repo_unix_permissions = -1;
 
 	struct transport_ls_refs_options transport_ls_refs_options =
 		TRANSPORT_LS_REFS_OPTIONS_INIT;
@@ -1097,7 +1098,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	}
 
 	init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
-		INIT_DB_QUIET);
+		do_not_override_repo_unix_permissions, INIT_DB_QUIET);
 
 	if (real_git_dir) {
 		free((char *)git_dir);
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 32ab0a13e09..ae0122534aa 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,8 +31,6 @@
 
 #define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
 
-static int init_shared_repository = -1;
-
 static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
 			     DIR *dir)
 {
@@ -199,6 +197,7 @@ static int create_default_files(const char *template_path,
 				const char *initial_branch,
 				const struct repository_format *fmt,
 				int prev_bare_repository,
+				int init_shared_repository,
 				int quiet)
 {
 	struct stat st1;
@@ -418,7 +417,7 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
 
 int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *template_dir, int hash, const char *initial_branch,
-	    unsigned int flags)
+	    int init_shared_repository, unsigned int flags)
 {
 	int reinit;
 	int exist_ok = flags & INIT_DB_EXIST_OK;
@@ -464,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	reinit = create_default_files(template_dir, original_git_dir,
 				      initial_branch, &repo_fmt,
 				      prev_bare_repository,
+				      init_shared_repository,
 				      flags & INIT_DB_QUIET);
 	if (reinit && initial_branch)
 		warning(_("re-init: ignored --initial-branch=%s"),
@@ -575,6 +575,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 	const char *object_format = NULL;
 	const char *initial_branch = NULL;
 	int hash_algo = GIT_HASH_UNKNOWN;
+	int init_shared_repository = -1;
 	const struct option init_db_options[] = {
 		OPT_STRING(0, "template", &template_dir, N_("template-directory"),
 				N_("directory from which templates will be used")),
@@ -732,5 +733,5 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 
 	flags |= INIT_DB_EXIST_OK;
 	return init_db(git_dir, real_git_dir, template_dir, hash_algo,
-		       initial_branch, flags);
+		       initial_branch, init_shared_repository, flags);
 }
diff --git a/cache.h b/cache.h
index bdedb87e83b..2bc1cd77d9b 100644
--- a/cache.h
+++ b/cache.h
@@ -327,7 +327,8 @@ extern struct index_state the_index;
 
 int init_db(const char *git_dir, const char *real_git_dir,
 	    const char *template_dir, int hash_algo,
-	    const char *initial_branch, unsigned int flags);
+	    const char *initial_branch, int init_shared_repository,
+	    unsigned int flags);
 void initialize_repository_version(int hash_algo, int reinit);
 
 /* Initialize and use the cache information */
-- 
gitgitgadget


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

* [PATCH v3 04/28] setup: adopt shared init-db & clone code
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (2 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 03/28] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 05/28] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
                       ` (24 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The functions init_db() and initialize_repository_version() were shared
by builtin/init-db.c and builtin/clone.c, and declared in cache.h.

Move these functions, plus their several helpers only used by these
functions, to setup.[ch].

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/init-db.c | 496 ----------------------------------------------
 cache.h           |   9 -
 setup.c           | 496 ++++++++++++++++++++++++++++++++++++++++++++++
 setup.h           |   9 +
 4 files changed, 505 insertions(+), 505 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index ae0122534aa..feb019a9dea 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -6,511 +6,15 @@
 #include "cache.h"
 #include "abspath.h"
 #include "config.h"
-#include "copy.h"
 #include "environment.h"
 #include "gettext.h"
-#include "refs.h"
 #include "builtin.h"
-#include "exec-cmd.h"
 #include "object-file.h"
 #include "parse-options.h"
 #include "path.h"
 #include "setup.h"
-#include "worktree.h"
 #include "wrapper.h"
 
-#ifndef DEFAULT_GIT_TEMPLATE_DIR
-#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
-#endif
-
-#ifdef NO_TRUSTABLE_FILEMODE
-#define TEST_FILEMODE 0
-#else
-#define TEST_FILEMODE 1
-#endif
-
-#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
-
-static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
-			     DIR *dir)
-{
-	size_t path_baselen = path->len;
-	size_t template_baselen = template_path->len;
-	struct dirent *de;
-
-	/* Note: if ".git/hooks" file exists in the repository being
-	 * re-initialized, /etc/core-git/templates/hooks/update would
-	 * cause "git init" to fail here.  I think this is sane but
-	 * it means that the set of templates we ship by default, along
-	 * with the way the namespace under .git/ is organized, should
-	 * be really carefully chosen.
-	 */
-	safe_create_dir(path->buf, 1);
-	while ((de = readdir(dir)) != NULL) {
-		struct stat st_git, st_template;
-		int exists = 0;
-
-		strbuf_setlen(path, path_baselen);
-		strbuf_setlen(template_path, template_baselen);
-
-		if (de->d_name[0] == '.')
-			continue;
-		strbuf_addstr(path, de->d_name);
-		strbuf_addstr(template_path, de->d_name);
-		if (lstat(path->buf, &st_git)) {
-			if (errno != ENOENT)
-				die_errno(_("cannot stat '%s'"), path->buf);
-		}
-		else
-			exists = 1;
-
-		if (lstat(template_path->buf, &st_template))
-			die_errno(_("cannot stat template '%s'"), template_path->buf);
-
-		if (S_ISDIR(st_template.st_mode)) {
-			DIR *subdir = opendir(template_path->buf);
-			if (!subdir)
-				die_errno(_("cannot opendir '%s'"), template_path->buf);
-			strbuf_addch(path, '/');
-			strbuf_addch(template_path, '/');
-			copy_templates_1(path, template_path, subdir);
-			closedir(subdir);
-		}
-		else if (exists)
-			continue;
-		else if (S_ISLNK(st_template.st_mode)) {
-			struct strbuf lnk = STRBUF_INIT;
-			if (strbuf_readlink(&lnk, template_path->buf,
-					    st_template.st_size) < 0)
-				die_errno(_("cannot readlink '%s'"), template_path->buf);
-			if (symlink(lnk.buf, path->buf))
-				die_errno(_("cannot symlink '%s' '%s'"),
-					  lnk.buf, path->buf);
-			strbuf_release(&lnk);
-		}
-		else if (S_ISREG(st_template.st_mode)) {
-			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
-				die_errno(_("cannot copy '%s' to '%s'"),
-					  template_path->buf, path->buf);
-		}
-		else
-			error(_("ignoring template %s"), template_path->buf);
-	}
-}
-
-static void copy_templates(const char *template_dir, const char *init_template_dir)
-{
-	struct strbuf path = STRBUF_INIT;
-	struct strbuf template_path = STRBUF_INIT;
-	size_t template_len;
-	struct repository_format template_format = REPOSITORY_FORMAT_INIT;
-	struct strbuf err = STRBUF_INIT;
-	DIR *dir;
-	char *to_free = NULL;
-
-	if (!template_dir)
-		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
-	if (!template_dir)
-		template_dir = init_template_dir;
-	if (!template_dir)
-		template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
-	if (!template_dir[0]) {
-		free(to_free);
-		return;
-	}
-
-	strbuf_addstr(&template_path, template_dir);
-	strbuf_complete(&template_path, '/');
-	template_len = template_path.len;
-
-	dir = opendir(template_path.buf);
-	if (!dir) {
-		warning(_("templates not found in %s"), template_dir);
-		goto free_return;
-	}
-
-	/* Make sure that template is from the correct vintage */
-	strbuf_addstr(&template_path, "config");
-	read_repository_format(&template_format, template_path.buf);
-	strbuf_setlen(&template_path, template_len);
-
-	/*
-	 * No mention of version at all is OK, but anything else should be
-	 * verified.
-	 */
-	if (template_format.version >= 0 &&
-	    verify_repository_format(&template_format, &err) < 0) {
-		warning(_("not copying templates from '%s': %s"),
-			  template_dir, err.buf);
-		strbuf_release(&err);
-		goto close_free_return;
-	}
-
-	strbuf_addstr(&path, get_git_common_dir());
-	strbuf_complete(&path, '/');
-	copy_templates_1(&path, &template_path, dir);
-close_free_return:
-	closedir(dir);
-free_return:
-	free(to_free);
-	strbuf_release(&path);
-	strbuf_release(&template_path);
-	clear_repository_format(&template_format);
-}
-
-/*
- * If the git_dir is not directly inside the working tree, then git will not
- * find it by default, and we need to set the worktree explicitly.
- */
-static int needs_work_tree_config(const char *git_dir, const char *work_tree)
-{
-	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
-		return 0;
-	if (skip_prefix(git_dir, work_tree, &git_dir) &&
-	    !strcmp(git_dir, "/.git"))
-		return 0;
-	return 1;
-}
-
-void initialize_repository_version(int hash_algo, int reinit)
-{
-	char repo_version_string[10];
-	int repo_version = GIT_REPO_VERSION;
-
-	if (hash_algo != GIT_HASH_SHA1)
-		repo_version = GIT_REPO_VERSION_READ;
-
-	/* This forces creation of new config file */
-	xsnprintf(repo_version_string, sizeof(repo_version_string),
-		  "%d", repo_version);
-	git_config_set("core.repositoryformatversion", repo_version_string);
-
-	if (hash_algo != GIT_HASH_SHA1)
-		git_config_set("extensions.objectformat",
-			       hash_algos[hash_algo].name);
-	else if (reinit)
-		git_config_set_gently("extensions.objectformat", NULL);
-}
-
-static int create_default_files(const char *template_path,
-				const char *original_git_dir,
-				const char *initial_branch,
-				const struct repository_format *fmt,
-				int prev_bare_repository,
-				int init_shared_repository,
-				int quiet)
-{
-	struct stat st1;
-	struct strbuf buf = STRBUF_INIT;
-	char *path;
-	char junk[2];
-	int reinit;
-	int filemode;
-	struct strbuf err = STRBUF_INIT;
-	const char *init_template_dir = NULL;
-	const char *work_tree = get_git_work_tree();
-
-	/*
-	 * First copy the templates -- we might have the default
-	 * config file there, in which case we would want to read
-	 * from it after installing.
-	 *
-	 * Before reading that config, we also need to clear out any cached
-	 * values (since we've just potentially changed what's available on
-	 * disk).
-	 */
-	git_config_get_pathname("init.templatedir", &init_template_dir);
-	copy_templates(template_path, init_template_dir);
-	free((char *)init_template_dir);
-	git_config_clear();
-	reset_shared_repository();
-	git_config(git_default_config, NULL);
-
-	/*
-	 * We must make sure command-line options continue to override any
-	 * values we might have just re-read from the config.
-	 */
-	if (init_shared_repository != -1)
-		set_shared_repository(init_shared_repository);
-	/*
-	 * TODO: heed core.bare from config file in templates if no
-	 *       command-line override given
-	 */
-	is_bare_repository_cfg = prev_bare_repository || !work_tree;
-	/* TODO (continued):
-	 *
-	 * Unfortunately, the line above is equivalent to
-	 *    is_bare_repository_cfg = !work_tree;
-	 * which ignores the config entirely even if no `--[no-]bare`
-	 * command line option was present.
-	 *
-	 * To see why, note that before this function, there was this call:
-	 *    prev_bare_repository = is_bare_repository()
-	 * expanding the right hand side:
-	 *                 = is_bare_repository_cfg && !get_git_work_tree()
-	 *                 = is_bare_repository_cfg && !work_tree
-	 * note that the last simplification above is valid because nothing
-	 * calls repo_init() or set_git_work_tree() between any of the
-	 * relevant calls in the code, and thus the !get_git_work_tree()
-	 * calls will return the same result each time.  So, what we are
-	 * interested in computing is the right hand side of the line of
-	 * code just above this comment:
-	 *     prev_bare_repository || !work_tree
-	 *        = is_bare_repository_cfg && !work_tree || !work_tree
-	 *        = !work_tree
-	 * because "A && !B || !B == !B" for all boolean values of A & B.
-	 */
-
-	/*
-	 * We would have created the above under user's umask -- under
-	 * shared-repository settings, we would need to fix them up.
-	 */
-	if (get_shared_repository()) {
-		adjust_shared_perm(get_git_dir());
-	}
-
-	/*
-	 * We need to create a "refs" dir in any case so that older
-	 * versions of git can tell that this is a repository.
-	 */
-	safe_create_dir(git_path("refs"), 1);
-	adjust_shared_perm(git_path("refs"));
-
-	if (refs_init_db(&err))
-		die("failed to set up refs db: %s", err.buf);
-
-	/*
-	 * Point the HEAD symref to the initial branch with if HEAD does
-	 * not yet exist.
-	 */
-	path = git_path_buf(&buf, "HEAD");
-	reinit = (!access(path, R_OK)
-		  || readlink(path, junk, sizeof(junk)-1) != -1);
-	if (!reinit) {
-		char *ref;
-
-		if (!initial_branch)
-			initial_branch = git_default_branch_name(quiet);
-
-		ref = xstrfmt("refs/heads/%s", initial_branch);
-		if (check_refname_format(ref, 0) < 0)
-			die(_("invalid initial branch name: '%s'"),
-			    initial_branch);
-
-		if (create_symref("HEAD", ref, NULL) < 0)
-			exit(1);
-		free(ref);
-	}
-
-	initialize_repository_version(fmt->hash_algo, 0);
-
-	/* Check filemode trustability */
-	path = git_path_buf(&buf, "config");
-	filemode = TEST_FILEMODE;
-	if (TEST_FILEMODE && !lstat(path, &st1)) {
-		struct stat st2;
-		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
-				!lstat(path, &st2) &&
-				st1.st_mode != st2.st_mode &&
-				!chmod(path, st1.st_mode));
-		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
-			filemode = 0;
-	}
-	git_config_set("core.filemode", filemode ? "true" : "false");
-
-	if (is_bare_repository())
-		git_config_set("core.bare", "true");
-	else {
-		git_config_set("core.bare", "false");
-		/* allow template config file to override the default */
-		if (log_all_ref_updates == LOG_REFS_UNSET)
-			git_config_set("core.logallrefupdates", "true");
-		if (needs_work_tree_config(original_git_dir, work_tree))
-			git_config_set("core.worktree", work_tree);
-	}
-
-	if (!reinit) {
-		/* Check if symlink is supported in the work tree */
-		path = git_path_buf(&buf, "tXXXXXX");
-		if (!close(xmkstemp(path)) &&
-		    !unlink(path) &&
-		    !symlink("testing", path) &&
-		    !lstat(path, &st1) &&
-		    S_ISLNK(st1.st_mode))
-			unlink(path); /* good */
-		else
-			git_config_set("core.symlinks", "false");
-
-		/* Check if the filesystem is case-insensitive */
-		path = git_path_buf(&buf, "CoNfIg");
-		if (!access(path, F_OK))
-			git_config_set("core.ignorecase", "true");
-		probe_utf8_pathname_composition();
-	}
-
-	strbuf_release(&buf);
-	return reinit;
-}
-
-static void create_object_directory(void)
-{
-	struct strbuf path = STRBUF_INIT;
-	size_t baselen;
-
-	strbuf_addstr(&path, get_object_directory());
-	baselen = path.len;
-
-	safe_create_dir(path.buf, 1);
-
-	strbuf_setlen(&path, baselen);
-	strbuf_addstr(&path, "/pack");
-	safe_create_dir(path.buf, 1);
-
-	strbuf_setlen(&path, baselen);
-	strbuf_addstr(&path, "/info");
-	safe_create_dir(path.buf, 1);
-
-	strbuf_release(&path);
-}
-
-static void separate_git_dir(const char *git_dir, const char *git_link)
-{
-	struct stat st;
-
-	if (!stat(git_link, &st)) {
-		const char *src;
-
-		if (S_ISREG(st.st_mode))
-			src = read_gitfile(git_link);
-		else if (S_ISDIR(st.st_mode))
-			src = git_link;
-		else
-			die(_("unable to handle file type %d"), (int)st.st_mode);
-
-		if (rename(src, git_dir))
-			die_errno(_("unable to move %s to %s"), src, git_dir);
-		repair_worktrees(NULL, NULL);
-	}
-
-	write_file(git_link, "gitdir: %s", git_dir);
-}
-
-static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
-{
-	const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
-	/*
-	 * If we already have an initialized repo, don't allow the user to
-	 * specify a different algorithm, as that could cause corruption.
-	 * Otherwise, if the user has specified one on the command line, use it.
-	 */
-	if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
-		die(_("attempt to reinitialize repository with different hash"));
-	else if (hash != GIT_HASH_UNKNOWN)
-		repo_fmt->hash_algo = hash;
-	else if (env) {
-		int env_algo = hash_algo_by_name(env);
-		if (env_algo == GIT_HASH_UNKNOWN)
-			die(_("unknown hash algorithm '%s'"), env);
-		repo_fmt->hash_algo = env_algo;
-	}
-}
-
-int init_db(const char *git_dir, const char *real_git_dir,
-	    const char *template_dir, int hash, const char *initial_branch,
-	    int init_shared_repository, unsigned int flags)
-{
-	int reinit;
-	int exist_ok = flags & INIT_DB_EXIST_OK;
-	char *original_git_dir = real_pathdup(git_dir, 1);
-	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
-	int prev_bare_repository;
-
-	if (real_git_dir) {
-		struct stat st;
-
-		if (!exist_ok && !stat(git_dir, &st))
-			die(_("%s already exists"), git_dir);
-
-		if (!exist_ok && !stat(real_git_dir, &st))
-			die(_("%s already exists"), real_git_dir);
-
-		set_git_dir(real_git_dir, 1);
-		git_dir = get_git_dir();
-		separate_git_dir(git_dir, original_git_dir);
-	}
-	else {
-		set_git_dir(git_dir, 1);
-		git_dir = get_git_dir();
-	}
-	startup_info->have_repository = 1;
-
-	/* Ensure `core.hidedotfiles` is processed */
-	git_config(platform_core_config, NULL);
-
-	safe_create_dir(git_dir, 0);
-
-	prev_bare_repository = is_bare_repository();
-
-	/* Check to see if the repository version is right.
-	 * Note that a newly created repository does not have
-	 * config file, so this will not fail.  What we are catching
-	 * is an attempt to reinitialize new repository with an old tool.
-	 */
-	check_repository_format(&repo_fmt);
-
-	validate_hash_algorithm(&repo_fmt, hash);
-
-	reinit = create_default_files(template_dir, original_git_dir,
-				      initial_branch, &repo_fmt,
-				      prev_bare_repository,
-				      init_shared_repository,
-				      flags & INIT_DB_QUIET);
-	if (reinit && initial_branch)
-		warning(_("re-init: ignored --initial-branch=%s"),
-			initial_branch);
-
-	create_object_directory();
-
-	if (get_shared_repository()) {
-		char buf[10];
-		/* We do not spell "group" and such, so that
-		 * the configuration can be read by older version
-		 * of git. Note, we use octal numbers for new share modes,
-		 * and compatibility values for PERM_GROUP and
-		 * PERM_EVERYBODY.
-		 */
-		if (get_shared_repository() < 0)
-			/* force to the mode value */
-			xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
-		else if (get_shared_repository() == PERM_GROUP)
-			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
-		else if (get_shared_repository() == PERM_EVERYBODY)
-			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
-		else
-			BUG("invalid value for shared_repository");
-		git_config_set("core.sharedrepository", buf);
-		git_config_set("receive.denyNonFastforwards", "true");
-	}
-
-	if (!(flags & INIT_DB_QUIET)) {
-		int len = strlen(git_dir);
-
-		if (reinit)
-			printf(get_shared_repository()
-			       ? _("Reinitialized existing shared Git repository in %s%s\n")
-			       : _("Reinitialized existing Git repository in %s%s\n"),
-			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
-		else
-			printf(get_shared_repository()
-			       ? _("Initialized empty shared Git repository in %s%s\n")
-			       : _("Initialized empty Git repository in %s%s\n"),
-			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
-	}
-
-	free(original_git_dir);
-	return 0;
-}
-
 static int guess_repository_type(const char *git_dir)
 {
 	const char *slash;
diff --git a/cache.h b/cache.h
index 2bc1cd77d9b..8b2eb52f04e 100644
--- a/cache.h
+++ b/cache.h
@@ -322,15 +322,6 @@ void prefetch_cache_entries(const struct index_state *istate,
 extern struct index_state the_index;
 #endif
 
-#define INIT_DB_QUIET 0x0001
-#define INIT_DB_EXIST_OK 0x0002
-
-int init_db(const char *git_dir, const char *real_git_dir,
-	    const char *template_dir, int hash_algo,
-	    const char *initial_branch, int init_shared_repository,
-	    unsigned int flags);
-void initialize_repository_version(int hash_algo, int reinit);
-
 /* Initialize and use the cache information */
 struct lock_file;
 void preload_index(struct index_state *index,
diff --git a/setup.c b/setup.c
index 59abc16ba6d..1cc1f3b3978 100644
--- a/setup.c
+++ b/setup.c
@@ -1,8 +1,11 @@
 #include "git-compat-util.h"
 #include "abspath.h"
+#include "copy.h"
 #include "environment.h"
+#include "exec-cmd.h"
 #include "gettext.h"
 #include "object-name.h"
+#include "refs.h"
 #include "repository.h"
 #include "config.h"
 #include "dir.h"
@@ -12,6 +15,7 @@
 #include "promisor-remote.h"
 #include "quote.h"
 #include "trace2.h"
+#include "worktree.h"
 #include "wrapper.h"
 
 static int inside_git_dir = -1;
@@ -1706,3 +1710,495 @@ int daemonize(void)
 	return 0;
 #endif
 }
+
+#ifndef DEFAULT_GIT_TEMPLATE_DIR
+#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
+#endif
+
+#ifdef NO_TRUSTABLE_FILEMODE
+#define TEST_FILEMODE 0
+#else
+#define TEST_FILEMODE 1
+#endif
+
+#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
+
+static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
+			     DIR *dir)
+{
+	size_t path_baselen = path->len;
+	size_t template_baselen = template_path->len;
+	struct dirent *de;
+
+	/* Note: if ".git/hooks" file exists in the repository being
+	 * re-initialized, /etc/core-git/templates/hooks/update would
+	 * cause "git init" to fail here.  I think this is sane but
+	 * it means that the set of templates we ship by default, along
+	 * with the way the namespace under .git/ is organized, should
+	 * be really carefully chosen.
+	 */
+	safe_create_dir(path->buf, 1);
+	while ((de = readdir(dir)) != NULL) {
+		struct stat st_git, st_template;
+		int exists = 0;
+
+		strbuf_setlen(path, path_baselen);
+		strbuf_setlen(template_path, template_baselen);
+
+		if (de->d_name[0] == '.')
+			continue;
+		strbuf_addstr(path, de->d_name);
+		strbuf_addstr(template_path, de->d_name);
+		if (lstat(path->buf, &st_git)) {
+			if (errno != ENOENT)
+				die_errno(_("cannot stat '%s'"), path->buf);
+		}
+		else
+			exists = 1;
+
+		if (lstat(template_path->buf, &st_template))
+			die_errno(_("cannot stat template '%s'"), template_path->buf);
+
+		if (S_ISDIR(st_template.st_mode)) {
+			DIR *subdir = opendir(template_path->buf);
+			if (!subdir)
+				die_errno(_("cannot opendir '%s'"), template_path->buf);
+			strbuf_addch(path, '/');
+			strbuf_addch(template_path, '/');
+			copy_templates_1(path, template_path, subdir);
+			closedir(subdir);
+		}
+		else if (exists)
+			continue;
+		else if (S_ISLNK(st_template.st_mode)) {
+			struct strbuf lnk = STRBUF_INIT;
+			if (strbuf_readlink(&lnk, template_path->buf,
+					    st_template.st_size) < 0)
+				die_errno(_("cannot readlink '%s'"), template_path->buf);
+			if (symlink(lnk.buf, path->buf))
+				die_errno(_("cannot symlink '%s' '%s'"),
+					  lnk.buf, path->buf);
+			strbuf_release(&lnk);
+		}
+		else if (S_ISREG(st_template.st_mode)) {
+			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
+				die_errno(_("cannot copy '%s' to '%s'"),
+					  template_path->buf, path->buf);
+		}
+		else
+			error(_("ignoring template %s"), template_path->buf);
+	}
+}
+
+static void copy_templates(const char *template_dir, const char *init_template_dir)
+{
+	struct strbuf path = STRBUF_INIT;
+	struct strbuf template_path = STRBUF_INIT;
+	size_t template_len;
+	struct repository_format template_format = REPOSITORY_FORMAT_INIT;
+	struct strbuf err = STRBUF_INIT;
+	DIR *dir;
+	char *to_free = NULL;
+
+	if (!template_dir)
+		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
+	if (!template_dir)
+		template_dir = init_template_dir;
+	if (!template_dir)
+		template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
+	if (!template_dir[0]) {
+		free(to_free);
+		return;
+	}
+
+	strbuf_addstr(&template_path, template_dir);
+	strbuf_complete(&template_path, '/');
+	template_len = template_path.len;
+
+	dir = opendir(template_path.buf);
+	if (!dir) {
+		warning(_("templates not found in %s"), template_dir);
+		goto free_return;
+	}
+
+	/* Make sure that template is from the correct vintage */
+	strbuf_addstr(&template_path, "config");
+	read_repository_format(&template_format, template_path.buf);
+	strbuf_setlen(&template_path, template_len);
+
+	/*
+	 * No mention of version at all is OK, but anything else should be
+	 * verified.
+	 */
+	if (template_format.version >= 0 &&
+	    verify_repository_format(&template_format, &err) < 0) {
+		warning(_("not copying templates from '%s': %s"),
+			  template_dir, err.buf);
+		strbuf_release(&err);
+		goto close_free_return;
+	}
+
+	strbuf_addstr(&path, get_git_common_dir());
+	strbuf_complete(&path, '/');
+	copy_templates_1(&path, &template_path, dir);
+close_free_return:
+	closedir(dir);
+free_return:
+	free(to_free);
+	strbuf_release(&path);
+	strbuf_release(&template_path);
+	clear_repository_format(&template_format);
+}
+
+/*
+ * If the git_dir is not directly inside the working tree, then git will not
+ * find it by default, and we need to set the worktree explicitly.
+ */
+static int needs_work_tree_config(const char *git_dir, const char *work_tree)
+{
+	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
+		return 0;
+	if (skip_prefix(git_dir, work_tree, &git_dir) &&
+	    !strcmp(git_dir, "/.git"))
+		return 0;
+	return 1;
+}
+
+void initialize_repository_version(int hash_algo, int reinit)
+{
+	char repo_version_string[10];
+	int repo_version = GIT_REPO_VERSION;
+
+	if (hash_algo != GIT_HASH_SHA1)
+		repo_version = GIT_REPO_VERSION_READ;
+
+	/* This forces creation of new config file */
+	xsnprintf(repo_version_string, sizeof(repo_version_string),
+		  "%d", repo_version);
+	git_config_set("core.repositoryformatversion", repo_version_string);
+
+	if (hash_algo != GIT_HASH_SHA1)
+		git_config_set("extensions.objectformat",
+			       hash_algos[hash_algo].name);
+	else if (reinit)
+		git_config_set_gently("extensions.objectformat", NULL);
+}
+
+static int create_default_files(const char *template_path,
+				const char *original_git_dir,
+				const char *initial_branch,
+				const struct repository_format *fmt,
+				int prev_bare_repository,
+				int init_shared_repository,
+				int quiet)
+{
+	struct stat st1;
+	struct strbuf buf = STRBUF_INIT;
+	char *path;
+	char junk[2];
+	int reinit;
+	int filemode;
+	struct strbuf err = STRBUF_INIT;
+	const char *init_template_dir = NULL;
+	const char *work_tree = get_git_work_tree();
+
+	/*
+	 * First copy the templates -- we might have the default
+	 * config file there, in which case we would want to read
+	 * from it after installing.
+	 *
+	 * Before reading that config, we also need to clear out any cached
+	 * values (since we've just potentially changed what's available on
+	 * disk).
+	 */
+	git_config_get_pathname("init.templatedir", &init_template_dir);
+	copy_templates(template_path, init_template_dir);
+	free((char *)init_template_dir);
+	git_config_clear();
+	reset_shared_repository();
+	git_config(git_default_config, NULL);
+
+	/*
+	 * We must make sure command-line options continue to override any
+	 * values we might have just re-read from the config.
+	 */
+	if (init_shared_repository != -1)
+		set_shared_repository(init_shared_repository);
+	/*
+	 * TODO: heed core.bare from config file in templates if no
+	 *       command-line override given
+	 */
+	is_bare_repository_cfg = prev_bare_repository || !work_tree;
+	/* TODO (continued):
+	 *
+	 * Unfortunately, the line above is equivalent to
+	 *    is_bare_repository_cfg = !work_tree;
+	 * which ignores the config entirely even if no `--[no-]bare`
+	 * command line option was present.
+	 *
+	 * To see why, note that before this function, there was this call:
+	 *    prev_bare_repository = is_bare_repository()
+	 * expanding the right hand side:
+	 *                 = is_bare_repository_cfg && !get_git_work_tree()
+	 *                 = is_bare_repository_cfg && !work_tree
+	 * note that the last simplification above is valid because nothing
+	 * calls repo_init() or set_git_work_tree() between any of the
+	 * relevant calls in the code, and thus the !get_git_work_tree()
+	 * calls will return the same result each time.  So, what we are
+	 * interested in computing is the right hand side of the line of
+	 * code just above this comment:
+	 *     prev_bare_repository || !work_tree
+	 *        = is_bare_repository_cfg && !work_tree || !work_tree
+	 *        = !work_tree
+	 * because "A && !B || !B == !B" for all boolean values of A & B.
+	 */
+
+	/*
+	 * We would have created the above under user's umask -- under
+	 * shared-repository settings, we would need to fix them up.
+	 */
+	if (get_shared_repository()) {
+		adjust_shared_perm(get_git_dir());
+	}
+
+	/*
+	 * We need to create a "refs" dir in any case so that older
+	 * versions of git can tell that this is a repository.
+	 */
+	safe_create_dir(git_path("refs"), 1);
+	adjust_shared_perm(git_path("refs"));
+
+	if (refs_init_db(&err))
+		die("failed to set up refs db: %s", err.buf);
+
+	/*
+	 * Point the HEAD symref to the initial branch with if HEAD does
+	 * not yet exist.
+	 */
+	path = git_path_buf(&buf, "HEAD");
+	reinit = (!access(path, R_OK)
+		  || readlink(path, junk, sizeof(junk)-1) != -1);
+	if (!reinit) {
+		char *ref;
+
+		if (!initial_branch)
+			initial_branch = git_default_branch_name(quiet);
+
+		ref = xstrfmt("refs/heads/%s", initial_branch);
+		if (check_refname_format(ref, 0) < 0)
+			die(_("invalid initial branch name: '%s'"),
+			    initial_branch);
+
+		if (create_symref("HEAD", ref, NULL) < 0)
+			exit(1);
+		free(ref);
+	}
+
+	initialize_repository_version(fmt->hash_algo, 0);
+
+	/* Check filemode trustability */
+	path = git_path_buf(&buf, "config");
+	filemode = TEST_FILEMODE;
+	if (TEST_FILEMODE && !lstat(path, &st1)) {
+		struct stat st2;
+		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
+				!lstat(path, &st2) &&
+				st1.st_mode != st2.st_mode &&
+				!chmod(path, st1.st_mode));
+		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
+			filemode = 0;
+	}
+	git_config_set("core.filemode", filemode ? "true" : "false");
+
+	if (is_bare_repository())
+		git_config_set("core.bare", "true");
+	else {
+		git_config_set("core.bare", "false");
+		/* allow template config file to override the default */
+		if (log_all_ref_updates == LOG_REFS_UNSET)
+			git_config_set("core.logallrefupdates", "true");
+		if (needs_work_tree_config(original_git_dir, work_tree))
+			git_config_set("core.worktree", work_tree);
+	}
+
+	if (!reinit) {
+		/* Check if symlink is supported in the work tree */
+		path = git_path_buf(&buf, "tXXXXXX");
+		if (!close(xmkstemp(path)) &&
+		    !unlink(path) &&
+		    !symlink("testing", path) &&
+		    !lstat(path, &st1) &&
+		    S_ISLNK(st1.st_mode))
+			unlink(path); /* good */
+		else
+			git_config_set("core.symlinks", "false");
+
+		/* Check if the filesystem is case-insensitive */
+		path = git_path_buf(&buf, "CoNfIg");
+		if (!access(path, F_OK))
+			git_config_set("core.ignorecase", "true");
+		probe_utf8_pathname_composition();
+	}
+
+	strbuf_release(&buf);
+	return reinit;
+}
+
+static void create_object_directory(void)
+{
+	struct strbuf path = STRBUF_INIT;
+	size_t baselen;
+
+	strbuf_addstr(&path, get_object_directory());
+	baselen = path.len;
+
+	safe_create_dir(path.buf, 1);
+
+	strbuf_setlen(&path, baselen);
+	strbuf_addstr(&path, "/pack");
+	safe_create_dir(path.buf, 1);
+
+	strbuf_setlen(&path, baselen);
+	strbuf_addstr(&path, "/info");
+	safe_create_dir(path.buf, 1);
+
+	strbuf_release(&path);
+}
+
+static void separate_git_dir(const char *git_dir, const char *git_link)
+{
+	struct stat st;
+
+	if (!stat(git_link, &st)) {
+		const char *src;
+
+		if (S_ISREG(st.st_mode))
+			src = read_gitfile(git_link);
+		else if (S_ISDIR(st.st_mode))
+			src = git_link;
+		else
+			die(_("unable to handle file type %d"), (int)st.st_mode);
+
+		if (rename(src, git_dir))
+			die_errno(_("unable to move %s to %s"), src, git_dir);
+		repair_worktrees(NULL, NULL);
+	}
+
+	write_file(git_link, "gitdir: %s", git_dir);
+}
+
+static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
+{
+	const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
+	/*
+	 * If we already have an initialized repo, don't allow the user to
+	 * specify a different algorithm, as that could cause corruption.
+	 * Otherwise, if the user has specified one on the command line, use it.
+	 */
+	if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
+		die(_("attempt to reinitialize repository with different hash"));
+	else if (hash != GIT_HASH_UNKNOWN)
+		repo_fmt->hash_algo = hash;
+	else if (env) {
+		int env_algo = hash_algo_by_name(env);
+		if (env_algo == GIT_HASH_UNKNOWN)
+			die(_("unknown hash algorithm '%s'"), env);
+		repo_fmt->hash_algo = env_algo;
+	}
+}
+
+int init_db(const char *git_dir, const char *real_git_dir,
+	    const char *template_dir, int hash, const char *initial_branch,
+	    int init_shared_repository, unsigned int flags)
+{
+	int reinit;
+	int exist_ok = flags & INIT_DB_EXIST_OK;
+	char *original_git_dir = real_pathdup(git_dir, 1);
+	struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+	int prev_bare_repository;
+
+	if (real_git_dir) {
+		struct stat st;
+
+		if (!exist_ok && !stat(git_dir, &st))
+			die(_("%s already exists"), git_dir);
+
+		if (!exist_ok && !stat(real_git_dir, &st))
+			die(_("%s already exists"), real_git_dir);
+
+		set_git_dir(real_git_dir, 1);
+		git_dir = get_git_dir();
+		separate_git_dir(git_dir, original_git_dir);
+	}
+	else {
+		set_git_dir(git_dir, 1);
+		git_dir = get_git_dir();
+	}
+	startup_info->have_repository = 1;
+
+	/* Ensure `core.hidedotfiles` is processed */
+	git_config(platform_core_config, NULL);
+
+	safe_create_dir(git_dir, 0);
+
+	prev_bare_repository = is_bare_repository();
+
+	/* Check to see if the repository version is right.
+	 * Note that a newly created repository does not have
+	 * config file, so this will not fail.  What we are catching
+	 * is an attempt to reinitialize new repository with an old tool.
+	 */
+	check_repository_format(&repo_fmt);
+
+	validate_hash_algorithm(&repo_fmt, hash);
+
+	reinit = create_default_files(template_dir, original_git_dir,
+				      initial_branch, &repo_fmt,
+				      prev_bare_repository,
+				      init_shared_repository,
+				      flags & INIT_DB_QUIET);
+	if (reinit && initial_branch)
+		warning(_("re-init: ignored --initial-branch=%s"),
+			initial_branch);
+
+	create_object_directory();
+
+	if (get_shared_repository()) {
+		char buf[10];
+		/* We do not spell "group" and such, so that
+		 * the configuration can be read by older version
+		 * of git. Note, we use octal numbers for new share modes,
+		 * and compatibility values for PERM_GROUP and
+		 * PERM_EVERYBODY.
+		 */
+		if (get_shared_repository() < 0)
+			/* force to the mode value */
+			xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
+		else if (get_shared_repository() == PERM_GROUP)
+			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
+		else if (get_shared_repository() == PERM_EVERYBODY)
+			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
+		else
+			BUG("invalid value for shared_repository");
+		git_config_set("core.sharedrepository", buf);
+		git_config_set("receive.denyNonFastforwards", "true");
+	}
+
+	if (!(flags & INIT_DB_QUIET)) {
+		int len = strlen(git_dir);
+
+		if (reinit)
+			printf(get_shared_repository()
+			       ? _("Reinitialized existing shared Git repository in %s%s\n")
+			       : _("Reinitialized existing Git repository in %s%s\n"),
+			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+		else
+			printf(get_shared_repository()
+			       ? _("Initialized empty shared Git repository in %s%s\n")
+			       : _("Initialized empty Git repository in %s%s\n"),
+			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+	}
+
+	free(original_git_dir);
+	return 0;
+}
diff --git a/setup.h b/setup.h
index 4c1ca9d0c94..58fd2605dd2 100644
--- a/setup.h
+++ b/setup.h
@@ -140,6 +140,15 @@ int verify_repository_format(const struct repository_format *format,
  */
 void check_repository_format(struct repository_format *fmt);
 
+#define INIT_DB_QUIET 0x0001
+#define INIT_DB_EXIST_OK 0x0002
+
+int init_db(const char *git_dir, const char *real_git_dir,
+	    const char *template_dir, int hash_algo,
+	    const char *initial_branch, int init_shared_repository,
+	    unsigned int flags);
+void initialize_repository_version(int hash_algo, int reinit);
+
 /*
  * NOTE NOTE NOTE!!
  *
-- 
gitgitgadget


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

* [PATCH v3 05/28] read-cache: move shared commit and ls-files code
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (3 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 04/28] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 06/28] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
                       ` (23 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function overlay_tree_on_index(), plus associated helper functions,
were defined in builtin/ls-files.c, but also shared with
builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/ls-files.c | 137 ---------------------------------------------
 read-cache.c       | 137 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 137 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 625f48f0d61..069b28bd484 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -516,143 +516,6 @@ static int get_common_prefix_len(const char *common_prefix)
 	return common_prefix_len;
 }
 
-static int read_one_entry_opt(struct index_state *istate,
-			      const struct object_id *oid,
-			      struct strbuf *base,
-			      const char *pathname,
-			      unsigned mode, int opt)
-{
-	int len;
-	struct cache_entry *ce;
-
-	if (S_ISDIR(mode))
-		return READ_TREE_RECURSIVE;
-
-	len = strlen(pathname);
-	ce = make_empty_cache_entry(istate, base->len + len);
-
-	ce->ce_mode = create_ce_mode(mode);
-	ce->ce_flags = create_ce_flags(1);
-	ce->ce_namelen = base->len + len;
-	memcpy(ce->name, base->buf, base->len);
-	memcpy(ce->name + base->len, pathname, len+1);
-	oidcpy(&ce->oid, oid);
-	return add_index_entry(istate, ce, opt);
-}
-
-static int read_one_entry(const struct object_id *oid, struct strbuf *base,
-			  const char *pathname, unsigned mode,
-			  void *context)
-{
-	struct index_state *istate = context;
-	return read_one_entry_opt(istate, oid, base, pathname,
-				  mode,
-				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
-}
-
-/*
- * This is used when the caller knows there is no existing entries at
- * the stage that will conflict with the entry being added.
- */
-static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
-				const char *pathname, unsigned mode,
-				void *context)
-{
-	struct index_state *istate = context;
-	return read_one_entry_opt(istate, oid, base, pathname,
-				  mode, ADD_CACHE_JUST_APPEND);
-}
-
-/*
- * Read the tree specified with --with-tree option
- * (typically, HEAD) into stage #1 and then
- * squash them down to stage #0.  This is used for
- * --error-unmatch to list and check the path patterns
- * that were given from the command line.  We are not
- * going to write this index out.
- */
-void overlay_tree_on_index(struct index_state *istate,
-			   const char *tree_name, const char *prefix)
-{
-	struct tree *tree;
-	struct object_id oid;
-	struct pathspec pathspec;
-	struct cache_entry *last_stage0 = NULL;
-	int i;
-	read_tree_fn_t fn = NULL;
-	int err;
-
-	if (repo_get_oid(the_repository, tree_name, &oid))
-		die("tree-ish %s not found.", tree_name);
-	tree = parse_tree_indirect(&oid);
-	if (!tree)
-		die("bad tree-ish %s", tree_name);
-
-	/* Hoist the unmerged entries up to stage #3 to make room */
-	/* TODO: audit for interaction with sparse-index. */
-	ensure_full_index(istate);
-	for (i = 0; i < istate->cache_nr; i++) {
-		struct cache_entry *ce = istate->cache[i];
-		if (!ce_stage(ce))
-			continue;
-		ce->ce_flags |= CE_STAGEMASK;
-	}
-
-	if (prefix) {
-		static const char *(matchbuf[1]);
-		matchbuf[0] = NULL;
-		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
-			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
-	} else
-		memset(&pathspec, 0, sizeof(pathspec));
-
-	/*
-	 * See if we have cache entry at the stage.  If so,
-	 * do it the original slow way, otherwise, append and then
-	 * sort at the end.
-	 */
-	for (i = 0; !fn && i < istate->cache_nr; i++) {
-		const struct cache_entry *ce = istate->cache[i];
-		if (ce_stage(ce) == 1)
-			fn = read_one_entry;
-	}
-
-	if (!fn)
-		fn = read_one_entry_quick;
-	err = read_tree(the_repository, tree, &pathspec, fn, istate);
-	clear_pathspec(&pathspec);
-	if (err)
-		die("unable to read tree entries %s", tree_name);
-
-	/*
-	 * Sort the cache entry -- we need to nuke the cache tree, though.
-	 */
-	if (fn == read_one_entry_quick) {
-		cache_tree_free(&istate->cache_tree);
-		QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
-	}
-
-	for (i = 0; i < istate->cache_nr; i++) {
-		struct cache_entry *ce = istate->cache[i];
-		switch (ce_stage(ce)) {
-		case 0:
-			last_stage0 = ce;
-			/* fallthru */
-		default:
-			continue;
-		case 1:
-			/*
-			 * If there is stage #0 entry for this, we do not
-			 * need to show it.  We use CE_UPDATE bit to mark
-			 * such an entry.
-			 */
-			if (last_stage0 &&
-			    !strcmp(last_stage0->name, ce->name))
-				ce->ce_flags |= CE_UPDATE;
-		}
-	}
-}
-
 static const char * const ls_files_usage[] = {
 	N_("git ls-files [<options>] [<file>...]"),
 	NULL
diff --git a/read-cache.c b/read-cache.c
index f4c31a68c85..c0df4586c9b 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3806,3 +3806,140 @@ void prefetch_cache_entries(const struct index_state *istate,
 				   to_fetch.oid, to_fetch.nr);
 	oid_array_clear(&to_fetch);
 }
+
+static int read_one_entry_opt(struct index_state *istate,
+			      const struct object_id *oid,
+			      struct strbuf *base,
+			      const char *pathname,
+			      unsigned mode, int opt)
+{
+	int len;
+	struct cache_entry *ce;
+
+	if (S_ISDIR(mode))
+		return READ_TREE_RECURSIVE;
+
+	len = strlen(pathname);
+	ce = make_empty_cache_entry(istate, base->len + len);
+
+	ce->ce_mode = create_ce_mode(mode);
+	ce->ce_flags = create_ce_flags(1);
+	ce->ce_namelen = base->len + len;
+	memcpy(ce->name, base->buf, base->len);
+	memcpy(ce->name + base->len, pathname, len+1);
+	oidcpy(&ce->oid, oid);
+	return add_index_entry(istate, ce, opt);
+}
+
+static int read_one_entry(const struct object_id *oid, struct strbuf *base,
+			  const char *pathname, unsigned mode,
+			  void *context)
+{
+	struct index_state *istate = context;
+	return read_one_entry_opt(istate, oid, base, pathname,
+				  mode,
+				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
+}
+
+/*
+ * This is used when the caller knows there is no existing entries at
+ * the stage that will conflict with the entry being added.
+ */
+static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
+				const char *pathname, unsigned mode,
+				void *context)
+{
+	struct index_state *istate = context;
+	return read_one_entry_opt(istate, oid, base, pathname,
+				  mode, ADD_CACHE_JUST_APPEND);
+}
+
+/*
+ * Read the tree specified with --with-tree option
+ * (typically, HEAD) into stage #1 and then
+ * squash them down to stage #0.  This is used for
+ * --error-unmatch to list and check the path patterns
+ * that were given from the command line.  We are not
+ * going to write this index out.
+ */
+void overlay_tree_on_index(struct index_state *istate,
+			   const char *tree_name, const char *prefix)
+{
+	struct tree *tree;
+	struct object_id oid;
+	struct pathspec pathspec;
+	struct cache_entry *last_stage0 = NULL;
+	int i;
+	read_tree_fn_t fn = NULL;
+	int err;
+
+	if (repo_get_oid(the_repository, tree_name, &oid))
+		die("tree-ish %s not found.", tree_name);
+	tree = parse_tree_indirect(&oid);
+	if (!tree)
+		die("bad tree-ish %s", tree_name);
+
+	/* Hoist the unmerged entries up to stage #3 to make room */
+	/* TODO: audit for interaction with sparse-index. */
+	ensure_full_index(istate);
+	for (i = 0; i < istate->cache_nr; i++) {
+		struct cache_entry *ce = istate->cache[i];
+		if (!ce_stage(ce))
+			continue;
+		ce->ce_flags |= CE_STAGEMASK;
+	}
+
+	if (prefix) {
+		static const char *(matchbuf[1]);
+		matchbuf[0] = NULL;
+		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
+			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
+	} else
+		memset(&pathspec, 0, sizeof(pathspec));
+
+	/*
+	 * See if we have cache entry at the stage.  If so,
+	 * do it the original slow way, otherwise, append and then
+	 * sort at the end.
+	 */
+	for (i = 0; !fn && i < istate->cache_nr; i++) {
+		const struct cache_entry *ce = istate->cache[i];
+		if (ce_stage(ce) == 1)
+			fn = read_one_entry;
+	}
+
+	if (!fn)
+		fn = read_one_entry_quick;
+	err = read_tree(the_repository, tree, &pathspec, fn, istate);
+	clear_pathspec(&pathspec);
+	if (err)
+		die("unable to read tree entries %s", tree_name);
+
+	/*
+	 * Sort the cache entry -- we need to nuke the cache tree, though.
+	 */
+	if (fn == read_one_entry_quick) {
+		cache_tree_free(&istate->cache_tree);
+		QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
+	}
+
+	for (i = 0; i < istate->cache_nr; i++) {
+		struct cache_entry *ce = istate->cache[i];
+		switch (ce_stage(ce)) {
+		case 0:
+			last_stage0 = ce;
+			/* fallthru */
+		default:
+			continue;
+		case 1:
+			/*
+			 * If there is stage #0 entry for this, we do not
+			 * need to show it.  We use CE_UPDATE bit to mark
+			 * such an entry.
+			 */
+			if (last_stage0 &&
+			    !strcmp(last_stage0->name, ce->name))
+				ce->ce_flags |= CE_UPDATE;
+		}
+	}
+}
-- 
gitgitgadget


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

* [PATCH v3 06/28] add: modify add_files_to_cache() to avoid globals
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (4 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 05/28] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 07/28] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
                       ` (22 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function add_files_to_cache() is used by all three of builtin/{add,
checkout, commit}.c.  That suggests this is common library code, and
should be moved somewhere else, like read-cache.c.  However, the
function and its helpers made use of two global variables that made
straight code movement difficult:
  * the_index
  * include_sparse
The latter was perhaps more problematic since it was only accessible in
builtin/add.c but was still affecting builtin/checkout.c and
builtin/commit.c without this fact being very clear from the code.  I'm
not sure if the other two callers would want to add a `--sparse` flag
similar to add.c to get non-default behavior, but exposing this
dependence will help if we ever decide we do want to add such a flag.

Modify add_files_to_cache() and its helpers to accept the necessary
arguments instead of relying on globals.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/add.c      | 22 +++++++++++++++-------
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  3 ++-
 cache.h            |  4 +++-
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index 76cc026a68a..a526eff734e 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -37,6 +37,8 @@ static int include_sparse;
 static const char *pathspec_from_file;
 
 struct update_callback_data {
+	struct index_state *index;
+	int include_sparse;
 	int flags;
 	int add_errors;
 };
@@ -100,7 +102,8 @@ static void update_callback(struct diff_queue_struct *q,
 		struct diff_filepair *p = q->queue[i];
 		const char *path = p->one->path;
 
-		if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
+		if (!data->include_sparse &&
+		    !path_in_sparse_checkout(path, data->index))
 			continue;
 
 		switch (fix_unmerged_status(p, data)) {
@@ -108,7 +111,7 @@ static void update_callback(struct diff_queue_struct *q,
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
 		case DIFF_STATUS_TYPE_CHANGED:
-			if (add_file_to_index(&the_index, path,	data->flags)) {
+			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
 				data->add_errors++;
@@ -118,7 +121,7 @@ static void update_callback(struct diff_queue_struct *q,
 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
 				break;
 			if (!(data->flags & ADD_CACHE_PRETEND))
-				remove_file_from_index(&the_index, path);
+				remove_file_from_index(data->index, path);
 			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
 				printf(_("remove '%s'\n"), path);
 			break;
@@ -126,16 +129,19 @@ static void update_callback(struct diff_queue_struct *q,
 	}
 }
 
-int add_files_to_cache(const char *prefix,
-		       const struct pathspec *pathspec, int flags)
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags)
 {
 	struct update_callback_data data;
 	struct rev_info rev;
 
 	memset(&data, 0, sizeof(data));
+	data.index = repo->index;
+	data.include_sparse = include_sparse;
 	data.flags = flags;
 
-	repo_init_revisions(the_repository, &rev, prefix);
+	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
 	if (pathspec)
 		copy_pathspec(&rev.prune_data, pathspec);
@@ -640,7 +646,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (add_renormalize)
 		exit_status |= renormalize_tracked_files(&pathspec, flags);
 	else
-		exit_status |= add_files_to_cache(prefix, &pathspec, flags);
+		exit_status |= add_files_to_cache(the_repository, prefix,
+						  &pathspec, include_sparse,
+						  flags);
 
 	if (add_new_files)
 		exit_status |= add_files(&dir, flags);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 715eeb5048f..d6765c9dbd9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -861,7 +861,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 * entries in the index.
 			 */
 
-			add_files_to_cache(NULL, NULL, 0);
+			add_files_to_cache(the_repository, NULL, NULL, 0, 0);
 			init_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index e67c4be2211..bd634ee6ad1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -447,7 +447,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
 	if (all || (also && pathspec.nr)) {
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
-		add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
+		add_files_to_cache(the_repository, also ? prefix : NULL,
+				   &pathspec, 0, 0);
 		refresh_cache_or_die(refresh_flags);
 		cache_tree_update(&the_index, WRITE_TREE_SILENT);
 		if (write_locked_index(&the_index, &index_lock, 0))
diff --git a/cache.h b/cache.h
index 8b2eb52f04e..02d69c24cd6 100644
--- a/cache.h
+++ b/cache.h
@@ -554,7 +554,9 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
  * return 0 if success, 1 - if addition of a file failed and
  * ADD_FILES_IGNORE_ERRORS was specified in flags
  */
-int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags);
 
 /* diff.c */
 extern int diff_auto_refresh_index;
-- 
gitgitgadget


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

* [PATCH v3 07/28] read-cache: move shared add/checkout/commit code
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (5 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 06/28] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 08/28] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
                       ` (21 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The function add_files_to_cache(), plus associated helper functions,
were defined in builtin/add.c, but also shared with builtin/checkout.c
and builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/add.c | 100 -------------------------------------------------
 read-cache.c  | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 100 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index a526eff734e..36ddbb159bf 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -36,13 +36,6 @@ static int pathspec_file_nul;
 static int include_sparse;
 static const char *pathspec_from_file;
 
-struct update_callback_data {
-	struct index_state *index;
-	int include_sparse;
-	int flags;
-	int add_errors;
-};
-
 static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 {
 	int i, ret = 0;
@@ -71,99 +64,6 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
 	return ret;
 }
 
-static int fix_unmerged_status(struct diff_filepair *p,
-			       struct update_callback_data *data)
-{
-	if (p->status != DIFF_STATUS_UNMERGED)
-		return p->status;
-	if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
-		/*
-		 * This is not an explicit add request, and the
-		 * path is missing from the working tree (deleted)
-		 */
-		return DIFF_STATUS_DELETED;
-	else
-		/*
-		 * Either an explicit add request, or path exists
-		 * in the working tree.  An attempt to explicitly
-		 * add a path that does not exist in the working tree
-		 * will be caught as an error by the caller immediately.
-		 */
-		return DIFF_STATUS_MODIFIED;
-}
-
-static void update_callback(struct diff_queue_struct *q,
-			    struct diff_options *opt UNUSED, void *cbdata)
-{
-	int i;
-	struct update_callback_data *data = cbdata;
-
-	for (i = 0; i < q->nr; i++) {
-		struct diff_filepair *p = q->queue[i];
-		const char *path = p->one->path;
-
-		if (!data->include_sparse &&
-		    !path_in_sparse_checkout(path, data->index))
-			continue;
-
-		switch (fix_unmerged_status(p, data)) {
-		default:
-			die(_("unexpected diff status %c"), p->status);
-		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
-			if (add_file_to_index(data->index, path, data->flags)) {
-				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
-					die(_("updating files failed"));
-				data->add_errors++;
-			}
-			break;
-		case DIFF_STATUS_DELETED:
-			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
-				break;
-			if (!(data->flags & ADD_CACHE_PRETEND))
-				remove_file_from_index(data->index, path);
-			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
-				printf(_("remove '%s'\n"), path);
-			break;
-		}
-	}
-}
-
-int add_files_to_cache(struct repository *repo, const char *prefix,
-		       const struct pathspec *pathspec, int include_sparse,
-		       int flags)
-{
-	struct update_callback_data data;
-	struct rev_info rev;
-
-	memset(&data, 0, sizeof(data));
-	data.index = repo->index;
-	data.include_sparse = include_sparse;
-	data.flags = flags;
-
-	repo_init_revisions(repo, &rev, prefix);
-	setup_revisions(0, NULL, &rev, NULL);
-	if (pathspec)
-		copy_pathspec(&rev.prune_data, pathspec);
-	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
-	rev.diffopt.format_callback = update_callback;
-	rev.diffopt.format_callback_data = &data;
-	rev.diffopt.flags.override_submodule_config = 1;
-	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
-
-	/*
-	 * Use an ODB transaction to optimize adding multiple objects.
-	 * This function is invoked from commands other than 'add', which
-	 * may not have their own transaction active.
-	 */
-	begin_odb_transaction();
-	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
-	end_odb_transaction();
-
-	release_revisions(&rev);
-	return !!data.add_errors;
-}
-
 static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
 {
 	int i, retval = 0;
diff --git a/read-cache.c b/read-cache.c
index c0df4586c9b..bfbd531ea60 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "alloc.h"
+#include "bulk-checkin.h"
 #include "config.h"
 #include "date.h"
 #include "diff.h"
@@ -26,6 +27,7 @@
 #include "mem-pool.h"
 #include "object-name.h"
 #include "resolve-undo.h"
+#include "revision.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "trace2.h"
@@ -3943,3 +3945,103 @@ void overlay_tree_on_index(struct index_state *istate,
 		}
 	}
 }
+
+struct update_callback_data {
+	struct index_state *index;
+	int include_sparse;
+	int flags;
+	int add_errors;
+};
+
+static int fix_unmerged_status(struct diff_filepair *p,
+			       struct update_callback_data *data)
+{
+	if (p->status != DIFF_STATUS_UNMERGED)
+		return p->status;
+	if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
+		/*
+		 * This is not an explicit add request, and the
+		 * path is missing from the working tree (deleted)
+		 */
+		return DIFF_STATUS_DELETED;
+	else
+		/*
+		 * Either an explicit add request, or path exists
+		 * in the working tree.  An attempt to explicitly
+		 * add a path that does not exist in the working tree
+		 * will be caught as an error by the caller immediately.
+		 */
+		return DIFF_STATUS_MODIFIED;
+}
+
+static void update_callback(struct diff_queue_struct *q,
+			    struct diff_options *opt UNUSED, void *cbdata)
+{
+	int i;
+	struct update_callback_data *data = cbdata;
+
+	for (i = 0; i < q->nr; i++) {
+		struct diff_filepair *p = q->queue[i];
+		const char *path = p->one->path;
+
+		if (!data->include_sparse &&
+		    !path_in_sparse_checkout(path, data->index))
+			continue;
+
+		switch (fix_unmerged_status(p, data)) {
+		default:
+			die(_("unexpected diff status %c"), p->status);
+		case DIFF_STATUS_MODIFIED:
+		case DIFF_STATUS_TYPE_CHANGED:
+			if (add_file_to_index(data->index, path, data->flags)) {
+				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
+					die(_("updating files failed"));
+				data->add_errors++;
+			}
+			break;
+		case DIFF_STATUS_DELETED:
+			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
+				break;
+			if (!(data->flags & ADD_CACHE_PRETEND))
+				remove_file_from_index(data->index, path);
+			if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
+				printf(_("remove '%s'\n"), path);
+			break;
+		}
+	}
+}
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags)
+{
+	struct update_callback_data data;
+	struct rev_info rev;
+
+	memset(&data, 0, sizeof(data));
+	data.index = repo->index;
+	data.include_sparse = include_sparse;
+	data.flags = flags;
+
+	repo_init_revisions(repo, &rev, prefix);
+	setup_revisions(0, NULL, &rev, NULL);
+	if (pathspec)
+		copy_pathspec(&rev.prune_data, pathspec);
+	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
+	rev.diffopt.format_callback = update_callback;
+	rev.diffopt.format_callback_data = &data;
+	rev.diffopt.flags.override_submodule_config = 1;
+	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+	/*
+	 * Use an ODB transaction to optimize adding multiple objects.
+	 * This function is invoked from commands other than 'add', which
+	 * may not have their own transaction active.
+	 */
+	begin_odb_transaction();
+	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+	end_odb_transaction();
+
+	release_revisions(&rev);
+	return !!data.add_errors;
+}
-- 
gitgitgadget


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

* [PATCH v3 08/28] statinfo: move stat_{data,validity} functions from cache/read-cache
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (6 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 07/28] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 09/28] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
                       ` (20 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

These functions do not depend upon struct cache_entry or struct
index_state in any way, and it seems more logical to break them out into
this file, especially since statinfo.h already has the struct stat_data
declaration.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Makefile              |  1 +
 cache.h               | 48 ------------------------
 object.c              |  1 +
 read-cache.c          | 84 -----------------------------------------
 refs/packed-backend.c |  1 +
 shallow.c             |  1 +
 statinfo.c            | 87 +++++++++++++++++++++++++++++++++++++++++++
 statinfo.h            | 51 +++++++++++++++++++++++++
 8 files changed, 142 insertions(+), 132 deletions(-)
 create mode 100644 statinfo.c

diff --git a/Makefile b/Makefile
index e440728c246..cbc7f212016 100644
--- a/Makefile
+++ b/Makefile
@@ -1142,6 +1142,7 @@ LIB_OBJS += sigchain.o
 LIB_OBJS += sparse-index.o
 LIB_OBJS += split-index.o
 LIB_OBJS += stable-qsort.o
+LIB_OBJS += statinfo.o
 LIB_OBJS += strbuf.o
 LIB_OBJS += streaming.o
 LIB_OBJS += string-list.o
diff --git a/cache.h b/cache.h
index 02d69c24cd6..891e5fec744 100644
--- a/cache.h
+++ b/cache.h
@@ -488,19 +488,6 @@ int has_racy_timestamp(struct index_state *istate);
 int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
 int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
 
-/*
- * Record to sd the data from st that we use to check whether a file
- * might have changed.
- */
-void fill_stat_data(struct stat_data *sd, struct stat *st);
-
-/*
- * Return 0 if st is consistent with a file not having been changed
- * since sd was filled.  If there are differences, return a
- * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
- * INODE_CHANGED, and DATA_CHANGED.
- */
-int match_stat_data(const struct stat_data *sd, struct stat *st);
 int match_stat_data_racy(const struct index_state *istate,
 			 const struct stat_data *sd, struct stat *st);
 
@@ -539,14 +526,6 @@ void set_alternate_index_output(const char *);
 extern int verify_index_checksum;
 extern int verify_ce_order;
 
-#define MTIME_CHANGED	0x0001
-#define CTIME_CHANGED	0x0002
-#define OWNER_CHANGED	0x0004
-#define MODE_CHANGED    0x0008
-#define INODE_CHANGED   0x0010
-#define DATA_CHANGED    0x0020
-#define TYPE_CHANGED    0x0040
-
 int cmp_cache_name_compare(const void *a_, const void *b_);
 
 /* add */
@@ -579,31 +558,4 @@ int checkout_fast_forward(struct repository *r,
 
 int sane_execvp(const char *file, char *const argv[]);
 
-/*
- * A struct to encapsulate the concept of whether a file has changed
- * since we last checked it. This uses criteria similar to those used
- * for the index.
- */
-struct stat_validity {
-	struct stat_data *sd;
-};
-
-void stat_validity_clear(struct stat_validity *sv);
-
-/*
- * Returns 1 if the path is a regular file (or a symlink to a regular
- * file) and matches the saved stat_validity, 0 otherwise.  A missing
- * or inaccessible file is considered a match if the struct was just
- * initialized, or if the previous update found an inaccessible file.
- */
-int stat_validity_check(struct stat_validity *sv, const char *path);
-
-/*
- * Update the stat_validity from a file opened at descriptor fd. If
- * the file is missing, inaccessible, or not a regular file, then
- * future calls to stat_validity_check will match iff one of those
- * conditions continues to be true.
- */
-void stat_validity_update(struct stat_validity *sv, int fd);
-
 #endif /* CACHE_H */
diff --git a/object.c b/object.c
index 6d4ef1524de..333e736fb24 100644
--- a/object.c
+++ b/object.c
@@ -6,6 +6,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "blob.h"
+#include "statinfo.h"
 #include "tree.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/read-cache.c b/read-cache.c
index bfbd531ea60..b99dbfd16b0 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -177,61 +177,6 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
 		add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
 
-void fill_stat_data(struct stat_data *sd, struct stat *st)
-{
-	sd->sd_ctime.sec = (unsigned int)st->st_ctime;
-	sd->sd_mtime.sec = (unsigned int)st->st_mtime;
-	sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
-	sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
-	sd->sd_dev = st->st_dev;
-	sd->sd_ino = st->st_ino;
-	sd->sd_uid = st->st_uid;
-	sd->sd_gid = st->st_gid;
-	sd->sd_size = st->st_size;
-}
-
-int match_stat_data(const struct stat_data *sd, struct stat *st)
-{
-	int changed = 0;
-
-	if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
-		changed |= MTIME_CHANGED;
-	if (trust_ctime && check_stat &&
-	    sd->sd_ctime.sec != (unsigned int)st->st_ctime)
-		changed |= CTIME_CHANGED;
-
-#ifdef USE_NSEC
-	if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
-		changed |= MTIME_CHANGED;
-	if (trust_ctime && check_stat &&
-	    sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
-		changed |= CTIME_CHANGED;
-#endif
-
-	if (check_stat) {
-		if (sd->sd_uid != (unsigned int) st->st_uid ||
-			sd->sd_gid != (unsigned int) st->st_gid)
-			changed |= OWNER_CHANGED;
-		if (sd->sd_ino != (unsigned int) st->st_ino)
-			changed |= INODE_CHANGED;
-	}
-
-#ifdef USE_STDEV
-	/*
-	 * st_dev breaks on network filesystems where different
-	 * clients will have different views of what "device"
-	 * the filesystem is on
-	 */
-	if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
-			changed |= INODE_CHANGED;
-#endif
-
-	if (sd->sd_size != (unsigned int) st->st_size)
-		changed |= DATA_CHANGED;
-
-	return changed;
-}
-
 /*
  * This only updates the "non-critical" parts of the directory
  * cache, ie the parts that aren't tracked by GIT, and only used
@@ -3536,35 +3481,6 @@ void *read_blob_data_from_index(struct index_state *istate,
 	return data;
 }
 
-void stat_validity_clear(struct stat_validity *sv)
-{
-	FREE_AND_NULL(sv->sd);
-}
-
-int stat_validity_check(struct stat_validity *sv, const char *path)
-{
-	struct stat st;
-
-	if (stat(path, &st) < 0)
-		return sv->sd == NULL;
-	if (!sv->sd)
-		return 0;
-	return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
-}
-
-void stat_validity_update(struct stat_validity *sv, int fd)
-{
-	struct stat st;
-
-	if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
-		stat_validity_clear(sv);
-	else {
-		if (!sv->sd)
-			CALLOC_ARRAY(sv->sd, 1);
-		fill_stat_data(sv->sd, &st);
-	}
-}
-
 void move_index_extensions(struct index_state *dst, struct index_state *src)
 {
 	dst->untracked = src->untracked;
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 704424f55c0..085becf773e 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -10,6 +10,7 @@
 #include "../iterator.h"
 #include "../lockfile.h"
 #include "../chdir-notify.h"
+#include "../statinfo.h"
 #include "../wrapper.h"
 #include "../write-or-die.h"
 
diff --git a/shallow.c b/shallow.c
index 128f56179ed..a2ebf0af2ba 100644
--- a/shallow.c
+++ b/shallow.c
@@ -17,6 +17,7 @@
 #include "list-objects.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "statinfo.h"
 #include "trace.h"
 #include "wrapper.h"
 
diff --git a/statinfo.c b/statinfo.c
new file mode 100644
index 00000000000..17bb8966c33
--- /dev/null
+++ b/statinfo.c
@@ -0,0 +1,87 @@
+#include "git-compat-util.h"
+#include "environment.h"
+#include "statinfo.h"
+
+void fill_stat_data(struct stat_data *sd, struct stat *st)
+{
+	sd->sd_ctime.sec = (unsigned int)st->st_ctime;
+	sd->sd_mtime.sec = (unsigned int)st->st_mtime;
+	sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
+	sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
+	sd->sd_dev = st->st_dev;
+	sd->sd_ino = st->st_ino;
+	sd->sd_uid = st->st_uid;
+	sd->sd_gid = st->st_gid;
+	sd->sd_size = st->st_size;
+}
+
+int match_stat_data(const struct stat_data *sd, struct stat *st)
+{
+	int changed = 0;
+
+	if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
+		changed |= MTIME_CHANGED;
+	if (trust_ctime && check_stat &&
+	    sd->sd_ctime.sec != (unsigned int)st->st_ctime)
+		changed |= CTIME_CHANGED;
+
+#ifdef USE_NSEC
+	if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
+		changed |= MTIME_CHANGED;
+	if (trust_ctime && check_stat &&
+	    sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
+		changed |= CTIME_CHANGED;
+#endif
+
+	if (check_stat) {
+		if (sd->sd_uid != (unsigned int) st->st_uid ||
+			sd->sd_gid != (unsigned int) st->st_gid)
+			changed |= OWNER_CHANGED;
+		if (sd->sd_ino != (unsigned int) st->st_ino)
+			changed |= INODE_CHANGED;
+	}
+
+#ifdef USE_STDEV
+	/*
+	 * st_dev breaks on network filesystems where different
+	 * clients will have different views of what "device"
+	 * the filesystem is on
+	 */
+	if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
+			changed |= INODE_CHANGED;
+#endif
+
+	if (sd->sd_size != (unsigned int) st->st_size)
+		changed |= DATA_CHANGED;
+
+	return changed;
+}
+
+void stat_validity_clear(struct stat_validity *sv)
+{
+	FREE_AND_NULL(sv->sd);
+}
+
+int stat_validity_check(struct stat_validity *sv, const char *path)
+{
+	struct stat st;
+
+	if (stat(path, &st) < 0)
+		return sv->sd == NULL;
+	if (!sv->sd)
+		return 0;
+	return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
+}
+
+void stat_validity_update(struct stat_validity *sv, int fd)
+{
+	struct stat st;
+
+	if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
+		stat_validity_clear(sv);
+	else {
+		if (!sv->sd)
+			CALLOC_ARRAY(sv->sd, 1);
+		fill_stat_data(sv->sd, &st);
+	}
+}
diff --git a/statinfo.h b/statinfo.h
index e49e3054eaa..bb9b61bc471 100644
--- a/statinfo.h
+++ b/statinfo.h
@@ -1,6 +1,8 @@
 #ifndef STATINFO_H
 #define STATINFO_H
 
+struct index_state;
+
 /*
  * The "cache_time" is just the low 32 bits of the
  * time. It doesn't matter if it overflows - we only
@@ -21,4 +23,53 @@ struct stat_data {
 	unsigned int sd_size;
 };
 
+/*
+ * A struct to encapsulate the concept of whether a file has changed
+ * since we last checked it. This uses criteria similar to those used
+ * for the index.
+ */
+struct stat_validity {
+	struct stat_data *sd;
+};
+
+#define MTIME_CHANGED	0x0001
+#define CTIME_CHANGED	0x0002
+#define OWNER_CHANGED	0x0004
+#define MODE_CHANGED    0x0008
+#define INODE_CHANGED   0x0010
+#define DATA_CHANGED    0x0020
+#define TYPE_CHANGED    0x0040
+
+/*
+ * Record to sd the data from st that we use to check whether a file
+ * might have changed.
+ */
+void fill_stat_data(struct stat_data *sd, struct stat *st);
+
+/*
+ * Return 0 if st is consistent with a file not having been changed
+ * since sd was filled.  If there are differences, return a
+ * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
+ * INODE_CHANGED, and DATA_CHANGED.
+ */
+int match_stat_data(const struct stat_data *sd, struct stat *st);
+
+void stat_validity_clear(struct stat_validity *sv);
+
+/*
+ * Returns 1 if the path is a regular file (or a symlink to a regular
+ * file) and matches the saved stat_validity, 0 otherwise.  A missing
+ * or inaccessible file is considered a match if the struct was just
+ * initialized, or if the previous update found an inaccessible file.
+ */
+int stat_validity_check(struct stat_validity *sv, const char *path);
+
+/*
+ * Update the stat_validity from a file opened at descriptor fd. If
+ * the file is missing, inaccessible, or not a regular file, then
+ * future calls to stat_validity_check will match iff one of those
+ * conditions continues to be true.
+ */
+void stat_validity_update(struct stat_validity *sv, int fd);
+
 #endif
-- 
gitgitgadget


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

* [PATCH v3 09/28] run-command.h: move declarations for run-command.c from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (7 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 08/28] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 10/28] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
                       ` (19 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h       | 3 ---
 exec-cmd.c    | 3 ++-
 run-command.c | 2 +-
 run-command.h | 2 ++
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cache.h b/cache.h
index 891e5fec744..d31b1515069 100644
--- a/cache.h
+++ b/cache.h
@@ -555,7 +555,4 @@ int checkout_fast_forward(struct repository *r,
 			  const struct object_id *to,
 			  int overwrite_ignore);
 
-
-int sane_execvp(const char *file, char *const argv[]);
-
 #endif /* CACHE_H */
diff --git a/exec-cmd.c b/exec-cmd.c
index 1e34e48c0e4..1d597e84ea7 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,10 +1,11 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "path.h"
 #include "quote.h"
+#include "run-command.h"
 #include "strvec.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/run-command.c b/run-command.c
index d4247d5fcc6..1873d0ba8e7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "run-command.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/run-command.h b/run-command.h
index 072db56a4df..9e47f91d462 100644
--- a/run-command.h
+++ b/run-command.h
@@ -564,4 +564,6 @@ enum start_bg_result start_bg_command(struct child_process *cmd,
 				      void *cb_data,
 				      unsigned int timeout_sec);
 
+int sane_execvp(const char *file, char *const argv[]);
+
 #endif
-- 
gitgitgadget


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

* [PATCH v3 10/28] name-hash.h: move declarations for name-hash.c from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (8 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 09/28] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 11/28] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
                       ` (18 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                             |  1 +
 builtin/mv.c                        |  1 +
 cache.h                             |  9 ---------
 dir.c                               |  1 +
 entry.c                             |  1 +
 merge-recursive.c                   |  1 +
 name-hash.c                         |  1 +
 name-hash.h                         | 16 ++++++++++++++++
 read-cache.c                        |  1 +
 sparse-index.c                      |  1 +
 t/helper/test-lazy-init-name-hash.c |  1 +
 unpack-trees.c                      |  1 +
 12 files changed, 26 insertions(+), 9 deletions(-)
 create mode 100644 name-hash.h

diff --git a/apply.c b/apply.c
index 6212ab3a1b3..3da33bb88fd 100644
--- a/apply.c
+++ b/apply.c
@@ -23,6 +23,7 @@
 #include "xdiff-interface.h"
 #include "ll-merge.h"
 #include "lockfile.h"
+#include "name-hash.h"
 #include "object-name.h"
 #include "object-file.h"
 #include "parse-options.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 665bd274485..e058b574654 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -11,6 +11,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "pathspec.h"
 #include "lockfile.h"
diff --git a/cache.h b/cache.h
index d31b1515069..316904da392 100644
--- a/cache.h
+++ b/cache.h
@@ -245,12 +245,6 @@ struct index_state {
 void index_state_init(struct index_state *istate, struct repository *r);
 void release_index(struct index_state *istate);
 
-/* Name hashing */
-int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
-void add_name_hash(struct index_state *istate, struct cache_entry *ce);
-void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
-void free_name_hash(struct index_state *istate);
-
 /* Cache entry creation and cleanup */
 
 /*
@@ -377,9 +371,6 @@ int repo_index_has_changes(struct repository *repo,
 
 int verify_path(const char *path, unsigned mode);
 int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-int index_dir_exists(struct index_state *istate, const char *name, int namelen);
-void adjust_dirname_case(struct index_state *istate, char *name);
-struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
 
 /*
  * Searches for an entry defined by name and namelen in the given index.
diff --git a/dir.c b/dir.c
index a7469df3ac7..029aab36fe8 100644
--- a/dir.c
+++ b/dir.c
@@ -13,6 +13,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "object-store.h"
 #include "attr.h"
diff --git a/entry.c b/entry.c
index 91a540bd29f..7791cc999cc 100644
--- a/entry.c
+++ b/entry.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "name-hash.h"
 #include "streaming.h"
 #include "submodule.h"
 #include "symlinks.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8e87b6386d9..b341ba4f38d 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -23,6 +23,7 @@
 #include "ll-merge.h"
 #include "lockfile.h"
 #include "match-trees.h"
+#include "name-hash.h"
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/name-hash.c b/name-hash.c
index fb13716e430..52ce47ea394 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "thread-utils.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/name-hash.h b/name-hash.h
new file mode 100644
index 00000000000..b1b4b0fb337
--- /dev/null
+++ b/name-hash.h
@@ -0,0 +1,16 @@
+#ifndef NAME_HASH_H
+#define NAME_HASH_H
+
+struct cache_entry;
+struct index_state;
+
+int index_dir_exists(struct index_state *istate, const char *name, int namelen);
+void adjust_dirname_case(struct index_state *istate, char *name);
+struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
+
+int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
+void add_name_hash(struct index_state *istate, struct cache_entry *ce);
+void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
+void free_name_hash(struct index_state *istate);
+
+#endif /* NAME_HASH_H */
diff --git a/read-cache.c b/read-cache.c
index b99dbfd16b0..e1016ae0317 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -25,6 +25,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "mem-pool.h"
+#include "name-hash.h"
 #include "object-name.h"
 #include "resolve-undo.h"
 #include "revision.h"
diff --git a/sparse-index.c b/sparse-index.c
index 886054729e5..60451daae80 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -2,6 +2,7 @@
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
+#include "name-hash.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index b83a75d19f6..6944b7e825f 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -2,6 +2,7 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "environment.h"
+#include "name-hash.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index e8c32a40dcb..078c53f7a13 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -7,6 +7,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "name-hash.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
-- 
gitgitgadget


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

* [PATCH v3 11/28] sparse-index.h: move declarations for sparse-index.c from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (9 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 10/28] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 12/28] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
                       ` (17 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Note in particular that this reverses the decision made in 118a2e8bde0
("cache: move ensure_full_index() to cache.h", 2021-04-01).

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/checkout-index.c    | 1 +
 builtin/commit.c            | 1 +
 builtin/difftool.c          | 1 +
 builtin/fsck.c              | 1 +
 builtin/ls-files.c          | 1 +
 builtin/merge-index.c       | 1 +
 builtin/read-tree.c         | 1 +
 builtin/reset.c             | 1 +
 builtin/rm.c                | 1 +
 builtin/stash.c             | 1 +
 builtin/submodule--helper.c | 1 +
 builtin/update-index.c      | 1 +
 cache.h                     | 2 --
 dir.c                       | 1 +
 entry.c                     | 1 +
 merge-ort.c                 | 1 +
 merge-recursive.c           | 1 +
 resolve-undo.c              | 1 +
 revision.c                  | 1 +
 sequencer.c                 | 1 +
 sparse-index.h              | 2 ++
 21 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 9375a05539f..b1cd8bef264 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -17,6 +17,7 @@
 #include "entry.h"
 #include "parallel-checkout.h"
 #include "setup.h"
+#include "sparse-index.h"
 
 #define CHECKOUT_ALL 4
 static int nul_term_line;
diff --git a/builtin/commit.c b/builtin/commit.c
index bd634ee6ad1..02e2ef3e307 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -38,6 +38,7 @@
 #include "gpg-interface.h"
 #include "column.h"
 #include "sequencer.h"
+#include "sparse-index.h"
 #include "mailmap.h"
 #include "help.h"
 #include "commit-reach.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 0049342f5c0..2c27a59e04a 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "strbuf.h"
 #include "lockfile.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 2cd461b84c1..7134596d218 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -25,6 +25,7 @@
 #include "replace-object.h"
 #include "resolve-undo.h"
 #include "run-command.h"
+#include "sparse-index.h"
 #include "worktree.h"
 #include "pack-revindex.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 069b28bd484..45b3b0ce5d8 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -23,6 +23,7 @@
 #include "pathspec.h"
 #include "run-command.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index ab16e70f23d..d16e8aa414b 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -3,6 +3,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "run-command.h"
+#include "sparse-index.h"
 
 static const char *pgm;
 static int one_shot, quiet;
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 440f19b1b87..bd1ce1d963f 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -22,6 +22,7 @@
 #include "repository.h"
 #include "resolve-undo.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 
diff --git a/builtin/reset.c b/builtin/reset.c
index f99f32d5802..3dc41ac3327 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -29,6 +29,7 @@
 #include "unpack-trees.h"
 #include "cache-tree.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "trace.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index b4589c824c0..377a0f66ad8 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -19,6 +19,7 @@
 #include "repository.h"
 #include "string-list.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule.h"
 #include "pathspec.h"
 
diff --git a/builtin/stash.c b/builtin/stash.c
index a7e17ffe384..8856ac6d5c7 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -20,6 +20,7 @@
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "log-tree.h"
 #include "diffcore.h"
 #include "exec-cmd.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6bf8d666ce9..c58cfbfd6d3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -13,6 +13,7 @@
 #include "pathspec.h"
 #include "dir.h"
 #include "setup.h"
+#include "sparse-index.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 5fab9ad2ec4..47dc9b626ef 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -24,6 +24,7 @@
 #include "dir.h"
 #include "repository.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "split-index.h"
 #include "symlinks.h"
 #include "fsmonitor.h"
diff --git a/cache.h b/cache.h
index 316904da392..79daaa166b1 100644
--- a/cache.h
+++ b/cache.h
@@ -327,8 +327,6 @@ int read_index_from(struct index_state *, const char *path,
 		    const char *gitdir);
 int is_index_unborn(struct index_state *);
 
-void ensure_full_index(struct index_state *istate);
-
 /* For use with `write_locked_index()`. */
 #define COMMIT_LOCK		(1 << 0)
 #define SKIP_IF_UNCHANGED	(1 << 1)
diff --git a/dir.c b/dir.c
index 029aab36fe8..1e84b1e1f28 100644
--- a/dir.c
+++ b/dir.c
@@ -25,6 +25,7 @@
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "submodule-config.h"
 #include "symlinks.h"
 #include "trace2.h"
diff --git a/entry.c b/entry.c
index 7791cc999cc..53d00386748 100644
--- a/entry.c
+++ b/entry.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "name-hash.h"
+#include "sparse-index.h"
 #include "streaming.h"
 #include "submodule.h"
 #include "symlinks.h"
diff --git a/merge-ort.c b/merge-ort.c
index 65837db77f0..4bff685e456 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -38,6 +38,7 @@
 #include "oid-array.h"
 #include "promisor-remote.h"
 #include "revision.h"
+#include "sparse-index.h"
 #include "strmap.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index b341ba4f38d..0e16e7a06df 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -29,6 +29,7 @@
 #include "object-store.h"
 #include "repository.h"
 #include "revision.h"
+#include "sparse-index.h"
 #include "string-list.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 70a6db526d2..7ec09e89d4f 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -2,6 +2,7 @@
 #include "dir.h"
 #include "hash.h"
 #include "resolve-undo.h"
+#include "sparse-index.h"
 #include "string-list.h"
 
 /* The only error case is to run out of memory in string-list */
diff --git a/revision.c b/revision.c
index b33cc1d106a..88b2f42daa6 100644
--- a/revision.c
+++ b/revision.c
@@ -32,6 +32,7 @@
 #include "packfile.h"
 #include "worktree.h"
 #include "setup.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "trace2.h"
 #include "commit-reach.h"
diff --git a/sequencer.c b/sequencer.c
index ff18f7f4203..cae9c75a54e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -28,6 +28,7 @@
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
+#include "sparse-index.h"
 #include "strvec.h"
 #include "quote.h"
 #include "trailer.h"
diff --git a/sparse-index.h b/sparse-index.h
index 59a92d819ec..a16f3e67d75 100644
--- a/sparse-index.h
+++ b/sparse-index.h
@@ -37,4 +37,6 @@ struct pattern_list;
  */
 void expand_index(struct index_state *istate, struct pattern_list *pl);
 
+void ensure_full_index(struct index_state *istate);
+
 #endif
-- 
gitgitgadget


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

* [PATCH v3 12/28] preload-index.h: move declarations for preload-index.c from elsewhere
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (10 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 11/28] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 13/28] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
                       ` (16 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

We already have a preload-index.c file; move the declarations for the
functions in that file into a new preload-index.h.  These were
previously split between cache.h and repository.h.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c           |  1 +
 builtin/add.c               |  1 +
 builtin/am.c                |  1 +
 builtin/checkout.c          |  1 +
 builtin/commit.c            |  1 +
 builtin/diff-files.c        |  1 +
 builtin/diff-index.c        |  1 +
 builtin/diff.c              |  1 +
 builtin/stash.c             |  1 +
 builtin/submodule--helper.c |  1 +
 cache.h                     |  3 ---
 preload-index.c             |  1 +
 preload-index.h             | 15 +++++++++++++++
 read-cache.c                |  1 +
 repository.h                |  3 ---
 15 files changed, 27 insertions(+), 6 deletions(-)
 create mode 100644 preload-index.h

diff --git a/add-interactive.c b/add-interactive.c
index de877ca0525..99f7dc3b0d1 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -5,6 +5,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/builtin/add.c b/builtin/add.c
index 36ddbb159bf..8397be4f8de 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -17,6 +17,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "revision.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5c83f2e003f..0d8f46f8d5a 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -29,6 +29,7 @@
 #include "unpack-trees.h"
 #include "branch.h"
 #include "object-name.h"
+#include "preload-index.h"
 #include "sequencer.h"
 #include "revision.h"
 #include "merge-recursive.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d6765c9dbd9..2d72a742d9d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,6 +20,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "refs.h"
 #include "remote.h"
 #include "resolve-undo.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 02e2ef3e307..fa769045c88 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -30,6 +30,7 @@
 #include "utf8.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "preload-index.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "unpack-trees.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index dc991f753bb..2e6b59a8bb3 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -8,6 +8,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "builtin.h"
 #include "submodule.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index b9a19bb7d38..9b98db2e77e 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -3,6 +3,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "builtin.h"
 #include "setup.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 7b64659fe79..967550739a6 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -16,6 +16,7 @@
 #include "diff.h"
 #include "diff-merges.h"
 #include "diffcore.h"
+#include "preload-index.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 8856ac6d5c7..06527ee8471 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -17,6 +17,7 @@
 #include "run-command.h"
 #include "dir.h"
 #include "entry.h"
+#include "preload-index.h"
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c58cfbfd6d3..597e780a93a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
+#include "preload-index.h"
 #include "dir.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/cache.h b/cache.h
index 79daaa166b1..b79802a4639 100644
--- a/cache.h
+++ b/cache.h
@@ -318,9 +318,6 @@ extern struct index_state the_index;
 
 /* Initialize and use the cache information */
 struct lock_file;
-void preload_index(struct index_state *index,
-		   const struct pathspec *pathspec,
-		   unsigned int refresh_flags);
 int do_read_index(struct index_state *istate, const char *path,
 		  int must_exist); /* for testting only! */
 int read_index_from(struct index_state *, const char *path,
diff --git a/preload-index.c b/preload-index.c
index 7a26b08c213..c26739debf8 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -8,6 +8,7 @@
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "config.h"
+#include "preload-index.h"
 #include "progress.h"
 #include "thread-utils.h"
 #include "repository.h"
diff --git a/preload-index.h b/preload-index.h
new file mode 100644
index 00000000000..251b1ed88e9
--- /dev/null
+++ b/preload-index.h
@@ -0,0 +1,15 @@
+#ifndef PRELOAD_INDEX_H
+#define PRELOAD_INDEX_H
+
+struct index_state;
+struct pathspec;
+struct repository;
+
+void preload_index(struct index_state *index,
+		   const struct pathspec *pathspec,
+		   unsigned int refresh_flags);
+int repo_read_index_preload(struct repository *,
+			    const struct pathspec *pathspec,
+			    unsigned refresh_flags);
+
+#endif /* PRELOAD_INDEX_H */
diff --git a/read-cache.c b/read-cache.c
index e1016ae0317..3fad839fb6f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@
 #include "mem-pool.h"
 #include "name-hash.h"
 #include "object-name.h"
+#include "preload-index.h"
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/repository.h b/repository.h
index 1a13ff28677..f81228bcfb5 100644
--- a/repository.h
+++ b/repository.h
@@ -220,9 +220,6 @@ int repo_hold_locked_index(struct repository *repo,
 			   struct lock_file *lf,
 			   int flags);
 
-int repo_read_index_preload(struct repository *,
-			    const struct pathspec *pathspec,
-			    unsigned refresh_flags);
 int repo_read_index_unmerged(struct repository *);
 /*
  * Opportunistically update the index but do not complain if we can't.
-- 
gitgitgadget


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

* [PATCH v3 13/28] diff.h: move declaration for global in diff.c from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (11 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 12/28] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 14/28] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
                       ` (15 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h | 3 ---
 diff.h  | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index b79802a4639..08f6fbd801d 100644
--- a/cache.h
+++ b/cache.h
@@ -523,9 +523,6 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, int include_sparse,
 		       int flags);
 
-/* diff.c */
-extern int diff_auto_refresh_index;
-
 /* ls-files */
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/diff.h b/diff.h
index 3a7a9e8b888..29a9cd217c2 100644
--- a/diff.h
+++ b/diff.h
@@ -694,4 +694,6 @@ void print_stat_summary(FILE *fp, int files,
 			int insertions, int deletions);
 void setup_diff_pager(struct diff_options *);
 
+extern int diff_auto_refresh_index;
+
 #endif /* DIFF_H */
-- 
gitgitgadget


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

* [PATCH v3 14/28] merge.h: move declarations for merge.c from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (12 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 13/28] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 15/28] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
                       ` (14 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/merge.c |  1 +
 builtin/pull.c  |  1 +
 cache.h         | 11 -----------
 merge.c         |  1 +
 merge.h         | 17 +++++++++++++++++
 sequencer.c     |  1 +
 6 files changed, 21 insertions(+), 11 deletions(-)
 create mode 100644 merge.h

diff --git a/builtin/merge.c b/builtin/merge.c
index 8da3e46abb0..6e8f7b9bb53 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -37,6 +37,7 @@
 #include "color.h"
 #include "rerere.h"
 #include "help.h"
+#include "merge.h"
 #include "merge-recursive.h"
 #include "merge-ort-wrappers.h"
 #include "resolve-undo.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 967368ebc65..f9ddc94ba9a 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
+#include "merge.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
diff --git a/cache.h b/cache.h
index 08f6fbd801d..5b690b80a16 100644
--- a/cache.h
+++ b/cache.h
@@ -527,15 +527,4 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
 
-/* merge.c */
-struct commit_list;
-int try_merge_command(struct repository *r,
-		const char *strategy, size_t xopts_nr,
-		const char **xopts, struct commit_list *common,
-		const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(struct repository *r,
-			  const struct object_id *from,
-			  const struct object_id *to,
-			  int overwrite_ignore);
-
 #endif /* CACHE_H */
diff --git a/merge.c b/merge.c
index 10aaec3a6c1..fade6b203b3 100644
--- a/merge.c
+++ b/merge.c
@@ -4,6 +4,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
+#include "merge.h"
 #include "commit.h"
 #include "run-command.h"
 #include "resolve-undo.h"
diff --git a/merge.h b/merge.h
new file mode 100644
index 00000000000..21ac7ef2f13
--- /dev/null
+++ b/merge.h
@@ -0,0 +1,17 @@
+#ifndef MERGE_H
+#define MERGE_H
+
+struct commit_list;
+struct object_id;
+struct repository;
+
+int try_merge_command(struct repository *r,
+		const char *strategy, size_t xopts_nr,
+		const char **xopts, struct commit_list *common,
+		const char *head_arg, struct commit_list *remotes);
+int checkout_fast_forward(struct repository *r,
+			  const struct object_id *from,
+			  const struct object_id *to,
+			  int overwrite_ignore);
+
+#endif /* MERGE_H */
diff --git a/sequencer.c b/sequencer.c
index cae9c75a54e..ec4a2e80a10 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -25,6 +25,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "rerere.h"
+#include "merge.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
-- 
gitgitgadget


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

* [PATCH v3 15/28] repository.h: move declaration of the_index from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (13 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 14/28] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 16/28] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
                       ` (13 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

the_index is a global variable defined in repository.c; as such, its
declaration feels better suited living in repository.h rather than
cache.h.  Move it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 cache.h                          | 4 ----
 repository.h                     | 3 +++
 t/helper/test-dump-split-index.c | 1 +
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cache.h b/cache.h
index 5b690b80a16..11882897741 100644
--- a/cache.h
+++ b/cache.h
@@ -312,10 +312,6 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
 void prefetch_cache_entries(const struct index_state *istate,
 			    must_prefetch_predicate must_prefetch);
 
-#ifdef USE_THE_INDEX_VARIABLE
-extern struct index_state the_index;
-#endif
-
 /* Initialize and use the cache information */
 struct lock_file;
 int do_read_index(struct index_state *istate, const char *path,
diff --git a/repository.h b/repository.h
index f81228bcfb5..763794880ed 100644
--- a/repository.h
+++ b/repository.h
@@ -169,6 +169,9 @@ struct repository {
 };
 
 extern struct repository *the_repository;
+#ifdef USE_THE_INDEX_VARIABLE
+extern struct index_state the_index;
+#endif
 
 /*
  * Define a custom repository layout. Any field can be NULL, which
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index d1badd71126..63fde9157c4 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 "repository.h"
 #include "setup.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
-- 
gitgitgadget


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

* [PATCH v3 16/28] read-cache*.h: move declarations for read-cache.c functions from cache.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (14 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 15/28] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 17/28] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
                       ` (12 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

For the functions defined in read-cache.c, move their declarations from
cache.h to a new header, read-cache-ll.h.  Also move some related inline
functions from cache.h to read-cache.h.  The purpose of the
read-cache-ll.h/read-cache.h split is that about 70% of the sites don't
need the inline functions and the extra headers they include.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                    |   1 +
 add-patch.c                          |   1 +
 apply.c                              |   1 +
 attr.c                               |   1 +
 blame.c                              |   1 +
 builtin/add.c                        |   1 +
 builtin/checkout--worker.c           |   1 +
 builtin/checkout-index.c             |   1 +
 builtin/checkout.c                   |   1 +
 builtin/clean.c                      |   1 +
 builtin/commit.c                     |   1 +
 builtin/describe.c                   |   1 +
 builtin/diff-tree.c                  |   1 +
 builtin/diff.c                       |   1 +
 builtin/difftool.c                   |   1 +
 builtin/fsck.c                       |   1 +
 builtin/grep.c                       |   1 +
 builtin/ls-files.c                   |   1 +
 builtin/merge-index.c                |   1 +
 builtin/mv.c                         |   1 +
 builtin/pull.c                       |   1 +
 builtin/rev-parse.c                  |   1 +
 builtin/rm.c                         |   1 +
 builtin/stash.c                      |   1 +
 builtin/submodule--helper.c          |   1 +
 builtin/update-index.c               |   1 +
 builtin/worktree.c                   |   1 +
 cache-tree.c                         |   1 +
 cache.h                              | 520 ---------------------------
 compat/precompose_utf8.c             |   1 +
 compat/sha1-chunked.c                |   1 +
 config.c                             |   1 +
 convert.c                            |   1 +
 diff-lib.c                           |   1 +
 diff.c                               |   1 +
 diffcore-break.c                     |   3 +-
 environment.h                        |   3 +-
 fsmonitor.h                          |   2 +
 git.c                                |   1 +
 hash-lookup.c                        |   1 +
 merge-ort-wrappers.c                 |   1 +
 merge-ort.c                          |   1 +
 name-hash.c                          |   2 +
 object-name.c                        |   1 +
 oidmap.h                             |   1 +
 parallel-checkout.c                  |   1 +
 pathspec.c                           |   1 +
 preload-index.c                      |   1 +
 read-cache-ll.h                      | 481 +++++++++++++++++++++++++
 read-cache.c                         |   1 +
 read-cache.h                         |  45 +++
 repository.c                         |   1 +
 rerere.c                             |   1 +
 resolve-undo.c                       |   1 +
 revision.c                           |   1 +
 split-index.c                        |   1 +
 submodule.c                          |   1 +
 t/helper/test-cache-tree.c           |   1 +
 t/helper/test-dump-cache-tree.c      |   1 +
 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-hash-speed.c           |   1 +
 t/helper/test-index-version.c        |   1 +
 t/helper/test-lazy-init-name-hash.c  |   1 +
 t/helper/test-path-utils.c           |   1 +
 t/helper/test-read-cache.c           |   1 +
 t/helper/test-scrap-cache-tree.c     |   1 +
 t/helper/test-sha1.c                 |   1 +
 t/helper/test-sha256.c               |   1 +
 t/helper/test-strcmp-offset.c        |   1 +
 t/helper/test-write-cache.c          |   1 +
 unpack-trees.c                       |   1 +
 unpack-trees.h                       |   2 +-
 wt-status.c                          |   1 +
 77 files changed, 603 insertions(+), 524 deletions(-)
 create mode 100644 read-cache-ll.h
 create mode 100644 read-cache.h

diff --git a/add-interactive.c b/add-interactive.c
index 99f7dc3b0d1..a9671e33491 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "preload-index.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 8d770d203ff..7d4d298286d 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/apply.c b/apply.c
index 3da33bb88fd..f056c8f3bb9 100644
--- a/apply.c
+++ b/apply.c
@@ -28,6 +28,7 @@
 #include "object-file.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "read-cache.h"
 #include "rerere.h"
 #include "apply.h"
 #include "entry.h"
diff --git a/attr.c b/attr.c
index ddf2b0cbc2e..57c813d8e77 100644
--- a/attr.c
+++ b/attr.c
@@ -16,6 +16,7 @@
 #include "gettext.h"
 #include "utf8.h"
 #include "quote.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "object-store.h"
 #include "setup.h"
diff --git a/blame.c b/blame.c
index 58dd58b6c97..a29ae7c14b2 100644
--- a/blame.c
+++ b/blame.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "tag.h"
 #include "trace2.h"
diff --git a/builtin/add.c b/builtin/add.c
index 8397be4f8de..9fe6b6ce290 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -20,6 +20,7 @@
 #include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "read-cache.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index 2120dd1d300..c655dc4b136 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -6,6 +6,7 @@
 #include "parallel-checkout.h"
 #include "parse-options.h"
 #include "pkt-line.h"
+#include "read-cache-ll.h"
 
 static void packet_to_pc_item(const char *buffer, int len,
 			      struct parallel_checkout_item *pc_item)
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index b1cd8bef264..f62f13f2b53 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -16,6 +16,7 @@
 #include "parse-options.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "sparse-index.h"
 
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2d72a742d9d..09b84156492 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -21,6 +21,7 @@
 #include "object-store.h"
 #include "parse-options.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "refs.h"
 #include "remote.h"
 #include "resolve-undo.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 78852d28cec..49c7af45b03 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "string-list.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index fa769045c88..5be05c9d9e1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -31,6 +31,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "unpack-trees.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 55b4baaa223..f1be7c36948 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -13,6 +13,7 @@
 #include "exec-cmd.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "diff.h"
 #include "hashmap.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 0b02c62b85e..5a1e5d6df7c 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -8,6 +8,7 @@
 #include "log-tree.h"
 #include "builtin.h"
 #include "submodule.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "tree.h"
 
diff --git a/builtin/diff.c b/builtin/diff.c
index 967550739a6..a9ce701ff97 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -17,6 +17,7 @@
 #include "diff-merges.h"
 #include "diffcore.h"
 #include "preload-index.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2c27a59e04a..88809976c53 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -23,6 +23,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "sparse-index.h"
 #include "strvec.h"
 #include "strbuf.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 7134596d218..e8c5fbca58f 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -22,6 +22,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "replace-object.h"
 #include "resolve-undo.h"
 #include "run-command.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index b86c754defb..0d567575890 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -31,6 +31,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pager.h"
+#include "read-cache-ll.h"
 #include "write-or-die.h"
 
 static const char *grep_prefix;
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 45b3b0ce5d8..d8c1c62bcb0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -21,6 +21,7 @@
 #include "resolve-undo.h"
 #include "string-list.h"
 #include "pathspec.h"
+#include "read-cache.h"
 #include "run-command.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index d16e8aa414b..270d5f644ac 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,6 +1,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "hex.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "run-command.h"
 #include "sparse-index.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index e058b574654..ae462bd7d41 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -19,6 +19,7 @@
 #include "cache-tree.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index f9ddc94ba9a..8aeb5abc7fb 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -20,6 +20,7 @@
 #include "oid-array.h"
 #include "remote.h"
 #include "dir.h"
+#include "read-cache-ll.h"
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 852e49e3403..ad93e5fad88 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -18,6 +18,7 @@
 #include "object-name.h"
 #include "parse-options.h"
 #include "diff.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "setup.h"
 #include "split-index.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 377a0f66ad8..463eeabceaa 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -16,6 +16,7 @@
 #include "tree-walk.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "string-list.h"
 #include "setup.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index 06527ee8471..d3d5bb95e26 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -18,6 +18,7 @@
 #include "dir.h"
 #include "entry.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "rerere.h"
 #include "revision.h"
 #include "setup.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 597e780a93a..86324b829a7 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -13,6 +13,7 @@
 #include "pathspec.h"
 #include "preload-index.h"
 #include "dir.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "submodule.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 47dc9b626ef..484a307df50 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -22,6 +22,7 @@
 #include "parse-options.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "setup.h"
 #include "sparse-index.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index f3180463be2..3c3d97ad5b0 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -13,6 +13,7 @@
 #include "parse-options.h"
 #include "strvec.h"
 #include "branch.h"
+#include "read-cache-ll.h"
 #include "refs.h"
 #include "repository.h"
 #include "run-command.h"
diff --git a/cache-tree.c b/cache-tree.c
index ebfe649b330..153217b47ff 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -9,6 +9,7 @@
 #include "bulk-checkin.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "sparse-index.h"
diff --git a/cache.h b/cache.h
index 11882897741..9b4e8d16874 100644
--- a/cache.h
+++ b/cache.h
@@ -2,525 +2,5 @@
 #define CACHE_H
 
 #include "git-compat-util.h"
-#include "strbuf.h"
-#include "hashmap.h"
-#include "pathspec.h"
-#include "object.h"
-#include "statinfo.h"
-
-/*
- * Basic data structures for the directory cache
- */
-
-#define CACHE_SIGNATURE 0x44495243	/* "DIRC" */
-struct cache_header {
-	uint32_t hdr_signature;
-	uint32_t hdr_version;
-	uint32_t hdr_entries;
-};
-
-#define INDEX_FORMAT_LB 2
-#define INDEX_FORMAT_UB 4
-
-struct cache_entry {
-	struct hashmap_entry ent;
-	struct stat_data ce_stat_data;
-	unsigned int ce_mode;
-	unsigned int ce_flags;
-	unsigned int mem_pool_allocated;
-	unsigned int ce_namelen;
-	unsigned int index;	/* for link extension */
-	struct object_id oid;
-	char name[FLEX_ARRAY]; /* more */
-};
-
-#define CE_STAGEMASK (0x3000)
-#define CE_EXTENDED  (0x4000)
-#define CE_VALID     (0x8000)
-#define CE_STAGESHIFT 12
-
-/*
- * Range 0xFFFF0FFF in ce_flags is divided into
- * two parts: in-memory flags and on-disk ones.
- * Flags in CE_EXTENDED_FLAGS will get saved on-disk
- * if you want to save a new flag, add it in
- * CE_EXTENDED_FLAGS
- *
- * In-memory only flags
- */
-#define CE_UPDATE            (1 << 16)
-#define CE_REMOVE            (1 << 17)
-#define CE_UPTODATE          (1 << 18)
-#define CE_ADDED             (1 << 19)
-
-#define CE_HASHED            (1 << 20)
-#define CE_FSMONITOR_VALID   (1 << 21)
-#define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
-#define CE_CONFLICTED        (1 << 23)
-
-#define CE_UNPACKED          (1 << 24)
-#define CE_NEW_SKIP_WORKTREE (1 << 25)
-
-/* used to temporarily mark paths matched by pathspecs */
-#define CE_MATCHED           (1 << 26)
-
-#define CE_UPDATE_IN_BASE    (1 << 27)
-#define CE_STRIP_NAME        (1 << 28)
-
-/*
- * Extended on-disk flags
- */
-#define CE_INTENT_TO_ADD     (1 << 29)
-#define CE_SKIP_WORKTREE     (1 << 30)
-/* CE_EXTENDED2 is for future extension */
-#define CE_EXTENDED2         (1U << 31)
-
-#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
-
-/*
- * Safeguard to avoid saving wrong flags:
- *  - CE_EXTENDED2 won't get saved until its semantic is known
- *  - Bits in 0x0000FFFF have been saved in ce_flags already
- *  - Bits in 0x003F0000 are currently in-memory flags
- */
-#if CE_EXTENDED_FLAGS & 0x803FFFFF
-#error "CE_EXTENDED_FLAGS out of range"
-#endif
-
-/* Forward structure decls */
-struct pathspec;
-struct tree;
-
-/*
- * Copy the sha1 and stat state of a cache entry from one to
- * another. But we never change the name, or the hash state!
- */
-static inline void copy_cache_entry(struct cache_entry *dst,
-				    const struct cache_entry *src)
-{
-	unsigned int state = dst->ce_flags & CE_HASHED;
-	int mem_pool_allocated = dst->mem_pool_allocated;
-
-	/* Don't copy hash chain and name */
-	memcpy(&dst->ce_stat_data, &src->ce_stat_data,
-			offsetof(struct cache_entry, name) -
-			offsetof(struct cache_entry, ce_stat_data));
-
-	/* Restore the hash state */
-	dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
-
-	/* Restore the mem_pool_allocated flag */
-	dst->mem_pool_allocated = mem_pool_allocated;
-}
-
-static inline unsigned create_ce_flags(unsigned stage)
-{
-	return (stage << CE_STAGESHIFT);
-}
-
-#define ce_namelen(ce) ((ce)->ce_namelen)
-#define ce_size(ce) cache_entry_size(ce_namelen(ce))
-#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
-#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
-#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
-#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
-#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
-
-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
-					     unsigned int mode)
-{
-	extern int trust_executable_bit, has_symlinks;
-	if (!has_symlinks && S_ISREG(mode) &&
-	    ce && S_ISLNK(ce->ce_mode))
-		return ce->ce_mode;
-	if (!trust_executable_bit && S_ISREG(mode)) {
-		if (ce && S_ISREG(ce->ce_mode))
-			return ce->ce_mode;
-		return create_ce_mode(0666);
-	}
-	return create_ce_mode(mode);
-}
-static inline int ce_to_dtype(const struct cache_entry *ce)
-{
-	unsigned ce_mode = ntohl(ce->ce_mode);
-	if (S_ISREG(ce_mode))
-		return DT_REG;
-	else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
-		return DT_DIR;
-	else if (S_ISLNK(ce_mode))
-		return DT_LNK;
-	else
-		return DT_UNKNOWN;
-}
-
-static inline int ce_path_match(struct index_state *istate,
-				const struct cache_entry *ce,
-				const struct pathspec *pathspec,
-				char *seen)
-{
-	return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
-			      S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
-}
-
-#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
-
-#define SOMETHING_CHANGED	(1 << 0) /* unclassified changes go here */
-#define CE_ENTRY_CHANGED	(1 << 1)
-#define CE_ENTRY_REMOVED	(1 << 2)
-#define CE_ENTRY_ADDED		(1 << 3)
-#define RESOLVE_UNDO_CHANGED	(1 << 4)
-#define CACHE_TREE_CHANGED	(1 << 5)
-#define SPLIT_INDEX_ORDERED	(1 << 6)
-#define UNTRACKED_CHANGED	(1 << 7)
-#define FSMONITOR_CHANGED	(1 << 8)
-
-struct split_index;
-struct untracked_cache;
-struct progress;
-struct pattern_list;
-
-enum sparse_index_mode {
-	/*
-	 * There are no sparse directories in the index at all.
-	 *
-	 * Repositories that don't use cone-mode sparse-checkout will
-	 * always have their indexes in this mode.
-	 */
-	INDEX_EXPANDED = 0,
-
-	/*
-	 * The index has already been collapsed to sparse directories
-	 * whereever possible.
-	 */
-	INDEX_COLLAPSED,
-
-	/*
-	 * The sparse directories that exist are outside the
-	 * sparse-checkout boundary, but it is possible that some file
-	 * entries could collapse to sparse directory entries.
-	 */
-	INDEX_PARTIALLY_SPARSE,
-};
-
-struct index_state {
-	struct cache_entry **cache;
-	unsigned int version;
-	unsigned int cache_nr, cache_alloc, cache_changed;
-	struct string_list *resolve_undo;
-	struct cache_tree *cache_tree;
-	struct split_index *split_index;
-	struct cache_time timestamp;
-	unsigned name_hash_initialized : 1,
-		 initialized : 1,
-		 drop_cache_tree : 1,
-		 updated_workdir : 1,
-		 updated_skipworktree : 1,
-		 fsmonitor_has_run_once : 1;
-	enum sparse_index_mode sparse_index;
-	struct hashmap name_hash;
-	struct hashmap dir_hash;
-	struct object_id oid;
-	struct untracked_cache *untracked;
-	char *fsmonitor_last_update;
-	struct ewah_bitmap *fsmonitor_dirty;
-	struct mem_pool *ce_mem_pool;
-	struct progress *progress;
-	struct repository *repo;
-	struct pattern_list *sparse_checkout_patterns;
-};
-
-/**
- * A "struct index_state istate" must be initialized with
- * INDEX_STATE_INIT or the corresponding index_state_init().
- *
- * If the variable won't be used again, use release_index() to free()
- * its resources. If it needs to be used again use discard_index(),
- * which does the same thing, but will use use index_state_init() at
- * the end. The discard_index() will use its own "istate->repo" as the
- * "r" argument to index_state_init() in that case.
- */
-#define INDEX_STATE_INIT(r) { \
-	.repo = (r), \
-}
-void index_state_init(struct index_state *istate, struct repository *r);
-void release_index(struct index_state *istate);
-
-/* Cache entry creation and cleanup */
-
-/*
- * Create cache_entry intended for use in the specified index. Caller
- * is responsible for discarding the cache_entry with
- * `discard_cache_entry`.
- */
-struct cache_entry *make_cache_entry(struct index_state *istate,
-				     unsigned int mode,
-				     const struct object_id *oid,
-				     const char *path,
-				     int stage,
-				     unsigned int refresh_options);
-
-struct cache_entry *make_empty_cache_entry(struct index_state *istate,
-					   size_t name_len);
-
-/*
- * Create a cache_entry that is not intended to be added to an index. If
- * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
- * pool. Caller is responsible for discarding "loose" entries with
- * `discard_cache_entry()` and the memory pool with
- * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
- */
-struct cache_entry *make_transient_cache_entry(unsigned int mode,
-					       const struct object_id *oid,
-					       const char *path,
-					       int stage,
-					       struct mem_pool *ce_mem_pool);
-
-struct cache_entry *make_empty_transient_cache_entry(size_t len,
-						     struct mem_pool *ce_mem_pool);
-
-/*
- * Discard cache entry.
- */
-void discard_cache_entry(struct cache_entry *ce);
-
-/*
- * Check configuration if we should perform extra validation on cache
- * entries.
- */
-int should_validate_cache_entries(void);
-
-/*
- * Duplicate a cache_entry. Allocate memory for the new entry from a
- * memory_pool. Takes into account cache_entry fields that are meant
- * for managing the underlying memory allocation of the cache_entry.
- */
-struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
-
-/*
- * Validate the cache entries in the index.  This is an internal
- * consistency check that the cache_entry structs are allocated from
- * the expected memory pool.
- */
-void validate_cache_entries(const struct index_state *istate);
-
-/*
- * Bulk prefetch all missing cache entries that are not GITLINKs and that match
- * the given predicate. This function should only be called if
- * repo_has_promisor_remote() returns true.
- */
-typedef int (*must_prefetch_predicate)(const struct cache_entry *);
-void prefetch_cache_entries(const struct index_state *istate,
-			    must_prefetch_predicate must_prefetch);
-
-/* Initialize and use the cache information */
-struct lock_file;
-int do_read_index(struct index_state *istate, const char *path,
-		  int must_exist); /* for testting only! */
-int read_index_from(struct index_state *, const char *path,
-		    const char *gitdir);
-int is_index_unborn(struct index_state *);
-
-/* For use with `write_locked_index()`. */
-#define COMMIT_LOCK		(1 << 0)
-#define SKIP_IF_UNCHANGED	(1 << 1)
-
-/*
- * Write the index while holding an already-taken lock. Close the lock,
- * and if `COMMIT_LOCK` is given, commit it.
- *
- * Unless a split index is in use, write the index into the lockfile.
- *
- * With a split index, write the shared index to a temporary file,
- * adjust its permissions and rename it into place, then write the
- * split index to the lockfile. If the temporary file for the shared
- * index cannot be created, fall back to the behavior described in
- * the previous paragraph.
- *
- * With `COMMIT_LOCK`, the lock is always committed or rolled back.
- * Without it, the lock is closed, but neither committed nor rolled
- * back.
- *
- * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
- * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
- */
-int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
-
-void discard_index(struct index_state *);
-void move_index_extensions(struct index_state *dst, struct index_state *src);
-int unmerged_index(const struct index_state *);
-
-/**
- * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
- * compares istate to HEAD.  If tree is NULL and on an unborn branch,
- * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
- * provided, the space-separated list of files that differ will be appended
- * to it.
- */
-int repo_index_has_changes(struct repository *repo,
-			   struct tree *tree,
-			   struct strbuf *sb);
-
-int verify_path(const char *path, unsigned mode);
-int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-
-/*
- * Searches for an entry defined by name and namelen in the given index.
- * If the return value is positive (including 0) it is the position of an
- * exact match. If the return value is negative, the negated value minus 1
- * is the position where the entry would be inserted.
- * Example: The current index consists of these files and its stages:
- *
- *   b#0, d#0, f#1, f#3
- *
- * index_name_pos(&index, "a", 1) -> -1
- * index_name_pos(&index, "b", 1) ->  0
- * index_name_pos(&index, "c", 1) -> -2
- * index_name_pos(&index, "d", 1) ->  1
- * index_name_pos(&index, "e", 1) -> -3
- * index_name_pos(&index, "f", 1) -> -3
- * index_name_pos(&index, "g", 1) -> -5
- */
-int index_name_pos(struct index_state *, const char *name, int namelen);
-
-/*
- * Like index_name_pos, returns the position of an entry of the given name in
- * the index if one exists, otherwise returns a negative value where the negated
- * value minus 1 is the position where the index entry would be inserted. Unlike
- * index_name_pos, however, a sparse index is not expanded to find an entry
- * inside a sparse directory.
- */
-int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
-
-/*
- * Determines whether an entry with the given name exists within the
- * given index. The return value is 1 if an exact match is found, otherwise
- * it is 0. Note that, unlike index_name_pos, this function does not expand
- * the index if it is sparse. If an item exists within the full index but it
- * is contained within a sparse directory (and not in the sparse index), 0 is
- * returned.
- */
-int index_entry_exists(struct index_state *, const char *name, int namelen);
-
-/*
- * Some functions return the negative complement of an insert position when a
- * precise match was not found but a position was found where the entry would
- * need to be inserted. This helper protects that logic from any integer
- * underflow.
- */
-static inline int index_pos_to_insert_pos(uintmax_t pos)
-{
-	if (pos > INT_MAX)
-		die("overflow: -1 - %"PRIuMAX, pos);
-	return -1 - (int)pos;
-}
-
-#define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
-#define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
-#define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
-#define ADD_CACHE_JUST_APPEND 8		/* Append only */
-#define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
-#define ADD_CACHE_KEEP_CACHE_TREE 32	/* Do not invalidate cache-tree */
-#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
-int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
-void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
-
-/* Remove entry, return true if there are more entries to go. */
-int remove_index_entry_at(struct index_state *, int pos);
-
-void remove_marked_cache_entries(struct index_state *istate, int invalidate);
-int remove_file_from_index(struct index_state *, const char *path);
-#define ADD_CACHE_VERBOSE 1
-#define ADD_CACHE_PRETEND 2
-#define ADD_CACHE_IGNORE_ERRORS	4
-#define ADD_CACHE_IGNORE_REMOVAL 8
-#define ADD_CACHE_INTENT 16
-/*
- * These two are used to add the contents of the file at path
- * to the index, marking the working tree up-to-date by storing
- * the cached stat info in the resulting cache entry.  A caller
- * that has already run lstat(2) on the path can call
- * add_to_index(), and all others can call add_file_to_index();
- * the latter will do necessary lstat(2) internally before
- * calling the former.
- */
-int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
-int add_file_to_index(struct index_state *, const char *path, int flags);
-
-int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
-int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
-void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
-int index_name_is_other(struct index_state *, const char *, int);
-void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
-
-/* do stat comparison even if CE_VALID is true */
-#define CE_MATCH_IGNORE_VALID		01
-/* do not check the contents but report dirty on racily-clean entries */
-#define CE_MATCH_RACY_IS_DIRTY		02
-/* do stat comparison even if CE_SKIP_WORKTREE is true */
-#define CE_MATCH_IGNORE_SKIP_WORKTREE	04
-/* ignore non-existent files during stat update  */
-#define CE_MATCH_IGNORE_MISSING		0x08
-/* enable stat refresh */
-#define CE_MATCH_REFRESH		0x10
-/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
-#define CE_MATCH_IGNORE_FSMONITOR 0X20
-int is_racy_timestamp(const struct index_state *istate,
-		      const struct cache_entry *ce);
-int has_racy_timestamp(struct index_state *istate);
-int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-
-int match_stat_data_racy(const struct index_state *istate,
-			 const struct stat_data *sd, struct stat *st);
-
-void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
-
-#define REFRESH_REALLY                   (1 << 0) /* ignore_valid */
-#define REFRESH_UNMERGED                 (1 << 1) /* allow unmerged */
-#define REFRESH_QUIET                    (1 << 2) /* be quiet about it */
-#define REFRESH_IGNORE_MISSING           (1 << 3) /* ignore non-existent */
-#define REFRESH_IGNORE_SUBMODULES        (1 << 4) /* ignore submodules */
-#define REFRESH_IN_PORCELAIN             (1 << 5) /* user friendly output, not "needs update" */
-#define REFRESH_PROGRESS                 (1 << 6) /* show progress bar if stderr is tty */
-#define REFRESH_IGNORE_SKIP_WORKTREE     (1 << 7) /* ignore skip_worktree entries */
-int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
-/*
- * Refresh the index and write it to disk.
- *
- * 'refresh_flags' is passed directly to 'refresh_index()', while
- * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
- * the lockfile is always either committed or rolled back.
- *
- * If 'gentle' is passed, errors locking the index are ignored.
- *
- * Return 1 if refreshing the index returns an error, -1 if writing
- * the index to disk fails, 0 on success.
- *
- * Note that if refreshing the index returns an error, we still write
- * out the index (unless locking fails).
- */
-int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg);
-
-struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
-
-void set_alternate_index_output(const char *);
-
-extern int verify_index_checksum;
-extern int verify_ce_order;
-
-int cmp_cache_name_compare(const void *a_, const void *b_);
-
-/* add */
-/*
- * return 0 if success, 1 - if addition of a file failed and
- * ADD_FILES_IGNORE_ERRORS was specified in flags
- */
-int add_files_to_cache(struct repository *repo, const char *prefix,
-		       const struct pathspec *pathspec, int include_sparse,
-		       int flags);
-
-/* ls-files */
-void overlay_tree_on_index(struct index_state *istate,
-			   const char *tree_name, const char *prefix);
 
 #endif /* CACHE_H */
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index a4d11376ba5..fb08475bc64 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -10,6 +10,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "path.h"
+#include "strbuf.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 6adfcfd5405..56729d92dcf 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "hash-ll.h"
 
 int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
 {
diff --git a/config.c b/config.c
index b79baf83e35..06e6cc6f1ec 100644
--- a/config.c
+++ b/config.c
@@ -33,6 +33,7 @@
 #include "replace-object.h"
 #include "refs.h"
 #include "setup.h"
+#include "strvec.h"
 #include "trace2.h"
 #include "worktree.h"
 #include "ws.h"
diff --git a/convert.c b/convert.c
index 7cf7bd0c883..236d5e3dc25 100644
--- a/convert.c
+++ b/convert.c
@@ -9,6 +9,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
+#include "read-cache-ll.h"
 #include "sigchain.h"
 #include "pkt-line.h"
 #include "sub-process.h"
diff --git a/diff-lib.c b/diff-lib.c
index 60e979dc1bd..36cd66ea237 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "read-cache.h"
 #include "revision.h"
 #include "cache-tree.h"
 #include "unpack-trees.h"
diff --git a/diff.c b/diff.c
index 07f140b425f..61b4dc61e1e 100644
--- a/diff.c
+++ b/diff.c
@@ -39,6 +39,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "strmap.h"
 #include "ws.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 5462420bbbe..4909dc088e6 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,9 +1,10 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "object.h"
 #include "promisor-remote.h"
 
 static int should_break(struct repository *r,
diff --git a/environment.h b/environment.h
index a63f0c6a24f..6eca4712e1e 100644
--- a/environment.h
+++ b/environment.h
@@ -1,9 +1,8 @@
 #ifndef ENVIRONMENT_H
 #define ENVIRONMENT_H
 
-#include "strvec.h"
-
 struct repository;
+struct strvec;
 
 /*
  * The character that begins a commented line in user-editable file
diff --git a/fsmonitor.h b/fsmonitor.h
index c67e0ebc09b..8b7a521552a 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -4,6 +4,8 @@
 #include "cache.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
+#include "object.h"
+#include "read-cache-ll.h"
 #include "trace.h"
 
 extern struct trace_key trace_fsmonitor;
diff --git a/git.c b/git.c
index 45899be8265..a1a538fc52e 100644
--- a/git.c
+++ b/git.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "help.h"
 #include "pager.h"
+#include "read-cache-ll.h"
 #include "run-command.h"
 #include "alias.h"
 #include "replace-object.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index bb54dfde9c7..8fec8939fd3 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "hash.h"
 #include "hash-lookup.h"
+#include "read-cache-ll.h"
 
 static uint32_t take2(const struct object_id *oid, size_t ofs)
 {
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a5507533009..a0bedcb63bb 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -3,6 +3,7 @@
 #include "hash.h"
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
+#include "read-cache-ll.h"
 #include "tree.h"
 
 #include "commit.h"
diff --git a/merge-ort.c b/merge-ort.c
index 4bff685e456..5512f40d321 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -37,6 +37,7 @@
 #include "object-store.h"
 #include "oid-array.h"
 #include "promisor-remote.h"
+#include "read-cache-ll.h"
 #include "revision.h"
 #include "sparse-index.h"
 #include "strmap.h"
diff --git a/name-hash.c b/name-hash.c
index 52ce47ea394..f2f3564cb20 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -9,6 +9,8 @@
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
+#include "object.h"
+#include "read-cache-ll.h"
 #include "thread-utils.h"
 #include "trace.h"
 #include "trace2.h"
diff --git a/object-name.c b/object-name.c
index 6fc3fa595b8..1eefeef746e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -18,6 +18,7 @@
 #include "packfile.h"
 #include "pretty.h"
 #include "object-store.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/oidmap.h b/oidmap.h
index c1642927fa6..05c673eb7c1 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,6 +1,7 @@
 #ifndef OIDMAP_H
 #define OIDMAP_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 
 /*
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 69d569f3525..2b1439c0c5f 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -8,6 +8,7 @@
 #include "parallel-checkout.h"
 #include "pkt-line.h"
 #include "progress.h"
+#include "read-cache-ll.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "streaming.h"
diff --git a/pathspec.c b/pathspec.c
index 1e57b6c667d..47d172fe414 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "pathspec.h"
 #include "attr.h"
+#include "read-cache.h"
 #include "repository.h"
 #include "setup.h"
 #include "strvec.h"
diff --git a/preload-index.c b/preload-index.c
index c26739debf8..d037a951efa 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "preload-index.h"
 #include "progress.h"
+#include "read-cache.h"
 #include "thread-utils.h"
 #include "repository.h"
 #include "symlinks.h"
diff --git a/read-cache-ll.h b/read-cache-ll.h
new file mode 100644
index 00000000000..9a1a7edc5a2
--- /dev/null
+++ b/read-cache-ll.h
@@ -0,0 +1,481 @@
+#ifndef READ_CACHE_LL_H
+#define READ_CACHE_LL_H
+
+#include "hash-ll.h"
+#include "hashmap.h"
+#include "statinfo.h"
+
+/*
+ * Basic data structures for the directory cache
+ */
+
+#define CACHE_SIGNATURE 0x44495243	/* "DIRC" */
+struct cache_header {
+	uint32_t hdr_signature;
+	uint32_t hdr_version;
+	uint32_t hdr_entries;
+};
+
+#define INDEX_FORMAT_LB 2
+#define INDEX_FORMAT_UB 4
+
+struct cache_entry {
+	struct hashmap_entry ent;
+	struct stat_data ce_stat_data;
+	unsigned int ce_mode;
+	unsigned int ce_flags;
+	unsigned int mem_pool_allocated;
+	unsigned int ce_namelen;
+	unsigned int index;	/* for link extension */
+	struct object_id oid;
+	char name[FLEX_ARRAY]; /* more */
+};
+
+#define CE_STAGEMASK (0x3000)
+#define CE_EXTENDED  (0x4000)
+#define CE_VALID     (0x8000)
+#define CE_STAGESHIFT 12
+
+/*
+ * Range 0xFFFF0FFF in ce_flags is divided into
+ * two parts: in-memory flags and on-disk ones.
+ * Flags in CE_EXTENDED_FLAGS will get saved on-disk
+ * if you want to save a new flag, add it in
+ * CE_EXTENDED_FLAGS
+ *
+ * In-memory only flags
+ */
+#define CE_UPDATE            (1 << 16)
+#define CE_REMOVE            (1 << 17)
+#define CE_UPTODATE          (1 << 18)
+#define CE_ADDED             (1 << 19)
+
+#define CE_HASHED            (1 << 20)
+#define CE_FSMONITOR_VALID   (1 << 21)
+#define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
+#define CE_CONFLICTED        (1 << 23)
+
+#define CE_UNPACKED          (1 << 24)
+#define CE_NEW_SKIP_WORKTREE (1 << 25)
+
+/* used to temporarily mark paths matched by pathspecs */
+#define CE_MATCHED           (1 << 26)
+
+#define CE_UPDATE_IN_BASE    (1 << 27)
+#define CE_STRIP_NAME        (1 << 28)
+
+/*
+ * Extended on-disk flags
+ */
+#define CE_INTENT_TO_ADD     (1 << 29)
+#define CE_SKIP_WORKTREE     (1 << 30)
+/* CE_EXTENDED2 is for future extension */
+#define CE_EXTENDED2         (1U << 31)
+
+#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
+
+/*
+ * Safeguard to avoid saving wrong flags:
+ *  - CE_EXTENDED2 won't get saved until its semantic is known
+ *  - Bits in 0x0000FFFF have been saved in ce_flags already
+ *  - Bits in 0x003F0000 are currently in-memory flags
+ */
+#if CE_EXTENDED_FLAGS & 0x803FFFFF
+#error "CE_EXTENDED_FLAGS out of range"
+#endif
+
+/* Forward structure decls */
+struct pathspec;
+struct tree;
+
+/*
+ * Copy the sha1 and stat state of a cache entry from one to
+ * another. But we never change the name, or the hash state!
+ */
+static inline void copy_cache_entry(struct cache_entry *dst,
+				    const struct cache_entry *src)
+{
+	unsigned int state = dst->ce_flags & CE_HASHED;
+	int mem_pool_allocated = dst->mem_pool_allocated;
+
+	/* Don't copy hash chain and name */
+	memcpy(&dst->ce_stat_data, &src->ce_stat_data,
+			offsetof(struct cache_entry, name) -
+			offsetof(struct cache_entry, ce_stat_data));
+
+	/* Restore the hash state */
+	dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
+
+	/* Restore the mem_pool_allocated flag */
+	dst->mem_pool_allocated = mem_pool_allocated;
+}
+
+static inline unsigned create_ce_flags(unsigned stage)
+{
+	return (stage << CE_STAGESHIFT);
+}
+
+#define ce_namelen(ce) ((ce)->ce_namelen)
+#define ce_size(ce) cache_entry_size(ce_namelen(ce))
+#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
+#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
+#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
+#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
+#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
+
+#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
+
+#define SOMETHING_CHANGED	(1 << 0) /* unclassified changes go here */
+#define CE_ENTRY_CHANGED	(1 << 1)
+#define CE_ENTRY_REMOVED	(1 << 2)
+#define CE_ENTRY_ADDED		(1 << 3)
+#define RESOLVE_UNDO_CHANGED	(1 << 4)
+#define CACHE_TREE_CHANGED	(1 << 5)
+#define SPLIT_INDEX_ORDERED	(1 << 6)
+#define UNTRACKED_CHANGED	(1 << 7)
+#define FSMONITOR_CHANGED	(1 << 8)
+
+struct split_index;
+struct untracked_cache;
+struct progress;
+struct pattern_list;
+
+enum sparse_index_mode {
+	/*
+	 * There are no sparse directories in the index at all.
+	 *
+	 * Repositories that don't use cone-mode sparse-checkout will
+	 * always have their indexes in this mode.
+	 */
+	INDEX_EXPANDED = 0,
+
+	/*
+	 * The index has already been collapsed to sparse directories
+	 * whereever possible.
+	 */
+	INDEX_COLLAPSED,
+
+	/*
+	 * The sparse directories that exist are outside the
+	 * sparse-checkout boundary, but it is possible that some file
+	 * entries could collapse to sparse directory entries.
+	 */
+	INDEX_PARTIALLY_SPARSE,
+};
+
+struct index_state {
+	struct cache_entry **cache;
+	unsigned int version;
+	unsigned int cache_nr, cache_alloc, cache_changed;
+	struct string_list *resolve_undo;
+	struct cache_tree *cache_tree;
+	struct split_index *split_index;
+	struct cache_time timestamp;
+	unsigned name_hash_initialized : 1,
+		 initialized : 1,
+		 drop_cache_tree : 1,
+		 updated_workdir : 1,
+		 updated_skipworktree : 1,
+		 fsmonitor_has_run_once : 1;
+	enum sparse_index_mode sparse_index;
+	struct hashmap name_hash;
+	struct hashmap dir_hash;
+	struct object_id oid;
+	struct untracked_cache *untracked;
+	char *fsmonitor_last_update;
+	struct ewah_bitmap *fsmonitor_dirty;
+	struct mem_pool *ce_mem_pool;
+	struct progress *progress;
+	struct repository *repo;
+	struct pattern_list *sparse_checkout_patterns;
+};
+
+/**
+ * A "struct index_state istate" must be initialized with
+ * INDEX_STATE_INIT or the corresponding index_state_init().
+ *
+ * If the variable won't be used again, use release_index() to free()
+ * its resources. If it needs to be used again use discard_index(),
+ * which does the same thing, but will use use index_state_init() at
+ * the end. The discard_index() will use its own "istate->repo" as the
+ * "r" argument to index_state_init() in that case.
+ */
+#define INDEX_STATE_INIT(r) { \
+	.repo = (r), \
+}
+void index_state_init(struct index_state *istate, struct repository *r);
+void release_index(struct index_state *istate);
+
+/* Cache entry creation and cleanup */
+
+/*
+ * Create cache_entry intended for use in the specified index. Caller
+ * is responsible for discarding the cache_entry with
+ * `discard_cache_entry`.
+ */
+struct cache_entry *make_cache_entry(struct index_state *istate,
+				     unsigned int mode,
+				     const struct object_id *oid,
+				     const char *path,
+				     int stage,
+				     unsigned int refresh_options);
+
+struct cache_entry *make_empty_cache_entry(struct index_state *istate,
+					   size_t name_len);
+
+/*
+ * Create a cache_entry that is not intended to be added to an index. If
+ * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
+ * pool. Caller is responsible for discarding "loose" entries with
+ * `discard_cache_entry()` and the memory pool with
+ * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
+ */
+struct cache_entry *make_transient_cache_entry(unsigned int mode,
+					       const struct object_id *oid,
+					       const char *path,
+					       int stage,
+					       struct mem_pool *ce_mem_pool);
+
+struct cache_entry *make_empty_transient_cache_entry(size_t len,
+						     struct mem_pool *ce_mem_pool);
+
+/*
+ * Discard cache entry.
+ */
+void discard_cache_entry(struct cache_entry *ce);
+
+/*
+ * Check configuration if we should perform extra validation on cache
+ * entries.
+ */
+int should_validate_cache_entries(void);
+
+/*
+ * Duplicate a cache_entry. Allocate memory for the new entry from a
+ * memory_pool. Takes into account cache_entry fields that are meant
+ * for managing the underlying memory allocation of the cache_entry.
+ */
+struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
+
+/*
+ * Validate the cache entries in the index.  This is an internal
+ * consistency check that the cache_entry structs are allocated from
+ * the expected memory pool.
+ */
+void validate_cache_entries(const struct index_state *istate);
+
+/*
+ * Bulk prefetch all missing cache entries that are not GITLINKs and that match
+ * the given predicate. This function should only be called if
+ * repo_has_promisor_remote() returns true.
+ */
+typedef int (*must_prefetch_predicate)(const struct cache_entry *);
+void prefetch_cache_entries(const struct index_state *istate,
+			    must_prefetch_predicate must_prefetch);
+
+/* Initialize and use the cache information */
+struct lock_file;
+int do_read_index(struct index_state *istate, const char *path,
+		  int must_exist); /* for testting only! */
+int read_index_from(struct index_state *, const char *path,
+		    const char *gitdir);
+int is_index_unborn(struct index_state *);
+
+/* For use with `write_locked_index()`. */
+#define COMMIT_LOCK		(1 << 0)
+#define SKIP_IF_UNCHANGED	(1 << 1)
+
+/*
+ * Write the index while holding an already-taken lock. Close the lock,
+ * and if `COMMIT_LOCK` is given, commit it.
+ *
+ * Unless a split index is in use, write the index into the lockfile.
+ *
+ * With a split index, write the shared index to a temporary file,
+ * adjust its permissions and rename it into place, then write the
+ * split index to the lockfile. If the temporary file for the shared
+ * index cannot be created, fall back to the behavior described in
+ * the previous paragraph.
+ *
+ * With `COMMIT_LOCK`, the lock is always committed or rolled back.
+ * Without it, the lock is closed, but neither committed nor rolled
+ * back.
+ *
+ * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
+ * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
+ */
+int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
+
+void discard_index(struct index_state *);
+void move_index_extensions(struct index_state *dst, struct index_state *src);
+int unmerged_index(const struct index_state *);
+
+/**
+ * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,
+ * compares istate to HEAD.  If tree is NULL and on an unborn branch,
+ * returns 1 if there are entries in istate, 0 otherwise.  If an strbuf is
+ * provided, the space-separated list of files that differ will be appended
+ * to it.
+ */
+int repo_index_has_changes(struct repository *repo,
+			   struct tree *tree,
+			   struct strbuf *sb);
+
+int verify_path(const char *path, unsigned mode);
+int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
+
+/*
+ * Searches for an entry defined by name and namelen in the given index.
+ * If the return value is positive (including 0) it is the position of an
+ * exact match. If the return value is negative, the negated value minus 1
+ * is the position where the entry would be inserted.
+ * Example: The current index consists of these files and its stages:
+ *
+ *   b#0, d#0, f#1, f#3
+ *
+ * index_name_pos(&index, "a", 1) -> -1
+ * index_name_pos(&index, "b", 1) ->  0
+ * index_name_pos(&index, "c", 1) -> -2
+ * index_name_pos(&index, "d", 1) ->  1
+ * index_name_pos(&index, "e", 1) -> -3
+ * index_name_pos(&index, "f", 1) -> -3
+ * index_name_pos(&index, "g", 1) -> -5
+ */
+int index_name_pos(struct index_state *, const char *name, int namelen);
+
+/*
+ * Like index_name_pos, returns the position of an entry of the given name in
+ * the index if one exists, otherwise returns a negative value where the negated
+ * value minus 1 is the position where the index entry would be inserted. Unlike
+ * index_name_pos, however, a sparse index is not expanded to find an entry
+ * inside a sparse directory.
+ */
+int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
+
+/*
+ * Determines whether an entry with the given name exists within the
+ * given index. The return value is 1 if an exact match is found, otherwise
+ * it is 0. Note that, unlike index_name_pos, this function does not expand
+ * the index if it is sparse. If an item exists within the full index but it
+ * is contained within a sparse directory (and not in the sparse index), 0 is
+ * returned.
+ */
+int index_entry_exists(struct index_state *, const char *name, int namelen);
+
+/*
+ * Some functions return the negative complement of an insert position when a
+ * precise match was not found but a position was found where the entry would
+ * need to be inserted. This helper protects that logic from any integer
+ * underflow.
+ */
+static inline int index_pos_to_insert_pos(uintmax_t pos)
+{
+	if (pos > INT_MAX)
+		die("overflow: -1 - %"PRIuMAX, pos);
+	return -1 - (int)pos;
+}
+
+#define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
+#define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
+#define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
+#define ADD_CACHE_JUST_APPEND 8		/* Append only */
+#define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
+#define ADD_CACHE_KEEP_CACHE_TREE 32	/* Do not invalidate cache-tree */
+#define ADD_CACHE_RENORMALIZE 64        /* Pass along HASH_RENORMALIZE */
+int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
+void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
+
+/* Remove entry, return true if there are more entries to go. */
+int remove_index_entry_at(struct index_state *, int pos);
+
+void remove_marked_cache_entries(struct index_state *istate, int invalidate);
+int remove_file_from_index(struct index_state *, const char *path);
+#define ADD_CACHE_VERBOSE 1
+#define ADD_CACHE_PRETEND 2
+#define ADD_CACHE_IGNORE_ERRORS	4
+#define ADD_CACHE_IGNORE_REMOVAL 8
+#define ADD_CACHE_INTENT 16
+/*
+ * These two are used to add the contents of the file at path
+ * to the index, marking the working tree up-to-date by storing
+ * the cached stat info in the resulting cache entry.  A caller
+ * that has already run lstat(2) on the path can call
+ * add_to_index(), and all others can call add_file_to_index();
+ * the latter will do necessary lstat(2) internally before
+ * calling the former.
+ */
+int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
+int add_file_to_index(struct index_state *, const char *path, int flags);
+
+int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
+int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
+void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
+int index_name_is_other(struct index_state *, const char *, int);
+void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
+
+/* do stat comparison even if CE_VALID is true */
+#define CE_MATCH_IGNORE_VALID		01
+/* do not check the contents but report dirty on racily-clean entries */
+#define CE_MATCH_RACY_IS_DIRTY		02
+/* do stat comparison even if CE_SKIP_WORKTREE is true */
+#define CE_MATCH_IGNORE_SKIP_WORKTREE	04
+/* ignore non-existent files during stat update  */
+#define CE_MATCH_IGNORE_MISSING		0x08
+/* enable stat refresh */
+#define CE_MATCH_REFRESH		0x10
+/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
+#define CE_MATCH_IGNORE_FSMONITOR 0X20
+int is_racy_timestamp(const struct index_state *istate,
+		      const struct cache_entry *ce);
+int has_racy_timestamp(struct index_state *istate);
+int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
+int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
+
+int match_stat_data_racy(const struct index_state *istate,
+			 const struct stat_data *sd, struct stat *st);
+
+void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
+
+#define REFRESH_REALLY                   (1 << 0) /* ignore_valid */
+#define REFRESH_UNMERGED                 (1 << 1) /* allow unmerged */
+#define REFRESH_QUIET                    (1 << 2) /* be quiet about it */
+#define REFRESH_IGNORE_MISSING           (1 << 3) /* ignore non-existent */
+#define REFRESH_IGNORE_SUBMODULES        (1 << 4) /* ignore submodules */
+#define REFRESH_IN_PORCELAIN             (1 << 5) /* user friendly output, not "needs update" */
+#define REFRESH_PROGRESS                 (1 << 6) /* show progress bar if stderr is tty */
+#define REFRESH_IGNORE_SKIP_WORKTREE     (1 << 7) /* ignore skip_worktree entries */
+int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
+/*
+ * Refresh the index and write it to disk.
+ *
+ * 'refresh_flags' is passed directly to 'refresh_index()', while
+ * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
+ * the lockfile is always either committed or rolled back.
+ *
+ * If 'gentle' is passed, errors locking the index are ignored.
+ *
+ * Return 1 if refreshing the index returns an error, -1 if writing
+ * the index to disk fails, 0 on success.
+ *
+ * Note that if refreshing the index returns an error, we still write
+ * out the index (unless locking fails).
+ */
+int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg);
+
+struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
+
+void set_alternate_index_output(const char *);
+
+extern int verify_index_checksum;
+extern int verify_ce_order;
+
+int cmp_cache_name_compare(const void *a_, const void *b_);
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+		       const struct pathspec *pathspec, int include_sparse,
+		       int flags);
+
+void overlay_tree_on_index(struct index_state *istate,
+			   const char *tree_name, const char *prefix);
+
+#endif /* READ_CACHE_LL_H */
diff --git a/read-cache.c b/read-cache.c
index 3fad839fb6f..42f27b06642 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -28,6 +28,7 @@
 #include "name-hash.h"
 #include "object-name.h"
 #include "preload-index.h"
+#include "read-cache.h"
 #include "resolve-undo.h"
 #include "revision.h"
 #include "run-command.h"
diff --git a/read-cache.h b/read-cache.h
new file mode 100644
index 00000000000..043da1f1aae
--- /dev/null
+++ b/read-cache.h
@@ -0,0 +1,45 @@
+#ifndef READ_CACHE_H
+#define READ_CACHE_H
+
+#include "read-cache-ll.h"
+#include "object.h"
+#include "pathspec.h"
+
+static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
+					     unsigned int mode)
+{
+	extern int trust_executable_bit, has_symlinks;
+	if (!has_symlinks && S_ISREG(mode) &&
+	    ce && S_ISLNK(ce->ce_mode))
+		return ce->ce_mode;
+	if (!trust_executable_bit && S_ISREG(mode)) {
+		if (ce && S_ISREG(ce->ce_mode))
+			return ce->ce_mode;
+		return create_ce_mode(0666);
+	}
+	return create_ce_mode(mode);
+}
+
+static inline int ce_to_dtype(const struct cache_entry *ce)
+{
+	unsigned ce_mode = ntohl(ce->ce_mode);
+	if (S_ISREG(ce_mode))
+		return DT_REG;
+	else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
+		return DT_DIR;
+	else if (S_ISLNK(ce_mode))
+		return DT_LNK;
+	else
+		return DT_UNKNOWN;
+}
+
+static inline int ce_path_match(struct index_state *istate,
+				const struct cache_entry *ce,
+				const struct pathspec *pathspec,
+				char *seen)
+{
+	return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
+			      S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
+}
+
+#endif /* READ_CACHE_H */
diff --git a/repository.c b/repository.c
index c53e480e326..ebad755c2cc 100644
--- a/repository.c
+++ b/repository.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
+#include "read-cache-ll.h"
 #include "remote.h"
 #include "setup.h"
 #include "submodule-config.h"
diff --git a/rerere.c b/rerere.c
index e968d413d65..3bc9aedc286 100644
--- a/rerere.c
+++ b/rerere.c
@@ -7,6 +7,7 @@
 #include "hex.h"
 #include "lockfile.h"
 #include "string-list.h"
+#include "read-cache-ll.h"
 #include "rerere.h"
 #include "xdiff-interface.h"
 #include "dir.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 7ec09e89d4f..59598877841 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "hash.h"
+#include "read-cache.h"
 #include "resolve-undo.h"
 #include "sparse-index.h"
 #include "string-list.h"
diff --git a/revision.c b/revision.c
index 88b2f42daa6..8d37ec9f495 100644
--- a/revision.c
+++ b/revision.c
@@ -31,6 +31,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "strvec.h"
diff --git a/split-index.c b/split-index.c
index 40e54760b35..0a8d3903d6f 100644
--- a/split-index.c
+++ b/split-index.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "hash.h"
 #include "mem-pool.h"
+#include "read-cache-ll.h"
 #include "split-index.h"
 #include "strbuf.h"
 #include "ewah/ewok.h"
diff --git a/submodule.c b/submodule.c
index 2e78f513496..e09722d6be3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -28,6 +28,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "commit-reach.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "shallow.h"
 #include "trace2.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9507b356e22..9d64422b3cc 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index f22f7bd84a9..78aa11bb194 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -5,6 +5,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "cache-tree.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 9a098a25cba..e4357d65ec5 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 63fde9157c4..59a24a842b4 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "split-index.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index df70be549fd..a1cbafd64f3 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index d1d63feaa9e..cbcf2419f9b 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -21,6 +21,7 @@
 #include "lockfile.h"
 #include "merge-ort.h"
 #include "object-name.h"
+#include "read-cache-ll.h"
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 9f18c685b7f..386f4cdaee5 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "thread-utils.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index f40d9ad0c2d..c1e82d5d028 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 #define NUM_SECONDS 3
 
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index a06c45c1f84..b3cbaf6d2a8 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "read-cache-ll.h"
 
 int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
 {
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 6944b7e825f..8eb327b3b93 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "name-hash.h"
 #include "parse-options.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "trace.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 2ef53d5f7a2..90e4d29a06f 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -3,6 +3,7 @@
 #include "abspath.h"
 #include "environment.h"
 #include "path.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "string-list.h"
 #include "trace.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index c1ae2763954..0d548814e08 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "wrapper.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 6e17f50d225..7b7e2384043 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 #include "tree.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index 71fe5c61455..dc6fb17f2a7 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 int cmd__sha1(int ac, const char **av)
 {
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 0ac6a99d5f2..f50f64f1f22 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "hash-ll.h"
 
 int cmd__sha256(int ac, const char **av)
 {
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index 96b9a5b5291..d3f39207f14 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "read-cache-ll.h"
 
 int cmd__strcmp_offset(int argc UNUSED, const char **argv)
 {
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index eace08072d7..d27125eeacf 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 "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
 
diff --git a/unpack-trees.c b/unpack-trees.c
index 078c53f7a13..fdcc46e474f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -15,6 +15,7 @@
 #include "progress.h"
 #include "refs.h"
 #include "attr.h"
+#include "read-cache.h"
 #include "split-index.h"
 #include "sparse-index.h"
 #include "submodule.h"
diff --git a/unpack-trees.h b/unpack-trees.h
index 30622aeebff..9b827c307f6 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -1,8 +1,8 @@
 #ifndef UNPACK_TREES_H
 #define UNPACK_TREES_H
 
-#include "cache.h"
 #include "convert.h"
+#include "read-cache-ll.h"
 #include "strvec.h"
 #include "string-list.h"
 #include "tree-walk.h"
diff --git a/wt-status.c b/wt-status.c
index 068b76ef6d9..847b63c906e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -18,6 +18,7 @@
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "read-cache.h"
 #include "setup.h"
 #include "strbuf.h"
 #include "trace.h"
-- 
gitgitgadget


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

* [PATCH v3 17/28] cache.h: remove this no-longer-used header
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (15 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 16/28] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 18/28] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
                       ` (11 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Since this header showed up in some places besides just #include
statements, update/clean-up/remove those other places as well.

Note that compat/fsmonitor/fsm-path-utils-darwin.c previously got
away with violating the rule that all files must start with an include
of git-compat-util.h (or a short-list of alternate headers that happen
to include it first).  This change exposed the violation and caused it
to stop building correctly; fix it by having it include
git-compat-util.h first, as per policy.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/CodingGuidelines           |  2 +-
 Documentation/MyFirstObjectWalk.txt      |  2 +-
 Documentation/user-manual.txt            | 18 ++++++++----------
 Makefile                                 |  2 +-
 add-interactive.c                        |  2 +-
 add-patch.c                              |  2 +-
 apply.c                                  |  2 +-
 attr.c                                   |  2 +-
 blame.c                                  |  2 +-
 builtin.h                                |  1 -
 builtin/add.c                            |  3 +--
 builtin/am.c                             |  3 +--
 builtin/apply.c                          |  1 -
 builtin/archive.c                        |  1 -
 builtin/bisect.c                         |  1 -
 builtin/branch.c                         |  3 +--
 builtin/bundle.c                         |  1 -
 builtin/cat-file.c                       |  3 +--
 builtin/check-attr.c                     |  1 -
 builtin/check-ignore.c                   |  1 -
 builtin/check-ref-format.c               |  3 +--
 builtin/clean.c                          |  1 -
 builtin/column.c                         |  1 -
 builtin/commit-tree.c                    |  3 +--
 builtin/commit.c                         |  3 +--
 builtin/count-objects.c                  |  3 +--
 builtin/describe.c                       |  3 +--
 builtin/diff-files.c                     |  3 +--
 builtin/diff-index.c                     |  3 +--
 builtin/diff-tree.c                      |  3 +--
 builtin/diff.c                           |  3 +--
 builtin/difftool.c                       |  3 +--
 builtin/fast-export.c                    |  1 -
 builtin/fast-import.c                    |  1 -
 builtin/fetch.c                          |  3 +--
 builtin/for-each-ref.c                   |  1 -
 builtin/for-each-repo.c                  |  3 +--
 builtin/fsck.c                           |  1 -
 builtin/get-tar-commit-id.c              |  3 +--
 builtin/grep.c                           |  3 +--
 builtin/help.c                           |  3 +--
 builtin/hook.c                           |  1 -
 builtin/init-db.c                        |  3 +--
 builtin/interpret-trailers.c             |  1 -
 builtin/ls-files.c                       |  3 +--
 builtin/ls-remote.c                      |  1 -
 builtin/ls-tree.c                        |  3 +--
 builtin/mailinfo.c                       |  3 +--
 builtin/mailsplit.c                      |  1 -
 builtin/merge-base.c                     |  1 -
 builtin/merge-file.c                     |  1 -
 builtin/merge-recursive.c                |  1 -
 builtin/merge.c                          |  3 +--
 builtin/multi-pack-index.c               |  1 -
 builtin/notes.c                          |  3 +--
 builtin/patch-id.c                       |  1 -
 builtin/prune.c                          |  3 +--
 builtin/pull.c                           |  3 +--
 builtin/push.c                           |  3 +--
 builtin/range-diff.c                     |  1 -
 builtin/read-tree.c                      |  3 +--
 builtin/replace.c                        |  3 +--
 builtin/rerere.c                         |  1 -
 builtin/rev-list.c                       |  3 +--
 builtin/rev-parse.c                      |  3 +--
 builtin/shortlog.c                       |  1 -
 builtin/show-branch.c                    |  3 +--
 builtin/show-index.c                     |  1 -
 builtin/show-ref.c                       |  1 -
 builtin/sparse-checkout.c                |  1 -
 builtin/stripspace.c                     |  1 -
 builtin/submodule--helper.c              |  1 -
 builtin/symbolic-ref.c                   |  1 -
 builtin/tag.c                            |  3 +--
 builtin/unpack-objects.c                 |  1 -
 builtin/update-index.c                   |  3 +--
 builtin/update-ref.c                     |  3 +--
 builtin/update-server-info.c             |  3 +--
 builtin/upload-archive.c                 |  1 -
 builtin/upload-pack.c                    |  1 -
 builtin/verify-commit.c                  |  3 +--
 builtin/verify-pack.c                    |  1 -
 builtin/verify-tag.c                     |  3 +--
 builtin/worktree.c                       |  3 +--
 builtin/write-tree.c                     |  1 -
 cache-tree.c                             |  2 +-
 cache.h                                  |  6 ------
 compat/fsmonitor/fsm-health-win32.c      |  2 +-
 compat/fsmonitor/fsm-listen-win32.c      |  2 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |  1 +
 compat/fsmonitor/fsm-path-utils-win32.c  |  2 +-
 compat/fsmonitor/fsm-settings-win32.c    |  2 +-
 compat/mingw.c                           |  1 -
 compat/precompose_utf8.c                 |  2 +-
 compat/sha1-chunked.c                    |  2 +-
 compat/simple-ipc/ipc-win32.c            |  2 +-
 compat/win32/trace2_win32_process_info.c |  2 +-
 convert.c                                |  2 +-
 diff-lib.c                               |  2 +-
 diff.c                                   |  2 +-
 entry.c                                  |  2 +-
 environment.c                            |  2 +-
 fsmonitor-ipc.c                          |  2 +-
 fsmonitor.c                              |  2 +-
 fsmonitor.h                              |  1 -
 hash-lookup.c                            |  2 +-
 merge-ort-wrappers.c                     |  2 +-
 merge-ort.c                              |  2 +-
 merge-recursive.c                        |  2 +-
 merge.c                                  |  2 +-
 name-hash.c                              |  2 +-
 object-name.c                            |  2 +-
 object.c                                 |  2 +-
 parallel-checkout.c                      |  2 +-
 pathspec.c                               |  2 +-
 preload-index.c                          |  2 +-
 read-cache.c                             |  2 +-
 refs/files-backend.c                     |  2 +-
 refs/packed-backend.c                    |  2 +-
 repository.c                             |  2 +-
 rerere.c                                 |  2 +-
 resolve-undo.c                           |  2 +-
 revision.c                               |  2 +-
 run-command.h                            |  2 +-
 sequencer.c                              |  2 +-
 shallow.c                                |  2 +-
 sparse-index.c                           |  2 +-
 split-index.c                            |  2 +-
 strbuf.h                                 |  4 ----
 submodule.c                              |  2 +-
 t/helper/test-cache-tree.c               |  1 -
 t/helper/test-dump-cache-tree.c          |  1 -
 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-hash-speed.c               |  1 -
 t/helper/test-index-version.c            |  1 -
 t/helper/test-lazy-init-name-hash.c      |  1 -
 t/helper/test-path-utils.c               |  1 -
 t/helper/test-read-cache.c               |  1 -
 t/helper/test-scrap-cache-tree.c         |  1 -
 t/helper/test-sha1.c                     |  1 -
 t/helper/test-sha256.c                   |  1 -
 t/helper/test-strcmp-offset.c            |  1 -
 t/helper/test-write-cache.c              |  1 -
 unpack-trees.c                           |  2 +-
 wt-status.c                              |  2 +-
 149 files changed, 99 insertions(+), 205 deletions(-)
 delete mode 100644 cache.h

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 003393ed161..2b472df29d5 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -444,7 +444,7 @@ For C programs:
  - The first #include in C files, except in platform specific compat/
    implementations and sha1dc/, must be either "git-compat-util.h" or
    one of the approved headers that includes it first for you.  (The
-   approved headers currently include "cache.h", "builtin.h",
+   approved headers currently include "builtin.h",
    "t/helper/test-tool.h", "xdiff/xinclude.h", or
    "reftable/system.h").  You do not have to include more than one of
    these.
diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index eee513e86f4..200e628e301 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -124,7 +124,7 @@ parameters provided by the user over the CLI.
 
 `nr` represents the number of `rev_cmdline_entry` present in the array.
 
-`alloc` is used by the `ALLOC_GROW` macro. Check `cache.h` - this variable is
+`alloc` is used by the `ALLOC_GROW` macro. Check `alloc.h` - this variable is
 used to track the allocated size of the list.
 
 Per entry, we find:
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index dc9c6a663a9..100630ba3d2 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -4102,13 +4102,11 @@ Note that terminology has changed since that revision.  For example, the
 README in that revision uses the word "changeset" to describe what we
 now call a <<def_commit_object,commit>>.
 
-Also, we do not call it "cache" any more, but rather "index"; however, the
-file is still called `cache.h`.  Remark: Not much reason to change it now,
-especially since there is no good single name for it anyway, because it is
-basically _the_ header file which is included by _all_ of Git's C sources.
+Also, we do not call it "cache" any more, but rather "index"; however,
+the file is still called `read-cache.h`.
 
 If you grasp the ideas in that initial commit, you should check out a
-more recent version and skim `cache.h`, `object.h` and `commit.h`.
+more recent version and skim `read-cache-ll.h`, `object.h` and `commit.h`.
 
 In the early days, Git (in the tradition of UNIX) was a bunch of programs
 which were extremely simple, and which you used in scripts, piping the
@@ -4119,11 +4117,11 @@ many of these parts have become builtins, and some of the core has been
 and to avoid code duplication.
 
 By now, you know what the index is (and find the corresponding data
-structures in `cache.h`), and that there are just a couple of object types
-(blobs, trees, commits and tags) which inherit their common structure from
-`struct object`, which is their first member (and thus, you can cast e.g.
-`(struct object *)commit` to achieve the _same_ as `&commit->object`, i.e.
-get at the object name and flags).
+structures in `read-cache-ll.h`), and that there are just a couple of
+object types (blobs, trees, commits and tags) which inherit their
+common structure from `struct object`, which is their first member
+(and thus, you can cast e.g.  `(struct object *)commit` to achieve the
+_same_ as `&commit->object`, i.e.  get at the object name and flags).
 
 Now is a good point to take a break to let this information sink in.
 
diff --git a/Makefile b/Makefile
index cbc7f212016..2d180abc5ca 100644
--- a/Makefile
+++ b/Makefile
@@ -1952,7 +1952,7 @@ endif
 	BASIC_CFLAGS += \
 		-DSHA1DC_NO_STANDARD_INCLUDES \
 		-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
-		-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
+		-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"git-compat-util.h\"" \
 		-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
 endif
 endif
diff --git a/add-interactive.c b/add-interactive.c
index a9671e33491..40f88c02051 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "add-interactive.h"
 #include "color.h"
 #include "config.h"
diff --git a/add-patch.c b/add-patch.c
index 7d4d298286d..875b96e2274 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "add-interactive.h"
 #include "advice.h"
 #include "alloc.h"
diff --git a/apply.c b/apply.c
index f056c8f3bb9..e44a5dd7c50 100644
--- a/apply.c
+++ b/apply.c
@@ -7,7 +7,7 @@
  *
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "base85.h"
diff --git a/attr.c b/attr.c
index 57c813d8e77..5a32bfadb37 100644
--- a/attr.c
+++ b/attr.c
@@ -6,7 +6,7 @@
  * an insanely large number of attributes.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/blame.c b/blame.c
index a29ae7c14b2..15bbf16057a 100644
--- a/blame.c
+++ b/blame.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "refs.h"
 #include "object-store.h"
 #include "cache-tree.h"
diff --git a/builtin.h b/builtin.h
index cb0db676814..3e6c22eef69 100644
--- a/builtin.h
+++ b/builtin.h
@@ -3,7 +3,6 @@
 
 #include "git-compat-util.h"
 #include "strbuf.h"
-#include "cache.h"
 #include "commit.h"
 
 /*
diff --git a/builtin/add.c b/builtin/add.c
index 9fe6b6ce290..50792c0d495 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,10 +4,9 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "lockfile.h"
 #include "editor.h"
 #include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 0d8f46f8d5a..2f0f2337915 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,11 +4,10 @@
  * Based on git-am.sh by Junio C Hamano.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "editor.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/builtin/apply.c b/builtin/apply.c
index e3ff02a09e3..c18b7ea5d3d 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/archive.c b/builtin/archive.c
index b0eaa3c14a3..90761fdfee0 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -2,7 +2,6 @@
  * Copyright (c) 2006 Franck Bui-Huu
  * Copyright (c) 2006 Rene Scharfe
  */
-#include "cache.h"
 #include "builtin.h"
 #include "archive.h"
 #include "gettext.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 4812450c393..bce0ee6268a 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "copy.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 501c47657c9..5e9b0e4ea44 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -5,14 +5,13 @@
  * Based on git-branch.sh by Junio C Hamano.
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "color.h"
 #include "editor.h"
 #include "environment.h"
 #include "refs.h"
 #include "commit.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "remote.h"
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 44113389d7a..3f63631c039 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -6,7 +6,6 @@
 #include "parse-options.h"
 #include "pkt-line.h"
 #include "repository.h"
-#include "cache.h"
 #include "bundle.h"
 
 /*
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 0bafc14e6c0..9646e7209ca 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -4,11 +4,10 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "alloc.h"
 #include "config.h"
 #include "convert.h"
-#include "builtin.h"
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index b2b678847f5..869c04420d3 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "attr.h"
 #include "environment.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index e4b78782a32..906cd967536 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 57f0505070f..5eb6bdc3f69 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -2,9 +2,8 @@
  * GIT - The information manager from hell
  */
 
-#include "cache.h"
-#include "refs.h"
 #include "builtin.h"
+#include "refs.h"
 #include "setup.h"
 #include "strbuf.h"
 
diff --git a/builtin/clean.c b/builtin/clean.c
index 49c7af45b03..66b4479356d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -9,7 +9,6 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/column.c b/builtin/column.c
index de623a16c2d..ce13ff0baa2 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d1d251c3ded..d2121f30d45 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -12,7 +12,6 @@
 #include "repository.h"
 #include "commit.h"
 #include "tree.h"
-#include "builtin.h"
 #include "utf8.h"
 #include "gpg-interface.h"
 #include "parse-options.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 5be05c9d9e1..3b90cb748cd 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,7 +6,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "lockfile.h"
@@ -15,7 +15,6 @@
 #include "dir.h"
 #include "editor.h"
 #include "environment.h"
-#include "builtin.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "commit.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index f3d8f1bcbb0..b9e6b55a9a9 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -4,13 +4,12 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "repository.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index f1be7c36948..508e8df00ef 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,5 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -9,7 +9,6 @@
 #include "tag.h"
 #include "blob.h"
 #include "refs.h"
-#include "builtin.h"
 #include "exec-cmd.h"
 #include "object-name.h"
 #include "parse-options.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index 2e6b59a8bb3..b7036aa7c2b 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -3,14 +3,13 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
 #include "revision.h"
-#include "builtin.h"
 #include "submodule.h"
 
 static const char diff_files_usage[] =
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 9b98db2e77e..1ab8f8b6dc5 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
 #include "revision.h"
-#include "builtin.h"
 #include "setup.h"
 #include "submodule.h"
 
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 5a1e5d6df7c..3e281150473 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,12 +1,11 @@
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "gettext.h"
 #include "hex.h"
 #include "log-tree.h"
-#include "builtin.h"
 #include "submodule.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index a9ce701ff97..b19530c996c 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "ewah/ewok.h"
 #include "lockfile.h"
@@ -20,7 +20,6 @@
 #include "read-cache-ll.h"
 #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 88809976c53..4a22de3eddb 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -12,11 +12,10 @@
  * Copyright (C) 2016 Johannes Schindelin
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "copy.h"
-#include "builtin.h"
 #include "run-command.h"
 #include "environment.h"
 #include "exec-cmd.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9a95f6a1a82..5f3ffd6912f 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2007 Johannes E. Schindelin
  */
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index bbd9b2b3e71..67a2260a5eb 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4d7c2897528..cbc991086cd 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1,7 +1,7 @@
 /*
  * "git fetch"
  */
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
 #include "gettext.h"
@@ -15,7 +15,6 @@
 #include "oidset.h"
 #include "oid-array.h"
 #include "commit.h"
-#include "builtin.h"
 #include "string-list.h"
 #include "remote.h"
 #include "transport.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 695fc8f4a5e..d0d6ab0fd34 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "refs.h"
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 37daf7bec14..28186b30f54 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e8c5fbca58f..f05617ceb14 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 564cfcac4fb..9303e386cc7 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -1,10 +1,9 @@
 /*
  * Copyright (c) 2005, 2006 Rene Scharfe
  */
-#include "cache.h"
+#include "builtin.h"
 #include "commit.h"
 #include "tar.h"
-#include "builtin.h"
 #include "quote.h"
 #include "wrapper.h"
 
diff --git a/builtin/grep.c b/builtin/grep.c
index 0d567575890..7638d779000 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
-#include "cache.h"
+#include "builtin.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hex.h"
@@ -14,7 +14,6 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree-walk.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/builtin/help.c b/builtin/help.c
index d3cf4af3f6e..e93533fb09e 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -1,9 +1,8 @@
 /*
  * Builtin help command
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "pager.h"
diff --git a/builtin/hook.c b/builtin/hook.c
index 88051795c7f..09b51a6487c 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index feb019a9dea..680ef7e1837 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -3,12 +3,11 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
-#include "builtin.h"
 #include "object-file.h"
 #include "parse-options.h"
 #include "path.h"
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
index 107ac28f0e8..c5e83452654 100644
--- a/builtin/interpret-trailers.c
+++ b/builtin/interpret-trailers.c
@@ -5,7 +5,6 @@
  *
  */
 
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index d8c1c62bcb0..a49c43864f7 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -5,13 +5,12 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "repository.h"
 #include "config.h"
 #include "convert.h"
 #include "quote.h"
 #include "dir.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "strbuf.h"
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index cb6cb77e086..a0aadc9b8ff 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "transport.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 077977a4610..f4331c640fc 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -13,7 +13,6 @@
 #include "tree.h"
 #include "commit.h"
 #include "quote.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "pathspec.h"
 
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index a032a1c3881..53b55dd71c0 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -2,9 +2,8 @@
  * Another stupid program, this one parsing the headers of an
  * email to figure out authorship and subject
  */
-#include "cache.h"
-#include "abspath.h"
 #include "builtin.h"
+#include "abspath.h"
 #include "environment.h"
 #include "gettext.h"
 #include "utf8.h"
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 0b6193a0915..3af9ddb8ae5 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -4,7 +4,6 @@
  * It just splits a mbox into a list of files: "0001" "0002" ..
  * so you can process them further from there.
  */
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "string-list.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 854019a32dc..e68b7fe45d7 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "gettext.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 781818d08f5..d7eb4c65401 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "setup.h"
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index b9e980384a4..3366699657c 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "advice.h"
 #include "commit.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index 6e8f7b9bb53..d7ac108ce94 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,7 +7,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "advice.h"
 #include "alloc.h"
@@ -18,7 +18,6 @@
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
-#include "builtin.h"
 #include "lockfile.h"
 #include "run-command.h"
 #include "hook.h"
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 1b5083f8b26..5bb71bce08d 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,6 +1,5 @@
 #include "builtin.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index d5788352b6e..efdf2451486 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -7,9 +7,8 @@
  * and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
  */
 
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "editor.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 9d5585d3a72..27952f1a6fd 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index 5dc9b207200..b3658b5b512 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,11 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
 #include "commit.h"
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "revision.h"
-#include "builtin.h"
 #include "reachable.h"
 #include "parse-options.h"
 #include "progress.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 8aeb5abc7fb..d4261804d76 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -6,10 +6,9 @@
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "gettext.h"
 #include "hex.h"
 #include "merge.h"
diff --git a/builtin/push.c b/builtin/push.c
index 4e5780dd50d..62d44736500 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -1,7 +1,7 @@
 /*
  * "git push"
  */
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "branch.h"
 #include "config.h"
@@ -10,7 +10,6 @@
 #include "refs.h"
 #include "refspec.h"
 #include "run-command.h"
-#include "builtin.h"
 #include "remote.h"
 #include "transport.h"
 #include "parse-options.h"
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 04339a92ea5..8610390d7c5 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "gettext.h"
 #include "object-name.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index bd1ce1d963f..63c92936faa 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,7 +5,7 @@
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
@@ -17,7 +17,6 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "dir.h"
-#include "builtin.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "resolve-undo.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 981f1894436..e0fbdc98ed3 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -8,9 +8,8 @@
  * git-tag.sh and mktag.c by Linus Torvalds.
  */
 
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "editor.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index d4bd52797f4..0458db9cadf 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 6dc8be492a2..8029f3de53c 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
@@ -15,7 +15,6 @@
 #include "object-store.h"
 #include "pack.h"
 #include "pack-bitmap.h"
-#include "builtin.h"
 #include "log-tree.h"
 #include "graph.h"
 #include "bisect.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index ad93e5fad88..8d8c870421d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,7 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
@@ -14,7 +14,6 @@
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
-#include "builtin.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "diff.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 46f4e0832ac..99be9dc417d 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 7ef4a642c17..cd215f89af8 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -6,7 +6,6 @@
 #include "hex.h"
 #include "pretty.h"
 #include "refs.h"
-#include "builtin.h"
 #include "color.h"
 #include "strvec.h"
 #include "object-name.h"
diff --git a/builtin/show-index.c b/builtin/show-index.c
index d839e55335d..540dc3dad1c 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hash.h"
 #include "hex.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index a2243b42195..e07e9ca862f 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 40d420f06cb..5c8ffb1f759 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 9451eb69ff4..397d7fe2dcd 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 86324b829a7..17567d91c88 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -6,7 +6,6 @@
 #include "gettext.h"
 #include "hex.h"
 #include "repository.h"
-#include "cache.h"
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 10198a74fae..a61fa3c0f81 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,6 +1,5 @@
 #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 1850a6a6fdc..ce298d08945 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -6,10 +6,9 @@
  * Based on git-tag.sh and mktag.c by Linus Torvalds.
  */
 
-#include "cache.h"
+#include "builtin.h"
 #include "advice.h"
 #include "config.h"
-#include "builtin.h"
 #include "editor.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 2c52c3a741f..85baf6a131a 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "bulk-checkin.h"
 #include "config.h"
 #include "environment.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 484a307df50..aee3cb8cbd3 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -4,7 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
 #include "bulk-checkin.h"
 #include "config.h"
 #include "environment.h"
@@ -15,7 +15,6 @@
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
-#include "builtin.h"
 #include "object-file.h"
 #include "refs.h"
 #include "resolve-undo.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0c59b1c9eff..242102273ee 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
 #include "config.h"
 #include "gettext.h"
 #include "hash.h"
 #include "refs.h"
-#include "builtin.h"
 #include "object-name.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 19dce3c0655..1dc3971edeb 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "server-info.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index 44ad400e183..d4c7f162ff0 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -1,7 +1,6 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
-#include "cache.h"
 #include "builtin.h"
 #include "archive.h"
 #include "pkt-line.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index beb9dd08610..ba5103a9331 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,4 +1,3 @@
-#include "cache.h"
 #include "builtin.h"
 #include "exec-cmd.h"
 #include "gettext.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 5d99b82a64f..aa34fb896ac 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -5,9 +5,8 @@
  *
  * Based on git-verify-tag
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index 190fd695409..aba92cf8af7 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,4 @@
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "gettext.h"
 #include "run-command.h"
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index c6019a0ad8c..d8753270ebe 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -5,9 +5,8 @@
  *
  * Based on git-verify-tag.sh
  */
-#include "cache.h"
-#include "config.h"
 #include "builtin.h"
+#include "config.h"
 #include "gettext.h"
 #include "tag.h"
 #include "run-command.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 3c3d97ad5b0..b9a84988637 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "checkout.h"
 #include "config.h"
 #include "copy.h"
-#include "builtin.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index f98d54c1df2..5917085f429 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,7 +5,6 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
-#include "cache.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/cache-tree.c b/cache-tree.c
index 153217b47ff..077932c2db5 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "environment.h"
 #include "hex.h"
diff --git a/cache.h b/cache.h
deleted file mode 100644
index 9b4e8d16874..00000000000
--- a/cache.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef CACHE_H
-#define CACHE_H
-
-#include "git-compat-util.h"
-
-#endif /* CACHE_H */
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index fe11bdd9ce6..6c81d7ee5c2 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsm-health.h"
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 677b1bbdeca..3c0df5cff8c 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsm-listen.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index 45eb4a9b9e7..ef0142e0fbf 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c
index 4024baafb97..27bb6945183 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index a8af31b71de..37288978643 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "repository.h"
 #include "fsmonitor.h"
diff --git a/compat/mingw.c b/compat/mingw.c
index d06cdc6254f..559abb1c617 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -6,7 +6,6 @@
 #include <wchar.h>
 #include "../strbuf.h"
 #include "../run-command.h"
-#include "../cache.h"
 #include "../abspath.h"
 #include "../alloc.h"
 #include "win32/lazyload.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index fb08475bc64..0bd5c24250a 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -5,7 +5,7 @@
 
 #define PRECOMPOSE_UNICODE_C
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 56729d92dcf..a4a6f930d7b 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hash-ll.h"
 
 int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 6adce3c650e..8bfe51248e5 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index a4e33768f43..a2b1506f9c9 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,4 +1,4 @@
-#include "../../cache.h"
+#include "../../git-compat-util.h"
 #include "../../json-writer.h"
 #include "../../repository.h"
 #include "../../trace2.h"
diff --git a/convert.c b/convert.c
index 236d5e3dc25..9e89f660308 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
 #include "convert.h"
diff --git a/diff-lib.c b/diff-lib.c
index 36cd66ea237..f3aa7f93c78 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "quote.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/diff.c b/diff.c
index 61b4dc61e1e..5e81dc0d02d 100644
--- a/diff.c
+++ b/diff.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "base85.h"
diff --git a/entry.c b/entry.c
index 53d00386748..041f5cf212d 100644
--- a/entry.c
+++ b/entry.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "blob.h"
 #include "object-store.h"
 #include "dir.h"
diff --git a/environment.c b/environment.c
index 28d18eaca8e..0cdd20a1589 100644
--- a/environment.c
+++ b/environment.c
@@ -110,7 +110,7 @@ char *git_work_tree_cfg;
 static char *git_namespace;
 
 /*
- * Repository-local GIT_* environment variables; see cache.h for details.
+ * Repository-local GIT_* environment variables; see environment.h for details.
  */
 const char * const local_repo_env[] = {
 	ALTERNATE_DB_ENVIRONMENT,
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6a6a89764a6..6ace978a1b4 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "fsmonitor.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/fsmonitor.c b/fsmonitor.c
index 28c083d4d84..f670c509378 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/fsmonitor.h b/fsmonitor.h
index 8b7a521552a..7702301d214 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,7 +1,6 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
-#include "cache.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
 #include "object.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 8fec8939fd3..9f0f95e2b9e 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hash.h"
 #include "hash-lookup.h"
 #include "read-cache-ll.h"
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a0bedcb63bb..4acedf3c338 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hash.h"
 #include "merge-ort.h"
diff --git a/merge-ort.c b/merge-ort.c
index 5512f40d321..c2d2ee73eaa 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,7 +14,7 @@
  * "cale", "peedy", or "ins" instead of "ort"?)
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "merge-ort.h"
 
 #include "alloc.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 0e16e7a06df..4bef9b62fa8 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,7 +3,7 @@
  * Fredrik Kuivinen.
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "merge-recursive.h"
 
 #include "advice.h"
diff --git a/merge.c b/merge.c
index fade6b203b3..83bcba6943e 100644
--- a/merge.c
+++ b/merge.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
diff --git a/name-hash.c b/name-hash.c
index f2f3564cb20..251f036eef6 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -5,7 +5,7 @@
  *
  * Copyright (C) 2008 Linus Torvalds
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
diff --git a/object-name.c b/object-name.c
index 1eefeef746e..45f4d51305b 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "object-name.h"
 #include "advice.h"
 #include "config.h"
diff --git a/object.c b/object.c
index 333e736fb24..60f954194f7 100644
--- a/object.c
+++ b/object.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object.h"
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 2b1439c0c5f..602fbf19d3c 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "entry.h"
diff --git a/pathspec.c b/pathspec.c
index 47d172fe414..0baa85384f8 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
diff --git a/preload-index.c b/preload-index.c
index d037a951efa..e44530c80cf 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2008 Linus Torvalds
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "pathspec.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/read-cache.c b/read-cache.c
index 42f27b06642..edab96765df 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "bulk-checkin.h"
 #include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index bca7b851c5a..01c08207619 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
 #include "../config.h"
 #include "../copy.h"
 #include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 085becf773e..713491a9e2c 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
 #include "../alloc.h"
 #include "../config.h"
 #include "../gettext.h"
diff --git a/repository.c b/repository.c
index ebad755c2cc..67ec56a70c5 100644
--- a/repository.c
+++ b/repository.c
@@ -3,7 +3,7 @@
  * declaration matches the definition in this file.
  */
 #define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
 #include "object-store.h"
diff --git a/rerere.c b/rerere.c
index 3bc9aedc286..2fb93a51125 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "config.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 59598877841..7817f5d6db1 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "dir.h"
 #include "hash.h"
 #include "read-cache.h"
diff --git a/revision.c b/revision.c
index 8d37ec9f495..66a1fece0df 100644
--- a/revision.c
+++ b/revision.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "config.h"
 #include "environment.h"
diff --git a/run-command.h b/run-command.h
index 9e47f91d462..1f22cc3827d 100644
--- a/run-command.h
+++ b/run-command.h
@@ -503,7 +503,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts);
  * exception of GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT (which cause the
  * corresponding environment variables to be unset in the subprocess) and adds
  * an environment variable pointing to new_git_dir. See local_repo_env in
- * cache.h for more information.
+ * environment.h for more information.
  */
 void prepare_other_repo_env(struct strvec *env, const char *new_git_dir);
 
diff --git a/sequencer.c b/sequencer.c
index ec4a2e80a10..08bd0e81743 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
 #include "alloc.h"
diff --git a/shallow.c b/shallow.c
index a2ebf0af2ba..f1c93e74648 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/sparse-index.c b/sparse-index.c
index 60451daae80..2c47954d933 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/split-index.c b/split-index.c
index 0a8d3903d6f..0ee3865a553 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "alloc.h"
 #include "gettext.h"
 #include "hash.h"
diff --git a/strbuf.h b/strbuf.h
index 3dfeadb44c2..e8dfab6ecd6 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -72,10 +72,6 @@ struct strbuf {
 extern char strbuf_slopbuf[];
 #define STRBUF_INIT  { .buf = strbuf_slopbuf }
 
-/*
- * Predeclare this here, since cache.h includes this file before it defines the
- * struct.
- */
 struct object_id;
 
 /**
diff --git a/submodule.c b/submodule.c
index e09722d6be3..20aa8ed0fb8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "alloc.h"
 #include "repository.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9d64422b3cc..e7236392c81 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 78aa11bb194..c38f546e4f0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "hash.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index e4357d65ec5..4f215fea025 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index 59a24a842b4..5cf0b26dca1 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "hex.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index a1cbafd64f3..b4af9712fe5 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "dir.h"
 #include "hex.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index cbcf2419f9b..62c5b5d704b 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -12,7 +12,6 @@
 
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "environment.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 386f4cdaee5..58d1dc5fc83 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -4,7 +4,6 @@
  */
 
 #include "test-tool.h"
-#include "cache.h"
 #include "parse-options.h"
 #include "fsmonitor-ipc.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index c1e82d5d028..b235da594f7 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 #define NUM_SECONDS 3
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index b3cbaf6d2a8..f3c2dbe0a2c 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 
 int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 8eb327b3b93..187a115d574 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "environment.h"
 #include "name-hash.h"
 #include "parse-options.h"
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 90e4d29a06f..70396fa3845 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "abspath.h"
 #include "environment.h"
 #include "path.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 0d548814e08..56c2d25f359 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "config.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 7b7e2384043..0a816a96e28 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index dc6fb17f2a7..dcb7f6c0032 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 int cmd__sha1(int ac, const char **av)
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index f50f64f1f22..08cf1490014 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "hash-ll.h"
 
 int cmd__sha256(int ac, const char **av)
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index d3f39207f14..d8473cf2fcf 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,4 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "read-cache-ll.h"
 
 int cmd__strcmp_offset(int argc UNUSED, const char **argv)
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index d27125eeacf..f084034d38e 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,6 +1,5 @@
 #define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
-#include "cache.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index fdcc46e474f..4b620df3031 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "strvec.h"
 #include "repository.h"
diff --git a/wt-status.c b/wt-status.c
index 847b63c906e..6ee8567ac2d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "advice.h"
 #include "wt-status.h"
 #include "object.h"
-- 
gitgitgadget


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

* [PATCH v3 18/28] log-tree: replace include of revision.h with simple forward declaration
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (16 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 17/28] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:33     ` [PATCH v3 19/28] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
                       ` (10 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/diff-tree.c | 1 +
 log-tree.c          | 1 +
 log-tree.h          | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 3e281150473..4ad55ecc3fc 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -9,6 +9,7 @@
 #include "submodule.h"
 #include "read-cache-ll.h"
 #include "repository.h"
+#include "revision.h"
 #include "tree.h"
 
 static struct rev_info log_tree_opt;
diff --git a/log-tree.c b/log-tree.c
index f4b22a60cc5..07d0b47b168 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -16,6 +16,7 @@
 #include "reflog-walk.h"
 #include "refs.h"
 #include "replace-object.h"
+#include "revision.h"
 #include "string-list.h"
 #include "color.h"
 #include "gpg-interface.h"
diff --git a/log-tree.h b/log-tree.h
index e7e4641cf83..bdb64328154 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -1,7 +1,7 @@
 #ifndef LOG_TREE_H
 #define LOG_TREE_H
 
-#include "revision.h"
+struct rev_info;
 
 struct log_info {
 	struct commit *commit, *parent;
-- 
gitgitgadget


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

* [PATCH v3 19/28] repository: remove unnecessary include of path.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (17 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 18/28] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
@ 2023-05-16  6:33     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 20/28] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
                       ` (9 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:33 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that several .c files that depended upon path.h
were missing a #include for it; add the missing includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.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/bisect.c                  | 1 +
 builtin/branch.c                  | 1 +
 builtin/checkout.c                | 1 +
 builtin/clean.c                   | 1 +
 builtin/clone.c                   | 1 +
 builtin/commit.c                  | 1 +
 builtin/count-objects.c           | 1 +
 builtin/fast-import.c             | 1 +
 builtin/fetch.c                   | 1 +
 builtin/fsck.c                    | 1 +
 builtin/gc.c                      | 1 +
 builtin/grep.c                    | 1 +
 builtin/ls-files.c                | 1 +
 builtin/ls-tree.c                 | 1 +
 builtin/merge.c                   | 1 +
 builtin/notes.c                   | 1 +
 builtin/prune.c                   | 1 +
 builtin/pull.c                    | 1 +
 builtin/rebase.c                  | 1 +
 builtin/receive-pack.c            | 1 +
 builtin/remote.c                  | 1 +
 builtin/repack.c                  | 1 +
 builtin/replace.c                 | 1 +
 builtin/reset.c                   | 1 +
 builtin/rev-parse.c               | 1 +
 builtin/submodule--helper.c       | 1 +
 builtin/tag.c                     | 1 +
 builtin/upload-archive.c          | 1 +
 builtin/upload-pack.c             | 1 +
 builtin/worktree.c                | 1 +
 commit-graph.c                    | 1 +
 compat/fsmonitor/fsm-ipc-darwin.c | 1 +
 config.c                          | 1 +
 connect.c                         | 1 +
 dir.c                             | 1 +
 environment.c                     | 1 +
 fetch-pack.c                      | 1 +
 fsck.c                            | 1 +
 http-backend.c                    | 1 +
 merge-ort.c                       | 1 +
 merge-recursive.c                 | 1 +
 notes-merge.c                     | 1 +
 object-file.c                     | 1 +
 pack-bitmap-write.c               | 1 +
 pack-write.c                      | 1 +
 read-cache.c                      | 1 +
 refs.c                            | 1 +
 refs/files-backend.c              | 1 +
 remote.c                          | 1 +
 repository.c                      | 1 +
 repository.h                      | 2 --
 rerere.c                          | 1 +
 sequencer.c                       | 1 +
 server-info.c                     | 1 +
 setup.c                           | 1 +
 shallow.c                         | 1 +
 strbuf.c                          | 1 +
 submodule-config.c                | 1 +
 submodule.c                       | 1 +
 t/helper/test-ref-store.c         | 1 +
 tmp-objdir.c                      | 1 +
 worktree.c                        | 1 +
 wt-status.c                       | 1 +
 71 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index e44a5dd7c50..be58dc08d22 100644
--- a/apply.c
+++ b/apply.c
@@ -27,6 +27,7 @@
 #include "object-name.h"
 #include "object-file.h"
 #include "parse-options.h"
+#include "path.h"
 #include "quote.h"
 #include "read-cache.h"
 #include "rerere.h"
diff --git a/archive.c b/archive.c
index 641baad627b..802a34d6b91 100644
--- a/archive.c
+++ b/archive.c
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "pretty.h"
 #include "setup.h"
 #include "refs.h"
diff --git a/attr.c b/attr.c
index 5a32bfadb37..435b51e11ff 100644
--- a/attr.c
+++ b/attr.c
@@ -14,6 +14,7 @@
 #include "attr.h"
 #include "dir.h"
 #include "gettext.h"
+#include "path.h"
 #include "utf8.h"
 #include "quote.h"
 #include "read-cache-ll.h"
diff --git a/bisect.c b/bisect.c
index 8d5f8e58851..9f7cf0be073 100644
--- a/bisect.c
+++ b/bisect.c
@@ -19,6 +19,7 @@
 #include "commit-reach.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "dir.h"
 
 static struct oid_array good_revs;
diff --git a/blame.c b/blame.c
index 15bbf16057a..b74ee70decf 100644
--- a/blame.c
+++ b/blame.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "read-cache.h"
 #include "setup.h"
 #include "tag.h"
diff --git a/branch.c b/branch.c
index 9415ee3f340..1c02078e6aa 100644
--- a/branch.c
+++ b/branch.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "path.h"
 #include "refs.h"
 #include "refspec.h"
 #include "remote.h"
diff --git a/builtin/add.c b/builtin/add.c
index 50792c0d495..43183114487 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -16,6 +16,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/builtin/am.c b/builtin/am.c
index 2f0f2337915..a78daa69714 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -41,6 +41,7 @@
 #include "string-list.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "repository.h"
 #include "pretty.h"
 #include "wrapper.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index bce0ee6268a..6478df34890 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -11,6 +11,7 @@
 #include "strvec.h"
 #include "run-command.h"
 #include "oid-array.h"
+#include "path.h"
 #include "prompt.h"
 #include "quote.h"
 #include "revision.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 5e9b0e4ea44..84f13b0cc71 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -18,6 +18,7 @@
 #include "parse-options.h"
 #include "branch.h"
 #include "diff.h"
+#include "path.h"
 #include "revision.h"
 #include "string-list.h"
 #include "column.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 09b84156492..716dcd4cae1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,6 +20,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 66b4479356d..1bb6b7965c5 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -13,6 +13,7 @@
 #include "dir.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index cc34c194f5e..6c5cb33f6a9 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -39,6 +39,7 @@
 #include "setup.h"
 #include "connected.h"
 #include "packfile.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "list-objects-filter-options.h"
 #include "hook.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index 3b90cb748cd..b3ab5e93844 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -29,6 +29,7 @@
 #include "utf8.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "string-list.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index b9e6b55a9a9..c9f82d0bce9 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -9,6 +9,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
+#include "path.h"
 #include "repository.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 67a2260a5eb..5698b92ae7d 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -12,6 +12,7 @@
 #include "commit.h"
 #include "delta.h"
 #include "pack.h"
+#include "path.h"
 #include "refs.h"
 #include "csum-file.h"
 #include "quote.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index cbc991086cd..4dbacd8f188 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -28,6 +28,7 @@
 #include "utf8.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "list-objects-filter-options.h"
 #include "commit-reach.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index f05617ceb14..d707ca32a61 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -21,6 +21,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "resolve-undo.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index d6e56e380cf..9ecc2513e9f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -30,6 +30,7 @@
 #include "object-store.h"
 #include "pack.h"
 #include "pack-objects.h"
+#include "path.h"
 #include "blob.h"
 #include "tree.h"
 #include "promisor-remote.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7638d779000..6bc8abcd3e1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -30,6 +30,7 @@
 #include "object-store.h"
 #include "packfile.h"
 #include "pager.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "write-or-die.h"
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a49c43864f7..ab90f821e44 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -19,6 +19,7 @@
 #include "parse-options.h"
 #include "resolve-undo.h"
 #include "string-list.h"
+#include "path.h"
 #include "pathspec.h"
 #include "read-cache.h"
 #include "run-command.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index f4331c640fc..c06858de4bf 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -12,6 +12,7 @@
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
+#include "path.h"
 #include "quote.h"
 #include "parse-options.h"
 #include "pathspec.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index d7ac108ce94..420e81008ed 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -27,6 +27,7 @@
 #include "refspec.h"
 #include "commit.h"
 #include "diffcore.h"
+#include "path.h"
 #include "revision.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index efdf2451486..0a870d90836 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -15,6 +15,7 @@
 #include "notes.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "blob.h"
 #include "pretty.h"
diff --git a/builtin/prune.c b/builtin/prune.c
index b3658b5b512..a46c5aa2b5b 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -7,6 +7,7 @@
 #include "revision.h"
 #include "reachable.h"
 #include "parse-options.h"
+#include "path.h"
 #include "progress.h"
 #include "prune-packed.h"
 #include "replace-object.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index d4261804d76..815f6135189 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -19,6 +19,7 @@
 #include "oid-array.h"
 #include "remote.h"
 #include "dir.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "rebase.h"
 #include "refs.h"
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ace1d5e8d11..91849f920f7 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -24,6 +24,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "commit.h"
 #include "diff.h"
 #include "wt-status.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 1a31a583674..d1718a3ac90 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -31,6 +31,7 @@
 #include "packfile.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "protocol.h"
 #include "commit-reach.h"
 #include "server-info.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 1e0b137d977..3794f13330d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "transport.h"
 #include "remote.h"
 #include "string-list.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 0541c3ce157..fe8d5810d48 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -6,6 +6,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "path.h"
 #include "run-command.h"
 #include "server-info.h"
 #include "sigchain.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index e0fbdc98ed3..6b266a66d30 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -16,6 +16,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "path.h"
 #include "run-command.h"
 #include "object-file.h"
 #include "object-name.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 3dc41ac3327..f947c449d14 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -26,6 +26,7 @@
 #include "branch.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
 #include "setup.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 8d8c870421d..6eb5965bee4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -16,6 +16,7 @@
 #include "quote.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "diff.h"
 #include "read-cache-ll.h"
 #include "revision.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 17567d91c88..6acba4ebb30 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "path.h"
 #include "pathspec.h"
 #include "preload-index.h"
 #include "dir.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index ce298d08945..87963d2cc0e 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -16,6 +16,7 @@
 #include "refs.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index d4c7f162ff0..1b09e5e1aa3 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -3,6 +3,7 @@
  */
 #include "builtin.h"
 #include "archive.h"
+#include "path.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "repository.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index ba5103a9331..b02d479248a 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "pkt-line.h"
 #include "parse-options.h"
+#include "path.h"
 #include "protocol.h"
 #include "replace-object.h"
 #include "upload-pack.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index b9a84988637..6ba463f6965 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -10,6 +10,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "parse-options.h"
+#include "path.h"
 #include "strvec.h"
 #include "branch.h"
 #include "read-cache-ll.h"
diff --git a/commit-graph.c b/commit-graph.c
index 843bdb458d0..25cbd66c33a 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -14,6 +14,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "oid-array.h"
+#include "path.h"
 #include "alloc.h"
 #include "hashmap.h"
 #include "replace-object.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 793073aaa72..964bc074db6 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "strbuf.h"
 #include "fsmonitor.h"
diff --git a/config.c b/config.c
index 06e6cc6f1ec..666ec73bab1 100644
--- a/config.c
+++ b/config.c
@@ -27,6 +27,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "pager.h"
+#include "path.h"
 #include "utf8.h"
 #include "dir.h"
 #include "color.h"
diff --git a/connect.c b/connect.c
index 3a0186280c4..37674f71122 100644
--- a/connect.c
+++ b/connect.c
@@ -12,6 +12,7 @@
 #include "url.h"
 #include "string-list.h"
 #include "oid-array.h"
+#include "path.h"
 #include "transport.h"
 #include "trace2.h"
 #include "strbuf.h"
diff --git a/dir.c b/dir.c
index 1e84b1e1f28..3cf3d428c7b 100644
--- a/dir.c
+++ b/dir.c
@@ -16,6 +16,7 @@
 #include "name-hash.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "path.h"
 #include "attr.h"
 #include "refs.h"
 #include "wildmatch.h"
diff --git a/environment.c b/environment.c
index 0cdd20a1589..56e8742ea66 100644
--- a/environment.c
+++ b/environment.c
@@ -21,6 +21,7 @@
 #include "strvec.h"
 #include "object-file.h"
 #include "object-store.h"
+#include "path.h"
 #include "replace-object.h"
 #include "tmp-objdir.h"
 #include "chdir-notify.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f71054fbae..207548b3e5a 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -25,6 +25,7 @@
 #include "oidset.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "path.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
 #include "fsck.h"
diff --git a/fsck.c b/fsck.c
index 3261ef9ec28..04e729953b2 100644
--- a/fsck.c
+++ b/fsck.c
@@ -3,6 +3,7 @@
 #include "date.h"
 #include "hex.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "object.h"
 #include "attr.h"
diff --git a/http-backend.c b/http-backend.c
index ac146d85c54..ddb9549ecbc 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "git-zlib.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/merge-ort.c b/merge-ort.c
index c2d2ee73eaa..eed71b04389 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -36,6 +36,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "oid-array.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "read-cache-ll.h"
 #include "revision.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 4bef9b62fa8..527dbbd010a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -27,6 +27,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "revision.h"
 #include "sparse-index.h"
diff --git a/notes-merge.c b/notes-merge.c
index 233e49e3195..4b328d852cd 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -6,6 +6,7 @@
 #include "object-file.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/object-file.c b/object-file.c
index 7c1af5c8db8..8d87720dd53 100644
--- a/object-file.c
+++ b/object-file.c
@@ -39,6 +39,7 @@
 #include "object-file.h"
 #include "object-store.h"
 #include "oidtree.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index cdffe2ce47d..623ee2a8197 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -15,6 +15,7 @@
 #include "pack-bitmap.h"
 #include "hash-lookup.h"
 #include "pack-objects.h"
+#include "path.h"
 #include "commit-reach.h"
 #include "prio-queue.h"
 #include "trace2.h"
diff --git a/pack-write.c b/pack-write.c
index 3b3ce89de6e..45681e2d7db 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -10,6 +10,7 @@
 #include "oidmap.h"
 #include "pack-objects.h"
 #include "pack-revindex.h"
+#include "path.h"
 #include "wrapper.h"
 
 void reset_pack_idx_option(struct pack_idx_option *opts)
diff --git a/read-cache.c b/read-cache.c
index edab96765df..86ada403a83 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@
 #include "mem-pool.h"
 #include "name-hash.h"
 #include "object-name.h"
+#include "path.h"
 #include "preload-index.h"
 #include "read-cache.h"
 #include "resolve-undo.h"
diff --git a/refs.c b/refs.c
index d2a98e1c21f..3c0c95ac442 100644
--- a/refs.c
+++ b/refs.c
@@ -19,6 +19,7 @@
 #include "object-name.h"
 #include "object-store.h"
 #include "object.h"
+#include "path.h"
 #include "tag.h"
 #include "submodule.h"
 #include "worktree.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 01c08207619..6fa7decec0a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -15,6 +15,7 @@
 #include "../lockfile.h"
 #include "../object.h"
 #include "../object-file.h"
+#include "../path.h"
 #include "../dir.h"
 #include "../chdir-notify.h"
 #include "../setup.h"
diff --git a/remote.c b/remote.c
index 0764fca0db9..8550056db43 100644
--- a/remote.c
+++ b/remote.c
@@ -11,6 +11,7 @@
 #include "refspec.h"
 #include "object-name.h"
 #include "object-store.h"
+#include "path.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/repository.c b/repository.c
index 67ec56a70c5..87a7a27b665 100644
--- a/repository.c
+++ b/repository.c
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
+#include "path.h"
 #include "read-cache-ll.h"
 #include "remote.h"
 #include "setup.h"
diff --git a/repository.h b/repository.h
index 763794880ed..510aa6d9a2f 100644
--- a/repository.h
+++ b/repository.h
@@ -1,8 +1,6 @@
 #ifndef REPOSITORY_H
 #define REPOSITORY_H
 
-#include "path.h"
-
 struct config_set;
 struct fsmonitor_settings;
 struct git_hash_algo;
diff --git a/rerere.c b/rerere.c
index 2fb93a51125..35b9785d573 100644
--- a/rerere.c
+++ b/rerere.c
@@ -14,6 +14,7 @@
 #include "resolve-undo.h"
 #include "ll-merge.h"
 #include "attr.h"
+#include "path.h"
 #include "pathspec.h"
 #include "object-file.h"
 #include "object-store.h"
diff --git a/sequencer.c b/sequencer.c
index 08bd0e81743..eddd38d4bed 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -23,6 +23,7 @@
 #include "utf8.h"
 #include "cache-tree.h"
 #include "diff.h"
+#include "path.h"
 #include "revision.h"
 #include "rerere.h"
 #include "merge.h"
diff --git a/server-info.c b/server-info.c
index 55aa04f00ab..85d17bbb151 100644
--- a/server-info.c
+++ b/server-info.c
@@ -9,6 +9,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "packfile.h"
+#include "path.h"
 #include "object-file.h"
 #include "object-store.h"
 #include "server-info.h"
diff --git a/setup.c b/setup.c
index 1cc1f3b3978..68041c0dc88 100644
--- a/setup.c
+++ b/setup.c
@@ -12,6 +12,7 @@
 #include "setup.h"
 #include "string-list.h"
 #include "chdir-notify.h"
+#include "path.h"
 #include "promisor-remote.h"
 #include "quote.h"
 #include "trace2.h"
diff --git a/shallow.c b/shallow.c
index f1c93e74648..45343e6a78b 100644
--- a/shallow.c
+++ b/shallow.c
@@ -11,6 +11,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "oid-array.h"
+#include "path.h"
 #include "diff.h"
 #include "revision.h"
 #include "commit-slab.h"
diff --git a/strbuf.c b/strbuf.c
index 08eec8f1d8b..d070e007f8a 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -6,6 +6,7 @@
 #include "hex.h"
 #include "object-name.h"
 #include "refs.h"
+#include "path.h"
 #include "repository.h"
 #include "string-list.h"
 #include "utf8.h"
diff --git a/submodule-config.c b/submodule-config.c
index 58dfbde9ae5..c67260a3e11 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -4,6 +4,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "path.h"
 #include "repository.h"
 #include "config.h"
 #include "submodule-config.h"
diff --git a/submodule.c b/submodule.c
index 20aa8ed0fb8..245300596ff 100644
--- a/submodule.c
+++ b/submodule.c
@@ -20,6 +20,7 @@
 #include "strvec.h"
 #include "blob.h"
 #include "thread-utils.h"
+#include "path.h"
 #include "quote.h"
 #include "remote.h"
 #include "worktree.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 6d8f844e9c7..1b30a6cba8b 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -4,6 +4,7 @@
 #include "setup.h"
 #include "worktree.h"
 #include "object-store.h"
+#include "path.h"
 #include "repository.h"
 
 struct flag_definition {
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c33a554f921..db1f7038dae 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -5,6 +5,7 @@
 #include "dir.h"
 #include "environment.h"
 #include "object-file.h"
+#include "path.h"
 #include "sigchain.h"
 #include "string-list.h"
 #include "strbuf.h"
diff --git a/worktree.c b/worktree.c
index b5ee71c5ebd..f9aa371ca70 100644
--- a/worktree.c
+++ b/worktree.c
@@ -3,6 +3,7 @@
 #include "alloc.h"
 #include "environment.h"
 #include "gettext.h"
+#include "path.h"
 #include "repository.h"
 #include "refs.h"
 #include "setup.h"
diff --git a/wt-status.c b/wt-status.c
index 6ee8567ac2d..7ada6b305f6 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -9,6 +9,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "path.h"
 #include "revision.h"
 #include "diffcore.h"
 #include "quote.h"
-- 
gitgitgadget


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

* [PATCH v3 20/28] diff.h: remove unnecessary include of oidset.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (18 preceding siblings ...)
  2023-05-16  6:33     ` [PATCH v3 19/28] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 21/28] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
                       ` (8 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that several .c files depended upon various
things that oidset included, but had omitted the direct #include for
those headers.  Add those now.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 add-interactive.c                | 2 ++
 add-patch.c                      | 1 +
 blame.h                          | 1 +
 builtin/add.c                    | 1 +
 builtin/diff-files.c             | 1 +
 builtin/diff-index.c             | 1 +
 builtin/merge-ours.c             | 1 +
 builtin/patch-id.c               | 1 +
 builtin/range-diff.c             | 1 +
 builtin/reflog.c                 | 1 +
 builtin/reset.c                  | 1 +
 builtin/rev-parse.c              | 1 +
 builtin/revert.c                 | 1 +
 builtin/shortlog.c               | 1 +
 builtin/stash.c                  | 1 +
 diff-lib.c                       | 2 ++
 diff.h                           | 4 +++-
 diffcore-break.c                 | 1 +
 diffcore-pickaxe.c               | 1 +
 line-log.c                       | 1 +
 merge.c                          | 2 ++
 patch-ids.c                      | 1 +
 pretty.c                         | 1 +
 range-diff.c                     | 1 +
 reflog-walk.c                    | 1 +
 t/helper/test-fast-rebase.c      | 1 +
 t/helper/test-revision-walking.c | 1 +
 transport-helper.c               | 1 +
 tree-diff.c                      | 1 +
 wt-status.c                      | 1 +
 30 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/add-interactive.c b/add-interactive.c
index 40f88c02051..add9a1ad436 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -4,9 +4,11 @@
 #include "config.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "preload-index.h"
 #include "read-cache-ll.h"
+#include "repository.h"
 #include "revision.h"
 #include "refs.h"
 #include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 875b96e2274..53e32482959 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -7,6 +7,7 @@
 #include "gettext.h"
 #include "object-name.h"
 #include "read-cache-ll.h"
+#include "repository.h"
 #include "strbuf.h"
 #include "run-command.h"
 #include "strvec.h"
diff --git a/blame.h b/blame.h
index b60d1d81e30..31ddc85f19e 100644
--- a/blame.h
+++ b/blame.h
@@ -2,6 +2,7 @@
 #define BLAME_H
 
 #include "commit.h"
+#include "oidset.h"
 #include "xdiff-interface.h"
 #include "revision.h"
 #include "prio-queue.h"
diff --git a/builtin/add.c b/builtin/add.c
index 43183114487..e3ca3e4edbe 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -21,6 +21,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "read-cache.h"
+#include "repository.h"
 #include "revision.h"
 #include "bulk-checkin.h"
 #include "strvec.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index b7036aa7c2b..07f6dff844c 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -9,6 +9,7 @@
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
+#include "repository.h"
 #include "revision.h"
 #include "submodule.h"
 
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 1ab8f8b6dc5..a8b2c0a4b96 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -4,6 +4,7 @@
 #include "diff-merges.h"
 #include "commit.h"
 #include "preload-index.h"
+#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 #include "submodule.h"
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index c2e519301e9..932924e5d0e 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -10,6 +10,7 @@
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
+#include "repository.h"
 
 static const char builtin_merge_ours_usage[] =
 	"git merge-ours <base>... -- HEAD <remote>...";
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 27952f1a6fd..b7118b290b1 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "diff.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "parse-options.h"
 
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 8610390d7c5..e455a4795cc 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -4,6 +4,7 @@
 #include "parse-options.h"
 #include "range-diff.h"
 #include "config.h"
+#include "repository.h"
 #include "revision.h"
 
 static const char * const builtin_range_diff_usage[] = {
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a1fa0c855f4..fc217748808 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
+#include "repository.h"
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index f947c449d14..dad2117c974 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -13,6 +13,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "tag.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 6eb5965bee4..4a219ea93bb 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -11,6 +11,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 0240ec8593b..f6f07d9b539 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "diff.h"
 #include "gettext.h"
+#include "repository.h"
 #include "revision.h"
 #include "rerere.h"
 #include "dir.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 99be9dc417d..1307ed2b88a 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -5,6 +5,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "string-list.h"
+#include "repository.h"
 #include "revision.h"
 #include "utf8.h"
 #include "mailmap.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index d3d5bb95e26..84e83e0627f 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "parse-options.h"
diff --git a/diff-lib.c b/diff-lib.c
index f3aa7f93c78..cad18099aba 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "read-cache.h"
@@ -14,6 +15,7 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "refs.h"
+#include "repository.h"
 #include "submodule.h"
 #include "symlinks.h"
 #include "trace.h"
diff --git a/diff.h b/diff.h
index 29a9cd217c2..c2e0e63609f 100644
--- a/diff.h
+++ b/diff.h
@@ -4,10 +4,12 @@
 #ifndef DIFF_H
 #define DIFF_H
 
+#include "hash-ll.h"
 #include "pathspec.h"
-#include "oidset.h"
 #include "strbuf.h"
 
+struct oidset;
+
 /**
  * The diff API is for programs that compare two sets of files (e.g. two trees,
  * one tree and the index) and present the found difference in various ways.
diff --git a/diffcore-break.c b/diffcore-break.c
index 4909dc088e6..f57ece2757d 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "hash.h"
 #include "object.h"
 #include "promisor-remote.h"
 
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 13c98a7b5e7..b195fa4eb3c 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -7,6 +7,7 @@
 #include "diffcore.h"
 #include "xdiff-interface.h"
 #include "kwset.h"
+#include "oidset.h"
 #include "pretty.h"
 #include "quote.h"
 
diff --git a/line-log.c b/line-log.c
index 6a7ac312a43..2eff914bf36 100644
--- a/line-log.c
+++ b/line-log.c
@@ -8,6 +8,7 @@
 #include "diff.h"
 #include "commit.h"
 #include "decorate.h"
+#include "repository.h"
 #include "revision.h"
 #include "xdiff-interface.h"
 #include "strbuf.h"
diff --git a/merge.c b/merge.c
index 83bcba6943e..b60925459c2 100644
--- a/merge.c
+++ b/merge.c
@@ -2,10 +2,12 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge.h"
 #include "commit.h"
+#include "repository.h"
 #include "run-command.h"
 #include "resolve-undo.h"
 #include "tree.h"
diff --git a/patch-ids.c b/patch-ids.c
index 19af7bee984..c3e1a0dd216 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "commit.h"
+#include "hash.h"
 #include "hash-lookup.h"
 #include "hex.h"
 #include "patch-ids.h"
diff --git a/pretty.c b/pretty.c
index 0bb938021ba..2cf2cbbd038 100644
--- a/pretty.c
+++ b/pretty.c
@@ -4,6 +4,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/range-diff.c b/range-diff.c
index 6a704e6f471..2e86063491e 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "pager.h"
 #include "pretty.h"
+#include "repository.h"
 #include "userdiff.h"
 #include "apply.h"
 #include "revision.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 4ba1a10c82c..d337e64431f 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
+#include "repository.h"
 #include "revision.h"
 #include "string-list.h"
 #include "reflog-walk.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index 62c5b5d704b..cac20a72b3f 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -16,6 +16,7 @@
 #include "commit.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index 0c62b9de185..f346951bc28 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -11,6 +11,7 @@
 #include "test-tool.h"
 #include "commit.h"
 #include "diff.h"
+#include "repository.h"
 #include "revision.h"
 #include "setup.h"
 
diff --git a/transport-helper.c b/transport-helper.c
index 6b816940dc6..5c0bc6a896e 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -8,6 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
+#include "repository.h"
 #include "revision.h"
 #include "remote.h"
 #include "string-list.h"
diff --git a/tree-diff.c b/tree-diff.c
index 20bb15f38d9..966946848ae 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "hash.h"
 #include "tree.h"
 #include "tree-walk.h"
 
diff --git a/wt-status.c b/wt-status.c
index 7ada6b305f6..bcd0ef80441 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "environment.h"
 #include "gettext.h"
+#include "hash.h"
 #include "hex.h"
 #include "object-name.h"
 #include "path.h"
-- 
gitgitgadget


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

* [PATCH v3 21/28] list-objects-filter-options.h: remove unneccessary include
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (19 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 20/28] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 22/28] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
                       ` (7 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 list-objects-filter-options.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index f6206125868..55fab8563d2 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -3,7 +3,6 @@
 
 #include "gettext.h"
 #include "object.h"
-#include "string-list.h"
 #include "strbuf.h"
 
 struct option;
-- 
gitgitgadget


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

* [PATCH v3 22/28] builtin.h: remove unneccessary includes
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (20 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 21/28] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 23/28] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
                       ` (6 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This also made it clear that a few .c files under builtin/ were
depending upon some headers but had forgotten to #include them.  Add the
missing direct includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin.h                  | 2 --
 builtin/check-mailmap.c    | 1 +
 builtin/commit-graph.c     | 1 +
 builtin/config.c           | 1 +
 builtin/credential-cache.c | 1 +
 builtin/for-each-ref.c     | 1 +
 builtin/init-db.c          | 1 +
 builtin/verify-pack.c      | 1 +
 8 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/builtin.h b/builtin.h
index 3e6c22eef69..d560baa6618 100644
--- a/builtin.h
+++ b/builtin.h
@@ -2,8 +2,6 @@
 #define BUILTIN_H
 
 #include "git-compat-util.h"
-#include "strbuf.h"
-#include "commit.h"
 
 /*
  * builtin API
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index 002d2941e93..b8a05b8e07b 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -4,6 +4,7 @@
 #include "ident.h"
 #include "mailmap.h"
 #include "parse-options.h"
+#include "strbuf.h"
 #include "string-list.h"
 #include "write-or-die.h"
 
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a3d00fa232b..96a8a677327 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "commit.h"
 #include "config.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/builtin/config.c b/builtin/config.c
index ff2fe8ef125..30f6d9fe67b 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -12,6 +12,7 @@
 #include "path.h"
 #include "quote.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "worktree.h"
 #include "wrapper.h"
 
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 0ffacfdd83c..ff3a47badbe 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -2,6 +2,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
+#include "strbuf.h"
 #include "wrapper.h"
 #include "write-or-die.h"
 
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index d0d6ab0fd34..15409337f83 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -5,6 +5,7 @@
 #include "object.h"
 #include "parse-options.h"
 #include "ref-filter.h"
+#include "strbuf.h"
 #include "strvec.h"
 #include "commit-reach.h"
 
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 680ef7e1837..0d8bd4d7219 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -12,6 +12,7 @@
 #include "parse-options.h"
 #include "path.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "wrapper.h"
 
 static int guess_repository_type(const char *git_dir)
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index aba92cf8af7..011dddd2dc3 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -3,6 +3,7 @@
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "strbuf.h"
 
 #define VERIFY_PACK_VERBOSE 01
 #define VERIFY_PACK_STAT_ONLY 02
-- 
gitgitgadget


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

* [PATCH v3 23/28] git-compat-util.h: remove unneccessary include of wildmatch.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (21 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 22/28] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 24/28] merge-ll: rename from ll-merge Elijah Newren via GitGitGadget
                       ` (5 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The include of wildmatch.h in git-compat-util.h was added in cebcab189aa
(Makefile: add USE_WILDMATCH to use wildmatch as fnmatch, 2013-01-01) as
a way to be able to compile-time force any calls to fnmatch() to instead
invoke wildmatch().  The defines and inline function were removed in
70a8fc999d9 (stop using fnmatch (either native or compat), 2014-02-15),
and this include in git-compat-util.h has been unnecessary ever since.

Remove the include from git-compat-util.h, but add it to the .c files
that had omitted the direct #include they needed.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                   | 1 +
 builtin/describe.c        | 1 +
 builtin/ls-remote.c       | 1 +
 builtin/name-rev.c        | 1 +
 builtin/reflog.c          | 1 +
 builtin/replace.c         | 1 +
 builtin/show-branch.c     | 1 +
 config.c                  | 1 +
 diffcore-order.c          | 1 +
 fmt-merge-msg.c           | 1 +
 git-compat-util.h         | 2 --
 log-tree.c                | 1 +
 pathspec.c                | 1 +
 refs.c                    | 1 +
 revision.c                | 1 +
 t/helper/test-wildmatch.c | 1 +
 trace2/tr2_cfg.c          | 1 +
 17 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index be58dc08d22..801f2bcc99c 100644
--- a/apply.c
+++ b/apply.c
@@ -35,6 +35,7 @@
 #include "entry.h"
 #include "setup.h"
 #include "symlinks.h"
+#include "wildmatch.h"
 #include "ws.h"
 #include "wrapper.h"
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 508e8df00ef..eb19ab0bbbe 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -22,6 +22,7 @@
 #include "object-store.h"
 #include "list-objects.h"
 #include "commit-slab.h"
+#include "wildmatch.h"
 
 #define MAX_TAGS	(FLAG_BITS - 1)
 
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index a0aadc9b8ff..fc765754305 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -7,6 +7,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "wildmatch.h"
 
 static const char * const ls_remote_usage[] = {
 	N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 593f0506a10..de9808e21c8 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -15,6 +15,7 @@
 #include "hash-lookup.h"
 #include "commit-slab.h"
 #include "commit-graph.h"
+#include "wildmatch.h"
 
 /*
  * One day.  See the 'name a rev shortly after epoch' test in t6120 when
diff --git a/builtin/reflog.c b/builtin/reflog.c
index fc217748808..79b4ff04aae 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -4,6 +4,7 @@
 #include "repository.h"
 #include "revision.h"
 #include "reachable.h"
+#include "wildmatch.h"
 #include "worktree.h"
 #include "reflog.h"
 #include "parse-options.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 6b266a66d30..a2f57a56b3e 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -24,6 +24,7 @@
 #include "replace-object.h"
 #include "repository.h"
 #include "tag.h"
+#include "wildmatch.h"
 
 static const char * const git_replace_usage[] = {
 	N_("git replace [-f] <object> <replacement>"),
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index cd215f89af8..a203f13cb0d 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -14,6 +14,7 @@
 #include "dir.h"
 #include "commit-slab.h"
 #include "date.h"
+#include "wildmatch.h"
 
 static const char* show_branch_usage[] = {
     N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
diff --git a/config.c b/config.c
index 666ec73bab1..0b2a9f1bd89 100644
--- a/config.c
+++ b/config.c
@@ -36,6 +36,7 @@
 #include "setup.h"
 #include "strvec.h"
 #include "trace2.h"
+#include "wildmatch.h"
 #include "worktree.h"
 #include "ws.h"
 #include "wrapper.h"
diff --git a/diffcore-order.c b/diffcore-order.c
index 57ccab28464..e7d20ebd2d1 100644
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -5,6 +5,7 @@
 #include "gettext.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "wildmatch.h"
 
 static char **order;
 static int order_cnt;
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 5af0d4715ba..f096b1ef549 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -15,6 +15,7 @@
 #include "fmt-merge-msg.h"
 #include "commit-reach.h"
 #include "gpg-interface.h"
+#include "wildmatch.h"
 
 static int use_branch_desc;
 static int suppress_dest_pattern_seen;
diff --git a/git-compat-util.h b/git-compat-util.h
index 5b2b99c17c5..1889da7986e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -625,8 +625,6 @@ static inline int git_has_dir_sep(const char *path)
 
 #include "compat/bswap.h"
 
-#include "wildmatch.h"
-
 struct strbuf;
 
 /* General helper functions */
diff --git a/log-tree.c b/log-tree.c
index 07d0b47b168..60b61597c42 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -26,6 +26,7 @@
 #include "range-diff.h"
 #include "strmap.h"
 #include "tree.h"
+#include "wildmatch.h"
 #include "write-or-die.h"
 
 static struct decoration name_decoration = { "object names" };
diff --git a/pathspec.c b/pathspec.c
index 0baa85384f8..ad9b9e7dc74 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -12,6 +12,7 @@
 #include "strvec.h"
 #include "symlinks.h"
 #include "quote.h"
+#include "wildmatch.h"
 
 /*
  * Finds which of the given pathspecs match items in the index.
diff --git a/refs.c b/refs.c
index 3c0c95ac442..5f76da35673 100644
--- a/refs.c
+++ b/refs.c
@@ -29,6 +29,7 @@
 #include "sigchain.h"
 #include "date.h"
 #include "commit.h"
+#include "wildmatch.h"
 #include "wrapper.h"
 
 /*
diff --git a/revision.c b/revision.c
index 66a1fece0df..d4b4b34fd80 100644
--- a/revision.c
+++ b/revision.c
@@ -46,6 +46,7 @@
 #include "list-objects-filter-options.h"
 #include "resolve-undo.h"
 #include "parse-options.h"
+#include "wildmatch.h"
 
 volatile show_early_output_fn_t show_early_output;
 
diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c
index a95bb4da9b1..b4ff5f986ae 100644
--- a/t/helper/test-wildmatch.c
+++ b/t/helper/test-wildmatch.c
@@ -1,4 +1,5 @@
 #include "test-tool.h"
+#include "wildmatch.h"
 
 int cmd__wildmatch(int argc, const char **argv)
 {
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index 78cfc15d52d..db817a80c53 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -4,6 +4,7 @@
 #include "trace2.h"
 #include "trace2/tr2_cfg.h"
 #include "trace2/tr2_sysenv.h"
+#include "wildmatch.h"
 
 static struct strbuf **tr2_cfg_patterns;
 static int tr2_cfg_count_patterns;
-- 
gitgitgadget


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

* [PATCH v3 24/28] merge-ll: rename from ll-merge
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (22 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 23/28] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 25/28] khash: name the structs that khash declares Elijah Newren via GitGitGadget
                       ` (4 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

A long term (but rather minor) pet-peeve of mine was the name
ll-merge.[ch].  I thought it made it harder to realize what stuff was
related to merging when I was working on the merge machinery and trying
to improve it.

Further, back in d1cbe1e6d8a ("hash-ll.h: split out of hash.h to remove
dependency on repository.h", 2023-04-22), we have split the portions of
hash.h that do not depend upon repository.h into a "hash-ll.h" (due to
the recommendation to use "ll" for "low-level" in its name[1], but which
I used as a suffix precisely because of my distaste for "ll-merge").
When we discussed adding additional "*-ll.h" files, a request was made
that we use "ll" consistently as either a prefix or a suffix.  Since it
is already in use as both a prefix and a suffix, the only way to do so
is to rename some files.

Besides my distaste for the ll-merge.[ch] name, let me also note that
the files
  ll-fsmonitor.h, ll-hash.h, ll-merge.h, ll-object-store.h, ll-read-cache.h
would have essentially nothing to do with each other and make no sense
to group.  But giving them the common "ll-" prefix would group them.  Using
"-ll" as a suffix thus seems just much more logical to me.  Rename
ll-merge.[ch] to merge-ll.[ch] to achieve this consistency, and to
ensure we get a more logical grouping of files.

[1] https://lore.kernel.org/git/kl6lsfcu1g8w.fsf@chooglen-macbookpro.roam.corp.google.com/

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/technical/api-merge.txt | 4 ++--
 Makefile                              | 2 +-
 apply.c                               | 2 +-
 builtin/checkout.c                    | 2 +-
 convert.c                             | 2 +-
 diff.c                                | 2 +-
 merge-blobs.c                         | 2 +-
 ll-merge.c => merge-ll.c              | 2 +-
 ll-merge.h => merge-ll.h              | 0
 merge-ort.c                           | 2 +-
 merge-recursive.c                     | 2 +-
 notes-merge.c                         | 2 +-
 rerere.c                              | 2 +-
 13 files changed, 13 insertions(+), 13 deletions(-)
 rename ll-merge.c => merge-ll.c (99%)
 rename ll-merge.h => merge-ll.h (100%)

diff --git a/Documentation/technical/api-merge.txt b/Documentation/technical/api-merge.txt
index 487d4d83fff..c2ba01828c6 100644
--- a/Documentation/technical/api-merge.txt
+++ b/Documentation/technical/api-merge.txt
@@ -28,9 +28,9 @@ and `diff.c` for examples.
 
 * `struct ll_merge_options`
 
-Check ll-merge.h for details.
+Check merge-ll.h for details.
 
 Low-level (single file) merge
 -----------------------------
 
-Check ll-merge.h for details.
+Check merge-ll.h for details.
diff --git a/Makefile b/Makefile
index 2d180abc5ca..045e2187c41 100644
--- a/Makefile
+++ b/Makefile
@@ -1051,7 +1051,6 @@ LIB_OBJS += linear-assignment.o
 LIB_OBJS += list-objects-filter-options.o
 LIB_OBJS += list-objects-filter.o
 LIB_OBJS += list-objects.o
-LIB_OBJS += ll-merge.o
 LIB_OBJS += lockfile.o
 LIB_OBJS += log-tree.o
 LIB_OBJS += ls-refs.o
@@ -1060,6 +1059,7 @@ LIB_OBJS += mailmap.o
 LIB_OBJS += match-trees.o
 LIB_OBJS += mem-pool.o
 LIB_OBJS += merge-blobs.o
+LIB_OBJS += merge-ll.o
 LIB_OBJS += merge-ort.o
 LIB_OBJS += merge-ort-wrappers.o
 LIB_OBJS += merge-recursive.o
diff --git a/apply.c b/apply.c
index 801f2bcc99c..2f66f93fec5 100644
--- a/apply.c
+++ b/apply.c
@@ -21,7 +21,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "lockfile.h"
 #include "name-hash.h"
 #include "object-name.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 716dcd4cae1..11e2359c548 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -13,7 +13,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "hook.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "lockfile.h"
 #include "mem-pool.h"
 #include "merge-recursive.h"
diff --git a/convert.c b/convert.c
index 9e89f660308..1f2cfc5f457 100644
--- a/convert.c
+++ b/convert.c
@@ -15,7 +15,7 @@
 #include "sub-process.h"
 #include "trace.h"
 #include "utf8.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "wrapper.h"
 
 /*
diff --git a/diff.c b/diff.c
index 5e81dc0d02d..9d6b88ece90 100644
--- a/diff.c
+++ b/diff.c
@@ -26,7 +26,7 @@
 #include "submodule.h"
 #include "hashmap.h"
 #include "mem-pool.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "string-list.h"
 #include "strvec.h"
 #include "graph.h"
diff --git a/merge-blobs.c b/merge-blobs.c
index 5632ff6abb6..40c48e3eba6 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "run-command.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "blob.h"
 #include "merge-blobs.h"
 #include "object-store.h"
diff --git a/ll-merge.c b/merge-ll.c
similarity index 99%
rename from ll-merge.c
rename to merge-ll.c
index 1993530688e..c076d048407 100644
--- a/ll-merge.c
+++ b/merge-ll.c
@@ -10,7 +10,7 @@
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "quote.h"
 #include "strbuf.h"
 #include "wrapper.h"
diff --git a/ll-merge.h b/merge-ll.h
similarity index 100%
rename from ll-merge.h
rename to merge-ll.h
diff --git a/merge-ort.c b/merge-ort.c
index eed71b04389..f4522951323 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -30,7 +30,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "entry.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "match-trees.h"
 #include "mem-pool.h"
 #include "object-name.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 527dbbd010a..35e1e7e1bef 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -20,7 +20,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "lockfile.h"
 #include "match-trees.h"
 #include "name-hash.h"
diff --git a/notes-merge.c b/notes-merge.c
index 4b328d852cd..4be11a01550 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -12,7 +12,7 @@
 #include "diffcore.h"
 #include "hex.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "dir.h"
 #include "notes.h"
 #include "notes-merge.h"
diff --git a/rerere.c b/rerere.c
index 35b9785d573..3584fecb07c 100644
--- a/rerere.c
+++ b/rerere.c
@@ -12,7 +12,7 @@
 #include "xdiff-interface.h"
 #include "dir.h"
 #include "resolve-undo.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
 #include "attr.h"
 #include "path.h"
 #include "pathspec.h"
-- 
gitgitgadget


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

* [PATCH v3 25/28] khash: name the structs that khash declares
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (23 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 24/28] merge-ll: rename from ll-merge Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 26/28] object-store-ll.h: split this header out of object-store.h Elijah Newren via GitGitGadget
                       ` (3 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

khash.h lets you instantiate custom hash types that map between two
types. These are defined as a struct, as you might expect, and khash
typedef's that to kh_foo_t. But it declares the struct anonymously,
which doesn't give a name to the struct type itself; there is no
"struct kh_foo". This has two small downsides:

  - when using khash, we declare "kh_foo_t *the_foo".  This is
    unlike our usual naming style, which is "struct kh_foo *the_foo".

  - you can't forward-declare a typedef of an unnamed struct type in
    C. So we might do something like this in a header file:

        struct kh_foo;
        struct bar {
                struct kh_foo *the_foo;
        };

    to avoid having to include the header that defines the real
    kh_foo. But that doesn't work with the typedef'd name. Without the
    "struct" keyword, the compiler doesn't know we mean that kh_foo is
    a type.

So let's always give khash structs the name that matches our
conventions ("struct kh_foo" to match "kh_foo_t"). We'll keep doing
the typedef to retain compatibility with existing callers.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 khash.h        | 2 +-
 object-store.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/khash.h b/khash.h
index 56241e6a5c9..a0a08dad8b7 100644
--- a/khash.h
+++ b/khash.h
@@ -62,7 +62,7 @@ static inline khint_t __ac_X31_hash_string(const char *s)
 static const double __ac_HASH_UPPER = 0.77;
 
 #define __KHASH_TYPE(name, khkey_t, khval_t) \
-	typedef struct { \
+	typedef struct kh_##name { \
 		khint_t n_buckets, size, n_occupied, upper_bound; \
 		khint32_t *flags; \
 		khkey_t *keys; \
diff --git a/object-store.h b/object-store.h
index 12415e5ea73..05803a03e92 100644
--- a/object-store.h
+++ b/object-store.h
@@ -164,7 +164,7 @@ struct raw_object_store {
 	 */
 	struct object_directory *odb;
 	struct object_directory **odb_tail;
-	kh_odb_path_map_t *odb_by_path;
+	struct kh_odb_path_map *odb_by_path;
 
 	int loaded_alternates;
 
-- 
gitgitgadget


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

* [PATCH v3 26/28] object-store-ll.h: split this header out of object-store.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (24 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 25/28] khash: name the structs that khash declares Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 27/28] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
                       ` (2 subsequent siblings)
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

The vast majority of files including object-store.h did not need dir.h
nor khash.h.  Split the header into two files, and let most just depend
upon object-store-ll.h, while letting the two callers that need it
depend on the full object-store.h.

After this patch:
    $ git grep -h include..object-store | sort | uniq -c
          2 #include "object-store.h"
        129 #include "object-store-ll.h"

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 apply.c                       |   2 +-
 archive-tar.c                 |   2 +-
 archive-zip.c                 |   2 +-
 archive.c                     |   2 +-
 attr.c                        |   2 +-
 bisect.c                      |   2 +-
 blame.c                       |   2 +-
 builtin/blame.c               |   2 +-
 builtin/cat-file.c            |   2 +-
 builtin/checkout.c            |   2 +-
 builtin/clone.c               |   2 +-
 builtin/commit-graph.c        |   2 +-
 builtin/commit-tree.c         |   2 +-
 builtin/count-objects.c       |   2 +-
 builtin/describe.c            |   2 +-
 builtin/difftool.c            |   2 +-
 builtin/fast-export.c         |   2 +-
 builtin/fast-import.c         |   2 +-
 builtin/fetch.c               |   2 +-
 builtin/fsck.c                |   2 +-
 builtin/gc.c                  |   2 +-
 builtin/grep.c                |   2 +-
 builtin/hash-object.c         |   3 +-
 builtin/index-pack.c          |   3 +-
 builtin/log.c                 |   2 +-
 builtin/ls-tree.c             |   2 +-
 builtin/merge-tree.c          |   2 +-
 builtin/mktag.c               |   3 +-
 builtin/mktree.c              |   3 +-
 builtin/multi-pack-index.c    |   3 +-
 builtin/notes.c               |   2 +-
 builtin/pack-objects.c        |   2 +-
 builtin/pack-redundant.c      |   2 +-
 builtin/prune.c               |   3 +-
 builtin/receive-pack.c        |   2 +-
 builtin/remote.c              |   2 +-
 builtin/repack.c              |   2 +-
 builtin/replace.c             |   2 +-
 builtin/rev-list.c            |   2 +-
 builtin/show-ref.c            |   2 +-
 builtin/submodule--helper.c   |   2 +-
 builtin/tag.c                 |   2 +-
 builtin/unpack-file.c         |   2 +-
 builtin/unpack-objects.c      |   2 +-
 builtin/verify-commit.c       |   2 +-
 bulk-checkin.c                |   2 +-
 bundle-uri.c                  |   2 +-
 bundle.c                      |   2 +-
 cache-tree.c                  |   2 +-
 combine-diff.c                |   2 +-
 commit-graph.c                |   2 +-
 commit-graph.h                |   2 +-
 commit.c                      |   2 +-
 config.c                      |   2 +-
 connected.c                   |   2 +-
 convert.c                     |   2 +-
 diagnose.c                    |   2 +-
 diff.c                        |   2 +-
 diffcore-rename.c             |   2 +-
 dir.c                         |   2 +-
 entry.c                       |   2 +-
 environment.c                 |   2 +-
 fetch-pack.c                  |   2 +-
 fmt-merge-msg.c               |   2 +-
 fsck.c                        |   3 +-
 grep.c                        |   2 +-
 http-backend.c                |   2 +-
 http-push.c                   |   2 +-
 http-walker.c                 |   2 +-
 http.c                        |   2 +-
 list-objects-filter.c         |   2 +-
 list-objects.c                |   2 +-
 log-tree.c                    |   2 +-
 mailmap.c                     |   2 +-
 match-trees.c                 |   3 +-
 merge-blobs.c                 |   2 +-
 merge-ort.c                   |   2 +-
 merge-recursive.c             |   2 +-
 midx.c                        |   2 +-
 notes-cache.c                 |   3 +-
 notes-merge.c                 |   2 +-
 notes.c                       |   2 +-
 object-name.c                 |   2 +-
 object-store-ll.h             | 533 ++++++++++++++++++++++++++++++++++
 object-store.h                | 528 +--------------------------------
 oss-fuzz/fuzz-pack-idx.c      |   2 +-
 pack-bitmap-write.c           |   2 +-
 pack-bitmap.c                 |   2 +-
 pack-check.c                  |   2 +-
 pack-mtimes.c                 |   3 +-
 pack-objects.h                |   2 +-
 pack-revindex.c               |   3 +-
 pack-write.c                  |   1 +
 packfile.c                    |   2 +-
 path.c                        |   2 +-
 promisor-remote.c             |   2 +-
 protocol-caps.c               |   2 +-
 prune-packed.c                |   2 +-
 reachable.c                   |   2 +-
 read-cache.c                  |   2 +-
 ref-filter.c                  |   2 +-
 reflog.c                      |   2 +-
 refs.c                        |   2 +-
 remote.c                      |   2 +-
 replace-object.c              |   2 +-
 replace-object.h              |   2 +-
 repository.c                  |   2 +-
 rerere.c                      |   2 +-
 revision.c                    |   2 +-
 send-pack.c                   |   2 +-
 sequencer.c                   |   2 +-
 server-info.c                 |   2 +-
 shallow.c                     |   2 +-
 streaming.c                   |   2 +-
 submodule-config.c            |   2 +-
 submodule.c                   |   2 +-
 t/helper/test-pack-mtimes.c   |   2 +-
 t/helper/test-partial-clone.c |   2 +-
 t/helper/test-read-graph.c    |   2 +-
 t/helper/test-read-midx.c     |   2 +-
 t/helper/test-ref-store.c     |   3 +-
 t/helper/test-repository.c    |   2 +-
 tag.c                         |   2 +-
 tmp-objdir.c                  |   2 +-
 transport.c                   |   2 +-
 tree-walk.c                   |   2 +-
 tree.c                        |   2 +-
 unpack-trees.c                |   2 +-
 upload-pack.c                 |   2 +-
 walker.c                      |   3 +-
 xdiff-interface.c             |   3 +-
 131 files changed, 677 insertions(+), 655 deletions(-)
 create mode 100644 object-store-ll.h

diff --git a/apply.c b/apply.c
index 2f66f93fec5..8bd0109fcc8 100644
--- a/apply.c
+++ b/apply.c
@@ -12,7 +12,7 @@
 #include "alloc.h"
 #include "base85.h"
 #include "config.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index 4cd81d8161e..fc06ff4c5d6 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -9,7 +9,7 @@
 #include "hex.h"
 #include "tar.h"
 #include "archive.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "streaming.h"
 #include "run-command.h"
 #include "write-or-die.h"
diff --git a/archive-zip.c b/archive-zip.c
index d0d065a312e..b4382640966 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -9,7 +9,7 @@
 #include "hex.h"
 #include "streaming.h"
 #include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "userdiff.h"
 #include "write-or-die.h"
 #include "xdiff-interface.h"
diff --git a/archive.c b/archive.c
index 802a34d6b91..0e5065fd505 100644
--- a/archive.c
+++ b/archive.c
@@ -10,7 +10,7 @@
 #include "pretty.h"
 #include "setup.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 435b51e11ff..f178190c5de 100644
--- a/attr.c
+++ b/attr.c
@@ -19,7 +19,7 @@
 #include "quote.h"
 #include "read-cache-ll.h"
 #include "revision.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index 9f7cf0be073..1be8e0a2711 100644
--- a/bisect.c
+++ b/bisect.c
@@ -18,7 +18,7 @@
 #include "commit-slab.h"
 #include "commit-reach.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "dir.h"
 
diff --git a/blame.c b/blame.c
index b74ee70decf..1d25cd29fce 100644
--- a/blame.c
+++ b/blame.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "cache-tree.h"
 #include "mergesort.h"
 #include "convert.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 2df6039a6e0..e811e7fbfb1 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -29,7 +29,7 @@
 #include "dir.h"
 #include "progress.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "blame.h"
 #include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9646e7209ca..48ccca95a1a 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -21,7 +21,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 11e2359c548..fd6ee8c2723 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -18,7 +18,7 @@
 #include "mem-pool.h"
 #include "merge-recursive.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "path.h"
 #include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 6c5cb33f6a9..687a686269a 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -23,7 +23,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 96a8a677327..48fa9f20c97 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -9,7 +9,7 @@
 #include "parse-options.h"
 #include "repository.h"
 #include "commit-graph.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "progress.h"
 #include "replace-object.h"
 #include "tag.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d2121f30d45..02625e71761 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -8,7 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "commit.h"
 #include "tree.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index c9f82d0bce9..97cdfb0ac57 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -14,7 +14,7 @@
 #include "parse-options.h"
 #include "quote.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static unsigned long garbage;
 static off_t size_garbage;
diff --git a/builtin/describe.c b/builtin/describe.c
index eb19ab0bbbe..7ce23e1b8e6 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
 #include "setup.h"
 #include "strvec.h"
 #include "run-command.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "list-objects.h"
 #include "commit-slab.h"
 #include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 4a22de3eddb..e2c9ab7d5d7 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -28,7 +28,7 @@
 #include "strbuf.h"
 #include "lockfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "dir.h"
 #include "entry.h"
 #include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 5f3ffd6912f..56dc69fac18 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "object.h"
 #include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 5698b92ae7d..2ee19c73733 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -21,7 +21,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "mem-pool.h"
 #include "commit-reach.h"
 #include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4dbacd8f188..86d409a6de3 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -11,7 +11,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oidset.h"
 #include "oid-array.h"
 #include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index d707ca32a61..a04c15e5e81 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -20,7 +20,7 @@
 #include "packfile.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index 9ecc2513e9f..7484946c506 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -27,7 +27,7 @@
 #include "commit-graph.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack.h"
 #include "pack-objects.h"
 #include "path.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 6bc8abcd3e1..72e70b3a48d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -27,7 +27,7 @@
 #include "submodule-config.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "pager.h"
 #include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index a3801211666..5ffec99dcea 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -10,12 +10,13 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
 #include "exec-cmd.h"
 #include "setup.h"
+#include "strbuf.h"
 #include "write-or-die.h"
 
 /*
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb67e166559..820860265d0 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -14,12 +14,13 @@
 #include "progress.h"
 #include "fsck.h"
 #include "exec-cmd.h"
+#include "strbuf.h"
 #include "streaming.h"
 #include "thread-utils.h"
 #include "packfile.h"
 #include "pack-revindex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
diff --git a/builtin/log.c b/builtin/log.c
index 676de107d61..d6543ba1f63 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -14,7 +14,7 @@
 #include "refs.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "color.h"
 #include "commit.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index c06858de4bf..4e17f13648e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -8,7 +8,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index aa8040c2a6a..23d7e98db0d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -9,7 +9,7 @@
 #include "commit-reach.h"
 #include "merge-ort.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "repository.h"
 #include "blob.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 44fa56eff38..43e2766db49 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -2,10 +2,11 @@
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "strbuf.h"
 #include "tag.h"
 #include "replace-object.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "fsck.h"
 #include "config.h"
 
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 09a7bd5c5c2..0eea810c7ea 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -8,9 +8,10 @@
 #include "gettext.h"
 #include "hex.h"
 #include "quote.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "parse-options.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static struct treeent {
 	unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 5bb71bce08d..a31dde1db9e 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -5,8 +5,9 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
+#include "strbuf.h"
 #include "trace2.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 #define BUILTIN_MIDX_WRITE_USAGE \
 	N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
diff --git a/builtin/notes.c b/builtin/notes.c
index 0a870d90836..0a19796f734 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -14,7 +14,7 @@
 #include "hex.h"
 #include "notes.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a5b466839ba..aa595f6a4a4 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -34,7 +34,7 @@
 #include "list.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "dir.h"
 #include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 43e9d12dfdc..4c735ba069c 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -11,7 +11,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 #define BLKSIZE 512
 
diff --git a/builtin/prune.c b/builtin/prune.c
index a46c5aa2b5b..cfb863ae848 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
+#include "dir.h"
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
@@ -13,7 +14,7 @@
 #include "replace-object.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "shallow.h"
 
 static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index d1718a3ac90..91caaf87066 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -30,7 +30,7 @@
 #include "oidset.h"
 #include "packfile.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "protocol.h"
 #include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 3794f13330d..7d96687ec74 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -11,7 +11,7 @@
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "strvec.h"
 #include "commit-reach.h"
 #include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index fe8d5810d48..6c896c9c805 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -16,7 +16,7 @@
 #include "midx.h"
 #include "packfile.h"
 #include "prune-packed.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "shallow.h"
 #include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index a2f57a56b3e..20c67a58890 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -20,7 +20,7 @@
 #include "run-command.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "repository.h"
 #include "tag.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 8029f3de53c..ff715d6918f 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -12,7 +12,7 @@
 #include "object.h"
 #include "object-name.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack.h"
 #include "pack-bitmap.h"
 #include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index e07e9ca862f..5110814f796 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "tag.h"
 #include "string-list.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6acba4ebb30..baf6ff88c3c 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -29,7 +29,7 @@
 #include "diff.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "advice.h"
 #include "branch.h"
 #include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 87963d2cc0e..076f832802c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -15,7 +15,7 @@
 #include "hex.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "tag.h"
 #include "run-command.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b35a4b9dfee..6842a6c4996 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -2,7 +2,7 @@
 #include "config.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "wrapper.h"
 
 static char *create_temp_file(struct object_id *oid)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 85baf6a131a..b4b46ae7291 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "git-zlib.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index aa34fb896ac..9680b587013 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -9,7 +9,7 @@
 #include "config.h"
 #include "gettext.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "commit.h"
 #include "run-command.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index d843279715c..e2f71db0f60 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -16,7 +16,7 @@
 #include "tmp-objdir.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "wrapper.h"
 
 static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 1b62902f014..a70c8887fd1 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -4,7 +4,7 @@
 #include "copy.h"
 #include "environment.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "refs.h"
 #include "run-command.h"
 #include "hashmap.h"
diff --git a/bundle.c b/bundle.c
index a5505368de5..8d5936c4212 100644
--- a/bundle.c
+++ b/bundle.c
@@ -4,7 +4,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "object.h"
 #include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index 077932c2db5..84d7491420e 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -8,7 +8,7 @@
 #include "cache-tree.h"
 #include "bulk-checkin.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "promisor-remote.h"
diff --git a/combine-diff.c b/combine-diff.c
index 1e3cd7fb170..11e9d7494a1 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "convert.h"
 #include "blob.h"
diff --git a/commit-graph.c b/commit-graph.c
index 25cbd66c33a..9e989f43491 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -12,7 +12,7 @@
 #include "hash-lookup.h"
 #include "commit-graph.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "path.h"
 #include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 83aaa1dbb92..5e534f0fcc8 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
 #ifndef COMMIT_GRAPH_H
 #define COMMIT_GRAPH_H
 
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oidset.h"
 
 #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index 10676165a1d..8dfc298d6e6 100644
--- a/commit.c
+++ b/commit.c
@@ -7,7 +7,7 @@
 #include "hex.h"
 #include "repository.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pkt-line.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/config.c b/config.c
index 0b2a9f1bd89..e08e2332a68 100644
--- a/config.c
+++ b/config.c
@@ -25,7 +25,7 @@
 #include "hashmap.h"
 #include "string-list.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pager.h"
 #include "path.h"
 #include "utf8.h"
diff --git a/connected.c b/connected.c
index d672521da41..8f89376dbcf 100644
--- a/connected.c
+++ b/connected.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "connected.h"
diff --git a/convert.c b/convert.c
index 1f2cfc5f457..0010828386f 100644
--- a/convert.c
+++ b/convert.c
@@ -5,7 +5,7 @@
 #include "copy.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff --git a/diagnose.c b/diagnose.c
index c8c7ebcfa39..8430064000b 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "strvec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "parse-options.h"
 #include "write-or-die.h"
diff --git a/diff.c b/diff.c
index 9d6b88ece90..36451b444b8 100644
--- a/diff.c
+++ b/diff.c
@@ -20,7 +20,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "userdiff.h"
 #include "submodule-config.h"
 #include "submodule.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 8e2e7a3ad73..926b554bd59 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -6,7 +6,7 @@
 #include "alloc.h"
 #include "diff.h"
 #include "diffcore.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hashmap.h"
 #include "mem-pool.h"
 #include "oid-array.h"
diff --git a/dir.c b/dir.c
index 3cf3d428c7b..fada2713b9e 100644
--- a/dir.c
+++ b/dir.c
@@ -15,7 +15,7 @@
 #include "gettext.h"
 #include "name-hash.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "attr.h"
 #include "refs.h"
diff --git a/entry.c b/entry.c
index 041f5cf212d..f9a7c726a4d 100644
--- a/entry.c
+++ b/entry.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "blob.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "dir.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/environment.c b/environment.c
index 56e8742ea66..5e9b331279f 100644
--- a/environment.c
+++ b/environment.c
@@ -20,7 +20,7 @@
 #include "commit.h"
 #include "strvec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "replace-object.h"
 #include "tmp-objdir.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 207548b3e5a..a432eacab99 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
 #include "oid-array.h"
 #include "oidset.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "connected.h"
 #include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index f096b1ef549..4da6c7a8bda 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -4,7 +4,7 @@
 #include "environment.h"
 #include "refs.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "diff.h"
 #include "diff-merges.h"
 #include "hex.h"
diff --git a/fsck.c b/fsck.c
index 04e729953b2..a219d6f2c0a 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,8 +1,9 @@
 #include "git-compat-util.h"
 #include "alloc.h"
 #include "date.h"
+#include "dir.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "object.h"
diff --git a/grep.c b/grep.c
index f00986c451a..ebcd6474788 100644
--- a/grep.c
+++ b/grep.c
@@ -3,7 +3,7 @@
 #include "gettext.h"
 #include "grep.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pretty.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index ddb9549ecbc..e1969c05dc6 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -16,7 +16,7 @@
 #include "url.h"
 #include "strvec.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "protocol.h"
 #include "date.h"
 #include "wrapper.h"
diff --git a/http-push.c b/http-push.c
index 29cf9db34e3..9ab2383d2b4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -18,7 +18,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit-reach.h"
 
 #ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index bba306b2d5e..78d99f7c4b0 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -7,7 +7,7 @@
 #include "list.h"
 #include "transport.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct alt_base {
 	char *base;
diff --git a/http.c b/http.c
index bb58bb3e6a3..25e4c8a1ae9 100644
--- a/http.c
+++ b/http.c
@@ -18,7 +18,7 @@
 #include "protocol.h"
 #include "string-list.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
 static int trace_curl_data = 1;
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 5d270ce5987..e075a66c99d 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -16,7 +16,7 @@
 #include "oidmap.h"
 #include "oidset.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 /* Remember to update object flag allocation in object.h */
 /*
diff --git a/list-objects.c b/list-objects.c
index eecca721ac0..672a4cd5298 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -12,7 +12,7 @@
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "trace.h"
 
 struct traversal_context {
diff --git a/log-tree.c b/log-tree.c
index 60b61597c42..f807e286c88 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -5,7 +5,7 @@
 #include "environment.h"
 #include "hex.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "repository.h"
 #include "tmp-objdir.h"
 #include "commit.h"
diff --git a/mailmap.c b/mailmap.c
index 5dc5223c430..3d6a5e9400f 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -3,7 +3,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 
 const char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 6bc8eb76477..0885ac681cd 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,9 +1,10 @@
 #include "git-compat-util.h"
 #include "hex.h"
 #include "match-trees.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "tree-walk.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static int score_missing(unsigned mode)
 {
diff --git a/merge-blobs.c b/merge-blobs.c
index 40c48e3eba6..9293cbf75c8 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
 #include "merge-ll.h"
 #include "blob.h"
 #include "merge-blobs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
diff --git a/merge-ort.c b/merge-ort.c
index f4522951323..63786c81ece 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -34,7 +34,7 @@
 #include "match-trees.h"
 #include "mem-pool.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "path.h"
 #include "promisor-remote.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 35e1e7e1bef..43f6b2d0364 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -26,7 +26,7 @@
 #include "name-hash.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "revision.h"
diff --git a/midx.c b/midx.c
index b500174d1f3..db459e448b7 100644
--- a/midx.c
+++ b/midx.c
@@ -9,7 +9,7 @@
 #include "lockfile.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hash-lookup.h"
 #include "midx.h"
 #include "progress.h"
diff --git a/notes-cache.c b/notes-cache.c
index 14288caf98f..0e1d5b1ac7a 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,10 +1,11 @@
 #include "git-compat-util.h"
 #include "notes-cache.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pretty.h"
 #include "repository.h"
 #include "commit.h"
 #include "refs.h"
+#include "strbuf.h"
 
 static int notes_cache_match_validity(struct repository *r,
 				      const char *ref,
diff --git a/notes-merge.c b/notes-merge.c
index 4be11a01550..071947894ed 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -5,7 +5,7 @@
 #include "refs.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
 #include "diff.h"
diff --git a/notes.c b/notes.c
index 02f1aa39ae1..4d2836a7c76 100644
--- a/notes.c
+++ b/notes.c
@@ -4,7 +4,7 @@
 #include "hex.h"
 #include "notes.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "tree.h"
 #include "utf8.h"
diff --git a/object-name.c b/object-name.c
index 45f4d51305b..7e96c97051e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -17,7 +17,7 @@
 #include "oidtree.h"
 #include "packfile.h"
 #include "pretty.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/object-store-ll.h b/object-store-ll.h
new file mode 100644
index 00000000000..e8f22cdb1b5
--- /dev/null
+++ b/object-store-ll.h
@@ -0,0 +1,533 @@
+#ifndef OBJECT_STORE_LL_H
+#define OBJECT_STORE_LL_H
+
+#include "hashmap.h"
+#include "object.h"
+#include "list.h"
+#include "thread-utils.h"
+#include "oidset.h"
+
+struct oidmap;
+struct oidtree;
+struct strbuf;
+
+struct object_directory {
+	struct object_directory *next;
+
+	/*
+	 * Used to store the results of readdir(3) calls when we are OK
+	 * sacrificing accuracy due to races for speed. That includes
+	 * object existence with OBJECT_INFO_QUICK, as well as
+	 * our search for unique abbreviated hashes. Don't use it for tasks
+	 * requiring greater accuracy!
+	 *
+	 * Be sure to call odb_load_loose_cache() before using.
+	 */
+	uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
+	struct oidtree *loose_objects_cache;
+
+	/*
+	 * This is a temporary object store created by the tmp_objdir
+	 * facility. Disable ref updates since the objects in the store
+	 * might be discarded on rollback.
+	 */
+	int disable_ref_updates;
+
+	/*
+	 * This object store is ephemeral, so there is no need to fsync.
+	 */
+	int will_destroy;
+
+	/*
+	 * Path to the alternative object store. If this is a relative path,
+	 * it is relative to the current working directory.
+	 */
+	char *path;
+};
+
+struct input_stream {
+	const void *(*read)(struct input_stream *, unsigned long *len);
+	void *data;
+	int is_finished;
+};
+
+void prepare_alt_odb(struct repository *r);
+int has_alt_odb(struct repository *r);
+char *compute_alternate_path(const char *path, struct strbuf *err);
+struct object_directory *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct object_directory *, void *);
+int foreach_alt_odb(alt_odb_fn, void*);
+typedef void alternate_ref_fn(const struct object_id *oid, void *);
+void for_each_alternate_ref(alternate_ref_fn, void *);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void add_to_alternates_file(const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternates (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void add_to_alternates_memory(const char *dir);
+
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary object directory.
+ */
+struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+
+/*
+ * Restore a previous ODB replaced by set_temporary_main_odb.
+ */
+void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+
+/*
+ * Populate and return the loose object cache array corresponding to the
+ * given object ID.
+ */
+struct oidtree *odb_loose_cache(struct object_directory *odb,
+				  const struct object_id *oid);
+
+/* Empty the loose object cache for the specified object directory. */
+void odb_clear_loose_cache(struct object_directory *odb);
+
+/* Clear and free the specified object directory */
+void free_object_directory(struct object_directory *odb);
+
+struct packed_git {
+	struct hashmap_entry packmap_ent;
+	struct packed_git *next;
+	struct list_head mru;
+	struct pack_window *windows;
+	off_t pack_size;
+	const void *index_data;
+	size_t index_size;
+	uint32_t num_objects;
+	uint32_t crc_offset;
+	struct oidset bad_objects;
+	int index_version;
+	time_t mtime;
+	int pack_fd;
+	int index;              /* for builtin/pack-objects.c */
+	unsigned pack_local:1,
+		 pack_keep:1,
+		 pack_keep_in_core:1,
+		 freshened:1,
+		 do_not_close:1,
+		 pack_promisor:1,
+		 multi_pack_index:1,
+		 is_cruft:1;
+	unsigned char hash[GIT_MAX_RAWSZ];
+	struct revindex_entry *revindex;
+	const uint32_t *revindex_data;
+	const uint32_t *revindex_map;
+	size_t revindex_size;
+	/*
+	 * mtimes_map points at the beginning of the memory mapped region of
+	 * this pack's corresponding .mtimes file, and mtimes_size is the size
+	 * of that .mtimes file
+	 */
+	const uint32_t *mtimes_map;
+	size_t mtimes_size;
+	/* something like ".git/objects/pack/xxxxx.pack" */
+	char pack_name[FLEX_ARRAY]; /* more */
+};
+
+struct multi_pack_index;
+
+static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
+				     const struct hashmap_entry *entry,
+				     const struct hashmap_entry *entry2,
+				     const void *keydata)
+{
+	const char *key = keydata;
+	const struct packed_git *pg1, *pg2;
+
+	pg1 = container_of(entry, const struct packed_git, packmap_ent);
+	pg2 = container_of(entry2, const struct packed_git, packmap_ent);
+
+	return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
+}
+
+struct raw_object_store {
+	/*
+	 * Set of all object directories; the main directory is first (and
+	 * cannot be NULL after initialization). Subsequent directories are
+	 * alternates.
+	 */
+	struct object_directory *odb;
+	struct object_directory **odb_tail;
+	struct kh_odb_path_map *odb_by_path;
+
+	int loaded_alternates;
+
+	/*
+	 * A list of alternate object directories loaded from the environment;
+	 * this should not generally need to be accessed directly, but will
+	 * populate the "odb" list when prepare_alt_odb() is run.
+	 */
+	char *alternate_db;
+
+	/*
+	 * Objects that should be substituted by other objects
+	 * (see git-replace(1)).
+	 */
+	struct oidmap *replace_map;
+	unsigned replace_map_initialized : 1;
+	pthread_mutex_t replace_mutex; /* protect object replace functions */
+
+	struct commit_graph *commit_graph;
+	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
+
+	/*
+	 * private data
+	 *
+	 * should only be accessed directly by packfile.c and midx.c
+	 */
+	struct multi_pack_index *multi_pack_index;
+
+	/*
+	 * private data
+	 *
+	 * should only be accessed directly by packfile.c
+	 */
+
+	struct packed_git *packed_git;
+	/* A most-recently-used ordered version of the packed_git list. */
+	struct list_head packed_git_mru;
+
+	struct {
+		struct packed_git **packs;
+		unsigned flags;
+	} kept_pack_cache;
+
+	/*
+	 * A map of packfiles to packed_git structs for tracking which
+	 * packs have been loaded already.
+	 */
+	struct hashmap pack_map;
+
+	/*
+	 * A fast, rough count of the number of objects in the repository.
+	 * These two fields are not meant for direct access. Use
+	 * repo_approximate_object_count() instead.
+	 */
+	unsigned long approximate_object_count;
+	unsigned approximate_object_count_valid : 1;
+
+	/*
+	 * Whether packed_git has already been populated with this repository's
+	 * packs.
+	 */
+	unsigned packed_git_initialized : 1;
+};
+
+struct raw_object_store *raw_object_store_new(void);
+void raw_object_store_clear(struct raw_object_store *o);
+
+/*
+ * Put in `buf` the name of the file in the local object database that
+ * would be used to store a loose object with the specified oid.
+ */
+const char *loose_object_path(struct repository *r, struct strbuf *buf,
+			      const struct object_id *oid);
+
+void *map_loose_object(struct repository *r, const struct object_id *oid,
+		       unsigned long *size);
+
+void *repo_read_object_file(struct repository *r,
+			    const struct object_id *oid,
+			    enum object_type *type,
+			    unsigned long *size);
+
+/* Read and unpack an object file into memory, write memory to an object file */
+int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
+
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+		      unsigned long len, enum object_type type,
+		      struct object_id *oid);
+
+int write_object_file_flags(const void *buf, unsigned long len,
+			    enum object_type type, struct object_id *oid,
+			    unsigned flags);
+static inline int write_object_file(const void *buf, unsigned long len,
+				    enum object_type type, struct object_id *oid)
+{
+	return write_object_file_flags(buf, len, type, oid, 0);
+}
+
+int write_object_file_literally(const void *buf, unsigned long len,
+				const char *type, struct object_id *oid,
+				unsigned flags);
+int stream_loose_object(struct input_stream *in_stream, size_t len,
+			struct object_id *oid);
+
+/*
+ * Add an object file to the in-memory object store, without writing it
+ * to disk.
+ *
+ * Callers are responsible for calling write_object_file to record the
+ * object in persistent storage before writing any other new objects
+ * that reference it.
+ */
+int pretend_object_file(void *, unsigned long, enum object_type,
+			struct object_id *oid);
+
+int force_object_loose(const struct object_id *oid, time_t mtime);
+
+struct object_info {
+	/* Request */
+	enum object_type *typep;
+	unsigned long *sizep;
+	off_t *disk_sizep;
+	struct object_id *delta_base_oid;
+	struct strbuf *type_name;
+	void **contentp;
+
+	/* Response */
+	enum {
+		OI_CACHED,
+		OI_LOOSE,
+		OI_PACKED,
+		OI_DBCACHED
+	} whence;
+	union {
+		/*
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } cached;
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } loose;
+		 */
+		struct {
+			struct packed_git *pack;
+			off_t offset;
+			unsigned int is_delta;
+		} packed;
+	} u;
+};
+
+/*
+ * Initializer for a "struct object_info" that wants no items. You may
+ * also memset() the memory to all-zeroes.
+ */
+#define OBJECT_INFO_INIT { 0 }
+
+/* Invoke lookup_replace_object() on the given hash */
+#define OBJECT_INFO_LOOKUP_REPLACE 1
+/* Allow reading from a loose object file of unknown/bogus type */
+#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
+/* Do not retry packed storage after checking packed and loose storage */
+#define OBJECT_INFO_QUICK 8
+/*
+ * Do not attempt to fetch the object if missing (even if fetch_is_missing is
+ * nonzero).
+ */
+#define OBJECT_INFO_SKIP_FETCH_OBJECT 16
+/*
+ * This is meant for bulk prefetching of missing blobs in a partial
+ * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
+ */
+#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
+
+/* Die if object corruption (not just an object being missing) was detected. */
+#define OBJECT_INFO_DIE_IF_CORRUPT 32
+
+int oid_object_info_extended(struct repository *r,
+			     const struct object_id *,
+			     struct object_info *, unsigned flags);
+
+/*
+ * Open the loose object at path, check its hash, and return the contents,
+ * use the "oi" argument to assert things about the object, or e.g. populate its
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+		      const struct object_id *expected_oid,
+		      struct object_id *real_oid,
+		      void **contents,
+		      struct object_info *oi);
+
+/* Retry packed storage after checking packed and loose storage */
+#define HAS_OBJECT_RECHECK_PACKED 1
+
+/*
+ * Returns 1 if the object exists. This function will not lazily fetch objects
+ * in a partial clone.
+ */
+int has_object(struct repository *r, const struct object_id *oid,
+	       unsigned flags);
+
+/*
+ * These macros and functions are deprecated. If checking existence for an
+ * object that is likely to be missing and/or whose absence is relatively
+ * inconsequential (or is consequential but the caller is prepared to handle
+ * it), use has_object(), which has better defaults (no lazy fetch in a partial
+ * clone and no rechecking of packed storage). In the unlikely event that a
+ * caller needs to assert existence of an object that it fully expects to
+ * exist, and wants to trigger a lazy fetch in a partial clone, use
+ * oid_object_info_extended() with a NULL struct object_info.
+ *
+ * These functions can be removed once all callers have migrated to
+ * has_object() and/or oid_object_info_extended().
+ */
+int repo_has_object_file(struct repository *r, const struct object_id *oid);
+int repo_has_object_file_with_flags(struct repository *r,
+				    const struct object_id *oid, int flags);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name.  This function does not respect replace
+ * references.
+ */
+int has_loose_object_nonlocal(const struct object_id *);
+
+int has_loose_object(const struct object_id *);
+
+/**
+ * format_object_header() is a thin wrapper around s xsnprintf() that
+ * writes the initial "<type> <obj-len>" part of the loose object
+ * header. It returns the size that snprintf() returns + 1.
+ */
+int format_object_header(char *str, size_t size, enum object_type type,
+			 size_t objsize);
+
+void assert_oid_type(const struct object_id *oid, enum object_type expect);
+
+/*
+ * Enabling the object read lock allows multiple threads to safely call the
+ * following functions in parallel: repo_read_object_file(),
+ * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ *
+ * obj_read_lock() and obj_read_unlock() may also be used to protect other
+ * section which cannot execute in parallel with object reading. Since the used
+ * lock is a recursive mutex, these sections can even contain calls to object
+ * reading functions. However, beware that in these cases zlib inflation won't
+ * be performed in parallel, losing performance.
+ *
+ * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * any of its callees end up calling it, this recursive call won't benefit from
+ * parallel inflation.
+ */
+void enable_obj_read_lock(void);
+void disable_obj_read_lock(void);
+
+extern int obj_read_use_lock;
+extern pthread_mutex_t obj_read_mutex;
+
+static inline void obj_read_lock(void)
+{
+	if(obj_read_use_lock)
+		pthread_mutex_lock(&obj_read_mutex);
+}
+
+static inline void obj_read_unlock(void)
+{
+	if(obj_read_use_lock)
+		pthread_mutex_unlock(&obj_read_mutex);
+}
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+				 const char *path,
+				 void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+				const char *path,
+				void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+				 const char *path,
+				 void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+				struct strbuf *path,
+				each_loose_object_fn obj_cb,
+				each_loose_cruft_fn cruft_cb,
+				each_loose_subdir_fn subdir_cb,
+				void *data);
+int for_each_loose_file_in_objdir(const char *path,
+				  each_loose_object_fn obj_cb,
+				  each_loose_cruft_fn cruft_cb,
+				  each_loose_subdir_fn subdir_cb,
+				  void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+				      each_loose_object_fn obj_cb,
+				      each_loose_cruft_fn cruft_cb,
+				      each_loose_subdir_fn subdir_cb,
+				      void *data);
+
+/* Flags for for_each_*_object() below. */
+enum for_each_object_flags {
+	/* Iterate only over local objects, not alternates. */
+	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+	/* Only iterate over packs obtained from the promisor remote. */
+	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+
+	/*
+	 * Visit objects within a pack in packfile order rather than .idx order
+	 */
+	FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
+
+	/* Only iterate over packs that are not marked as kept in-core. */
+	FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
+
+	/* Only iterate over packs that do not have .keep files. */
+	FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
+};
+
+/*
+ * Iterate over all accessible loose objects without respect to
+ * reachability. By default, this includes both local and alternate objects.
+ * The order in which objects are visited is unspecified.
+ *
+ * Any flags specific to packs are ignored.
+ */
+int for_each_loose_object(each_loose_object_fn, void *,
+			  enum for_each_object_flags flags);
+
+/*
+ * Iterate over all accessible packed objects without respect to reachability.
+ * By default, this includes both local and alternate packs.
+ *
+ * Note that some objects may appear twice if they are found in multiple packs.
+ * Each pack is visited in an unspecified order. By default, objects within a
+ * pack are visited in pack-idx order (i.e., sorted by oid).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+				  struct packed_git *pack,
+				  uint32_t pos,
+				  void *data);
+int for_each_object_in_pack(struct packed_git *p,
+			    each_packed_object_fn, void *data,
+			    enum for_each_object_flags flags);
+int for_each_packed_object(each_packed_object_fn, void *,
+			   enum for_each_object_flags flags);
+
+#endif /* OBJECT_STORE_LL_H */
diff --git a/object-store.h b/object-store.h
index 05803a03e92..1b3e3d7d014 100644
--- a/object-store.h
+++ b/object-store.h
@@ -1,537 +1,11 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
-#include "object.h"
-#include "list.h"
-#include "thread-utils.h"
 #include "khash.h"
 #include "dir.h"
-#include "oidset.h"
-
-struct oidmap;
-struct oidtree;
-struct strbuf;
-
-struct object_directory {
-	struct object_directory *next;
-
-	/*
-	 * Used to store the results of readdir(3) calls when we are OK
-	 * sacrificing accuracy due to races for speed. That includes
-	 * object existence with OBJECT_INFO_QUICK, as well as
-	 * our search for unique abbreviated hashes. Don't use it for tasks
-	 * requiring greater accuracy!
-	 *
-	 * Be sure to call odb_load_loose_cache() before using.
-	 */
-	uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
-	struct oidtree *loose_objects_cache;
-
-	/*
-	 * This is a temporary object store created by the tmp_objdir
-	 * facility. Disable ref updates since the objects in the store
-	 * might be discarded on rollback.
-	 */
-	int disable_ref_updates;
-
-	/*
-	 * This object store is ephemeral, so there is no need to fsync.
-	 */
-	int will_destroy;
-
-	/*
-	 * Path to the alternative object store. If this is a relative path,
-	 * it is relative to the current working directory.
-	 */
-	char *path;
-};
-
-struct input_stream {
-	const void *(*read)(struct input_stream *, unsigned long *len);
-	void *data;
-	int is_finished;
-};
+#include "object-store-ll.h"
 
 KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
 	struct object_directory *, 1, fspathhash, fspatheq)
 
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
-/*
- * Add the directory to the on-disk alternates file; the new entry will also
- * take effect in the current process.
- */
-void add_to_alternates_file(const char *dir);
-
-/*
- * Add the directory to the in-memory list of alternates (along with any
- * recursive alternates it points to), but do not modify the on-disk alternates
- * file.
- */
-void add_to_alternates_memory(const char *dir);
-
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
-
-/*
- * Populate and return the loose object cache array corresponding to the
- * given object ID.
- */
-struct oidtree *odb_loose_cache(struct object_directory *odb,
-				  const struct object_id *oid);
-
-/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
-
-/* Clear and free the specified object directory */
-void free_object_directory(struct object_directory *odb);
-
-struct packed_git {
-	struct hashmap_entry packmap_ent;
-	struct packed_git *next;
-	struct list_head mru;
-	struct pack_window *windows;
-	off_t pack_size;
-	const void *index_data;
-	size_t index_size;
-	uint32_t num_objects;
-	uint32_t crc_offset;
-	struct oidset bad_objects;
-	int index_version;
-	time_t mtime;
-	int pack_fd;
-	int index;              /* for builtin/pack-objects.c */
-	unsigned pack_local:1,
-		 pack_keep:1,
-		 pack_keep_in_core:1,
-		 freshened:1,
-		 do_not_close:1,
-		 pack_promisor:1,
-		 multi_pack_index:1,
-		 is_cruft:1;
-	unsigned char hash[GIT_MAX_RAWSZ];
-	struct revindex_entry *revindex;
-	const uint32_t *revindex_data;
-	const uint32_t *revindex_map;
-	size_t revindex_size;
-	/*
-	 * mtimes_map points at the beginning of the memory mapped region of
-	 * this pack's corresponding .mtimes file, and mtimes_size is the size
-	 * of that .mtimes file
-	 */
-	const uint32_t *mtimes_map;
-	size_t mtimes_size;
-	/* something like ".git/objects/pack/xxxxx.pack" */
-	char pack_name[FLEX_ARRAY]; /* more */
-};
-
-struct multi_pack_index;
-
-static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
-				     const struct hashmap_entry *entry,
-				     const struct hashmap_entry *entry2,
-				     const void *keydata)
-{
-	const char *key = keydata;
-	const struct packed_git *pg1, *pg2;
-
-	pg1 = container_of(entry, const struct packed_git, packmap_ent);
-	pg2 = container_of(entry2, const struct packed_git, packmap_ent);
-
-	return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
-}
-
-struct raw_object_store {
-	/*
-	 * Set of all object directories; the main directory is first (and
-	 * cannot be NULL after initialization). Subsequent directories are
-	 * alternates.
-	 */
-	struct object_directory *odb;
-	struct object_directory **odb_tail;
-	struct kh_odb_path_map *odb_by_path;
-
-	int loaded_alternates;
-
-	/*
-	 * A list of alternate object directories loaded from the environment;
-	 * this should not generally need to be accessed directly, but will
-	 * populate the "odb" list when prepare_alt_odb() is run.
-	 */
-	char *alternate_db;
-
-	/*
-	 * Objects that should be substituted by other objects
-	 * (see git-replace(1)).
-	 */
-	struct oidmap *replace_map;
-	unsigned replace_map_initialized : 1;
-	pthread_mutex_t replace_mutex; /* protect object replace functions */
-
-	struct commit_graph *commit_graph;
-	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
-
-	/*
-	 * private data
-	 *
-	 * should only be accessed directly by packfile.c and midx.c
-	 */
-	struct multi_pack_index *multi_pack_index;
-
-	/*
-	 * private data
-	 *
-	 * should only be accessed directly by packfile.c
-	 */
-
-	struct packed_git *packed_git;
-	/* A most-recently-used ordered version of the packed_git list. */
-	struct list_head packed_git_mru;
-
-	struct {
-		struct packed_git **packs;
-		unsigned flags;
-	} kept_pack_cache;
-
-	/*
-	 * A map of packfiles to packed_git structs for tracking which
-	 * packs have been loaded already.
-	 */
-	struct hashmap pack_map;
-
-	/*
-	 * A fast, rough count of the number of objects in the repository.
-	 * These two fields are not meant for direct access. Use
-	 * repo_approximate_object_count() instead.
-	 */
-	unsigned long approximate_object_count;
-	unsigned approximate_object_count_valid : 1;
-
-	/*
-	 * Whether packed_git has already been populated with this repository's
-	 * packs.
-	 */
-	unsigned packed_git_initialized : 1;
-};
-
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
-
-/*
- * Put in `buf` the name of the file in the local object database that
- * would be used to store a loose object with the specified oid.
- */
-const char *loose_object_path(struct repository *r, struct strbuf *buf,
-			      const struct object_id *oid);
-
-void *map_loose_object(struct repository *r, const struct object_id *oid,
-		       unsigned long *size);
-
-void *repo_read_object_file(struct repository *r,
-			    const struct object_id *oid,
-			    enum object_type *type,
-			    unsigned long *size);
-
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
-void hash_object_file(const struct git_hash_algo *algo, const void *buf,
-		      unsigned long len, enum object_type type,
-		      struct object_id *oid);
-
-int write_object_file_flags(const void *buf, unsigned long len,
-			    enum object_type type, struct object_id *oid,
-			    unsigned flags);
-static inline int write_object_file(const void *buf, unsigned long len,
-				    enum object_type type, struct object_id *oid)
-{
-	return write_object_file_flags(buf, len, type, oid, 0);
-}
-
-int write_object_file_literally(const void *buf, unsigned long len,
-				const char *type, struct object_id *oid,
-				unsigned flags);
-int stream_loose_object(struct input_stream *in_stream, size_t len,
-			struct object_id *oid);
-
-/*
- * Add an object file to the in-memory object store, without writing it
- * to disk.
- *
- * Callers are responsible for calling write_object_file to record the
- * object in persistent storage before writing any other new objects
- * that reference it.
- */
-int pretend_object_file(void *, unsigned long, enum object_type,
-			struct object_id *oid);
-
-int force_object_loose(const struct object_id *oid, time_t mtime);
-
-struct object_info {
-	/* Request */
-	enum object_type *typep;
-	unsigned long *sizep;
-	off_t *disk_sizep;
-	struct object_id *delta_base_oid;
-	struct strbuf *type_name;
-	void **contentp;
-
-	/* Response */
-	enum {
-		OI_CACHED,
-		OI_LOOSE,
-		OI_PACKED,
-		OI_DBCACHED
-	} whence;
-	union {
-		/*
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } cached;
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } loose;
-		 */
-		struct {
-			struct packed_git *pack;
-			off_t offset;
-			unsigned int is_delta;
-		} packed;
-	} u;
-};
-
-/*
- * Initializer for a "struct object_info" that wants no items. You may
- * also memset() the memory to all-zeroes.
- */
-#define OBJECT_INFO_INIT { 0 }
-
-/* Invoke lookup_replace_object() on the given hash */
-#define OBJECT_INFO_LOOKUP_REPLACE 1
-/* Allow reading from a loose object file of unknown/bogus type */
-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
-/* Do not retry packed storage after checking packed and loose storage */
-#define OBJECT_INFO_QUICK 8
-/*
- * Do not attempt to fetch the object if missing (even if fetch_is_missing is
- * nonzero).
- */
-#define OBJECT_INFO_SKIP_FETCH_OBJECT 16
-/*
- * This is meant for bulk prefetching of missing blobs in a partial
- * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
- */
-#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
-
-/* Die if object corruption (not just an object being missing) was detected. */
-#define OBJECT_INFO_DIE_IF_CORRUPT 32
-
-int oid_object_info_extended(struct repository *r,
-			     const struct object_id *,
-			     struct object_info *, unsigned flags);
-
-/*
- * Open the loose object at path, check its hash, and return the contents,
- * use the "oi" argument to assert things about the object, or e.g. populate its
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
-		      const struct object_id *expected_oid,
-		      struct object_id *real_oid,
-		      void **contents,
-		      struct object_info *oi);
-
-/* Retry packed storage after checking packed and loose storage */
-#define HAS_OBJECT_RECHECK_PACKED 1
-
-/*
- * Returns 1 if the object exists. This function will not lazily fetch objects
- * in a partial clone.
- */
-int has_object(struct repository *r, const struct object_id *oid,
-	       unsigned flags);
-
-/*
- * These macros and functions are deprecated. If checking existence for an
- * object that is likely to be missing and/or whose absence is relatively
- * inconsequential (or is consequential but the caller is prepared to handle
- * it), use has_object(), which has better defaults (no lazy fetch in a partial
- * clone and no rechecking of packed storage). In the unlikely event that a
- * caller needs to assert existence of an object that it fully expects to
- * exist, and wants to trigger a lazy fetch in a partial clone, use
- * oid_object_info_extended() with a NULL struct object_info.
- *
- * These functions can be removed once all callers have migrated to
- * has_object() and/or oid_object_info_extended().
- */
-int repo_has_object_file(struct repository *r, const struct object_id *oid);
-int repo_has_object_file_with_flags(struct repository *r,
-				    const struct object_id *oid, int flags);
-
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name.  This function does not respect replace
- * references.
- */
-int has_loose_object_nonlocal(const struct object_id *);
-
-int has_loose_object(const struct object_id *);
-
-/**
- * format_object_header() is a thin wrapper around s xsnprintf() that
- * writes the initial "<type> <obj-len>" part of the loose object
- * header. It returns the size that snprintf() returns + 1.
- */
-int format_object_header(char *str, size_t size, enum object_type type,
-			 size_t objsize);
-
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
-
-/*
- * Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
- *
- * obj_read_lock() and obj_read_unlock() may also be used to protect other
- * section which cannot execute in parallel with object reading. Since the used
- * lock is a recursive mutex, these sections can even contain calls to object
- * reading functions. However, beware that in these cases zlib inflation won't
- * be performed in parallel, losing performance.
- *
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
- * any of its callees end up calling it, this recursive call won't benefit from
- * parallel inflation.
- */
-void enable_obj_read_lock(void);
-void disable_obj_read_lock(void);
-
-extern int obj_read_use_lock;
-extern pthread_mutex_t obj_read_mutex;
-
-static inline void obj_read_lock(void)
-{
-	if(obj_read_use_lock)
-		pthread_mutex_lock(&obj_read_mutex);
-}
-
-static inline void obj_read_unlock(void)
-{
-	if(obj_read_use_lock)
-		pthread_mutex_unlock(&obj_read_mutex);
-}
-
-/*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-				 const char *path,
-				 void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-				const char *path,
-				void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-				 const char *path,
-				 void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-				struct strbuf *path,
-				each_loose_object_fn obj_cb,
-				each_loose_cruft_fn cruft_cb,
-				each_loose_subdir_fn subdir_cb,
-				void *data);
-int for_each_loose_file_in_objdir(const char *path,
-				  each_loose_object_fn obj_cb,
-				  each_loose_cruft_fn cruft_cb,
-				  each_loose_subdir_fn subdir_cb,
-				  void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-				      each_loose_object_fn obj_cb,
-				      each_loose_cruft_fn cruft_cb,
-				      each_loose_subdir_fn subdir_cb,
-				      void *data);
-
-/* Flags for for_each_*_object() below. */
-enum for_each_object_flags {
-	/* Iterate only over local objects, not alternates. */
-	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
-
-	/* Only iterate over packs obtained from the promisor remote. */
-	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
-
-	/*
-	 * Visit objects within a pack in packfile order rather than .idx order
-	 */
-	FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
-
-	/* Only iterate over packs that are not marked as kept in-core. */
-	FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
-
-	/* Only iterate over packs that do not have .keep files. */
-	FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
-};
-
-/*
- * Iterate over all accessible loose objects without respect to
- * reachability. By default, this includes both local and alternate objects.
- * The order in which objects are visited is unspecified.
- *
- * Any flags specific to packs are ignored.
- */
-int for_each_loose_object(each_loose_object_fn, void *,
-			  enum for_each_object_flags flags);
-
-/*
- * Iterate over all accessible packed objects without respect to reachability.
- * By default, this includes both local and alternate packs.
- *
- * Note that some objects may appear twice if they are found in multiple packs.
- * Each pack is visited in an unspecified order. By default, objects within a
- * pack are visited in pack-idx order (i.e., sorted by oid).
- */
-typedef int each_packed_object_fn(const struct object_id *oid,
-				  struct packed_git *pack,
-				  uint32_t pos,
-				  void *data);
-int for_each_object_in_pack(struct packed_git *p,
-			    each_packed_object_fn, void *data,
-			    enum for_each_object_flags flags);
-int for_each_packed_object(each_packed_object_fn, void *,
-			   enum for_each_object_flags flags);
-
 #endif /* OBJECT_STORE_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..3e190214d14 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 623ee2a8197..d86f4e739a4 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -3,7 +3,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tag.h"
 #include "diff.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index e0fad723bf3..3981655f3cf 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
 #include "repository.h"
 #include "trace2.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "list-objects-filter-options.h"
 #include "midx.h"
 #include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 049f2f0bfc0..977f619618e 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -7,7 +7,7 @@
 #include "progress.h"
 #include "packfile.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct idx_entry {
 	off_t                offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 020a37f8fe3..cdf30b8d2b0 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -2,8 +2,9 @@
 #include "gettext.h"
 #include "pack-mtimes.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
+#include "strbuf.h"
 
 static char *pack_mtimes_filename(struct packed_git *p)
 {
diff --git a/pack-objects.h b/pack-objects.h
index 579476687c4..0d78db40cb2 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
 #ifndef PACK_OBJECTS_H
 #define PACK_OBJECTS_H
 
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "thread-utils.h"
 #include "pack.h"
 
diff --git a/pack-revindex.c b/pack-revindex.c
index 1f51b712e87..7fffcad9125 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -2,8 +2,9 @@
 #include "gettext.h"
 #include "pack-revindex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
+#include "strbuf.h"
 #include "trace2.h"
 #include "config.h"
 #include "midx.h"
diff --git a/pack-write.c b/pack-write.c
index 45681e2d7db..af48813a9bb 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -11,6 +11,7 @@
 #include "pack-objects.h"
 #include "pack-revindex.h"
 #include "path.h"
+#include "strbuf.h"
 #include "wrapper.h"
 
 void reset_pack_idx_option(struct pack_idx_option *opts)
diff --git a/packfile.c b/packfile.c
index fd083c86e00..c60aeb05ece 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
 #include "tree-walk.h"
 #include "tree.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "midx.h"
 #include "commit-graph.h"
 #include "pack-revindex.h"
diff --git a/path.c b/path.c
index 7c1cd8182a8..c3b6618c77b 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
 #include "submodule-config.h"
 #include "path.h"
 #include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "lockfile.h"
 #include "exec-cmd.h"
 #include "wrapper.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 1adcd6fb0a5..db88d2064d4 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "config.h"
 #include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index a90c48852e5..808a68c974a 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,7 +7,7 @@
 #include "hash-ll.h"
 #include "hex.h"
 #include "object.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "string-list.h"
 #include "strbuf.h"
 
diff --git a/prune-packed.c b/prune-packed.c
index 58412b4fb91..e54daf740a2 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "progress.h"
 #include "prune-packed.h"
diff --git a/reachable.c b/reachable.c
index 55bb1143530..434f09e9ebf 100644
--- a/reachable.c
+++ b/reachable.c
@@ -13,7 +13,7 @@
 #include "list-objects.h"
 #include "packfile.h"
 #include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack-bitmap.h"
 #include "pack-mtimes.h"
 
diff --git a/read-cache.c b/read-cache.c
index 86ada403a83..b9a995e5a18 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -17,7 +17,7 @@
 #include "refs.h"
 #include "dir.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 4991cd4f7a8..e0d03a9f8e9 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -8,7 +8,7 @@
 #include "refs.h"
 #include "wildmatch.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "repository.h"
 #include "commit.h"
diff --git a/reflog.c b/reflog.c
index ee1bf5d032c..9ad50e7d93e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "reflog.h"
 #include "refs.h"
 #include "revision.h"
diff --git a/refs.c b/refs.c
index 5f76da35673..54a827b45b3 100644
--- a/refs.c
+++ b/refs.c
@@ -17,7 +17,7 @@
 #include "run-command.h"
 #include "hook.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "path.h"
 #include "tag.h"
diff --git a/remote.c b/remote.c
index 8550056db43..6538b6037de 100644
--- a/remote.c
+++ b/remote.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index e98825d5852..ca4017635df 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "oidmap.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "refs.h"
 #include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index 500482b02b3..a964db1670e 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
 
 #include "oidmap.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 /*
  * Do replace refs need to be checked this run?  This variable is
diff --git a/repository.c b/repository.c
index 87a7a27b665..8c77b7ed236 100644
--- a/repository.c
+++ b/repository.c
@@ -6,7 +6,7 @@
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "config.h"
 #include "object.h"
 #include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3584fecb07c..e2b8597f88c 100644
--- a/rerere.c
+++ b/rerere.c
@@ -17,7 +17,7 @@
 #include "path.h"
 #include "pathspec.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "hash-lookup.h"
 #include "strmap.h"
 #include "wrapper.h"
diff --git a/revision.c b/revision.c
index d4b4b34fd80..84768565cef 100644
--- a/revision.c
+++ b/revision.c
@@ -6,7 +6,7 @@
 #include "hex.h"
 #include "object-name.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "tag.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/send-pack.c b/send-pack.c
index 0c7ccaef680..9510bef8561 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index eddd38d4bed..1b9607da268 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -11,7 +11,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "pager.h"
 #include "commit.h"
diff --git a/server-info.c b/server-info.c
index 85d17bbb151..382e481a2b0 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
 #include "packfile.h"
 #include "path.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "server-info.h"
 #include "strbuf.h"
 #include "wrapper.h"
diff --git a/shallow.c b/shallow.c
index 45343e6a78b..f3ef94d4c92 100644
--- a/shallow.c
+++ b/shallow.c
@@ -4,7 +4,7 @@
 #include "repository.h"
 #include "tempfile.h"
 #include "lockfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 21e39585e89..49791ab958d 100644
--- a/streaming.c
+++ b/streaming.c
@@ -7,7 +7,7 @@
 #include "streaming.h"
 #include "repository.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "replace-object.h"
 #include "packfile.h"
 #include "wrapper.h"
diff --git a/submodule-config.c b/submodule-config.c
index c67260a3e11..1efd5471698 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -11,7 +11,7 @@
 #include "submodule.h"
 #include "strbuf.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "parse-options.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index 245300596ff..f0f8788d2e3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
 #include "parse-options.h"
 #include "object-file.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit-reach.h"
 #include "read-cache-ll.h"
 #include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 0f3fbeec532..67a964ef904 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "hex.h"
 #include "strbuf.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "packfile.h"
 #include "pack-mtimes.h"
 #include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 362bd64a4c2..910a1286144 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "hex.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "setup.h"
 
 /*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 3ac496e27e4..8c7a83f578f 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "commit-graph.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "bloom.h"
 #include "setup.h"
 
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 211addaa005..e9a444ddba5 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -2,7 +2,7 @@
 #include "hex.h"
 #include "midx.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "pack-bitmap.h"
 #include "packfile.h"
 #include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 1b30a6cba8b..04d26fc2fef 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -3,9 +3,10 @@
 #include "refs.h"
 #include "setup.h"
 #include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "path.h"
 #include "repository.h"
+#include "strbuf.h"
 
 struct flag_definition {
 	const char *name;
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index bafd2a5bf95..4cd8a952e5c 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -4,7 +4,7 @@
 #include "config.h"
 #include "environment.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "object.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/tag.c b/tag.c
index 96dbd5b2d55..c5426484b22 100644
--- a/tag.c
+++ b/tag.c
@@ -2,7 +2,7 @@
 #include "environment.h"
 #include "tag.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index db1f7038dae..5f9074ad1c0 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -11,7 +11,7 @@
 #include "strbuf.h"
 #include "strvec.h"
 #include "quote.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 
 struct tmp_objdir {
 	struct strbuf path;
diff --git a/transport.c b/transport.c
index 67afdae57c1..4dc187a3885 100644
--- a/transport.c
+++ b/transport.c
@@ -27,7 +27,7 @@
 #include "transport-internal.h"
 #include "protocol.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "color.h"
 #include "bundle-uri.h"
 #include "wrapper.h"
diff --git a/tree-walk.c b/tree-walk.c
index d3c48e06df0..42ed86ef581 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -5,7 +5,7 @@
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "trace2.h"
 #include "tree.h"
 #include "pathspec.h"
diff --git a/tree.c b/tree.c
index 0dd2029a8a2..e118914a76a 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
 #include "hex.h"
 #include "tree.h"
 #include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 4b620df3031..87517364dc0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -23,7 +23,7 @@
 #include "symlinks.h"
 #include "trace2.h"
 #include "fsmonitor.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "promisor-remote.h"
 #include "entry.h"
 #include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 08633dc1216..2502dcb4699 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -7,7 +7,7 @@
 #include "pkt-line.h"
 #include "sideband.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "oid-array.h"
 #include "tag.h"
 #include "object.h"
diff --git a/walker.c b/walker.c
index 24ff7dfdc28..65002a7220a 100644
--- a/walker.c
+++ b/walker.c
@@ -3,8 +3,9 @@
 #include "hex.h"
 #include "walker.h"
 #include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
 #include "commit.h"
+#include "strbuf.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "tag.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 0460e03f5ed..abc7275a528 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "strbuf.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
-- 
gitgitgadget


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

* [PATCH v3 27/28] hash-ll, hashmap: move oidhash() to hash-ll
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (25 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 26/28] object-store-ll.h: split this header out of object-store.h Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-16  6:34     ` [PATCH v3 28/28] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
  2023-05-23 19:49     ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Calvin Wan
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

oidhash() was used by both hashmap and khash, which makes sense.
However, the location of this function in hashmap.[ch] meant that
khash.h had to depend upon hashmap.h, making people unfamiliar with
khash think that it was built upon hashmap.  (Or at least, I personally
was confused for a while about this in the past.)

Move this function to hash-ll, so that khash.h can stop depending upon
hashmap.h.

This has another benefit as well: it allows us to remove hashmap.h's
dependency on hash-ll.h.  While some callers of hashmap.h were making
use of oidhash, most were not, so this change provides another way to
reduce the number of includes.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 decorate.c |  1 -
 dir.h      |  1 +
 hash-ll.h  | 19 +++++++++++++++++++
 hashmap.h  | 21 ---------------------
 khash.h    |  1 -
 remote.h   |  1 +
 serve.c    |  1 +
 7 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/decorate.c b/decorate.c
index 71e79daa825..a5c43c0c146 100644
--- a/decorate.c
+++ b/decorate.c
@@ -3,7 +3,6 @@
  * data.
  */
 #include "git-compat-util.h"
-#include "hashmap.h"
 #include "object.h"
 #include "decorate.h"
 
diff --git a/dir.h b/dir.h
index 79b85a01ee4..279a0660801 100644
--- a/dir.h
+++ b/dir.h
@@ -1,6 +1,7 @@
 #ifndef DIR_H
 #define DIR_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 #include "pathspec.h"
 #include "statinfo.h"
diff --git a/hash-ll.h b/hash-ll.h
index 80509251370..8d7973769fd 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -270,6 +270,25 @@ static inline void oid_set_algo(struct object_id *oid, const struct git_hash_alg
 	oid->algo = hash_algo_by_ptr(algop);
 }
 
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+	/*
+	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+	 * platforms that don't support unaligned reads.
+	 */
+	unsigned int hash;
+	memcpy(&hash, oid->hash, sizeof(hash));
+	return hash;
+}
+
 const char *empty_tree_oid_hex(void);
 const char *empty_blob_oid_hex(void);
 
diff --git a/hashmap.h b/hashmap.h
index 2695f3d3a6e..c8216e47bb2 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -1,8 +1,6 @@
 #ifndef HASHMAP_H
 #define HASHMAP_H
 
-#include "hash-ll.h"
-
 /*
  * Generic implementation of hash-based key-value mappings.
  *
@@ -120,25 +118,6 @@ unsigned int memhash(const void *buf, size_t len);
 unsigned int memihash(const void *buf, size_t len);
 unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
 
-/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
-	/*
-	 * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
-	 * platforms that don't support unaligned reads.
-	 */
-	unsigned int hash;
-	memcpy(&hash, oid->hash, sizeof(hash));
-	return hash;
-}
-
 /*
  * struct hashmap_entry is an opaque structure representing an entry in the
  * hash table.
diff --git a/khash.h b/khash.h
index a0a08dad8b7..ff881631778 100644
--- a/khash.h
+++ b/khash.h
@@ -26,7 +26,6 @@
 #ifndef __AC_KHASH_H
 #define __AC_KHASH_H
 
-#include "hashmap.h"
 #include "hash.h"
 
 #define AC_VERSION_KHASH_H "0.2.8"
diff --git a/remote.h b/remote.h
index 73638cefeb1..929c7c676d3 100644
--- a/remote.h
+++ b/remote.h
@@ -1,6 +1,7 @@
 #ifndef REMOTE_H
 #define REMOTE_H
 
+#include "hash-ll.h"
 #include "hashmap.h"
 #include "refspec.h"
 
diff --git a/serve.c b/serve.c
index 5329c91011f..a1d71134d49 100644
--- a/serve.c
+++ b/serve.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "repository.h"
 #include "config.h"
+#include "hash-ll.h"
 #include "pkt-line.h"
 #include "version.h"
 #include "ls-refs.h"
-- 
gitgitgadget


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

* [PATCH v3 28/28] fsmonitor-ll.h: split this header out of fsmonitor.h
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (26 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 27/28] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
@ 2023-05-16  6:34     ` Elijah Newren via GitGitGadget
  2023-05-23 19:49     ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Calvin Wan
  28 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren via GitGitGadget @ 2023-05-16  6:34 UTC (permalink / raw)
  To: git
  Cc: Elijah Newren, Calvin Wan, Jeff King, Glen Choo, Jonathan Tan,
	Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

This creates a new fsmonitor-ll.h with most of the functions from
fsmonitor.h, though it leaves three inline functions where they were.
Two-thirds of the files that previously included fsmonitor.h did not
need those three inline functions or the six extra includes those inline
functions required, so this allows them to only include the lower level
header.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/fsmonitor--daemon.c              |  4 +-
 compat/fsmonitor/fsm-health-darwin.c     |  2 +-
 compat/fsmonitor/fsm-health-win32.c      |  2 +-
 compat/fsmonitor/fsm-ipc-darwin.c        |  2 +-
 compat/fsmonitor/fsm-listen-darwin.c     |  3 +-
 compat/fsmonitor/fsm-listen-win32.c      |  2 +-
 compat/fsmonitor/fsm-path-utils-darwin.c |  3 +-
 compat/fsmonitor/fsm-path-utils-win32.c  |  3 +-
 compat/fsmonitor/fsm-settings-darwin.c   |  2 +-
 compat/fsmonitor/fsm-settings-win32.c    |  2 +-
 dir.c                                    |  3 +-
 fsmonitor-ipc.c                          |  2 +-
 fsmonitor-ll.h                           | 52 ++++++++++++++++++++++++
 fsmonitor.h                              | 46 +--------------------
 sparse-index.c                           |  3 +-
 15 files changed, 73 insertions(+), 58 deletions(-)
 create mode 100644 fsmonitor-ll.h

diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index f6dd9a784c1..74d1d6a585d 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -5,15 +5,17 @@
 #include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-path-utils.h"
+#include "fsmonitor-settings.h"
 #include "compat/fsmonitor/fsm-health.h"
 #include "compat/fsmonitor/fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "simple-ipc.h"
 #include "khash.h"
 #include "pkt-line.h"
+#include "trace.h"
 #include "trace2.h"
 
 static const char * const builtin_fsmonitor__daemon_usage[] = {
diff --git a/compat/fsmonitor/fsm-health-darwin.c b/compat/fsmonitor/fsm-health-darwin.c
index 4c291f8a066..5b1709d63f7 100644
--- a/compat/fsmonitor/fsm-health-darwin.c
+++ b/compat/fsmonitor/fsm-health-darwin.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
 
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index 6c81d7ee5c2..2d4e245beb1 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-health.h"
 #include "fsmonitor--daemon.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 964bc074db6..6f3a95410cc 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -5,7 +5,7 @@
 #include "path.h"
 #include "repository.h"
 #include "strbuf.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-path-utils.h"
 
diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 23e24b4b374..36c7e13281c 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -24,12 +24,13 @@
 #endif
 
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
 #include "string-list.h"
+#include "trace.h"
 
 struct fsm_listen_data
 {
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 3c0df5cff8c..a361a7db20e 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsm-listen.h"
 #include "fsmonitor--daemon.h"
 #include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index ef0142e0fbf..049f97eaaf2 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
+#include "trace.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 27bb6945183..c8a3e9dcdbb 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,7 +1,8 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-path-utils.h"
 #include "gettext.h"
+#include "trace.h"
 
 /*
  * Check remote working directory protocol.
diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c
index 58b623fbb9a..a3825906351 100644
--- a/compat/fsmonitor/fsm-settings-darwin.c
+++ b/compat/fsmonitor/fsm-settings-darwin.c
@@ -1,6 +1,6 @@
 #include "git-compat-util.h"
 #include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-ipc.h"
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index 37288978643..b6f67444944 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "repository.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
 
diff --git a/dir.c b/dir.c
index fada2713b9e..3acac7beb11 100644
--- a/dir.c
+++ b/dir.c
@@ -24,7 +24,8 @@
 #include "utf8.h"
 #include "varint.h"
 #include "ewah/ewok.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
+#include "read-cache-ll.h"
 #include "setup.h"
 #include "sparse-index.h"
 #include "submodule-config.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6ace978a1b4..88575aa54ca 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,5 +1,5 @@
 #include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 #include "gettext.h"
 #include "simple-ipc.h"
 #include "fsmonitor-ipc.h"
diff --git a/fsmonitor-ll.h b/fsmonitor-ll.h
new file mode 100644
index 00000000000..0504ca07d62
--- /dev/null
+++ b/fsmonitor-ll.h
@@ -0,0 +1,52 @@
+#ifndef FSMONITOR_LL_H
+#define FSMONITOR_LL_H
+
+struct index_state;
+struct strbuf;
+
+extern struct trace_key trace_fsmonitor;
+
+/*
+ * Read the fsmonitor index extension and (if configured) restore the
+ * CE_FSMONITOR_VALID state.
+ */
+int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
+
+/*
+ * Fill the fsmonitor_dirty ewah bits with their state from the index,
+ * before it is split during writing.
+ */
+void fill_fsmonitor_bitmap(struct index_state *istate);
+
+/*
+ * Write the CE_FSMONITOR_VALID state into the fsmonitor index
+ * extension.  Reads from the fsmonitor_dirty ewah in the index.
+ */
+void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension
+ */
+void add_fsmonitor(struct index_state *istate);
+void remove_fsmonitor(struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension as necessary based on the current
+ * core.fsmonitor setting.
+ */
+void tweak_fsmonitor(struct index_state *istate);
+
+/*
+ * Run the configured fsmonitor integration script and clear the
+ * CE_FSMONITOR_VALID bit for any files returned as dirty.  Also invalidate
+ * any corresponding untracked cache directory structures. Optimized to only
+ * run the first time it is called.
+ */
+void refresh_fsmonitor(struct index_state *istate);
+
+/*
+ * Does the received result contain the "trivial" response?
+ */
+int fsmonitor_is_trivial_response(const struct strbuf *query_result);
+
+#endif /* FSMONITOR_LL_H */
diff --git a/fsmonitor.h b/fsmonitor.h
index 7702301d214..5195a8624db 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,57 +1,13 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
 
+#include "fsmonitor-ll.h"
 #include "dir.h"
 #include "fsmonitor-settings.h"
 #include "object.h"
 #include "read-cache-ll.h"
 #include "trace.h"
 
-extern struct trace_key trace_fsmonitor;
-
-/*
- * Read the fsmonitor index extension and (if configured) restore the
- * CE_FSMONITOR_VALID state.
- */
-int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
-
-/*
- * Fill the fsmonitor_dirty ewah bits with their state from the index,
- * before it is split during writing.
- */
-void fill_fsmonitor_bitmap(struct index_state *istate);
-
-/*
- * Write the CE_FSMONITOR_VALID state into the fsmonitor index
- * extension.  Reads from the fsmonitor_dirty ewah in the index.
- */
-void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension
- */
-void add_fsmonitor(struct index_state *istate);
-void remove_fsmonitor(struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension as necessary based on the current
- * core.fsmonitor setting.
- */
-void tweak_fsmonitor(struct index_state *istate);
-
-/*
- * Run the configured fsmonitor integration script and clear the
- * CE_FSMONITOR_VALID bit for any files returned as dirty.  Also invalidate
- * any corresponding untracked cache directory structures. Optimized to only
- * run the first time it is called.
- */
-void refresh_fsmonitor(struct index_state *istate);
-
-/*
- * Does the received result contain the "trivial" response?
- */
-int fsmonitor_is_trivial_response(const struct strbuf *query_result);
-
 /*
  * Check if refresh_fsmonitor has been called at least once.
  * refresh_fsmonitor is idempotent. Returns true if fsmonitor is
diff --git a/sparse-index.c b/sparse-index.c
index 2c47954d933..90d04622568 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -3,6 +3,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "name-hash.h"
+#include "read-cache-ll.h"
 #include "repository.h"
 #include "sparse-index.h"
 #include "tree.h"
@@ -11,7 +12,7 @@
 #include "cache-tree.h"
 #include "config.h"
 #include "dir.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
 
 struct modify_index_context {
 	struct index_state *write;
-- 
gitgitgadget

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

* Re: [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
                       ` (27 preceding siblings ...)
  2023-05-16  6:34     ` [PATCH v3 28/28] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
@ 2023-05-23 19:49     ` Calvin Wan
  2023-05-24  0:11       ` Elijah Newren
  28 siblings, 1 reply; 115+ messages in thread
From: Calvin Wan @ 2023-05-23 19:49 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: Calvin Wan, git, Elijah Newren, Jeff King, Glen Choo,
	Jonathan Tan

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  * a textual & semantic conflict with cw/strbuf-cleanup (affecting strbuf.c;
>    to address, delete the conflict region and also delete the include of
>    repository.h)

In patch 19, you also include path.h into strbuf.c because before my
series, strbuf.c had a dependency on repository.h. Since that dependency
is removed, there is no need to include path.h anymore.

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

* Re: [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers)
  2023-05-23 19:49     ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Calvin Wan
@ 2023-05-24  0:11       ` Elijah Newren
  0 siblings, 0 replies; 115+ messages in thread
From: Elijah Newren @ 2023-05-24  0:11 UTC (permalink / raw)
  To: Calvin Wan
  Cc: Elijah Newren via GitGitGadget, git, Jeff King, Glen Choo,
	Jonathan Tan

On Tue, May 23, 2023 at 12:49 PM Calvin Wan <calvinwan@google.com> wrote:
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> >  * a textual & semantic conflict with cw/strbuf-cleanup (affecting strbuf.c;
> >    to address, delete the conflict region and also delete the include of
> >    repository.h)
>
> In patch 19, you also include path.h into strbuf.c because before my
> series, strbuf.c had a dependency on repository.h. Since that dependency
> is removed, there is no need to include path.h anymore.

The path.h include is shown within the conflict markers, thus removing
it was already part of my instructions ("delete the conflict
region...").

It looks like Junio merged your series to seen first, as I was
assuming in my instructions, so this suggests there was an error of
some sort when he merged my series:

$ git show --oneline --remerge-diff
862248e47048c9282bc00ac6d9dcc7a21bd11ab1 -- strbuf.c
862248e4704 (gitster/jch, gitgitgadget/jch) Merge branch
'en/header-split-cache-h-part-3' into jch
diff --git a/strbuf.c b/strbuf.c
remerge CONFLICT (content): Merge conflict in strbuf.c
index dfaf41d2f18..37fd5247b32 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -2,16 +2,7 @@
 #include "alloc.h"
 #include "gettext.h"
 #include "hex.h"
-<<<<<<< d1af2a2c773 (Merge branch 'la/doc-interpret-trailers' into jch)
-||||||| merged common ancestors
-#include "object-name.h"
-#include "refs.h"
-=======
-#include "object-name.h"
-#include "refs.h"
 #include "path.h"
->>>>>>> d677f7e76ab (fsmonitor-ll.h: split this header out of fsmonitor.h)
-#include "repository.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "utf8.h"

Junio: Do you want to fix/amend that merge to remove the entire
conflict region (so removing the line involving path.h too)?  Or are
you preserving that line for some reason?

Anyway, not a real big deal; it'll still compile with the extra
include.  If Junio doesn't tweak the merges to clean this up, then
I'll just add this into my follow-on series dealing with extra include
cleanups.

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

end of thread, other threads:[~2023-05-24  0:11 UTC | newest]

Thread overview: 115+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-07  3:45 [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 01/24] init-db: remove unnecessary global variable & document existing bug Elijah Newren via GitGitGadget
2023-05-11 17:24   ` Calvin Wan
2023-05-12  1:55     ` Elijah Newren
2023-05-11 20:43   ` Glen Choo
2023-05-12  1:21     ` Elijah Newren
2023-05-12 17:26       ` Glen Choo
2023-05-07  3:45 ` [PATCH 02/24] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 03/24] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 04/24] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 05/24] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 06/24] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 07/24] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 08/24] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 09/24] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 10/24] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 11/24] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 12/24] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 13/24] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 14/24] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 15/24] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 16/24] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 17/24] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 18/24] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 19/24] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 20/24] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 21/24] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 22/24] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
2023-05-07  3:45 ` [PATCH 23/24] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
2023-05-11 17:24   ` Calvin Wan
2023-05-11 18:31     ` Jeff King
2023-05-11 18:39       ` Felipe Contreras
2023-05-12  2:08       ` Elijah Newren
2023-05-12  4:07         ` Jeff King
2023-05-07  3:45 ` [PATCH 24/24] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
2023-05-08 15:29 ` [PATCH 00/24] Header cleanups (final splitting of cache.h, and some splitting of other headers) Junio C Hamano
2023-05-09  1:31   ` Elijah Newren
2023-05-09 16:03     ` Junio C Hamano
2023-05-08 15:55 ` Junio C Hamano
2023-05-11 17:41 ` Calvin Wan
2023-05-12  6:58   ` Elijah Newren
2023-05-12  7:04 ` [PATCH v2 00/27] " Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 01/27] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
2023-05-12 21:34     ` Jonathan Tan
2023-05-16  3:08       ` Elijah Newren
2023-05-12  7:04   ` [PATCH v2 02/27] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
2023-05-12 20:20     ` Glen Choo
2023-05-12  7:04   ` [PATCH v2 03/27] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
2023-05-12 21:28     ` Jonathan Tan
2023-05-16  2:57       ` Elijah Newren
2023-05-12  7:04   ` [PATCH v2 04/27] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 05/27] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
2023-05-12 21:25     ` Jonathan Tan
2023-05-12  7:04   ` [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
2023-05-15 21:44     ` Jonathan Tan
2023-05-12  7:04   ` [PATCH v2 07/27] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 08/27] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 09/27] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 10/27] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 11/27] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 12/27] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 13/27] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 14/27] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 15/27] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
2023-05-15 21:50     ` Jonathan Tan
2023-05-12  7:04   ` [PATCH v2 16/27] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
2023-05-16  0:00     ` Jonathan Tan
2023-05-12  7:04   ` [PATCH v2 17/27] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
2023-05-16  0:02     ` Jonathan Tan
2023-05-16  3:02       ` Elijah Newren
2023-05-12  7:04   ` [PATCH v2 18/27] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 19/27] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 20/27] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 21/27] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 22/27] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 23/27] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 24/27] merge-ll: rename from ll-merge Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 25/27] khash: name the structs that khash declares Elijah Newren via GitGitGadget
2023-05-12  7:04   ` [PATCH v2 26/27] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
2023-05-16  0:16     ` Jonathan Tan
2023-05-16  3:06       ` Elijah Newren
2023-05-12  7:04   ` [PATCH v2 27/27] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
2023-05-16  0:17     ` Jonathan Tan
2023-05-16  3:07       ` Elijah Newren
2023-05-16  6:33   ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 01/28] init-db: document existing bug with core.bare in template config Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 02/28] init-db: remove unnecessary global variable Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 03/28] init-db, clone: change unnecessary global into passed parameter Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 04/28] setup: adopt shared init-db & clone code Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 05/28] read-cache: move shared commit and ls-files code Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 06/28] add: modify add_files_to_cache() to avoid globals Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 07/28] read-cache: move shared add/checkout/commit code Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 08/28] statinfo: move stat_{data,validity} functions from cache/read-cache Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 09/28] run-command.h: move declarations for run-command.c from cache.h Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 10/28] name-hash.h: move declarations for name-hash.c " Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 11/28] sparse-index.h: move declarations for sparse-index.c " Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 12/28] preload-index.h: move declarations for preload-index.c from elsewhere Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 13/28] diff.h: move declaration for global in diff.c from cache.h Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 14/28] merge.h: move declarations for merge.c " Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 15/28] repository.h: move declaration of the_index " Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 16/28] read-cache*.h: move declarations for read-cache.c functions " Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 17/28] cache.h: remove this no-longer-used header Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 18/28] log-tree: replace include of revision.h with simple forward declaration Elijah Newren via GitGitGadget
2023-05-16  6:33     ` [PATCH v3 19/28] repository: remove unnecessary include of path.h Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 20/28] diff.h: remove unnecessary include of oidset.h Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 21/28] list-objects-filter-options.h: remove unneccessary include Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 22/28] builtin.h: remove unneccessary includes Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 23/28] git-compat-util.h: remove unneccessary include of wildmatch.h Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 24/28] merge-ll: rename from ll-merge Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 25/28] khash: name the structs that khash declares Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 26/28] object-store-ll.h: split this header out of object-store.h Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 27/28] hash-ll, hashmap: move oidhash() to hash-ll Elijah Newren via GitGitGadget
2023-05-16  6:34     ` [PATCH v3 28/28] fsmonitor-ll.h: split this header out of fsmonitor.h Elijah Newren via GitGitGadget
2023-05-23 19:49     ` [PATCH v3 00/28] Header cleanups (final splitting of cache.h, and some splitting of other headers) Calvin Wan
2023-05-24  0:11       ` Elijah Newren

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