# [PATCH 0/2] Organize mingw includes

9 messages from 2025-10-09 to 2025-10-13. Participants: Johannes Schindelin via GitGitGadget, Patrick Steinhardt, Johannes Schindelin, Junio C Hamano, Matthias Aßhauer, Johannes Sixt.
Thread: https://gitlist.dev/t/64281

## Johannes Schindelin via GitGitGadget, 2025-10-09 07:45

Subject: [PATCH 0/2] Organize mingw includes
Message-ID: <pull.1985.git.1759995961.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.1985.git.1759995961.gitgitgadget%40gmail.com

```
Following in the footsteps of the many, many recent #include refactorings,
this patch series orders the #include statements in compat/mingw.c.

Johannes Schindelin (2):
  mingw: avoid relative `#include`s
  mingw: order `#include`s alphabetically

 compat/mingw.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)


base-commit: 79cf913ea9321f774da29b2330b5781d5ff420ef
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1985%2Fdscho%2Forganize-mingw-includes-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1985/dscho/organize-mingw-includes-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1985
-- 
gitgitgadget

```

## Johannes Schindelin via GitGitGadget, 2025-10-09 07:46

Subject: [PATCH 1/2] mingw: avoid relative `#include`s
Message-ID: <484ef8b825e5d1d68a61f0f8cc2520457e8f4f3a.1759995961.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/484ef8b825e5d1d68a61f0f8cc2520457e8f4f3a.1759995961.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.1985.git.1759995961.gitgitgadget@gmail.com>

```
From: Johannes Schindelin <johannes.schindelin@gmx.de>

We want to make them relative to the top-level directory.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/mingw.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 8538e3d172..da99473f56 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1,22 +1,22 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
-#include "../git-compat-util.h"
+#include "git-compat-util.h"
 #include "win32.h"
 #include <aclapi.h>
 #include <sddl.h>
 #include <conio.h>
 #include <wchar.h>
-#include "../strbuf.h"
-#include "../run-command.h"
-#include "../abspath.h"
-#include "../alloc.h"
+#include "strbuf.h"
+#include "run-command.h"
+#include "abspath.h"
+#include "alloc.h"
 #include "win32/lazyload.h"
-#include "../config.h"
-#include "../environment.h"
-#include "../trace2.h"
-#include "../symlinks.h"
-#include "../wrapper.h"
+#include "config.h"
+#include "environment.h"
+#include "trace2.h"
+#include "symlinks.h"
+#include "wrapper.h"
 #include "dir.h"
 #include "gettext.h"
 #define SECURITY_WIN32
-- 
gitgitgadget


```

## Johannes Schindelin via GitGitGadget, 2025-10-09 07:46

Subject: [PATCH 2/2] mingw: order `#include`s alphabetically
Message-ID: <5303aa57c4e5aa8e88b4a3d553ff3a69dbe54871.1759995961.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/5303aa57c4e5aa8e88b4a3d553ff3a69dbe54871.1759995961.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.1985.git.1759995961.gitgitgadget@gmail.com>

```
From: Johannes Schindelin <johannes.schindelin@gmx.de>

It allows for more consistent patches that way.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/mingw.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index da99473f56..736a07a028 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2,25 +2,25 @@
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
-#include "win32.h"
-#include <aclapi.h>
-#include <sddl.h>
-#include <conio.h>
-#include <wchar.h>
-#include "strbuf.h"
-#include "run-command.h"
 #include "abspath.h"
 #include "alloc.h"
-#include "win32/lazyload.h"
 #include "config.h"
+#include "dir.h"
 #include "environment.h"
-#include "trace2.h"
+#include "gettext.h"
+#include "run-command.h"
+#include "strbuf.h"
 #include "symlinks.h"
+#include "trace2.h"
+#include "win32.h"
+#include "win32/lazyload.h"
 #include "wrapper.h"
-#include "dir.h"
-#include "gettext.h"
+#include <aclapi.h>
+#include <conio.h>
+#include <sddl.h>
 #define SECURITY_WIN32
 #include <sspi.h>
+#include <wchar.h>
 #include <winternl.h>
 
 #define STATUS_DELETE_PENDING ((NTSTATUS) 0xC0000056)
-- 
gitgitgadget

```

## Patrick Steinhardt, 2025-10-10 09:53

Subject: Re: [PATCH 0/2] Organize mingw includes
Message-ID: <aOjXjEJePkpCDoI3@pks.im>
URL: https://gitlist.dev/e/aOjXjEJePkpCDoI3%40pks.im
In-Reply-To: <pull.1985.git.1759995961.gitgitgadget@gmail.com>

