{"thread":{"id":"4599","subject":"[PATCH 2/4] upload-pack: prepare for sideband message support.","startedAt":"2006-06-21T08:12:47Z","lastAt":"2006-06-21T08:12:47Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"22176","messageId":"7vlkrr3p1c.fsf@assigned-by-dhcp.cox.net","threadId":"4599","inReplyTo":null,"subject":"[PATCH 2/4] upload-pack: prepare for sideband message support.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-21T08:12:47Z","receivedAt":"2006-06-21T08:12:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This does not implement sideband for propagating the status to\nthe downloader yet, but add code to capture the standard error\noutput from the pack-objects process in preparation for sending\nit off to the client when the protocol extension allows us to do\nso.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n pack-objects.c |    4 ++++\n upload-pack.c  |   46 +++++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 43 insertions(+), 7 deletions(-)\n\ndiff --git a/pack-objects.c b/pack-objects.c\nindex 179560f..7a8c16c 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -1221,6 +1221,10 @@ int main(int argc, char **argv)\n \t\t\t\tlocal = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(\"--progress\", arg)) {\n+\t\t\t\tprogress = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(\"--incremental\", arg)) {\n \t\t\t\tincremental = 1;\n \t\t\t\tcontinue;\ndiff --git a/upload-pack.c b/upload-pack.c\nindex a9a8f2e..13eaa22 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -36,11 +36,13 @@ static int strip(char *line, int len)\n \n static void create_pack_file(void)\n {\n-\t/* Pipes between rev-list to pack-objects and pack-objects to us. */\n-\tint lp_pipe[2], pu_pipe[2];\n+\t/* Pipes between rev-list to pack-objects, pack-objects to us\n+\t * and pack-objects error stream for progress bar.\n+\t */\n+\tint lp_pipe[2], pu_pipe[2], pe_pipe[2];\n \tpid_t pid_rev_list, pid_pack_objects;\n \tint create_full_pack = (nr_our_refs == nr_needs && !nr_has);\n-\tchar data[8193];\n+\tchar data[8193], progress[128];\n \tint buffered = -1;\n \n \tif (pipe(lp_pipe) < 0)\n@@ -95,6 +97,8 @@ static void create_pack_file(void)\n \n \tif (pipe(pu_pipe) < 0)\n \t\tdie(\"git-upload-pack: unable to create pipe\");\n+\tif (pipe(pe_pipe) < 0)\n+\t\tdie(\"git-upload-pack: unable to create pipe\");\n \tpid_pack_objects = fork();\n \tif (pid_pack_objects < 0) {\n \t\t/* daemon sets things up to ignore TERM */\n@@ -104,12 +108,15 @@ static void create_pack_file(void)\n \tif (!pid_pack_objects) {\n \t\tdup2(lp_pipe[0], 0);\n \t\tdup2(pu_pipe[1], 1);\n+\t\tdup2(pe_pipe[1], 2);\n \n \t\tclose(lp_pipe[0]);\n \t\tclose(lp_pipe[1]);\n \t\tclose(pu_pipe[0]);\n \t\tclose(pu_pipe[1]);\n-\t\texecl_git_cmd(\"pack-objects\", \"--stdout\", NULL);\n+\t\tclose(pe_pipe[0]);\n+\t\tclose(pe_pipe[1]);\n+\t\texecl_git_cmd(\"pack-objects\", \"--stdout\", \"--progress\", NULL);\n \t\tkill(pid_rev_list, SIGKILL);\n \t\tdie(\"git-upload-pack: unable to exec git-pack-objects\");\n \t}\n@@ -117,20 +124,23 @@ static void create_pack_file(void)\n \tclose(lp_pipe[0]);\n \tclose(lp_pipe[1]);\n \n-\t/* We read from pu_pipe[0] to capture the pack data.\n+\t/* We read from pe_pipe[0] to capture stderr output for\n+\t * progress bar, and pu_pipe[0] to capture the pack data.\n \t */\n+\tclose(pe_pipe[1]);\n \tclose(pu_pipe[1]);\n \n \twhile (1) {\n \t\tconst char *who;\n+\t\tchar *cp;\n \t\tstruct pollfd pfd[2];\n \t\tpid_t pid;\n \t\tint status;\n \t\tssize_t sz;\n-\t\tint pu, pollsize;\n+\t\tint pe, pu, pollsize;\n \n \t\tpollsize = 0;\n-\t\tpu = -1;\n+\t\tpe = pu = -1;\n \n \t\tif (0 <= pu_pipe[0]) {\n \t\t\tpfd[pollsize].fd = pu_pipe[0];\n@@ -138,6 +148,12 @@ static void create_pack_file(void)\n \t\t\tpu = pollsize;\n \t\t\tpollsize++;\n \t\t}\n+\t\tif (0 <= pe_pipe[0]) {\n+\t\t\tpfd[pollsize].fd = pe_pipe[0];\n+\t\t\tpfd[pollsize].events = POLLIN;\n+\t\t\tpe = pollsize;\n+\t\t\tpollsize++;\n+\t\t}\n \n \t\tif (pollsize) {\n \t\t\tif (poll(pfd, pollsize, -1) < 0) {\n@@ -187,6 +203,22 @@ static void create_pack_file(void)\n \t\t\t\tif (sz < 0)\n \t\t\t\t\tgoto fail;\n \t\t\t}\n+\t\t\tif (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {\n+\t\t\t\t/* Status ready; we do not use it for now,\n+\t\t\t\t * but later we will add side-band to send it\n+\t\t\t\t * to the other side.\n+\t\t\t\t */\n+\t\t\t\tsz = read(pe_pipe[0], progress,\n+\t\t\t\t\t  sizeof(progress));\n+\t\t\t\tif (0 < sz)\n+\t\t\t\t\twrite(2, progress, sz);\n+\t\t\t\telse if (sz == 0) {\n+\t\t\t\t\tclose(pe_pipe[0]);\n+\t\t\t\t\tpe_pipe[0] = -1;\n+\t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t\tgoto fail;\n+\t\t\t}\n \t\t}\n \n \t\t/* See if the children are still there */\n-- \n1.4.0.gbb3f\n"}]}