receive-pack: relay connectivity errors to sideband

If the connectivity check encounters a problem when receiving a push, the error output goes to receive-pack's stderr, whose destination depends on the protocol used (ssh tends to send it to the user, though without a "remote" prefix; http will generally eat it in the server's error log). The information should consistently go back to the user, as there is a reasonable chance their client is buggy and generating a bad pack. We can do so by muxing it over the sideband as we do with other sub-process stderr. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 15, 2016 at 06:36 UTC d415092ac4a7fb474dc9823a1cc08ae824267e35
1 file changed +17 -1
builtin/receive-pack.c
+17 -1
@@ -1317,9 +1317,12 @@ static void execute_commands(struct command *commands,
1317 const char *unpacker_error,
1318 struct shallow_info *si)
1319 {
1320 + struct check_connected_options opt = CHECK_CONNECTED_INIT;
1321 struct command *cmd;
1322 unsigned char sha1[20];
1323 struct iterate_data data;
1324 + struct async muxer;
1325 + int err_fd = 0;
1326
1327 if (unpacker_error) {
1328 for (cmd = commands; cmd; cmd = cmd->next)
@@ -1327,11 +1330,24 @@ static void execute_commands(struct command *commands,
1330 return;
1331 }
1332
1333 + if (use_sideband) {
1334 + memset(&muxer, 0, sizeof(muxer));
1335 + muxer.proc = copy_to_sideband;
1336 + muxer.in = -1;
1337 + if (!start_async(&muxer))
1338 + err_fd = muxer.in;
1339 + /* ...else, continue without relaying sideband */
1340 + }
1341 +
1342 data.cmds = commands;
1343 data.si = si;
1332 - if (check_connected(iterate_receive_command_list, &data, NULL))
1344 + opt.err_fd = err_fd;
1345 + if (check_connected(iterate_receive_command_list, &data, &opt))
1346 set_connectivity_errors(commands, si);
1347
1348 + if (use_sideband)
1349 + finish_async(&muxer);
1350 +
1351 reject_updates_to_hidden(commands);
1352
1353 if (run_receive_hook(commands, "pre-receive", 0)) {