Subject: [PATCH v3 0/1] Fix t5516 flakiness in Visual Studio builds

From: "Johannes Schindelin via GitGitGadget" <[email-masked]>
Date: Tue, 29 Oct 2019 20:01:19 +0000

Among the flaky tests, it seems that the Azure Pipeline suffers relatively
frequently from t5516 failing with the Visual Studio builds. Essentially, we
grep for an error message, but that error message is produced twice, once by
a fetch and once by the upload-pack spawned from it, and those error
messages are usually interleaved because of MSVC runtime fprintf() 
idiosyncracies.

As a consequence, I have to re-run about half a dozen failed builds a day,
which I would like to avoid. My plan is therefore to merge this patch into
Git for Windows v2.24.0-rc2.

The commit message of this patch is based, in part, on 
https://github.com/gitgitgadget/git/pull/407. 

This fixes https://github.com/gitgitgadget/git/issues/240.

Changes since v2:

 * Using write_in_full() instead of xwrite() again (to make sure that the
   entire message is printed).
 * When vsnprintf() fails, now we at least print the prefix.
 * The code to check whether prefix was too long no longer tests an
   inequality between pointers, but between sizes.

Changes since v1:

 * Changed the oneline to be more accurate (thanks Junio).
 * Improved the commit message (e.g. talking about the xwrite() function
   this patch uses, rather than the write_in_full() function used by an
   earlier iteration, thanks Gábor).
 * Revamped the actual code to account for insanely long prefixes (thanks
   for the advice, Junio).

Johannes Schindelin (1):
  vreportf(): avoid relying on stdio buffering

 usage.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

base-commit: 566a1439f6f56c2171b8853ddbca0ad3f5098770
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-428%2Fdscho%2Ffix-t5516-flakiness-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-428/dscho/fix-t5516-flakiness-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/428

Range-diff vs v2:

 1:  e426627e14 ! 1:  fce0894ee4 vreportf(): avoid relying on stdio buffering
     @@ -16,7 +16,7 @@
          Let's avoid this predicament altogether by rendering the entire message,
          including the prefix and the trailing newline, into the buffer we
          already have (and which is still fixed size) and then write it out via
     -    `xwrite()`.
     +    `write_in_full()`.
      
          We still clip the message to at most 4095 characters.
      
     @@ -46,6 +46,7 @@
          Git Bash on Windows: in this case, `stderr` is not actually truly
          unbuffered, and needs the extra help.
      
     +    Helped-by: Jeff King <[email-masked]>
          Helped-by: Alexandr Miloslavskiy <[email-masked]>
          Helped-by: SZEDER Gábor <[email-masked]>
          Helped-by: Junio C Hamano <[email-masked]>
     @@ -64,9 +65,9 @@
       
      -	vsnprintf(msg, sizeof(msg), err, params);
      -	for (p = msg; *p; p++) {
     -+	p = msg + off < pend ? msg + off : pend - 1;
     ++	p = off < pend - msg ? msg + off : pend - 1;
      +	if (vsnprintf(p, pend - p, err, params) < 0)
     -+		return; /* vsnprintf() failed, there is nothing we can do */
     ++		*p = '\0'; /* vsnprintf() failed, clip at prefix */
      +
      +	for (; p != pend - 1 && *p; p++) {
       		if (iscntrl(*p) && *p != '\t' && *p != '\n')
     @@ -76,7 +77,7 @@
      +
      +	*(p++) = '\n'; /* we no longer need a NUL */
      +	fflush(stderr);
     -+	xwrite(2, msg, p - msg);
     ++	write_in_full(2, msg, p - msg);
       }
       
       static NORETURN void usage_builtin(const char *err, va_list params)

-- 
gitgitgadget