```
On Thu, Oct 09, 2025 at 07:45:59AM +0000, Johannes Schindelin via GitGitGadget wrote:
> Following in the footsteps of the many, many recent #include refactorings,
> this patch series orders the #include statements in compat/mingw.c.

Both of these patches look good to me and I like the improved
consistency that they bring. I may also do the same for our code in
"refs/", where some of the files use relative includes, as well. Might
be worth to document this somewhere if it isn't already, but that
doesn't have to be part of your patch series here.

Sorting them also makes sense. It's another thing where I wish that we
had a tool to enforce this. clang-format supports this in theory, but
it's disabled right now. And I'm not even sure whether it can be told to
include e.g. "git-compat-util.h" first.

Thanks!

Patrick

```

## Johannes Schindelin, 2025-10-10 13:55

Subject: Re: [PATCH 0/2] Organize mingw includes
Message-ID: <c4a03e23-1c14-05b7-25ad-a3d6998df876@gmx.de>
URL: https://gitlist.dev/e/c4a03e23-1c14-05b7-25ad-a3d6998df876%40gmx.de
In-Reply-To: <aOjXjEJePkpCDoI3@pks.im>

```
Hi Patrick,

On Fri, 10 Oct 2025, Patrick Steinhardt wrote:

> On Thu, Oct 09, 2025 at 07:45:59AM +0000, Johannes Schindelin via GitGitGadget wrote:
> > Following in the footsteps of the many, many recent #include refactorings,
> > this patch series orders the #include statements in compat/mingw.c.
> 
> Both of these patches look good to me and I like the improved
> consistency that they bring. I may also do the same for our code in
> "refs/", where some of the files use relative includes, as well. Might
> be worth to document this somewhere if it isn't already, but that
> doesn't have to be part of your patch series here.

There's already such a lot of documentation that I fear it is intimidating
to any new contributor (and if I was one, I'd be tempted to read it
exclusively via AI summaries). I don't want to add to that amount.

> Sorting them also makes sense. It's another thing where I wish that we
> had a tool to enforce this. clang-format supports this in theory, but
> it's disabled right now. And I'm not even sure whether it can be told to
> include e.g. "git-compat-util.h" first.

In theory, I am totally with you: Sorting `#include`s is a job best left
to tools. But then, I say the same about formatting, and I see a lot of
appetite on this list for preventing that to become a tool-driven job, and
instead requiring developer time to be spent on it. Therefore, I don't
want to spend any effort trying to get this automated when I see small
chances of success in the endeavor of freeing up cognitive cycles for
tasks I find more intellectually rewarding than figuring out where a space
or a line break goes.

Ciao,
Johannes

```

## Junio C Hamano, 2025-10-10 16:18

Subject: Re: [PATCH 0/2] Organize mingw includes
Message-ID: <xmqqfrbqafxj.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqfrbqafxj.fsf%40gitster.g
In-Reply-To: <c4a03e23-1c14-05b7-25ad-a3d6998df876@gmx.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> Sorting them also makes sense. It's another thing where I wish that we
>> had a tool to enforce this. clang-format supports this in theory, but
>> it's disabled right now. And I'm not even sure whether it can be told to
>> include e.g. "git-compat-util.h" first.
>
> In theory, I am totally with you: Sorting `#include`s is a job best left
> to tools. But then, I say the same about formatting,

