Skip to contentSkip to conversation

protocol transition

PATCH Superseded Brandon Williams 10 participants 161 messages Sep 13, 2017 – Nov 17, 2017 Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#125 lore raw

PATCH 2/5 connect: split ssh command line options into separate function

In reply to Jonathan Nieder

The git_connect function is growing long. Split the portion that discovers an ssh command and options it accepts before the service name and path to a separate function to make it easier to read.

No functional change intended.

---
As before, except for the Reviewed-by.

 connect.c | 116 +++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 61 insertions(+), 55 deletions(-)
connect.c +61 -55
index 068e70caad..77ab6db3bb 100644
@@ -908,6 +908,65 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
 	return conn;
 }
 
+/* Prepare a child_process for use by Git's SSH-tunneled transport. */
+static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
+			  const char *port, int flags)
+{
+	const char *ssh;
+	enum ssh_variant variant;
+
+	if (looks_like_command_line_option(ssh_host))
+		die("strange hostname '%s' blocked", ssh_host);
+
+	ssh = get_ssh_command();
+	if (ssh) {
+		variant = determine_ssh_variant(ssh, 1);
+	} else {
+		/*
+		 * GIT_SSH is the no-shell version of
+		 * GIT_SSH_COMMAND (and must remain so for
+		 * historical compatibility).
+		 */
+		conn->use_shell = 0;
+
+		ssh = getenv("GIT_SSH");
+		if (!ssh)
+			ssh = "ssh";
+		variant = determine_ssh_variant(ssh, 0);
+	}
+
+	argv_array_push(&conn->args, ssh);
+
+	if (variant == VARIANT_SSH &&
+	    get_protocol_version_config() > 0) {
+		argv_array_push(&conn->args, "-o");
+		argv_array_push(&conn->args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
+		argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
+				 get_protocol_version_config());
+	}
+
+	if (variant != VARIANT_SIMPLE) {
+		if (flags & CONNECT_IPV4)
+			argv_array_push(&conn->args, "-4");
+		else if (flags & CONNECT_IPV6)
+			argv_array_push(&conn->args, "-6");
+	}
+
+	if (variant == VARIANT_TORTOISEPLINK)
+		argv_array_push(&conn->args, "-batch");
+
+	if (port && variant != VARIANT_SIMPLE) {
+		if (variant == VARIANT_SSH)
+			argv_array_push(&conn->args, "-p");
+		else
+			argv_array_push(&conn->args, "-P");
+
+		argv_array_push(&conn->args, port);
+	}
+
+	argv_array_push(&conn->args, ssh_host);
+}
+
 /*
  * This returns a dummy child_process if the transport protocol does not
  * need fork(2), or a struct child_process object if it does.  Once done,
@@ -961,16 +1020,13 @@ struct child_process *git_connect(int fd[2], const char *url,
 		conn->use_shell = 1;
 		conn->in = conn->out = -1;
 		if (protocol == PROTO_SSH) {
-			const char *ssh;
-			enum ssh_variant variant;
 			char *ssh_host = hostandport;
 			const char *port = NULL;
+
 			transport_check_allowed("ssh");
 			get_host_and_port(&ssh_host, &port);
-
 			if (!port)
 				port = get_port(ssh_host);
-
 			if (flags & CONNECT_DIAG_URL) {
 				printf("Diag: url=%s\n", url ? url : "NULL");
 				printf("Diag: protocol=%s\n", prot_name(protocol));
@@ -984,57 +1040,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 				strbuf_release(&cmd);
 				return NULL;
 			}
-
-			if (looks_like_command_line_option(ssh_host))
-				die("strange hostname '%s' blocked", ssh_host);
-
-			ssh = get_ssh_command();
-			if (ssh) {
-				variant = determine_ssh_variant(ssh, 1);
-			} else {
-				/*
-				 * GIT_SSH is the no-shell version of
-				 * GIT_SSH_COMMAND (and must remain so for
-				 * historical compatibility).
-				 */
-				conn->use_shell = 0;
-
-				ssh = getenv("GIT_SSH");
-				if (!ssh)
-					ssh = "ssh";
-				variant = determine_ssh_variant(ssh, 0);
-			}
-
-			argv_array_push(&conn->args, ssh);
-
-			if (variant == VARIANT_SSH &&
-			    get_protocol_version_config() > 0) {
-				argv_array_push(&conn->args, "-o");
-				argv_array_push(&conn->args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
-				argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
-						 get_protocol_version_config());
-			}
-
-			if (variant != VARIANT_SIMPLE) {
-				if (flags & CONNECT_IPV4)
-					argv_array_push(&conn->args, "-4");
-				else if (flags & CONNECT_IPV6)
-					argv_array_push(&conn->args, "-6");
-			}
-
-			if (variant == VARIANT_TORTOISEPLINK)
-				argv_array_push(&conn->args, "-batch");
-
-			if (port && variant != VARIANT_SIMPLE) {
-				if (variant == VARIANT_SSH)
-					argv_array_push(&conn->args, "-p");
-				else
-					argv_array_push(&conn->args, "-P");
-
-				argv_array_push(&conn->args, port);
-			}
-
-			argv_array_push(&conn->args, ssh_host);
+			fill_ssh_args(conn, ssh_host, port, flags);
 		} else {
 			transport_check_allowed("file");
 			if (get_protocol_version_config() > 0) {
Signature · 1 line
2.15.0.rc1.287.g2b38de12cc-goog
#127 lore raw

PATCH 3/5 ssh: 'auto' variant to select between 'ssh' and 'simple'

In reply to Jonathan Nieder

Android's "repo" tool is a tool for managing a large codebase consisting of multiple smaller repositories, similar to Git's submodule feature. Starting with Git 94b8ae5a (ssh: introduce a 'simple' ssh variant, 2017-10-16), users noticed that it stopped handling the port in ssh:// URLs.

The cause: when it encounters ssh:// URLs, repo pre-connects to the server and sets GIT_SSH to a helper ".repo/repo/git_ssh" that reuses that connection. Before 94b8ae5a, the helper was assumed to support OpenSSH options for lack of a better guess and got passed a -p option to set the port. After that patch, it uses the new default of a simple helper that does not accept an option to set the port.

The next release of "repo" will set GIT_SSH_VARIANT to "ssh" to avoid that. But users of old versions and of other similar GIT_SSH implementations would not get the benefit of that fix.

So update the default to use OpenSSH options again, with a twist. As observed in 94b8ae5a, we cannot assume that $GIT_SSH always handles OpenSSH options: common helpers such as travis-ci's dpl[*] are configured using GIT_SSH and do not accept OpenSSH options. So make the default a new variant "auto", with the following behavior:

1. First, check for a recognized basename, like today.

2. If the basename is not recognized, check whether $GIT_SSH supports OpenSSH options by running

$GIT_SSH -G <options> <host>

This returns status 0 and prints configuration in OpenSSH if it recognizes all <options> and returns status 255 if it encounters an unrecognized option. A wrapper script like

exec ssh -- "$@"

would fail with

ssh: Could not resolve hostname -g: Name or service not known

, correctly reflecting that it does not support OpenSSH options.

3. Based on the result from step (2), behave like "ssh" (if it succeeded) or "simple" (if it failed).

This way, the default ssh variant for unrecognized commands can handle both the repo and dpl cases as intended.

[*] https://github.com/travis-ci/dpl/blob/6c3fddfda1f2a85944c544446b068bac0a77c049/lib/dpl/provider.rb#L215

---
This is the main one. Simplified by making "auto" behave the same as unset.

 Documentation/config.txt | 24 ++++++++------
 connect.c                | 82 +++++++++++++++++++++++++++++++-----------------
 t/t5601-clone.sh         | 20 ++++++++++++
 3 files changed, 88 insertions(+), 38 deletions(-)
Documentation/config.txt +15 -9
index 0460af37e2..6dffa4aa3d 100644
@@ -2081,16 +2081,22 @@ matched against are those given directly to Git commands.  This means any URLs
 visited as a result of a redirection do not participate in matching.
 
 ssh.variant::
-	Depending on the value of the environment variables `GIT_SSH` or
-	`GIT_SSH_COMMAND`, or the config setting `core.sshCommand`, Git
-	auto-detects whether to adjust its command-line parameters for use
-	with ssh (OpenSSH), plink or tortoiseplink, as opposed to the default
-	(simple).
+	By default, Git determines the command line arguments to use
+	based on the basename of the configured SSH command (configured
+	using the environment variable `GIT_SSH` or `GIT_SSH_COMMAND` or
+	the config setting `core.sshCommand`). If the basename is
+	unrecognized, Git will attempt to detect support of OpenSSH
+	options by first invoking the configured SSH command with the
+	`-G` (print configuration) option and will subsequently use
+	OpenSSH options (if that is successful) or no options besides
+	the host and remote command (if it fails).
 +
-The config variable `ssh.variant` can be set to override this auto-detection;
-valid values are `ssh`, `simple`, `plink`, `putty` or `tortoiseplink`. Any
-other value will be treated as normal ssh. This setting can be overridden via
-the environment variable `GIT_SSH_VARIANT`.
+The config variable `ssh.variant` can be set to override this detection:
+valid values are `ssh` (to use OpenSSH options), `plink`, `putty`,
+`tortoiseplink`, `simple` (no options except the host and remote command).
+The default auto-detection can be explicitly requested using the value
+`auto`.  Any other value is treated as `ssh`.  This setting can also be
+overridden via the environment variable `GIT_SSH_VARIANT`.
 +
 The current command-line parameters used for each variant are as
 follows:
connect.c +53 -29

130 lines not on this page · raw message

t/t5601-clone.sh +20 -0
index 86811a0c35..df9dfafdd8 100755
@@ -372,6 +372,12 @@ test_expect_success 'variant can be overriden' '
 	expect_ssh myhost src
 '
 
+test_expect_success 'variant=auto picks based on basename' '
+	copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
+	git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
+	expect_ssh "-4 -P 123" myhost src
+'
+
 test_expect_success 'simple is treated as simple' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
 	git clone -4 "[myhost:123]:src" ssh-bracket-clone-simple &&
@@ -384,6 +390,20 @@ test_expect_success 'uplink is treated as simple' '
 	expect_ssh myhost src
 '
 
+test_expect_success 'OpenSSH-like uplink is treated as ssh' '
+	write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
+	if test "\$1" = "-G"
+	then
+		exit 0
+	fi &&
+	exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
+	EOF
+	GIT_SSH="$TRASH_DIRECTORY/uplink" &&
+	export GIT_SSH &&
+	git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
+	expect_ssh "-p 123" myhost src
+'
+
 test_expect_success 'plink is treated specially (as putty)' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
 	git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
Signature · 1 line
2.15.0.rc1.287.g2b38de12cc
#130 lore raw

PATCH 4/5 ssh: 'simple' variant does not support -4/-6

In reply to Jonathan Nieder

If the user passes -4/--ipv4 or -6/--ipv6 to "git fetch" or "git push" and the ssh command configured with GIT_SSH does not support such a setting, error out instead of ignoring the option and continuing.

---
As before, just rebased.

 connect.c        | 25 ++++++++++++++++++++++---
 t/t5601-clone.sh | 12 ++++++------
 2 files changed, 28 insertions(+), 9 deletions(-)
connect.c +22 -3
index 0441dcbacf..9c64e8155a 100644
@@ -923,11 +923,30 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
 				 get_protocol_version_config());
 	}
 
