treewide: ensure one of the appropriate headers is sourced first

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>

Elijah Newren committed Feb 24, 2023 at 00:09 UTC 8bff5ca030d314d613e1ab58f07b27914d6dfd33
14 files changed +19 -3
Documentation/CodingGuidelines
+6 -2
@@ -442,8 +442,12 @@ For C programs:
442 detail.
443
444 - The first #include in C files, except in platform specific compat/
445 - implementations, must be either "git-compat-util.h", "cache.h" or
446 - "builtin.h". You do not have to include more than one of these.
445 + implementations and sha1dc/, must be either "git-compat-util.h" or
446 + one of the approved headers that includes it first for you. (The
447 + approved headers currently include "cache.h", "builtin.h",
448 + "t/helper/test-tool.h", "xdiff/xinclude.h", or
449 + "reftable/system.h"). You do not have to include more than one of
450 + these.
451
452 - A C file must directly include the header files that declare the
453 functions and the types it uses, except for the functions and types
cbtree.c
+1
@@ -4,6 +4,7 @@
4 * Based on Adam Langley's adaptation of Dan Bernstein's public domain code
5 * git clone https://github.com/agl/critbit.git
6 */
7 +#include "git-compat-util.h"
8 #include "cbtree.h"
9
10 static struct cb_node *cb_node_of(const void *p)
compat/fsmonitor/fsm-ipc-win32.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "config.h"
3 #include "fsmonitor-ipc.h"
4
compat/fsmonitor/fsm-settings-darwin.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "config.h"
3 #include "fsmonitor.h"
4 #include "fsmonitor-ipc.h"
diff-merges.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "diff-merges.h"
3
4 #include "revision.h"
fmt-merge-msg.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "config.h"
3 #include "refs.h"
4 #include "object-store.h"
oidtree.c
+1
@@ -2,6 +2,7 @@
2 * A wrapper around cbtree which stores oids
3 * May be used to replace oid-array for prefix (abbreviation) matches
4 */
5 +#include "git-compat-util.h"
6 #include "oidtree.h"
7 #include "alloc.h"
8 #include "hash.h"
oss-fuzz/fuzz-commit-graph.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "commit-graph.h"
3 #include "repository.h"
4
oss-fuzz/fuzz-pack-headers.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "packfile.h"
3
4 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
oss-fuzz/fuzz-pack-idx.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "object-store.h"
3 #include "packfile.h"
4
prune-packed.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "object-store.h"
3 #include "packfile.h"
4 #include "progress.h"
rebase.c
+1
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "rebase.h"
3 #include "config.h"
4 #include "gettext.h"
refs/debug.c
+1 -1
@@ -1,4 +1,4 @@
1 -
1 +#include "git-compat-util.h"
2 #include "refs-internal.h"
3 #include "trace.h"
4
sub-process.c
+1
@@ -1,6 +1,7 @@
1 /*
2 * Generic implementation of background process infrastructure.
3 */
4 +#include "git-compat-util.h"
5 #include "sub-process.h"
6 #include "sigchain.h"
7 #include "pkt-line.h"