<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/compat/poll/poll.c, branch main</title>
<subtitle>Fork of git SCM with my patches.</subtitle>
<id>http://git.kilabit.info/git/atom?h=main</id>
<link rel='self' href='http://git.kilabit.info/git/atom?h=main'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/'/>
<updated>2026-04-06T17:06:20Z</updated>
<entry>
<title>unify and bump _WIN32_WINNT definition to Windows 8.1</title>
<updated>2026-04-06T17:06:20Z</updated>
<author>
<name>Matthias Aßhauer</name>
<email>mha1993@live.de</email>
</author>
<published>2026-04-06T05:45:29Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=66dd13f3f72e8cad1327b6b134dec079936c4b07'/>
<id>urn:sha1:66dd13f3f72e8cad1327b6b134dec079936c4b07</id>
<content type='text'>
Git for Windows doesn't support anything prior to Windows 8.1 since 2.47.0
and Git followed along with commits like ce6ccba (mingw: drop Windows
7-specific work-around, 2025-08-04).

There is no need to pretend to the compiler that we still support Windows
Vista, just to lock us out of easy access to newer APIs. There is also no
need to have conflicting and unused definitions claiming we support some
versions of Windows XP or even Windows NT 4.0.

Bump all definitions of _WIN32_WINNT to a realistic value of Windows 8.1.
This will also simplify code for a followup commit that will improve cpu
core detection on multi-socket systems.

Signed-off-by: Matthias Aßhauer &lt;mha1993@live.de&gt;
Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>global: mark code units that generate warnings with `-Wsign-compare`</title>
<updated>2024-12-06T11:20:02Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-06T10:27:19Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=41f43b8243f42b9df2e98be8460646d4c0100ad3'/>
<id>urn:sha1:41f43b8243f42b9df2e98be8460646d4c0100ad3</id>
<content type='text'>
Mark code units that generate warnings with `-Wsign-compare`. This
allows for a structured approach to get rid of all such warnings over
time in a way that can be easily measured.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>mingw: workaround for hangs when sending STDIN</title>
<updated>2020-02-27T22:23:29Z</updated>
<author>
<name>Alexandr Miloslavskiy</name>
<email>alexandr.miloslavskiy@syntevo.com</email>
</author>
<published>2020-02-17T18:01:26Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=94f4d01932279c419844aa708bec31a26056bc6b'/>
<id>urn:sha1:94f4d01932279c419844aa708bec31a26056bc6b</id>
<content type='text'>
Explanation
-----------
The problem here is flawed `poll()` implementation. When it tries to
see if pipe can be written without blocking, it eventually calls
`NtQueryInformationFile()` and tests `WriteQuotaAvailable`. However,
the meaning of quota was misunderstood. The value of quota is reduced
when either some data was written to a pipe, *or* there is a pending
read on the pipe. Therefore, if there is a pending read of size &gt;= than
the pipe's buffer size, poll() will think that pipe is not writable and
will hang forever, usually that means deadlocking both pipe users.

I have studied the problem and found that Windows pipes track two values:
`QuotaUsed` and `BytesInQueue`. The code in `poll()` apparently wants to
know `BytesInQueue` instead of quota. Unfortunately, `BytesInQueue` can
only be requested from read end of the pipe, while `poll()` receives
write end.

The git's implementation of `poll()` was copied from gnulib, which also
contains a flawed implementation up to today.

I also had a look at implementation in cygwin, which is also broken in a
subtle way. It uses this code in `pipe_data_available()`:
	fpli.WriteQuotaAvailable = (fpli.OutboundQuota - fpli.ReadDataAvailable)
However, `ReadDataAvailable` always returns 0 for the write end of the pipe,
turning the code into an obfuscated version of returning pipe's total
buffer size, which I guess will in turn have `poll()` always say that pipe
is writable. The commit that introduced the code doesn't say anything about
this change, so it could be some debugging code that slipped in.

These are the typical sizes used in git:
0x2000 - default read size in `strbuf_read()`
0x1000 - default read size in CRT, used by `strbuf_getwholeline()`
0x2000 - pipe buffer size in compat\mingw.c

As a consequence, as soon as child process uses `strbuf_read()`,
`poll()` in parent process will hang forever, deadlocking both
processes.

