git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/5] Header includes cleanup

From
Christian Couder <chriscool@tuxfamily.org>
Date
Apr 2, 2009, 03:57 UTC
Message-ID
<200904020557.25058.chriscool@tuxfamily.org>
In-Reply-To
<7vk56565m1.fsf@gitster.siamese.dyndns.org>
Le mardi 31 mars 2009, Junio C Hamano a écrit :
Show 30 quoted lines
> Christian Couder <chriscool@tuxfamily.org> writes:
> > I think it's a good thing that you started working on it even if in the
> > end we decide that we want these cleanup to be done otherwise. At least
> > we will hopefully have clarified our include header policy.
>
> Before seeing a lot of patches to change #include all over the place, I'd
> like to see a simple guiding principle described, not just a subjective
> "I think this makes things better" but with "... because of X and Y and
> Z".
>
> The document Documentation/CodingGuidelines describes the only policy
> that exists currently: git-compat-util.h must be the first thing the
> compiler sees.  The language should probably be stronger than what
> appears there:
>
>  - The first #include in C files, except in platform specific
>    compat/ implementations, should be git-compat-util.h or another
>    well-known header file that includes it at the beginning, namely
>    cache.h or builtin.h.
>
> Even though http.h may include "cache.h" at the very beginning, I'd
> rather not to see http-walker.c lose inclusion of "cache.h".  It will
> force us to remember that http.h is Ok to include as the first file, and
> that won't scale.
>
> The reason git-compat-util.h must be the first is because inclusion of
> all the system header files is supposed to happen there, and there are
> some platforms that have broken system header dependencies we do not want
> application writers to care about, and the compat-util header knows about
> them.
Ok, so I suggest the following simple guiding principles:
- git-compat-util.h or cache.h or builtin.h should always be the first 
#include in C files,
- header files should include other incude files if and only if the other 
includes are needed to compile them,
- a header file should be included in a C file only if it is needed to 
compile the C file (it is not ok to include it only because it includes 
many other headers that are needed)
- other than the above rules, it is ok to reduce the number of includes as 
much as possible
What do you think?

By the way, Nathaniel, you should try to give more meaningful titles to the individual patches in your patch series and perhaps make them smaller so that they are easier to review and have less conflicts with other patches.

For example your patch "[PATCH 1/5] Header includes cleanup" could be splitted and the resulting patches could be renamed like this

"delete includes of 'git-compat-util.h' where 'builtin.h' is included" "delete includes of 'cache.h' where 'builtin.h' is included" "delete includes of 'strbuf.h' where 'builtin.h' is included" "delete includes of 'commit.h' where 'builtin.h' is included"

Or perhaps Junio would prefer that you work on a C file by C file basis? Like for example:

"delete useless includes in 'builtin-diff-files.c'" "delete useless includes in 'builtin-diff-index.c'" ...

Thanks, Christian.

Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 17 in “Header includes cleanup”
  1. 0/5 Header includes cleanupNathaniel P Dawson, Mar 30, 2009
  2. 1/5 Header includes cleanupNathaniel P Dawson, Mar 30, 2009
  3. 2/5 Header includes cleanupNathaniel P Dawson, Mar 30, 2009
  4. 3/5 Header includes cleanupNathaniel P Dawson, Mar 30, 2009
  5. 4/5 Header includes cleanupNathaniel P Dawson, Mar 30, 2009
  6. 5/5 Header includes cleanupNathaniel P Dawson, Mar 30, 2009
  7. Johannes SixtMar 30, 2009
  8. Nathaniel P DawsonMar 30, 2009
  9. Christian CouderMar 31, 2009
  10. Junio C HamanoMar 31, 2009
  11. Christian CouderApr 2, 2009
  12. Junio C HamanoApr 2, 2009
  13. Jeff KingApr 2, 2009
  14. Christian CouderApr 3, 2009
  15. Jeff KingApr 3, 2009
  16. Christian CouderApr 3, 2009
  17. Christian CouderMar 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.