@@ -446,12 +446,41 @@ For C programs:
446
446
detail.
447
447
448
448
- The first #include in C files, except in platform specific compat/
449
- implementations and sha1dc/, must be either "git-compat-util.h" or
450
- one of the approved headers that includes it first for you. (The
451
- approved headers currently include "builtin.h",
452
- "t/helper/test-tool.h", "xdiff/xinclude.h", or
453
- "reftable/system.h".) You do not have to include more than one of
454
- these.
449
+ implementations and sha1dc/, must be <git-compat-util.h>. This
450
+ header file insulates other header files and source files from
451
+ platform differences, like which system header files must be
452
+ included in what order, and what C preprocessor feature macros must
453
+ be defined to trigger certain features we expect out of the system.
454
+ A collorary to this is that C files should not directly include
455
+ system header files themselves.
456
+
457
+ There are some exceptions, because certain group of files that
458
+ implement an API all have to include the same header file that
459
+ defines the API and it is convenient to include <git-compat-util.h>
460
+ there. Namely:
461
+
462
+ - the implementation of the built-in commands in the "builtin/"
463
+ directory that include "builtin.h" for the cmd_foo() prototype
464
+ definition,
465
+
466
+ - the test helper programs in the "t/helper/" directory that include
467
+ "t/helper/test-tool.h" for the cmd__foo() prototype definition,
468
+
469
+ - the xdiff implementation in the "xdiff/" directory that includes
470
+ "xdiff/xinclude.h" for the xdiff machinery internals,
471
+
472
+ - the unit test programs in "t/unit-tests/" directory that include
473
+ "t/unit-tests/test-lib.h" that gives them the unit-tests
474
+ framework, and
475
+
476
+ - the source files that implement reftable in the "reftable/"
477
+ directory that include "reftable/system.h" for the reftable
478
+ internals,
479
+
480
+ are allowed to assume that they do not have to include
481
+ <git-compat-util.h> themselves, as it is included as the first
482
+ '#include' in these header files. These headers must be the first
483
+ header file to be "#include"d in them, though.
455
484
456
485
- A C file must directly include the header files that declare the
457
486
functions and the types it uses, except for the functions and types
0 commit comments