Skip to contentSkip to conversation

git-remote-fd & git-remote-ext

RFC PATCH Superseded Ilari Liusvaara 3 participants 7 messages Jun 15, 2016

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover git-remote-fd & git-remote-ext

This adds two new remote helpers.

* git-remote-fd, which connects to git service on given file descriptor(s), useful for graphical user interfaces that want to use internal ssh client.

* git-remote-ext, which connect to git service using external program. Useful for connecting using odd one-off ssh options, to services in abstract namespace, using unix domain sockets, using TLS, etc...

Changes from last time:
* Some misc cleanups.
* Fix bug in transfer loop that manifests when remote end is socket and tasks are implemented as processes.

Ilari Liusvaara (3):
Add bidirectional_transfer_loop()
git-remote-fd
git-remote-ext

 .gitignore                       |    2 +
 Documentation/git-remote-ext.txt |  125 +++++++++++++++
 Documentation/git-remote-fd.txt  |   59 +++++++
 Makefile                         |    2 +
 builtin.h                        |    2 +
 builtin/remote-ext.c             |  248 ++++++++++++++++++++++++++++++
 builtin/remote-fd.c              |   79 ++++++++++
 compat/mingw.h                   |    5 +
 git.c                            |    2 +
 transport-helper.c               |  311 ++++++++++++++++++++++++++++++++++++++
 transport.h                      |    1 +
 11 files changed, 836 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/git-remote-ext.txt
 create mode 100644 Documentation/git-remote-fd.txt
 create mode 100644 builtin/remote-ext.c
 create mode 100644 builtin/remote-fd.c
Signature · 1 line
1.7.3.1.53.g597b29.dirty
#1 lore raw

RFC PATCH v7 1/3 Add bidirectional_transfer_loop()

This helper function copies bidirectional stream of data between stdin/stdout and specified file descriptors.

---
 compat/mingw.h     |    5 +
 transport-helper.c |  311 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 transport.h        |    1 +
 3 files changed, 317 insertions(+), 0 deletions(-)
compat/mingw.h +5 -0
index 3b2477b..f27a7b6 100644
@@ -23,6 +23,9 @@ typedef int pid_t;
 #define WEXITSTATUS(x) ((x) & 0xff)
 #define WTERMSIG(x) SIGTERM
 
+#define EWOULDBLOCK EAGAIN
+#define SHUT_WR SD_SEND
+
 #define SIGHUP 1
 #define SIGQUIT 3
 #define SIGKILL 9
@@ -50,6 +53,8 @@ struct pollfd {
 };
 #define POLLIN 1
 #define POLLHUP 2
+#define POLLOUT 4
+#define POLLNVAL 8
 #endif
 
 typedef void (__cdecl *sig_handler_t)(int);
transport-helper.c +311 -0

314 lines not on this page · raw message

transport.h +1 -0
index c59d973..e803c0e 100644
@@ -154,6 +154,7 @@ int transport_connect(struct transport *transport, const char *name,
 
 /* Transport methods defined outside transport.c */
 int transport_helper_init(struct transport *transport, const char *name);
+int bidirectional_transfer_loop(int input, int output);
 
 /* common methods used by transport.c and builtin-send-pack.c */
 void transport_verify_remote_names(int nr_heads, const char **heads);
Signature · 1 line
1.7.3.1.53.g597b29.dirty
#2 lore raw

RFC PATCH v7 2/3 git-remote-fd

In reply to Ilari Liusvaara

This remote helper reflects raw smart remote transport stream back to the calling program. This is useful for example if some UI wants to handle ssh itself and not use hacks via GIT_SSH.

---
 .gitignore                      |    1 +
 Documentation/git-remote-fd.txt |   59 +++++++++++++++++++++++++++++
 Makefile                        |    1 +
 builtin.h                       |    1 +
 builtin/remote-fd.c             |   79 +++++++++++++++++++++++++++++++++++++++
 git.c                           |    1 +
 6 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/git-remote-fd.txt
 create mode 100644 builtin/remote-fd.c
.gitignore +1 -0
index 20560b8..89f37f4 100644
@@ -112,6 +112,7 @@
 /git-remote-https
 /git-remote-ftp
 /git-remote-ftps
+/git-remote-fd
 /git-remote-testgit
 /git-repack
 /git-replace
Documentation/git-remote-fd.txt new file +59 -0

59 lines not on this page · raw message

Makefile +1 -0
index 8a56b9a..7da54d7 100644
@@ -728,6 +728,7 @@ BUILTIN_OBJS += builtin/read-tree.o
 BUILTIN_OBJS += builtin/receive-pack.o
 BUILTIN_OBJS += builtin/reflog.o
 BUILTIN_OBJS += builtin/remote.o
+BUILTIN_OBJS += builtin/remote-fd.o
 BUILTIN_OBJS += builtin/replace.o
 BUILTIN_OBJS += builtin/rerere.o
 BUILTIN_OBJS += builtin/reset.o
builtin.h +1 -0
index f2a25a0..1a816e1 100644
@@ -108,6 +108,7 @@ extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
 extern int cmd_reflog(int argc, const char **argv, const char *prefix);
 extern int cmd_remote(int argc, const char **argv, const char *prefix);
+extern int cmd_remote_fd(int argc, const char **argv, const char *prefix);
 extern int cmd_config(int argc, const char **argv, const char *prefix);
 extern int cmd_rerere(int argc, const char **argv, const char *prefix);
 extern int cmd_reset(int argc, const char **argv, const char *prefix);
builtin/remote-fd.c new file +79 -0

79 lines not on this page · raw message

git.c +1 -0
index 50a1401..b7b96b0 100644
@@ -374,6 +374,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "receive-pack", cmd_receive_pack },
 		{ "reflog", cmd_reflog, RUN_SETUP },
 		{ "remote", cmd_remote, RUN_SETUP },