This results in two observable behaviors:
1) If parent process begins sending STDIN quickly (and usually that's
   the case), then first `poll()` will succeed and first block will go
   through. MAX_IO_SIZE_DEFAULT is 8MB, so if STDIN exceeds 8MB, then
   it will deadlock.
2) If parent process waits a little bit for any reason (including OS
   scheduler) and child is first to issue `strbuf_read()`, then it will
   deadlock immediately even on small STDINs.

The problem is illustrated by `git stash push`, which will currently
read the entire patch into memory and then send it to `git apply` via
STDIN. If patch exceeds 8MB, git hangs on Windows.

Possible solutions
------------------
1) Somehow obtain `BytesInQueue` instead of `QuotaUsed`
   I did a pretty thorough search and didn't find any ways to obtain
   the value from write end of the pipe.
2) Also give read end of the pipe to `poll()`
   That can be done, but it will probably invite some dirty code,
   because `poll()`
   * can accept multiple pipes at once
   * can accept things that are not pipes
   * is expected to have a well known signature.
3) Make `poll()` always reply "writable" for write end of the pipe
   Afterall it seems that cygwin (accidentally?) does that for years.
   Also, it should be noted that `pump_io_round()` writes 8MB blocks,
   completely ignoring the fact that pipe's buffer size is only 8KB,
   which means that pipe gets clogged many times during that single
   write. This may invite a deadlock, if child's STDERR/STDOUT gets
   clogged while it's trying to deal with 8MB of STDIN. Such deadlocks
   could be defeated with writing less than pipe's buffer size per
   round, and always reading everything from STDOUT/STDERR before
   starting next round. Therefore, making `poll()` always reply
   "writable" shouldn't cause any new issues or block any future
   solutions.
4) Increase the size of the pipe's buffer
   The difference between `BytesInQueue` and `QuotaUsed` is the size
   of pending reads. Therefore, if buffer is bigger than size of reads,
   `poll()` won't hang so easily. However, I found that for example
   `strbuf_read()` will get more and more hungry as it reads large inputs,
   eventually surpassing any reasonable pipe buffer size.

Chosen solution
---------------
Make `poll()` always reply "writable" for write end of the pipe.
Hopefully one day someone will find a way to implement it properly.

Reproduction
------------
printf "%8388608s" X &gt;large_file.txt
git stash push --include-untracked -- large_file.txt

I have decided not to include this as test to avoid slowing down the
test suite. I don't expect the specific problem to come back, and
chances are that `git stash push` will be reworked to avoid sending the
entire patch via STDIN.

Signed-off-by: Alexandr Miloslavskiy &lt;alexandr.miloslavskiy@syntevo.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'js/mingw-use-utf8'</title>
<updated>2019-07-11T22:16:49Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-07-11T22:16:49Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=0a2ff7c6b5ec5e4301a9cfb3c0dd26590d70ad7a'/>
<id>urn:sha1:0a2ff7c6b5ec5e4301a9cfb3c0dd26590d70ad7a</id>
<content type='text'>
Windows update.

* js/mingw-use-utf8:
  mingw: fix possible buffer overrun when calling `GetUserNameW()`
  mingw: use Unicode functions explicitly
  mingw: get pw_name in UTF-8 format
</content>
</entry>
<entry>
<title>mingw: use Unicode functions explicitly</title>
<updated>2019-06-27T19:56:15Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-06-27T09:37:19Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=94238859b9809afc806919cb7022a45cdc8e6748'/>
<id>urn:sha1:94238859b9809afc806919cb7022a45cdc8e6748</id>
<content type='text'>
Many Win32 API functions actually exist in two variants: one with
the `A` suffix that takes ANSI parameters (`char *` or `const char *`)
and one with the `W` suffix that takes Unicode parameters (`wchar_t *`
or `const wchar_t *`).

The ANSI variant assumes that the strings are encoded according to
whatever is the current locale. This is not what Git wants to use on
Windows: we assume that `char *` variables point to strings encoded in
UTF-8.

There is a pseudo UTF-8 locale on Windows, but it does not work
as one might expect. In addition, if we overrode the user's locale, that
would modify the behavior of programs spawned by Git (such as editors,
difftools, etc), therefore we cannot use that pseudo locale.

Further, it is actually highly encouraged to use the Unicode versions
instead of the ANSI versions, so let's do precisely that.

