@matheusbsbs / matheus-bagliano / commits / a48b409f9c
Fork 0

git_connect: clarify conn->use_shell flag

When executing user-specified programs, we generally always want to use a shell, for flexibility and consistency. One big exception is executing $GIT_SSH, which for historical reasons must not use a shell. Once upon a time the logic in git_connect looked like: if (protocol == PROTO_SSH) { ... setup ssh ... } else { ... setup local connection ... conn->use_shell = 1; } But over time the PROTO_SSH block has grown, and the "local" block has shrunk so that it contains only conn->use_shell; it's easy to miss at the end of the large block. Moreover, PROTO_SSH now also sometimes sets use_shell, when the new GIT_SSH_COMMAND is used. Let's just set conn->use_shell when we're setting up the "conn" struct, and unset it (with a comment) in the historical GIT_SSH case. This will make the flow easier to follow. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 8, 2015 at 04:33 UTC a48b409f9ccd4e1957286ba064fd3a25a9ea2b56
1 file changed +13 -9
connect.c
+13 -9
@@ -723,10 +723,11 @@ struct child_process *git_connect(int fd[2], const char *url,
723
724 /* remove repo-local variables from the environment */
725 conn->env = local_repo_env;
726 + conn->use_shell = 1;
727 conn->in = conn->out = -1;
728 if (protocol == PROTO_SSH) {
729 const char *ssh;
729 - int putty, tortoiseplink = 0;
730 + int putty = 0, tortoiseplink = 0;
731 char *ssh_host = hostandport;
732 const char *port = NULL;
733 get_host_and_port(&ssh_host, &port);
@@ -748,13 +749,17 @@ struct child_process *git_connect(int fd[2], const char *url,
749 }
750
751 ssh = getenv("GIT_SSH_COMMAND");
751 - if (ssh) {
752 - conn->use_shell = 1;
753 - putty = 0;
754 - } else {
752 + if (!ssh) {
753 const char *base;
754 char *ssh_dup;
755
756 + /*
757 + * GIT_SSH is the no-shell version of
758 + * GIT_SSH_COMMAND (and must remain so for
759 + * historical compatibility).
760 + */
761 + conn->use_shell = 0;
762 +
763 ssh = getenv("GIT_SSH");
764 if (!ssh)
765 ssh = "ssh";
@@ -764,8 +769,9 @@ struct child_process *git_connect(int fd[2], const char *url,
769
770 tortoiseplink = !strcasecmp(base, "tortoiseplink") ||
771 !strcasecmp(base, "tortoiseplink.exe");
767 - putty = !strcasecmp(base, "plink") ||
768 - !strcasecmp(base, "plink.exe") || tortoiseplink;
772 + putty = tortoiseplink ||
773 + !strcasecmp(base, "plink") ||
774 + !strcasecmp(base, "plink.exe");
775
776 free(ssh_dup);
777 }
@@ -779,8 +785,6 @@ struct child_process *git_connect(int fd[2], const char *url,
785 argv_array_push(&conn->args, port);
786 }
787 argv_array_push(&conn->args, ssh_host);
782 - } else {
783 - conn->use_shell = 1;
788 }
789 argv_array_push(&conn->args, cmd.buf);
790