Re: [PATCH][Outreachy] remove all the inclusions of git-compat-util.h in header files
The mistake -- if any! -- is mine: I suggested to Outreachy students to look for the #leftoverbits needle in our mail archive haystack, and to pick something to get a feel for contributing to Git.
Personally, I find the "whoever is picking it up should do the thinking" much too harsh for a first-time contributor who specifically came through the Outreachy program, i.e. expected to have a gentle introduction into the project, and into the ways we work.
Granted, that introduction should have been performed by the potential mentors (i.e. Chris & I, but I was out sick), but let's face it: we are an open source project, so every single one of us should feel the call to be a mentor, and we should certainly try to make every new contributor as welcome as we would like to be invited into a new project.
In this context, I would think that the "do the thinking" part is particularly hard because our rules are implicit, and inconsistent: when do we include header files, when do we skip the include?
If in doubt, follow the age-old wisdom "when in Rome, do as the Romans do", i.e. ignore the explicitly written-down rules, and instead imitate what active contributors are doing.
Unfortunately, I have no easy way to suggest for mining the mailing list for sentiments about including header files. And in any case, it would probably boil down on personal taste, which -- let's face it -- is rather diverse in our community... :-)
So in this case, what I would suggest is to look instead for the commit history, where header files were added or modified. The Git command for that is:
git log --no-merges -p \*.h
Apart from the rather wonderful examples you see there for commit messages (I am a big fan of commit messages that are clear and descriptive, i.e. start by detailing the why rather than the how, with notes thrown in about design decisions that are not obvious from the patch), this command will lead us pretty soon to this commit, especially when looking for the search term #include:
https://github.com/git/git/commit/69d846f05381
In other words, we explicitly introduced an `#include "git-compat-util.h"` in a header there.
The commit message also offers a pretty compelling rationale: it was the most efficient way to have that header included *first thing* in all test helpers.
Following that rationale, let's have a look at the patch we are improving here (because that's what code review really should all be about: improving the code, putting together all of our expertise to get the best patch we can in a reasonable amount of time):
The first thing we can already say is that the change to t/helper/test-tool.h would revert the commit referenced above, so I think we should drop that change.
Next, I want to have a look at advice.h:
git grep -O 'advice\.h'
(the backslash is necessary because this is a regular expression, and the period character has the special meaning "any character" there, unless escaped by a backslash)
What we can see is that indeed, every file that includes this header already includes cache.h first. We can even see that cache.h *itself* includes advice.h, meaning that we could add another patch that drops the advice.h include from, say, commit.c.
At this point, this seems to become a rabbit hole: which header files are already included in cache.h that are *also* included (unnecessarily) in .c files that *already* included cache.h?
Ananya, it is now up to you how far you want to go down that rabbit hole ;-)
If I had the time, *I* would now be tempted to try my hand at writing a script that analyzes our source code to ensure that:
- "cache.h" or "git-compat-util.h" is the first header included (as per
that commit message of the commit mentioned above)
- every header that is already included in cache.h is not included by a .c
file that already included cache.h
It is the kind of side-track I could lose days over, but I have to admit that the benefit would probably not merit the effort ;-)
In any case, I am delighted by your first patch: you took the first hurdle :-)
Ciao, Johannes
P.S.: Please record your contribution on the Outreachy site, unless you already did...