{"thread":{"id":"38402","subject":"[PATCH 3/3] t5500: Show user name and host in diag-url","startedAt":"2015-01-19T17:21:34Z","lastAt":"2015-01-19T17:21:34Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"254901","messageId":"54BD3D1E.8080701@web.de","threadId":"38402","inReplyTo":null,"subject":"[PATCH 3/3] t5500: Show user name and host in diag-url","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2015-01-19T17:21:34Z","receivedAt":"2015-01-19T17:21:34Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"The URL for ssh may have include a username before the hostname,\nlike ssh://user@host/repo.\nWhen literal IPV6 addresses are used together with a username,\nthe substring \"user@[::1]\" must be converted into \"user@::1\".\n\nMake that conversion visible for the user, and write userandhost\nin the diagnostics\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n connect.c             | 35 +++++++++++++++++++++++------------\n t/t5500-fetch-pack.sh | 51 +++++++++++++++++++++++++++++++++------------------\n 2 files changed, 56 insertions(+), 30 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex b608976..84f8156 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -675,7 +675,7 @@ struct child_process *git_connect(int fd[2], const char *url,\n \tsignal(SIGCHLD, SIG_DFL);\n \n \tprotocol = parse_connect_url(url, &hostandport, &path);\n-\tif (flags & CONNECT_DIAG_URL) {\n+\tif ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {\n \t\tprintf(\"Diag: url=%s\\n\", url ? url : \"NULL\");\n \t\tprintf(\"Diag: protocol=%s\\n\", prot_name(protocol));\n \t\tprintf(\"Diag: hostandport=%s\\n\", hostandport ? hostandport : \"NULL\");\n@@ -719,18 +719,29 @@ struct child_process *git_connect(int fd[2], const char *url,\n \t\t\tget_host_and_port(&ssh_host, &port);\n \t\t\tif (!port)\n \t\t\t\tport = get_port(ssh_host);\n-\n-\t\t\tif (!ssh) ssh = \"ssh\";\n-\n-\t\t\targv_array_push(&conn->args, ssh);\n-\t\t\tif (putty && !strcasestr(ssh, \"tortoiseplink\"))\n-\t\t\t\targv_array_push(&conn->args, \"-batch\");\n-\t\t\tif (port) {\n-\t\t\t\t/* P is for PuTTY, p is for OpenSSH */\n-\t\t\t\targv_array_push(&conn->args, putty ? \"-P\" : \"-p\");\n-\t\t\t\targv_array_push(&conn->args, port);\n+\t\t\tif (flags & CONNECT_DIAG_URL) {\n+\t\t\t\tprintf(\"Diag: url=%s\\n\", url ? url : \"NULL\");\n+\t\t\t\tprintf(\"Diag: protocol=%s\\n\", prot_name(protocol));\n+\t\t\t\tprintf(\"Diag: userandhost=%s\\n\", ssh_host ? ssh_host : \"NULL\");\n+\t\t\t\tprintf(\"Diag: port=%s\\n\", port ? port : \"NONE\");\n+\t\t\t\tprintf(\"Diag: path=%s\\n\", path ? path : \"NULL\");\n+\n+\t\t\t\tfree(hostandport);\n+\t\t\t\tfree(path);\n+\t\t\t\treturn NULL;\n+\t\t\t} else {\n+\t\t\t\tif (!ssh) ssh = \"ssh\";\n+\n+\t\t\t\targv_array_push(&conn->args, ssh);\n+\t\t\t\tif (putty && !strcasestr(ssh, \"tortoiseplink\"))\n+\t\t\t\t\targv_array_push(&conn->args, \"-batch\");\n+\t\t\t\tif (port) {\n+\t\t\t\t\t/* P is for PuTTY, p is for OpenSSH */\n+\t\t\t\t\targv_array_push(&conn->args, putty ? \"-P\" : \"-p\");\n+\t\t\t\t\targv_array_push(&conn->args, port);\n+\t\t\t\t}\n+\t\t\t\targv_array_push(&conn->args, ssh_host);\n \t\t\t}\n-\t\t\targv_array_push(&conn->args, ssh_host);\n \t\t} else {\n \t\t\t/* remove repo-local variables from the environment */\n \t\t\tconn->env = local_repo_env;\ndiff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh\nindex 5b2b1c2..bd37f04 100755\n--- a/t/t5500-fetch-pack.sh\n+++ b/t/t5500-fetch-pack.sh\n@@ -541,13 +541,30 @@ check_prot_path () {\n \ttest_cmp expected actual\n }\n \n-check_prot_host_path () {\n-\tcat >expected <<-EOF &&\n+check_prot_host_port_path () {\n+\tlocal diagport\n+\tcase \"$2\" in\n+\t\t*ssh*)\n+\t\tpp=ssh\n+\t\tuah=userandhost\n+\t\tehost=$(echo $3 | tr -d \"[]\")\n+\t\tdiagport=\"Diag: port=$4\"\n+\t\t;;\n+\t\t*)\n+\t\tpp=$p\n+\t\tuah=hostandport\n+\t\tehost=$(echo $3$4 | sed -e \"s/22$/:22/\" -e \"s/NONE//\")\n+\t\tdiagport=\"\"\n+\t\t;;\n+\tesac\n+\tcat >exp <<-EOF &&\n \tDiag: url=$1\n-\tDiag: protocol=$2\n-\tDiag: hostandport=$3\n-\tDiag: path=$4\n+\tDiag: protocol=$pp\n+\tDiag: $uah=$ehost\n+\t$diagport\n+\tDiag: path=$5\n \tEOF\n+\tgrep -v \"^$\" exp >expected\n \tgit fetch-pack --diag-url \"$1\" >actual &&\n \ttest_cmp expected actual\n }\n@@ -557,22 +574,20 @@ do\n \t# git or ssh with scheme\n \tfor p in \"ssh+git\" \"git+ssh\" git ssh\n \tdo\n-\t\tfor h in host host:12 [::1] [::1]:23\n+\t\tfor h in host user@host user@[::1] user@::1\n \t\tdo\n-\t\t\tcase \"$p\" in\n-\t\t\t*ssh*)\n-\t\t\t\tpp=ssh\n-\t\t\t\t;;\n-\t\t\t*)\n-\t\t\t\tpp=$p\n-\t\t\t;;\n-\t\t\tesac\n \t\t\ttest_expect_success \"fetch-pack --diag-url $p://$h/$r\" '\n-\t\t\t\tcheck_prot_host_path $p://$h/$r $pp \"$h\" \"/$r\"\n+\t\t\t\tcheck_prot_host_port_path $p://$h/$r $p \"$h\" NONE \"/$r\"\n \t\t\t'\n \t\t\t# \"/~\" -> \"~\" conversion\n \t\t\ttest_expect_success \"fetch-pack --diag-url $p://$h/~$r\" '\n-\t\t\t\tcheck_prot_host_path $p://$h/~$r $pp \"$h\" \"~$r\"\n+\t\t\t\tcheck_prot_host_port_path $p://$h/~$r $p \"$h\" NONE \"~$r\"\n+\t\t\t'\n+\t\tdone\n+\t\tfor h in host User@host User@[::1]\n+\t\tdo\n+\t\t\ttest_expect_success \"fetch-pack --diag-url $p://$h:22/$r\" '\n+\t\t\t\tcheck_prot_host_port_path $p://$h:22/$r $p \"$h\" 22 \"/$r\"\n \t\t\t'\n \t\tdone\n \tdone\n@@ -603,11 +618,11 @@ do\n \tfor h in host [::1]\n \tdo\n \t\ttest_expect_success \"fetch-pack --diag-url $h:$r\" '\n-\t\t\tcheck_prot_path $h:$r $p \"$r\"\n+\t\t\tcheck_prot_host_port_path $h:$r $p \"$h\" NONE \"$r\"\n \t\t'\n \t\t# Do \"/~\" -> \"~\" conversion\n \t\ttest_expect_success \"fetch-pack --diag-url $h:/~$r\" '\n-\t\t\tcheck_prot_host_path $h:/~$r $p \"$h\" \"~$r\"\n+\t\t\tcheck_prot_host_port_path $h:/~$r $p \"$h\" NONE \"~$r\"\n \t\t'\n \tdone\n done\n-- \n2.2.0.rc1.26.g3e3a70d\n"}]}