I am afraid that it is apples-to-oranges comparison.  Nobody has to
read the #include directives; they may have to see if a header they
care about (because they are planning to add a call to a function
that hasn't been used in the particular C source file, perhaps) is
already included, and sorted list of includes is a good tool to help
them.  IOW, they do not read them, they scan in them.  But the code,
the result of formatting, must be readable by people.

```

## Matthias Aßhauer, 2025-10-11 09:03

Subject: Re: [PATCH 1/2] mingw: avoid relative `#include`s
Message-ID: <DB9P250MB06929F022ADC9A0544947BDAA5ECA@DB9P250MB0692.EURP250.PROD.OUTLOOK.COM>
URL: https://gitlist.dev/e/DB9P250MB06929F022ADC9A0544947BDAA5ECA%40DB9P250MB0692.EURP250.PROD.OUTLOOK.COM
In-Reply-To: <484ef8b825e5d1d68a61f0f8cc2520457e8f4f3a.1759995961.git.gitgitgadget@gmail.com>

```
On Thu, 9 Oct 2025, Johannes Schindelin via GitGitGadget wrote:

> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> We want to make them relative to the top-level directory.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> compat/mingw.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 8538e3d172..da99473f56 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1,22 +1,22 @@
> #define USE_THE_REPOSITORY_VARIABLE
> #define DISABLE_SIGN_COMPARE_WARNINGS
>
> -#include "../git-compat-util.h"
> +#include "git-compat-util.h"
> #include "win32.h"

Isn't this include also relative to compat/ and should become #include 
"compat/win32.h"?

> #include <aclapi.h>
> #include <sddl.h>
> #include <conio.h>
> #include <wchar.h>
> -#include "../strbuf.h"
> -#include "../run-command.h"
> -#include "../abspath.h"
> -#include "../alloc.h"
> +#include "strbuf.h"
> +#include "run-command.h"
> +#include "abspath.h"
> +#include "alloc.h"
> #include "win32/lazyload.h"

Same situation here.

best regards

Matthias

```

## Johannes Sixt, 2025-10-12 11:45

Subject: Re: [PATCH 1/2] mingw: avoid relative `#include`s
Message-ID: <e593886e-eeb4-440f-a317-a2959577e1e3@kdbg.org>
URL: https://gitlist.dev/e/e593886e-eeb4-440f-a317-a2959577e1e3%40kdbg.org
In-Reply-To: <484ef8b825e5d1d68a61f0f8cc2520457e8f4f3a.1759995961.git.gitgitgadget@gmail.com>

```
Am 09.10.25 um 09:46 schrieb Johannes Schindelin via GitGitGadget:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> We want to make them relative to the top-level directory.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  compat/mingw.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 8538e3d172..da99473f56 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1,22 +1,22 @@
>  #define USE_THE_REPOSITORY_VARIABLE
>  #define DISABLE_SIGN_COMPARE_WARNINGS
>  
> -#include "../git-compat-util.h"
> +#include "git-compat-util.h"
>  #include "win32.h"
>  #include <aclapi.h>
>  #include <sddl.h>
>  #include <conio.h>
>  #include <wchar.h>
> -#include "../strbuf.h"
> -#include "../run-command.h"
> -#include "../abspath.h"
> -#include "../alloc.h"
> +#include "strbuf.h"
> +#include "run-command.h"
> +#include "abspath.h"
> +#include "alloc.h"
>  #include "win32/lazyload.h"
> -#include "../config.h"
> -#include "../environment.h"
> -#include "../trace2.h"
> -#include "../symlinks.h"
> -#include "../wrapper.h"
> +#include "config.h"
> +#include "environment.h"
> +#include "trace2.h"
> +#include "symlinks.h"
> +#include "wrapper.h"
>  #include "dir.h"
>  #include "gettext.h"
>  #define SECURITY_WIN32

Why is this needed?

With #include "foo" it is quite clear that the file is first looked up
from the directory of the file being processed. The changed code
requires that the top-level directory is among the -I directives of the
command lines. Then it would be much more logical to use #include <foo>
instead. But that I wouldn't regard as desirable, either, because the
included file isn't from a subordinate module or library.

So, IMO, the status quo is perfect and does not need this change.

-- Hannes


```

## Junio C Hamano, 2025-10-13 16:29

Subject: Re: [PATCH 1/2] mingw: avoid relative `#include`s
Message-ID: <xmqqa51u3guw.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqa51u3guw.fsf%40gitster.g
In-Reply-To: <e593886e-eeb4-440f-a317-a2959577e1e3@kdbg.org>

```
Johannes Sixt <j6t@kdbg.org> writes:

> Why is this needed?

;-)

As pointed out by Matthias, the changes in the posted patch are not
complete/comprehensive.

> With #include "foo" it is quite clear that the file is first looked up
> from the directory of the file being processed. The changed code
> requires that the top-level directory is among the -I directives of the
> command lines. Then it would be much more logical to use #include <foo>
> instead.

I actually prefer that, but that is a taste thing I do not want to
impose on this project.

> So, IMO, the status quo is perfect and does not need this change.

I tend to agree, but it would be a waste of time to further discuss
on this.  As long as it does not break compilation, I'll just let
the patch graduate.

My preference is to 

 * always name custom headers using the path from the top-level (we
   use -I in BASIC_CFLAGS exactly for this purpose), 
   e.g.

	#include "compat/win32.h" (good)
	#include "win32.h" (not good)

 * compat header that aims to replace system supplied headers like
   <regex.h> should use -I appropriately and appear as if they are
   from the system, e.g.

	#include <regex.h> (good)
	#include "compat/regex/regex.h" (not good)

If somebody truly wants to improve things once the dust settles from
these patches, I would appreciate they keep the above in mind.

THanks.

```
