Merge branch 'mh/ref-directory-file' into maint
[gitweb.git] / connect.c
index 170e391221cfcef7f8a55d635dfcd7cb4c719f92..c0144d859ae4275860df464f73a688c649d092fe 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -310,6 +310,8 @@ static void get_host_and_port(char **host, const char **port)
                if (end != colon + 1 && *end == '\0' && 0 <= portnr && portnr < 65536) {
                        *colon = 0;
                        *port = colon + 1;
+               } else if (!colon[1]) {
+                       *colon = 0;
                }
        }
 }
@@ -722,7 +724,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                conn->in = conn->out = -1;
                if (protocol == PROTO_SSH) {
                        const char *ssh;
-                       int putty;
+                       int putty, tortoiseplink = 0;
                        char *ssh_host = hostandport;
                        const char *port = NULL;
                        get_host_and_port(&ssh_host, &port);
@@ -739,6 +741,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 
                                free(hostandport);
                                free(path);
+                               free(conn);
                                return NULL;
                        }
 
@@ -747,14 +750,26 @@ struct child_process *git_connect(int fd[2], const char *url,
                                conn->use_shell = 1;
                                putty = 0;
                        } else {
+                               const char *base;
+                               char *ssh_dup;
+
                                ssh = getenv("GIT_SSH");
                                if (!ssh)
                                        ssh = "ssh";
-                               putty = !!strcasestr(ssh, "plink");
+
+                               ssh_dup = xstrdup(ssh);
+                               base = basename(ssh_dup);
+
+                               tortoiseplink = !strcasecmp(base, "tortoiseplink") ||
+                                       !strcasecmp(base, "tortoiseplink.exe");
+                               putty = !strcasecmp(base, "plink") ||
+                                       !strcasecmp(base, "plink.exe") || tortoiseplink;
+
+                               free(ssh_dup);
                        }
 
                        argv_array_push(&conn->args, ssh);
-                       if (putty && !strcasestr(ssh, "tortoiseplink"))
+                       if (tortoiseplink)
                                argv_array_push(&conn->args, "-batch");
                        if (port) {
                                /* P is for PuTTY, p is for OpenSSH */