5 #define COMMAND_SIZE 4096
7 int setup_connection(int *fd_in
, int *fd_out
, const char *remote_prog
,
8 char *url
, int rmt_argc
, char **rmt_argv
)
17 if (!strcmp(url
, "-")) {
23 host
= strstr(url
, "//");
26 path
= strchr(host
, '/');
29 path
= strchr(host
, ':');
34 return error("Bad URL: %s", url
);
37 /* $GIT_RSH <host> "env GIT_DIR=<path> <remote_prog> <args...>" */
38 strbuf_init(&cmd
, COMMAND_SIZE
);
39 strbuf_addstr(&cmd
, "env ");
40 strbuf_addstr(&cmd
, GIT_DIR_ENVIRONMENT
"=");
41 sq_quote_buf(&cmd
, path
);
42 strbuf_addch(&cmd
, ' ');
43 sq_quote_buf(&cmd
, remote_prog
);
45 for (i
= 0 ; i
< rmt_argc
; i
++) {
46 strbuf_addch(&cmd
, ' ');
47 sq_quote_buf(&cmd
, rmt_argv
[i
]);
50 strbuf_addstr(&cmd
, " -");
52 if (cmd
.len
>= COMMAND_SIZE
)
53 return error("Command line too long");
55 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, sv
))
56 return error("Couldn't create socket");
60 return error("Couldn't fork");
62 const char *ssh
, *ssh_basename
;
63 ssh
= getenv("GIT_SSH");
64 if (!ssh
) ssh
= "ssh";
65 ssh_basename
= strrchr(ssh
, '/');
73 execlp(ssh
, ssh_basename
, host
, cmd
.buf
, NULL
);