t5500: show user name and host in diag-url

The URL for ssh may have include a username before the hostname, like ssh://user@host/repo. When literal IPV6 addresses are used together with a username, the substring "user@[::1]" must be converted into "user@::1". Make that conversion visible for the user, and write userandhost in the diagnostics Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Feb 21, 2015 at 16:52 UTC 3f55ccab8e0fec73c8e38b909e9bb4963bfb8f6a
2 files changed +56 -30
connect.c
+23 -12
@@ -675,7 +675,7 @@ struct child_process *git_connect(int fd[2], const char *url,
675 signal(SIGCHLD, SIG_DFL);
676
677 protocol = parse_connect_url(url, &hostandport, &path);
678 - if (flags & CONNECT_DIAG_URL) {
678 + if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
679 printf("Diag: url=%s\n", url ? url : "NULL");
680 printf("Diag: protocol=%s\n", prot_name(protocol));
681 printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
@@ -719,18 +719,29 @@ struct child_process *git_connect(int fd[2], const char *url,
719 get_host_and_port(&ssh_host, &port);
720 if (!port)
721 port = get_port(ssh_host);
722 -
723 - if (!ssh) ssh = "ssh";
724 -
725 - argv_array_push(&conn->args, ssh);
726 - if (putty && !strcasestr(ssh, "tortoiseplink"))
727 - argv_array_push(&conn->args, "-batch");
728 - if (port) {
729 - /* P is for PuTTY, p is for OpenSSH */
730 - argv_array_push(&conn->args, putty ? "-P" : "-p");
731 - argv_array_push(&conn->args, port);
722 + if (flags & CONNECT_DIAG_URL) {
723 + printf("Diag: url=%s\n", url ? url : "NULL");
724 + printf("Diag: protocol=%s\n", prot_name(protocol));
725 + printf("Diag: userandhost=%s\n", ssh_host ? ssh_host : "NULL");
726 + printf("Diag: port=%s\n", port ? port : "NONE");
727 + printf("Diag: path=%s\n", path ? path : "NULL");
728 +
729 + free(hostandport);
730 + free(path);
731 + return NULL;
732 + } else {
733 + if (!ssh) ssh = "ssh";
734 +
735 + argv_array_push(&conn->args, ssh);
736 + if (putty && !strcasestr(ssh, "tortoiseplink"))
737 + argv_array_push(&conn->args, "-batch");
738 + if (port) {
739 + /* P is for PuTTY, p is for OpenSSH */
740 + argv_array_push(&conn->args, putty ? "-P" : "-p");
741 + argv_array_push(&conn->args, port);
742 + }
743 + argv_array_push(&conn->args, ssh_host);
744 }
733 - argv_array_push(&conn->args, ssh_host);
745 } else {
746 /* remove repo-local variables from the environment */
747 conn->env = local_repo_env;
t/t5500-fetch-pack.sh
+33 -18
@@ -541,13 +541,30 @@ check_prot_path () {
541 test_cmp expected actual
542 }
543
544 -check_prot_host_path () {
545 - cat >expected <<-EOF &&
544 +check_prot_host_port_path () {
545 + local diagport
546 + case "$2" in
547 + *ssh*)
548 + pp=ssh
549 + uah=userandhost
550 + ehost=$(echo $3 | tr -d "[]")
551 + diagport="Diag: port=$4"
552 + ;;
553 + *)
554 + pp=$p
555 + uah=hostandport
556 + ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
557 + diagport=""
558 + ;;
559 + esac
560 + cat >exp <<-EOF &&
561 Diag: url=$1
547 - Diag: protocol=$2
548 - Diag: hostandport=$3
549 - Diag: path=$4
562 + Diag: protocol=$pp
563 + Diag: $uah=$ehost
564 + $diagport
565 + Diag: path=$5
566 EOF
567 + grep -v "^$" exp >expected
568 git fetch-pack --diag-url "$1" >actual &&
569 test_cmp expected actual
570 }
@@ -557,22 +574,20 @@ do
574 # git or ssh with scheme
575 for p in "ssh+git" "git+ssh" git ssh
576 do
560 - for h in host host:12 [::1] [::1]:23
577 + for h in host user@host user@[::1] user@::1
578 do
562 - case "$p" in
563 - *ssh*)
564 - pp=ssh
565 - ;;
566 - *)
567 - pp=$p
568 - ;;
569 - esac
579 test_expect_success "fetch-pack --diag-url $p://$h/$r" '
571 - check_prot_host_path $p://$h/$r $pp "$h" "/$r"
580 + check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
581 '
582 # "/~" -> "~" conversion
583 test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
575 - check_prot_host_path $p://$h/~$r $pp "$h" "~$r"
584 + check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
585 + '
586 + done
587 + for h in host User@host User@[::1]
588 + do
589 + test_expect_success "fetch-pack --diag-url $p://$h:22/$r" '
590 + check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
591 '
592 done
593 done
@@ -603,11 +618,11 @@ do
618 for h in host [::1]
619 do
620 test_expect_success "fetch-pack --diag-url $h:$r" '
606 - check_prot_path $h:$r $p "$r"
621 + check_prot_host_port_path $h:$r $p "$h" NONE "$r"
622 '
623 # Do "/~" -> "~" conversion
624 test_expect_success "fetch-pack --diag-url $h:/~$r" '
610 - check_prot_host_path $h:/~$r $p "$h" "~$r"
625 + check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
626 '
627 done
628 done