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

[PATCH v2 10/16] treewide: remove unnecessary includes of cache.h

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 21, 2023, 06:26 UTC
Message-ID
<a6c7245219af6552c139903b5ecd12e497384f67.1679379972.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1493.v2.git.1679379968.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

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

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

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

Just to ensure that nothing else was bringing in cache.h, all of the
affected files have been checked to ensure that
    gcc -E -I. $SOURCE_FILE | grep '"cache.h"'
found no hits and that
    make DEVELOPER=1 ${OBJECT_FILE_FOR_SOURCE_FILE}
successfully compiles without warnings.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 compat/terminal.c      | 2 +-
 gpg-interface.c        | 2 +-
 lockfile.c             | 2 +-
 parse-options.c        | 1 -
 t/helper/test-delta.c  | 1 -
 t/helper/test-trace2.c | 2 +-
 tempfile.c             | 3 ++-
 trace2/tr2_cfg.c       | 4 +++-
 trace2/tr2_cmd_name.c  | 3 ++-
 trace2/tr2_dst.c       | 3 ++-
 trace2/tr2_sid.c       | 3 ++-
 usage.c                | 3 ++-
 12 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/compat/terminal.c b/compat/terminal.c
index ed2b30b38f7..d87e3211892 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "compat/terminal.h"
 #include "gettext.h"
 #include "sigchain.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index 6644701fda0..aceeb083367 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "commit.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/lockfile.c b/lockfile.c
index 673c21d17a9..1d5ed016828 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2005, Junio C Hamano
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
 #include "lockfile.h"
diff --git a/parse-options.c b/parse-options.c
index a577cc85f67..b6803647d0e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,7 +1,6 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "abspath.h"
-#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "color.h"
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index 6609fcbc12e..e7d134ec251 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -11,7 +11,6 @@
 #include "test-tool.h"
 #include "git-compat-util.h"
 #include "delta.h"
-#include "cache.h"
 #include "wrapper.h"
 
 static const char usage_str[] =
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index f374c21ec32..a476df6c6cb 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,9 +1,9 @@
 #include "test-tool.h"
-#include "cache.h"
 #include "strvec.h"
 #include "run-command.h"
 #include "exec-cmd.h"
 #include "config.h"
+#include "trace2.h"
 
 typedef int(fn_unit_test)(int argc, const char **argv);
 
diff --git a/tempfile.c b/tempfile.c
index cdd2cab3bad..50c377134ce 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -42,7 +42,8 @@
  * file created by its parent.
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
+#include "path.h"
 #include "tempfile.h"
 #include "sigchain.h"
 #include "wrapper.h"
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index ec9ac1a6efd..78cfc15d52d 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -1,5 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
+#include "strbuf.h"
+#include "trace2.h"
 #include "trace2/tr2_cfg.h"
 #include "trace2/tr2_sysenv.h"
 
diff --git a/trace2/tr2_cmd_name.c b/trace2/tr2_cmd_name.c
index dd313204f51..b7b5a869b74 100644
--- a/trace2/tr2_cmd_name.c
+++ b/trace2/tr2_cmd_name.c
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "strbuf.h"
 #include "trace2/tr2_cmd_name.h"
 
 #define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME"
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index 273260e1f18..5be892cd5cd 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "abspath.h"
 #include "sigchain.h"
+#include "strbuf.h"
 #include "trace2/tr2_dst.h"
 #include "trace2/tr2_sid.h"
 #include "trace2/tr2_sysenv.h"
diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c
index 5f1ce6f85cf..09c4ef0d173 100644
--- a/trace2/tr2_sid.c
+++ b/trace2/tr2_sid.c
@@ -1,5 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "hex.h"
+#include "strbuf.h"
 #include "trace2/tr2_tbuf.h"
 #include "trace2/tr2_sid.h"
 
