{"thread":{"id":"42072","subject":"[PATCHv2 0/4] Implements the GIT_TRACE_CURL environment variable","startedAt":"2016-04-19T15:10:40Z","lastAt":"2016-04-19T22:11:55Z","messageCount":11,"participants":["Elia Pinto","Junio C Hamano","Ramsay Jones"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"283791","messageId":"20160419151044.27814-1-gitter.spiros@gmail.com","threadId":"42072","inReplyTo":null,"subject":"[PATCHv2 0/4] Implements the GIT_TRACE_CURL environment variable","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2016-04-19T15:10:40Z","receivedAt":"2016-04-19T15:10:40Z","isPatch":false,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"This is the second version but in reality is the complete rewriting of the patches discussed here\n\n$gmane/290520\n$gmane/290521\n\nChanges from V1\n\n- introduced GIT_TRACE_CURL variable with its documentation\n- changed the name of the temporary variable \"i\" in \"w\" in the helper routine\n- used the c escape sequences instead of the hex equivalent\n- dropped the previous GIT_DEBUG_CURL env var\n- curl_dump and curl_trace factored out to a shared implementation\nin http.c \n\n  \nElia Pinto (4):\n  http.h: Add debug callback and helper routine for implementing     the\n    GIT_TRACE_CURL environment variable in http.c\n  http.c: implements the GIT_TRACE_CURL environment variable\n  git.txt: document the new GIT_TRACE_CURL environment variable\n  imap-send.c: introduce the GIT_TRACE_CURL enviroment variable\n\n Documentation/git.txt |  8 +++++\n http.c                | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n http.h                |  6 ++++\n imap-send.c           |  6 ++++\n 4 files changed, 117 insertions(+), 1 deletion(-)\n\n-- \n2.5.0\n"},{"id":"283794","messageId":"20160419151044.27814-2-gitter.spiros@gmail.com","threadId":"42072","inReplyTo":"20160419151044.27814-1-gitter.spiros@gmail.com","subject":"[PATCH 1/4] http.h: Add debug callback and helper routine for implementing the GIT_TRACE_CURL environment variable in http.c","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2016-04-19T15:10:41Z","receivedAt":"2016-04-19T15:10:41Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Add the debug callback and helper routine prototype used by\ncurl_easy_setopt CURLOPT_DEBUGFUNCTION in http.c\nfor implementing the GIT_TRACE_CURL environment variable\n\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nHelped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com> \nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\n http.h | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/http.h b/http.h\nindex 4ef4bbd..a2d10bc 100644\n--- a/http.h\n+++ b/http.h\n@@ -224,4 +224,10 @@ extern int finish_http_object_request(struct http_object_request *freq);\n extern void abort_http_object_request(struct http_object_request *freq);\n extern void release_http_object_request(struct http_object_request *freq);\n \n+/* Debug callback and helper routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */\n+static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n+int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp);\n+void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex);\n+\n+\n #endif /* HTTP_H */\n-- \n2.5.0\n"},{"id":"283792","messageId":"20160419151044.27814-3-gitter.spiros@gmail.com","threadId":"42072","inReplyTo":"20160419151044.27814-1-gitter.spiros@gmail.com","subject":"[PATCH 2/4] http.c: implements the GIT_TRACE_CURL environment variable","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2016-04-19T15:10:42Z","receivedAt":"2016-04-19T15:10:42Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Implements the GIT_TRACE_CURL environment variable to allow a\ngreater degree of detail of GIT_CURL_VERBOSE, in particular\nthe complete transport header and all the data payload exchanged.\nIt might be useful if a particular situation could require a more\nthorough debugging analysis\n\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nHelped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com> \nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\n http.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 97 insertions(+), 1 deletion(-)\n\ndiff --git a/http.c b/http.c\nindex 4304b80..278991e 100644\n--- a/http.c\n+++ b/http.c\n@@ -11,6 +11,9 @@\n #include \"gettext.h\"\n #include \"transport.h\"\n \n+/*\n+tatic struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n+*/\n #if LIBCURL_VERSION_NUM >= 0x070a08\n long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;\n #else\n@@ -464,6 +467,95 @@ static void set_curl_keepalive(CURL *c)\n }\n #endif\n \n+\n+void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex)\n+{\n+\tsize_t i;\n+\tsize_t w;\n+\tstruct strbuf out = STRBUF_INIT;;\n+\n+\tunsigned int width = 0x10;\n+\n+\tif (nohex)\n+\t\t/* without the hex output, we can fit more on screen */\n+\t\twidth = 0x40;\n+\n+\tstrbuf_addf(&out, \"%s, %10.10ld bytes (0x%8.8lx)\\n\",\n+\t\ttext, (long)size, (long)size);\n+\n+\tfor (i = 0; i < size; i += width) {\n+\n+\t\tstrbuf_addf(&out, \"%4.4lx: \", (long)i);\n+\n+\t\tif (!nohex) {\n+\t\t\t/* hex not disabled, show it */\n+\t\t\tfor (w = 0; w < width; w++)\n+\t\t\t\tif (i + w < size)\n+\t\t\t\t\tstrbuf_addf(&out, \"%02x \", ptr[i + w]);\n+\t\t\t\telse\n+\t\t\t\t\tstrbuf_addf(&out,\"   \");\n+\t\t}\n+\n+\t\tfor (w = 0; (w < width) && (i + w < size); w++) {\n+\t\t\t/* check for 0D0A; if found, skip past and start a new line of output */\n+\t\t\tif (nohex && (i + w + 1 < size) && ptr[i + w] == '\\r'\n+\t\t\t    && ptr[i + w + 1] == '\\n') {\n+\t\t\t\ti += (w + 2 - width);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tstrbuf_addch(&out, (ptr[i + w] >= 0x20)\n+\t\t\t\t&& (ptr[i + w] < 0x80) ? ptr[i + w] : '.');\n+\t\t\t/* check again for 0D0A, to avoid an extra \\n if it's at width */\n+\t\t\tif (nohex && (i + w + 2 < size)\n+\t\t\t    && ptr[i + w + 1] == '\\r'\n+\t\t\t    && ptr[i + w + 2] == '\\n') {\n+\t\t\t\ti += (w + 3 - width);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tstrbuf_addch(&out, '\\n');\n+\t\ttrace_strbuf(&trace_curl, &out);\n+\t\tstrbuf_release(&out);\n+\t}\n+}\n+\n+int curl_trace(CURL *handle, curl_infotype type,\n+\t     char *data, size_t size, void *userp)\n+{\n+\tconst char *text;\n+\t(void)handle;\t\t/* prevent compiler warning */\n+\n+\tswitch (type) {\n+\tcase CURLINFO_TEXT:\n+\t\ttrace_printf_key(&trace_curl, \"== Info: %s\", data);\n+\tdefault:\t\t/* in case a new one is introduced to shock us */\n+\t\treturn 0;\n+\n+\tcase CURLINFO_HEADER_OUT:\n+\t\ttext = \"=> Send header\";\n+\t\tbreak;\n+\tcase CURLINFO_DATA_OUT:\n+\t\ttext = \"=> Send data\";\n+\t\tbreak;\n+\tcase CURLINFO_SSL_DATA_OUT:\n+\t\ttext = \"=> Send SSL data\";\n+\t\tbreak;\n+\tcase CURLINFO_HEADER_IN:\n+\t\ttext = \"<= Recv header\";\n+\t\tbreak;\n+\tcase CURLINFO_DATA_IN:\n+\t\ttext = \"<= Recv data\";\n+\t\tbreak;\n+\tcase CURLINFO_SSL_DATA_IN:\n+\t\ttext = \"<= Recv SSL data\";\n+\t\tbreak;\n+\t}\n+\n+\tcurl_dump(text, (unsigned char *)data, size, 1);\n+\treturn 0;\n+}\n+\n+\n static CURL *get_curl_handle(void)\n {\n \tCURL *result = curl_easy_init();\n@@ -563,7 +655,11 @@ static CURL *get_curl_handle(void)\n \t\t\t\"your curl version is too old (>= 7.19.4)\");\n #endif\n \n-\tif (getenv(\"GIT_CURL_VERBOSE\"))\n+\tif (trace_want(&trace_curl)) {\n+\t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1L);\n+\t\tcurl_easy_setopt(result, CURLOPT_DEBUGFUNCTION, curl_trace);\n+\t\tcurl_easy_setopt(result, CURLOPT_DEBUGDATA, NULL);\n+\t} else if (getenv(\"GIT_CURL_VERBOSE\"))\n \t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1);\n \n \tcurl_easy_setopt(result, CURLOPT_USERAGENT,\n-- \n2.5.0\n"},{"id":"283793","messageId":"20160419151044.27814-4-gitter.spiros@gmail.com","threadId":"42072","inReplyTo":"20160419151044.27814-1-gitter.spiros@gmail.com","subject":"[PATCH 3/4] git.txt: document the new GIT_TRACE_CURL environment variable","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2016-04-19T15:10:43Z","receivedAt":"2016-04-19T15:10:43Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Describe the purpose of the GIT_TRACE_CURL environment variable\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nHelped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com> \nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\n Documentation/git.txt | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 8afe349..958db0f 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -1075,6 +1075,14 @@ of clones and fetches.\n \tcloning of shallow repositories.\n \tSee 'GIT_TRACE' for available trace output options.\n \n+'GIT_TRACE_CURL'::\n+\tEnables a curl full trace dump of all incoming and outgoing data,\n+\tincluding descriptive information, of the git transport protocol.\n+\tThis is similar to doing curl --trace-ascii on the command line.\n+\tThis option overrides setting the GIT_CURL_VERBOSE environment\n+\tvariable.\n+\tSee 'GIT_TRACE' for available trace output options.\n+\n 'GIT_LITERAL_PATHSPECS'::\n \tSetting this variable to `1` will cause Git to treat all\n \tpathspecs literally, rather than as glob patterns. For example,\n-- \n2.5.0\n"},{"id":"283795","messageId":"20160419151044.27814-5-gitter.spiros@gmail.com","threadId":"42072","inReplyTo":"20160419151044.27814-1-gitter.spiros@gmail.com","subject":"[PATCH 4/4] imap-send.c: introduce the GIT_TRACE_CURL enviroment variable","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2016-04-19T15:10:44Z","receivedAt":"2016-04-19T15:10:44Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Permit the use of the GIT_TRACE_CURL environment variable calling\nthe curl_trace and curl_dump http.c helper routine\n\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nHelped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com> \nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\n imap-send.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 938c691..b371a78 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1444,6 +1444,12 @@ static CURL *setup_curl(struct imap_server_conf *srvc)\n \tif (0 < verbosity || getenv(\"GIT_CURL_VERBOSE\"))\n \t\tcurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n \n+\tif (trace_want(&trace_curl)) {\n+\t\tcurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n+\t\tcurl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curl_trace);\n+\t\tcurl_easy_setopt(curl, CURLOPT_DEBUGDATA, NULL);\n+\t}\n+\n \treturn curl;\n }\n \n-- \n2.5.0\n"},{"id":"283816","messageId":"xmqqy4891nsv.fsf@gitster.mtv.corp.google.com","threadId":"42072","inReplyTo":"20160419151044.27814-2-gitter.spiros@gmail.com","subject":"Re: [PATCH 1/4] http.h: Add debug callback and helper routine for implementing the GIT_TRACE_CURL environment variable in http.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-19T18:00:32Z","receivedAt":"2016-04-19T18:00:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Add the debug callback and helper routine prototype used by\n> curl_easy_setopt CURLOPT_DEBUGFUNCTION in http.c\n> for implementing the GIT_TRACE_CURL environment variable\n>\n>\n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com> \n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n> ---\n>  http.h | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/http.h b/http.h\n> index 4ef4bbd..a2d10bc 100644\n> --- a/http.h\n> +++ b/http.h\n> @@ -224,4 +224,10 @@ extern int finish_http_object_request(struct http_object_request *freq);\n>  extern void abort_http_object_request(struct http_object_request *freq);\n>  extern void release_http_object_request(struct http_object_request *freq);\n>  \n> +/* Debug callback and helper routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */\n> +static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n\nThis will be multiply instanciated in every *.c file that includes http.h?\n\n> +int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp);\n> +void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex);\n> +\n> +\n>  #endif /* HTTP_H */\n\nIn any case, you'd want to combine this with 2/4 and write a single\nlog message for the combined change.\n"},{"id":"283817","messageId":"xmqqtwix1nnp.fsf@gitster.mtv.corp.google.com","threadId":"42072","inReplyTo":"20160419151044.27814-3-gitter.spiros@gmail.com","subject":"Re: [PATCH 2/4] http.c: implements the GIT_TRACE_CURL environment variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-19T18:03:38Z","receivedAt":"2016-04-19T18:03:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Implements the GIT_TRACE_CURL environment variable to allow a\n> greater degree of detail of GIT_CURL_VERBOSE, in particular\n> the complete transport header and all the data payload exchanged.\n> It might be useful if a particular situation could require a more\n> thorough debugging analysis\n>\n>\n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com> \n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n> ---\n>  http.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 97 insertions(+), 1 deletion(-)\n>\n> diff --git a/http.c b/http.c\n> index 4304b80..278991e 100644\n> --- a/http.c\n> +++ b/http.c\n> @@ -11,6 +11,9 @@\n>  #include \"gettext.h\"\n>  #include \"transport.h\"\n>  \n> +/*\n> +tatic struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n> +*/\n\nIs this a sign that this hasn't been proof-read before sending?\n\n>  #if LIBCURL_VERSION_NUM >= 0x070a08\n>  long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;\n>  #else\n> @@ -464,6 +467,95 @@ static void set_curl_keepalive(CURL *c)\n>  }\n>  #endif\n>  \n> +\n> +void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex)\n> +{\n> +\tsize_t i;\n> +\tsize_t w;\n> +\tstruct strbuf out = STRBUF_INIT;;\n> +\n> +\tunsigned int width = 0x10;\n> +\n> +\tif (nohex)\n> +\t\t/* without the hex output, we can fit more on screen */\n> +\t\twidth = 0x40;\n> +\n> +\tstrbuf_addf(&out, \"%s, %10.10ld bytes (0x%8.8lx)\\n\",\n> +\t\ttext, (long)size, (long)size);\n> +\n> +\tfor (i = 0; i < size; i += width) {\n> +\n> +\t\tstrbuf_addf(&out, \"%4.4lx: \", (long)i);\n> +\n> +\t\tif (!nohex) {\n> +\t\t\t/* hex not disabled, show it */\n> +\t\t\tfor (w = 0; w < width; w++)\n> +\t\t\t\tif (i + w < size)\n> +\t\t\t\t\tstrbuf_addf(&out, \"%02x \", ptr[i + w]);\n> +\t\t\t\telse\n> +\t\t\t\t\tstrbuf_addf(&out,\"   \");\n> +\t\t}\n> +\n> +\t\tfor (w = 0; (w < width) && (i + w < size); w++) {\n> +\t\t\t/* check for 0D0A; if found, skip past and start a new line of output */\n> +\t\t\tif (nohex && (i + w + 1 < size) && ptr[i + w] == '\\r'\n> +\t\t\t    && ptr[i + w + 1] == '\\n') {\n> +\t\t\t\ti += (w + 2 - width);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t\tstrbuf_addch(&out, (ptr[i + w] >= 0x20)\n> +\t\t\t\t&& (ptr[i + w] < 0x80) ? ptr[i + w] : '.');\n> +\t\t\t/* check again for 0D0A, to avoid an extra \\n if it's at width */\n> +\t\t\tif (nohex && (i + w + 2 < size)\n> +\t\t\t    && ptr[i + w + 1] == '\\r'\n> +\t\t\t    && ptr[i + w + 2] == '\\n') {\n> +\t\t\t\ti += (w + 3 - width);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\t\tstrbuf_addch(&out, '\\n');\n> +\t\ttrace_strbuf(&trace_curl, &out);\n> +\t\tstrbuf_release(&out);\n> +\t}\n> +}\n> +\n> +int curl_trace(CURL *handle, curl_infotype type,\n> +\t     char *data, size_t size, void *userp)\n> +{\n> +\tconst char *text;\n> +\t(void)handle;\t\t/* prevent compiler warning */\n> +\n> +\tswitch (type) {\n> +\tcase CURLINFO_TEXT:\n> +\t\ttrace_printf_key(&trace_curl, \"== Info: %s\", data);\n> +\tdefault:\t\t/* in case a new one is introduced to shock us */\n> +\t\treturn 0;\n> +\n> +\tcase CURLINFO_HEADER_OUT:\n> +\t\ttext = \"=> Send header\";\n> +\t\tbreak;\n> +\tcase CURLINFO_DATA_OUT:\n> +\t\ttext = \"=> Send data\";\n> +\t\tbreak;\n> +\tcase CURLINFO_SSL_DATA_OUT:\n> +\t\ttext = \"=> Send SSL data\";\n> +\t\tbreak;\n> +\tcase CURLINFO_HEADER_IN:\n> +\t\ttext = \"<= Recv header\";\n> +\t\tbreak;\n> +\tcase CURLINFO_DATA_IN:\n> +\t\ttext = \"<= Recv data\";\n> +\t\tbreak;\n> +\tcase CURLINFO_SSL_DATA_IN:\n> +\t\ttext = \"<= Recv SSL data\";\n> +\t\tbreak;\n> +\t}\n> +\n> +\tcurl_dump(text, (unsigned char *)data, size, 1);\n> +\treturn 0;\n> +}\n> +\n> +\n>  static CURL *get_curl_handle(void)\n>  {\n>  \tCURL *result = curl_easy_init();\n> @@ -563,7 +655,11 @@ static CURL *get_curl_handle(void)\n>  \t\t\t\"your curl version is too old (>= 7.19.4)\");\n>  #endif\n>  \n> -\tif (getenv(\"GIT_CURL_VERBOSE\"))\n> +\tif (trace_want(&trace_curl)) {\n> +\t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1L);\n> +\t\tcurl_easy_setopt(result, CURLOPT_DEBUGFUNCTION, curl_trace);\n> +\t\tcurl_easy_setopt(result, CURLOPT_DEBUGDATA, NULL);\n> +\t} else if (getenv(\"GIT_CURL_VERBOSE\"))\n>  \t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1);\n>  \n>  \tcurl_easy_setopt(result, CURLOPT_USERAGENT,\n"},{"id":"283820","messageId":"xmqqpotl1nl1.fsf@gitster.mtv.corp.google.com","threadId":"42072","inReplyTo":"20160419151044.27814-5-gitter.spiros@gmail.com","subject":"Re: [PATCH 4/4] imap-send.c: introduce the GIT_TRACE_CURL enviroment variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-19T18:05:14Z","receivedAt":"2016-04-19T18:05:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Permit the use of the GIT_TRACE_CURL environment variable calling\n> the curl_trace and curl_dump http.c helper routine\n\ns/$/./; the patch itself is very concise and the \"dump\" thing in 3/4\nlooked sensible.\n\n>\n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com> \n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n> ---\n>  imap-send.c | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/imap-send.c b/imap-send.c\n> index 938c691..b371a78 100644\n> --- a/imap-send.c\n> +++ b/imap-send.c\n> @@ -1444,6 +1444,12 @@ static CURL *setup_curl(struct imap_server_conf *srvc)\n>  \tif (0 < verbosity || getenv(\"GIT_CURL_VERBOSE\"))\n>  \t\tcurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n>  \n> +\tif (trace_want(&trace_curl)) {\n> +\t\tcurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n> +\t\tcurl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curl_trace);\n> +\t\tcurl_easy_setopt(curl, CURLOPT_DEBUGDATA, NULL);\n> +\t}\n> +\n>  \treturn curl;\n>  }\n"},{"id":"283843","messageId":"xmqqy489z6rd.fsf@gitster.mtv.corp.google.com","threadId":"42072","inReplyTo":"20160419151044.27814-3-gitter.spiros@gmail.com","subject":"Re: [PATCH 2/4] http.c: implements the GIT_TRACE_CURL environment variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-19T20:24:38Z","receivedAt":"2016-04-19T20:24:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Implements the GIT_TRACE_CURL environment variable to allow a\n> greater degree of detail of GIT_CURL_VERBOSE, in particular\n> the complete transport header and all the data payload exchanged.\n> It might be useful if a particular situation could require a more\n> thorough debugging analysis\n>\n>\n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com> \n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n> ---\n>  http.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 97 insertions(+), 1 deletion(-)\n>\n> diff --git a/http.c b/http.c\n> index 4304b80..278991e 100644\n> --- a/http.c\n> +++ b/http.c\n> @@ -11,6 +11,9 @@\n>  #include \"gettext.h\"\n>  #include \"transport.h\"\n>  \n> +/*\n> +tatic struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n> +*/\n>  #if LIBCURL_VERSION_NUM >= 0x070a08\n>  long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;\n>  #else\n> @@ -464,6 +467,95 @@ static void set_curl_keepalive(CURL *c)\n>  }\n>  #endif\n>  \n> +\n> +void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex)\n> +{\n> +\tsize_t i;\n> +\tsize_t w;\n> +\tstruct strbuf out = STRBUF_INIT;;\n\n;; makes the next line decl-after-stmt.\n\n> +\n> +\tunsigned int width = 0x10;\n\n\n\n\n> +\n> +\tif (nohex)\n> +\t\t/* without the hex output, we can fit more on screen */\n> +\t\twidth = 0x40;\n> +\n> +\tstrbuf_addf(&out, \"%s, %10.10ld bytes (0x%8.8lx)\\n\",\n> +\t\ttext, (long)size, (long)size);\n> +\n> +\tfor (i = 0; i < size; i += width) {\n> +\n> +\t\tstrbuf_addf(&out, \"%4.4lx: \", (long)i);\n> +\n> +\t\tif (!nohex) {\n> +\t\t\t/* hex not disabled, show it */\n> +\t\t\tfor (w = 0; w < width; w++)\n> +\t\t\t\tif (i + w < size)\n> +\t\t\t\t\tstrbuf_addf(&out, \"%02x \", ptr[i + w]);\n> +\t\t\t\telse\n> +\t\t\t\t\tstrbuf_addf(&out,\"   \");\n> +\t\t}\n> +\n> +\t\tfor (w = 0; (w < width) && (i + w < size); w++) {\n> +\t\t\t/* check for 0D0A; if found, skip past and start a new line of output */\n> +\t\t\tif (nohex && (i + w + 1 < size) && ptr[i + w] == '\\r'\n> +\t\t\t    && ptr[i + w + 1] == '\\n') {\n> +\t\t\t\ti += (w + 2 - width);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t\tstrbuf_addch(&out, (ptr[i + w] >= 0x20)\n> +\t\t\t\t&& (ptr[i + w] < 0x80) ? ptr[i + w] : '.');\n> +\t\t\t/* check again for 0D0A, to avoid an extra \\n if it's at width */\n> +\t\t\tif (nohex && (i + w + 2 < size)\n> +\t\t\t    && ptr[i + w + 1] == '\\r'\n> +\t\t\t    && ptr[i + w + 2] == '\\n') {\n> +\t\t\t\ti += (w + 3 - width);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\t\tstrbuf_addch(&out, '\\n');\n> +\t\ttrace_strbuf(&trace_curl, &out);\n> +\t\tstrbuf_release(&out);\n> +\t}\n> +}\n> +\n> +int curl_trace(CURL *handle, curl_infotype type,\n> +\t     char *data, size_t size, void *userp)\n> +{\n> +\tconst char *text;\n> +\t(void)handle;\t\t/* prevent compiler warning */\n> +\n> +\tswitch (type) {\n> +\tcase CURLINFO_TEXT:\n> +\t\ttrace_printf_key(&trace_curl, \"== Info: %s\", data);\n> +\tdefault:\t\t/* in case a new one is introduced to shock us */\n> +\t\treturn 0;\n> +\n> +\tcase CURLINFO_HEADER_OUT:\n> +\t\ttext = \"=> Send header\";\n> +\t\tbreak;\n> +\tcase CURLINFO_DATA_OUT:\n> +\t\ttext = \"=> Send data\";\n> +\t\tbreak;\n> +\tcase CURLINFO_SSL_DATA_OUT:\n> +\t\ttext = \"=> Send SSL data\";\n> +\t\tbreak;\n> +\tcase CURLINFO_HEADER_IN:\n> +\t\ttext = \"<= Recv header\";\n> +\t\tbreak;\n> +\tcase CURLINFO_DATA_IN:\n> +\t\ttext = \"<= Recv data\";\n> +\t\tbreak;\n> +\tcase CURLINFO_SSL_DATA_IN:\n> +\t\ttext = \"<= Recv SSL data\";\n> +\t\tbreak;\n> +\t}\n> +\n> +\tcurl_dump(text, (unsigned char *)data, size, 1);\n> +\treturn 0;\n> +}\n> +\n> +\n>  static CURL *get_curl_handle(void)\n>  {\n>  \tCURL *result = curl_easy_init();\n> @@ -563,7 +655,11 @@ static CURL *get_curl_handle(void)\n>  \t\t\t\"your curl version is too old (>= 7.19.4)\");\n>  #endif\n>  \n> -\tif (getenv(\"GIT_CURL_VERBOSE\"))\n> +\tif (trace_want(&trace_curl)) {\n> +\t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1L);\n> +\t\tcurl_easy_setopt(result, CURLOPT_DEBUGFUNCTION, curl_trace);\n> +\t\tcurl_easy_setopt(result, CURLOPT_DEBUGDATA, NULL);\n> +\t} else if (getenv(\"GIT_CURL_VERBOSE\"))\n>  \t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1);\n>  \n>  \tcurl_easy_setopt(result, CURLOPT_USERAGENT,\n"},{"id":"283860","messageId":"5716A7C6.40507@ramsayjones.plus.com","threadId":"42072","inReplyTo":"20160419151044.27814-2-gitter.spiros@gmail.com","subject":"Re: [PATCH 1/4] http.h: Add debug callback and helper routine for implementing the GIT_TRACE_CURL environment variable in http.c","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2016-04-19T21:48:54Z","receivedAt":"2016-04-19T21:48:54Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 19/04/16 16:10, Elia Pinto wrote:\n> Add the debug callback and helper routine prototype used by\n> curl_easy_setopt CURLOPT_DEBUGFUNCTION in http.c\n> for implementing the GIT_TRACE_CURL environment variable\n> \n> \n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com> \n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>\n> ---\n>  http.h | 6 ++++++\n>  1 file changed, 6 insertions(+)\n> \n> diff --git a/http.h b/http.h\n> index 4ef4bbd..a2d10bc 100644\n> --- a/http.h\n> +++ b/http.h\n> @@ -224,4 +224,10 @@ extern int finish_http_object_request(struct http_object_request *freq);\n>  extern void abort_http_object_request(struct http_object_request *freq);\n>  extern void release_http_object_request(struct http_object_request *freq);\n>  \n> +/* Debug callback and helper routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */\n> +static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n\nAh no, this would add 6 instances of the 'trace_curl' key in http-fetch.c,\nhttp-push.c, http-walker.c, http.c, imap-send.c and remote-curl.c. Hmm ...\nsince these would end up in different executables (by and large) it might\nwork OK, ... but is simply not necessary.\n\nAlso, patches #1 and #2 should be squashed into one patch and, since the\ncurl_dump() function is only called from http.c, it can be a static symbol.\n\nI think the minimal fixup (including Junio's comment on patch #2, which also\ntriggered for me) is given in the patch below.\n\nHope that helps.\n\nATB,\nRamsay Jones\n\n> +int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp);\n> +void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex);\n> +\n> +\n>  #endif /* HTTP_H */\n\n-- >8 --\nSubject: [PATCH] curl-trace: fix scope/visibility of various symbols\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n http.c | 9 +++------\n http.h | 3 +--\n 2 files changed, 4 insertions(+), 8 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex 64dd975..ce91421 100644\n--- a/http.c\n+++ b/http.c\n@@ -11,9 +11,7 @@\n #include \"gettext.h\"\n #include \"transport.h\"\n \n-/*\n-tatic struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n-*/\n+struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n #if LIBCURL_VERSION_NUM >= 0x070a08\n long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;\n #else\n@@ -468,12 +466,11 @@ static void set_curl_keepalive(CURL *c)\n #endif\n \n \n-void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex)\n+static void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex)\n {\n \tsize_t i;\n \tsize_t w;\n-\tstruct strbuf out = STRBUF_INIT;;\n-\n+\tstruct strbuf out = STRBUF_INIT;\n \tunsigned int width = 0x10;\n \n \tif (nohex)\ndiff --git a/http.h b/http.h\nindex a2d10bc..00e4ad7 100644\n--- a/http.h\n+++ b/http.h\n@@ -225,9 +225,8 @@ extern void abort_http_object_request(struct http_object_request *freq);\n extern void release_http_object_request(struct http_object_request *freq);\n \n /* Debug callback and helper routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */\n-static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n+extern struct trace_key trace_curl;\n int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp);\n-void curl_dump(const char *text, unsigned char *ptr, size_t size, char nohex);\n \n \n #endif /* HTTP_H */\n-- \n2.8.0\n"},{"id":"283862","messageId":"5716AD2B.3050701@ramsayjones.plus.com","threadId":"42072","inReplyTo":"5716A7C6.40507@ramsayjones.plus.com","subject":"Re: [PATCH 1/4] http.h: Add debug callback and helper routine for implementing the GIT_TRACE_CURL environment variable in http.c","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2016-04-19T22:11:55Z","receivedAt":"2016-04-19T22:11:55Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 19/04/16 22:48, Ramsay Jones wrote:\n> \n[snip]\n\n> I think the minimal fixup (including Junio's comment on patch #2, which also\n> triggered for me) is given in the patch below.\n\nBTW, if you want to have a single static instance of the 'struct trace_key',\nthen the following patch on top should work. (Also, I have compiled and run\nthe testsuite on these patches, but _not_ tested that the trace functionality\nactually works!) ;-)\n\nHTH\n\nATB,\nRamsay Jones\n-- >8 --\nSubject: [PATCH] curl-trace: reduce visibility of the trace key struct\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n http.c      | 9 +++++++--\n http.h      | 2 +-\n imap-send.c | 2 +-\n 3 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex ce91421..eed6dba 100644\n--- a/http.c\n+++ b/http.c\n@@ -11,7 +11,7 @@\n #include \"gettext.h\"\n #include \"transport.h\"\n \n-struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n+static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);\n #if LIBCURL_VERSION_NUM >= 0x070a08\n long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;\n #else\n@@ -516,6 +516,11 @@ static void curl_dump(const char *text, unsigned char *ptr, size_t size, char no\n \t}\n }\n \n+int curl_trace_want(void)\n+{\n+\treturn trace_want(&trace_curl);\n+}\n+\n int curl_trace(CURL *handle, curl_infotype type,\n \t     char *data, size_t size, void *userp)\n {\n@@ -652,7 +657,7 @@ static CURL *get_curl_handle(void)\n \t\t\t\"your curl version is too old (>= 7.19.4)\");\n #endif\n \n-\tif (trace_want(&trace_curl)) {\n+\tif (curl_trace_want()) {\n \t\tcurl_easy_setopt(result, CURLOPT_VERBOSE, 1L);\n \t\tcurl_easy_setopt(result, CURLOPT_DEBUGFUNCTION, curl_trace);\n \t\tcurl_easy_setopt(result, CURLOPT_DEBUGDATA, NULL);\ndiff --git a/http.h b/http.h\nindex 00e4ad7..153ff17 100644\n--- a/http.h\n+++ b/http.h\n@@ -225,7 +225,7 @@ extern void abort_http_object_request(struct http_object_request *freq);\n extern void release_http_object_request(struct http_object_request *freq);\n \n /* Debug callback and helper routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */\n-extern struct trace_key trace_curl;\n+int curl_trace_want(void);\n int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp);\n \n \ndiff --git a/imap-send.c b/imap-send.c\nindex 36ff843..627ffa4 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1444,7 +1444,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc)\n \tif (0 < verbosity || getenv(\"GIT_CURL_VERBOSE\"))\n \t\tcurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n \n-\tif (trace_want(&trace_curl)) {\n+\tif (curl_trace_want()) {\n \t\tcurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n \t\tcurl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curl_trace);\n \t\tcurl_easy_setopt(curl, CURLOPT_DEBUGDATA, NULL);\n-- \n2.8.0\n"}]}