connect: display connection progress
Make git notify the user about host resolution/connection attempts. This is useful both as a progress indicator on slow links, and helps reassure the user there are no firewall problems. Signed-off-by: Michael S. Tsirkin <mst@dev.mellanox.co.il> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Michael S. Tsirkin committed
May 16, 2007 at 20:09 UTC
7841ce79854868eaaa146c1d018b17fc4f3320be
6 files changed
+30
-11
builtin-archive.c
+1
-1
@@ -45,7 +45,7 @@ static int run_remote_archiver(const char *remote, int argc,
45
}
46
47
url = xstrdup(remote);
48
- pid = git_connect(fd, url, exec);
48
+ pid = git_connect(fd, url, exec, 0);
49
if (pid < 0)
50
return pid;
51
cache.h
+2
-1
@@ -463,7 +463,8 @@ struct ref {
463
#define REF_HEADS (1u << 1)
464
#define REF_TAGS (1u << 2)
465
466
-extern pid_t git_connect(int fd[2], char *url, const char *prog);
466
+#define CONNECT_VERBOSE (1u << 0)
467
+extern pid_t git_connect(int fd[2], char *url, const char *prog, int flags);
468
extern int finish_connect(pid_t pid);
469
extern int path_match(const char *path, int nr, char **match);
470
extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
connect.c
+24
-6
@@ -394,7 +394,7 @@ static enum protocol get_protocol(const char *name)
394
/*
395
* Returns a connected socket() fd, or else die()s.
396
*/
397
-static int git_tcp_connect_sock(char *host)
397
+static int git_tcp_connect_sock(char *host, int flags)
398
{
399
int sockfd = -1, saved_errno = 0;
400
char *colon, *end;
@@ -425,10 +425,16 @@ static int git_tcp_connect_sock(char *host)
425
hints.ai_socktype = SOCK_STREAM;
426
hints.ai_protocol = IPPROTO_TCP;
427
428
+ if (flags & CONNECT_VERBOSE)
429
+ fprintf(stderr, "Looking up %s ... ", host);
430
+
431
gai = getaddrinfo(host, port, &hints, &ai);
432
if (gai)
433
die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai));
434
435
+ if (flags & CONNECT_VERBOSE)
436
+ fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
437
+
438
for (ai0 = ai; ai; ai = ai->ai_next) {
439
sockfd = socket(ai->ai_family,
440
ai->ai_socktype, ai->ai_protocol);
@@ -450,6 +456,9 @@ static int git_tcp_connect_sock(char *host)
456
if (sockfd < 0)
457
die("unable to connect a socket (%s)", strerror(saved_errno));
458
459
+ if (flags & CONNECT_VERBOSE)
460
+ fprintf(stderr, "done.\n");
461
+
462
return sockfd;
463
}
464
@@ -458,7 +467,7 @@ static int git_tcp_connect_sock(char *host)
467
/*
468
* Returns a connected socket() fd, or else die()s.
469
*/
461
-static int git_tcp_connect_sock(char *host)
470
+static int git_tcp_connect_sock(char *host, int flags)
471
{
472
int sockfd = -1, saved_errno = 0;
473
char *colon, *end;
@@ -485,6 +494,9 @@ static int git_tcp_connect_sock(char *host)
494
port = colon + 1;
495
}
496
497
+ if (flags & CONNECT_VERBOSE)
498
+ fprintf(stderr, "Looking up %s ... ", host);
499
+
500
he = gethostbyname(host);
501
if (!he)
502
die("Unable to look up %s (%s)", host, hstrerror(h_errno));
@@ -497,6 +509,9 @@ static int git_tcp_connect_sock(char *host)
509
nport = se->s_port;
510
}
511
512
+ if (flags & CONNECT_VERBOSE)
513
+ fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port);
514
+
515
for (ap = he->h_addr_list; *ap; ap++) {
516
sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
517
if (sockfd < 0) {
@@ -521,15 +536,18 @@ static int git_tcp_connect_sock(char *host)
536
if (sockfd < 0)
537
die("unable to connect a socket (%s)", strerror(saved_errno));
538
539
+ if (flags & CONNECT_VERBOSE)
540
+ fprintf(stderr, "done.\n");
541
+
542
return sockfd;
543
}
544
545
#endif /* NO_IPV6 */
546
547
530
-static void git_tcp_connect(int fd[2], char *host)
548
+static void git_tcp_connect(int fd[2], char *host, int flags)
549
{
532
- int sockfd = git_tcp_connect_sock(host);
550
+ int sockfd = git_tcp_connect_sock(host, flags);
551
552
fd[0] = sockfd;
553
fd[1] = dup(sockfd);
@@ -646,7 +664,7 @@ static void git_proxy_connect(int fd[2], char *host)
664
*
665
* Does not return a negative value on error; it just dies.
666
*/
649
-pid_t git_connect(int fd[2], char *url, const char *prog)
667
+pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
668
{
669
char *host, *path = url;
670
char *end;
@@ -719,7 +737,7 @@ pid_t git_connect(int fd[2], char *url, const char *prog)
737
if (git_use_proxy(host))
738
git_proxy_connect(fd, host);
739
else
722
- git_tcp_connect(fd, host);
740
+ git_tcp_connect(fd, host, flags);
741
/*
742
* Separate original protocol components prog and path
743
* from extended components with a NUL byte.
fetch-pack.c
+1
-1
@@ -733,7 +733,7 @@ int main(int argc, char **argv)
733
}
734
if (!dest)
735
usage(fetch_pack_usage);
736
- pid = git_connect(fd, dest, uploadpack);
736
+ pid = git_connect(fd, dest, uploadpack, verbose ? CONNECT_VERBOSE : 0);
737
if (pid < 0)
738
return 1;
739
if (heads && nr_heads)
peek-remote.c
+1
-1
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
64
if (!dest || i != argc - 1)
65
usage(peek_remote_usage);
66
67
- pid = git_connect(fd, dest, uploadpack);
67
+ pid = git_connect(fd, dest, uploadpack, 0);
68
if (pid < 0)
69
return 1;
70
ret = peek_remote(fd, flags);
send-pack.c
+1
-1
@@ -393,7 +393,7 @@ int main(int argc, char **argv)
393
usage(send_pack_usage);
394
verify_remote_names(nr_heads, heads);
395
396
- pid = git_connect(fd, dest, receivepack);
396
+ pid = git_connect(fd, dest, receivepack, verbose ? CONNECT_VERBOSE : 0);
397
if (pid < 0)
398
return 1;
399
ret = send_pack(fd[0], fd[1], nr_heads, heads);