diff --git a/usage.c b/usage.c
index b53c99dbe5b..46d99f8bd43 100644
--- a/usage.c
+++ b/usage.c
@@ -3,8 +3,9 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "cache.h"
+#include "git-compat-util.h"
 #include "gettext.h"
+#include "trace2.h"
 #include "wrapper.h"
 
 static void vreportf(const char *prefix, const char *err, va_list params)
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 28 of 37 in “Header cleanups”
  1. 00/16 Header cleanupsElijah Newren via GitGitGadget, Mar 19, 2023
  2. 03/16 treewide: remove unnecessary inclusion of gettext.hElijah Newren via GitGitGadget, Mar 19, 2023
  3. 05/16 environment: move comment_line_char from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  4. 01/16 treewide: remove unnecessary cache.h inclusion from a few headersElijah Newren via GitGitGadget, Mar 19, 2023
  5. 04/16 treewide: remove unnecessary cache.h inclusion from several sourcesElijah Newren via GitGitGadget, Mar 19, 2023
  6. 07/16 cache.h: remove expand_user_path()Elijah Newren via GitGitGadget, Mar 19, 2023
  7. 06/16 abspath.h: move absolute path functions from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  8. 08/16 path.h: move function declarations for path.c functions from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  9. 02/16 treewide: be explicit about dependence on gettext.hElijah Newren via GitGitGadget, Mar 19, 2023
  10. 10/16 treewide: remove unnecessary includes of cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  11. 12/16 treewide: remove cache.h inclusion due to environment.h changesElijah Newren via GitGitGadget, Mar 19, 2023
  12. 09/16 wrapper.h: move declarations for wrapper.c functions from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  13. 14/16 treewide: remove cache.h inclusion due to setup.h changesElijah Newren via GitGitGadget, Mar 19, 2023
  14. 15/16 write-or-die.h: move declarations for write-or-die.c functions from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  15. 16/16 csum-file.h: remove unnecessary inclusion of cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  16. 11/16 environment.h: move declarations for environment.c functions from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  17. 13/16 setup.h: move declarations for setup.c functions from cache.hElijah Newren via GitGitGadget, Mar 19, 2023
  18. Ævar Arnfjörð BjarmasonMar 20, 2023
  19. Elijah NewrenMar 20, 2023
  20. 00/16 Header cleanupsElijah Newren via GitGitGadget, Mar 21, 2023
  21. 01/16 treewide: remove unnecessary cache.h inclusion from a few headersElijah Newren via GitGitGadget, Mar 21, 2023
  22. 03/16 treewide: remove unnecessary inclusion of gettext.hElijah Newren via GitGitGadget, Mar 21, 2023
  23. 04/16 treewide: remove unnecessary cache.h inclusion from several sourcesElijah Newren via GitGitGadget, Mar 21, 2023
  24. 05/16 environment: move comment_line_char from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  25. 07/16 cache.h: remove expand_user_path()Elijah Newren via GitGitGadget, Mar 21, 2023
  26. 06/16 abspath.h: move absolute path functions from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  27. 08/16 path.h: move function declarations for path.c functions from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  28. 10/16 treewide: remove unnecessary includes of cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  29. 12/16 treewide: remove cache.h inclusion due to environment.h changesElijah Newren via GitGitGadget, Mar 21, 2023
  30. 09/16 wrapper.h: move declarations for wrapper.c functions from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  31. 11/16 environment.h: move declarations for environment.c functions from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  32. 02/16 treewide: be explicit about dependence on gettext.hElijah Newren via GitGitGadget, Mar 21, 2023
  33. 14/16 treewide: remove cache.h inclusion due to setup.h changesElijah Newren via GitGitGadget, Mar 21, 2023
  34. 15/16 write-or-die.h: move declarations for write-or-die.c functions from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  35. 16/16 csum-file.h: remove unnecessary inclusion of cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  36. 13/16 setup.h: move declarations for setup.c functions from cache.hElijah Newren via GitGitGadget, Mar 21, 2023
  37. Jonathan TanMar 21, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.