chiark / gitweb /
Dgit.pm: printcmd: Print in one go
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jul 2019 12:28:06 +0000 (13:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jul 2019 12:33:01 +0000 (13:33 +0100)
Sometimes this message is used to report failure of `git fetch' etc.
But when such operations fail, they may interleave output from the
remote git, which typically prints
  fatal: The remote end hung up unexpectedly
(referring to the local end as the `remote' end, from its point
of view), after the the local end printed its message and failed.

This sets up a race between Dgit.pm's printcmd and the message from
the remote.  If we're really unlucky, the remote's message interrupts
the output from printcmd.

We can avoid the within-line interleaving - at least, the interruption
of our message - by printing the whole message in one go, so do that.
(Strictly, the approach we use here only ensures that the message
appears in a single write(2) call if it fits in the stdio buffer.)

One of our test cases (tagupl) depends on this message not being split
and has a small chance of failing without this fix.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm

index 9c1a08e7e28641661833e0bf1d1dd080c72664ac..d99e52011a3638ad287a393e950f4b3b47a1f785 100644 (file)
@@ -219,9 +219,7 @@ sub shellquote {
 sub printcmd {
     my $fh = shift @_;
     my $intro = shift @_;
-    print $fh $intro," " or confess "$!";
-    print $fh shellquote @_ or confess "$!";
-    print $fh "\n" or confess "$!";
+    print $fh $intro." ".(join '', shellquote @_)."\n" or confess "$!";
 }
 
 sub debugcmd {