{"thread":{"id":"25757","subject":"[PATCH v8 3/3] git-remote-ext","startedAt":"2010-11-16T03:34:11Z","lastAt":"2010-11-18T02:31:04Z","messageCount":6,"participants":["Ilari Liusvaara","Junio C Hamano"],"isPatch":true,"patchVersion":8,"patchTotal":3},"messages":[{"id":"155974","messageId":"1289878454-17192-1-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25757","inReplyTo":null,"subject":"[PATCH v8 0/3] git-remote-fd & git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-11-16T03:34:11Z","receivedAt":"2010-11-16T03:34:11Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"This adds two new remote helpers.\n\n* git-remote-fd, which connects to git service on given file descriptor(s),\nuseful for graphical user interfaces that want to use internal ssh client.\n\n* git-remote-ext, which connect to git service using external program. Useful\nfor connecting using odd one-off ssh options, to services in abstract\nnamespace, using unix domain sockets, using TLS, etc...\n\nChanges from last time:\n* Some manpage formatting changes.\n* Some manpage wording changes.\n* Don't try to write outside buffers if all-whitespace command line is\nreceived.\n* Some code cleanups.\n\n\nIlari Liusvaara (3):\n  Add bidirectional_transfer_loop()\n  git-remote-fd\n  git-remote-ext\n\n .gitignore                       |    2 +\n Documentation/git-remote-ext.txt |  125 +++++++++++++++\n Documentation/git-remote-fd.txt  |   59 +++++++\n Makefile                         |    2 +\n builtin.h                        |    2 +\n builtin/remote-ext.c             |  246 +++++++++++++++++++++++++++++\n builtin/remote-fd.c              |   79 ++++++++++\n compat/mingw.h                   |    5 +\n git.c                            |    2 +\n transport-helper.c               |  316 ++++++++++++++++++++++++++++++++++++++\n transport.h                      |    1 +\n 11 files changed, 839 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-remote-ext.txt\n create mode 100644 Documentation/git-remote-fd.txt\n create mode 100644 builtin/remote-ext.c\n create mode 100644 builtin/remote-fd.c\n"},{"id":"155976","messageId":"1289878454-17192-2-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25757","inReplyTo":"1289878454-17192-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH v8 1/3] Add bidirectional_transfer_loop()","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-11-16T03:34:12Z","receivedAt":"2010-11-16T03:34:12Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"This helper function copies bidirectional stream of data between\nstdin/stdout and specified file descriptors.\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\n compat/mingw.h     |    5 +\n transport-helper.c |  316 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n transport.h        |    1 +\n 3 files changed, 322 insertions(+), 0 deletions(-)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex f465566..00ee685 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -23,6 +23,9 @@ typedef int pid_t;\n #define WEXITSTATUS(x) ((x) & 0xff)\n #define WTERMSIG(x) SIGTERM\n \n+#define EWOULDBLOCK EAGAIN\n+#define SHUT_WR SD_SEND\n+\n #define SIGHUP 1\n #define SIGQUIT 3\n #define SIGKILL 9\n@@ -50,6 +53,8 @@ struct pollfd {\n };\n #define POLLIN 1\n #define POLLHUP 2\n+#define POLLOUT 4\n+#define POLLNVAL 8\n #endif\n \n typedef void (__cdecl *sig_handler_t)(int);\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 0381de5..b52c08e 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -9,6 +9,11 @@\n #include \"remote.h\"\n #include \"string-list.h\"\n \n+#ifndef NO_PTHREADS\n+#include <pthread.h>\n+#include \"thread-utils.h\"\n+#endif\n+\n static int debug;\n \n struct helper_data\n@@ -862,3 +867,314 @@ int transport_helper_init(struct transport *transport, const char *name)\n \ttransport->smart_options = &(data->transport_options);\n \treturn 0;\n }\n+\n+/*\n+ * Linux pipes can buffer 65536 bytes at once (and most platforms can\n+ * buffer less), so attempt reads and writes with up to that size.\n+ */\n+#define BUFFERSIZE 65536\n+/* This should be enough to hold debugging message. */\n+#define PBUFFERSIZE 8192\n+\n+/* Print bidirectional transfer loop debug message. */\n+static void transfer_debug(const char *fmt, ...)\n+{\n+\tva_list args;\n+\tchar msgbuf[PBUFFERSIZE];\n+\tstatic int debug_enabled = -1;\n+\n+\tif (debug_enabled < 0)\n+\t\tdebug_enabled = getenv(\"GIT_TRANSLOOP_DEBUG\") ? 1 : 0;\n+\tif (!debug_enabled)\n+\t\treturn;\n+\n+\tva_start(args, fmt);\n+\tvsnprintf(msgbuf, PBUFFERSIZE, fmt, args);\n+\tva_end(args);\n+\tfprintf(stderr, \"Transfer loop debugging: %s\\n\", msgbuf);\n+}\n+\n+/* Stream state: More data may be coming in this direction. */\n+#define SSTATE_TRANSFERING 0\n+/*\n+ * Stream state: No more data coming in this direction, flushing rest of\n+ * data.\n+ */\n+#define SSTATE_FLUSHING 1\n+/* Stream state: Transfer in this direction finished. */\n+#define SSTATE_FINISHED 2\n+\n+#define STATE_NEEDS_READING(state) ((state) <= SSTATE_TRANSFERING)\n+#define STATE_NEEDS_WRITING(state) ((state) <= SSTATE_FLUSHING)\n+#define STATE_NEEDS_CLOSING(state) ((state) == SSTATE_FLUSHING)\n+\n+/* Unidirectional transfer. */\n+struct unidirectional_transfer {\n+\t/* Source */\n+\tint src;\n+\t/* Destination */\n+\tint dest;\n+\t/* Is source socket? */\n+\tint src_is_sock;\n+\t/* Is destination socket? */\n+\tint dest_is_sock;\n+\t/* Transfer state (TRANSFERING/FLUSHING/FINISHED) */\n+\tint state;\n+\t/* Buffer. */\n+\tchar buf[BUFFERSIZE];\n+\t/* Buffer used. */\n+\tsize_t bufuse;\n+\t/* Name of source. */\n+\tconst char *src_name;\n+\t/* Name of destination. */\n+\tconst char *dest_name;\n+};\n+\n+/* Closes the target (for writing) if transfer has finished. */\n+static void udt_close_if_finished(struct unidirectional_transfer *t)\n+{\n+\tif (STATE_NEEDS_CLOSING(t->state) && !t->bufuse) {\n+\t\tt->state = SSTATE_FINISHED;\n+\t\tif (t->dest_is_sock)\n+\t\t\tshutdown(t->dest, SHUT_WR);\n+\t\telse\n+\t\t\tclose(t->dest);\n+\t\ttransfer_debug(\"Closed %s.\", t->dest_name);\n+\t}\n+}\n+\n+/*\n+ * Tries to read read data from source into buffer. If buffer is full,\n+ * no data is read. Returns 0 on success, -1 on error.\n+ */\n+static int udt_do_read(struct unidirectional_transfer *t)\n+{\n+\tssize_t bytes;\n+\n+\tif (t->bufuse == BUFFERSIZE)\n+\t\treturn 0;\t/* No space for more. */\n+\n+\ttransfer_debug(\"%s is readable\", t->src_name);\n+\tbytes = read(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse);\n+\tif (bytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&\n+\t\terrno != EINTR) {\n+\t\terror(\"read(%s) failed: %s\", t->src_name, strerror(errno));\n+\t\treturn -1;\n+\t} else if (bytes == 0) {\n+\t\ttransfer_debug(\"%s EOF (with %i bytes in buffer)\",\n+\t\t\tt->src_name, t->bufuse);\n+\t\tt->state = SSTATE_FLUSHING;\n+\t} else if (bytes > 0) {\n+\t\tt->bufuse += bytes;\n+\t\ttransfer_debug(\"Read %i bytes from %s (buffer now at %i)\",\n+\t\t\t(int)bytes, t->src_name, (int)t->bufuse);\n+\t}\n+\treturn 0;\n+}\n+\n+/* Tries to write data from buffer into destination. If buffer is empty,\n+ * no data is written. Returns 0 on success, -1 on error.\n+ */\n+static int udt_do_write(struct unidirectional_transfer *t)\n+{\n+\tsize_t bytes;\n+\n+\tif (t->bufuse == 0)\n+\t\treturn 0;\t/* Nothing to write. */\n+\n+\ttransfer_debug(\"%s is writable\", t->dest_name);\n+\tbytes = write(t->dest, t->buf, t->bufuse);\n+\tif (bytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&\n+\t\terrno != EINTR) {\n+\t\terror(\"write(%s) failed: %s\", t->dest_name, strerror(errno));\n+\t\treturn -1;\n+\t} else if (bytes > 0) {\n+\t\tt->bufuse -= bytes;\n+\t\tif (t->bufuse)\n+\t\t\tmemmove(t->buf, t->buf + bytes, t->bufuse);\n+\t\ttransfer_debug(\"Wrote %i bytes to %s (buffer now at %i)\",\n+\t\t\t(int)bytes, t->dest_name, (int)t->bufuse);\n+\t}\n+\treturn 0;\n+}\n+\n+\n+/* State of bidirectional transfer loop. */\n+struct bidirectional_transfer_state {\n+\t/* Direction from program to git. */\n+\tstruct unidirectional_transfer ptg;\n+\t/* Direction from git to program. */\n+\tstruct unidirectional_transfer gtp;\n+};\n+\n+static void *udt_copy_task_routine(void *udt)\n+{\n+\tstruct unidirectional_transfer *t = (struct unidirectional_transfer *)udt;\n+\twhile (t->state != SSTATE_FINISHED) {\n+\t\tif (STATE_NEEDS_READING(t->state))\n+\t\t\tif (udt_do_read(t))\n+\t\t\t\treturn NULL;\n+\t\tif (STATE_NEEDS_WRITING(t->state))\n+\t\t\tif (udt_do_write(t))\n+\t\t\t\treturn NULL;\n+\t\tif (STATE_NEEDS_CLOSING(t->state))\n+\t\t\tudt_close_if_finished(t);\n+\t}\n+\treturn udt;\t/* Just some non-NULL value. */\n+}\n+\n+#ifndef NO_PTHREADS\n+\n+/*\n+ * Join thread, with apporiate errors on failure. Name is name for the\n+ * thread (for error messages). Returns 0 on success, 1 on failure.\n+ */\n+static int tloop_join(pthread_t thread, const char *name)\n+{\n+\tint err;\n+\tvoid *tret;\n+\terr = pthread_join(thread, &tret);\n+\tif (!tret) {\n+\t\terror(\"%s thread failed\", name);\n+\t\treturn 1;\n+\t}\n+\tif (err) {\n+\t\terror(\"%s thread failed to join: %s\", name, strerror(err));\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * Spawn the transfer tasks and then wait for them. Returns 0 on success,\n+ * -1 on failure.\n+ */\n+static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)\n+{\n+\tpthread_t gtp_thread;\n+\tpthread_t ptg_thread;\n+\tint err;\n+\tint ret = 0;\n+\terr = pthread_create(&gtp_thread, NULL, udt_copy_task_routine,\n+\t\t&s->gtp);\n+\tif (err)\n+\t\tdie(\"Can't start thread for copying data: %s\", strerror(err));\n+\terr = pthread_create(&ptg_thread, NULL, udt_copy_task_routine,\n+\t\t&s->ptg);\n+\tif (err)\n+\t\tdie(\"Can't start thread for copying data: %s\", strerror(err));\n+\n+\tret |= tloop_join(gtp_thread, \"Git to program copy\");\n+\tret |= tloop_join(ptg_thread, \"Program to git copy\");\n+\treturn ret;\n+}\n+#else\n+\n+/* Close the source and target (for writing) for transfer. */\n+static void udt_kill_transfer(struct unidirectional_transfer *t)\n+{\n+\tt->state = SSTATE_FINISHED;\n+\t/*\n+\t * Socket read end left open isn't a disaster if nobody\n+\t * attempts to read from it (mingw compat headers do not\n+\t * have SHUT_RD)...\n+\t *\n+\t * We can't fully close the socket since otherwise gtp\n+\t * task would first close the socket it sends data to\n+\t * while closing the ptg file descriptors.\n+\t */\n+\tif (!t->src_is_sock)\n+\t\tclose(t->src);\n+\tif (t->dest_is_sock)\n+\t\tshutdown(t->dest, SHUT_WR);\n+\telse\n+\t\tclose(t->dest);\n+}\n+\n+/*\n+ * Join process, with apporiate errors on failure. Name is name for the\n+ * process (for error messages). Returns 0 on success, 1 on failure.\n+ */\n+static int tloop_join(pid_t pid, const char *name)\n+{\n+\tint tret;\n+\tif (waitpid(pid, &tret, 0) < 0) {\n+\t\terror(\"%s process failed to wait: %s\", name, strerror(errno));\n+\t\treturn 1;\n+\t}\n+\tif (!WIFEXITED(tret) || WEXITSTATUS(tret)) {\n+\t\terror(\"%s process failed\", name);\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * Spawn the transfer tasks and then wait for them. Returns 0 on success,\n+ * -1 on failure.\n+ */\n+static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)\n+{\n+\tpid_t pid1, pid2;\n+\tint ret = 0;\n+\n+\t/* Fork thread #1: git to program. */\n+\tpid1 = fork();\n+\tif (pid1 < 0)\n+\t\tdie_errno(\"Can't start thread for copying data\");\n+\telse if (pid1 == 0) {\n+\t\tudt_kill_transfer(&s->ptg);\n+\t\texit(udt_copy_task_routine(&s->gtp) ? 0 : 1);\n+\t}\n+\n+\t/* Fork thread #2: program to git. */\n+\tpid2 = fork();\n+\tif (pid2 < 0)\n+\t\tdie_errno(\"Can't start thread for copying data\");\n+\telse if (pid2 == 0) {\n+\t\tudt_kill_transfer(&s->gtp);\n+\t\texit(udt_copy_task_routine(&s->ptg) ? 0 : 1);\n+\t}\n+\n+\t/*\n+\t * Close both streams in parent as to not interfere with\n+\t * end of file detection and wait for both tasks to finish.\n+\t */\n+\tudt_kill_transfer(&s->gtp);\n+\tudt_kill_transfer(&s->ptg);\n+\tret |= tloop_join(pid1, \"Git to program copy\");\n+\tret |= tloop_join(pid2, \"Program to git copy\");\n+\treturn ret;\n+}\n+#endif\n+\n+/*\n+ * Copies data from stdin to output and from input to stdout simultaneously.\n+ * Additionally filtering through given filter. If filter is NULL, uses\n+ * identity filter.\n+ */\n+int bidirectional_transfer_loop(int input, int output)\n+{\n+\tstruct bidirectional_transfer_state state;\n+\n+\t/* Fill the state fields. */\n+\tstate.ptg.src = input;\n+\tstate.ptg.dest = 1;\n+\tstate.ptg.src_is_sock = (input == output);\n+\tstate.ptg.dest_is_sock = 0;\n+\tstate.ptg.state = SSTATE_TRANSFERING;\n+\tstate.ptg.bufuse = 0;\n+\tstate.ptg.src_name = \"remote input\";\n+\tstate.ptg.dest_name = \"stdout\";\n+\n+\tstate.gtp.src = 0;\n+\tstate.gtp.dest = output;\n+\tstate.gtp.src_is_sock = 0;\n+\tstate.gtp.dest_is_sock = (input == output);\n+\tstate.gtp.state = SSTATE_TRANSFERING;\n+\tstate.gtp.bufuse = 0;\n+\tstate.gtp.src_name = \"stdin\";\n+\tstate.gtp.dest_name = \"remote output\";\n+\n+\treturn tloop_spawnwait_tasks(&state);\n+}\ndiff --git a/transport.h b/transport.h\nindex c59d973..e803c0e 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -154,6 +154,7 @@ int transport_connect(struct transport *transport, const char *name,\n \n /* Transport methods defined outside transport.c */\n int transport_helper_init(struct transport *transport, const char *name);\n+int bidirectional_transfer_loop(int input, int output);\n \n /* common methods used by transport.c and builtin-send-pack.c */\n void transport_verify_remote_names(int nr_heads, const char **heads);\n-- \n1.7.1.336.ge601a.dirty\n"},{"id":"155975","messageId":"1289878454-17192-3-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25757","inReplyTo":"1289878454-17192-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH v8 2/3] git-remote-fd","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-11-16T03:34:13Z","receivedAt":"2010-11-16T03:34:13Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"This remote helper reflects raw smart remote transport stream back to the\ncalling program. This is useful for example if some UI wants to handle\nssh itself and not use hacks via GIT_SSH.\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\n .gitignore                      |    1 +\n Documentation/git-remote-fd.txt |   59 +++++++++++++++++++++++++++++\n Makefile                        |    1 +\n builtin.h                       |    1 +\n builtin/remote-fd.c             |   79 +++++++++++++++++++++++++++++++++++++++\n git.c                           |    1 +\n 6 files changed, 142 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-remote-fd.txt\n create mode 100644 builtin/remote-fd.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 14e2b6b..7509b01 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -112,6 +112,7 @@\n /git-remote-https\n /git-remote-ftp\n /git-remote-ftps\n+/git-remote-fd\n /git-remote-testgit\n /git-repack\n /git-replace\ndiff --git a/Documentation/git-remote-fd.txt b/Documentation/git-remote-fd.txt\nnew file mode 100644\nindex 0000000..abc4944\n--- /dev/null\n+++ b/Documentation/git-remote-fd.txt\n@@ -0,0 +1,59 @@\n+git-remote-fd(1)\n+================\n+\n+NAME\n+----\n+git-remote-fd - Reflect smart transport stream back to caller\n+\n+SYNOPSIS\n+--------\n+\"fd::<infd>[,<outfd>][/<anything>]\" (as URL)\n+\n+DESCRIPTION\n+-----------\n+This helper uses specified file descriptors to connect to remote git server.\n+This is not meant for end users but for programs and scripts calling git\n+fetch, push or archive.\n+\n+If only <infd> is given, it is assumed to be bidirectional socket connected\n+to remote git server (git-upload-pack, git-receive-pack or\n+git-upload-achive). If both <infd> and <outfd> are given, they are assumed\n+to be pipes connected to remote git server (<infd> being the inbound pipe\n+and <outfd> being the outbound pipe.\n+\n+It is assumed that any handshaking procedures have already been completed\n+(such as sending service request for git://) before this helper is started.\n+\n+<anything> can be any string. It is ignored. It is meant for provoding\n+information to user in the URL in case that URL is displayed in some\n+context.\n+\n+ENVIRONMENT VARIABLES\n+---------------------\n+GIT_TRANSLOOP_DEBUG::\n+\tIf set, prints debugging information about various reads/writes.\n+\n+EXAMPLES\n+--------\n+git fetch fd::17 master::\n+\tFetch master, using file descriptor #17 to communicate with\n+\tgit-upload-pack.\n+\n+git fetch fd::17/foo master::\n+\tSame as above.\n+\n+git push fd::7,8 master (as URL)::\n+\tPush master, using file descriptor #7 to read data from\n+\tgit-receive-pack and file descriptor #8 to write data to\n+\tsame service.\n+\n+git push fd::7,8/bar master::\n+\tSame as above.\n+\n+Documentation\n+--------------\n+Documentation by Ilari Liusvaara and the git list <git@vger.kernel.org>\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Makefile b/Makefile\nindex 5fa893c..ad53b52 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -702,6 +702,7 @@ BUILTIN_OBJS += builtin/read-tree.o\n BUILTIN_OBJS += builtin/receive-pack.o\n BUILTIN_OBJS += builtin/reflog.o\n BUILTIN_OBJS += builtin/remote.o\n+BUILTIN_OBJS += builtin/remote-fd.o\n BUILTIN_OBJS += builtin/replace.o\n BUILTIN_OBJS += builtin/rerere.o\n BUILTIN_OBJS += builtin/reset.o\ndiff --git a/builtin.h b/builtin.h\nindex 5c887ef..d870695 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -106,6 +106,7 @@ extern int cmd_read_tree(int argc, const char **argv, const char *prefix);\n extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);\n extern int cmd_reflog(int argc, const char **argv, const char *prefix);\n extern int cmd_remote(int argc, const char **argv, const char *prefix);\n+extern int cmd_remote_fd(int argc, const char **argv, const char *prefix);\n extern int cmd_config(int argc, const char **argv, const char *prefix);\n extern int cmd_rerere(int argc, const char **argv, const char *prefix);\n extern int cmd_reset(int argc, const char **argv, const char *prefix);\ndiff --git a/builtin/remote-fd.c b/builtin/remote-fd.c\nnew file mode 100644\nindex 0000000..1f2467b\n--- /dev/null\n+++ b/builtin/remote-fd.c\n@@ -0,0 +1,79 @@\n+#include \"git-compat-util.h\"\n+#include \"transport.h\"\n+\n+/*\n+ * URL syntax:\n+ *\t'fd::<inoutfd>[/<anything>]'\t\tRead/write socket pair\n+ *\t\t\t\t\t\t<inoutfd>.\n+ *\t'fd::<infd>,<outfd>[/<anything>]'\tRead pipe <infd> and write\n+ *\t\t\t\t\t\tpipe <outfd>.\n+ *\t[foo] indicates 'foo' is optional. <anything> is any string.\n+ *\n+ * The data output to <outfd>/<inoutfd> should be passed unmolested to\n+ * git-receive-pack/git-upload-pack/git-upload-archive and output of\n+ * git-receive-pack/git-upload-pack/git-upload-archive should be passed\n+ * unmolested to <infd>/<inoutfd>.\n+ *\n+ */\n+\n+#define MAXCOMMAND 4096\n+\n+static void command_loop(int input_fd, int output_fd)\n+{\n+\tchar buffer[MAXCOMMAND];\n+\n+\twhile (1) {\n+\t\tsize_t i;\n+\t\tif (!fgets(buffer, MAXCOMMAND - 1, stdin)) {\n+\t\t\tif (ferror(stdin))\n+\t\t\t\tdie(\"Input error\");\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Strip end of line characters. */\n+\t\ti = strlen(buffer);\n+\t\twhile (i > 0 && isspace(buffer[i - 1]))\n+\t\t\tbuffer[--i] = 0;\n+\n+\t\tif (!strcmp(buffer, \"capabilities\")) {\n+\t\t\tprintf(\"*connect\\n\\n\");\n+\t\t\tfflush(stdout);\n+\t\t} else if (!strncmp(buffer, \"connect \", 8)) {\n+\t\t\tprintf(\"\\n\");\n+\t\t\tfflush(stdout);\n+\t\t\tif (bidirectional_transfer_loop(input_fd,\n+\t\t\t\toutput_fd))\n+\t\t\t\tdie(\"Copying data between file descriptors failed\");\n+\t\t\treturn;\n+\t\t} else {\n+\t\t\tdie(\"Bad command: %s\", buffer);\n+\t\t}\n+\t}\n+}\n+\n+int cmd_remote_fd(int argc, const char **argv, const char *prefix)\n+{\n+\tint input_fd = -1;\n+\tint output_fd = -1;\n+\tchar *end;\n+\n+\tif (argc != 3)\n+\t\tdie(\"Expected two arguments\");\n+\n+\tinput_fd = (int)strtoul(argv[2], &end, 10);\n+\n+\tif ((end == argv[2]) || (*end != ',' && *end != '/' && *end))\n+\t\tdie(\"Bad URL syntax\");\n+\n+\tif (*end == '/' || !*end) {\n+\t\toutput_fd = input_fd;\n+\t} else {\n+\t\tchar *end2;\n+\t\toutput_fd = (int)strtoul(end + 1, &end2, 10);\n+\n+\t\tif ((end2 == end + 1) || (*end2 != '/' && *end2))\n+\t\t\tdie(\"Bad URL syntax\");\n+\t}\n+\n+\tcommand_loop(input_fd, output_fd);\n+\treturn 0;\n+}\ndiff --git a/git.c b/git.c\nindex 99f0363..f5fc07b 100644\n--- a/git.c\n+++ b/git.c\n@@ -368,6 +368,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"receive-pack\", cmd_receive_pack },\n \t\t{ \"reflog\", cmd_reflog, RUN_SETUP },\n \t\t{ \"remote\", cmd_remote, RUN_SETUP },\n+\t\t{ \"remote-fd\", cmd_remote_fd },\n \t\t{ \"replace\", cmd_replace, RUN_SETUP },\n \t\t{ \"repo-config\", cmd_config },\n \t\t{ \"rerere\", cmd_rerere, RUN_SETUP },\n-- \n1.7.1.336.ge601a.dirty\n"},{"id":"155973","messageId":"1289878454-17192-4-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25757","inReplyTo":"1289878454-17192-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH v8 3/3] git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-11-16T03:34:14Z","receivedAt":"2010-11-16T03:34:14Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"This remote helper invokes external command and passes raw smart transport\nstream through it. This is useful for instance for invoking ssh with\none-off odd options, connecting to git services in unix domain\nsockets, in abstract namespace, using TLS or other secure protocols,\netc...\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\n .gitignore                       |    1 +\n Documentation/git-remote-ext.txt |  125 +++++++++++++++++++\n Makefile                         |    1 +\n builtin.h                        |    1 +\n builtin/remote-ext.c             |  246 ++++++++++++++++++++++++++++++++++++++\n git.c                            |    1 +\n 6 files changed, 375 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-remote-ext.txt\n create mode 100644 builtin/remote-ext.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 7509b01..2b3111f 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -113,6 +113,7 @@\n /git-remote-ftp\n /git-remote-ftps\n /git-remote-fd\n+/git-remote-ext\n /git-remote-testgit\n /git-repack\n /git-replace\ndiff --git a/Documentation/git-remote-ext.txt b/Documentation/git-remote-ext.txt\nnew file mode 100644\nindex 0000000..f4fbf67\n--- /dev/null\n+++ b/Documentation/git-remote-ext.txt\n@@ -0,0 +1,125 @@\n+git-remote-ext(1)\n+=================\n+\n+NAME\n+----\n+git-remote-ext - Bridge smart transport to external command.\n+\n+SYNOPSIS\n+--------\n+git remote add nick \"ext::<command>[ <arguments>...]\"\n+\n+DESCRIPTION\n+-----------\n+This remote helper uses the specified 'program' to connect\n+to a remote git server.\n+\n+Data written to stdin of this specified 'program' is assumed\n+to be sent to git:// server, git-upload-pack, git-receive-pack\n+or git-upload-archive (depending on situation), and data read\n+from stdout of this program is assumed to be received from\n+the same service.\n+\n+Command and arguments are separated by unescaped space.\n+\n+The following sequences have a special meaning:\n+\n+'% '::\n+\tLiteral space in command or argument.\n+\n+'%%'::\n+\tLiteral percent sign.\n+\n+'%s'::\n+\tReplaced with name (receive-pack, upload-pack, or\n+\tupload-archive) of the service git wants to invoke.\n+\n+'%S'::\n+\tReplaced with long name (git-receive-pack,\n+\tgit-upload-pack, or git-upload-archive) of the service\n+\tgit wants to invoke.\n+\n+'%G' (must be first characters in argument)::\n+\tThis argument will not be passed to 'program'. Instead, it\n+\twill cause helper to start by sending git:// service request to\n+\tremote side with service field set to approiate value and\n+\trepository field set to rest of the argument. Default is not to send\n+\tsuch request.\n++\n+This is useful if remote side is git:// server accessed over\n+some tunnel.\n+\n+'%V' (must be first characters in argument)::\n+\tThis argument will not be passed to 'program'. Instead it sets\n+\tthe vhost field in git:// service request (to rest of the argument).\n+\tDefault is not to send vhost in such request (if sent).\n+\n+ENVIRONMENT VARIABLES:\n+----------------------\n+\n+GIT_TRANSLOOP_DEBUG::\n+\tIf set, prints debugging information about various reads/writes.\n+\n+ENVIRONMENT VARIABLES PASSED TO COMMAND:\n+----------------------------------------\n+\n+GIT_EXT_SERVICE::\n+\tSet to long name (git-upload-pack, etc...) of service helper needs\n+\tto invoke.\n+\n+GIT_EXT_SERVICE_NOPREFIX::\n+\tSet to long name (upload-pack, etc...) of service helper needs\n+\tto invoke.\n+\n+\n+EXAMPLES:\n+---------\n+This remote helper is transparently used by git when\n+you use commands such as \"git fetch <URL>\", \"git clone <URL>\",\n+, \"git push <URL>\" or \"git remote add nick <URL>\", where <URL>\n+begins with `ext::`.  Examples:\n+\n+\"ext::ssh -i /home/foo/.ssh/somekey user&#64;host.example %S 'foo/repo'\"::\n+\tLike host.example:foo/repo, but use /home/foo/.ssh/somekey as\n+\tkeypair and user as user on remote side. This avoids needing to\n+\tedit .ssh/config.\n+\n+\"ext::socat -t3600 - ABSTRACT-CONNECT:/git-server %G/somerepo\"::\n+\tRepresents repository with path /somerepo accessable over\n+\tgit protocol at abstract namespace address /git-server.\n+\n+\"ext::git-server-alias foo %G/repo\"::\n+\tRepresents a repository with path /repo accessed using the\n+\thelper program \"git-server-alias foo\".  The path to the\n+\trepository and type of request are not passed on the command\n+\tline but as part of the protocol stream, as usual with git://\n+\tprotocol.\n+\n+\"ext::git-server-alias foo %G/repo %Vfoo\"::\n+\tRepresents a repository with path /repo accessed using the\n+\thelper program \"git-server-alias foo\".  The hostname for the\n+\tremote server passed in the protocol stream will be \"foo\"\n+\t(this allows multiple virtual git servers to share a\n+\tlink-level address).\n+\n+\"ext::git-server-alias foo %G/repo% with% spaces %Vfoo\"::\n+\tRepresents a repository with path '/repo with spaces' accessed\n+\tusing the helper program \"git-server-alias foo\".  The hostname for\n+\tthe remote server passed in the protocol stream will be \"foo\"\n+\t(this allows multiple virtual git servers to share a\n+\tlink-level address).\n+\n+\"ext::git-ssl foo.example /bar\"::\n+\tRepresents a repository accessed using the helper program\n+\t\"git-ssl foo.example /bar\".  The type of request can be\n+\tdetermined by the helper using environment variables (see\n+\tabove).\n+\n+Documentation\n+--------------\n+Documentation by Ilari Liusvaara, Jonathan Nieder and the git list\n+<git@vger.kernel.org>\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Makefile b/Makefile\nindex ad53b52..88e752f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -702,6 +702,7 @@ BUILTIN_OBJS += builtin/read-tree.o\n BUILTIN_OBJS += builtin/receive-pack.o\n BUILTIN_OBJS += builtin/reflog.o\n BUILTIN_OBJS += builtin/remote.o\n+BUILTIN_OBJS += builtin/remote-ext.o\n BUILTIN_OBJS += builtin/remote-fd.o\n BUILTIN_OBJS += builtin/replace.o\n BUILTIN_OBJS += builtin/rerere.o\ndiff --git a/builtin.h b/builtin.h\nindex d870695..2fb609f 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -106,6 +106,7 @@ extern int cmd_read_tree(int argc, const char **argv, const char *prefix);\n extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);\n extern int cmd_reflog(int argc, const char **argv, const char *prefix);\n extern int cmd_remote(int argc, const char **argv, const char *prefix);\n+extern int cmd_remote_ext(int argc, const char **argv, const char *prefix);\n extern int cmd_remote_fd(int argc, const char **argv, const char *prefix);\n extern int cmd_config(int argc, const char **argv, const char *prefix);\n extern int cmd_rerere(int argc, const char **argv, const char *prefix);\ndiff --git a/builtin/remote-ext.c b/builtin/remote-ext.c\nnew file mode 100644\nindex 0000000..1f77317\n--- /dev/null\n+++ b/builtin/remote-ext.c\n@@ -0,0 +1,246 @@\n+#include \"git-compat-util.h\"\n+#include \"transport.h\"\n+#include \"run-command.h\"\n+\n+/*\n+ * URL syntax:\n+ *\t'command [arg1 [arg2 [...]]]'\tInvoke command with given arguments.\n+ *\tSpecial characters:\n+ *\t'% ': Literal space in argument.\n+ *\t'%%': Literal percent sign.\n+ *\t'%S': Name of service (git-upload-pack/git-upload-archive/\n+ *\t\tgit-receive-pack.\n+ *\t'%s': Same as \\s, but with possible git- prefix stripped.\n+ *\t'%G': Only allowed as first 'character' of argument. Do not pass this\n+ *\t\tArgument to command, instead send this as name of repository\n+ *\t\tin in-line git://-style request (also activates sending this\n+ *\t\tstyle of request).\n+ *\t'%V': Only allowed as first 'character' of argument. Used in\n+ *\t\tconjunction with '%G': Do not pass this argument to command,\n+ *\t\tinstead send this as vhost in git://-style request (note: does\n+ *\t\tnot activate sending git:// style request).\n+ */\n+\n+static char *git_req;\n+static char *git_req_vhost;\n+\n+static char *strip_escapes(const char *str, const char *service,\n+\tconst char **next)\n+{\n+\tsize_t rpos = 0;\n+\tint escape = 0;\n+\tchar special = 0;\n+\tsize_t pslen = 0;\n+\tsize_t pSlen = 0;\n+\tsize_t psoff = 0;\n+\tstruct strbuf ret = STRBUF_INIT;\n+\n+\t/* Calculate prefix length for \\s and lengths for \\s and \\S */\n+\tif (!strncmp(service, \"git-\", 4))\n+\t\tpsoff = 4;\n+\tpSlen = strlen(service);\n+\tpslen = pSlen - psoff;\n+\n+\t/* Pass the service to command. */\n+\tsetenv(\"GIT_EXT_SERVICE\", service, 1);\n+\tsetenv(\"GIT_EXT_SERVICE_NOPREFIX\", service + psoff, 1);\n+\n+\t/* Scan the length of argument. */\n+\twhile (str[rpos] && (escape || str[rpos] != ' ')) {\n+\t\tif (escape) {\n+\t\t\tswitch (str[rpos]) {\n+\t\t\tcase ' ':\n+\t\t\tcase '%':\n+\t\t\tcase 's':\n+\t\t\tcase 'S':\n+\t\t\t\tbreak;\n+\t\t\tcase 'G':\n+\t\t\tcase 'V':\n+\t\t\t\tspecial = str[rpos];\n+\t\t\t\tif (rpos == 1)\n+\t\t\t\t\tbreak;\n+\t\t\t\t/* Fall-through to error. */\n+\t\t\tdefault:\n+\t\t\t\tdie(\"Bad remote-ext placeholder '%%%c'.\",\n+\t\t\t\t\tstr[rpos]);\n+\t\t\t}\n+\t\t\tescape = 0;\n+\t\t} else\n+\t\t\tescape = (str[rpos] == '%');\n+\t\trpos++;\n+\t}\n+\tif (escape && !str[rpos])\n+\t\tdie(\"remote-ext command has incomplete placeholder\");\n+\t*next = str + rpos;\n+\tif (**next == ' ')\n+\t\t++*next;\t/* Skip over space */\n+\n+\t/*\n+\t * Do the actual placeholder substitution. The string will be short\n+\t * enough not to overflow integers.\n+\t */\n+\trpos = special ? 2 : 0;\t\t/* Skip first 2 bytes in specials. */\n+\tescape = 0;\n+\twhile (str[rpos] && (escape || str[rpos] != ' ')) {\n+\t\tif (escape) {\n+\t\t\tswitch (str[rpos]) {\n+\t\t\tcase ' ':\n+\t\t\tcase '%':\n+\t\t\t\tstrbuf_addch(&ret, str[rpos]);\n+\t\t\t\tbreak;\n+\t\t\tcase 's':\n+\t\t\t\tstrbuf_addstr(&ret, service + psoff);\n+\t\t\t\tbreak;\n+\t\t\tcase 'S':\n+\t\t\t\tstrbuf_addstr(&ret, service);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tescape = 0;\n+\t\t} else\n+\t\t\tswitch (str[rpos]) {\n+\t\t\tcase '%':\n+\t\t\t\tescape = 1;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tstrbuf_addch(&ret, str[rpos]);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\trpos++;\n+\t}\n+\tswitch (special) {\n+\tcase 'G':\n+\t\tgit_req = strbuf_detach(&ret, NULL);\n+\t\treturn NULL;\n+\tcase 'V':\n+\t\tgit_req_vhost = strbuf_detach(&ret, NULL);\n+\t\treturn NULL;\n+\tdefault:\n+\t\treturn strbuf_detach(&ret, NULL);\n+\t}\n+}\n+\n+/* Should be enough... */\n+#define MAXARGUMENTS 256\n+\n+static const char **parse_argv(const char *arg, const char *service)\n+{\n+\tint arguments = 0;\n+\tint i;\n+\tconst char **ret;\n+\tchar *temparray[MAXARGUMENTS + 1];\n+\n+\twhile (*arg) {\n+\t\tchar *expanded;\n+\t\tif (arguments == MAXARGUMENTS)\n+\t\t\tdie(\"remote-ext command has too many arguments\");\n+\t\texpanded = strip_escapes(arg, service, &arg);\n+\t\tif (expanded)\n+\t\t\ttemparray[arguments++] = expanded;\n+\t}\n+\n+\tret = xmalloc((arguments + 1) * sizeof(char *));\n+\tfor (i = 0; i < arguments; i++)\n+\t\tret[i] = temparray[i];\n+\tret[arguments] = NULL;\n+\treturn ret;\n+}\n+\n+static void send_git_request(int stdin_fd, const char *serv, const char *repo,\n+\tconst char *vhost)\n+{\n+\tsize_t bufferspace;\n+\tsize_t wpos = 0;\n+\tchar *buffer;\n+\n+\t/*\n+\t * Request needs 12 bytes extra if there is vhost (xxxx \\0host=\\0) and\n+\t * 6 bytes extra (xxxx \\0) if there is no vhost.\n+\t */\n+\tif (vhost)\n+\t\tbufferspace = strlen(serv) + strlen(repo) + strlen(vhost) + 12;\n+\telse\n+\t\tbufferspace = strlen(serv) + strlen(repo) + 6;\n+\n+\tif (bufferspace > 0xFFFF)\n+\t\tdie(\"Request too large to send\");\n+\tbuffer = xmalloc(bufferspace);\n+\n+\t/* Make the packet. */\n+\twpos = sprintf(buffer, \"%04x%s %s%c\", (unsigned)bufferspace,\n+\t\tserv, repo, 0);\n+\n+\t/* Add vhost if any. */\n+\tif (vhost)\n+\t\tsprintf(buffer + wpos, \"host=%s%c\", vhost, 0);\n+\n+\t/* Send the request */\n+\tif (write_in_full(stdin_fd, buffer, bufferspace) < 0)\n+\t\tdie_errno(\"Failed to send request\");\n+\n+\tfree(buffer);\n+}\n+\n+static int run_child(const char *arg, const char *service)\n+{\n+\tint r;\n+\tstruct child_process child;\n+\n+\tmemset(&child, 0, sizeof(child));\n+\tchild.in = -1;\n+\tchild.out = -1;\n+\tchild.err = 0;\n+\tchild.argv = parse_argv(arg, service);\n+\n+\tif (start_command(&child) < 0)\n+\t\tdie(\"Can't run specified command\");\n+\n+\tif (git_req)\n+\t\tsend_git_request(child.in, service, git_req, git_req_vhost);\n+\n+\tr = bidirectional_transfer_loop(child.out, child.in);\n+\tif (!r)\n+\t\tr = finish_command(&child);\n+\telse\n+\t\tfinish_command(&child);\n+\treturn r;\n+}\n+\n+#define MAXCOMMAND 4096\n+\n+static int command_loop(const char *child)\n+{\n+\tchar buffer[MAXCOMMAND];\n+\n+\twhile (1) {\n+\t\tsize_t length;\n+\t\tif (!fgets(buffer, MAXCOMMAND - 1, stdin)) {\n+\t\t\tif (ferror(stdin))\n+\t\t\t\tdie(\"Comammand input error\");\n+\t\t\texit(0);\n+\t\t}\n+\t\t/* Strip end of line characters. */\n+\t\tlength = strlen(buffer);\n+\t\twhile (isspace((unsigned char)buffer[length - 1]))\n+\t\t\tbuffer[--length] = 0;\n+\n+\t\tif (!strcmp(buffer, \"capabilities\")) {\n+\t\t\tprintf(\"*connect\\n\\n\");\n+\t\t\tfflush(stdout);\n+\t\t} else if (!strncmp(buffer, \"connect \", 8)) {\n+\t\t\tprintf(\"\\n\");\n+\t\t\tfflush(stdout);\n+\t\t\treturn run_child(child, buffer + 8);\n+\t\t} else {\n+\t\t\tfprintf(stderr, \"Bad command\");\n+\t\t\treturn 1;\n+\t\t}\n+\t}\n+}\n+\n+int cmd_remote_ext(int argc, const char **argv, const char *prefix)\n+{\n+\tif (argc != 3)\n+\t\tdie(\"Expected two arguments\");\n+\n+\treturn command_loop(argv[2]);\n+}\ndiff --git a/git.c b/git.c\nindex f5fc07b..ab67f9f 100644\n--- a/git.c\n+++ b/git.c\n@@ -368,6 +368,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"receive-pack\", cmd_receive_pack },\n \t\t{ \"reflog\", cmd_reflog, RUN_SETUP },\n \t\t{ \"remote\", cmd_remote, RUN_SETUP },\n+\t\t{ \"remote-ext\", cmd_remote_ext },\n \t\t{ \"remote-fd\", cmd_remote_fd },\n \t\t{ \"replace\", cmd_replace, RUN_SETUP },\n \t\t{ \"repo-config\", cmd_config },\n-- \n1.7.1.336.ge601a.dirty\n"},{"id":"156058","messageId":"7vy68rg9c9.fsf@alter.siamese.dyndns.org","threadId":"25757","inReplyTo":"1289878454-17192-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v8 0/3] git-remote-fd & git-remote-ext","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-17T17:15:34Z","receivedAt":"2010-11-17T17:15:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; the changes from the last round all look sensible to me, but did\nyou know that the last round has already been in 'next' for a few weeks by\nnow already?\n\nIf you don't mind I'll turn these three into the following and queue as\n4/3 on top of what is already merged, as reverting the merge with the old\nseries and merging the new round to 'next' makes it messier than it\nalready is.\n\n-- >8 --\nFrom: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\nSubject: remote-fd/ext: finishing touches after code review\n\nWhen compiling with pthread support, transport-helper.c needs to include\nnecessary header files.  Also fix a few error messages in remote-ext and\nremote-fd programs, and a potential buffer underrun in remote-fd.\n\nIn the documentation, clarify how %G and %V are used; the old description\nlooked as if they take repository/vhost parameters, which was wrong.\n\nAlso fix AsciiDoc markup for the page title of remote-fd/remote-ext manpages,\nand tweak the way how section headers are shown.\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-remote-ext.txt |   10 +++++-----\n Documentation/git-remote-fd.txt  |   10 +++++-----\n builtin/remote-ext.c             |    8 +++-----\n builtin/remote-fd.c              |    6 +++---\n transport-helper.c               |    5 +++++\n 5 files changed, 21 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/git-remote-ext.txt b/Documentation/git-remote-ext.txt\nindex 8fb260b..f4fbf67 100644\n--- a/Documentation/git-remote-ext.txt\n+++ b/Documentation/git-remote-ext.txt\n@@ -39,20 +39,20 @@ The following sequences have a special meaning:\n \tgit-upload-pack, or git-upload-archive) of the service\n \tgit wants to invoke.\n \n-'%G<repository>' (as argument)::\n+'%G' (must be first characters in argument)::\n \tThis argument will not be passed to 'program'. Instead, it\n \twill cause helper to start by sending git:// service request to\n \tremote side with service field set to approiate value and\n-\trepository field set to <repository>. Default is not to send\n+\trepository field set to rest of the argument. Default is not to send\n \tsuch request.\n +\n This is useful if remote side is git:// server accessed over\n some tunnel.\n \n-'%V<host>' (as argument)::\n+'%V' (must be first characters in argument)::\n \tThis argument will not be passed to 'program'. Instead it sets\n-\tthe vhost field in git:// service request. Default is not to\n-\tsend vhost in such request (if sent).\n+\tthe vhost field in git:// service request (to rest of the argument).\n+\tDefault is not to send vhost in such request (if sent).\n \n ENVIRONMENT VARIABLES:\n ----------------------\ndiff --git a/Documentation/git-remote-fd.txt b/Documentation/git-remote-fd.txt\nindex 1c1a179..abc4944 100644\n--- a/Documentation/git-remote-fd.txt\n+++ b/Documentation/git-remote-fd.txt\n@@ -1,5 +1,5 @@\n git-remote-fd(1)\n-=================\n+================\n \n NAME\n ----\n@@ -28,13 +28,13 @@ It is assumed that any handshaking procedures have already been completed\n information to user in the URL in case that URL is displayed in some\n context.\n \n-ENVIRONMENT VARIABLES:\n-----------------------\n+ENVIRONMENT VARIABLES\n+---------------------\n GIT_TRANSLOOP_DEBUG::\n \tIf set, prints debugging information about various reads/writes.\n \n-EXAMPLES:\n----------\n+EXAMPLES\n+--------\n git fetch fd::17 master::\n \tFetch master, using file descriptor #17 to communicate with\n \tgit-upload-pack.\ndiff --git a/builtin/remote-ext.c b/builtin/remote-ext.c\nindex 1d3f1cf..1f77317 100644\n--- a/builtin/remote-ext.c\n+++ b/builtin/remote-ext.c\n@@ -142,7 +142,7 @@ static const char **parse_argv(const char *arg, const char *service)\n \tfor (i = 0; i < arguments; i++)\n \t\tret[i] = temparray[i];\n \tret[arguments] = NULL;\n-\treturn (const char **)ret;\n+\treturn ret;\n }\n \n static void send_git_request(int stdin_fd, const char *serv, const char *repo,\n@@ -239,10 +239,8 @@ static int command_loop(const char *child)\n \n int cmd_remote_ext(int argc, const char **argv, const char *prefix)\n {\n-\tif (argc < 3) {\n-\t\tfprintf(stderr, \"Error: URL missing\");\n-\t\texit(1);\n-\t}\n+\tif (argc != 3)\n+\t\tdie(\"Expected two arguments\");\n \n \treturn command_loop(argv[2]);\n }\ndiff --git a/builtin/remote-fd.c b/builtin/remote-fd.c\nindex 7517f24..1f2467b 100644\n--- a/builtin/remote-fd.c\n+++ b/builtin/remote-fd.c\n@@ -31,7 +31,7 @@ static void command_loop(int input_fd, int output_fd)\n \t\t}\n \t\t/* Strip end of line characters. */\n \t\ti = strlen(buffer);\n-\t\twhile (isspace(buffer[i - 1]))\n+\t\twhile (i > 0 && isspace(buffer[i - 1]))\n \t\t\tbuffer[--i] = 0;\n \n \t\tif (!strcmp(buffer, \"capabilities\")) {\n@@ -56,8 +56,8 @@ int cmd_remote_fd(int argc, const char **argv, const char *prefix)\n \tint output_fd = -1;\n \tchar *end;\n \n-\tif (argc < 3)\n-\t\tdie(\"URL missing\");\n+\tif (argc != 3)\n+\t\tdie(\"Expected two arguments\");\n \n \tinput_fd = (int)strtoul(argv[2], &end, 10);\n \ndiff --git a/transport-helper.c b/transport-helper.c\nindex 0c094d6..3a50856 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -9,6 +9,11 @@\n #include \"remote.h\"\n #include \"string-list.h\"\n \n+#ifndef NO_PTHREADS\n+#include <pthread.h>\n+#include \"thread-utils.h\"\n+#endif\n+\n static int debug;\n \n struct helper_data\n"},{"id":"156077","messageId":"20101118023104.GA28255@LK-Perkele-V2.elisa-laajakaista.fi","threadId":"25757","inReplyTo":"7vy68rg9c9.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v8 0/3] git-remote-fd & git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-11-18T02:31:04Z","receivedAt":"2010-11-18T02:31:04Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"On Wed, Nov 17, 2010 at 09:15:34AM -0800, Junio C Hamano wrote:\n> Thanks; the changes from the last round all look sensible to me, but did\n> you know that the last round has already been in 'next' for a few weeks by\n> now already?\n\nOops... Sorry. :-/\n \n> If you don't mind I'll turn these three into the following and queue as\n> 4/3 on top of what is already merged, as reverting the merge with the old\n> series and merging the new round to 'next' makes it messier than it\n> already is.\n\nI tested applying that patch. Doesn't seem to break things at least code-\nwise (no surprise, it only adds headers and adds one conditional that only\nevaluates to false on invalid input).\n\nSo I don't mind applying that patch. Acking the patch.\n\n-Ilari\n"}]}