{"thread":{"id":"25334","subject":"[PATCH v4 0/3] git-remote-fd & git-remote-ext","startedAt":"2010-10-04T11:04:15Z","lastAt":"2010-10-07T05:55:35Z","messageCount":13,"participants":["Ilari Liusvaara","Jonathan Nieder","Sverre Rabbelier","Junio C Hamano","yj2133011"],"isPatch":true,"patchVersion":4,"patchTotal":3},"messages":[{"id":"152509","messageId":"1286190258-12724-1-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25334","inReplyTo":null,"subject":"[PATCH v4 0/3] git-remote-fd & git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-10-04T11:04:15Z","receivedAt":"2010-10-04T11:04:15Z","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* Refactor the transfer loop quite a bit.\n* Change the \"format character\" in remote-ext from '\\' to '%'.\n* Some code changes in remote-fd.\n* Documentation changes for remote-fd.\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 |  119 ++++++++++++++\n Documentation/git-remote-fd.txt  |   59 +++++++\n Makefile                         |    2 +\n builtin.h                        |    2 +\n builtin/remote-ext.c             |  243 ++++++++++++++++++++++++++++\n builtin/remote-fd.c              |   80 ++++++++++\n compat/mingw.h                   |    5 +\n git.c                            |    2 +\n transport-helper.c               |  324 ++++++++++++++++++++++++++++++++++++++\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\n-- \n1.7.3.1.48.g63ac7.dirty\n"},{"id":"152511","messageId":"1286190258-12724-2-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25334","inReplyTo":"1286190258-12724-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH v4 1/3] Add bidirectional_transfer_loop()","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-10-04T11:04:16Z","receivedAt":"2010-10-04T11:04:16Z","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 |  324 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n transport.h        |    1 +\n 3 files changed, 330 insertions(+), 0 deletions(-)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 3b2477b..f27a7b6 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 acfc88e..1f7bad6 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -862,3 +862,327 @@ 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+{\n+\t/* Source */\n+\tint src;\n+\t/* Destination */\n+\tint dest;\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+static int udt_can_read(struct unidirectional_transfer *t)\n+{\n+\treturn (STATE_NEEDS_READING(t->state) && t->bufuse < BUFFERSIZE);\n+}\n+\n+static int udt_can_write(struct unidirectional_transfer *t)\n+{\n+\treturn (STATE_NEEDS_WRITING(t->state) && t->bufuse > 0);\n+}\n+\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+static int udt_do_read(struct unidirectional_transfer *t)\n+{\n+\tint r;\n+\ttransfer_debug(\"%s is readable\", t->src_name);\n+\tr = read(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse);\n+\tif (r < 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 (r == 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 (r > 0) {\n+\t\tt->bufuse += r;\n+\t\ttransfer_debug(\"Read %i bytes from %s (buffer now at %i)\",\n+\t\t\tr, t->src_name, (int)t->bufuse);\n+\t}\n+\treturn 0;\n+}\n+\n+static int udt_do_write(struct unidirectional_transfer *t)\n+{\n+\tint r;\n+\ttransfer_debug(\"%s is writable\", t->dest_name);\n+\tr = write(t->dest, t->buf, t->bufuse);\n+\tif (r < 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 (r > 0) {\n+\t\tt->bufuse -= r;\n+\t\tif(t->bufuse)\n+\t\t\tmemmove(t->buf, t->buf + r, t->bufuse);\n+\t\ttransfer_debug(\"Wrote %i bytes to %s (buffer now at %i)\",\n+\t\t\tr, t->dest_name, (int)t->bufuse);\n+\t}\n+\treturn 0;\n+}\n+\n+/* State of bidirectional transfer loop. */\n+struct bidirectional_transfer_state\n+{\n+\t/*\n+\t * Current polls. Up to 4 because both read and write for both\n+\t * directions possibly needs to poll, and all of these may occur\n+\t * at once.\n+\t */\n+\tstruct pollfd polls[4];\n+\t/* Number of polls active. */\n+\tint polls_active;\n+\t/* Index for stdin in poll array, -1 if none. */\n+\tint stdin_index;\n+\t/* Index for stdout in poll array, -1 if none. */\n+\tint stdout_index;\n+\t/* Index for input descriptor in poll array, -1 if none. */\n+\tint input_index;\n+\t/* Index for output descrptor in poll array, -1 if none. */\n+\tint output_index;\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+/*\n+ * Allocate individual poll array entry.\n+ * polls -> The polls array. Must have at least *active + 1 entries.\n+ * active -> Place for number of active polls. Value in this location is\n+ * incremented.\n+ * index -> Place to store index for newly allocated entry.\n+ * fd -> The file descriptor to place there.\n+ * name -> Name for fd to print. If NULL, no message is printed.\n+ */\n+static void allocate_poll_array_entry(struct pollfd* polls, int* active,\n+\tint* index, int fd, const char* name)\n+{\n+\t*index = (*active)++;\n+\tpolls[*index].fd = fd;\n+\tif (name)\n+\t\ttransfer_debug(\"Adding %s to fds to wait for...\", name);\n+}\n+\n+\n+/* Allocate indexes for file descriptors in poll array. */\n+static void allocate_poll_indexes(struct bidirectional_transfer_state* s)\n+{\n+\t/* Initialize fields like there was nothing waiting. */\n+\ts->stdin_index = -1;\n+\ts->stdout_index = -1;\n+\ts->input_index = -1;\n+\ts->output_index = -1;\n+\ts->polls_active = 0;\n+\n+\tif (udt_can_read(&s->ptg))\n+\t\tallocate_poll_array_entry(s->polls, &s->polls_active,\n+\t\t\t&s->input_index, s->ptg.src, s->ptg.src_name);\n+\tif (udt_can_write(&s->ptg))\n+\t\tallocate_poll_array_entry(s->polls, &s->polls_active,\n+\t\t\t&s->stdout_index, s->ptg.dest, s->ptg.dest_name);\n+\tif (udt_can_read(&s->gtp))\n+\t\tallocate_poll_array_entry(s->polls, &s->polls_active,\n+\t\t\t&s->stdin_index, s->gtp.src, s->gtp.src_name);\n+\tif (udt_can_write(&s->gtp)) {\n+\t\tif (s->gtp.dest == s->ptg.src && s->input_index >= 0)\n+\t\t\ts->output_index = s->input_index;\n+\t\telse\n+\t\t\tallocate_poll_array_entry(s->polls, &s->polls_active,\n+\t\t\t\t&s->output_index, s->gtp.dest,\n+\t\t\t\ts->gtp.dest_name);\n+\t\ttransfer_debug(\"Adding %s to fds to wait for\",\n+\t\t\ts->gtp.dest_name);\n+\t}\n+}\n+\n+/*\n+ * Set specified event flags for specified poll array entry if index is\n+ * valid. If msg is not null, it is printed as debug message.\n+ */\n+static void mark_for_wait(struct pollfd* polls, int index, int flags,\n+\tconst char* msg)\n+{\n+\tif (index < 0)\n+\t\treturn;\t\t/* Index not in use. */\n+\tpolls[index].events |= flags;\n+\ttransfer_debug(\"Setting fd wait flags: fd=%i, flags=%i, index=%i\",\n+\t\tpolls[index].fd, flags, index);\n+\tif (msg)\n+\t\ttransfer_debug(\"%s\", msg);\n+}\n+\n+/*\n+ * Load the parameters into poll array and related fields based on rest of\n+ * fields.\n+ */\n+static void load_poll_params(struct bidirectional_transfer_state* s)\n+{\n+\tint i;\n+\n+\tallocate_poll_indexes(s);\n+\tfor (i = 0; i < s->polls_active; i++)\n+\t\ts->polls[i].events = s->polls[i].revents = 0;\n+\n+\tmark_for_wait(s->polls, s->stdin_index, POLLIN,\n+\t\t\"Waiting for stdin to become readable\");\n+\tmark_for_wait(s->polls, s->input_index, POLLIN,\n+\t\t\"Waiting for remote input to become readable\");\n+\tmark_for_wait(s->polls, s->stdout_index, POLLOUT,\n+\t\t\"Waiting for stdout to become writable\");\n+\tmark_for_wait(s->polls, s->output_index, POLLOUT,\n+\t\t\"Waiting for remote output to become writable\");\n+}\n+\n+/* Call handler if ready. */\n+static int call_handler_if(int r, struct bidirectional_transfer_state* s,\n+\tint index, int flagmask, const char* name,\n+\tint (*on_ready)(struct unidirectional_transfer *t),\n+\tstruct unidirectional_transfer *transfer)\n+{\n+\tif(r)\n+\t\treturn r;\n+\tif(index < 0)\n+\t\treturn 0;\t\t/* This is not being waited. */\n+\tif(s->polls[index].revents & POLLNVAL) {\n+\t\terror(\"%s got unexpectedly closed\", name);\n+\t\treturn -1;\n+\t}\n+\tif(!(s->polls[index].revents & flagmask))\n+\t\treturn 0;\t\t/* No events returned. */\n+\treturn on_ready(transfer);\n+}\n+\n+/* Handle events occured during poll. Returns -1 on error, 0 on success. */\n+static int transfer_handle_events(struct bidirectional_transfer_state* s)\n+{\n+\tint r = 0;\n+\tr = call_handler_if(r, s, s->stdin_index, POLLIN | POLLHUP,\n+\t\ts->gtp.src_name, udt_do_read, &s->gtp);\n+\tr = call_handler_if(r, s, s->input_index, POLLIN | POLLHUP,\n+\t\ts->ptg.src_name, udt_do_read, &s->ptg);\n+\tr = call_handler_if(r, s, s->output_index, POLLOUT,\n+\t\ts->gtp.dest_name, udt_do_write, &s->gtp);\n+\tr = call_handler_if(r, s, s->stdout_index, POLLOUT,\n+\t\ts->ptg.dest_name, udt_do_write, &s->ptg);\n+\tudt_close_if_finished(&s->ptg);\n+\tudt_close_if_finished(&s->gtp);\n+\treturn r;\n+}\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.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.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+\twhile (1) {\n+\t\tint r;\n+\t\tload_poll_params(&state);\n+\t\tif (!state.polls_active) {\n+\t\t\ttransfer_debug(\"Transfer done\");\n+\t\t\tbreak;\n+\t\t}\n+\t\ttransfer_debug(\"Waiting for %i file descriptors\",\n+\t\t\tstate.polls_active);\n+\t\tr = poll(state.polls, state.polls_active, -1);\n+\t\tif (r < 0) {\n+\t\t\tif (errno == EWOULDBLOCK || errno == EAGAIN ||\n+\t\t\t\terrno == EINTR)\n+\t\t\t\tcontinue;\n+\t\t\terror(\"poll failed: %s\", strerror(errno));\n+\t\t\treturn -1;\n+\t\t} else if (r == 0)\n+\t\t\tcontinue;\n+\n+\t\tr = transfer_handle_events(&state);\n+\t\tif (r)\n+\t\t\treturn r;\n+\t}\n+\treturn 0;\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.3.1.48.g63ac7.dirty\n"},{"id":"152510","messageId":"1286190258-12724-3-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25334","inReplyTo":"1286190258-12724-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH v4 2/3] git-remote-fd","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-10-04T11:04:17Z","receivedAt":"2010-10-04T11:04:17Z","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             |   80 +++++++++++++++++++++++++++++++++++++++\n git.c                           |    1 +\n 6 files changed, 143 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 20560b8..89f37f4 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..1c1a179\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 8a56b9a..7da54d7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -728,6 +728,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 f2a25a0..1a816e1 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -108,6 +108,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..bb7eadc\n--- /dev/null\n+++ b/builtin/remote-fd.c\n@@ -0,0 +1,80 @@\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+int input_fd = -1;\n+int output_fd = -1;\n+\n+#define MAXCOMMAND 4096\n+\n+static void command_loop(void)\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 (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+\tchar* end;\n+\n+\tif (argc < 3)\n+\t\tdie(\"URL missing\");\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();\n+\treturn 0;\n+}\ndiff --git a/git.c b/git.c\nindex 50a1401..b7b96b0 100644\n--- a/git.c\n+++ b/git.c\n@@ -374,6 +374,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, RUN_SETUP_GENTLY },\n \t\t{ \"rerere\", cmd_rerere, RUN_SETUP },\n-- \n1.7.3.1.48.g63ac7.dirty\n"},{"id":"152512","messageId":"1286190258-12724-4-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"25334","inReplyTo":"1286190258-12724-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH v4 3/3] git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-10-04T11:04:18Z","receivedAt":"2010-10-04T11:04:18Z","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 |  119 +++++++++++++++++++\n Makefile                         |    1 +\n builtin.h                        |    1 +\n builtin/remote-ext.c             |  243 ++++++++++++++++++++++++++++++++++++++\n git.c                            |    1 +\n 6 files changed, 366 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 89f37f4..87b833c 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..748f106\n--- /dev/null\n+++ b/Documentation/git-remote-ext.txt\n@@ -0,0 +1,119 @@\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+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<repository>' (as 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+\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+\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+\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 7da54d7..9909ca1 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -728,6 +728,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 1a816e1..a4bba61 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -108,6 +108,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..b2041ff\n--- /dev/null\n+++ b/builtin/remote-ext.c\n@@ -0,0 +1,243 @@\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+char* git_req = NULL;\n+char* git_req_vhost = NULL;\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+\tchar** ret;\n+\tchar *(temparray[MAXARGUMENTS + 1]);\n+\n+\twhile (*arg) {\n+\t\tchar* ret;\n+\t\tif (arguments == MAXARGUMENTS)\n+\t\t\tdie(\"remote-ext command has too many arguments\");\n+\t\tret = strip_escapes(arg, service, &arg);\n+\t\tif (ret)\n+\t\t\ttemparray[arguments++] = ret;\n+\t}\n+\n+\tret = xcalloc(arguments + 1, sizeof(char*));\n+\tfor (i = 0; i < arguments; i++)\n+\t\tret[i] = temparray[i];\n+\n+\treturn (const char**)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\tif (!fgets(buffer, MAXCOMMAND - 1, stdin))\n+\t\t\texit(0);\n+\t\t/* Strip end of line characters. */\n+\t\twhile (isspace((unsigned char)buffer[strlen(buffer) - 1]))\n+\t\t\tbuffer[strlen(buffer) - 1] = 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\tfprintf(stderr, \"Error: URL missing\");\n+\t\texit(1);\n+\t}\n+\n+\treturn command_loop(argv[2]);\n+}\ndiff --git a/git.c b/git.c\nindex b7b96b0..e95a1ba 100644\n--- a/git.c\n+++ b/git.c\n@@ -374,6 +374,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, RUN_SETUP_GENTLY },\n-- \n1.7.3.1.48.g63ac7.dirty\n"},{"id":"152513","messageId":"20101004111904.GC4738@burratino","threadId":"25334","inReplyTo":"1286190258-12724-2-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v4 1/3] Add bidirectional_transfer_loop()","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-04T11:19:04Z","receivedAt":"2010-10-04T11:19:04Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ilari Liusvaara wrote:\n\n> --- a/transport-helper.c\n> +++ b/transport-helper.c\n> @@ -862,3 +862,327 @@ int transport_helper_init(struct transport *transport, const char *name)\n[...]\n> +/* Unidirectional transfer. */\n> +struct unidirectional_transfer\n> +{\n> +\tint src;\n> +\tint dest;\n> +\tint dest_is_sock;\n> +\tint state;\n> +\tchar buf[BUFFERSIZE];\n> +\tsize_t bufuse;\n> +\tconst char *src_name;\n> +\tconst char *dest_name;\n> +};\n\nNice. :)\n\n(I would have written\n\n\tint src;\n\tint dest\n\tunsigned dest_is_sock:1;\n\tenum unidirectional_transfer_state state;\n\tchar buf[BUFFERSIZE];\n\t...\n\nto make the types more obvious, but I think that's more of a matter of\nstyle.)\n\n[...]\n> +/* State of bidirectional transfer loop. */\n> +struct bidirectional_transfer_state\n> +{\n> +\tstruct pollfd polls[4];\n> +\tint polls_active;\n> +\tint stdin_index;\n> +\tint stdout_index;\n> +\tint input_index;\n> +\tint output_index;\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\nSensible.\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.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.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> +\twhile (1) {\n> +\t\tint r;\n> +\t\tload_poll_params(&state);\n> +\t\tif (!state.polls_active) {\n> +\t\t\ttransfer_debug(\"Transfer done\");\n> +\t\t\tbreak;\n> +\t\t}\n> +\t\ttransfer_debug(\"Waiting for %i file descriptors\",\n> +\t\t\tstate.polls_active);\n> +\t\tr = poll(state.polls, state.polls_active, -1);\n> +\t\tif (r < 0) {\n> +\t\t\tif (errno == EWOULDBLOCK || errno == EAGAIN ||\n> +\t\t\t\terrno == EINTR)\n> +\t\t\t\tcontinue;\n> +\t\t\terror(\"poll failed: %s\", strerror(errno));\n> +\t\t\treturn -1;\n> +\t\t} else if (r == 0)\n> +\t\t\tcontinue;\n> +\n> +\t\tr = transfer_handle_events(&state);\n> +\t\tif (r)\n> +\t\t\treturn r;\n> +\t}\n> +\treturn 0;\n> +}\n\nYes, that's much clearer.\n\nLinux's scripts/checkpatch.pl would have a few things to say, but\nI have no complaint myself except the density of comments (which is a\nmatter of taste).\n\nThanks!\n"},{"id":"152514","messageId":"20101004112556.GD4738@burratino","threadId":"25334","inReplyTo":"1286190258-12724-3-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v4 2/3] git-remote-fd","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-04T11:25:56Z","receivedAt":"2010-10-04T11:25:56Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ilari Liusvaara wrote:\n\n> --- /dev/null\n> +++ b/Documentation/git-remote-fd.txt\n\nMuch clearer.  The synopsis still does not make me happy; the synopsis\nI suggested did not make me happy, either.  Some section headers still\nhave trailing colons but I'm not convinced that's worth the overhead\nto fix.\n\n> --- /dev/null\n> +++ b/builtin/remote-fd.c\n\nLooks good.  Probably input_fd and output_fd should be static ---\nJunio, can you fix that up?  And now that the documentation makes it\nclear this is only for fetch, push, and archive, I guess I am not so\nworried about the interface any more.\n"},{"id":"152515","messageId":"20101004113043.GE4738@burratino","threadId":"25334","inReplyTo":"1286190258-12724-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v4 0/3] git-remote-fd & git-remote-ext","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-04T11:30:43Z","receivedAt":"2010-10-04T11:30:43Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ilari Liusvaara wrote:\n\n> This adds two new remote helpers.\n\nLooks good to me.  I assume you've checked it still works. :)\n"},{"id":"152518","messageId":"20101004120643.GA12948@LK-Perkele-V2.elisa-laajakaista.fi","threadId":"25334","inReplyTo":"20101004113043.GE4738@burratino","subject":"Re: [PATCH v4 0/3] git-remote-fd & git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-10-04T12:06:43Z","receivedAt":"2010-10-04T12:06:43Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"On Mon, Oct 04, 2010 at 06:30:43AM -0500, Jonathan Nieder wrote:\n> Ilari Liusvaara wrote:\n> \n> > This adds two new remote helpers.\n> \n> Looks good to me.  I assume you've checked it still works. :)\n\nYeah, it does:\n\n[Ilari@<...>:~/repositories/git(remote-fd)]$ git push -f hostmirror remote-fd \nCounting objects: 27, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100% (20/20), done.\nWriting objects: 100% (20/20), 6.80 KiB, done.\nTotal 20 (delta 14), reused 0 (delta 0)\nTo ext::socat - ABSTRACT-CONNECT:/tmp/gits %G/Ilari/git-mirror\n + 63ac78b...ae35921 remote-fd -> remote-fd (forced update)\n\n[Ilari@<...>:~/repositories/git(remote-fd)]$ git push fd::3,4 master 4>/tmp/fin 3</tmp/fout\nCounting objects: 101805, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100% (29579/29579), done.\nWriting objects: 100% (101805/101805), 24.74 MiB | 22.43 MiB/s, done.\nTotal 101805 (delta 74164), reused 98023 (delta 70709)\nTo fd::3,4\n * [new branch]      master -> master\n\n[Ilari@<...>:~/repositories/git(remote-fd)]$ git ls-remote 'ext::git-ssl localhost Ilari/git-mirror' refs/heads/*\ndepth=1 <...>\nverify return:1\ndepth=0 <...>\nverify return:1\n3b4609d029e2db42b5154f019facecee49196bf0        refs/heads/html\n2f76919517e98bb5e979d6c8c7bbc3478a066a21        refs/heads/maint\nb43f48fc1c841a29db0817c726e3d3beb17d4ba0        refs/heads/man\n9855b08d35edf8a8a441f24ff7b00e220a29f261        refs/heads/master\n92b87a9bab1a84261d2381e813e58577967bdc79        refs/heads/next\ncfe4082cb3c8db8eb0fe2fd67221a1076d0ace9b        refs/heads/pu\nae35921b925cce12a57f237cb627b4673e7c1032        refs/heads/remote-fd\n9551e394549d4526054f8b8d3e05f9bf1cd818ce        refs/heads/todo\n\n\n-Ilari\n"},{"id":"299182","messageId":"1286195325563-5598911.post@n2.nabble.com","threadId":"25334","inReplyTo":"1286190258-12724-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v4 0/3] git-remote-fd & git-remote-ext","fromName":"yj2133011","fromEmail":"274040551@qq.com","sentAt":"2010-10-04T12:28:45Z","receivedAt":"2010-10-04T12:28:45Z","isPatch":true,"sender":{"key":"274040551@qq.com","avatar":null},"body":"\nWrite good cheer, host.\n\n\n--------------------------------------------------------\nThis \nhttp://www.tomtop.com/black-remote-controller-charger2x-2800mah-battery-packs-for-wii_p11124.html?aid=z\nWii Charger  looks good n stylish. It lights up all blue which made me think\nthis is good. Get a \nhttp://www.tomtop.com/mini-bluetooth-keyboard-for-ps3-mac-os-android-pc-pda.html?aid=z\nWireless Keyboard  and mouse combo for your computer workstation and reduce\ndesktop clutter.\n\n-----\nThe voice input and output is very good in this \nhttp://www.tomtop.com/black-ps3-wireless-bluetooth-headset-for-playstation-3.html?aid=z\nWireless PS3 Headset . It is compatible with all PS3 games.Buy from Reliable \nhttp://www.tomtop.com/google-android-7-notebook-3g-tablet-pc-umpc-wifi-mid-pda.html?aid=z\nGoogle Android PC  apad Wholesalers.\n-- \nView this message in context: http://git.661346.n2.nabble.com/PATCH-v4-0-3-git-remote-fd-git-remote-ext-tp5598634p5598911.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"152544","messageId":"AANLkTikenkhm0RJR0ovVyY9WLHtwWo+qQsyAhFDk=BO2@mail.gmail.com","threadId":"25334","inReplyTo":"1286190258-12724-4-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v4 3/3] git-remote-ext","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-10-04T16:56:24Z","receivedAt":"2010-10-04T16:56:24Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, Oct 4, 2010 at 13:04, Ilari Liusvaara\n<ilari.liusvaara@elisanet.fi> wrote:\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\nMuch better! I was hesitant about this patch in earlier iterations\nbecause I didn't understand it's purpose, but with these examples it\nmakes much more sense.\n\n\n> +\"ext::git-server-alias foo %G/repo %Vfoo\"::\n> +       Represents a repository with path /repo accessed using the\n> +       helper program \"git-server-alias foo\".  The hostname for the\n> +       remote server passed in the protocol stream will be \"foo\"\n> +       (this allows multiple virtual git servers to share a\n> +       link-level address).\n\nCan you explain better what the 'git-server-alias' helper is supposed to do?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"152558","messageId":"AANLkTinW1cZzYACcHBqCTCJ6pybW3UnqQuY-6CcMgJCx@mail.gmail.com","threadId":"25334","inReplyTo":"20101004181133.GA14661@LK-Perkele-V2.elisa-laajakaista.fi","subject":"Re: [PATCH v4 3/3] git-remote-ext","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-10-04T18:09:03Z","receivedAt":"2010-10-04T18:09:03Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, Oct 4, 2010 at 20:11, Ilari Liusvaara\n<ilari.liusvaara@elisanet.fi> wrote:\n> Connect its stdin and stdout to git://-type server somewhere. It might\n> be that the actual address of server is variable depending on network\n> conditions, the connection is tunneled somehow, etc..\n\nSGTM, can you add that to the doc somewhere?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"152555","messageId":"20101004181133.GA14661@LK-Perkele-V2.elisa-laajakaista.fi","threadId":"25334","inReplyTo":"AANLkTikenkhm0RJR0ovVyY9WLHtwWo+qQsyAhFDk=BO2@mail.gmail.com","subject":"Re: [PATCH v4 3/3] git-remote-ext","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-10-04T18:11:33Z","receivedAt":"2010-10-04T18:11:33Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"On Mon, Oct 04, 2010 at 06:56:24PM +0200, Sverre Rabbelier wrote:\n> \n> > +\"ext::git-server-alias foo %G/repo %Vfoo\"::\n> > +       Represents a repository with path /repo accessed using the\n> > +       helper program \"git-server-alias foo\".  The hostname for the\n> > +       remote server passed in the protocol stream will be \"foo\"\n> > +       (this allows multiple virtual git servers to share a\n> > +       link-level address).\n> \n> Can you explain better what the 'git-server-alias' helper is supposed to do?\n\nConnect its stdin and stdout to git://-type server somewhere. It might\nbe that the actual address of server is variable depending on network\nconditions, the connection is tunneled somehow, etc..\n\n-Ilari\n"},{"id":"152848","messageId":"7v7hhuy2aw.fsf@alter.siamese.dyndns.org","threadId":"25334","inReplyTo":"20101004112556.GD4738@burratino","subject":"Re: [PATCH v4 2/3] git-remote-fd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-07T05:55:35Z","receivedAt":"2010-10-07T05:55:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Looks good.  Probably input_fd and output_fd should be static ---\n> Junio, can you fix that up?  And now that the documentation makes it\n> clear this is only for fetch, push, and archive, I guess I am not so\n> worried about the interface any more.\n\nDone, unfortunately along with quite a lot of style violation fixes...\n"}]}