* [PATCH] doc: clarify the wording on <git-compat-util.h> requirement
@ 2024-02-24 20:22 Junio C Hamano
2024-02-24 22:36 ` [PATCH v2] " Junio C Hamano
2024-02-24 22:38 ` [PATCH] " Kyle Lippincott
0 siblings, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2024-02-24 20:22 UTC (permalink / raw)
To: git; +Cc: Kyle Lippincott, Calvin Wan, Jonathan Tan, Elijah Newren
The reason why we insist including the compat-util header as the
very first thing is because it is our mechanism to absorb the
differences across platforms, like the order in which system header
files must be included, and C preprocessor feature macros that are
needed to trigger certain features we want out of the systems, and
insulate other headers and sources from such minutiae.
Earlier we tried to clarify the rule in the coding guidelines
document, but the wording was a bit fuzzy that can lead to
misinterpretations like you can include xdiff/xinclude.h only to
avoid having to include git-compat-util.h file even if you have
nothing to do with xdiff implementation, for example. "You do not
have to include more than one of these" were also misleading and
would have been puzzling if you _needed_ to depend on more than one
of these approved headers (answer: you are allowed to include them
all if you need the declarations in them for reasons other than that
you want to avoid including compat-util yourself).
Instead of using the phrase "approved headers", enumerate them as
exceptions, each labeled with intended audiences, to avoid such
misinterpretations. The structure also makes it easier to add new
exceptions, so add the description of "t/unit-tests/test-lib.h"
being an exception only for the unit tests implementation as an
example.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* git-std-lib folks CC'ed to show them where to put their exception
when things start to stabilize; Elijah CC'ed for his 8bff5ca0
(treewide: ensure one of the appropriate headers is sourced
first, 2023-02-24) and bc5c5ec0 (cache.h: remove this
no-longer-used header, 2023-05-16).
Documentation/CodingGuidelines | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines
index 578587a471..b3443dd773 100644
--- c/Documentation/CodingGuidelines
+++ w/Documentation/CodingGuidelines
@@ -446,12 +446,30 @@ For C programs:
detail.
- The first #include in C files, except in platform specific compat/
- 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 "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.
+ implementations and sha1dc/, must be "git-compat-util.h". In
+ addition:
+
+ - the implementation of the built-in commands in the "builtin/"
+ directory that include "builtin.h" for the cmd_foo() prototype
+ definition
+
+ - the test helper programs in the "t/helper/" directory that include
+ "t/helper/test-tool.h" for the cmd__foo() prototype definition
+
+ - the xdiff implementation in the "xdiff/" directory that includes
+ "xdiff/xinclude.h" for the xdiff machinery internals
+
+ - the unit test programs in "t/unit-tests/" directory that include
+ "test-lib.h" that gives them the unit-tests framework
+
+ - the source files that implement reftable in the "reftable/"
+ directory that include "reftable/system.h" for the reftable
+ internals
+
+ are allowed to assume that their header file includes
+ "git-compat-util.h", and they do not have to include
+ "git-compat-util.h" themselves. These headers must be the first
+ header file to be "#include"d in them, though.
- A C file must directly include the header files that declare the
functions and the types it uses, except for the functions and types
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-24 20:22 [PATCH] doc: clarify the wording on <git-compat-util.h> requirement Junio C Hamano
@ 2024-02-24 22:36 ` Junio C Hamano
2024-02-26 23:28 ` [PATCH v3] " Junio C Hamano
2024-02-24 22:38 ` [PATCH] " Kyle Lippincott
1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2024-02-24 22:36 UTC (permalink / raw)
To: git; +Cc: Kyle Lippincott, Calvin Wan, Jonathan Tan, Elijah Newren
The reason why we require the <git-compat-util.h> file to be the
first header file to be included is because it insulates other
header files and source files from platform differences, like which
system header files must be included in what order, and what C
preprocessor feature macros must be defined to trigger certain
features we want out of the system.
We tried to clarify the rule in the coding guidelines document, but
the wording was a bit fuzzy that can lead to misinterpretations like
you can include <xdiff/xinclude.h> only to avoid having to include
<git-compat-util.h> even if you have nothing to do with the xdiff
implementation, for example. "You do not have to include more than
one of these" was also misleading and would have been puzzling if
you _needed_ to depend on more than one of these approved headers
(answer: you are allowed to include them all if you need the
declarations in them for reasons other than that you want to avoid
including compat-util yourself).
Instead of using the phrase "approved headers", enumerate them as
exceptions, each labeled with its intended audiences, to avoid such
misinterpretations. The structure also makes it easier to add new
exceptions, so add the description of "t/unit-tests/test-lib.h"
being an exception only for the unit tests implementation as an
example.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* The most notable change since the first one is that the reason
why the requirement exists is added to the document, not just
telling them what to do but also telling them why.
Also the path to "test-lib.h" used in the unit-test framework has
been spelled out relative to the root of the working tree, like
all other header files.
Range-diff:
1: dde3a79470 ! 1: b9f3d36e9a doc: clarify the wording on <git-compat-util.h> requirement
@@ Metadata
## Commit message ##
doc: clarify the wording on <git-compat-util.h> requirement
- The reason why we insist including the compat-util header as the
- very first thing is because it is our mechanism to absorb the
- differences across platforms, like the order in which system header
- files must be included, and C preprocessor feature macros that are
- needed to trigger certain features we want out of the systems, and
- insulate other headers and sources from such minutiae.
+ The reason why we require the <git-compat-util.h> file to be the
+ first header file to be included is because it insulates other
+ header files and source files from platform differences, like which
+ system header files must be included in what order, and what C
+ preprocessor feature macros must be defined to trigger certain
+ features we want out of the system.
- Earlier we tried to clarify the rule in the coding guidelines
- document, but the wording was a bit fuzzy that can lead to
- misinterpretations like you can include xdiff/xinclude.h only to
- avoid having to include git-compat-util.h file even if you have
- nothing to do with xdiff implementation, for example. "You do not
- have to include more than one of these" were also misleading and
- would have been puzzling if you _needed_ to depend on more than one
- of these approved headers (answer: you are allowed to include them
- all if you need the declarations in them for reasons other than that
- you want to avoid including compat-util yourself).
+ We tried to clarify the rule in the coding guidelines document, but
+ the wording was a bit fuzzy that can lead to misinterpretations like
+ you can include <xdiff/xinclude.h> only to avoid having to include
+ <git-compat-util.h> even if you have nothing to do with the xdiff
+ implementation, for example. "You do not have to include more than
+ one of these" was also misleading and would have been puzzling if
+ you _needed_ to depend on more than one of these approved headers
+ (answer: you are allowed to include them all if you need the
+ declarations in them for reasons other than that you want to avoid
+ including compat-util yourself).
Instead of using the phrase "approved headers", enumerate them as
- exceptions, each labeled with intended audiences, to avoid such
+ exceptions, each labeled with its intended audiences, to avoid such
misinterpretations. The structure also makes it easier to add new
exceptions, so add the description of "t/unit-tests/test-lib.h"
being an exception only for the unit tests implementation as an
@@ Documentation/CodingGuidelines: For C programs:
- "t/helper/test-tool.h", "xdiff/xinclude.h", or
- "reftable/system.h".) You do not have to include more than one of
- these.
-+ implementations and sha1dc/, must be "git-compat-util.h". In
-+ addition:
++ implementations and sha1dc/, must be "git-compat-util.h". This
++ header file insulates other header files and source files from
++ platform differences, like which system header files must be
++ included in what order, and what C preprocessor feature macros must
++ be defined to trigger certain features we expect out of the system.
++
++ In addition:
+
+ - the implementation of the built-in commands in the "builtin/"
+ directory that include "builtin.h" for the cmd_foo() prototype
@@ Documentation/CodingGuidelines: For C programs:
+ "xdiff/xinclude.h" for the xdiff machinery internals
+
+ - the unit test programs in "t/unit-tests/" directory that include
-+ "test-lib.h" that gives them the unit-tests framework
++ "t/unit-tests/test-lib.h" that gives them the unit-tests
++ framework
+
+ - the source files that implement reftable in the "reftable/"
+ directory that include "reftable/system.h" for the reftable
+ internals
+
-+ are allowed to assume that their header file includes
-+ "git-compat-util.h", and they do not have to include
-+ "git-compat-util.h" themselves. These headers must be the first
++ are allowed to assume that they do not have to include
++ "git-compat-util.h" themselves, as it is included as the first
++ '#include' in these header files. These headers must be the first
+ header file to be "#include"d in them, though.
- A C file must directly include the header files that declare the
Documentation/CodingGuidelines | 36 ++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 578587a471..291b2898a2 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -446,12 +446,36 @@ For C programs:
detail.
- The first #include in C files, except in platform specific compat/
- 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 "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.
+ implementations and sha1dc/, must be "git-compat-util.h". This
+ header file insulates other header files and source files from
+ platform differences, like which system header files must be
+ included in what order, and what C preprocessor feature macros must
+ be defined to trigger certain features we expect out of the system.
+
+ In addition:
+
+ - the implementation of the built-in commands in the "builtin/"
+ directory that include "builtin.h" for the cmd_foo() prototype
+ definition
+
+ - the test helper programs in the "t/helper/" directory that include
+ "t/helper/test-tool.h" for the cmd__foo() prototype definition
+
+ - the xdiff implementation in the "xdiff/" directory that includes
+ "xdiff/xinclude.h" for the xdiff machinery internals
+
+ - the unit test programs in "t/unit-tests/" directory that include
+ "t/unit-tests/test-lib.h" that gives them the unit-tests
+ framework
+
+ - the source files that implement reftable in the "reftable/"
+ directory that include "reftable/system.h" for the reftable
+ internals
+
+ are allowed to assume that they do not have to include
+ "git-compat-util.h" themselves, as it is included as the first
+ '#include' in these header files. These headers must be the first
+ header file to be "#include"d in them, though.
- A C file must directly include the header files that declare the
functions and the types it uses, except for the functions and types
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-24 20:22 [PATCH] doc: clarify the wording on <git-compat-util.h> requirement Junio C Hamano
2024-02-24 22:36 ` [PATCH v2] " Junio C Hamano
@ 2024-02-24 22:38 ` Kyle Lippincott
2024-02-24 22:54 ` Junio C Hamano
1 sibling, 1 reply; 8+ messages in thread
From: Kyle Lippincott @ 2024-02-24 22:38 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Calvin Wan, Jonathan Tan, Elijah Newren
On Sat, Feb 24, 2024 at 12:22 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> The reason why we insist including the compat-util header as the
> very first thing is because it is our mechanism to absorb the
> differences across platforms, like the order in which system header
> files must be included, and C preprocessor feature macros that are
> needed to trigger certain features we want out of the systems, and
> insulate other headers and sources from such minutiae.
>
> Earlier we tried to clarify the rule in the coding guidelines
> document, but the wording was a bit fuzzy that can lead to
> misinterpretations like you can include xdiff/xinclude.h only to
> avoid having to include git-compat-util.h file even if you have
> nothing to do with xdiff implementation, for example. "You do not
> have to include more than one of these" were also misleading and
> would have been puzzling if you _needed_ to depend on more than one
> of these approved headers (answer: you are allowed to include them
> all if you need the declarations in them for reasons other than that
> you want to avoid including compat-util yourself).
>
> Instead of using the phrase "approved headers", enumerate them as
> exceptions, each labeled with intended audiences, to avoid such
> misinterpretations. The structure also makes it easier to add new
> exceptions, so add the description of "t/unit-tests/test-lib.h"
> being an exception only for the unit tests implementation as an
> example.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> * git-std-lib folks CC'ed to show them where to put their exception
> when things start to stabilize; Elijah CC'ed for his 8bff5ca0
> (treewide: ensure one of the appropriate headers is sourced
> first, 2023-02-24) and bc5c5ec0 (cache.h: remove this
> no-longer-used header, 2023-05-16).
>
> Documentation/CodingGuidelines | 30 ++++++++++++++++++++++++------
> 1 file changed, 24 insertions(+), 6 deletions(-)
>
> diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines
> index 578587a471..b3443dd773 100644
> --- c/Documentation/CodingGuidelines
> +++ w/Documentation/CodingGuidelines
> @@ -446,12 +446,30 @@ For C programs:
> detail.
>
> - The first #include in C files, except in platform specific compat/
> - 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 "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.
> + implementations and sha1dc/, must be "git-compat-util.h". In
> + addition:
This "In addition" ties to the "are allowed to" 19 lines below, which
was confusing for me until I intentionally ignored the "In addition",
continued reading, and finally caught the other piece of it. Perhaps
either `Exceptions:`, or something like `The following cases are
allowed to assume that their header file includes "git-compat-util.h",
and they do not have to include "git-compat-util.h" themselves:` -- I
have a slight preference for the latter form, but I worry that the
"These headers must be the first header file to be "#include"d in
them" bit will be missed. So maybe if we went with the latter version,
we change each bullet point to include that qualification. Example: -
the implementation of the built-in commands in the "builtin/"
directory that include "builtin.h" as the first header". I don't know
if we need the reasoning why you'd #include these files in the bullets
below, which is why I didn't include it here. I'm assuming there's a
concern about implying that builtin/foo.c should include builtin.h
instead of git-compat-util.h (even if foo.c doesn't use cmd_foo()?).
> +
> + - the implementation of the built-in commands in the "builtin/"
> + directory that include "builtin.h" for the cmd_foo() prototype
> + definition
> +
> + - the test helper programs in the "t/helper/" directory that include
> + "t/helper/test-tool.h" for the cmd__foo() prototype definition
> +
> + - the xdiff implementation in the "xdiff/" directory that includes
> + "xdiff/xinclude.h" for the xdiff machinery internals
> +
> + - the unit test programs in "t/unit-tests/" directory that include
> + "test-lib.h" that gives them the unit-tests framework
> +
> + - the source files that implement reftable in the "reftable/"
> + directory that include "reftable/system.h" for the reftable
> + internals
> +
> + are allowed to assume that their header file includes
> + "git-compat-util.h", and they do not have to include
> + "git-compat-util.h" themselves. These headers must be the first
> + header file to be "#include"d in them, though.
>
> - A C file must directly include the header files that declare the
> functions and the types it uses, except for the functions and types
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-24 22:38 ` [PATCH] " Kyle Lippincott
@ 2024-02-24 22:54 ` Junio C Hamano
0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2024-02-24 22:54 UTC (permalink / raw)
To: Kyle Lippincott; +Cc: git, Calvin Wan, Jonathan Tan, Elijah Newren
Kyle Lippincott <spectral@google.com> writes:
> This "In addition" ties to the "are allowed to" 19 lines below, which
> was confusing for me until I intentionally ignored the "In addition",
> continued reading, and finally caught the other piece of it. Perhaps
> either `Exceptions:`, or something like `The following cases are
> allowed to assume that their header file includes "git-compat-util.h",
> and they do not have to include "git-compat-util.h" themselves:` -- I
> have a slight preference for the latter form, but I worry that the
> "These headers must be the first header file to be "#include"d in
> them" bit will be missed.
I'd appreciate people to help figuring out what the preamble should
read like to make it easier to follow.
> ... I don't know
> if we need the reasoning why you'd #include these files in the bullets
> below, which is why I didn't include it here. I'm assuming there's a
> concern about implying that builtin/foo.c should include builtin.h
> instead of git-compat-util.h (even if foo.c doesn't use cmd_foo()?).
It is more about helping folks new to the codebase understand the
reasoning behind the convention. As whoever implements "git foo" as
a built-in command is supposed to
- declare cmd_foo() in builtin.h
- add builtin/foo.c, define cmd_foo() there, and include builtin.h
- add "foo" and "cmd_foo" to git.c:commands[].
it is natural to expect any and all builtin/foo.c to include
builtin.h (hence it makes it convenient to allow an exception by
including compat-util in builtin.h to give everybody in builtin/
indirect access to compat-util).
But those who are not yet familar with the structure of the system
may not understand why it is natural. So, addition of "why is this
header allowed to be a substitute for which source files? Because
these source files are supposed to be including that header anyway"
is an important part of this patch.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-24 22:36 ` [PATCH v2] " Junio C Hamano
@ 2024-02-26 23:28 ` Junio C Hamano
2024-02-26 23:57 ` Kyle Lippincott
2024-02-27 4:25 ` Elijah Newren
0 siblings, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2024-02-26 23:28 UTC (permalink / raw)
To: git; +Cc: Kyle Lippincott, Calvin Wan, Jonathan Tan, Elijah Newren
The reason why we require the <git-compat-util.h> file to be the
first header file to be included is because it insulates other
header files and source files from platform differences, like which
system header files must be included in what order, and what C
preprocessor feature macros must be defined to trigger certain
features we want out of the system.
We tried to clarify the rule in the coding guidelines document, but
the wording was a bit fuzzy that can lead to misinterpretations like
you can include <xdiff/xinclude.h> only to avoid having to include
<git-compat-util.h> even if you have nothing to do with the xdiff
implementation, for example. "You do not have to include more than
one of these" was also misleading and would have been puzzling if
you _needed_ to depend on more than one of these approved headers
(answer: you are allowed to include them all if you need the
declarations in them for reasons other than that you want to avoid
including compat-util yourself).
Instead of using the phrase "approved headers", enumerate them as
exceptions, each labeled with its intended audiences, to avoid such
misinterpretations. The structure also makes it easier to add new
exceptions, so add the description of "t/unit-tests/test-lib.h"
being an exception only for the unit tests implementation as an
example.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* Updated the leading phrase introducing the list of exceptions.
I think this is now clear enough to be ready for 'next'?
Range-diff:
1: 2e7082d2d2 ! 1: 470f33a078 doc: clarify the wording on <git-compat-util.h> requirement
@@ Documentation/CodingGuidelines: For C programs:
- "t/helper/test-tool.h", "xdiff/xinclude.h", or
- "reftable/system.h".) You do not have to include more than one of
- these.
-+ implementations and sha1dc/, must be "git-compat-util.h". This
++ implementations and sha1dc/, must be <git-compat-util.h>. This
+ header file insulates other header files and source files from
+ platform differences, like which system header files must be
+ included in what order, and what C preprocessor feature macros must
+ be defined to trigger certain features we expect out of the system.
++ A collorary to this is that C files should not directly include
++ system header files themselves.
+
-+ In addition:
++ There are some exceptions, because certain group of files that
++ implement an API all have to include the same header file that
++ defines the API and it is convenient to include <git-compat-util.h>
++ there. Namely:
+
+ - the implementation of the built-in commands in the "builtin/"
+ directory that include "builtin.h" for the cmd_foo() prototype
-+ definition
++ definition,
+
+ - the test helper programs in the "t/helper/" directory that include
-+ "t/helper/test-tool.h" for the cmd__foo() prototype definition
++ "t/helper/test-tool.h" for the cmd__foo() prototype definition,
+
+ - the xdiff implementation in the "xdiff/" directory that includes
-+ "xdiff/xinclude.h" for the xdiff machinery internals
++ "xdiff/xinclude.h" for the xdiff machinery internals,
+
+ - the unit test programs in "t/unit-tests/" directory that include
+ "t/unit-tests/test-lib.h" that gives them the unit-tests
-+ framework
++ framework, and
+
+ - the source files that implement reftable in the "reftable/"
+ directory that include "reftable/system.h" for the reftable
-+ internals
++ internals,
+
+ are allowed to assume that they do not have to include
-+ "git-compat-util.h" themselves, as it is included as the first
++ <git-compat-util.h> themselves, as it is included as the first
+ '#include' in these header files. These headers must be the first
+ header file to be "#include"d in them, though.
Documentation/CodingGuidelines | 41 +++++++++++++++++++++++++++++-----
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 578587a471..806979f75b 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -446,12 +446,41 @@ For C programs:
detail.
- The first #include in C files, except in platform specific compat/
- 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 "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.
+ implementations and sha1dc/, must be <git-compat-util.h>. This
+ header file insulates other header files and source files from
+ platform differences, like which system header files must be
+ included in what order, and what C preprocessor feature macros must
+ be defined to trigger certain features we expect out of the system.
+ A collorary to this is that C files should not directly include
+ system header files themselves.
+
+ There are some exceptions, because certain group of files that
+ implement an API all have to include the same header file that
+ defines the API and it is convenient to include <git-compat-util.h>
+ there. Namely:
+
+ - the implementation of the built-in commands in the "builtin/"
+ directory that include "builtin.h" for the cmd_foo() prototype
+ definition,
+
+ - the test helper programs in the "t/helper/" directory that include
+ "t/helper/test-tool.h" for the cmd__foo() prototype definition,
+
+ - the xdiff implementation in the "xdiff/" directory that includes
+ "xdiff/xinclude.h" for the xdiff machinery internals,
+
+ - the unit test programs in "t/unit-tests/" directory that include
+ "t/unit-tests/test-lib.h" that gives them the unit-tests
+ framework, and
+
+ - the source files that implement reftable in the "reftable/"
+ directory that include "reftable/system.h" for the reftable
+ internals,
+
+ are allowed to assume that they do not have to include
+ <git-compat-util.h> themselves, as it is included as the first
+ '#include' in these header files. These headers must be the first
+ header file to be "#include"d in them, though.
- A C file must directly include the header files that declare the
functions and the types it uses, except for the functions and types
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-26 23:28 ` [PATCH v3] " Junio C Hamano
@ 2024-02-26 23:57 ` Kyle Lippincott
2024-02-27 4:25 ` Elijah Newren
1 sibling, 0 replies; 8+ messages in thread
From: Kyle Lippincott @ 2024-02-26 23:57 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Calvin Wan, Jonathan Tan, Elijah Newren
On Mon, Feb 26, 2024 at 3:28 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> The reason why we require the <git-compat-util.h> file to be the
> first header file to be included is because it insulates other
> header files and source files from platform differences, like which
> system header files must be included in what order, and what C
> preprocessor feature macros must be defined to trigger certain
> features we want out of the system.
>
> We tried to clarify the rule in the coding guidelines document, but
> the wording was a bit fuzzy that can lead to misinterpretations like
> you can include <xdiff/xinclude.h> only to avoid having to include
> <git-compat-util.h> even if you have nothing to do with the xdiff
> implementation, for example. "You do not have to include more than
> one of these" was also misleading and would have been puzzling if
> you _needed_ to depend on more than one of these approved headers
> (answer: you are allowed to include them all if you need the
> declarations in them for reasons other than that you want to avoid
> including compat-util yourself).
>
> Instead of using the phrase "approved headers", enumerate them as
> exceptions, each labeled with its intended audiences, to avoid such
> misinterpretations. The structure also makes it easier to add new
> exceptions, so add the description of "t/unit-tests/test-lib.h"
> being an exception only for the unit tests implementation as an
> example.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> * Updated the leading phrase introducing the list of exceptions.
> I think this is now clear enough to be ready for 'next'?
>
> Range-diff:
> 1: 2e7082d2d2 ! 1: 470f33a078 doc: clarify the wording on <git-compat-util.h> requirement
> @@ Documentation/CodingGuidelines: For C programs:
> - "t/helper/test-tool.h", "xdiff/xinclude.h", or
> - "reftable/system.h".) You do not have to include more than one of
> - these.
> -+ implementations and sha1dc/, must be "git-compat-util.h". This
> ++ implementations and sha1dc/, must be <git-compat-util.h>. This
> + header file insulates other header files and source files from
> + platform differences, like which system header files must be
> + included in what order, and what C preprocessor feature macros must
> + be defined to trigger certain features we expect out of the system.
> ++ A collorary to this is that C files should not directly include
> ++ system header files themselves.
> +
> -+ In addition:
> ++ There are some exceptions, because certain group of files that
> ++ implement an API all have to include the same header file that
> ++ defines the API and it is convenient to include <git-compat-util.h>
> ++ there. Namely:
> +
> + - the implementation of the built-in commands in the "builtin/"
> + directory that include "builtin.h" for the cmd_foo() prototype
> -+ definition
> ++ definition,
> +
> + - the test helper programs in the "t/helper/" directory that include
> -+ "t/helper/test-tool.h" for the cmd__foo() prototype definition
> ++ "t/helper/test-tool.h" for the cmd__foo() prototype definition,
> +
> + - the xdiff implementation in the "xdiff/" directory that includes
> -+ "xdiff/xinclude.h" for the xdiff machinery internals
> ++ "xdiff/xinclude.h" for the xdiff machinery internals,
> +
> + - the unit test programs in "t/unit-tests/" directory that include
> + "t/unit-tests/test-lib.h" that gives them the unit-tests
> -+ framework
> ++ framework, and
> +
> + - the source files that implement reftable in the "reftable/"
> + directory that include "reftable/system.h" for the reftable
> -+ internals
> ++ internals,
> +
> + are allowed to assume that they do not have to include
> -+ "git-compat-util.h" themselves, as it is included as the first
> ++ <git-compat-util.h> themselves, as it is included as the first
> + '#include' in these header files. These headers must be the first
> + header file to be "#include"d in them, though.
>
>
> Documentation/CodingGuidelines | 41 +++++++++++++++++++++++++++++-----
> 1 file changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index 578587a471..806979f75b 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -446,12 +446,41 @@ For C programs:
> detail.
>
> - The first #include in C files, except in platform specific compat/
> - 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 "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.
> + implementations and sha1dc/, must be <git-compat-util.h>. This
> + header file insulates other header files and source files from
> + platform differences, like which system header files must be
> + included in what order, and what C preprocessor feature macros must
> + be defined to trigger certain features we expect out of the system.
> + A collorary to this is that C files should not directly include
> + system header files themselves.
> +
> + There are some exceptions, because certain group of files that
> + implement an API all have to include the same header file that
> + defines the API and it is convenient to include <git-compat-util.h>
> + there. Namely:
> +
> + - the implementation of the built-in commands in the "builtin/"
> + directory that include "builtin.h" for the cmd_foo() prototype
> + definition,
> +
> + - the test helper programs in the "t/helper/" directory that include
> + "t/helper/test-tool.h" for the cmd__foo() prototype definition,
> +
> + - the xdiff implementation in the "xdiff/" directory that includes
> + "xdiff/xinclude.h" for the xdiff machinery internals,
> +
> + - the unit test programs in "t/unit-tests/" directory that include
> + "t/unit-tests/test-lib.h" that gives them the unit-tests
> + framework, and
> +
> + - the source files that implement reftable in the "reftable/"
> + directory that include "reftable/system.h" for the reftable
> + internals,
> +
> + are allowed to assume that they do not have to include
> + <git-compat-util.h> themselves, as it is included as the first
> + '#include' in these header files. These headers must be the first
> + header file to be "#include"d in them, though.
>
> - A C file must directly include the header files that declare the
> functions and the types it uses, except for the functions and types
> --
> 2.44.0
>
Looks good
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-26 23:28 ` [PATCH v3] " Junio C Hamano
2024-02-26 23:57 ` Kyle Lippincott
@ 2024-02-27 4:25 ` Elijah Newren
2024-02-27 5:35 ` Junio C Hamano
1 sibling, 1 reply; 8+ messages in thread
From: Elijah Newren @ 2024-02-27 4:25 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Kyle Lippincott, Calvin Wan, Jonathan Tan
On Mon, Feb 26, 2024 at 3:28 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> The reason why we require the <git-compat-util.h> file to be the
> first header file to be included is because it insulates other
> header files and source files from platform differences, like which
> system header files must be included in what order, and what C
> preprocessor feature macros must be defined to trigger certain
> features we want out of the system.
>
> We tried to clarify the rule in the coding guidelines document, but
> the wording was a bit fuzzy that can lead to misinterpretations like
> you can include <xdiff/xinclude.h> only to avoid having to include
> <git-compat-util.h> even if you have nothing to do with the xdiff
> implementation, for example. "You do not have to include more than
> one of these" was also misleading and would have been puzzling if
> you _needed_ to depend on more than one of these approved headers
> (answer: you are allowed to include them all if you need the
> declarations in them for reasons other than that you want to avoid
> including compat-util yourself).
>
> Instead of using the phrase "approved headers", enumerate them as
> exceptions, each labeled with its intended audiences, to avoid such
> misinterpretations. The structure also makes it easier to add new
> exceptions, so add the description of "t/unit-tests/test-lib.h"
> being an exception only for the unit tests implementation as an
> example.
Makes sense.
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> * Updated the leading phrase introducing the list of exceptions.
> I think this is now clear enough to be ready for 'next'?
>
> Range-diff:
> 1: 2e7082d2d2 ! 1: 470f33a078 doc: clarify the wording on <git-compat-util.h> requirement
> @@ Documentation/CodingGuidelines: For C programs:
> - "t/helper/test-tool.h", "xdiff/xinclude.h", or
> - "reftable/system.h".) You do not have to include more than one of
> - these.
> -+ implementations and sha1dc/, must be "git-compat-util.h". This
> ++ implementations and sha1dc/, must be <git-compat-util.h>. This
> + header file insulates other header files and source files from
> + platform differences, like which system header files must be
> + included in what order, and what C preprocessor feature macros must
> + be defined to trigger certain features we expect out of the system.
> ++ A collorary to this is that C files should not directly include
> ++ system header files themselves.
> +
> -+ In addition:
> ++ There are some exceptions, because certain group of files that
> ++ implement an API all have to include the same header file that
> ++ defines the API and it is convenient to include <git-compat-util.h>
> ++ there. Namely:
> +
> + - the implementation of the built-in commands in the "builtin/"
> + directory that include "builtin.h" for the cmd_foo() prototype
> -+ definition
> ++ definition,
> +
> + - the test helper programs in the "t/helper/" directory that include
> -+ "t/helper/test-tool.h" for the cmd__foo() prototype definition
> ++ "t/helper/test-tool.h" for the cmd__foo() prototype definition,
> +
> + - the xdiff implementation in the "xdiff/" directory that includes
> -+ "xdiff/xinclude.h" for the xdiff machinery internals
> ++ "xdiff/xinclude.h" for the xdiff machinery internals,
> +
> + - the unit test programs in "t/unit-tests/" directory that include
> + "t/unit-tests/test-lib.h" that gives them the unit-tests
> -+ framework
> ++ framework, and
> +
> + - the source files that implement reftable in the "reftable/"
> + directory that include "reftable/system.h" for the reftable
> -+ internals
> ++ internals,
> +
> + are allowed to assume that they do not have to include
> -+ "git-compat-util.h" themselves, as it is included as the first
> ++ <git-compat-util.h> themselves, as it is included as the first
> + '#include' in these header files. These headers must be the first
> + header file to be "#include"d in them, though.
>
>
> Documentation/CodingGuidelines | 41 +++++++++++++++++++++++++++++-----
> 1 file changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index 578587a471..806979f75b 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -446,12 +446,41 @@ For C programs:
> detail.
>
> - The first #include in C files, except in platform specific compat/
> - 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 "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.
> + implementations and sha1dc/, must be <git-compat-util.h>. This
> + header file insulates other header files and source files from
> + platform differences, like which system header files must be
> + included in what order, and what C preprocessor feature macros must
> + be defined to trigger certain features we expect out of the system.
> + A collorary to this is that C files should not directly include
> + system header files themselves.
> +
> + There are some exceptions, because certain group of files that
> + implement an API all have to include the same header file that
> + defines the API and it is convenient to include <git-compat-util.h>
> + there. Namely:
> +
> + - the implementation of the built-in commands in the "builtin/"
> + directory that include "builtin.h" for the cmd_foo() prototype
> + definition,
> +
> + - the test helper programs in the "t/helper/" directory that include
> + "t/helper/test-tool.h" for the cmd__foo() prototype definition,
> +
> + - the xdiff implementation in the "xdiff/" directory that includes
> + "xdiff/xinclude.h" for the xdiff machinery internals,
> +
> + - the unit test programs in "t/unit-tests/" directory that include
> + "t/unit-tests/test-lib.h" that gives them the unit-tests
> + framework, and
> +
> + - the source files that implement reftable in the "reftable/"
> + directory that include "reftable/system.h" for the reftable
> + internals,
> +
> + are allowed to assume that they do not have to include
> + <git-compat-util.h> themselves, as it is included as the first
> + '#include' in these header files. These headers must be the first
> + header file to be "#include"d in them, though.
>
> - A C file must directly include the header files that declare the
> functions and the types it uses, except for the functions and types
> --
> 2.44.0
I like this latest version.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] doc: clarify the wording on <git-compat-util.h> requirement
2024-02-27 4:25 ` Elijah Newren
@ 2024-02-27 5:35 ` Junio C Hamano
0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2024-02-27 5:35 UTC (permalink / raw)
To: Elijah Newren; +Cc: git, Kyle Lippincott, Calvin Wan, Jonathan Tan
Elijah Newren <newren@gmail.com> writes:
> I like this latest version.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-02-27 5:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-24 20:22 [PATCH] doc: clarify the wording on <git-compat-util.h> requirement Junio C Hamano
2024-02-24 22:36 ` [PATCH v2] " Junio C Hamano
2024-02-26 23:28 ` [PATCH v3] " Junio C Hamano
2024-02-26 23:57 ` Kyle Lippincott
2024-02-27 4:25 ` Elijah Newren
2024-02-27 5:35 ` Junio C Hamano
2024-02-24 22:38 ` [PATCH] " Kyle Lippincott
2024-02-24 22:54 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).