Skip to content

Commit a22e6f8

Browse files
peffgitster
authored andcommitted
receive-pack: send pack-processing stderr over sideband
Receive-pack invokes either unpack-objects or index-pack to handle the incoming pack. However, we do not redirect the stderr of the sub-processes at all, so it is never seen by the client. From the initial thread adding sideband support, which is here: http://thread.gmane.org/gmane.comp.version-control.git/139471 it is clear that some messages are specifically kept off the sideband (with the assumption that they are of interest only to an administrator, not the client). The stderr of the subprocesses is mentioned in the thread, but it's unclear if they are included in that group, or were simply forgotten. However, there are a few good reasons to show them to the client: 1. In many cases, they are directly about the incoming packfile (e.g., fsck warnings with --strict, corruption in the packfile, etc). Without these messages, the client just gets "unpacker error" with no extra useful diagnosis. 2. No matter what the cause, we are probably better off showing the errors to the client. If the client and the server admin are not the same entity, it is probably much easier for the client to cut-and-paste the errors they see than for the admin to try to dig them out of a log and correlate them with a particular session. 3. Users of the ssh transport typically already see these stderr messages, as the remote's stderr is copied literally by ssh. This brings other transports (http, and push-over-git if you are crazy enough to enable it) more in line with ssh. As a bonus for ssh users, because the messages are now fed through the sideband and printed by the local git, they will have "remote:" prepended and be properly interleaved with any local output to stderr. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59bfdfb commit a22e6f8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

builtin/receive-pack.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static const char *parse_pack_header(struct pack_header *hdr)
801801

802802
static const char *pack_lockfile;
803803

804-
static const char *unpack(void)
804+
static const char *unpack(int err_fd)
805805
{
806806
struct pack_header hdr;
807807
const char *hdr_err;
@@ -833,6 +833,7 @@ static const char *unpack(void)
833833
memset(&child, 0, sizeof(child));
834834
child.argv = unpacker;
835835
child.no_stdout = 1;
836+
child.err = err_fd;
836837
child.git_cmd = 1;
837838
code = run_command(&child);
838839
if (!code)
@@ -859,6 +860,7 @@ static const char *unpack(void)
859860
memset(&ip, 0, sizeof(ip));
860861
ip.argv = keeper;
861862
ip.out = -1;
863+
ip.err = err_fd;
862864
ip.git_cmd = 1;
863865
status = start_command(&ip);
864866
if (status) {
@@ -875,6 +877,26 @@ static const char *unpack(void)
875877
}
876878
}
877879

880+
static const char *unpack_with_sideband(void)
881+
{
882+
struct async muxer;
883+
const char *ret;
884+
885+
if (!use_sideband)
886+
return unpack(0);
887+
888+
memset(&muxer, 0, sizeof(muxer));
889+
muxer.proc = copy_to_sideband;
890+
muxer.in = -1;
891+
if (start_async(&muxer))
892+
return NULL;
893+
894+
ret = unpack(muxer.in);
895+
896+
finish_async(&muxer);
897+
return ret;
898+
}
899+
878900
static void report(struct command *commands, const char *unpack_status)
879901
{
880902
struct command *cmd;
@@ -972,7 +994,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
972994
const char *unpack_status = NULL;
973995

974996
if (!delete_only(commands))
975-
unpack_status = unpack();
997+
unpack_status = unpack_with_sideband();
976998
execute_commands(commands, unpack_status);
977999
if (pack_lockfile)
9781000
unlink_or_warn(pack_lockfile);

0 commit comments

Comments
 (0)