connect: split ssh option computation to its own function
This puts the determination of options to pass to each ssh variant (see ssh.variant in git-config(1)) in one place. A follow-up patch will use this in an initial dry run to detect which variant to use when the ssh command is ambiguous. No functional change intended yet. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Nov 20, 2017 at 13:26 UTC
957e2ad28290076fffe3bf28ae8609c637cf8151
1 file changed
+37
-28
connect.c
+37
-28
@@ -919,6 +919,42 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
919
return conn;
920
}
921
922
+/*
923
+ * Append the appropriate environment variables to `env` and options to
924
+ * `args` for running ssh in Git's SSH-tunneled transport.
925
+ */
926
+static void push_ssh_options(struct argv_array *args, struct argv_array *env,
927
+ enum ssh_variant variant, const char *port,
928
+ int flags)
929
+{
930
+ if (variant == VARIANT_SSH &&
931
+ get_protocol_version_config() > 0) {
932
+ argv_array_push(args, "-o");
933
+ argv_array_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
934
+ argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
935
+ get_protocol_version_config());
936
+ }
937
+
938
+ if (variant != VARIANT_SIMPLE) {
939
+ if (flags & CONNECT_IPV4)
940
+ argv_array_push(args, "-4");
941
+ else if (flags & CONNECT_IPV6)
942
+ argv_array_push(args, "-6");
943
+ }
944
+
945
+ if (variant == VARIANT_TORTOISEPLINK)
946
+ argv_array_push(args, "-batch");
947
+
948
+ if (port && variant != VARIANT_SIMPLE) {
949
+ if (variant == VARIANT_SSH)
950
+ argv_array_push(args, "-p");
951
+ else
952
+ argv_array_push(args, "-P");
953
+
954
+ argv_array_push(args, port);
955
+ }
956
+}
957
+
958
/* Prepare a child_process for use by Git's SSH-tunneled transport. */
959
static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
960
const char *port, int flags)
@@ -947,34 +983,7 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
983
}
984
985
argv_array_push(&conn->args, ssh);
950
-
951
- if (variant == VARIANT_SSH &&
952
- get_protocol_version_config() > 0) {
953
- argv_array_push(&conn->args, "-o");
954
- argv_array_push(&conn->args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
955
- argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
956
- get_protocol_version_config());
957
- }
958
-
959
- if (variant != VARIANT_SIMPLE) {
960
- if (flags & CONNECT_IPV4)
961
- argv_array_push(&conn->args, "-4");
962
- else if (flags & CONNECT_IPV6)
963
- argv_array_push(&conn->args, "-6");
964
- }
965
-
966
- if (variant == VARIANT_TORTOISEPLINK)
967
- argv_array_push(&conn->args, "-batch");
968
-
969
- if (port && variant != VARIANT_SIMPLE) {
970
- if (variant == VARIANT_SSH)
971
- argv_array_push(&conn->args, "-p");
972
- else
973
- argv_array_push(&conn->args, "-P");
974
-
975
- argv_array_push(&conn->args, port);
976
- }
977
-
986
+ push_ssh_options(&conn->args, &conn->env_array, variant, port, flags);
987
argv_array_push(&conn->args, ssh_host);
988
}
989