sideband.c: refactor recv_sideband()
authorLukas Fleischer <lfleischer@lfos.de>
Tue, 28 Jun 2016 04:35:26 +0000 (06:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2016 20:09:37 +0000 (13:09 -0700)
commit5e5be9e257239b3599701f05518ce9e45f565e9f
tree0043651653e62cd21bd1b3c9b6a6e6e17f38b29f
parent765428699a5381f113d19974720bc91b5bfeaf1d
sideband.c: refactor recv_sideband()

We used character buffer manipulations to split messages from the
sideband at line breaks and insert "remote: " at the beginning of
each line, using the packet size to determine the end of a message.

However, since it is safe to assume that diagnostic messages from
the sideband never contain NUL characters, we can also NUL-terminate
the buffer, use strpbrk() for splitting lines and use format strings
to insert the prefix, to make the code easier to read and maintain.

A strbuf is used for accumulating the output which is then printed
using a single write(2) call to ensure the atomicity of the output.
See 9ac13ec (atomic write for sideband remote messages, 2006-10-11)
for details.

Helped-by: Jeff King <peff@peff.net>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sideband.c