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

[PATCH 01/16] treewide: ensure one of the appropriate headers is sourced first

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 23, 2023, 08:05 UTC
Message-ID
<a143d62472422e11537b68ab6e87cfafdc8e0c7c.1677139521.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1485.git.1677139521.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

We had several C files ignoring the rule to include one of the appropriate headers first; fix that.

While at it, the rule in Documentation/CodingGuidelines about which header to include has also fallen out of sync, so update the wording to mention other allowed headers.

Unfortunately, C files in reftable/ don't actually follow the previous or updated rule. If you follow the #include chain in its C files, reftable/system.h _tends_ to be first (i.e. record.c first includes record.h, which first includes basics.h, which first includees system.h), but not always (e.g. publicbasics.c includes another header first that does not include system.h). However, I'm going to punt on making actual changes to the C files in reftable/ since I do not want to risk bringing it out-of-sync with any version being used externally.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/CodingGuidelines | 8 ++++++--
 cbtree.c                       | 1 +
 diff-merges.c                  | 1 +
 fmt-merge-msg.c                | 1 +
 oidtree.c                      | 1 +
 oss-fuzz/fuzz-commit-graph.c   | 1 +
 oss-fuzz/fuzz-pack-headers.c   | 1 +
 oss-fuzz/fuzz-pack-idx.c       | 1 +
 prune-packed.c                 | 1 +
 rebase.c                       | 1 +
 refs/debug.c                   | 2 +-
 sub-process.c                  | 1 +
 12 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 9d5c27807a4..003393ed161 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -442,8 +442,12 @@ For C programs:
    detail.
 
  - The first #include in C files, except in platform specific compat/
-   implementations, must be either "git-compat-util.h", "cache.h" or
-   "builtin.h".  You do not have to include more than one of these.
+   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",
+   "t/helper/test-tool.h", "xdiff/xinclude.h", or
+   "reftable/system.h").  You do not have to include more than one of
+   these.
 
  - A C file must directly include the header files that declare the
    functions and the types it uses, except for the functions and types
diff --git a/cbtree.c b/cbtree.c
index 336e46dbba5..c1cc30a5dc7 100644
--- a/cbtree.c
+++ b/cbtree.c
@@ -4,6 +4,7 @@
  * Based on Adam Langley's adaptation of Dan Bernstein's public domain code
  * git clone https://github.com/agl/critbit.git
  */
+#include "git-compat-util.h"
 #include "cbtree.h"
 
 static struct cb_node *cb_node_of(const void *p)
diff --git a/diff-merges.c b/diff-merges.c
index 85cbefa5afd..faa7bc73a34 100644
--- a/diff-merges.c
+++ b/diff-merges.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "diff-merges.h"
 
 #include "revision.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index f48f44f9cd1..f317f129904 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "config.h"
 #include "refs.h"
 #include "object-store.h"
diff --git a/oidtree.c b/oidtree.c
index 0d39389bee2..7d57b7b19e3 100644
--- a/oidtree.c
+++ b/oidtree.c
@@ -2,6 +2,7 @@
  * A wrapper around cbtree which stores oids
  * May be used to replace oid-array for prefix (abbreviation) matches
  */
+#include "git-compat-util.h"
 #include "oidtree.h"
 #include "alloc.h"
 #include "hash.h"
diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c
index 914026f5d80..2992079dd97 100644
--- a/oss-fuzz/fuzz-commit-graph.c
+++ b/oss-fuzz/fuzz-commit-graph.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "commit-graph.h"
 #include "repository.h"
 
diff --git a/oss-fuzz/fuzz-pack-headers.c b/oss-fuzz/fuzz-pack-headers.c
index 99da1d0fd38..150c0f5fa2d 100644
--- a/oss-fuzz/fuzz-pack-headers.c
+++ b/oss-fuzz/fuzz-pack-headers.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "packfile.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 0c3d777aac8..609a343ee3e 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "object-store.h"
 #include "packfile.h"
 
diff --git a/prune-packed.c b/prune-packed.c
index 261520b472c..d2813f6a405 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "object-store.h"
 #include "packfile.h"
 #include "progress.h"
diff --git a/rebase.c b/rebase.c
index 6775cddb284..17a570f1ff9 100644
--- a/rebase.c
+++ b/rebase.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "rebase.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/refs/debug.c b/refs/debug.c
index eed8bc94b04..ff7766bc636 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -1,4 +1,4 @@
-
+#include "git-compat-util.h"
 #include "refs-internal.h"
 #include "trace.h"
 
diff --git a/sub-process.c b/sub-process.c
index 6d4232294db..1daf5a97525 100644
--- a/sub-process.c
+++ b/sub-process.c
@@ -1,6 +1,7 @@
 /*
  * Generic implementation of background process infrastructure.
  */
