This patch appears to fix the custom ports/plink problem with a patch to
git's core code. Some issues with the patch:

- It's highly Windows specific, so if it is to be merged upstream, needs
to be encapsulated with pre-compiler directives.

- I couldn't figure out how to get git to forward stdin to plink (it
works fine with OpenSSH, but not for plink, I suspect MingW). So I was
forced to put plink in verbose batch mode to prevent mysterious errors.
Namely, if a host you're connecting to is not on the list of known
hosts, PuTTY will terminate the connection. I don't know how to tell the
user nicely to manually interact with PuTTY to get the host into the
known keys list, but it shouldn't be too much of a problem.

- I arbitrarily increased the allocation to arg. I think I could have
gotten away with one less sizeof(*arg).

- There's a little bit of duplication with *arg++ = port; Dunno if we'd
like to take it outside of the conditional.

- I'm stupid, and a C n00b, so there are probably more problems with the
patch.

If things are good, it would be cool if someone am'ed it into the public
repository.

-- 
 Edward Z. Yang                        GnuPG: 0x869C48DA
 HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter
 [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
From de486e3ab19486b3b3e43e3cc272dacce79662ed Mon Sep 17 00:00:00 2001
From: Edward Z. Yang <[EMAIL PROTECTED]>
Date: Thu, 5 Jun 2008 00:17:50 -0400
Subject: [PATCH] Add support for plink as GIT_SSH, by using alternate port 
syntax.

---
 connect.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/connect.c b/connect.c
index 8d600c9..08598cd 100644
--- a/connect.c
+++ b/connect.c
@@ -595,15 +595,28 @@ struct child_process *git_connect(int fd[2], const char 
*url_orig,
                die("command line too long");
 
        conn->in = conn->out = -1;
-       conn->argv = arg = xcalloc(6, sizeof(*arg));
+       /* be sure to increase this size if you add more args */
+       conn->argv = arg = xcalloc(9, sizeof(*arg));
        if (protocol == PROTO_SSH) {
                const char *ssh = getenv("GIT_SSH");
+               int putty = ssh && strlen(ssh) >= 5 && strstr(ssh, "plink");
                if (!ssh) ssh = "ssh";
 
                *arg++ = ssh;
+               if (putty) {
+                       *arg++ = "-batch";
+                       *arg++ = "-v";
+               }
                if (port) {
-                       *arg++ = "-p";
-                       *arg++ = port;
+                       if (putty) {
+                               /* using PuTTY */
+                               *arg++ = "-P";
+                               *arg++ = port;
+                       } else {
+                               /* using OpenSSH */
+                               *arg++ = "-p";
+                               *arg++ = port;
+                       }
                }
                *arg++ = host;
        }
-- 
1.5.5.1015.g9d258.dirty

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to