+		{ "remote-fd", cmd_remote_fd },
 		{ "replace", cmd_replace, RUN_SETUP },
 		{ "repo-config", cmd_config, RUN_SETUP_GENTLY },
 		{ "rerere", cmd_rerere, RUN_SETUP },
Signature · 1 line
1.7.3.1.53.g597b29.dirty
#3 lore raw

Re: [RFC PATCH v7 2/3] git-remote-fd

Documentation/git-remote-fd.txt line 2

Quoted 8 lines · Ilari Liusvaara
Documentation/git-remote-fd.txt new file +2 -0
new file mode 100644
index 0000000..1c1a179
@@ -0,0 +1,59 @@
+git-remote-fd(1)
+=================

It appears to me that it has one equal sign too many. Does this format correctly?

Documentation/git-remote-fd.txt line 32

Quoted 2 lines
Documentation/git-remote-fd.txt new file +2 -0
+ENVIRONMENT VARIABLES:
+----------------------

I didn't follow the discussion closely but I recall somebody saying that the final colon is out of place, and I think I agree.

Documentation/git-remote-fd.txt line 37

Quoted 2 lines
Documentation/git-remote-fd.txt new file +2 -0
+EXAMPLES:
+---------

Likewise.

Quoted 31 lines
builtin/remote-fd.c new file +25 -0
new file mode 100644
index 0000000..7517f24
@@ -0,0 +1,79 @@
+#include "git-compat-util.h"
+#include "transport.h"
+
+/*
+ * URL syntax:
+ *	'fd::<inoutfd>[/<anything>]'		Read/write socket pair
+ *						<inoutfd>.
+ *	'fd::<infd>,<outfd>[/<anything>]'	Read pipe <infd> and write
+ *						pipe <outfd>.
+ *	[foo] indicates 'foo' is optional. <anything> is any string.
+ *
+ * The data output to <outfd>/<inoutfd> should be passed unmolested to
+ * git-receive-pack/git-upload-pack/git-upload-archive and output of
+ * git-receive-pack/git-upload-pack/git-upload-archive should be passed
+ * unmolested to <infd>/<inoutfd>.
+ *
+ */
+
+#define MAXCOMMAND 4096
+
+static void command_loop(int input_fd, int output_fd)
+{
+	char buffer[MAXCOMMAND];
+
+	while (1) {

builtin/remote-fd.c line 35

Quoted 10 lines
builtin/remote-fd.c new file +10 -0
+		size_t i;
+		if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
+			if (ferror(stdin))
+				die("Input error");
+			return;
+		}
+		/* Strip end of line characters. */
+		i = strlen(buffer);
+		while (isspace(buffer[i - 1]))
+			buffer[--i] = 0;

Hopefully you won't get a line with all space, going beyond the beginning of the buffer?

builtin/remote-fd.c line 60

Quoted 8 lines
builtin/remote-fd.c new file +8 -0
+int cmd_remote_fd(int argc, const char **argv, const char *prefix)
+{
+	int input_fd = -1;
+	int output_fd = -1;
+	char *end;
+
+	if (argc < 3)
+		die("URL missing");

Is it Ok to have excess arguments to be ignored?

#4 lore raw

RFC PATCH v7 3/3 git-remote-ext

In reply to Ilari Liusvaara

This remote helper invokes external command and passes raw smart transport stream through it. This is useful for instance for invoking ssh with one-off odd options, connecting to git services in unix domain sockets, in abstract namespace, using TLS or other secure protocols, etc...

---
 .gitignore                       |    1 +
 Documentation/git-remote-ext.txt |  125 +++++++++++++++++++
 Makefile                         |    1 +
 builtin.h                        |    1 +
 builtin/remote-ext.c             |  248 ++++++++++++++++++++++++++++++++++++++
 git.c                            |    1 +
 6 files changed, 377 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/git-remote-ext.txt
 create mode 100644 builtin/remote-ext.c
.gitignore +1 -0
index 89f37f4..87b833c 100644
@@ -113,6 +113,7 @@
 /git-remote-ftp
 /git-remote-ftps
 /git-remote-fd
+/git-remote-ext
 /git-remote-testgit
 /git-repack
 /git-replace
Documentation/git-remote-ext.txt new file +125 -0

125 lines not on this page · raw message

Makefile +1 -0
index 7da54d7..9909ca1 100644
@@ -728,6 +728,7 @@ BUILTIN_OBJS += builtin/read-tree.o
 BUILTIN_OBJS += builtin/receive-pack.o
 BUILTIN_OBJS += builtin/reflog.o
 BUILTIN_OBJS += builtin/remote.o
+BUILTIN_OBJS += builtin/remote-ext.o
 BUILTIN_OBJS += builtin/remote-fd.o
 BUILTIN_OBJS += builtin/replace.o
 BUILTIN_OBJS += builtin/rerere.o
builtin.h +1 -0
index 1a816e1..a4bba61 100644
@@ -108,6 +108,7 @@ extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
 extern int cmd_reflog(int argc, const char **argv, const char *prefix);
 extern int cmd_remote(int argc, const char **argv, const char *prefix);
+extern int cmd_remote_ext(int argc, const char **argv, const char *prefix);
 extern int cmd_remote_fd(int argc, const char **argv, const char *prefix);
 extern int cmd_config(int argc, const char **argv, const char *prefix);
 extern int cmd_rerere(int argc, const char **argv, const char *prefix);
builtin/remote-ext.c new file +248 -0

248 lines not on this page · raw message

git.c +1 -0
index b7b96b0..e95a1ba 100644
@@ -374,6 +374,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "receive-pack", cmd_receive_pack },
 		{ "reflog", cmd_reflog, RUN_SETUP },
 		{ "remote", cmd_remote, RUN_SETUP },
+		{ "remote-ext", cmd_remote_ext },
 		{ "remote-fd", cmd_remote_fd },
 		{ "replace", cmd_replace, RUN_SETUP },
 		{ "repo-config", cmd_config, RUN_SETUP_GENTLY },
Signature · 1 line
1.7.3.1.53.g597b29.dirty
#5 lore raw

Re: [RFC PATCH v7 3/3] git-remote-ext

Quoted 4 lines · Ilari Liusvaara

+'%G<repository>' (as argument)::

Documentation/git-remote-ext.txt new file +3 -0
+	This argument will not be passed to 'program'. Instead, it
+	will cause helper to start by sending git:// service request to
+	remote side with service field set to approiate value and

Documentation/git-remote-ext.txt line 55

Quoted 10 lines
Documentation/git-remote-ext.txt new file +10 -0
+	repository field set to <repository>. Default is not to send
+	such request.
++
+This is useful if remote side is git:// server accessed over
+some tunnel.
+
+'%V<host>' (as argument)::
+	This argument will not be passed to 'program'. Instead it sets
+	the vhost field in git:// service request. Default is not to
+	send vhost in such request (if sent).

The above does not say anything about being the first 'character' in an argument, like the in-code comment does. Is that intended?

Quoted 12 lines
builtin/remote-ext.c new file +12 -0
+static const char **parse_argv(const char *arg, const char *service)
+{
+	int arguments = 0;
+	int i;
+	const char **ret;
+	char *temparray[MAXARGUMENTS + 1];
+
+	while (*arg) {
+		char *expanded;
+		if (arguments == MAXARGUMENTS)
+			die("remote-ext command has too many arguments");
+		expanded = strip_escapes(arg, service, &arg);

builtin/remote-ext.c line 146

Quoted 10 lines
builtin/remote-ext.c new file +10 -0
+		if (expanded)
+			temparray[arguments++] = expanded;
+	}
+
+	ret = xmalloc((arguments + 1) * sizeof(char *));
+	for (i = 0; i < arguments; i++)
+		ret[i] = temparray[i];
+	ret[arguments] = NULL;
+	return (const char **)ret;
+}

Isn't "ret" declared to be of that type?

#6 lore raw

PATCH 1/1 remote-ext: do not segfault for blank lines

In reply to Ilari Liusvaara

Instead of stripping space characters past the beginning of the line and overflowing a buffer, stop at the beginning of the line (mimicking the corresponding fix in remote-fd).

The argument to isspace does not need to be cast explicitly because git isspace takes care of that already.

---
 builtin/remote-ext.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
builtin/remote-ext.c +4 -4
index 1f77317..ea71977 100644
@@ -212,16 +212,16 @@ static int command_loop(const char *child)
 	char buffer[MAXCOMMAND];
 
 	while (1) {
-		size_t length;
+		size_t i;
 		if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
 			if (ferror(stdin))
 				die("Comammand input error");
 			exit(0);
 		}
 		/* Strip end of line characters. */
-		length = strlen(buffer);
-		while (isspace((unsigned char)buffer[length - 1]))
-			buffer[--length] = 0;
+		i = strlen(buffer);
+		while (i > 0 && isspace(buffer[i - 1]))
+			buffer[--i] = 0;
 
 		if (!strcmp(buffer, "capabilities")) {
 			printf("*connect\n\n");
Signature · 1 line
1.7.4.rc2