+#include "git-compat-util.h"
 #include "sub-process.h"
 #include "sigchain.h"
 #include "pkt-line.h"
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 2 of 60 in “Header cleanups”
  1. 00/16 Header cleanupsElijah Newren via GitGitGadget, Feb 23, 2023
  2. 01/16 treewide: ensure one of the appropriate headers is sourced firstElijah Newren via GitGitGadget, Feb 23, 2023
  3. 02/16 treewide: remove unnecessary git-compat-util.h includes in headersElijah Newren via GitGitGadget, Feb 23, 2023
  4. Derrick StoleeFeb 23, 2023
  5. Elijah NewrenFeb 23, 2023
  6. Junio C HamanoFeb 23, 2023
  7. Elijah NewrenFeb 23, 2023
  8. Junio C HamanoFeb 23, 2023
  9. Elijah NewrenFeb 23, 2023
  10. 03/16 treewide: remove unnecessary cache.h includesElijah Newren via GitGitGadget, Feb 23, 2023
  11. 04/16 treewide: remove unnecessary cache.h includes in source filesElijah Newren via GitGitGadget, Feb 23, 2023
  12. Derrick StoleeFeb 23, 2023
  13. 06/16 hash.h: move some oid-related declarations from cache.hElijah Newren via GitGitGadget, Feb 23, 2023
  14. Derrick StoleeFeb 23, 2023
  15. Elijah NewrenFeb 23, 2023
  16. Jonathan TanFeb 24, 2023
  17. 05/16 alloc.h: move ALLOC_GROW() functions from cache.hElijah Newren via GitGitGadget, Feb 23, 2023
  18. Derrick StoleeFeb 23, 2023
  19. Elijah NewrenFeb 23, 2023
  20. Junio C HamanoFeb 23, 2023
  21. Junio C HamanoFeb 23, 2023
  22. 07/16 hex.h: move some hex-related declarations from cache.hElijah Newren via GitGitGadget, Feb 23, 2023
  23. Derrick StoleeFeb 23, 2023
  24. Elijah NewrenFeb 23, 2023
  25. 09/16 ident.h: move ident-related declarations out of cache.hElijah Newren via GitGitGadget, Feb 23, 2023
  26. 08/16 pretty.h: move has_non_ascii() declaration from commit.hElijah Newren via GitGitGadget, Feb 23, 2023
  27. 10/16 object.h: stop depending on cache.h; make cache.h depend on object.hElijah Newren via GitGitGadget, Feb 23, 2023
  28. Derrick StoleeFeb 23, 2023
  29. Elijah NewrenFeb 23, 2023
  30. 11/16 dir.h: refactor to no longer need to include cache.hElijah Newren via GitGitGadget, Feb 23, 2023
  31. 12/16 object-store.h: move struct object_info from cache.hElijah Newren via GitGitGadget, Feb 23, 2023
  32. Derrick StoleeFeb 23, 2023
  33. Elijah NewrenFeb 23, 2023
  34. 13/16 replace-object.h: move read_replace_refs declaration from cache.h to hereElijah Newren via GitGitGadget, Feb 23, 2023
  35. 15/16 Remove unnecessary includes of builtin.hElijah Newren via GitGitGadget, Feb 23, 2023
  36. 14/16 treewide: replace cache.h with more direct headers, where possibleElijah Newren via GitGitGadget, Feb 23, 2023
  37. 16/16 diff.h: remove unnecessary include of object.hElijah Newren via GitGitGadget, Feb 23, 2023
  38. Derrick StoleeFeb 23, 2023
  39. 00/17 Header cleanupsElijah Newren via GitGitGadget, Feb 24, 2023
  40. 01/17 treewide: ensure one of the appropriate headers is sourced firstElijah Newren via GitGitGadget, Feb 24, 2023
  41. 02/17 treewide: remove unnecessary git-compat-util.h includes in headersElijah Newren via GitGitGadget, Feb 24, 2023
  42. 03/17 treewide: remove unnecessary cache.h includesElijah Newren via GitGitGadget, Feb 24, 2023
  43. 04/17 treewide: remove unnecessary cache.h includes in source filesElijah Newren via GitGitGadget, Feb 24, 2023
  44. 06/17 hash.h: move some oid-related declarations from cache.hElijah Newren via GitGitGadget, Feb 24, 2023
  45. 07/17 hex.h: move some hex-related declarations from cache.hElijah Newren via GitGitGadget, Feb 24, 2023
  46. 09/17 pretty.h: move has_non_ascii() declaration from commit.hElijah Newren via GitGitGadget, Feb 24, 2023
  47. 05/17 alloc.h: move ALLOC_GROW() functions from cache.hElijah Newren via GitGitGadget, Feb 24, 2023
  48. 10/17 ident.h: move ident-related declarations out of cache.hElijah Newren via GitGitGadget, Feb 24, 2023
  49. 11/17 object.h: stop depending on cache.h; make cache.h depend on object.hElijah Newren via GitGitGadget, Feb 24, 2023
  50. 12/17 dir.h: refactor to no longer need to include cache.hElijah Newren via GitGitGadget, Feb 24, 2023
  51. 13/17 object-store.h: move struct object_info from cache.hElijah Newren via GitGitGadget, Feb 24, 2023
  52. 15/17 treewide: replace cache.h with more direct headers, where possibleElijah Newren via GitGitGadget, Feb 24, 2023
  53. 14/17 replace-object.h: move read_replace_refs declaration from cache.h to hereElijah Newren via GitGitGadget, Feb 24, 2023
  54. 16/17 Remove unnecessary includes of builtin.hElijah Newren via GitGitGadget, Feb 24, 2023
  55. 08/17 cache.h: remove dependence on hex.h; make other files include it explicitlyElijah Newren via GitGitGadget, Feb 24, 2023
  56. 17/17 diff.h: remove unnecessary include of object.hElijah Newren via GitGitGadget, Feb 24, 2023
  57. Johannes SchindelinFeb 24, 2023
  58. Jonathan TanFeb 25, 2023
  59. Elijah NewrenFeb 25, 2023
  60. Derrick StoleeFeb 27, 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.