Note: when calling the Win32 API functions _without_ any suffix, it
depends whether the `UNICODE` constant is defined before the relevant
headers are #include'd. Without that constant, the ANSI variants are
used. Let's be explicit and avoid that ambiguity.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>poll (mingw): allow compiling with GCC 8 and DEVELOPER=1</title>
<updated>2019-06-13T16:34:16Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-06-13T11:49:44Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=8d4679fe0995affd40301169fbfe6d679561bc64'/>
<id>urn:sha1:8d4679fe0995affd40301169fbfe6d679561bc64</id>
<content type='text'>
The return type of the `GetProcAddress()` function is `FARPROC` which
evaluates to `long long int (*)()`, i.e. it cannot be cast to the
correct function signature by GCC 8.

To work around that, we first cast to `void *` and go on with our merry
lives.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>poll: use GetTickCount64() to avoid wrap-around issues</title>
<updated>2018-11-05T04:02:42Z</updated>
<author>
<name>Steve Hoelzer</name>
<email>shoelzer@gmail.com</email>
</author>
<published>2018-10-31T21:11:36Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=e8dfcace316aaaca226c2ae2d268bcc4d3131b38'/>
<id>urn:sha1:e8dfcace316aaaca226c2ae2d268bcc4d3131b38</id>
<content type='text'>
The value of timeout starts as an int value, and for this reason it
cannot overflow unsigned long long aka ULONGLONG. The unsigned version
of this initial value is available in orig_timeout. The difference
(orig_timeout - elapsed) cannot wrap around because it is protected by
a conditional (as can be seen in the patch text). Hence, the ULONGLONG
difference can only have values that are smaller than the initial
timeout value and truncation to int cannot overflow.

Signed-off-by: Steve Hoelzer &lt;shoelzer@gmail.com&gt;
[j6t: improved both implementation and log message]
Signed-off-by: Johannes Sixt &lt;j6t@kdbg.org&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>compat/poll: prepare for targeting Windows Vista</title>
<updated>2018-10-04T12:39:56Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2018-10-03T19:43:41Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=d7e357fb9c702979d5b3a7d9faa869844a12e4d9'/>
<id>urn:sha1:d7e357fb9c702979d5b3a7d9faa869844a12e4d9</id>
<content type='text'>
Windows Vista (and later) actually have a working poll(), but we still
cannot use it because it only works on sockets.

So let's detect when we are targeting Windows Vista and undefine those
constants, and define `pollfd` so that we can declare our own pollfd
struct.

We also need to make sure that we override those constants *after*
`winsock2.h` has been `#include`d (otherwise we would not really
override those constants).

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Replace Free Software Foundation address in license notices</title>
<updated>2017-11-09T04:21:21Z</updated>
<author>
<name>Todd Zullinger</name>
<email>tmz@pobox.com</email>
</author>
<published>2017-11-07T05:39:33Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=484257925fada31045aefec7484fd663f7c40c2f'/>
<id>urn:sha1:484257925fada31045aefec7484fd663f7c40c2f</id>
<content type='text'>
The mailing address for the FSF has changed over the years.  Rather than
updating the address across all files, refer readers to gnu.org, as the
GNU GPL documentation now suggests for license notices.  The mailing
address is retained in the full license files (COPYING and LGPL-2.1).

The old address is still present in t/diff-lib/COPYING.  This is
intentional, as the file is used in tests and the contents are not
expected to change.

Signed-off-by: Todd Zullinger &lt;tmz@pobox.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>poll.c: always set revents, even if to zero</title>
<updated>2017-09-29T09:33:22Z</updated>
<author>
<name>Randall S. Becker</name>
<email>randall.becker@nexbridge.ca</email>
</author>
<published>2017-09-28T22:47:17Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=61b2a1acaae22b0b4cd45218525d9890e03b377c'/>
<id>urn:sha1:61b2a1acaae22b0b4cd45218525d9890e03b377c</id>
<content type='text'>
Match what is done to pfd[i].revents when compute_revents() returns
0 to the upstream gnulib's commit d42461c3 ("poll: fixes for large
fds", 2015-02-20).  The revents field is set to 0, without
incrementing the value rc to be returned from the function.  The
original code left the field to whatever random value the field was
initialized to.

This fixes occasional hangs in git-upload-pack on HPE NonStop.

Signed-off-by: Randall S. Becker &lt;randall.becker@nexbridge.ca&gt;
Reviewed-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
