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>

Torsten Bögershausen committed Nov 28, 2013 at 20:49 UTC 5610b7c0c6957cf0b236b6fac087c1f4dc209376
4 files changed +41 -3
builtin/fetch-pack.c
+11 -3
@@ -7,7 +7,7 @@
7 static const char fetch_pack_usage[] =
8 "git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
9 "[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
10 -"[--no-progress] [-v] [<host>:]<directory> [<refs>...]";
10 +"[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]";
11
12 static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
13 const char *name, int namelen)
@@ -81,6 +81,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
81 args.stdin_refs = 1;
82 continue;
83 }
84 + if (!strcmp("--diag-url", arg)) {
85 + args.diag_url = 1;
86 + continue;
87 + }
88 if (!strcmp("-v", arg)) {
89 args.verbose = 1;
90 continue;
@@ -146,10 +150,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
150 fd[0] = 0;
151 fd[1] = 1;
152 } else {
153 + int flags = args.verbose ? CONNECT_VERBOSE : 0;
154 + if (args.diag_url)
155 + flags |= CONNECT_DIAG_URL;
156 conn = git_connect(fd, dest, args.uploadpack,
150 - args.verbose ? CONNECT_VERBOSE : 0);
157 + flags);
158 + if (!conn)
159 + return args.diag_url ? 0 : 1;
160 }
152 -
161 get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
162
163 ref = fetch_pack(&args, fd, conn, ref, dest,
connect.c
+28
@@ -236,6 +236,20 @@ enum protocol {
236 PROTO_GIT
237 };
238
239 +static const char *prot_name(enum protocol protocol)
240 +{
241 + switch (protocol) {
242 + case PROTO_LOCAL:
243 + return "file";
244 + case PROTO_SSH:
245 + return "ssh";
246 + case PROTO_GIT:
247 + return "git";
248 + default:
249 + return "unkown protocol";
250 + }
251 +}
252 +
253 static enum protocol get_protocol(const char *name)
254 {
255 if (!strcmp(name, "ssh"))
@@ -670,6 +684,20 @@ struct child_process *git_connect(int fd[2], const char *url,
684 signal(SIGCHLD, SIG_DFL);
685
686 protocol = parse_connect_url(url, &host, &port, &path);
687 + if (flags & CONNECT_DIAG_URL) {
688 + printf("Diag: url=%s\n", url ? url : "NULL");
689 + printf("Diag: protocol=%s\n", prot_name(protocol));
690 + printf("Diag: hostandport=%s", host ? host : "NULL");
691 + if (port)
692 + printf(":%s\n", port);
693 + else
694 + printf("\n");
695 + printf("Diag: path=%s\n", path ? path : "NULL");
696 + free(host);
697 + free(port);
698 + free(path);
699 + return NULL;
700 + }
701
702 if (protocol == PROTO_GIT) {
703 /* These underlying connection commands die() if they
connect.h
+1
@@ -2,6 +2,7 @@
2 #define CONNECT_H
3
4 #define CONNECT_VERBOSE (1u << 0)
5 +#define CONNECT_DIAG_URL (1u << 1)
6 extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
7 extern int finish_connect(struct child_process *conn);
8 extern int git_connection_is_socket(struct child_process *conn);
fetch-pack.h
+1
@@ -14,6 +14,7 @@ struct fetch_pack_args {
14 use_thin_pack:1,
15 fetch_all:1,
16 stdin_refs:1,
17 + diag_url:1,
18 verbose:1,
19 no_progress:1,
20 include_tag:1,