]> git.ipfire.org Git - thirdparty/git.git/commitdiff
treewide: ensure one of the appropriate headers is sourced first
authorElijah Newren <newren@gmail.com>
Fri, 24 Feb 2023 00:09:20 +0000 (00:09 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Feb 2023 01:25:28 +0000 (17:25 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
Documentation/CodingGuidelines
cbtree.c
compat/fsmonitor/fsm-ipc-win32.c
compat/fsmonitor/fsm-settings-darwin.c
diff-merges.c
fmt-merge-msg.c
oidtree.c
oss-fuzz/fuzz-commit-graph.c
oss-fuzz/fuzz-pack-headers.c
oss-fuzz/fuzz-pack-idx.c
prune-packed.c
rebase.c
refs/debug.c
sub-process.c

index 9d5c27807a40bcf597c6266b848d89f15afb5165..003393ed161dab04a5c73269d49fa2e2f2fdd1f6 100644 (file)
@@ -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
index 336e46dbba5a06e7d9b5fdb5dd6f3c7bdd971186..c1cc30a5dc7edaadfa69877b4a8f7a6e3a92ffdb 100644 (file)
--- 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)
index e08c505c148933ed830ae2071198999827d84d14..c9536dfb666318468612701481d7216fd3b723e9 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor-ipc.h"
 
index 6abbc7af3ab53cd4911edf93d91ebf18e2c5c152..58b623fbb9a3bf598e44d6fe377340d960e004f4 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "config.h"
 #include "fsmonitor.h"
 #include "fsmonitor-ipc.h"
index 85cbefa5afd7c00e903232011ef3d2ff7aca4a8f..faa7bc73a343a1eca1e28d920ab32980e0a2f730 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "diff-merges.h"
 
 #include "revision.h"
index f48f44f9cd1dbdd3aeafbe5a4bd3598e783d0e25..f317f129904e79b04c0d21b763a22963a8a8e16c 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "config.h"
 #include "refs.h"
 #include "object-store.h"
index 0d39389bee29be3f0496185331df1ac85f87003b..7d57b7b19e364706f037ccb44388e00e901b1583 100644 (file)
--- 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"
index 914026f5d80f876c8a7c28a914a58295a5a72346..2992079dd97d75892f4f411cd4a979f459d68170 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "commit-graph.h"
 #include "repository.h"
 
index 99da1d0fd385eb3bc0c7f0b4a0b8cd167e0cb5e0..150c0f5fa2d7ec2b9dd6a14f6000e5b58b753aa9 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "packfile.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
index 0c3d777aac8de618a36777c5c82edae302c1bbcc..609a343ee3ea41e6c4f18f0d07a104922dc952f2 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "object-store.h"
 #include "packfile.h"
 
index 261520b472c9c2bbac57ea94460dcabeefb3a91b..d2813f6a40547035daaff40fcd0bc296c0832cca 100644 (file)
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "object-store.h"
 #include "packfile.h"
 #include "progress.h"
index 6775cddb28434d0780cb483357476f4783e1f596..17a570f1ff97fab8e789d2960ae54894b1c42a80 100644 (file)
--- a/rebase.c
+++ b/rebase.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "rebase.h"
 #include "config.h"
 #include "gettext.h"
index eed8bc94b04f68125bb84eddfc26381ad86d3157..ff7766bc636ca63d3df7a0f2b8c5c89dc40ac3a6 100644 (file)
@@ -1,4 +1,4 @@
-
+#include "git-compat-util.h"
 #include "refs-internal.h"
 #include "trace.h"
 
index 6d4232294dbee7ad2928b0ac12e1860dcf04a12d..1daf5a975254b9b9ea286c5486f4d07f3874bb26 100644 (file)
@@ -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"