git fetch-pack: add --diag-url

The main purpose is to trace the URL parser called by git_connect() in
connect.c

The main features of the parser can be listed as this:

- parse out host and path for URLs with a scheme (git:// file:// ssh://)
- parse host names embedded by [] correctly
- extract the port number, if present
- separate URLs like "file" (which are local)
  from URLs like "host:repo" which should use ssh

Add the new parameter "--diag-url" to "git fetch-pack", which prints
the value for protocol, host and path to stderr and exits.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Torsten Bögershausen
2013-11-28 20:49:17 +01:00
committed by Junio C Hamano
parent cabc3c12e4
commit 5610b7c0c6
4 changed files with 41 additions and 3 deletions

View File

@ -236,6 +236,20 @@ enum protocol {
PROTO_GIT
};
static const char *prot_name(enum protocol protocol)
{
switch (protocol) {
case PROTO_LOCAL:
return "file";
case PROTO_SSH:
return "ssh";
case PROTO_GIT:
return "git";
default:
return "unkown protocol";
}
}
static enum protocol get_protocol(const char *name)
{
if (!strcmp(name, "ssh"))
@ -670,6 +684,20 @@ struct child_process *git_connect(int fd[2], const char *url,
signal(SIGCHLD, SIG_DFL);
protocol = parse_connect_url(url, &host, &port, &path);
if (flags & CONNECT_DIAG_URL) {
printf("Diag: url=%s\n", url ? url : "NULL");
printf("Diag: protocol=%s\n", prot_name(protocol));
printf("Diag: hostandport=%s", host ? host : "NULL");
if (port)
printf(":%s\n", port);
else
printf("\n");
printf("Diag: path=%s\n", path ? path : "NULL");
free(host);
free(port);
free(path);
return NULL;
}
if (protocol == PROTO_GIT) {
/* These underlying connection commands die() if they