-	if (variant != VARIANT_SIMPLE) {
-		if (flags & CONNECT_IPV4)
+	if (flags & CONNECT_IPV4) {
+		switch (variant) {
+		case VARIANT_AUTO:
+			BUG("VARIANT_AUTO passed to push_ssh_options");
+		case VARIANT_SIMPLE:
+			die("ssh variant 'simple' does not support -4");
+		case VARIANT_SSH:
+		case VARIANT_PLINK:
+		case VARIANT_PUTTY:
+		case VARIANT_TORTOISEPLINK:
 			argv_array_push(args, "-4");
-		else if (flags & CONNECT_IPV6)
+		}
+	} else if (flags & CONNECT_IPV6) {
+		switch (variant) {
+		case VARIANT_AUTO:
+			BUG("VARIANT_AUTO passed to push_ssh_options");
+		case VARIANT_SIMPLE:
+			die("ssh variant 'simple' does not support -6");
+		case VARIANT_SSH:
+		case VARIANT_PLINK:
+		case VARIANT_PUTTY:
+		case VARIANT_TORTOISEPLINK:
 			argv_array_push(args, "-6");
+		}
 	}
 
 	if (variant == VARIANT_TORTOISEPLINK)
t/t5601-clone.sh +6 -6
index df9dfafdd8..ea401cec1f 100755
@@ -367,9 +367,10 @@ test_expect_success 'OpenSSH variant passes -4' '
 	expect_ssh "-4 -p 123" myhost src
 '
 
-test_expect_success 'variant can be overriden' '
-	git -c ssh.variant=simple clone -4 "[myhost:123]:src" ssh-simple-clone &&
-	expect_ssh myhost src
+test_expect_success 'variant can be overridden' '
+	copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" &&
+	git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone &&
+	expect_ssh "-4 -P 123" myhost src
 '
 
 test_expect_success 'variant=auto picks based on basename' '
@@ -378,10 +379,9 @@ test_expect_success 'variant=auto picks based on basename' '
 	expect_ssh "-4 -P 123" myhost src
 '
 
-test_expect_success 'simple is treated as simple' '
+test_expect_success 'simple does not support -4/-6' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
-	git clone -4 "[myhost:123]:src" ssh-bracket-clone-simple &&
-	expect_ssh myhost src
+	test_must_fail git clone -4 "[myhost:123]:src" ssh-bracket-clone-simple
 '
 
 test_expect_success 'uplink is treated as simple' '
Signature · 1 line
2.15.0.rc1.287.g2b38de12cc
#131 lore raw

PATCH 5/5 ssh: 'simple' variant does not support --port

In reply to Jonathan Nieder

When trying to connect to an ssh:// URL with port explicitly specified and the ssh command configured with GIT_SSH does not support such a setting, it is less confusing to error out than to silently suppress the port setting and continue.

This requires updating the GIT_SSH setting in t5603-clone-dirname.sh. That test is about the directory name produced when cloning various URLs. It uses an ssh wrapper that ignores all its arguments but does not declare that it supports a port argument; update it to set GIT_SSH_VARIANT=ssh to do so. (Real-life ssh wrappers that pass a port argument to OpenSSH would also support -G and would not require such an update.)

---
That's the end of the series. Thanks for reading.

 connect.c                | 15 ++++++++++++---
 t/t5601-clone.sh         | 10 ++++++++--
 t/t5603-clone-dirname.sh |  2 ++
 3 files changed, 22 insertions(+), 5 deletions(-)
connect.c +12 -3
index 9c64e8155a..06bcd3981e 100644
@@ -952,11 +952,20 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
 	if (variant == VARIANT_TORTOISEPLINK)
 		argv_array_push(args, "-batch");
 
-	if (port && variant != VARIANT_SIMPLE) {
-		if (variant == VARIANT_SSH)
+	if (port) {
+		switch (variant) {
+		case VARIANT_AUTO:
+			BUG("VARIANT_AUTO passed to push_ssh_options");
+		case VARIANT_SIMPLE:
+			die("ssh variant 'simple' does not support setting port");
+		case VARIANT_SSH:
 			argv_array_push(args, "-p");
-		else
+			break;
+		case VARIANT_PLINK:
+		case VARIANT_PUTTY:
+		case VARIANT_TORTOISEPLINK:
 			argv_array_push(args, "-P");
+		}
 
 		argv_array_push(args, port);
 	}
t/t5601-clone.sh +8 -2
index ea401cec1f..f9a2ae84c7 100755
@@ -381,12 +381,18 @@ test_expect_success 'variant=auto picks based on basename' '
 
 test_expect_success 'simple does not support -4/-6' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
-	test_must_fail git clone -4 "[myhost:123]:src" ssh-bracket-clone-simple
+	test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple
+'
+
+test_expect_success 'simple does not support port' '
+	copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
+	test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple
 '
 
 test_expect_success 'uplink is treated as simple' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
-	git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
+	test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
+	git clone "myhost:src" ssh-clone-uplink &&
 	expect_ssh myhost src
 '
 
t/t5603-clone-dirname.sh +2 -0
index d5af758129..13b5e5eb9b 100755
@@ -11,7 +11,9 @@ test_expect_success 'setup ssh wrapper' '
 	git upload-pack "$TRASH_DIRECTORY"
 	EOF
 	GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
+	GIT_SSH_VARIANT=ssh &&
 	export GIT_SSH &&
+	export GIT_SSH_VARIANT &&
 	export TRASH_DIRECTORY
 '
 
Signature · 1 line
2.15.0.rc1.287.g2b38de12cc
#128 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

In reply to Jonathan Nieder
Quoted 48 lines · Jonathan Nieder

Android's "repo" tool is a tool for managing a large codebase consisting of multiple smaller repositories, similar to Git's submodule feature. Starting with Git 94b8ae5a (ssh: introduce a 'simple' ssh variant, 2017-10-16), users noticed that it stopped handling the port in ssh:// URLs.

The cause: when it encounters ssh:// URLs, repo pre-connects to the server and sets GIT_SSH to a helper ".repo/repo/git_ssh" that reuses that connection. Before 94b8ae5a, the helper was assumed to support OpenSSH options for lack of a better guess and got passed a -p option to set the port. After that patch, it uses the new default of a simple helper that does not accept an option to set the port.

The next release of "repo" will set GIT_SSH_VARIANT to "ssh" to avoid that. But users of old versions and of other similar GIT_SSH implementations would not get the benefit of that fix.

So update the default to use OpenSSH options again, with a twist. As observed in 94b8ae5a, we cannot assume that $GIT_SSH always handles OpenSSH options: common helpers such as travis-ci's dpl[*] are configured using GIT_SSH and do not accept OpenSSH options. So make the default a new variant "auto", with the following behavior:

1. First, check for a recognized basename, like today.

2. If the basename is not recognized, check whether $GIT_SSH supports OpenSSH options by running

$GIT_SSH -G <options> <host>

This returns status 0 and prints configuration in OpenSSH if it recognizes all <options> and returns status 255 if it encounters an unrecognized option. A wrapper script like

exec ssh -- "$@"

would fail with

ssh: Could not resolve hostname -g: Name or service not known

, correctly reflecting that it does not support OpenSSH options.

3. Based on the result from step (2), behave like "ssh" (if it succeeded) or "simple" (if it failed).

This way, the default ssh variant for unrecognized commands can handle both the repo and dpl cases as intended.

Quoted 8 lines

[*] https://github.com/travis-ci/dpl/blob/6c3fddfda1f2a85944c544446b068bac0a77c049/lib/dpl/provider.rb#L215

---
This is the main one. Simplified by making "auto" behave the same as unset.

I still don't see the benefit of allowing a user to explicitly set 'auto' then, if setting it to 'auto' is effectively a noop. But maybe there's something I'm not seeing.

Quoted 222 lines
 Documentation/config.txt | 24 ++++++++------
 connect.c                | 82 +++++++++++++++++++++++++++++++-----------------
 t/t5601-clone.sh         | 20 ++++++++++++
 3 files changed, 88 insertions(+), 38 deletions(-)
Documentation/config.txt +15 -9
index 0460af37e2..6dffa4aa3d 100644
@@ -2081,16 +2081,22 @@ matched against are those given directly to Git commands.  This means any URLs
 visited as a result of a redirection do not participate in matching.
 
 ssh.variant::
-	Depending on the value of the environment variables `GIT_SSH` or
-	`GIT_SSH_COMMAND`, or the config setting `core.sshCommand`, Git
-	auto-detects whether to adjust its command-line parameters for use
-	with ssh (OpenSSH), plink or tortoiseplink, as opposed to the default
-	(simple).
+	By default, Git determines the command line arguments to use
+	based on the basename of the configured SSH command (configured
+	using the environment variable `GIT_SSH` or `GIT_SSH_COMMAND` or
+	the config setting `core.sshCommand`). If the basename is
+	unrecognized, Git will attempt to detect support of OpenSSH
+	options by first invoking the configured SSH command with the
+	`-G` (print configuration) option and will subsequently use
+	OpenSSH options (if that is successful) or no options besides
+	the host and remote command (if it fails).
 +
-The config variable `ssh.variant` can be set to override this auto-detection;
-valid values are `ssh`, `simple`, `plink`, `putty` or `tortoiseplink`. Any
-other value will be treated as normal ssh. This setting can be overridden via
-the environment variable `GIT_SSH_VARIANT`.
+The config variable `ssh.variant` can be set to override this detection:
+valid values are `ssh` (to use OpenSSH options), `plink`, `putty`,
+`tortoiseplink`, `simple` (no options except the host and remote command).
+The default auto-detection can be explicitly requested using the value
+`auto`.  Any other value is treated as `ssh`.  This setting can also be
+overridden via the environment variable `GIT_SSH_VARIANT`.
 +
 The current command-line parameters used for each variant are as
 follows:
connect.c +53 -29
index 77ab6db3bb..0441dcbacf 100644
@@ -777,6 +777,7 @@ static const char *get_ssh_command(void)
 }
 
 enum ssh_variant {
+	VARIANT_AUTO,
 	VARIANT_SIMPLE,
 	VARIANT_SSH,
 	VARIANT_PLINK,
@@ -784,14 +785,16 @@ enum ssh_variant {
 	VARIANT_TORTOISEPLINK,
 };
 
-static int override_ssh_variant(enum ssh_variant *ssh_variant)
+static void override_ssh_variant(enum ssh_variant *ssh_variant)
 {
 	const char *variant = getenv("GIT_SSH_VARIANT");
 
 	if (!variant && git_config_get_string_const("ssh.variant", &variant))
-		return 0;
+		return;
 
-	if (!strcmp(variant, "plink"))
+	if (!strcmp(variant, "auto"))
+		*ssh_variant = VARIANT_AUTO;
+	else if (!strcmp(variant, "plink"))
 		*ssh_variant = VARIANT_PLINK;
 	else if (!strcmp(variant, "putty"))
 		*ssh_variant = VARIANT_PUTTY;
@@ -801,18 +804,18 @@ static int override_ssh_variant(enum ssh_variant *ssh_variant)
 		*ssh_variant = VARIANT_SIMPLE;
 	else
 		*ssh_variant = VARIANT_SSH;
-
-	return 1;
 }
 
 static enum ssh_variant determine_ssh_variant(const char *ssh_command,
 					      int is_cmdline)
 {
-	enum ssh_variant ssh_variant = VARIANT_SIMPLE;
+	enum ssh_variant ssh_variant = VARIANT_AUTO;
 	const char *variant;
 	char *p = NULL;
 
-	if (override_ssh_variant(&ssh_variant))
+	override_ssh_variant(&ssh_variant);
+
+	if (ssh_variant != VARIANT_AUTO)
 		return ssh_variant;
 
 	if (!is_cmdline) {
@@ -908,6 +911,38 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
 	return conn;
 }
 
+static void push_ssh_options(struct argv_array *args, struct argv_array *env,
+			       enum ssh_variant variant, const char *port,
+			       int flags)
+{
+	if (variant == VARIANT_SSH &&
+	    get_protocol_version_config() > 0) {
+		argv_array_push(args, "-o");
+		argv_array_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
+		argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
+				 get_protocol_version_config());
+	}
+
+	if (variant != VARIANT_SIMPLE) {
+		if (flags & CONNECT_IPV4)
+			argv_array_push(args, "-4");
+		else if (flags & CONNECT_IPV6)
+			argv_array_push(args, "-6");
+	}
+
+	if (variant == VARIANT_TORTOISEPLINK)
+		argv_array_push(args, "-batch");
+
+	if (port && variant != VARIANT_SIMPLE) {
+		if (variant == VARIANT_SSH)
+			argv_array_push(args, "-p");
+		else
+			argv_array_push(args, "-P");
+
+		argv_array_push(args, port);
+	}
+}
+
 /* Prepare a child_process for use by Git's SSH-tunneled transport. */
 static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
 			  const char *port, int flags)
@@ -937,33 +972,22 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
 
 	argv_array_push(&conn->args, ssh);
 
-	if (variant == VARIANT_SSH &&
-	    get_protocol_version_config() > 0) {
-		argv_array_push(&conn->args, "-o");
-		argv_array_push(&conn->args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
-		argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
-				 get_protocol_version_config());
-	}
-
-	if (variant != VARIANT_SIMPLE) {
-		if (flags & CONNECT_IPV4)
-			argv_array_push(&conn->args, "-4");
-		else if (flags & CONNECT_IPV6)
-			argv_array_push(&conn->args, "-6");
-	}
+	if (variant == VARIANT_AUTO) {
+		struct child_process detect = CHILD_PROCESS_INIT;
 
-	if (variant == VARIANT_TORTOISEPLINK)
-		argv_array_push(&conn->args, "-batch");
+		detect.use_shell = conn->use_shell;
+		detect.no_stdin = detect.no_stdout = detect.no_stderr = 1;
 
-	if (port && variant != VARIANT_SIMPLE) {
-		if (variant == VARIANT_SSH)
-			argv_array_push(&conn->args, "-p");
-		else
-			argv_array_push(&conn->args, "-P");
+		argv_array_push(&detect.args, ssh);
+		argv_array_push(&detect.args, "-G");
+		push_ssh_options(&detect.args, &detect.env_array,
+				 VARIANT_SSH, port, flags);
+		argv_array_push(&detect.args, ssh_host);
 
-		argv_array_push(&conn->args, port);
+		variant = run_command(&detect) ? VARIANT_SIMPLE : VARIANT_SSH;
 	}
 
+	push_ssh_options(&conn->args, &conn->env_array, variant, port, flags);
 	argv_array_push(&conn->args, ssh_host);
 }
 
t/t5601-clone.sh +20 -0
index 86811a0c35..df9dfafdd8 100755
@@ -372,6 +372,12 @@ test_expect_success 'variant can be overriden' '
 	expect_ssh myhost src
 '
 
+test_expect_success 'variant=auto picks based on basename' '
+	copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
+	git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
+	expect_ssh "-4 -P 123" myhost src
+'
+
 test_expect_success 'simple is treated as simple' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
 	git clone -4 "[myhost:123]:src" ssh-bracket-clone-simple &&
@@ -384,6 +390,20 @@ test_expect_success 'uplink is treated as simple' '
 	expect_ssh myhost src
 '
 
+test_expect_success 'OpenSSH-like uplink is treated as ssh' '
+	write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
+	if test "\$1" = "-G"
+	then
+		exit 0
+	fi &&
+	exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
+	EOF
+	GIT_SSH="$TRASH_DIRECTORY/uplink" &&
+	export GIT_SSH &&
+	git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
+	expect_ssh "-p 123" myhost src
+'
+
 test_expect_success 'plink is treated specially (as putty)' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
 	git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
Signature · 1 line
2.15.0.rc1.287.g2b38de12cc
Signature · 1 line
Brandon Williams
#129 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

Quoted 7 lines
Quoted 2 lines

This is the main one. Simplified by making "auto" behave the same as unset.

I still don't see the benefit of allowing a user to explicitly set 'auto' then, if setting it to 'auto' is effectively a noop. But maybe there's something I'm not seeing.

If /etc/gitconfig says SSH, and you have different configs in your different repos,
the easiest way out is setting AUTO in ~/.gitconfig.

#106 lore raw

PATCH 1/1 diff: add option to ignore whitespaces for move detection only

In reply to Stefan Beller

---

 diff.c                     |  10 ++--
 diff.h                     |   1 +
 t/t4015-diff-whitespace.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++-

See, only 10 lines of code! (and a few more for tests)

We have run out of space in diff_options.flags,touched_flags. as we 1<<U31 as the highest bit. We could reuse 1<<9 that is currently unused (removed in 882749a04f (diff: add --word-diff option that generalizes --color-words, 2010-04-14)). But that postpones the real fix for only a short amount of time.

Ideas welcome how to extend the flag space. (We cannot just make it a long either, as some arcane architecures have 32 bit longs.)

Another TODO: documentation

I plan to trim the CC list for any resend that will be needed.

Thanks,
Stefan

 3 files changed, 121 insertions(+), 4 deletions(-)
diff.c +7 -3
index c4a669ffa8..ddb2018307 100644
@@ -726,7 +726,8 @@ static int next_byte(const char **cp, const char **endp,
 			return (int)' ';
 		}
 
-		if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
+		if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE) ||
+		    diffopt->color_moved_ignore_space) {
 			while (*cp < *endp && isspace(**cp))
 				(*cp)++;
 			/*
@@ -751,7 +752,8 @@ static int moved_entry_cmp(const struct diff_options *diffopt,
 	const char *ap = a->es->line, *ae = a->es->line + a->es->len;
 	const char *bp = b->es->line, *be = b->es->line + b->es->len;
 
-	if (!(diffopt->xdl_opts & XDF_WHITESPACE_FLAGS))
+	if (!(diffopt->xdl_opts & XDF_WHITESPACE_FLAGS) &&
+	    !diffopt->color_moved_ignore_space)
 		return a->es->len != b->es->len  || memcmp(ap, bp, a->es->len);
 
 	if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_AT_EOL)) {
@@ -774,7 +776,7 @@ static int moved_entry_cmp(const struct diff_options *diffopt,
 
 static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_options *o)
 {
-	if (o->xdl_opts & XDF_WHITESPACE_FLAGS) {
+	if ((o->xdl_opts & XDF_WHITESPACE_FLAGS) || o->color_moved_ignore_space) {
 		static struct strbuf sb = STRBUF_INIT;
 		const char *ap = es->line, *ae = es->line + es->len;
 		int c;
@@ -4660,6 +4662,8 @@ int diff_opt_parse(struct diff_options *options,
 		DIFF_XDL_CLR(options, NEED_MINIMAL);
 	else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
 		DIFF_XDL_SET(options, IGNORE_WHITESPACE);
+	else if (!strcmp(arg, "--ignore-all-space-in-move-detection"))
+		options->color_moved_ignore_space = 1;
 	else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
 		DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
 	else if (!strcmp(arg, "--ignore-space-at-eol"))
diff.h +1 -0
index aca150ba2e..6ba3f53bbd 100644
@@ -196,6 +196,7 @@ struct diff_options {
 	} color_moved;
 	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
 	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
+	int color_moved_ignore_space;
 };
 
 void diff_emit_submodule_del(struct diff_options *o, const char *line);
t/t4015-diff-whitespace.sh +113 -1

120 lines not on this page · raw message

Signature · 1 line
2.15.0.rc2.6.g953226eb5f
#122 lore raw

Re: [PATCH 1/5] connect: split git:// setup into a separate function

In reply to Jonathan Nieder
Quoted 10 lines · Jonathan Nieder

The git_connect function is growing long. Split the PROTO_GIT-specific portion to a separate function to make it easier to read.

No functional change intended.

---
As before, except with sbeller's Reviewed-by.

I found this quite nice, except for one thing.

connect.c static enum ssh_variant determine_ssh_variant(const char *ssh_command, · line 864

Quoted 12 lines
connect.c +12 -0
+/*
+ * Open a connection using Git's native protocol.
+ *
+ * The caller is responsible for freeing hostandport, but this function may
+ * modify it (for example, to truncate it to remove the port part).
+ */
+static struct child_process *git_connect_git(int fd[2], char *hostandport,
+					     const char *path, const char *prog,
+					     int flags)
+{
+	struct child_process *conn = &no_fork;
+	struct strbuf request = STRBUF_INIT;

As this one decides what "conn" to return, including the fallback &no_fork instance,...

connect.c struct child_process *git_connect(int fd[2], const char *url,

Quoted 8 lines
connect.c +4 -0
+	...
+	return conn;
+}
+
 /*
  * This returns a dummy child_process if the transport protocol does not
  * need fork(2), or a struct child_process object if it does.  Once done,
@@ -881,50 +939,7 @@ struct child_process *git_connect(int fd[2], const char *url,

Each of the if/elseif/ cascade, one of which calls the new helper, now makes an explicit assignment to "conn" declared in git_connect().

Which means the defaulting of git_connect::conn to &no_fork is now unneeded. One of the things that made the original cascade a bit harder to follow than necessary, aside from the physical length of the PROTO_GIT part, was that the case where conn remains to point at no_fork looked very special and it was buried in that long PROTO_GIT part. Now the main source of that issue is fixed, it would make it clear to leave conn uninitialized (or initialize to NULL---but leaving it uninitialized would make the intention of the code more clear, I would think, that each of the if/elseif/ cascade must assign to it).

Quoted 9 lines
connect.c +1 -2
 		printf("Diag: path=%s\n", path ? path : "NULL");
 		conn = NULL;
 	} else if (protocol == PROTO_GIT) {
-		struct strbuf request = STRBUF_INIT;
-...
+		conn = git_connect_git(fd, hostandport, path, prog, flags);
 	} else {
 		struct strbuf cmd = STRBUF_INIT;
 		const char *const *var;
#111 lore raw

Re: [PATCH 1/5] connect: split git:// setup into a separate function

In reply to Stefan Beller
Quoted 4 lines · Stefan Beller

I think once this option is given, all we have to do is pay attention to this option in diff.c#moved_entry_cmp/next_byte, which is best built on top of Peffs recent fixes origin/jk/diff-color-moved-fix. Would that be of interest for people?

Two things and a half.

* I was hoping that the next_byte() and string_hash() thing, once they are cleaned up, will eventually be shared with the xdiff/ code at the lower layer, which needs to do pretty much the same in order to implement various whitespace ignoring options. I am not sure how well the approach taken by the WIP patch meshes with the needs of the lower layer.

* I agree that -w that applies only one or the other and not both may sometimes produce a better/readable result, but the more important part is how the user can tell when to exercise the option. Would it be realistic to expect them to try -w in different combinations and see which looks the best? What if we have a patch that touch two files, one looks better with -w only for coloring moved and the other looks better with -w for both?

* As moved-lines display is mostly a presentation thing, I wonder if it makes sense to always match loosely wrt whitespace differences. It is tempting because if it is true, we do not have to worry about the second issue above.

Thanks.

#126 lore raw

Re: [PATCH 2/5] connect: split ssh command line options into separate function

In reply to Jonathan Nieder
Quoted 6 lines · Jonathan Nieder

The git_connect function is growing long. Split the portion that discovers an ssh command and options it accepts before the service name and path to a separate function to make it easier to read.

No functional change intended.

Quoted 7 lines

---
As before, except for the Reviewed-by.

 connect.c | 116 +++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 61 insertions(+), 55 deletions(-)

Looks like a straight-forwrd split. Makes sense.

Thanks.

#136 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

In reply to Jonathan Nieder
Quoted 8 lines · Jonathan Nieder

1. First, check whether $GIT_SSH supports OpenSSH options by running

$GIT_SSH -G <options> <host>

This returns status 0 and prints configuration in OpenSSH if it recognizes all <options> and returns status 255 if it encounters an unrecognized option. A wrapper script like

Quoted 7 lines

exec ssh -- "$@"

would fail with

ssh: Could not resolve hostname -g: Name or service not known

, correctly reflecting that it does not support OpenSSH options.

Two comments.

* It would have been really nicer if the push_ssh_options() got split from its caller in a separate preparatory [PATCH 2.5/5].

* Use of -G for auto-detection is clever and cute, but do we know how safe it would be in the real world? What worries me the most is "myssh -G localhost" (no extra options) that does not fit our expectation on "-G" to either exit immediately with an error when it is not understood, or to exit like OpenSSH does, and instead successfully makes a connection and gets stuck.

#132 lore raw

Re: [PATCH v2 0/5] Coping with unrecognized ssh wrapper scripts in GIT_SSH

In reply to Jonathan Nieder
Quoted 9 lines · Jonathan Nieder
Quoted 5 lines · Jonathan Tan
Quoted 3 lines · Jonathan Nieder
Quoted 2 lines

If this looks good, I can reroll in a moment.

Yes, this looks good.

Thanks. Here goes.

Quoted 8 lines

The interdiff is upthread. Thanks, all, for the quick review.

Jonathan Nieder (5):
connect: split git:// setup into a separate function
connect: split ssh command line options into separate function
ssh: 'auto' variant to select between 'ssh' and 'simple'
ssh: 'simple' variant does not support -4/-6
ssh: 'simple' variant does not support --port

These looked mostly good. I left some nitpicks on individual patches.

#112 lore raw

Re: [PATCH 1/5] connect: split git:// setup into a separate function

In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Stefan Beller

I think once this option is given, all we have to do is pay attention to this option in diff.c#moved_entry_cmp/next_byte, which is best built on top of Peffs recent fixes origin/jk/diff-color-moved-fix. Would that be of interest for people?

Quoted 8 lines

Two things and a half.

* I was hoping that the next_byte() and string_hash() thing, once they are cleaned up, will eventually be shared with the xdiff/ code at the lower layer, which needs to do pretty much the same in order to implement various whitespace ignoring options. I am not sure how well the approach taken by the WIP patch meshes with the needs of the lower layer.

Good point. I'll keep that in mind when redoing that patch. (I might even try to clean up the xdiff stuff and reuse the code here)

Quoted 8 lines

* I agree that -w that applies only one or the other and not both may sometimes produce a better/readable result, but the more important part is how the user can tell when to exercise the option. Would it be realistic to expect them to try -w in different combinations and see which looks the best? What if we have a patch that touch two files, one looks better with -w only for coloring moved and the other looks better with -w for both?

Quoted 4 lines

* As moved-lines display is mostly a presentation thing, I wonder if it makes sense to always match loosely wrt whitespace differences. It is tempting because if it is true, we do not have to worry about the second issue above.

Well, sometimes the user wants to know if it is byte-for-byte identical (unlikely to be code, but maybe column oriented data for input; think of all our FORTRAN users. ;)
and at other times the user just wants to approximately know if it is the same (i.e. code ignoring white space changes). If Git was *really* smart w.r.t. languages it might even ignore identifier renames in the programming language.

So I think an "unconditionally ignore all white space in move detection" is not the best (it could be a good default though!) but the user wants to have a possibility to byte-for-byte comparision (maybe even including CRLFs/LFs)

Thanks,
Stefan

Quoted 1 line

Thanks.

#107 lore raw

Re: [WIP PATCH] diff: add option to ignore whitespaces for move detection only

In reply to Stefan Beller
Quoted 9 lines · Stefan Beller

---

 diff.c                     |  10 ++--
 diff.h                     |   1 +
 t/t4015-diff-whitespace.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++-

See, only 10 lines of code! (and a few more for tests)

Quoted 8 lines

We have run out of space in diff_options.flags,touched_flags. as we 1<<U31 as the highest bit. We could reuse 1<<9 that is currently unused (removed in 882749a04f (diff: add --word-diff option that generalizes --color-words, 2010-04-14)). But that postpones the real fix for only a short amount of time.

Ideas welcome how to extend the flag space. (We cannot just make it a long either, as some arcane architecures have 32 bit longs.)

One simple idea would be to convert the single 'flag' into various bit fields themselves, that way if you need to add a new flag you would just make a new bit field. I'm unaware of any downsides of doing so (though i may be missing something) but doing so would probably cause a bit of code churn.

Signature · 1 line
Brandon Williams
#108 lore raw

Re: [WIP PATCH] diff: add option to ignore whitespaces for move detection only

Quoted 5 lines · Brandon Williams

One simple idea would be to convert the single 'flag' into various bit fields themselves, that way if you need to add a new flag you would just make a new bit field. I'm unaware of any downsides of doing so (though i may be missing something) but doing so would probably cause a bit of code churn.

The reason why people want to have their own bit in the flags word is because they want to use DIFF_OPT_{SET,CLR,TST,TOUCHED} but they do not want to do the work to extend them beyond a single word.

I think it is doable by making everything a 1-bit wide bitfield without affecting existing users.

#109 lore raw

Re: [WIP PATCH] diff: add option to ignore whitespaces for move detection only

Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Brandon Williams

One simple idea would be to convert the single 'flag' into various bit fields themselves, that way if you need to add a new flag you would just make a new bit field. I'm unaware of any downsides of doing so (though i may be missing something) but doing so would probably cause a bit of code churn.

Quoted 6 lines

The reason why people want to have their own bit in the flags word is because they want to use DIFF_OPT_{SET,CLR,TST,TOUCHED} but they do not want to do the work to extend them beyond a single word.

I think it is doable by making everything a 1-bit wide bitfield without affecting existing users.

... but the "touched" thing may be harder---I haven't thought it through.

#137 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

In reply to Jonathan Nieder

Hi Jonathan,

[I only saw that you replied to 3/5 with v2 after writing this reply, but it would apply to v2's 3/5, too]

Quoted 15 lines · Jonathan Nieder
t/t5601-clone.sh +7 -0
index 86811a0c35..fd94dd40d2 100755
@@ -384,6 +384,20 @@ test_expect_success 'uplink is treated as simple' '
 	expect_ssh myhost src
 '
 
+test_expect_success 'OpenSSH-like uplink is treated as ssh' '
+	write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
+	if test "\$1" = "-G"
+	then
+		exit 0
+	fi &&
+	exec "\$TRASH_DIRECTORY/ssh$X" "\$@"

t/t5601-clone.sh test_expect_success 'uplink is treated as simple' ' · line 403

Quoted 10 lines
t/t5601-clone.sh +7 -0
+	EOF
+	GIT_SSH="$TRASH_DIRECTORY/uplink" &&
+	export GIT_SSH &&
+	git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
+	expect_ssh "-p 123" myhost src
+'
+
 test_expect_success 'plink is treated specially (as putty)' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
 	git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&

This breaks on Windows. And it is not immediately obvious how so, so let me explain:

As you know, on Windows there is no executable flag. There is the .exe file extension to indicate an executable (and .com and .bat and .cmd are also handled as executable, at least as executable script).

Now, what happens if you call "abc" in the MSYS2 Bash and there is no script called "abc" but an executable called "abc.exe" in the PATH? Why, of course we execute that executable. It has to, because if "abc.exe" would be renamed into "abc", it would not work any longer.

That is also the reason why that "copy_ssh_wrapper" helper function automatically appends that .exe file suffix on Windows: it has to.

Every workaround breaks down at some point, and this workaround is no exception. What should the MSYS2 Bash do if asked to overwrite "abc" and there is only an "abc.exe"? It actually overwrites "abc.exe" and moves on.

And this is where we are here: the previous test case copied the ssh wrapper as "uplink". Except on Windows, it is "uplink.exe". And your newly introduced test case overwrites it. And then it tells Git specifically to look for "uplink", and Git does *not* append that .exe suffix automatically as the MSYS2 Bash would do, because git.exe is not intended to work MSYS2-like.

As a consequence, the test fails. Could you please squash in this, to fix the test on Windows?

-- snipsnap --

t/t5601-clone.sh +1 -0
index ec4b17bca62..1afcbd00617 100755
@@ -393,6 +393,7 @@ test_expect_success 'simple does not support port' '
 
 test_expect_success 'uplink is treated as simple' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
+	test_when_finished "rm \"$TRASH_DIRECTORY/uplink$X\"" &&
 	test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
 	git clone "myhost:src" ssh-clone-uplink &&
 	expect_ssh myhost src
#138 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

Quoted 59 lines · Johannes Schindelin

Hi Jonathan,

[I only saw that you replied to 3/5 with v2 after writing this reply, but it would apply to v2's 3/5, too]

Quoted 15 lines · Jonathan Nieder
t/t5601-clone.sh +7 -0
index 86811a0c35..fd94dd40d2 100755
@@ -384,6 +384,20 @@ test_expect_success 'uplink is treated as simple' '
      expect_ssh myhost src
 '
 
+test_expect_success 'OpenSSH-like uplink is treated as ssh' '
+     write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
+     if test "\$1" = "-G"
+     then
+             exit 0
+     fi &&
+     exec "\$TRASH_DIRECTORY/ssh$X" "\$@"

t/t5601-clone.sh test_expect_success 'uplink is treated as simple' ' · line 403

Quoted 10 lines
t/t5601-clone.sh +7 -0
+     EOF
+     GIT_SSH="$TRASH_DIRECTORY/uplink" &&
+     export GIT_SSH &&
+     git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
+     expect_ssh "-p 123" myhost src
+'
+
 test_expect_success 'plink is treated specially (as putty)' '
      copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
      git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&

This breaks on Windows. And it is not immediately obvious how so, so let me explain:

As you know, on Windows there is no executable flag. There is the .exe file extension to indicate an executable (and .com and .bat and .cmd are also handled as executable, at least as executable script).

Now, what happens if you call "abc" in the MSYS2 Bash and there is no script called "abc" but an executable called "abc.exe" in the PATH? Why, of course we execute that executable. It has to, because if "abc.exe" would be renamed into "abc", it would not work any longer.

That is also the reason why that "copy_ssh_wrapper" helper function automatically appends that .exe file suffix on Windows: it has to.

Every workaround breaks down at some point, and this workaround is no exception. What should the MSYS2 Bash do if asked to overwrite "abc" and there is only an "abc.exe"? It actually overwrites "abc.exe" and moves on.

And this is where we are here: the previous test case copied the ssh wrapper as "uplink". Except on Windows, it is "uplink.exe". And your newly introduced test case overwrites it. And then it tells Git specifically to look for "uplink", and Git does *not* append that .exe suffix automatically as the MSYS2 Bash would do, because git.exe is not intended to work MSYS2-like.

Quoted 2 lines

As a consequence, the test fails. Could you please squash in this, to fix the test on Windows?

This explanation is in detail and would even make a good commit message for a follow up commit. (Squashing just that line would loose the explanation as I suspect the original commit will not dedicate so much text to this single line)

Quoted 15 lines

-- snipsnap --

t/t5601-clone.sh +1 -0
index ec4b17bca62..1afcbd00617 100755
@@ -393,6 +393,7 @@ test_expect_success 'simple does not support port' '
 
 test_expect_success 'uplink is treated as simple' '
        copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
+       test_when_finished "rm \"$TRASH_DIRECTORY/uplink$X\"" &&
        test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
        git clone "myhost:src" ssh-clone-uplink &&
        expect_ssh myhost src
#139 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

Hi,

Quoted 5 lines · Stefan Beller
Quoted 2 lines · Johannes Schindelin

This breaks on Windows. And it is not immediately obvious how so, so let me explain:

[nice explanation snipped]

Quoted 7 lines
Quoted 2 lines

As a consequence, the test fails. Could you please squash in this, to fix the test on Windows?

This explanation is in detail and would even make a good commit message for a follow up commit. (Squashing just that line would loose the explanation as I suspect the original commit will not dedicate so much text to this single line)

I have other changes to make when rerolling anyway (from Junio's review), so no need for a followup patch. Will fix this in the reroll today.

Thanks for catching and diagnosing this, Dscho!

Jonathan

#110 lore raw

Re: [WIP PATCH] diff: add option to ignore whitespaces for move detection only

In reply to Junio C Hamano
Quoted 14 lines · Junio C Hamano
Quoted 12 lines · Junio C Hamano
Quoted 5 lines · Brandon Williams

One simple idea would be to convert the single 'flag' into various bit fields themselves, that way if you need to add a new flag you would just make a new bit field. I'm unaware of any downsides of doing so (though i may be missing something) but doing so would probably cause a bit of code churn.

The reason why people want to have their own bit in the flags word is because they want to use DIFF_OPT_{SET,CLR,TST,TOUCHED} but they do not want to do the work to extend them beyond a single word.

Quoted 5 lines
Quoted 2 lines

I think it is doable by making everything a 1-bit wide bitfield without affecting existing users.

... but the "touched" thing may be harder---I haven't thought it through.

From what I can tell the 'touched' thing is implemented as a parallel flag field so we would just need to have each flag use 2-bits, one for the flag itself and one for the 'touched' field. Then when using those macros it would just need to update the corresponding 'touched' field as well as what ever happens with the flag itself. It may be a little more involved than the current scheme but it should be doable if we need to extend the flag space past 32 bits.

Signature · 1 line
Brandon Williams
#140 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

In reply to Jonathan Nieder
Quoted 5 lines · Jonathan Nieder

I have other changes to make when rerolling anyway (from Junio's review), so no need for a followup patch. Will fix this in the reroll today.

Thanks for catching and diagnosing this, Dscho!

In the meantime, I've queued this from Dscho; please take it into consideration when you reroll.

Thanks.

-- >8 --
From: Johannes Schindelin <[email protected]>
Date: Sun, 29 Oct 2017 16:12:46 +0100
Subject: [PATCH] fixup! ssh: 'auto' variant to select between 'ssh' and 'simple'

This is needed because on Windows, if uplink.exe exists, the MSYS2 Bash will overwrite that when redirecting via >uplink.

---
 t/t5601-clone.sh | 1 +
 1 file changed, 1 insertion(+)
t/t5601-clone.sh +1 -0
index f9a2ae84c7..534eb21915 100755
@@ -391,6 +391,7 @@ test_expect_success 'simple does not support port' '
 
 test_expect_success 'uplink is treated as simple' '
 	copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
+	test_when_finished "rm \"$TRASH_DIRECTORY/uplink$X\"" &&
 	test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
 	git clone "myhost:src" ssh-clone-uplink &&
 	expect_ssh myhost src
Signature · 1 line
2.15.0-rc2-267-g7d3ed0014a
#141 lore raw

Re: [PATCH 3/5] ssh: 'auto' variant to select between 'ssh' and 'simple'

Hi Junio,

Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Jonathan Nieder

I have other changes to make when rerolling anyway (from Junio's review), so no need for a followup patch. Will fix this in the reroll today.

Quoted 6 lines
Quoted 1 line

Thanks for catching and diagnosing this, Dscho!

In the meantime, I've queued this from Dscho; please take it into consideration when you reroll.

Thanks.

Thanks for sending it out as an email.

Ciao,
Dscho

#123 lore raw

Re: [PATCH 1/5] connect: split git:// setup into a separate function

In reply to Junio C Hamano

Hi,

Quoted 25 lines · Junio C Hamano

Review

Quoted 6 lines · Jonathan Nieder
(quoted diff) +6 -0
+static struct child_process *git_connect_git(int fd[2], char *hostandport,
+					     const char *path, const char *prog,
+					     int flags)
+{
+	struct child_process *conn = &no_fork;
+	struct strbuf request = STRBUF_INIT;

As this one decides what "conn" to return, including the fallback &no_fork instance,...

Review struct child_process *git_connect(int fd[2], const char *url,

Quoted 8 lines
(quoted diff) +4 -0
+	...
+	return conn;
+}
+
 /*
  * This returns a dummy child_process if the transport protocol does not
  * need fork(2), or a struct child_process object if it does.  Once done,
@@ -881,50 +939,7 @@ struct child_process *git_connect(int fd[2], const char *url,

Each of the if/elseif/ cascade, one of which calls the new helper, now makes an explicit assignment to "conn" declared in git_connect().

Quoted 6 lines

Which means the defaulting of git_connect::conn to &no_fork is now unneeded. One of the things that made the original cascade a bit harder to follow than necessary, aside from the physical length of the PROTO_GIT part, was that the case where conn remains to point at no_fork looked very special and it was buried in that long PROTO_GIT part.

Good idea. Here's what I'll include in the reroll.

-- >8 --
Subject: connect: move no_fork fallback to git_tcp_connect

git_connect has the structure

	struct child_process *conn = &no_fork;

	...
	switch (protocol) {
	case PROTO_GIT:
		if (git_use_proxy(hostandport))
			conn = git_proxy_connect(fd, hostandport);
		else
			git_tcp_connect(fd, hostandport, flags);
		...
		break;
	case PROTO_SSH:
		conn = xmalloc(sizeof(*conn));
		child_process_init(conn);
		argv_array_push(&conn->args, ssh);
		...
		break;
	...
	return conn;

In all cases except the git_tcp_connect case, conn is explicitly assigned a value. Make the code clearer by explicitly assigning 'conn = &no_fork' in the tcp case and eliminating the default so the compiler can ensure conn is always correctly assigned.

---
 connect.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
connect.c +12 -10
index 7fbd396b35..b6accf71cb 100644
@@ -582,12 +582,21 @@ static int git_tcp_connect_sock(char *host, int flags)
 #endif /* NO_IPV6 */
 
 
-static void git_tcp_connect(int fd[2], char *host, int flags)
+static struct child_process no_fork = CHILD_PROCESS_INIT;
+
+int git_connection_is_socket(struct child_process *conn)
+{
+	return conn == &no_fork;
+}
+
+static struct child_process *git_tcp_connect(int fd[2], char *host, int flags)
 {
 	int sockfd = git_tcp_connect_sock(host, flags);
 
 	fd[0] = sockfd;
 	fd[1] = dup(sockfd);
+
+	return &no_fork;
 }
 
 
@@ -761,8 +770,6 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
 	return protocol;
 }
 
-static struct child_process no_fork = CHILD_PROCESS_INIT;
-
 static const char *get_ssh_command(void)
 {
 	const char *ssh;
@@ -865,7 +872,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 				  const char *prog, int flags)
 {
 	char *hostandport, *path;
-	struct child_process *conn = &no_fork;
+	struct child_process *conn;
 	enum protocol protocol;
 
 	/* Without this we cannot rely on waitpid() to tell
@@ -901,7 +908,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 		if (git_use_proxy(hostandport))
 			conn = git_proxy_connect(fd, hostandport);
 		else
-			git_tcp_connect(fd, hostandport, flags);
+			conn = git_tcp_connect(fd, hostandport, flags);
 		/*
 		 * Separate original protocol components prog and path
 		 * from extended host header with a NUL byte.
@@ -1041,11 +1048,6 @@ struct child_process *git_connect(int fd[2], const char *url,
 	return conn;
 }
 
-int git_connection_is_socket(struct child_process *conn)
-{
-	return conn == &no_fork;
-}
-
 int finish_connect(struct child_process *conn)
 {
 	int code;
Signature · 1 line
2.15.0.448.gf294e3d99a
#124 lore raw

Re: [PATCH 1/5] connect: split git:// setup into a separate function

Quoted 8 lines · Jonathan Nieder
Quoted 6 lines

Which means the defaulting of git_connect::conn to &no_fork is now unneeded. One of the things that made the original cascade a bit harder to follow than necessary, aside from the physical length of the PROTO_GIT part, was that the case where conn remains to point at no_fork looked very special and it was buried in that long PROTO_GIT part.

Good idea. Here's what I'll include in the reroll.

Sounds good.