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:
parent
cabc3c12e4
commit
5610b7c0c6
@ -7,7 +7,7 @@
|
||||
static const char fetch_pack_usage[] =
|
||||
"git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
|
||||
"[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
|
||||
"[--no-progress] [-v] [<host>:]<directory> [<refs>...]";
|
||||
"[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]";
|
||||
|
||||
static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
|
||||
const char *name, int namelen)
|
||||
@ -81,6 +81,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
|
||||
args.stdin_refs = 1;
|
||||
continue;
|
||||
}
|
||||
if (!strcmp("--diag-url", arg)) {
|
||||
args.diag_url = 1;
|
||||
continue;
|
||||
}
|
||||
if (!strcmp("-v", arg)) {
|
||||
args.verbose = 1;
|
||||
continue;
|
||||
@ -146,10 +150,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
|
||||
fd[0] = 0;
|
||||
fd[1] = 1;
|
||||
} else {
|
||||
int flags = args.verbose ? CONNECT_VERBOSE : 0;
|
||||
if (args.diag_url)
|
||||
flags |= CONNECT_DIAG_URL;
|
||||
conn = git_connect(fd, dest, args.uploadpack,
|
||||
args.verbose ? CONNECT_VERBOSE : 0);
|
||||
flags);
|
||||
if (!conn)
|
||||
return args.diag_url ? 0 : 1;
|
||||
}
|
||||
|
||||
get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
|
||||
|
||||
ref = fetch_pack(&args, fd, conn, ref, dest,
|
||||
|
28
connect.c
28
connect.c
@ -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
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define CONNECT_H
|
||||
|
||||
#define CONNECT_VERBOSE (1u << 0)
|
||||
#define CONNECT_DIAG_URL (1u << 1)
|
||||
extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
|
||||
extern int finish_connect(struct child_process *conn);
|
||||
extern int git_connection_is_socket(struct child_process *conn);
|
||||
|
@ -14,6 +14,7 @@ struct fetch_pack_args {
|
||||
use_thin_pack:1,
|
||||
fetch_all:1,
|
||||
stdin_refs:1,
|
||||
diag_url:1,
|
||||
verbose:1,
|
||||
no_progress:1,
|
||||
include_tag:1,
|
||||
|
Loading…
Reference in New Issue
Block a user