pkt-line: share buffer/descriptor reading implementation
[git/git.git] / connect.c
CommitLineData
731043fd 1#include "git-compat-util.h"
f7192598 2#include "cache.h"
41cb7488 3#include "pkt-line.h"
b10d0ec7 4#include "quote.h"
6abf5c0c 5#include "refs.h"
15a1c012 6#include "run-command.h"
6b62816c 7#include "remote.h"
9d2e9420 8#include "url.h"
f7192598 9
96f1e58f 10static char *server_capabilities;
211b5f9e 11
2718ff09
LT
12static int check_ref(const char *name, int len, unsigned int flags)
13{
14 if (!flags)
15 return 1;
16
c41e20b3 17 if (len < 5 || memcmp(name, "refs/", 5))
2718ff09
LT
18 return 0;
19
20 /* Skip the "refs/" part */
21 name += 5;
22 len -= 5;
23
24 /* REF_NORMAL means that we don't want the magic fake tag refs */
8d9c5010 25 if ((flags & REF_NORMAL) && check_refname_format(name, 0))
2718ff09
LT
26 return 0;
27
28 /* REF_HEADS means that we want regular branch heads */
29 if ((flags & REF_HEADS) && !memcmp(name, "heads/", 6))
30 return 1;
31
32 /* REF_TAGS means that we want tags */
33 if ((flags & REF_TAGS) && !memcmp(name, "tags/", 5))
34 return 1;
35
36 /* All type bits clear means that we are ok with anything */
37 return !(flags & ~REF_NORMAL);
38}
39
4577370e
DB
40int check_ref_type(const struct ref *ref, int flags)
41{
42 return check_ref(ref->name, strlen(ref->name), flags);
43}
44
40c155ff
JH
45static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1)
46{
47 ALLOC_GROW(extra->array, extra->nr + 1, extra->alloc);
48 hashcpy(&(extra->array[extra->nr][0]), sha1);
49 extra->nr++;
50}
51
46284dd1
HV
52static void die_initial_contact(int got_at_least_one_head)
53{
54 if (got_at_least_one_head)
55 die("The remote end hung up upon initial contact");
56 else
57 die("Could not read from remote repository.\n\n"
58 "Please make sure you have the correct access rights\n"
59 "and the repository exists.");
60}
61
d1c133f5
LT
62/*
63 * Read all the refs from the other end
64 */
1a7141ff 65struct ref **get_remote_heads(int in, struct ref **list,
40c155ff
JH
66 unsigned int flags,
67 struct extra_have_objects *extra_have)
d1c133f5 68{
46284dd1
HV
69 int got_at_least_one_head = 0;
70
d1c133f5
LT
71 *list = NULL;
72 for (;;) {
73 struct ref *ref;
74 unsigned char old_sha1[20];
d1c133f5 75 char *name;
211b5f9e 76 int len, name_len;
74543a04 77 char *buffer = packet_buffer;
d1c133f5 78
4981fe75
JK
79 len = packet_read(in, NULL, NULL,
80 packet_buffer, sizeof(packet_buffer),
819b929d
JK
81 PACKET_READ_GENTLE_ON_EOF |
82 PACKET_READ_CHOMP_NEWLINE);
46284dd1
HV
83 if (len < 0)
84 die_initial_contact(got_at_least_one_head);
85
d1c133f5
LT
86 if (!len)
87 break;
d1c133f5 88
a8073289
TPW
89 if (len > 4 && !prefixcmp(buffer, "ERR "))
90 die("remote error: %s", buffer + 4);
91
d1c133f5
LT
92 if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
93 die("protocol error: expected sha/ref, got '%s'", buffer);
94 name = buffer + 41;
1a7141ff 95
211b5f9e
JS
96 name_len = strlen(name);
97 if (len != name_len + 41) {
8e0f7003 98 free(server_capabilities);
9befac47 99 server_capabilities = xstrdup(name + name_len + 1);
211b5f9e
JS
100 }
101
40c155ff
JH
102 if (extra_have &&
103 name_len == 5 && !memcmp(".have", name, 5)) {
104 add_extra_have(extra_have, old_sha1);
105 continue;
106 }
107
2718ff09 108 if (!check_ref(name, name_len, flags))
cfee10a7 109 continue;
59c69c0c 110 ref = alloc_ref(buffer + 41);
e702496e 111 hashcpy(ref->old_sha1, old_sha1);
d1c133f5
LT
112 *list = ref;
113 list = &ref->next;
46284dd1 114 got_at_least_one_head = 1;
d1c133f5
LT
115 }
116 return list;
117}
118
94427108 119const char *parse_feature_value(const char *feature_list, const char *feature, int *lenp)
f47182c8
JH
120{
121 int len;
122
123 if (!feature_list)
124 return NULL;
125
126 len = strlen(feature);
127 while (*feature_list) {
128 const char *found = strstr(feature_list, feature);
129 if (!found)
130 return NULL;
94427108
JK
131 if (feature_list == found || isspace(found[-1])) {
132 const char *value = found + len;
133 /* feature with no value (e.g., "thin-pack") */
134 if (!*value || isspace(*value)) {
135 if (lenp)
136 *lenp = 0;
137 return value;
138 }
139 /* feature with a value (e.g., "agent=git/1.2.3") */
140 else if (*value == '=') {
141 value++;
142 if (lenp)
143 *lenp = strcspn(value, " \t\n");
144 return value;
145 }
146 /*
147 * otherwise we matched a substring of another feature;
148 * keep looking
149 */
150 }
f47182c8
JH
151 feature_list = found + 1;
152 }
153 return NULL;
211b5f9e
JS
154}
155
94427108
JK
156int parse_feature_request(const char *feature_list, const char *feature)
157{
158 return !!parse_feature_value(feature_list, feature, NULL);
159}
160
161const char *server_feature_value(const char *feature, int *len)
162{
163 return parse_feature_value(server_capabilities, feature, len);
164}
165
166int server_supports(const char *feature)
167{
168 return !!server_feature_value(feature, NULL);
169}
170
2386d658
LT
171enum protocol {
172 PROTO_LOCAL = 1,
173 PROTO_SSH,
4b05548f 174 PROTO_GIT
2386d658
LT
175};
176
177static enum protocol get_protocol(const char *name)
178{
179 if (!strcmp(name, "ssh"))
180 return PROTO_SSH;
181 if (!strcmp(name, "git"))
182 return PROTO_GIT;
c05186cc
LT
183 if (!strcmp(name, "git+ssh"))
184 return PROTO_SSH;
185 if (!strcmp(name, "ssh+git"))
186 return PROTO_SSH;
72a4f4b6
LT
187 if (!strcmp(name, "file"))
188 return PROTO_LOCAL;
2386d658
LT
189 die("I don't handle protocol '%s'", name);
190}
191
5ba88448
YH
192#define STR_(s) # s
193#define STR(s) STR_(s)
2386d658 194
72a534da
ML
195static void get_host_and_port(char **host, const char **port)
196{
197 char *colon, *end;
198
199 if (*host[0] == '[') {
200 end = strchr(*host + 1, ']');
201 if (end) {
202 *end = 0;
203 end++;
204 (*host)++;
205 } else
206 end = *host;
207 } else
208 end = *host;
209 colon = strchr(end, ':');
210
211 if (colon) {
212 *colon = 0;
213 *port = colon + 1;
214 }
215}
216
e47a8583
EW
217static void enable_keepalive(int sockfd)
218{
219 int ka = 1;
220
221 if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0)
222 fprintf(stderr, "unable to set SO_KEEPALIVE on socket: %s\n",
223 strerror(errno));
224}
225
49744d63 226#ifndef NO_IPV6
4c505f71 227
ba505322
AR
228static const char *ai_name(const struct addrinfo *ai)
229{
785a9857
BK
230 static char addr[NI_MAXHOST];
231 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, addr, sizeof(addr), NULL, 0,
232 NI_NUMERICHOST) != 0)
ba505322 233 strcpy(addr, "(unknown)");
785a9857 234
ba505322
AR
235 return addr;
236}
237
5ad312be
JL
238/*
239 * Returns a connected socket() fd, or else die()s.
240 */
7841ce79 241static int git_tcp_connect_sock(char *host, int flags)
2386d658 242{
63a995b6
DZ
243 struct strbuf error_message = STRBUF_INIT;
244 int sockfd = -1;
554fe20d 245 const char *port = STR(DEFAULT_GIT_PORT);
5ba88448
YH
246 struct addrinfo hints, *ai0, *ai;
247 int gai;
ba505322 248 int cnt = 0;
5ba88448 249
72a534da
ML
250 get_host_and_port(&host, &port);
251 if (!*port)
252 port = "<none>";
5ba88448
YH
253
254 memset(&hints, 0, sizeof(hints));
255 hints.ai_socktype = SOCK_STREAM;
256 hints.ai_protocol = IPPROTO_TCP;
257
7841ce79
MT
258 if (flags & CONNECT_VERBOSE)
259 fprintf(stderr, "Looking up %s ... ", host);
260
5ba88448
YH
261 gai = getaddrinfo(host, port, &hints, &ai);
262 if (gai)
608d48b2 263 die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai));
5ba88448 264
7841ce79
MT
265 if (flags & CONNECT_VERBOSE)
266 fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
267
e08afecd 268 for (ai0 = ai; ai; ai = ai->ai_next, cnt++) {
5ad312be
JL
269 sockfd = socket(ai->ai_family,
270 ai->ai_socktype, ai->ai_protocol);
63a995b6
DZ
271 if ((sockfd < 0) ||
272 (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0)) {
273 strbuf_addf(&error_message, "%s[%d: %s]: errno=%s\n",
274 host, cnt, ai_name(ai), strerror(errno));
275 if (0 <= sockfd)
276 close(sockfd);
5ba88448
YH
277 sockfd = -1;
278 continue;
2386d658 279 }
ba505322
AR
280 if (flags & CONNECT_VERBOSE)
281 fprintf(stderr, "%s ", ai_name(ai));
5ba88448 282 break;
2386d658
LT
283 }
284
5ba88448 285 freeaddrinfo(ai0);
2386d658 286
2386d658 287 if (sockfd < 0)
63a995b6 288 die("unable to connect to %s:\n%s", host, error_message.buf);
5ba88448 289
e47a8583
EW
290 enable_keepalive(sockfd);
291
7841ce79
MT
292 if (flags & CONNECT_VERBOSE)
293 fprintf(stderr, "done.\n");
294
63a995b6
DZ
295 strbuf_release(&error_message);
296
5ad312be 297 return sockfd;
2386d658
LT
298}
299
49744d63 300#else /* NO_IPV6 */
4c505f71 301
5ad312be
JL
302/*
303 * Returns a connected socket() fd, or else die()s.
304 */
7841ce79 305static int git_tcp_connect_sock(char *host, int flags)
4c505f71 306{
7203a2d1
EFL
307 struct strbuf error_message = STRBUF_INIT;
308 int sockfd = -1;
72a534da
ML
309 const char *port = STR(DEFAULT_GIT_PORT);
310 char *ep;
4c505f71
PA
311 struct hostent *he;
312 struct sockaddr_in sa;
313 char **ap;
314 unsigned int nport;
ba505322 315 int cnt;
4c505f71 316
72a534da 317 get_host_and_port(&host, &port);
4c505f71 318
7841ce79
MT
319 if (flags & CONNECT_VERBOSE)
320 fprintf(stderr, "Looking up %s ... ", host);
321
4c505f71
PA
322 he = gethostbyname(host);
323 if (!he)
324 die("Unable to look up %s (%s)", host, hstrerror(h_errno));
325 nport = strtoul(port, &ep, 10);
326 if ( ep == port || *ep ) {
327 /* Not numeric */
328 struct servent *se = getservbyname(port,"tcp");
329 if ( !se )
d7530708 330 die("Unknown port %s", port);
4c505f71
PA
331 nport = se->s_port;
332 }
333
7841ce79
MT
334 if (flags & CONNECT_VERBOSE)
335 fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
336
ba505322 337 for (cnt = 0, ap = he->h_addr_list; *ap; ap++, cnt++) {
4c505f71
PA
338 memset(&sa, 0, sizeof sa);
339 sa.sin_family = he->h_addrtype;
6573faff 340 sa.sin_port = htons(nport);
c6164218 341 memcpy(&sa.sin_addr, *ap, he->h_length);
4c505f71 342
7203a2d1
EFL
343 sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
344 if ((sockfd < 0) ||
345 connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
346 strbuf_addf(&error_message, "%s[%d: %s]: errno=%s\n",
ba505322
AR
347 host,
348 cnt,
349 inet_ntoa(*(struct in_addr *)&sa.sin_addr),
7203a2d1
EFL
350 strerror(errno));
351 if (0 <= sockfd)
352 close(sockfd);
4c505f71
PA
353 sockfd = -1;
354 continue;
355 }
ba505322
AR
356 if (flags & CONNECT_VERBOSE)
357 fprintf(stderr, "%s ",
358 inet_ntoa(*(struct in_addr *)&sa.sin_addr));
4c505f71
PA
359 break;
360 }
361
362 if (sockfd < 0)
7203a2d1 363 die("unable to connect to %s:\n%s", host, error_message.buf);
4c505f71 364
e47a8583
EW
365 enable_keepalive(sockfd);
366
7841ce79
MT
367 if (flags & CONNECT_VERBOSE)
368 fprintf(stderr, "done.\n");
369
5ad312be
JL
370 return sockfd;
371}
372
373#endif /* NO_IPV6 */
374
375
7841ce79 376static void git_tcp_connect(int fd[2], char *host, int flags)
5ad312be 377{
7841ce79 378 int sockfd = git_tcp_connect_sock(host, flags);
5ad312be 379
4c505f71 380 fd[0] = sockfd;
ec587fde 381 fd[1] = dup(sockfd);
4c505f71
PA
382}
383
4c505f71 384
96f1e58f 385static char *git_proxy_command;
f8014776 386
ef90d6d4
JS
387static int git_proxy_command_options(const char *var, const char *value,
388 void *cb)
f8014776 389{
e814bc4d 390 if (!strcmp(var, "core.gitproxy")) {
c3df8568
YH
391 const char *for_pos;
392 int matchlen = -1;
393 int hostlen;
15112c95
EFL
394 const char *rhost_name = cb;
395 int rhost_len = strlen(rhost_name);
c3df8568 396
e814bc4d 397 if (git_proxy_command)
f8014776 398 return 0;
c64b9ad0
JH
399 if (!value)
400 return config_error_nonbool(var);
e814bc4d
JH
401 /* [core]
402 * ;# matches www.kernel.org as well
403 * gitproxy = netcatter-1 for kernel.org
404 * gitproxy = netcatter-2 for sample.xz
405 * gitproxy = netcatter-default
406 */
c3df8568 407 for_pos = strstr(value, " for ");
e814bc4d
JH
408 if (!for_pos)
409 /* matches everybody */
410 matchlen = strlen(value);
411 else {
412 hostlen = strlen(for_pos + 5);
413 if (rhost_len < hostlen)
414 matchlen = -1;
415 else if (!strncmp(for_pos + 5,
416 rhost_name + rhost_len - hostlen,
417 hostlen) &&
418 ((rhost_len == hostlen) ||
419 rhost_name[rhost_len - hostlen -1] == '.'))
420 matchlen = for_pos - value;
421 else
422 matchlen = -1;
423 }
424 if (0 <= matchlen) {
425 /* core.gitproxy = none for kernel.org */
a6080a0a 426 if (matchlen == 4 &&
e814bc4d
JH
427 !memcmp(value, "none", 4))
428 matchlen = 0;
182af834 429 git_proxy_command = xmemdupz(value, matchlen);
f8014776 430 }
e814bc4d 431 return 0;
f8014776
PC
432 }
433
ef90d6d4 434 return git_default_config(var, value, cb);
f8014776
PC
435}
436
e814bc4d 437static int git_use_proxy(const char *host)
f8014776
PC
438{
439 git_proxy_command = getenv("GIT_PROXY_COMMAND");
15112c95 440 git_config(git_proxy_command_options, (void*)host);
e814bc4d 441 return (git_proxy_command && *git_proxy_command);
f8014776
PC
442}
443
5cbf8246 444static struct child_process *git_proxy_connect(int fd[2], char *host)
f8014776 445{
554fe20d 446 const char *port = STR(DEFAULT_GIT_PORT);
5cbf8246
JK
447 const char **argv;
448 struct child_process *proxy;
f8014776 449
72a534da 450 get_host_and_port(&host, &port);
f8014776 451
5cbf8246 452 argv = xmalloc(sizeof(*argv) * 4);
15a1c012
SP
453 argv[0] = git_proxy_command;
454 argv[1] = host;
455 argv[2] = port;
456 argv[3] = NULL;
5cbf8246
JK
457 proxy = xcalloc(1, sizeof(*proxy));
458 proxy->argv = argv;
459 proxy->in = -1;
460 proxy->out = -1;
461 if (start_command(proxy))
15a1c012 462 die("cannot start proxy %s", argv[0]);
5cbf8246
JK
463 fd[0] = proxy->out; /* read from proxy stdout */
464 fd[1] = proxy->in; /* write to proxy stdin */
465 return proxy;
f8014776
PC
466}
467
0f503d77
CC
468#define MAX_CMD_LEN 1024
469
2af202be 470static char *get_port(char *host)
2e776665
LT
471{
472 char *end;
473 char *p = strchr(host, ':');
474
475 if (p) {
8f148253
RS
476 long port = strtol(p + 1, &end, 10);
477 if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
2e776665
LT
478 *p = '\0';
479 return p+1;
480 }
481 }
482
483 return NULL;
484}
485
fb32c917
JS
486static struct child_process no_fork;
487
f7192598 488/*
fb32c917
JS
489 * This returns a dummy child_process if the transport protocol does not
490 * need fork(2), or a struct child_process object if it does. Once done,
491 * finish the connection with finish_connect() with the value returned from
492 * this function (it is safe to call finish_connect() with NULL to support
493 * the former case).
f42a5c4e 494 *
fb32c917
JS
495 * If it returns, the connect is successful; it just dies on errors (this
496 * will hopefully be changed in a libification effort, to return NULL when
497 * the connection failed).
f7192598 498 */
4577370e 499struct child_process *git_connect(int fd[2], const char *url_orig,
98158e9c 500 const char *prog, int flags)
f7192598 501{
9d2e9420 502 char *url;
8e76bf3f 503 char *host, *path;
356bece0
YH
504 char *end;
505 int c;
5cbf8246 506 struct child_process *conn = &no_fork;
faea9ccb 507 enum protocol protocol = PROTO_LOCAL;
da2a95b2 508 int free_path = 0;
2e776665 509 char *port = NULL;
f364cb88
JS
510 const char **arg;
511 struct strbuf cmd;
faea9ccb 512
f0b7367c
JH
513 /* Without this we cannot rely on waitpid() to tell
514 * what happened to our children.
515 */
516 signal(SIGCHLD, SIG_DFL);
517
9d2e9420
JK
518 if (is_url(url_orig))
519 url = url_decode(url_orig);
520 else
521 url = xstrdup(url_orig);
522
faea9ccb 523 host = strstr(url, "://");
eeefa7c9 524 if (host) {
faea9ccb
AE
525 *host = '\0';
526 protocol = get_protocol(url);
527 host += 3;
356bece0
YH
528 c = '/';
529 } else {
f7192598 530 host = url;
356bece0
YH
531 c = ':';
532 }
533
9aa5053d
IL
534 /*
535 * Don't do destructive transforms with git:// as that
9517e6b8 536 * protocol code does '[]' unwrapping of its own.
9aa5053d 537 */
356bece0
YH
538 if (host[0] == '[') {
539 end = strchr(host + 1, ']');
540 if (end) {
9aa5053d
IL
541 if (protocol != PROTO_GIT) {
542 *end = 0;
543 host++;
544 }
356bece0 545 end++;
356bece0
YH
546 } else
547 end = host;
548 } else
549 end = host;
550
551 path = strchr(end, c);
be501813 552 if (path && !has_dos_drive_prefix(end)) {
72a4f4b6 553 if (c == ':') {
faea9ccb 554 protocol = PROTO_SSH;
356bece0 555 *path++ = '\0';
72a4f4b6
LT
556 }
557 } else
558 path = end;
2386d658 559
faea9ccb
AE
560 if (!path || !*path)
561 die("No path specified. See 'man git-pull' for valid url syntax");
562
563 /*
564 * null-terminate hostname and point path to ~ for URL's like this:
565 * ssh://host.xz/~user/repo
566 */
567 if (protocol != PROTO_LOCAL && host != url) {
568 char *ptr = path;
569 if (path[1] == '~')
570 path++;
da2a95b2 571 else {
9befac47 572 path = xstrdup(ptr);
da2a95b2
SH
573 free_path = 1;
574 }
faea9ccb
AE
575
576 *ptr = '\0';
577 }
578
2e776665
LT
579 /*
580 * Add support for ssh port: ssh://host.xy:<port>/...
581 */
582 if (protocol == PROTO_SSH && host != url)
7acf4382 583 port = get_port(end);
2e776665 584
f8014776 585 if (protocol == PROTO_GIT) {
5ad312be
JL
586 /* These underlying connection commands die() if they
587 * cannot connect.
588 */
9befac47 589 char *target_host = xstrdup(host);
e814bc4d 590 if (git_use_proxy(host))
5cbf8246 591 conn = git_proxy_connect(fd, host);
da2a95b2 592 else
7841ce79 593 git_tcp_connect(fd, host, flags);
5ad312be
JL
594 /*
595 * Separate original protocol components prog and path
73bb33a9
SP
596 * from extended host header with a NUL byte.
597 *
598 * Note: Do not add any other headers here! Doing so
599 * will cause older git-daemon servers to crash.
5ad312be
JL
600 */
601 packet_write(fd[1],
602 "%s %s%chost=%s%c",
603 prog, path, 0,
604 target_host, 0);
605 free(target_host);
4577370e 606 free(url);
da2a95b2
SH
607 if (free_path)
608 free(path);
5cbf8246 609 return conn;
f8014776 610 }
2386d658 611
98158e9c 612 conn = xcalloc(1, sizeof(*conn));
2e776665 613
f364cb88
JS
614 strbuf_init(&cmd, MAX_CMD_LEN);
615 strbuf_addstr(&cmd, prog);
616 strbuf_addch(&cmd, ' ');
617 sq_quote_buf(&cmd, path);
618 if (cmd.len >= MAX_CMD_LEN)
619 die("command line too long");
620
621 conn->in = conn->out = -1;
36ad53ff 622 conn->argv = arg = xcalloc(7, sizeof(*arg));
f364cb88
JS
623 if (protocol == PROTO_SSH) {
624 const char *ssh = getenv("GIT_SSH");
36ad53ff 625 int putty = ssh && strcasestr(ssh, "plink");
f364cb88
JS
626 if (!ssh) ssh = "ssh";
627
628 *arg++ = ssh;
36ad53ff
EY
629 if (putty && !strcasestr(ssh, "tortoiseplink"))
630 *arg++ = "-batch";
f364cb88 631 if (port) {
36ad53ff
EY
632 /* P is for PuTTY, p is for OpenSSH */
633 *arg++ = putty ? "-P" : "-p";
f364cb88 634 *arg++ = port;
4852f723 635 }
f364cb88
JS
636 *arg++ = host;
637 }
638 else {
48a7c1c4
GB
639 /* remove repo-local variables from the environment */
640 conn->env = local_repo_env;
4cfb2a44 641 conn->use_shell = 1;
016fb48b 642 }
f364cb88
JS
643 *arg++ = cmd.buf;
644 *arg = NULL;
645
646 if (start_command(conn))
647 die("unable to fork");
648
649 fd[0] = conn->out; /* read from child's stdout */
650 fd[1] = conn->in; /* write to child's stdin */
651 strbuf_release(&cmd);
4577370e 652 free(url);
da2a95b2
SH
653 if (free_path)
654 free(path);
98158e9c 655 return conn;
f7192598
LT
656}
657
7ffe853b
JK
658int git_connection_is_socket(struct child_process *conn)
659{
660 return conn == &no_fork;
661}
662
98158e9c 663int finish_connect(struct child_process *conn)
f7192598 664{
f364cb88 665 int code;
7ffe853b 666 if (!conn || git_connection_is_socket(conn))
f42a5c4e
FBH
667 return 0;
668
f364cb88
JS
669 code = finish_command(conn);
670 free(conn->argv);
98158e9c 671 free(conn);
f364cb88 672 return code;
f7192598 673}