{"thread":{"id":"35425","subject":"[PATCH v7 05/10] git fetch-pack: Add --diag-url","startedAt":"2013-11-28T19:49:17Z","lastAt":"2013-11-28T19:49:17Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":7,"patchTotal":10},"messages":[{"id":"231255","messageId":"201311282049.18196.tboegi@web.de","threadId":"35425","inReplyTo":null,"subject":"[PATCH v7 05/10] git fetch-pack: Add --diag-url","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-11-28T19:49:17Z","receivedAt":"2013-11-28T19:49:17Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"The main purpose is to trace the URL parser called by git_connect() in\nconnect.c\n\nThe main features of the parser can be listed as this:\n- parse out host and path for URLs with a scheme (git:// file:// ssh://)\n- parse host names embedded by [] correctly\n- extract the port number, if present\n- separate URLs like \"file\" (which are local)\n  from URLs like \"host:repo\" which should use ssh\n\nAdd the new parameter \"--diag-url\" to \"git fetch-pack\",\nwhich prints the value for protocol, host and path to stderr and exits.\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n builtin/fetch-pack.c | 14 +++++++++++---\n connect.c            | 28 ++++++++++++++++++++++++++++\n connect.h            |  1 +\n fetch-pack.h         |  1 +\n 4 files changed, 41 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex c8e8582..758b5ac 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -7,7 +7,7 @@\n static const char fetch_pack_usage[] =\n \"git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] \"\n \"[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] \"\n-\"[--no-progress] [-v] [<host>:]<directory> [<refs>...]\";\n+\"[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]\";\n \n static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,\n \t\t\t\t const char *name, int namelen)\n@@ -81,6 +81,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \t\t\targs.stdin_refs = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(\"--diag-url\", arg)) {\n+\t\t\targs.diag_url = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(\"-v\", arg)) {\n \t\t\targs.verbose = 1;\n \t\t\tcontinue;\n@@ -146,10 +150,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \t\tfd[0] = 0;\n \t\tfd[1] = 1;\n \t} else {\n+\t\tint flags = args.verbose ? CONNECT_VERBOSE : 0;\n+\t\tif (args.diag_url)\n+\t\t\tflags |= CONNECT_DIAG_URL;\n \t\tconn = git_connect(fd, dest, args.uploadpack,\n-\t\t\t\t   args.verbose ? CONNECT_VERBOSE : 0);\n+\t\t\t\t   flags);\n+\t\tif (!conn)\n+\t\t\treturn args.diag_url ? 0 : 1;\n \t}\n-\n \tget_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);\n \n \tref = fetch_pack(&args, fd, conn, ref, dest,\ndiff --git a/connect.c b/connect.c\nindex a6cf345..a16bdaf 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -236,6 +236,20 @@ enum protocol {\n \tPROTO_GIT\n };\n \n+static const char *prot_name(enum protocol protocol)\n+{\n+\tswitch (protocol) {\n+\t\tcase PROTO_LOCAL:\n+\t\t\treturn \"file\";\n+\t\tcase PROTO_SSH:\n+\t\t\treturn \"ssh\";\n+\t\tcase PROTO_GIT:\n+\t\t\treturn \"git\";\n+\t\tdefault:\n+\t\t\treturn \"unkown protocol\";\n+\t}\n+}\n+\n static enum protocol get_protocol(const char *name)\n {\n \tif (!strcmp(name, \"ssh\"))\n@@ -670,6 +684,20 @@ struct child_process *git_connect(int fd[2], const char *url,\n \tsignal(SIGCHLD, SIG_DFL);\n \n \tprotocol = parse_connect_url(url, &host, &port, &path);\n+\tif (flags & CONNECT_DIAG_URL) {\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\", host ? host : \"NULL\");\n+\t\tif (port)\n+\t\t\tprintf(\":%s\\n\", port);\n+\t\telse\n+\t\t\tprintf(\"\\n\");\n+\t\tprintf(\"Diag: path=%s\\n\", path ? path : \"NULL\");\n+\t\tfree(host);\n+\t\tfree(port);\n+\t\tfree(path);\n+\t\treturn NULL;\n+\t}\n \n \tif (protocol == PROTO_GIT) {\n \t\t/* These underlying connection commands die() if they\ndiff --git a/connect.h b/connect.h\nindex 64fb7db..527d58a 100644\n--- a/connect.h\n+++ b/connect.h\n@@ -2,6 +2,7 @@\n #define CONNECT_H\n \n #define CONNECT_VERBOSE       (1u << 0)\n+#define CONNECT_DIAG_URL      (1u << 1)\n extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);\n extern int finish_connect(struct child_process *conn);\n extern int git_connection_is_socket(struct child_process *conn);\ndiff --git a/fetch-pack.h b/fetch-pack.h\nindex 461cbf3..20ccc12 100644\n--- a/fetch-pack.h\n+++ b/fetch-pack.h\n@@ -14,6 +14,7 @@ struct fetch_pack_args {\n \t\tuse_thin_pack:1,\n \t\tfetch_all:1,\n \t\tstdin_refs:1,\n+\t\tdiag_url:1,\n \t\tverbose:1,\n \t\tno_progress:1,\n \t\tinclude_tag:1,\n-- \n1.8.5.rc0.23.gaa27064\n"}]}