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

Re: [PATCH] bisect.c: remove unused includes

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 31, 2022, 21:29 UTC
Message-ID
<xmqqlewpzu7t.fsf@gitster.g>
In-Reply-To
<20220331194436.58005-1-garrit@slashdev.space>
Garrit Franke <garrit@slashdev.space> writes:
Show 13 quoted lines
> Clean up includes no longer needed by bisect.c.
>
> Signed-off-by: Garrit Franke <garrit@slashdev.space>
> ---
>  bisect.c | 9 ---------
>  1 file changed, 9 deletions(-)
>
> diff --git a/bisect.c b/bisect.c
> index 9e6a2b7f20..e07e2d215d 100644
> --- a/bisect.c
> +++ b/bisect.c
> @@ -1,21 +1,12 @@
> -#include "cache.h"
cf. Documentation/CodingGuidelines

The first #include must be <git-compat-util.h>, or <cache.h> or <builtin.h>, which are well known to include <git-compat-util.h> first.

Including <git-compat-util.h> indirectly by <config.h> -> <hashmap.h> -> <hash.h> -> <git-compat-util.h> does not count.

>  #include "config.h"
> -#include "commit.h"

Other headers may indirectly include <commit.h> as their implementation detail, but what matters is that *we* in this source file use what <commit.h> gives us ourselves, like the concrete shape of "struct commit_list". This change is not wanted.

I'll stop here. There may be truly leftover "unused" includes among those removed by the remainder of this patch, but I suspect that some are like <commit.h> above, i.e. we directly use it, and because we do not want to be broken by some header file's implementation detail changing, we MUST include it ourselves.

I think this should give us a useful guideline to sift through the rest, and an updated patch to remove truly unused ones are very much welcome. We may actually find some we are not directly including ourselves but we should (e.g. I do not see <string-list.h> included by us, but we clearly use structures and functions declared there, and probably is depending, wrongly, on some header file we include happens to indirectly include it).

Thanks.
Show 18 quoted lines
> -#include "diff.h"
> -#include "revision.h"
>  #include "refs.h"
>  #include "list-objects.h"
>  #include "quote.h"
> -#include "hash-lookup.h"
>  #include "run-command.h"
>  #include "log-tree.h"
>  #include "bisect.h"
> -#include "oid-array.h"
> -#include "strvec.h"
> -#include "commit-slab.h"
>  #include "commit-reach.h"
>  #include "object-store.h"
> -#include "dir.h"
>  
>  static struct oid_array good_revs;
>  static struct oid_array skipped_revs;
Previous: Garrit FrankeNext: Ævar Arnfjörð Bjarmason
Message 2 of 12 in “bisect.c: remove unused includes”
  1. bisect.c: remove unused includesGarrit Franke, Mar 31, 2022
  2. Junio C HamanoMar 31, 2022
  3. using iwyu (include-what-you-use) to analyze includes (was: [PATCH] bisect.c: remove unused includes)Ævar Arnfjörð Bjarmason, Apr 1, 2022
  4. 0/4 various: use iwyu (include-what-you-use) to analyze includesGarrit Franke, Apr 5, 2022
  5. Ævar Arnfjörð BjarmasonApr 6, 2022
  6. 4/4 apply.c: remove unnecessary includeGarrit Franke, Apr 5, 2022
  7. 3/4 serve.c: remove unnecessary includeGarrit Franke, Apr 5, 2022
  8. 1/4 contrib: add iwyu scriptGarrit Franke, Apr 5, 2022
  9. Ævar Arnfjörð BjarmasonApr 6, 2022
  10. 2/4 bisect.c: remove unnecessary includeGarrit Franke, Apr 5, 2022
  11. Ævar Arnfjörð BjarmasonApr 6, 2022
  12. Junio C HamanoApr 6, 2022

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.