Re: [PATCH 02/16] treewide: remove unnecessary git-compat-util.h includes in headers
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 23, 2023, 19:35 UTC
- Message-ID
- <xmqq1qmg899v.fsf@gitster.g>
- In-Reply-To
- <adafa655432dd13d1c727522377ac9a4b515b76a.1677139521.git.gitgitgadget@gmail.com>
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 8 quoted lines
> From: Elijah Newren <newren@gmail.com> > > Since git-compat-util.h needs to be included first in C files, having it > appear in header files is unnecessary. More importantly, having it > included in header files seems to lead to folks leaving it out of C > files, which makes it harder to verify that the rule is being followed. > Remove it from header files, other than the ones that have been approved > as alternate first includes.
Hmph, doesn't this cut both ways?
I like the idea that the removal of compat-util from other header files may increase the likelihood that a C file that includes such header files without including compat-util fail to compile, because it would fail to find what is defined or declared in compat-util.
But from "include what you use" point of view, shouldn't a header that defines or declares its own stuff using what is defined or declared in compat-util be including compat-util itself?
Or do I misunderstand what "make hdr-check" is trying to achieve?
Granted that the check does not fail with this patch in place, but I suspect that it is by accident (i.e. there happens to be nobody who depends on what is defined/declared in compat-util for their own definition or declaration). Also I am not sure how to interpret the fact that "make hdr-check" succeeds with this patch. Does it mean C files that include these header files while forgetting to include compat-util may not be caught by the compiler after all?
So, I dunno.