{"thread":{"id":"34530","subject":"[PATCH] test-url-normalize.c: Fix gcc errors and sparse warnings","startedAt":"2013-07-24T19:07:55Z","lastAt":"2013-07-31T19:31:55Z","messageCount":19,"participants":["Ramsay Jones","Kyle J. McKay","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"224056","messageId":"51F0260B.5000905@ramsay1.demon.co.uk","threadId":"34530","inReplyTo":null,"subject":"[PATCH] test-url-normalize.c: Fix gcc errors and sparse warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-07-24T19:07:55Z","receivedAt":"2013-07-24T19:07:55Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSparse issues an \"non-ANSI function declaration of function 'main'\"\nwarning when NO_CURL is set. In order to suppress the warning, we\nsimply add the function prototype.\n\nWhen NO_CURL and USE_CURL_MULTI are not defined, then gcc issues the\nfollowing error:\n\n      CC test-url-normalize.o\n  test-url-normalize.c: In function `run_http_options':\n  test-url-normalize.c:49: error: `max_requests' undeclared (first use in this function)\n  test-url-normalize.c:49: error: (Each undeclared identifier is reported only once\n  test-url-normalize.c:49: error: for each function it appears in.)\n  make: *** [test-url-normalize.o] Error 1\n\nIn order to fix the error, we simply protect the use of the 'max_requests'\nvariable with an preprocessor conditional.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nHi Kyle,\n\nWhen you next update the patches in your 'km/http-curl-config-per-url'\nbranch, could you please squash this (or something like it) into the\nrelevant patches.\n\nThanks!\n\nATB,\nRamsay Jones\n\n test-url-normalize.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/test-url-normalize.c b/test-url-normalize.c\nindex abfa4eb..86ce553 100644\n--- a/test-url-normalize.c\n+++ b/test-url-normalize.c\n@@ -1,6 +1,6 @@\n #ifdef NO_CURL\n \n-int main()\n+int main(void)\n {\n \treturn 125;\n }\n@@ -45,8 +45,10 @@ static int run_http_options(const char *file,\n \t\tprintf(\"%s\\n\", curl_ssl_try ? \"true\" : \"false\");\n \telse if (!strcmp(\"minsessions\", opt_lc.buf))\n \t\tprintf(\"%d\\n\", min_curl_sessions);\n+#ifdef USE_CURL_MULTI\n \telse if (!strcmp(\"maxrequests\", opt_lc.buf))\n \t\tprintf(\"%d\\n\", max_requests);\n+#endif\n \telse if (!strcmp(\"lowspeedlimit\", opt_lc.buf))\n \t\tprintf(\"%ld\\n\", curl_low_speed_limit);\n \telse if (!strcmp(\"lowspeedtime\", opt_lc.buf))\n-- \n1.8.3\n"},{"id":"224057","messageId":"FDCB9C95-34A7-45D8-AC23-9739C24043B5@gmail.com","threadId":"34530","inReplyTo":"51F0260B.5000905@ramsay1.demon.co.uk","subject":"Re: [PATCH] test-url-normalize.c: Fix gcc errors and sparse warnings","fromName":"Kyle J. McKay","fromEmail":"mackyle@gmail.com","sentAt":"2013-07-24T19:35:50Z","receivedAt":"2013-07-24T19:35:50Z","isPatch":true,"sender":{"key":"mackyle@gmail.com","avatar":"https://avatars.githubusercontent.com/u/813346?v=4"},"body":"On Jul 24, 2013, at 12:07, Ramsay Jones wrote:\n\n>\n> Sparse issues an \"non-ANSI function declaration of function 'main'\"\n> warning when NO_CURL is set. In order to suppress the warning, we\n> simply add the function prototype.\n>\n> When NO_CURL and USE_CURL_MULTI are not defined, then gcc issues the\n> following error:\n>\n>      CC test-url-normalize.o\n>  test-url-normalize.c: In function `run_http_options':\n>  test-url-normalize.c:49: error: `max_requests' undeclared (first  \n> use in this function)\n>  test-url-normalize.c:49: error: (Each undeclared identifier is  \n> reported only once\n>  test-url-normalize.c:49: error: for each function it appears in.)\n>  make: *** [test-url-normalize.o] Error 1\n>\n> In order to fix the error, we simply protect the use of the  \n> 'max_requests'\n> variable with an preprocessor conditional.\n>\n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n> ---\n>\n> Hi Kyle,\n>\n> When you next update the patches in your 'km/http-curl-config-per-url'\n> branch, could you please squash this (or something like it) into the\n> relevant patches.\n>\n> Thanks!\n>\n> ATB,\n> Ramsay Jones\n\nThanks.\n\nAnd hopefully Junio can add this as an incremental patch against next  \nas it looks good to me.\n"},{"id":"224061","messageId":"7vli4v66b3.fsf@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"FDCB9C95-34A7-45D8-AC23-9739C24043B5@gmail.com","subject":"Re: [PATCH] test-url-normalize.c: Fix gcc errors and sparse warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-24T20:39:44Z","receivedAt":"2013-07-24T20:39:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Kyle J. McKay\" <mackyle@gmail.com> writes:\n\n> And hopefully Junio can add this as an incremental patch against next\n> as it looks good to me.\n\nNot likely to happen until the weekend.\n\nIf I had time for such a clean-up, I would rather be doing the\nrestructuring of the whole thing to make Peff's \"git config --url\n<class> <variable> $URL\" easier to code myself ;-)\n"},{"id":"224267","messageId":"1375138150-19520-1-git-send-email-gitster@pobox.com","threadId":"34530","inReplyTo":"7vli4v66b3.fsf@alter.siamese.dyndns.org","subject":"[PATCH 0/3] \"git config --get-urlmatch $section.$key $url\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-29T22:49:07Z","receivedAt":"2013-07-29T22:49:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"So here is a bit of refactoring to extract the logic to find the\nentry $section.<urlpattern>.$key from the configuration that best\nmatches the given $url to answer \"what value $section.$key should be\nfor $url?\" out of http.c (primarily because we never want to link\n\"git cofnig\" with the cURL library), and use it from \"git config\" to\nimplement Peff's idea to extend \"git config\".\n\nThe first step is a pure code movement, plus some renaming of the\nfunctions.\n\nThe second step is to factor out the code to handle --bool, --int, etc.\nas a helper so that the new codepath can use it.\n\nThe last step currently duplicates the logic in http_options(), but\nwe might want to refactor it further so that the two functions can\nshare more code.  We hopefully can get rid of test-url-normalize and\ninstead use \"git config --get-urlmatch\" in the tests that protect\nthe http.<url>.config topic.\n\nJunio C Hamano (3):\n  url-match: split out URL matching logic out of http.c\n  builtin/config: refactor collect_config()\n  config: --get-urlmatch\n\n Makefile             |   2 +\n builtin/config.c     | 183 ++++++++++++++++---\n http.c               | 500 +--------------------------------------------------\n test-url-normalize.c |   2 -\n url-match.c          | 468 +++++++++++++++++++++++++++++++++++++++++++++++\n url-match.h          |  35 ++++\n 6 files changed, 671 insertions(+), 519 deletions(-)\n create mode 100644 url-match.c\n create mode 100644 url-match.h\n\n-- \n1.8.4-rc0-137-g17832d4\n"},{"id":"224268","messageId":"1375138150-19520-2-git-send-email-gitster@pobox.com","threadId":"34530","inReplyTo":"1375138150-19520-1-git-send-email-gitster@pobox.com","subject":"[PATCH 1/3] url-match: split out URL matching logic out of http.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-29T22:49:08Z","receivedAt":"2013-07-29T22:49:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Move reusable URL matching code out of http.c, because it is not\nlimited to http, and we do not necessarily want to link its users\nwith the cURL library.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile             |   2 +\n http.c               | 500 +--------------------------------------------------\n test-url-normalize.c |   2 -\n url-match.c          | 468 +++++++++++++++++++++++++++++++++++++++++++++++\n url-match.h          |  35 ++++\n 5 files changed, 509 insertions(+), 498 deletions(-)\n create mode 100644 url-match.c\n create mode 100644 url-match.h\n\ndiff --git a/Makefile b/Makefile\nindex f83879c..92ccfb3 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -722,6 +722,7 @@ LIB_H += tree-walk.h\n LIB_H += tree.h\n LIB_H += unpack-trees.h\n LIB_H += url.h\n+LIB_H += url-match.h\n LIB_H += userdiff.h\n LIB_H += utf8.h\n LIB_H += varint.h\n@@ -869,6 +870,7 @@ LIB_OBJS += tree.o\n LIB_OBJS += tree-walk.o\n LIB_OBJS += unpack-trees.o\n LIB_OBJS += url.o\n+LIB_OBJS += url-match.o\n LIB_OBJS += usage.o\n LIB_OBJS += userdiff.o\n LIB_OBJS += utf8.o\ndiff --git a/http.c b/http.c\nindex c636d3c..a91a00b 100644\n--- a/http.c\n+++ b/http.c\n@@ -3,6 +3,7 @@\n #include \"sideband.h\"\n #include \"run-command.h\"\n #include \"url.h\"\n+#include \"url-match.h\"\n #include \"credential.h\"\n #include \"version.h\"\n #include \"pkt-line.h\"\n@@ -56,33 +57,6 @@ enum http_option_type {\n \tOPT_MAX\n };\n \n-struct url_info {\n-\tchar *url;\t\t/* normalized url on success, must be freed, otherwise NULL */\n-\tconst char *err;\t/* if !url, a brief reason for the failure, otherwise NULL */\n-\n-\t/* the rest of the fields are only set if url != NULL */\n-\n-\tsize_t url_len;\t\t/* total length of url (which is now normalized) */\n-\tsize_t scheme_len;\t/* length of scheme name (excluding final :) */\n-\tsize_t user_off;\t/* offset into url to start of user name (0 => none) */\n-\tsize_t user_len;\t/* length of user name; if user_off != 0 but\n-\t\t\t\t   user_len == 0, an empty user name was given */\n-\tsize_t passwd_off;\t/* offset into url to start of passwd (0 => none) */\n-\tsize_t passwd_len;\t/* length of passwd; if passwd_off != 0 but\n-\t\t\t\t   passwd_len == 0, an empty passwd was given */\n-\tsize_t host_off;\t/* offset into url to start of host name (0 => none) */\n-\tsize_t host_len;\t/* length of host name; this INCLUDES any ':portnum';\n-\t\t\t\t * file urls may have host_len == 0 */\n-\tsize_t port_len;\t/* if a portnum is present (port_len != 0), it has\n-\t\t\t\t * this length (excluding the leading ':') at the\n-\t\t\t\t * end of the host name (always 0 for file urls) */\n-\tsize_t path_off;\t/* offset into url to the start of the url path;\n-\t\t\t\t * this will always point to a '/' character\n-\t\t\t\t * after the url has been normalized */\n-\tsize_t path_len;\t/* length of path portion excluding any trailing\n-\t\t\t\t * '?...' and '#...' portion; will always be >= 1 */\n-};\n-\n static size_t http_option_max_matched_len[OPT_MAX];\n static int http_option_user_matched[OPT_MAX];\n \n@@ -197,472 +171,6 @@ static void process_curl_messages(void)\n }\n #endif\n \n-#define URL_ALPHA \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"\n-#define URL_DIGIT \"0123456789\"\n-#define URL_ALPHADIGIT URL_ALPHA URL_DIGIT\n-#define URL_SCHEME_CHARS URL_ALPHADIGIT \"+.-\"\n-#define URL_HOST_CHARS URL_ALPHADIGIT \".-[:]\" /* IPv6 literals need [:] */\n-#define URL_UNSAFE_CHARS \" <>\\\"%{}|\\\\^`\" /* plus 0x00-0x1F,0x7F-0xFF */\n-#define URL_GEN_RESERVED \":/?#[]@\"\n-#define URL_SUB_RESERVED \"!$&'()*+,;=\"\n-#define URL_RESERVED URL_GEN_RESERVED URL_SUB_RESERVED /* only allowed delims */\n-\n-static int append_normalized_escapes(struct strbuf *buf,\n-\t\t\t\t     const char *from,\n-\t\t\t\t     size_t from_len,\n-\t\t\t\t     const char *esc_extra,\n-\t\t\t\t     const char *esc_ok)\n-{\n-\t/*\n-\t * Append to strbuf 'buf' characters from string 'from' with length\n-\t * 'from_len' while unescaping characters that do not need to be escaped\n-\t * and escaping characters that do.  The set of characters to escape\n-\t * (the complement of which is unescaped) starts out as the RFC 3986\n-\t * unsafe characters (0x00-0x1F,0x7F-0xFF,\" <>\\\"#%{}|\\\\^`\").  If\n-\t * 'esc_extra' is not NULL, those additional characters will also always\n-\t * be escaped.  If 'esc_ok' is not NULL, those characters will be left\n-\t * escaped if found that way, but will not be unescaped otherwise (used\n-\t * for delimiters).  If a %-escape sequence is encountered that is not\n-\t * followed by 2 hexadecimal digits, the sequence is invalid and\n-\t * false (0) will be returned.  Otherwise true (1) will be returned for\n-\t * success.\n-\t *\n-\t * Note that all %-escape sequences will be normalized to UPPERCASE\n-\t * as indicated in RFC 3986.  Unless included in esc_extra or esc_ok\n-\t * alphanumerics and \"-._~\" will always be unescaped as per RFC 3986.\n-\t */\n-\n-\twhile (from_len) {\n-\t\tint ch = *from++;\n-\t\tint was_esc = 0;\n-\n-\t\tfrom_len--;\n-\t\tif (ch == '%') {\n-\t\t\tif (from_len < 2 ||\n-\t\t\t    !isxdigit((unsigned char)from[0]) ||\n-\t\t\t    !isxdigit((unsigned char)from[1]))\n-\t\t\t\treturn 0;\n-\t\t\tch = hexval_table[(unsigned char)*from++] << 4;\n-\t\t\tch |= hexval_table[(unsigned char)*from++];\n-\t\t\tfrom_len -= 2;\n-\t\t\twas_esc = 1;\n-\t\t}\n-\t\tif ((unsigned char)ch <= 0x1F || (unsigned char)ch >= 0x7F ||\n-\t\t    strchr(URL_UNSAFE_CHARS, ch) ||\n-\t\t    (esc_extra && strchr(esc_extra, ch)) ||\n-\t\t    (was_esc && strchr(esc_ok, ch)))\n-\t\t\tstrbuf_addf(buf, \"%%%02X\", (unsigned char)ch);\n-\t\telse\n-\t\t\tstrbuf_addch(buf, ch);\n-\t}\n-\n-\treturn 1;\n-}\n-\n-static char *http_options_url_normalize(const char *url, struct url_info *out_info)\n-{\n-\t/*\n-\t * Normalize NUL-terminated url using the following rules:\n-\t *\n-\t * 1. Case-insensitive parts of url will be converted to lower case\n-\t * 2. %-encoded characters that do not need to be will be unencoded\n-\t * 3. Characters that are not %-encoded and must be will be encoded\n-\t * 4. All %-encodings will be converted to upper case hexadecimal\n-\t * 5. Leading 0s are removed from port numbers\n-\t * 6. If the default port for the scheme is given it will be removed\n-\t * 7. A path part (including empty) not starting with '/' has one added\n-\t * 8. Any dot segments (. or ..) in the path are resolved and removed\n-\t * 9. IPv6 host literals are allowed (but not normalized or validated)\n-\t *\n-\t * The rules are based on information in RFC 3986.\n-\t *\n-\t * Please note this function requires a full URL including a scheme\n-\t * and host part (except for file: URLs which may have an empty host).\n-\t *\n-\t * The return value is a newly allocated string that must be freed\n-\t * or NULL if the url is not valid.\n-\t *\n-\t * If out_info is non-NULL, the url and err fields therein will always\n-\t * be set.  If a non-NULL value is returned, it will be stored in\n-\t * out_info->url as well, out_info->err will be set to NULL and the\n-\t * other fields of *out_info will also be filled in.  If a NULL value\n-\t * is returned, NULL will be stored in out_info->url and out_info->err\n-\t * will be set to a brief, translated, error message, but no other\n-\t * fields will be filled in.\n-\t *\n-\t * This is NOT a URL validation function.  Full URL validation is NOT\n-\t * performed.  Some invalid host names are passed through this function\n-\t * undetected.  However, most all other problems that make a URL invalid\n-\t * will be detected (including a missing host for non file: URLs).\n-\t */\n-\n-\tsize_t url_len = strlen(url);\n-\tstruct strbuf norm;\n-\tsize_t spanned;\n-\tsize_t scheme_len, user_off=0, user_len=0, passwd_off=0, passwd_len=0;\n-\tsize_t host_off=0, host_len=0, port_len=0, path_off, path_len, result_len;\n-\tconst char *slash_ptr, *at_ptr, *colon_ptr, *path_start;\n-\tchar *result;\n-\n-\t/*\n-\t * Copy lowercased scheme and :// suffix, %-escapes are not allowed\n-\t * First character of scheme must be URL_ALPHA\n-\t */\n-\tspanned = strspn(url, URL_SCHEME_CHARS);\n-\tif (!spanned || !isalpha(url[0]) || spanned + 3 > url_len ||\n-\t    url[spanned] != ':' || url[spanned+1] != '/' || url[spanned+2] != '/') {\n-\t\tif (out_info) {\n-\t\t\tout_info->url = NULL;\n-\t\t\tout_info->err = _(\"invalid URL scheme name or missing '://' suffix\");\n-\t\t}\n-\t\treturn NULL; /* Bad scheme and/or missing \"://\" part */\n-\t}\n-\tstrbuf_init(&norm, url_len);\n-\tscheme_len = spanned;\n-\tspanned += 3;\n-\turl_len -= spanned;\n-\twhile (spanned--)\n-\t\tstrbuf_addch(&norm, tolower(*url++));\n-\n-\n-\t/*\n-\t * Copy any username:password if present normalizing %-escapes\n-\t */\n-\tat_ptr = strchr(url, '@');\n-\tslash_ptr = url + strcspn(url, \"/?#\");\n-\tif (at_ptr && at_ptr < slash_ptr) {\n-\t\tuser_off = norm.len;\n-\t\tif (at_ptr > url) {\n-\t\t\tif (!append_normalized_escapes(&norm, url, at_ptr - url,\n-\t\t\t\t\t\t       \"\", URL_RESERVED)) {\n-\t\t\t\tif (out_info) {\n-\t\t\t\t\tout_info->url = NULL;\n-\t\t\t\t\tout_info->err = _(\"invalid %XX escape sequence\");\n-\t\t\t\t}\n-\t\t\t\tstrbuf_release(&norm);\n-\t\t\t\treturn NULL;\n-\t\t\t}\n-\t\t\tcolon_ptr = strchr(norm.buf + scheme_len + 3, ':');\n-\t\t\tif (colon_ptr) {\n-\t\t\t\tpasswd_off = (colon_ptr + 1) - norm.buf;\n-\t\t\t\tpasswd_len = norm.len - passwd_off;\n-\t\t\t\tuser_len = (passwd_off - 1) - (scheme_len + 3);\n-\t\t\t} else {\n-\t\t\t\tuser_len = norm.len - (scheme_len + 3);\n-\t\t\t}\n-\t\t}\n-\t\tstrbuf_addch(&norm, '@');\n-\t\turl_len -= (++at_ptr - url);\n-\t\turl = at_ptr;\n-\t}\n-\n-\n-\t/*\n-\t * Copy the host part excluding any port part, no %-escapes allowed\n-\t */\n-\tif (!url_len || strchr(\":/?#\", *url)) {\n-\t\t/* Missing host invalid for all URL schemes except file */\n-\t\tif (strncmp(norm.buf, \"file:\", 5)) {\n-\t\t\tif (out_info) {\n-\t\t\t\tout_info->url = NULL;\n-\t\t\t\tout_info->err = _(\"missing host and scheme is not 'file:'\");\n-\t\t\t}\n-\t\t\tstrbuf_release(&norm);\n-\t\t\treturn NULL;\n-\t\t}\n-\t} else {\n-\t\thost_off = norm.len;\n-\t}\n-\tcolon_ptr = slash_ptr - 1;\n-\twhile (colon_ptr > url && *colon_ptr != ':' && *colon_ptr != ']')\n-\t\tcolon_ptr--;\n-\tif (*colon_ptr != ':') {\n-\t\tcolon_ptr = slash_ptr;\n-\t} else if (!host_off && colon_ptr < slash_ptr && colon_ptr + 1 != slash_ptr) {\n-\t\t/* file: URLs may not have a port number */\n-\t\tif (out_info) {\n-\t\t\tout_info->url = NULL;\n-\t\t\tout_info->err = _(\"a 'file:' URL may not have a port number\");\n-\t\t}\n-\t\tstrbuf_release(&norm);\n-\t\treturn NULL;\n-\t}\n-\tspanned = strspn(url, URL_HOST_CHARS);\n-\tif (spanned < colon_ptr - url) {\n-\t\t/* Host name has invalid characters */\n-\t\tif (out_info) {\n-\t\t\tout_info->url = NULL;\n-\t\t\tout_info->err = _(\"invalid characters in host name\");\n-\t\t}\n-\t\tstrbuf_release(&norm);\n-\t\treturn NULL;\n-\t}\n-\twhile (url < colon_ptr) {\n-\t\tstrbuf_addch(&norm, tolower(*url++));\n-\t\turl_len--;\n-\t}\n-\n-\n-\t/*\n-\t * Check the port part and copy if not the default (after removing any\n-\t * leading 0s); no %-escapes allowed\n-\t */\n-\tif (colon_ptr < slash_ptr) {\n-\t\t/* skip the ':' and leading 0s but not the last one if all 0s */\n-\t\turl++;\n-\t\turl += strspn(url, \"0\");\n-\t\tif (url == slash_ptr && url[-1] == '0')\n-\t\t\turl--;\n-\t\tif (url == slash_ptr) {\n-\t\t\t/* Skip \":\" port with no number, it's same as default */\n-\t\t} else if (slash_ptr - url == 2 &&\n-\t\t\t   !strncmp(norm.buf, \"http:\", 5) &&\n-\t\t\t   !strncmp(url, \"80\", 2)) {\n-\t\t\t/* Skip http :80 as it's the default */\n-\t\t} else if (slash_ptr - url == 3 &&\n-\t\t\t   !strncmp(norm.buf, \"https:\", 6) &&\n-\t\t\t   !strncmp(url, \"443\", 3)) {\n-\t\t\t/* Skip https :443 as it's the default */\n-\t\t} else {\n-\t\t\t/*\n-\t\t\t * Port number must be all digits with leading 0s removed\n-\t\t\t * and since all the protocols we deal with have a 16-bit\n-\t\t\t * port number it must also be in the range 1..65535\n-\t\t\t * 0 is not allowed because that means \"next available\"\n-\t\t\t * on just about every system and therefore cannot be used\n-\t\t\t */\n-\t\t\tunsigned long pnum = 0;\n-\t\t\tspanned = strspn(url, URL_DIGIT);\n-\t\t\tif (spanned < slash_ptr - url) {\n-\t\t\t\t/* port number has invalid characters */\n-\t\t\t\tif (out_info) {\n-\t\t\t\t\tout_info->url = NULL;\n-\t\t\t\t\tout_info->err = _(\"invalid port number\");\n-\t\t\t\t}\n-\t\t\t\tstrbuf_release(&norm);\n-\t\t\t\treturn NULL;\n-\t\t\t}\n-\t\t\tif (slash_ptr - url <= 5)\n-\t\t\t\tpnum = strtoul(url, NULL, 10);\n-\t\t\tif (pnum == 0 || pnum > 65535) {\n-\t\t\t\t/* port number not in range 1..65535 */\n-\t\t\t\tif (out_info) {\n-\t\t\t\t\tout_info->url = NULL;\n-\t\t\t\t\tout_info->err = _(\"invalid port number\");\n-\t\t\t\t}\n-\t\t\t\tstrbuf_release(&norm);\n-\t\t\t\treturn NULL;\n-\t\t\t}\n-\t\t\tstrbuf_addch(&norm, ':');\n-\t\t\tstrbuf_add(&norm, url, slash_ptr - url);\n-\t\t\tport_len = slash_ptr - url;\n-\t\t}\n-\t\turl_len -= slash_ptr - colon_ptr;\n-\t\turl = slash_ptr;\n-\t}\n-\tif (host_off)\n-\t\thost_len = norm.len - host_off;\n-\n-\n-\t/*\n-\t * Now copy the path resolving any . and .. segments being careful not\n-\t * to corrupt the URL by unescaping any delimiters, but do add an\n-\t * initial '/' if it's missing and do normalize any %-escape sequences.\n-\t */\n-\tpath_off = norm.len;\n-\tpath_start = norm.buf + path_off;\n-\tstrbuf_addch(&norm, '/');\n-\tif (*url == '/') {\n-\t\turl++;\n-\t\turl_len--;\n-\t}\n-\tfor (;;) {\n-\t\tconst char *seg_start = norm.buf + norm.len;\n-\t\tconst char *next_slash = url + strcspn(url, \"/?#\");\n-\t\tint skip_add_slash = 0;\n-\t\t/*\n-\t\t * RFC 3689 indicates that any . or .. segments should be\n-\t\t * unescaped before being checked for.\n-\t\t */\n-\t\tif (!append_normalized_escapes(&norm, url, next_slash - url, \"\",\n-\t\t\t\t\t       URL_RESERVED)) {\n-\t\t\tif (out_info) {\n-\t\t\t\tout_info->url = NULL;\n-\t\t\t\tout_info->err = _(\"invalid %XX escape sequence\");\n-\t\t\t}\n-\t\t\tstrbuf_release(&norm);\n-\t\t\treturn NULL;\n-\t\t}\n-\t\tif (!strcmp(seg_start, \".\")) {\n-\t\t\t/* ignore a . segment; be careful not to remove initial '/' */\n-\t\t\tif (seg_start == path_start + 1) {\n-\t\t\t\tstrbuf_setlen(&norm, norm.len - 1);\n-\t\t\t\tskip_add_slash = 1;\n-\t\t\t} else {\n-\t\t\t\tstrbuf_setlen(&norm, norm.len - 2);\n-\t\t\t}\n-\t\t} else if (!strcmp(seg_start, \"..\")) {\n-\t\t\t/*\n-\t\t\t * ignore a .. segment and remove the previous segment;\n-\t\t\t * be careful not to remove initial '/' from path\n-\t\t\t */\n-\t\t\tconst char *prev_slash = norm.buf + norm.len - 3;\n-\t\t\tif (prev_slash == path_start) {\n-\t\t\t\t/* invalid .. because no previous segment to remove */\n-\t\t\t\tif (out_info) {\n-\t\t\t\t\tout_info->url = NULL;\n-\t\t\t\t\tout_info->err = _(\"invalid '..' path segment\");\n-\t\t\t\t}\n-\t\t\t\tstrbuf_release(&norm);\n-\t\t\t\treturn NULL;\n-\t\t\t}\n-\t\t\twhile (*--prev_slash != '/') {}\n-\t\t\tif (prev_slash == path_start) {\n-\t\t\t\tstrbuf_setlen(&norm, prev_slash - norm.buf + 1);\n-\t\t\t\tskip_add_slash = 1;\n-\t\t\t} else {\n-\t\t\t\tstrbuf_setlen(&norm, prev_slash - norm.buf);\n-\t\t\t}\n-\t\t}\n-\t\turl_len -= next_slash - url;\n-\t\turl = next_slash;\n-\t\t/* if the next char is not '/' done with the path */\n-\t\tif (*url != '/')\n-\t\t\tbreak;\n-\t\turl++;\n-\t\turl_len--;\n-\t\tif (!skip_add_slash)\n-\t\t\tstrbuf_addch(&norm, '/');\n-\t}\n-\tpath_len = norm.len - path_off;\n-\n-\n-\t/*\n-\t * Now simply copy the rest, if any, only normalizing %-escapes and\n-\t * being careful not to corrupt the URL by unescaping any delimiters.\n-\t */\n-\tif (*url) {\n-\t\tif (!append_normalized_escapes(&norm, url, url_len, \"\", URL_RESERVED)) {\n-\t\t\tif (out_info) {\n-\t\t\t\tout_info->url = NULL;\n-\t\t\t\tout_info->err = _(\"invalid %XX escape sequence\");\n-\t\t\t}\n-\t\t\tstrbuf_release(&norm);\n-\t\t\treturn NULL;\n-\t\t}\n-\t}\n-\n-\n-\tresult = strbuf_detach(&norm, &result_len);\n-\tif (out_info) {\n-\t\tout_info->url = result;\n-\t\tout_info->err = NULL;\n-\t\tout_info->url_len = result_len;\n-\t\tout_info->scheme_len = scheme_len;\n-\t\tout_info->user_off = user_off;\n-\t\tout_info->user_len = user_len;\n-\t\tout_info->passwd_off = passwd_off;\n-\t\tout_info->passwd_len = passwd_len;\n-\t\tout_info->host_off = host_off;\n-\t\tout_info->host_len = host_len;\n-\t\tout_info->port_len = port_len;\n-\t\tout_info->path_off = path_off;\n-\t\tout_info->path_len = path_len;\n-\t}\n-\treturn result;\n-}\n-\n-static size_t http_options_url_match_prefix(const char *url,\n-\t\t\t\t\t    const char *url_prefix,\n-\t\t\t\t\t    size_t url_prefix_len)\n-{\n-\t/*\n-\t * url_prefix matches url if url_prefix is an exact match for url or it\n-\t * is a prefix of url and the match ends on a path component boundary.\n-\t * Both url and url_prefix are considered to have an implicit '/' on the\n-\t * end for matching purposes if they do not already.\n-\t *\n-\t * url must be NUL terminated.  url_prefix_len is the length of\n-\t * url_prefix which need not be NUL terminated.\n-\t *\n-\t * The return value is the length of the match in characters (including\n-\t * the final '/' even if it's implicit) or 0 for no match.\n-\t *\n-\t * Passing NULL as url and/or url_prefix will always cause 0 to be\n-\t * returned without causing any faults.\n-\t */\n-\tif (!url || !url_prefix)\n-\t\treturn 0;\n-\tif (!url_prefix_len || (url_prefix_len == 1 && *url_prefix == '/'))\n-\t\treturn (!*url || *url == '/') ? 1 : 0;\n-\tif (url_prefix[url_prefix_len - 1] == '/')\n-\t\turl_prefix_len--;\n-\tif (strncmp(url, url_prefix, url_prefix_len))\n-\t\treturn 0;\n-\tif ((strlen(url) == url_prefix_len) || (url[url_prefix_len] == '/'))\n-\t\treturn url_prefix_len + 1;\n-\treturn 0;\n-}\n-\n-static int http_options_match_urls(const struct url_info *url,\n-\t\t\t\t   const struct url_info *url_prefix,\n-\t\t\t\t   int *exactusermatch)\n-{\n-\t/*\n-\t * url_prefix matches url if the scheme, host and port of url_prefix\n-\t * are the same as those of url and the path portion of url_prefix\n-\t * is the same as the path portion of url or it is a prefix that\n-\t * matches at a '/' boundary.  If url_prefix contains a user name,\n-\t * that must also exactly match the user name in url.\n-\t *\n-\t * If the user, host, port and path match in this fashion, the returned\n-\t * value is the length of the path match including any implicit\n-\t * final '/'.  For example, \"http://me@example.com/path\" is matched by\n-\t * \"http://example.com\" with a path length of 1.\n-\t *\n-\t * If there is a match and exactusermatch is not NULL, then\n-\t * *exactusermatch will be set to true if both url and url_prefix\n-\t * contained a user name or false if url_prefix did not have a\n-\t * user name.  If there is no match *exactusermatch is left untouched.\n-\t */\n-\tint usermatched = 0;\n-\tint pathmatchlen;\n-\n-\tif (!url || !url_prefix || !url->url || !url_prefix->url)\n-\t\treturn 0;\n-\n-\t/* check the scheme */\n-\tif (url_prefix->scheme_len != url->scheme_len ||\n-\t    strncmp(url->url, url_prefix->url, url->scheme_len))\n-\t\treturn 0; /* schemes do not match */\n-\n-\t/* check the user name if url_prefix has one */\n-\tif (url_prefix->user_off) {\n-\t\tif (!url->user_off || url->user_len != url_prefix->user_len ||\n-\t\t    strncmp(url->url + url->user_off,\n-\t\t\t    url_prefix->url + url_prefix->user_off,\n-\t\t\t    url->user_len))\n-\t\t\treturn 0; /* url_prefix has a user but it's not a match */\n-\t\tusermatched = 1;\n-\t}\n-\n-\t/* check the host and port */\n-\tif (url_prefix->host_len != url->host_len ||\n-\t    strncmp(url->url + url->host_off,\n-\t\t    url_prefix->url + url_prefix->host_off, url->host_len))\n-\t\treturn 0; /* host names and/or ports do not match */\n-\n-\t/* check the path */\n-\tpathmatchlen = http_options_url_match_prefix(\n-\t\turl->url + url->path_off,\n-\t\turl_prefix->url + url_prefix->path_off,\n-\t\turl_prefix->url_len - url_prefix->path_off);\n-\n-\tif (pathmatchlen && exactusermatch)\n-\t\t*exactusermatch = usermatched;\n-\treturn pathmatchlen;\n-}\n-\n static int match_is_ignored(size_t matchlen, int usermatch, enum http_option_type opt)\n {\n \t/*\n@@ -720,11 +228,11 @@ static int http_options(const char *var, const char *value, void *cb)\n \t\tif (!info || !info->url)\n \t\t\treturn 0;\n \t\tconfig_url = xmemdupz(key, dot - key);\n-\t\tnorm_url = http_options_url_normalize(config_url, &norm_info);\n+\t\tnorm_url = url_normalize(config_url, &norm_info);\n \t\tfree(config_url);\n \t\tif (!norm_url)\n \t\t\treturn 0;\n-\t\tmatchlen = http_options_match_urls(info, &norm_info, &usermatch);\n+\t\tmatchlen = match_urls(info, &norm_info, &usermatch);\n \t\tfree(norm_url);\n \t\tif (!matchlen)\n \t\t\treturn 0;\n@@ -967,7 +475,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)\n \n \tmemset(http_option_max_matched_len, 0, sizeof(http_option_max_matched_len));\n \tmemset(http_option_user_matched, 0, sizeof(http_option_user_matched));\n-\thttp_options_url_normalize(url, &info);\n+\turl_normalize(url, &info);\n \tgit_config(http_options, &info);\n \tfree(info.url);\n \ndiff --git a/test-url-normalize.c b/test-url-normalize.c\nindex 4f870dc..0b809eb 100644\n--- a/test-url-normalize.c\n+++ b/test-url-normalize.c\n@@ -65,8 +65,6 @@ static int run_http_options(const char *file,\n \treturn 0;\n }\n \n-#define url_normalize(u,i) http_options_url_normalize(u,i)\n-\n int main(int argc, char **argv)\n {\n \tconst char *usage = \"test-url-normalize [-p | -l] <url1> | <url1> <url2>\"\ndiff --git a/url-match.c b/url-match.c\nnew file mode 100644\nindex 0000000..424a0a0\n--- /dev/null\n+++ b/url-match.c\n@@ -0,0 +1,468 @@\n+#include \"cache.h\"\n+#include \"url-match.h\"\n+\n+#define URL_ALPHA \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"\n+#define URL_DIGIT \"0123456789\"\n+#define URL_ALPHADIGIT URL_ALPHA URL_DIGIT\n+#define URL_SCHEME_CHARS URL_ALPHADIGIT \"+.-\"\n+#define URL_HOST_CHARS URL_ALPHADIGIT \".-[:]\" /* IPv6 literals need [:] */\n+#define URL_UNSAFE_CHARS \" <>\\\"%{}|\\\\^`\" /* plus 0x00-0x1F,0x7F-0xFF */\n+#define URL_GEN_RESERVED \":/?#[]@\"\n+#define URL_SUB_RESERVED \"!$&'()*+,;=\"\n+#define URL_RESERVED URL_GEN_RESERVED URL_SUB_RESERVED /* only allowed delims */\n+\n+static int append_normalized_escapes(struct strbuf *buf,\n+\t\t\t\t     const char *from,\n+\t\t\t\t     size_t from_len,\n+\t\t\t\t     const char *esc_extra,\n+\t\t\t\t     const char *esc_ok)\n+{\n+\t/*\n+\t * Append to strbuf 'buf' characters from string 'from' with length\n+\t * 'from_len' while unescaping characters that do not need to be escaped\n+\t * and escaping characters that do.  The set of characters to escape\n+\t * (the complement of which is unescaped) starts out as the RFC 3986\n+\t * unsafe characters (0x00-0x1F,0x7F-0xFF,\" <>\\\"#%{}|\\\\^`\").  If\n+\t * 'esc_extra' is not NULL, those additional characters will also always\n+\t * be escaped.  If 'esc_ok' is not NULL, those characters will be left\n+\t * escaped if found that way, but will not be unescaped otherwise (used\n+\t * for delimiters).  If a %-escape sequence is encountered that is not\n+\t * followed by 2 hexadecimal digits, the sequence is invalid and\n+\t * false (0) will be returned.  Otherwise true (1) will be returned for\n+\t * success.\n+\t *\n+\t * Note that all %-escape sequences will be normalized to UPPERCASE\n+\t * as indicated in RFC 3986.  Unless included in esc_extra or esc_ok\n+\t * alphanumerics and \"-._~\" will always be unescaped as per RFC 3986.\n+\t */\n+\n+\twhile (from_len) {\n+\t\tint ch = *from++;\n+\t\tint was_esc = 0;\n+\n+\t\tfrom_len--;\n+\t\tif (ch == '%') {\n+\t\t\tif (from_len < 2 ||\n+\t\t\t    !isxdigit((unsigned char)from[0]) ||\n+\t\t\t    !isxdigit((unsigned char)from[1]))\n+\t\t\t\treturn 0;\n+\t\t\tch = hexval_table[(unsigned char)*from++] << 4;\n+\t\t\tch |= hexval_table[(unsigned char)*from++];\n+\t\t\tfrom_len -= 2;\n+\t\t\twas_esc = 1;\n+\t\t}\n+\t\tif ((unsigned char)ch <= 0x1F || (unsigned char)ch >= 0x7F ||\n+\t\t    strchr(URL_UNSAFE_CHARS, ch) ||\n+\t\t    (esc_extra && strchr(esc_extra, ch)) ||\n+\t\t    (was_esc && strchr(esc_ok, ch)))\n+\t\t\tstrbuf_addf(buf, \"%%%02X\", (unsigned char)ch);\n+\t\telse\n+\t\t\tstrbuf_addch(buf, ch);\n+\t}\n+\n+\treturn 1;\n+}\n+\n+char *url_normalize(const char *url, struct url_info *out_info)\n+{\n+\t/*\n+\t * Normalize NUL-terminated url using the following rules:\n+\t *\n+\t * 1. Case-insensitive parts of url will be converted to lower case\n+\t * 2. %-encoded characters that do not need to be will be unencoded\n+\t * 3. Characters that are not %-encoded and must be will be encoded\n+\t * 4. All %-encodings will be converted to upper case hexadecimal\n+\t * 5. Leading 0s are removed from port numbers\n+\t * 6. If the default port for the scheme is given it will be removed\n+\t * 7. A path part (including empty) not starting with '/' has one added\n+\t * 8. Any dot segments (. or ..) in the path are resolved and removed\n+\t * 9. IPv6 host literals are allowed (but not normalized or validated)\n+\t *\n+\t * The rules are based on information in RFC 3986.\n+\t *\n+\t * Please note this function requires a full URL including a scheme\n+\t * and host part (except for file: URLs which may have an empty host).\n+\t *\n+\t * The return value is a newly allocated string that must be freed\n+\t * or NULL if the url is not valid.\n+\t *\n+\t * If out_info is non-NULL, the url and err fields therein will always\n+\t * be set.  If a non-NULL value is returned, it will be stored in\n+\t * out_info->url as well, out_info->err will be set to NULL and the\n+\t * other fields of *out_info will also be filled in.  If a NULL value\n+\t * is returned, NULL will be stored in out_info->url and out_info->err\n+\t * will be set to a brief, translated, error message, but no other\n+\t * fields will be filled in.\n+\t *\n+\t * This is NOT a URL validation function.  Full URL validation is NOT\n+\t * performed.  Some invalid host names are passed through this function\n+\t * undetected.  However, most all other problems that make a URL invalid\n+\t * will be detected (including a missing host for non file: URLs).\n+\t */\n+\n+\tsize_t url_len = strlen(url);\n+\tstruct strbuf norm;\n+\tsize_t spanned;\n+\tsize_t scheme_len, user_off=0, user_len=0, passwd_off=0, passwd_len=0;\n+\tsize_t host_off=0, host_len=0, port_len=0, path_off, path_len, result_len;\n+\tconst char *slash_ptr, *at_ptr, *colon_ptr, *path_start;\n+\tchar *result;\n+\n+\t/*\n+\t * Copy lowercased scheme and :// suffix, %-escapes are not allowed\n+\t * First character of scheme must be URL_ALPHA\n+\t */\n+\tspanned = strspn(url, URL_SCHEME_CHARS);\n+\tif (!spanned || !isalpha(url[0]) || spanned + 3 > url_len ||\n+\t    url[spanned] != ':' || url[spanned+1] != '/' || url[spanned+2] != '/') {\n+\t\tif (out_info) {\n+\t\t\tout_info->url = NULL;\n+\t\t\tout_info->err = _(\"invalid URL scheme name or missing '://' suffix\");\n+\t\t}\n+\t\treturn NULL; /* Bad scheme and/or missing \"://\" part */\n+\t}\n+\tstrbuf_init(&norm, url_len);\n+\tscheme_len = spanned;\n+\tspanned += 3;\n+\turl_len -= spanned;\n+\twhile (spanned--)\n+\t\tstrbuf_addch(&norm, tolower(*url++));\n+\n+\n+\t/*\n+\t * Copy any username:password if present normalizing %-escapes\n+\t */\n+\tat_ptr = strchr(url, '@');\n+\tslash_ptr = url + strcspn(url, \"/?#\");\n+\tif (at_ptr && at_ptr < slash_ptr) {\n+\t\tuser_off = norm.len;\n+\t\tif (at_ptr > url) {\n+\t\t\tif (!append_normalized_escapes(&norm, url, at_ptr - url,\n+\t\t\t\t\t\t       \"\", URL_RESERVED)) {\n+\t\t\t\tif (out_info) {\n+\t\t\t\t\tout_info->url = NULL;\n+\t\t\t\t\tout_info->err = _(\"invalid %XX escape sequence\");\n+\t\t\t\t}\n+\t\t\t\tstrbuf_release(&norm);\n+\t\t\t\treturn NULL;\n+\t\t\t}\n+\t\t\tcolon_ptr = strchr(norm.buf + scheme_len + 3, ':');\n+\t\t\tif (colon_ptr) {\n+\t\t\t\tpasswd_off = (colon_ptr + 1) - norm.buf;\n+\t\t\t\tpasswd_len = norm.len - passwd_off;\n+\t\t\t\tuser_len = (passwd_off - 1) - (scheme_len + 3);\n+\t\t\t} else {\n+\t\t\t\tuser_len = norm.len - (scheme_len + 3);\n+\t\t\t}\n+\t\t}\n+\t\tstrbuf_addch(&norm, '@');\n+\t\turl_len -= (++at_ptr - url);\n+\t\turl = at_ptr;\n+\t}\n+\n+\n+\t/*\n+\t * Copy the host part excluding any port part, no %-escapes allowed\n+\t */\n+\tif (!url_len || strchr(\":/?#\", *url)) {\n+\t\t/* Missing host invalid for all URL schemes except file */\n+\t\tif (strncmp(norm.buf, \"file:\", 5)) {\n+\t\t\tif (out_info) {\n+\t\t\t\tout_info->url = NULL;\n+\t\t\t\tout_info->err = _(\"missing host and scheme is not 'file:'\");\n+\t\t\t}\n+\t\t\tstrbuf_release(&norm);\n+\t\t\treturn NULL;\n+\t\t}\n+\t} else {\n+\t\thost_off = norm.len;\n+\t}\n+\tcolon_ptr = slash_ptr - 1;\n+\twhile (colon_ptr > url && *colon_ptr != ':' && *colon_ptr != ']')\n+\t\tcolon_ptr--;\n+\tif (*colon_ptr != ':') {\n+\t\tcolon_ptr = slash_ptr;\n+\t} else if (!host_off && colon_ptr < slash_ptr && colon_ptr + 1 != slash_ptr) {\n+\t\t/* file: URLs may not have a port number */\n+\t\tif (out_info) {\n+\t\t\tout_info->url = NULL;\n+\t\t\tout_info->err = _(\"a 'file:' URL may not have a port number\");\n+\t\t}\n+\t\tstrbuf_release(&norm);\n+\t\treturn NULL;\n+\t}\n+\tspanned = strspn(url, URL_HOST_CHARS);\n+\tif (spanned < colon_ptr - url) {\n+\t\t/* Host name has invalid characters */\n+\t\tif (out_info) {\n+\t\t\tout_info->url = NULL;\n+\t\t\tout_info->err = _(\"invalid characters in host name\");\n+\t\t}\n+\t\tstrbuf_release(&norm);\n+\t\treturn NULL;\n+\t}\n+\twhile (url < colon_ptr) {\n+\t\tstrbuf_addch(&norm, tolower(*url++));\n+\t\turl_len--;\n+\t}\n+\n+\n+\t/*\n+\t * Check the port part and copy if not the default (after removing any\n+\t * leading 0s); no %-escapes allowed\n+\t */\n+\tif (colon_ptr < slash_ptr) {\n+\t\t/* skip the ':' and leading 0s but not the last one if all 0s */\n+\t\turl++;\n+\t\turl += strspn(url, \"0\");\n+\t\tif (url == slash_ptr && url[-1] == '0')\n+\t\t\turl--;\n+\t\tif (url == slash_ptr) {\n+\t\t\t/* Skip \":\" port with no number, it's same as default */\n+\t\t} else if (slash_ptr - url == 2 &&\n+\t\t\t   !strncmp(norm.buf, \"http:\", 5) &&\n+\t\t\t   !strncmp(url, \"80\", 2)) {\n+\t\t\t/* Skip http :80 as it's the default */\n+\t\t} else if (slash_ptr - url == 3 &&\n+\t\t\t   !strncmp(norm.buf, \"https:\", 6) &&\n+\t\t\t   !strncmp(url, \"443\", 3)) {\n+\t\t\t/* Skip https :443 as it's the default */\n+\t\t} else {\n+\t\t\t/*\n+\t\t\t * Port number must be all digits with leading 0s removed\n+\t\t\t * and since all the protocols we deal with have a 16-bit\n+\t\t\t * port number it must also be in the range 1..65535\n+\t\t\t * 0 is not allowed because that means \"next available\"\n+\t\t\t * on just about every system and therefore cannot be used\n+\t\t\t */\n+\t\t\tunsigned long pnum = 0;\n+\t\t\tspanned = strspn(url, URL_DIGIT);\n+\t\t\tif (spanned < slash_ptr - url) {\n+\t\t\t\t/* port number has invalid characters */\n+\t\t\t\tif (out_info) {\n+\t\t\t\t\tout_info->url = NULL;\n+\t\t\t\t\tout_info->err = _(\"invalid port number\");\n+\t\t\t\t}\n+\t\t\t\tstrbuf_release(&norm);\n+\t\t\t\treturn NULL;\n+\t\t\t}\n+\t\t\tif (slash_ptr - url <= 5)\n+\t\t\t\tpnum = strtoul(url, NULL, 10);\n+\t\t\tif (pnum == 0 || pnum > 65535) {\n+\t\t\t\t/* port number not in range 1..65535 */\n+\t\t\t\tif (out_info) {\n+\t\t\t\t\tout_info->url = NULL;\n+\t\t\t\t\tout_info->err = _(\"invalid port number\");\n+\t\t\t\t}\n+\t\t\t\tstrbuf_release(&norm);\n+\t\t\t\treturn NULL;\n+\t\t\t}\n+\t\t\tstrbuf_addch(&norm, ':');\n+\t\t\tstrbuf_add(&norm, url, slash_ptr - url);\n+\t\t\tport_len = slash_ptr - url;\n+\t\t}\n+\t\turl_len -= slash_ptr - colon_ptr;\n+\t\turl = slash_ptr;\n+\t}\n+\tif (host_off)\n+\t\thost_len = norm.len - host_off;\n+\n+\n+\t/*\n+\t * Now copy the path resolving any . and .. segments being careful not\n+\t * to corrupt the URL by unescaping any delimiters, but do add an\n+\t * initial '/' if it's missing and do normalize any %-escape sequences.\n+\t */\n+\tpath_off = norm.len;\n+\tpath_start = norm.buf + path_off;\n+\tstrbuf_addch(&norm, '/');\n+\tif (*url == '/') {\n+\t\turl++;\n+\t\turl_len--;\n+\t}\n+\tfor (;;) {\n+\t\tconst char *seg_start = norm.buf + norm.len;\n+\t\tconst char *next_slash = url + strcspn(url, \"/?#\");\n+\t\tint skip_add_slash = 0;\n+\t\t/*\n+\t\t * RFC 3689 indicates that any . or .. segments should be\n+\t\t * unescaped before being checked for.\n+\t\t */\n+\t\tif (!append_normalized_escapes(&norm, url, next_slash - url, \"\",\n+\t\t\t\t\t       URL_RESERVED)) {\n+\t\t\tif (out_info) {\n+\t\t\t\tout_info->url = NULL;\n+\t\t\t\tout_info->err = _(\"invalid %XX escape sequence\");\n+\t\t\t}\n+\t\t\tstrbuf_release(&norm);\n+\t\t\treturn NULL;\n+\t\t}\n+\t\tif (!strcmp(seg_start, \".\")) {\n+\t\t\t/* ignore a . segment; be careful not to remove initial '/' */\n+\t\t\tif (seg_start == path_start + 1) {\n+\t\t\t\tstrbuf_setlen(&norm, norm.len - 1);\n+\t\t\t\tskip_add_slash = 1;\n+\t\t\t} else {\n+\t\t\t\tstrbuf_setlen(&norm, norm.len - 2);\n+\t\t\t}\n+\t\t} else if (!strcmp(seg_start, \"..\")) {\n+\t\t\t/*\n+\t\t\t * ignore a .. segment and remove the previous segment;\n+\t\t\t * be careful not to remove initial '/' from path\n+\t\t\t */\n+\t\t\tconst char *prev_slash = norm.buf + norm.len - 3;\n+\t\t\tif (prev_slash == path_start) {\n+\t\t\t\t/* invalid .. because no previous segment to remove */\n+\t\t\t\tif (out_info) {\n+\t\t\t\t\tout_info->url = NULL;\n+\t\t\t\t\tout_info->err = _(\"invalid '..' path segment\");\n+\t\t\t\t}\n+\t\t\t\tstrbuf_release(&norm);\n+\t\t\t\treturn NULL;\n+\t\t\t}\n+\t\t\twhile (*--prev_slash != '/') {}\n+\t\t\tif (prev_slash == path_start) {\n+\t\t\t\tstrbuf_setlen(&norm, prev_slash - norm.buf + 1);\n+\t\t\t\tskip_add_slash = 1;\n+\t\t\t} else {\n+\t\t\t\tstrbuf_setlen(&norm, prev_slash - norm.buf);\n+\t\t\t}\n+\t\t}\n+\t\turl_len -= next_slash - url;\n+\t\turl = next_slash;\n+\t\t/* if the next char is not '/' done with the path */\n+\t\tif (*url != '/')\n+\t\t\tbreak;\n+\t\turl++;\n+\t\turl_len--;\n+\t\tif (!skip_add_slash)\n+\t\t\tstrbuf_addch(&norm, '/');\n+\t}\n+\tpath_len = norm.len - path_off;\n+\n+\n+\t/*\n+\t * Now simply copy the rest, if any, only normalizing %-escapes and\n+\t * being careful not to corrupt the URL by unescaping any delimiters.\n+\t */\n+\tif (*url) {\n+\t\tif (!append_normalized_escapes(&norm, url, url_len, \"\", URL_RESERVED)) {\n+\t\t\tif (out_info) {\n+\t\t\t\tout_info->url = NULL;\n+\t\t\t\tout_info->err = _(\"invalid %XX escape sequence\");\n+\t\t\t}\n+\t\t\tstrbuf_release(&norm);\n+\t\t\treturn NULL;\n+\t\t}\n+\t}\n+\n+\n+\tresult = strbuf_detach(&norm, &result_len);\n+\tif (out_info) {\n+\t\tout_info->url = result;\n+\t\tout_info->err = NULL;\n+\t\tout_info->url_len = result_len;\n+\t\tout_info->scheme_len = scheme_len;\n+\t\tout_info->user_off = user_off;\n+\t\tout_info->user_len = user_len;\n+\t\tout_info->passwd_off = passwd_off;\n+\t\tout_info->passwd_len = passwd_len;\n+\t\tout_info->host_off = host_off;\n+\t\tout_info->host_len = host_len;\n+\t\tout_info->port_len = port_len;\n+\t\tout_info->path_off = path_off;\n+\t\tout_info->path_len = path_len;\n+\t}\n+\treturn result;\n+}\n+\n+static size_t http_options_url_match_prefix(const char *url,\n+\t\t\t\t\t    const char *url_prefix,\n+\t\t\t\t\t    size_t url_prefix_len)\n+{\n+\t/*\n+\t * url_prefix matches url if url_prefix is an exact match for url or it\n+\t * is a prefix of url and the match ends on a path component boundary.\n+\t * Both url and url_prefix are considered to have an implicit '/' on the\n+\t * end for matching purposes if they do not already.\n+\t *\n+\t * url must be NUL terminated.  url_prefix_len is the length of\n+\t * url_prefix which need not be NUL terminated.\n+\t *\n+\t * The return value is the length of the match in characters (including\n+\t * the final '/' even if it's implicit) or 0 for no match.\n+\t *\n+\t * Passing NULL as url and/or url_prefix will always cause 0 to be\n+\t * returned without causing any faults.\n+\t */\n+\tif (!url || !url_prefix)\n+\t\treturn 0;\n+\tif (!url_prefix_len || (url_prefix_len == 1 && *url_prefix == '/'))\n+\t\treturn (!*url || *url == '/') ? 1 : 0;\n+\tif (url_prefix[url_prefix_len - 1] == '/')\n+\t\turl_prefix_len--;\n+\tif (strncmp(url, url_prefix, url_prefix_len))\n+\t\treturn 0;\n+\tif ((strlen(url) == url_prefix_len) || (url[url_prefix_len] == '/'))\n+\t\treturn url_prefix_len + 1;\n+\treturn 0;\n+}\n+\n+int match_urls(const struct url_info *url,\n+\t       const struct url_info *url_prefix,\n+\t       int *exactusermatch)\n+{\n+\t/*\n+\t * url_prefix matches url if the scheme, host and port of url_prefix\n+\t * are the same as those of url and the path portion of url_prefix\n+\t * is the same as the path portion of url or it is a prefix that\n+\t * matches at a '/' boundary.  If url_prefix contains a user name,\n+\t * that must also exactly match the user name in url.\n+\t *\n+\t * If the user, host, port and path match in this fashion, the returned\n+\t * value is the length of the path match including any implicit\n+\t * final '/'.  For example, \"http://me@example.com/path\" is matched by\n+\t * \"http://example.com\" with a path length of 1.\n+\t *\n+\t * If there is a match and exactusermatch is not NULL, then\n+\t * *exactusermatch will be set to true if both url and url_prefix\n+\t * contained a user name or false if url_prefix did not have a\n+\t * user name.  If there is no match *exactusermatch is left untouched.\n+\t */\n+\tint usermatched = 0;\n+\tint pathmatchlen;\n+\n+\tif (!url || !url_prefix || !url->url || !url_prefix->url)\n+\t\treturn 0;\n+\n+\t/* check the scheme */\n+\tif (url_prefix->scheme_len != url->scheme_len ||\n+\t    strncmp(url->url, url_prefix->url, url->scheme_len))\n+\t\treturn 0; /* schemes do not match */\n+\n+\t/* check the user name if url_prefix has one */\n+\tif (url_prefix->user_off) {\n+\t\tif (!url->user_off || url->user_len != url_prefix->user_len ||\n+\t\t    strncmp(url->url + url->user_off,\n+\t\t\t    url_prefix->url + url_prefix->user_off,\n+\t\t\t    url->user_len))\n+\t\t\treturn 0; /* url_prefix has a user but it's not a match */\n+\t\tusermatched = 1;\n+\t}\n+\n+\t/* check the host and port */\n+\tif (url_prefix->host_len != url->host_len ||\n+\t    strncmp(url->url + url->host_off,\n+\t\t    url_prefix->url + url_prefix->host_off, url->host_len))\n+\t\treturn 0; /* host names and/or ports do not match */\n+\n+\t/* check the path */\n+\tpathmatchlen = http_options_url_match_prefix(\n+\t\turl->url + url->path_off,\n+\t\turl_prefix->url + url_prefix->path_off,\n+\t\turl_prefix->url_len - url_prefix->path_off);\n+\n+\tif (pathmatchlen && exactusermatch)\n+\t\t*exactusermatch = usermatched;\n+\treturn pathmatchlen;\n+}\ndiff --git a/url-match.h b/url-match.h\nnew file mode 100644\nindex 0000000..e9cecd3\n--- /dev/null\n+++ b/url-match.h\n@@ -0,0 +1,35 @@\n+#ifndef URL_MATCH_H\n+\n+struct url_info {\n+\t/* normalized url on success, must be freed, otherwise NULL */\n+\tchar *url;\n+\t/* if !url, a brief reason for the failure, otherwise NULL */\n+\tconst char *err;\n+\n+\t/* the rest of the fields are only set if url != NULL */\n+\n+\tsize_t url_len;\t\t/* total length of url (which is now normalized) */\n+\tsize_t scheme_len;\t/* length of scheme name (excluding final :) */\n+\tsize_t user_off;\t/* offset into url to start of user name (0 => none) */\n+\tsize_t user_len;\t/* length of user name; if user_off != 0 but\n+\t\t\t\t   user_len == 0, an empty user name was given */\n+\tsize_t passwd_off;\t/* offset into url to start of passwd (0 => none) */\n+\tsize_t passwd_len;\t/* length of passwd; if passwd_off != 0 but\n+\t\t\t\t   passwd_len == 0, an empty passwd was given */\n+\tsize_t host_off;\t/* offset into url to start of host name (0 => none) */\n+\tsize_t host_len;\t/* length of host name; this INCLUDES any ':portnum';\n+\t\t\t\t * file urls may have host_len == 0 */\n+\tsize_t port_len;\t/* if a portnum is present (port_len != 0), it has\n+\t\t\t\t * this length (excluding the leading ':') at the\n+\t\t\t\t * end of the host name (always 0 for file urls) */\n+\tsize_t path_off;\t/* offset into url to the start of the url path;\n+\t\t\t\t * this will always point to a '/' character\n+\t\t\t\t * after the url has been normalized */\n+\tsize_t path_len;\t/* length of path portion excluding any trailing\n+\t\t\t\t * '?...' and '#...' portion; will always be >= 1 */\n+};\n+\n+extern char *url_normalize(const char *, struct url_info *);\n+extern int match_urls(const struct url_info *url, const struct url_info *url_prefix, int *exactusermatch);\n+\n+#endif /* URL_MATCH_H */\n-- \n1.8.4-rc0-137-g17832d4\n"},{"id":"224269","messageId":"1375138150-19520-3-git-send-email-gitster@pobox.com","threadId":"34530","inReplyTo":"1375138150-19520-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/3] builtin/config: refactor collect_config()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-29T22:49:09Z","receivedAt":"2013-07-29T22:49:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"In order to reuse the logic to format the configuration value while\nhonouring the requested type, split this function into two.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/config.c | 42 +++++++++++++++++++++---------------------\n 1 file changed, 21 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 33c9bf9..12c5073 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -100,25 +100,13 @@ struct strbuf_list {\n \tint alloc;\n };\n \n-static int collect_config(const char *key_, const char *value_, void *cb)\n+static int format_config(struct strbuf *buf, const char *key_, const char *value_)\n {\n-\tstruct strbuf_list *values = cb;\n-\tstruct strbuf *buf;\n-\tchar value[256];\n-\tconst char *vptr = value;\n \tint must_free_vptr = 0;\n \tint must_print_delim = 0;\n+\tchar value[256];\n+\tconst char *vptr = value;\n \n-\tif (!use_key_regexp && strcmp(key_, key))\n-\t\treturn 0;\n-\tif (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))\n-\t\treturn 0;\n-\tif (regexp != NULL &&\n-\t    (do_not_match ^ !!regexec(regexp, (value_?value_:\"\"), 0, NULL, 0)))\n-\t\treturn 0;\n-\n-\tALLOC_GROW(values->items, values->nr + 1, values->alloc);\n-\tbuf = &values->items[values->nr++];\n \tstrbuf_init(buf, 0);\n \n \tif (show_keys) {\n@@ -126,7 +114,7 @@ static int collect_config(const char *key_, const char *value_, void *cb)\n \t\tmust_print_delim = 1;\n \t}\n \tif (types == TYPE_INT)\n-\t\tsprintf(value, \"%d\", git_config_int(key_, value_?value_:\"\"));\n+\t\tsprintf(value, \"%d\", git_config_int(key_, value_ ? value_ : \"\"));\n \telse if (types == TYPE_BOOL)\n \t\tvptr = git_config_bool(key_, value_) ? \"true\" : \"false\";\n \telse if (types == TYPE_BOOL_OR_INT) {\n@@ -154,15 +142,27 @@ static int collect_config(const char *key_, const char *value_, void *cb)\n \tstrbuf_addch(buf, term);\n \n \tif (must_free_vptr)\n-\t\t/* If vptr must be freed, it's a pointer to a\n-\t\t * dynamically allocated buffer, it's safe to cast to\n-\t\t * const.\n-\t\t*/\n \t\tfree((char *)vptr);\n-\n \treturn 0;\n }\n \n+static int collect_config(const char *key_, const char *value_, void *cb)\n+{\n+\tstruct strbuf_list *values = cb;\n+\n+\tif (!use_key_regexp && strcmp(key_, key))\n+\t\treturn 0;\n+\tif (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))\n+\t\treturn 0;\n+\tif (regexp != NULL &&\n+\t    (do_not_match ^ !!regexec(regexp, (value_?value_:\"\"), 0, NULL, 0)))\n+\t\treturn 0;\n+\n+\tALLOC_GROW(values->items, values->nr + 1, values->alloc);\n+\n+\treturn format_config(&values->items[values->nr++], key_, value_);\n+}\n+\n static int get_value(const char *key_, const char *regex_)\n {\n \tint ret = CONFIG_GENERIC_ERROR;\n-- \n1.8.4-rc0-137-g17832d4\n"},{"id":"224270","messageId":"1375138150-19520-4-git-send-email-gitster@pobox.com","threadId":"34530","inReplyTo":"1375138150-19520-1-git-send-email-gitster@pobox.com","subject":"[PATCH 3/3] config: --get-urlmatch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-29T22:49:10Z","receivedAt":"2013-07-29T22:49:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"git config --get-urlmatch $section[.$variable] $url\" is a way to\nlearn what the configured value for $section.$variable is for the\ngiven URL, using the logic introduced by the http.<url>.config\ntopic.  In addition to $section.$variable, entries in the\nconfiguration file(s) that match $section.<urlpattern>.$variable are\nlooked up and the one with <urlpattern> that matches the given $url\nthe best is used to answer the query.\n\nThis can still be further refactored to remove code from http_options()\nin http.c, I think.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/config.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 141 insertions(+)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 12c5073..c1d32ae 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"color.h\"\n #include \"parse-options.h\"\n+#include \"url-match.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [options]\"),\n@@ -41,6 +42,7 @@ static int respect_includes = -1;\n #define ACTION_SET_ALL (1<<12)\n #define ACTION_GET_COLOR (1<<13)\n #define ACTION_GET_COLORBOOL (1<<14)\n+#define ACTION_GET_URLMATCH (1<<15)\n \n #define TYPE_BOOL (1<<0)\n #define TYPE_INT (1<<1)\n@@ -57,6 +59,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"get\", &actions, N_(\"get value: name [value-regex]\"), ACTION_GET),\n \tOPT_BIT(0, \"get-all\", &actions, N_(\"get all values: key [value-regex]\"), ACTION_GET_ALL),\n \tOPT_BIT(0, \"get-regexp\", &actions, N_(\"get values for regexp: name-regex [value-regex]\"), ACTION_GET_REGEXP),\n+\tOPT_BIT(0, \"get-urlmatch\", &actions, N_(\"get value specific for the URL: section[.var] URL\"), ACTION_GET_URLMATCH),\n \tOPT_BIT(0, \"replace-all\", &actions, N_(\"replace all matching variables: name value [value_regex]\"), ACTION_REPLACE_ALL),\n \tOPT_BIT(0, \"add\", &actions, N_(\"add a new variable: name value\"), ACTION_ADD),\n \tOPT_BIT(0, \"unset\", &actions, N_(\"remove a variable: name [value-regex]\"), ACTION_UNSET),\n@@ -348,6 +351,140 @@ static int get_colorbool(int print)\n \t\treturn get_colorbool_found ? 0 : 1;\n }\n \n+struct urlmatch_collect {\n+\tstruct string_list vars;\n+\tstruct url_info url;\n+\tconst char *section;\n+\tconst char *key;\n+};\n+\n+struct urlmatch_item {\n+\tsize_t max_matched_len;\n+\tchar user_matched;\n+\tchar value_is_null;\n+\tstruct strbuf value;\n+};\n+\n+static int urlmatch_collect(const char *var, const char *value, void *cb)\n+{\n+\tstruct string_list_item *item;\n+\tstruct urlmatch_collect *collect = cb;\n+\tstruct urlmatch_item *matched;\n+\tstruct url_info *url = &collect->url;\n+\tconst char *key, *dot;\n+\tsize_t matchlen = 0;\n+\tint usermatch = 0;\n+\n+\tkey = skip_prefix(var, collect->section);\n+\tif (!key || *(key++) != '.')\n+\t\treturn 0; /* not interested */\n+\tdot = strrchr(key, '.');\n+\tif (dot) {\n+\t\tchar *config_url, *norm_url;\n+\t\tstruct url_info norm_info;\n+\t\tint matchlen;\n+\n+\t\tconfig_url = xmemdupz(key, dot - key);\n+\t\tnorm_url = url_normalize(config_url, &norm_info);\n+\t\tfree(config_url);\n+\t\tif (!norm_url)\n+\t\t\treturn 0;\n+\t\tmatchlen = match_urls(url, &norm_info, &usermatch);\n+\t\tfree(norm_url);\n+\t\tif (!matchlen)\n+\t\t\treturn 0;\n+\t\tkey = dot + 1;\n+\t}\n+\n+\tif (collect->key && strcmp(key, collect->key))\n+\t\treturn 0;\n+\n+\titem = string_list_insert(&collect->vars, key);\n+\tif (!item->util) {\n+\t\tmatched = xcalloc(1, sizeof(*matched));\n+\t\titem->util = matched;\n+\t\tstrbuf_init(&matched->value, 0);\n+\t} else {\n+\t\tmatched = item->util;\n+\t\t/*\n+\t\t * Is our match shorter?  Is our match the same\n+\t\t * length, and without user while the current\n+\t\t * candidate is with user?  Then we cannot use it.\n+\t\t */\n+\t\tif (matchlen < matched->max_matched_len ||\n+\t\t    ((matchlen == matched->max_matched_len) &&\n+\t\t     (!usermatch && matched->user_matched)))\n+\t\t\treturn 0;\n+\t\t/*\n+\t\t * Otherwise, release the old one and replace\n+\t\t * with ours.\n+\t\t */\n+\t\tstrbuf_release(&matched->value);\n+\t}\n+\n+\tmatched->max_matched_len = matchlen;\n+\tmatched->user_matched = usermatch;\n+\tif (value) {\n+\t\tstrbuf_addstr(&matched->value, value);\n+\t\tmatched->value_is_null = 0;\n+\t} else {\n+\t\tmatched->value_is_null = 1;\n+\t}\n+\treturn 0;\n+}\n+\n+static int get_urlmatch(const char *var, const char *url)\n+{\n+\tconst char *section_tail;\n+\tstruct string_list_item *item;\n+\tstruct urlmatch_collect collect = { STRING_LIST_INIT_DUP };\n+\n+\tif (!url_normalize(url, &collect.url))\n+\t\tdie(collect.url.err);\n+\n+\tsection_tail = strchr(var, '.');\n+\tif (section_tail) {\n+\t\tcollect.section = xmemdupz(var, section_tail - var);\n+\t\tcollect.key = strrchr(var, '.') + 1;\n+\t\tshow_keys = 0;\n+\t} else {\n+\t\tcollect.section = var;\n+\t\tcollect.key = NULL;\n+\t\tshow_keys = 1;\n+\t}\n+\n+\tgit_config_with_options(urlmatch_collect, &collect,\n+\t\t\t\tgiven_config_file, respect_includes);\n+\n+\tfor_each_string_list_item(item, &collect.vars) {\n+\t\tstruct urlmatch_item *matched = item->util;\n+\t\tstruct strbuf key = STRBUF_INIT;\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\n+\t\tstrbuf_addstr(&key, collect.section);\n+\t\tstrbuf_addch(&key, '.');\n+\t\tstrbuf_addstr(&key, item->string);\n+\t\tformat_config(&buf, key.buf,\n+\t\t\t      matched->value_is_null ? NULL : matched->value.buf);\n+\t\tfwrite(buf.buf, 1, buf.len, stdout);\n+\t\tstrbuf_release(&key);\n+\t\tstrbuf_release(&buf);\n+\n+\t\tstrbuf_release(&matched->value);\n+\t}\n+\tstring_list_clear(&collect.vars, 1);\n+\n+\t/*\n+\t * section name may have been copied to replace the dot, in which\n+\t * case it needs to be freed.  key name is either NULL (e.g. 'http'\n+\t * alone) or points into var (e.g. 'http.savecookies'), and we do\n+\t * not own the storage.\n+\t */\n+\tif (collect.section != var)\n+\t\tfree((void *)collect.section);\n+\treturn 0;\n+}\n+\n int cmd_config(int argc, const char **argv, const char *prefix)\n {\n \tint nongit = !startup_info->have_repository;\n@@ -499,6 +636,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tcheck_argc(argc, 1, 2);\n \t\treturn get_value(argv[0], argv[1]);\n \t}\n+\telse if (actions == ACTION_GET_URLMATCH) {\n+\t\tcheck_argc(argc, 2, 2);\n+\t\treturn get_urlmatch(argv[0], argv[1]);\n+\t}\n \telse if (actions == ACTION_UNSET) {\n \t\tcheck_argc(argc, 1, 2);\n \t\tif (argc == 2)\n-- \n1.8.4-rc0-137-g17832d4\n"},{"id":"224272","messageId":"20130730003716.GA13114@sigill.intra.peff.net","threadId":"34530","inReplyTo":"1375138150-19520-4-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 3/3] config: --get-urlmatch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-07-30T00:37:16Z","receivedAt":"2013-07-30T00:37:16Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jul 29, 2013 at 03:49:10PM -0700, Junio C Hamano wrote:\n\n> \"git config --get-urlmatch $section[.$variable] $url\" is a way to\n> learn what the configured value for $section.$variable is for the\n> given URL, using the logic introduced by the http.<url>.config\n> topic.\n\nThat interface looks good to me. It matches the --get-all/--get-regexp\noptions of git-config. It does not quite match --get-color, which is\nreally a type (like --bool or --int), but I think --get-color is the odd\none out there.\n\n> This can still be further refactored to remove code from http_options()\n> in http.c, I think.\n\nYeah, that would be the ultimate goal. I think you would just need to\nkeep the same string_list there, with one urlmatch_item per key that we\ncare about.\n\n> ---\n>  builtin/config.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\nIt seems like some of the logic here should be reusable for http.c.\nShould it be in config.c instead?\n\n> +struct urlmatch_collect {\n> +\tstruct string_list vars;\n> +\tstruct url_info url;\n> +\tconst char *section;\n> +\tconst char *key;\n> +};\n> +\n> +struct urlmatch_item {\n> +\tsize_t max_matched_len;\n> +\tchar user_matched;\n> +\tchar value_is_null;\n> +\tstruct strbuf value;\n> +};\n\nI think you ultimately want such a string_list for matching arbitrary\nnumbers of keys, but do you need it for the git-config case?\n\nYou will always be matching collect->key, so you will only ever insert a\nsingle item into the collect->vars list. IOW, this could be:\n\n  struct urlmatch_collect {\n    struct url_info url;\n    const char *section;\n    const char *key;\n    struct urlmatch_item match;\n  };\n\nI don't mind if it is more complicated than this single-case needs to be\nif the code is also being used to http.c, but I haven't seen that yet\n(and this code would not used as-is, as you would want to call the\nfunction with many potential collect->key values, but without\nre-normalizing the URL over and over).\n\nAnd of course, it needs docs and tests. :) The latter can probably come\nby converting some of the test-url-normalize tests to just use\ngit-config instead.\n\n-Peff\n"},{"id":"224274","messageId":"7vbo5kzv9k.fsf@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"20130730003716.GA13114@sigill.intra.peff.net","subject":"Re: [PATCH 3/3] config: --get-urlmatch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-30T01:33:43Z","receivedAt":"2013-07-30T01:33:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>> +struct urlmatch_item {\n>> +\tsize_t max_matched_len;\n>> +\tchar user_matched;\n>> +\tchar value_is_null;\n>> +\tstruct strbuf value;\n>> +};\n>\n> I think you ultimately want such a string_list for matching arbitrary\n> numbers of keys, but do you need it for the git-config case?\n\n\"git config\" does not know the semantics of each key, nor available\nset of keys, no?  The string-list is only to support\n\n    git config --get-urlmatch http http://www.google.com/\n\ni.e. \"list everything under http.* hierarchy\".\n\nAnd unlike http_option() which can incrementally always call back\nthe setter (and let it override older value), the command has to\nread everything through and then give us the final value, so I do\nnot think we can get away without one.\n\n> You will always be matching collect->key, so you will only ever insert a\n> single item into the collect->vars list. IOW, this could be:\n>\n>   struct urlmatch_collect {\n>     struct url_info url;\n>     const char *section;\n>     const char *key;\n>     struct urlmatch_item match;\n>   };\n>\n> I don't mind if it is more complicated than this single-case needs to be\n> if the code is also being used to http.c, but I haven't seen that yet\n\nThat is in the works, of course ;-)\n"},{"id":"224276","messageId":"7v7gg8ztvk.fsf_-_@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"1375138150-19520-1-git-send-email-gitster@pobox.com","subject":"[PATCH 4/3] url-match: generalize configuration collection logic","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-30T02:03:43Z","receivedAt":"2013-07-30T02:03:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Instead of always collecting the found value in the strbuf in the\nstring list item for each found key, allow a set of callback\nfunctions to be specified by the user to be called back at strategic\nplaces.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n builtin/config.c | 117 +++++++++++++++++--------------------------------------\n url-match.c      |  75 +++++++++++++++++++++++++++++++++++\n url-match.h      |  22 +++++++++++\n 3 files changed, 133 insertions(+), 81 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex c1d32ae..173c18f 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -351,79 +351,17 @@ static int get_colorbool(int print)\n \t\treturn get_colorbool_found ? 0 : 1;\n }\n \n-struct urlmatch_collect {\n-\tstruct string_list vars;\n-\tstruct url_info url;\n-\tconst char *section;\n-\tconst char *key;\n-};\n-\n-struct urlmatch_item {\n-\tsize_t max_matched_len;\n-\tchar user_matched;\n+struct urlmatch_config_item {\n+\tstruct urlmatch_item match;\n \tchar value_is_null;\n \tstruct strbuf value;\n };\n \n-static int urlmatch_collect(const char *var, const char *value, void *cb)\n+static int urlmatch_collect_fn(const char *var, const char *value,\n+\t\t\t       void *cb, void *matched_cb)\n {\n-\tstruct string_list_item *item;\n-\tstruct urlmatch_collect *collect = cb;\n-\tstruct urlmatch_item *matched;\n-\tstruct url_info *url = &collect->url;\n-\tconst char *key, *dot;\n-\tsize_t matchlen = 0;\n-\tint usermatch = 0;\n-\n-\tkey = skip_prefix(var, collect->section);\n-\tif (!key || *(key++) != '.')\n-\t\treturn 0; /* not interested */\n-\tdot = strrchr(key, '.');\n-\tif (dot) {\n-\t\tchar *config_url, *norm_url;\n-\t\tstruct url_info norm_info;\n-\t\tint matchlen;\n-\n-\t\tconfig_url = xmemdupz(key, dot - key);\n-\t\tnorm_url = url_normalize(config_url, &norm_info);\n-\t\tfree(config_url);\n-\t\tif (!norm_url)\n-\t\t\treturn 0;\n-\t\tmatchlen = match_urls(url, &norm_info, &usermatch);\n-\t\tfree(norm_url);\n-\t\tif (!matchlen)\n-\t\t\treturn 0;\n-\t\tkey = dot + 1;\n-\t}\n-\n-\tif (collect->key && strcmp(key, collect->key))\n-\t\treturn 0;\n+\tstruct urlmatch_config_item *matched = matched_cb;\n \n-\titem = string_list_insert(&collect->vars, key);\n-\tif (!item->util) {\n-\t\tmatched = xcalloc(1, sizeof(*matched));\n-\t\titem->util = matched;\n-\t\tstrbuf_init(&matched->value, 0);\n-\t} else {\n-\t\tmatched = item->util;\n-\t\t/*\n-\t\t * Is our match shorter?  Is our match the same\n-\t\t * length, and without user while the current\n-\t\t * candidate is with user?  Then we cannot use it.\n-\t\t */\n-\t\tif (matchlen < matched->max_matched_len ||\n-\t\t    ((matchlen == matched->max_matched_len) &&\n-\t\t     (!usermatch && matched->user_matched)))\n-\t\t\treturn 0;\n-\t\t/*\n-\t\t * Otherwise, release the old one and replace\n-\t\t * with ours.\n-\t\t */\n-\t\tstrbuf_release(&matched->value);\n-\t}\n-\n-\tmatched->max_matched_len = matchlen;\n-\tmatched->user_matched = usermatch;\n \tif (value) {\n \t\tstrbuf_addstr(&matched->value, value);\n \t\tmatched->value_is_null = 0;\n@@ -433,35 +371,52 @@ static int urlmatch_collect(const char *var, const char *value, void *cb)\n \treturn 0;\n }\n \n+static void *urlmatch_alloc_fn(const char *var, const char *value, void *cb)\n+{\n+\treturn xcalloc(1, sizeof(struct urlmatch_config_item));\n+}\n+\n+static void urlmatch_clear_fn(void *matched_cb)\n+{\n+\tstruct urlmatch_config_item *matched = matched_cb;\n+\tstrbuf_init(&matched->value, 0);\n+}\n+\n static int get_urlmatch(const char *var, const char *url)\n {\n \tconst char *section_tail;\n \tstruct string_list_item *item;\n-\tstruct urlmatch_collect collect = { STRING_LIST_INIT_DUP };\n+\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n+\n+\tconfig.fn = urlmatch_collect_fn;\n+\tconfig.cascade_fn = NULL;\n+\tconfig.item_alloc = urlmatch_alloc_fn;\n+\tconfig.item_clear = urlmatch_clear_fn;\n+\tconfig.cb = NULL;\n \n-\tif (!url_normalize(url, &collect.url))\n-\t\tdie(collect.url.err);\n+\tif (!url_normalize(url, &config.url))\n+\t\tdie(config.url.err);\n \n \tsection_tail = strchr(var, '.');\n \tif (section_tail) {\n-\t\tcollect.section = xmemdupz(var, section_tail - var);\n-\t\tcollect.key = strrchr(var, '.') + 1;\n+\t\tconfig.section = xmemdupz(var, section_tail - var);\n+\t\tconfig.key = strrchr(var, '.') + 1;\n \t\tshow_keys = 0;\n \t} else {\n-\t\tcollect.section = var;\n-\t\tcollect.key = NULL;\n+\t\tconfig.section = var;\n+\t\tconfig.key = NULL;\n \t\tshow_keys = 1;\n \t}\n \n-\tgit_config_with_options(urlmatch_collect, &collect,\n+\tgit_config_with_options(urlmatch_config_entry, &config,\n \t\t\t\tgiven_config_file, respect_includes);\n \n-\tfor_each_string_list_item(item, &collect.vars) {\n-\t\tstruct urlmatch_item *matched = item->util;\n+\tfor_each_string_list_item(item, &config.vars) {\n+\t\tstruct urlmatch_config_item *matched = item->util;\n \t\tstruct strbuf key = STRBUF_INIT;\n \t\tstruct strbuf buf = STRBUF_INIT;\n \n-\t\tstrbuf_addstr(&key, collect.section);\n+\t\tstrbuf_addstr(&key, config.section);\n \t\tstrbuf_addch(&key, '.');\n \t\tstrbuf_addstr(&key, item->string);\n \t\tformat_config(&buf, key.buf,\n@@ -472,7 +427,7 @@ static int get_urlmatch(const char *var, const char *url)\n \n \t\tstrbuf_release(&matched->value);\n \t}\n-\tstring_list_clear(&collect.vars, 1);\n+\tstring_list_clear(&config.vars, 1);\n \n \t/*\n \t * section name may have been copied to replace the dot, in which\n@@ -480,8 +435,8 @@ static int get_urlmatch(const char *var, const char *url)\n \t * alone) or points into var (e.g. 'http.savecookies'), and we do\n \t * not own the storage.\n \t */\n-\tif (collect.section != var)\n-\t\tfree((void *)collect.section);\n+\tif (config.section != var)\n+\t\tfree((void *)config.section);\n \treturn 0;\n }\n \ndiff --git a/url-match.c b/url-match.c\nindex 424a0a0..290ba40 100644\n--- a/url-match.c\n+++ b/url-match.c\n@@ -466,3 +466,78 @@ int match_urls(const struct url_info *url,\n \t\t*exactusermatch = usermatched;\n \treturn pathmatchlen;\n }\n+\n+int urlmatch_config_entry(const char *var, const char *value, void *cb)\n+{\n+\tstruct string_list_item *item;\n+\tstruct urlmatch_config *collect = cb;\n+\tstruct urlmatch_item *matched;\n+\tstruct url_info *url = &collect->url;\n+\tconst char *key, *dot;\n+\tstruct strbuf synthkey = STRBUF_INIT;\n+\tsize_t matched_len = 0;\n+\tint user_matched = 0;\n+\tint retval;\n+\n+\tkey = skip_prefix(var, collect->section);\n+\tif (!key || *(key++) != '.') {\n+\t\tif (collect->cascade_fn)\n+\t\t\treturn collect->cascade_fn(var, value, cb);\n+\t\treturn 0; /* not interested */\n+\t}\n+\tdot = strrchr(key, '.');\n+\tif (dot) {\n+\t\tchar *config_url, *norm_url;\n+\t\tstruct url_info norm_info;\n+\n+\t\tconfig_url = xmemdupz(key, dot - key);\n+\t\tnorm_url = url_normalize(config_url, &norm_info);\n+\t\tfree(config_url);\n+\t\tif (!norm_url)\n+\t\t\treturn 0;\n+\t\tmatched_len = match_urls(url, &norm_info, &user_matched);\n+\t\tfree(norm_url);\n+\t\tif (!matched_len)\n+\t\t\treturn 0;\n+\t\tkey = dot + 1;\n+\t}\n+\n+\tif (collect->key && strcmp(key, collect->key))\n+\t\treturn 0;\n+\n+\titem = string_list_insert(&collect->vars, key);\n+\tif (!item->util) {\n+\t\tif (collect->item_alloc)\n+\t\t\tmatched = collect->item_alloc(var, value, cb);\n+\t\telse\n+\t\t\tmatched = xcalloc(1, sizeof(*matched));\n+\t\titem->util = matched;\n+\t} else {\n+\t\tmatched = item->util;\n+\t\t/*\n+\t\t * Is our match shorter?  Is our match the same\n+\t\t * length, and without user while the current\n+\t\t * candidate is with user?  Then we cannot use it.\n+\t\t */\n+\t\tif (matched_len < matched->matched_len ||\n+\t\t    ((matched_len == matched->matched_len) &&\n+\t\t     (!user_matched && matched->user_matched)))\n+\t\t\treturn 0;\n+\t\t/*\n+\t\t * Otherwise, clear the old one and replace it\n+\t\t * with this one.\n+\t\t */\n+\t\tif (collect->item_clear)\n+\t\t\tcollect->item_clear(matched);\n+\t}\n+\n+\tmatched->matched_len = matched_len;\n+\tmatched->user_matched = user_matched;\n+\tstrbuf_addstr(&synthkey, collect->section);\n+\tstrbuf_addch(&synthkey, '.');\n+\tstrbuf_addstr(&synthkey, key);\n+\tretval = collect->fn(synthkey.buf, value, collect->cb, matched);\n+\n+\tstrbuf_release(&synthkey);\n+\treturn retval;\n+}\ndiff --git a/url-match.h b/url-match.h\nindex e9cecd3..c3a5783 100644\n--- a/url-match.h\n+++ b/url-match.h\n@@ -1,4 +1,5 @@\n #ifndef URL_MATCH_H\n+#include \"string-list.h\"\n \n struct url_info {\n \t/* normalized url on success, must be freed, otherwise NULL */\n@@ -32,4 +33,25 @@ struct url_info {\n extern char *url_normalize(const char *, struct url_info *);\n extern int match_urls(const struct url_info *url, const struct url_info *url_prefix, int *exactusermatch);\n \n+struct urlmatch_item {\n+\tsize_t matched_len;\n+\tchar user_matched;\n+\t/* possibly more */\n+};\n+\n+struct urlmatch_config {\n+\tstruct string_list vars;\n+\tstruct url_info url;\n+\tconst char *section;\n+\tconst char *key;\n+\n+\tvoid *cb;\n+\tint (*fn)(const char *var, const char *value, void *cb, void *matched);\n+\tint (*cascade_fn)(const char *var, const char *value, void *cb);\n+\tvoid *(*item_alloc)(const char *var, const char *value, void *cb);\n+\tvoid (*item_clear)(void *);\n+};\n+\n+extern int urlmatch_config_entry(const char *var, const char *value, void *cb);\n+\n #endif /* URL_MATCH_H */\n-- \n1.8.4-rc0-137-g17832d4\n"},{"id":"224277","messageId":"7v1u6gztf1.fsf_-_@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"7v7gg8ztvk.fsf_-_@alter.siamese.dyndns.org","subject":"[PATCH 5/3] revert most of the http_options() change","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-30T02:13:38Z","receivedAt":"2013-07-30T02:13:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"With the previous preparation step, the earlier 1bb00006 (config:\nadd support for http.<url>.* settings, 2013-07-21) that introduced\nmany repeated changes:\n\n        -if (!strcmp(\"http.key\", var)) {\n        +if (!strcmp(\"key\", key)) {\n        +       if (match_is_shorter(..., OPT_KEY_NAME))\n        +               return 0;\n                ... original processing for KEY_NAME ...\n         }\n\ncan be reverted.\n\nThis allows us to also get rid of the \"repeating yourself to the\ndeath\" enum http_option_type, and new code (like db/http-savecookies\npatch) that wants to add a new configuration to the http.* subsystem\ndoes not have to conflict with http.<urlpattern>.variable series at\nall.\n\nThis is more-or-less how I want the endgame to look like. Not even\ncompile tested, but it is getting late so I'll show it to the list\nin case people may want to play with it and polish it while I am\naway for the night ;-).\n\nIf people can agree that this is going in the right direction,\nperhaps we should rebuild Kyle's series without detouring of adding\nand then yanking what 1bb00006 (config: add support for http.<url>.*\nsettings, 2013-07-21) did in the next cycle.\n\n http.c               | 181 +++++++++------------------------------------------\n test-url-normalize.c |   9 ++-\n 2 files changed, 39 insertions(+), 151 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex a91a00b..c7f513b 100644\n--- a/http.c\n+++ b/http.c\n@@ -31,35 +31,6 @@ static CURL *curl_default;\n \n char curl_errorstr[CURL_ERROR_SIZE];\n \n-enum http_option_type {\n-\tOPT_POST_BUFFER,\n-\tOPT_MIN_SESSIONS,\n-\tOPT_SSL_VERIFY,\n-\tOPT_SSL_TRY,\n-\tOPT_SSL_CERT,\n-\tOPT_SSL_CAINFO,\n-\tOPT_LOW_SPEED,\n-\tOPT_LOW_TIME,\n-\tOPT_NO_EPSV,\n-\tOPT_HTTP_PROXY,\n-\tOPT_COOKIE_FILE,\n-\tOPT_USER_AGENT,\n-\tOPT_PASSWD_REQ,\n-#ifdef USE_CURL_MULTI\n-\tOPT_MAX_REQUESTS,\n-#endif\n-#if LIBCURL_VERSION_NUM >= 0x070903\n-\tOPT_SSL_KEY,\n-#endif\n-#if LIBCURL_VERSION_NUM >= 0x070908\n-\tOPT_SSL_CAPATH,\n-#endif\n-\tOPT_MAX\n-};\n-\n-static size_t http_option_max_matched_len[OPT_MAX];\n-static int http_option_user_matched[OPT_MAX];\n-\n static int curl_ssl_verify = -1;\n static int curl_ssl_try;\n static const char *ssl_cert;\n@@ -171,119 +142,37 @@ static void process_curl_messages(void)\n }\n #endif\n \n-static int match_is_ignored(size_t matchlen, int usermatch, enum http_option_type opt)\n+static int http_options(const char *var, const char *value, void *cb, void *matched)\n {\n-\t/*\n-\t * Compare matchlen to the last matched path length of option opt and\n-\t * return true if matchlen is shorter than the last matched length\n-\t * (meaning the config setting should be ignored).  Upon seeing the\n-\t * _same_ key (i.e. new key has the same match length which is therefore\n-\t * not shorter) the new setting will override the previous setting\n-\t * unless the new setting did not match the user and the previous match\n-\t * did.  Otherwise return false and record matchlen as the current last\n-\t * matched path length of option opt and usermatch as the last user\n-\t * matching state for option opt.\n-\t */\n-\tif (matchlen < http_option_max_matched_len[opt])\n-\t\treturn 1;\n-\tif (matchlen > http_option_max_matched_len[opt]) {\n-\t\thttp_option_max_matched_len[opt] = matchlen;\n-\t\thttp_option_user_matched[opt] = usermatch;\n-\t\treturn 0;\n-\t}\n-\t/*\n-\t * If a previous match of the same length explicitly matched the user\n-\t * name, but the current match matched on any user, ignore it.\n-\t */\n-\tif (!usermatch && http_option_user_matched[opt])\n-\t\treturn 1;\n-\thttp_option_user_matched[opt] = usermatch;\n-\treturn 0;\n-}\n-\n-static int http_options(const char *var, const char *value, void *cb)\n-{\n-\tconst struct url_info *info = cb;\n-\tconst char *key, *dot;\n-\tsize_t matchlen = 0;\n-\tint usermatch = 0;\n-\n-\tkey = skip_prefix(var, \"http.\");\n-\tif (!key)\n-\t\treturn git_default_config(var, value, cb);\n-\n-\t/*\n-\t * If the part following the leading \"http.\" contains a '.' then check\n-\t * to see if the part between \"http.\" and the last '.' is a match to\n-\t * url.  If it's not then ignore the setting.  Otherwise set key to\n-\t * point to the option which is the part after the final '.' and\n-\t * use key in subsequent comparisons to determine the option type.\n-\t */\n-\tdot = strrchr(key, '.');\n-\tif (dot) {\n-\t\tchar *config_url;\n-\t\tstruct url_info norm_info;\n-\t\tchar *norm_url;\n-\n-\t\tif (!info || !info->url)\n-\t\t\treturn 0;\n-\t\tconfig_url = xmemdupz(key, dot - key);\n-\t\tnorm_url = url_normalize(config_url, &norm_info);\n-\t\tfree(config_url);\n-\t\tif (!norm_url)\n-\t\t\treturn 0;\n-\t\tmatchlen = match_urls(info, &norm_info, &usermatch);\n-\t\tfree(norm_url);\n-\t\tif (!matchlen)\n-\t\t\treturn 0;\n-\t\tkey = dot + 1;\n-\t}\n-\n-\tif (!strcmp(\"sslverify\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_SSL_VERIFY))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.sslverify\", var)) {\n \t\tcurl_ssl_verify = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(\"sslcert\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_SSL_CERT))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.sslcert\", var)) {\n \t\treturn git_config_string(&ssl_cert, var, value);\n \t}\n #if LIBCURL_VERSION_NUM >= 0x070903\n-\tif (!strcmp(\"sslkey\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_SSL_KEY))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.sslkey\", var)) {\n \t\treturn git_config_string(&ssl_key, var, value);\n \t}\n #endif\n #if LIBCURL_VERSION_NUM >= 0x070908\n-\tif (!strcmp(\"sslcapath\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_SSL_CAPATH))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.sslcapath\", var)) {\n \t\treturn git_config_string(&ssl_capath, var, value);\n \t}\n #endif\n-\tif (!strcmp(\"sslcainfo\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_SSL_CAINFO))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.sslcainfo\", var)) {\n \t\treturn git_config_string(&ssl_cainfo, var, value);\n \t}\n-\tif (!strcmp(\"sslcertpasswordprotected\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_PASSWD_REQ))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.sslcertpasswordprotected\", var)) {\n \t\tssl_cert_password_required = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(\"ssltry\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_SSL_TRY))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.ssltry\", var)) {\n \t\tcurl_ssl_try = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(\"minsessions\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_MIN_SESSIONS))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.minsessions\", var)) {\n \t\tmin_curl_sessions = git_config_int(var, value);\n #ifndef USE_CURL_MULTI\n \t\tif (min_curl_sessions > 1)\n@@ -292,56 +181,40 @@ static int http_options(const char *var, const char *value, void *cb)\n \t\treturn 0;\n \t}\n #ifdef USE_CURL_MULTI\n-\tif (!strcmp(\"maxrequests\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_MAX_REQUESTS))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.maxrequests\", var)) {\n \t\tmax_requests = git_config_int(var, value);\n \t\treturn 0;\n \t}\n #endif\n-\tif (!strcmp(\"lowspeedlimit\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_LOW_SPEED))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.lowspeedlimit\", var)) {\n \t\tcurl_low_speed_limit = (long)git_config_int(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(\"lowspeedtime\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_LOW_TIME))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.lowspeedtime\", var)) {\n \t\tcurl_low_speed_time = (long)git_config_int(var, value);\n \t\treturn 0;\n \t}\n \n-\tif (!strcmp(\"noepsv\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_NO_EPSV))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.noepsv\", var)) {\n \t\tcurl_ftp_no_epsv = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(\"proxy\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_HTTP_PROXY))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.proxy\", var)) {\n \t\treturn git_config_string(&curl_http_proxy, var, value);\n \t}\n \n-\tif (!strcmp(\"cookiefile\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_COOKIE_FILE))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.cookiefile\", var)) {\n \t\treturn git_config_string(&curl_cookie_file, var, value);\n \t}\n \n-\tif (!strcmp(\"postbuffer\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_POST_BUFFER))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.postbuffer\", var)) {\n \t\thttp_post_buffer = git_config_int(var, value);\n \t\tif (http_post_buffer < LARGE_PACKET_MAX)\n \t\t\thttp_post_buffer = LARGE_PACKET_MAX;\n \t\treturn 0;\n \t}\n \n-\tif (!strcmp(\"useragent\", key)) {\n-\t\tif (match_is_ignored(matchlen, usermatch, OPT_USER_AGENT))\n-\t\t\treturn 0;\n+\tif (!strcmp(\"http.useragent\", var)) {\n \t\treturn git_config_string(&user_agent, var, value);\n \t}\n \n@@ -469,15 +342,23 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)\n {\n \tchar *low_speed_limit;\n \tchar *low_speed_time;\n-\tstruct url_info info;\n+\tchar *normalized_url;\n+\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n+\n+\tconfig.fn = http_options;\n+\tconfig.cascade_fn = git_default_config;\n+\tconfig.item_alloc = NULL;\n+\tconfig.item_clear = NULL;\n+\tconfig.cb = NULL;\n \n \thttp_is_verbose = 0;\n+\tnormalized_url = url_normalize(url, &config.url);\n+\n+\tconfig.section = \"http\";\n+\tconfig.key = NULL;\n \n-\tmemset(http_option_max_matched_len, 0, sizeof(http_option_max_matched_len));\n-\tmemset(http_option_user_matched, 0, sizeof(http_option_user_matched));\n-\turl_normalize(url, &info);\n-\tgit_config(http_options, &info);\n-\tfree(info.url);\n+\tgit_config(urlmatch_config_entry, &config);\n+\tfree(normalized_url);\n \n \tcurl_global_init(CURL_GLOBAL_ALL);\n \ndiff --git a/test-url-normalize.c b/test-url-normalize.c\nindex 0b809eb..fab94e5 100644\n--- a/test-url-normalize.c\n+++ b/test-url-normalize.c\n@@ -15,8 +15,15 @@ static int run_http_options(const char *file,\n {\n \tstruct strbuf opt_lc;\n \tsize_t i, len;\n+\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n \n-\tif (git_config_with_options(http_options, (void *)info, file, 0))\n+\tconfig.fn = http_options;\n+\tconfig.cascade_fn = git_default_config;\n+\tconfig.item_alloc = NULL;\n+\tconfig.item_clear = NULL;\n+\tconfig.cb = NULL;\n+\n+\tif (git_config_with_options(urlmatch_config_entry, &config, file, 0))\n \t\treturn 1;\n \n \tlen = strlen(opt);\n"},{"id":"224284","messageId":"20130730081413.GC16693@sigill.intra.peff.net","threadId":"34530","inReplyTo":"7vbo5kzv9k.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 3/3] config: --get-urlmatch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-07-30T08:14:13Z","receivedAt":"2013-07-30T08:14:13Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jul 29, 2013 at 06:33:43PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> >> +struct urlmatch_item {\n> >> +\tsize_t max_matched_len;\n> >> +\tchar user_matched;\n> >> +\tchar value_is_null;\n> >> +\tstruct strbuf value;\n> >> +};\n> >\n> > I think you ultimately want such a string_list for matching arbitrary\n> > numbers of keys, but do you need it for the git-config case?\n> \n> \"git config\" does not know the semantics of each key, nor available\n> set of keys, no?  The string-list is only to support\n> \n>     git config --get-urlmatch http http://www.google.com/\n> \n> i.e. \"list everything under http.* hierarchy\".\n\nAh, I missed that you could leave \"key\" empty. I had expected\ncollect->key to be filled in, at which point you only ever have one such\nkey (and you do not need to know the semantics, only which one is the\n\"winner\").\n\n-Peff\n"},{"id":"224294","messageId":"7vsiywxiii.fsf@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"20130730081413.GC16693@sigill.intra.peff.net","subject":"Re: [PATCH 3/3] config: --get-urlmatch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-30T13:52:05Z","receivedAt":"2013-07-30T13:52:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Ah, I missed that you could leave \"key\" empty.\n\nYes, the general syntax is\n\n\tgit config [--<type>] --get-urlmatch <section>[.<key>] <url>\n\nand giving <section> without a specific <key> would list all the\nvariables in the section that apply to <url>.\n\nThis is why we should do documentation at some point before\npublishing a patch series; sorry about that.\n"},{"id":"224309","messageId":"C34D29B7-055D-4D82-B9FE-27150E51FF79@gmail.com","threadId":"34530","inReplyTo":"1375138150-19520-4-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 3/3] config: --get-urlmatch","fromName":"Kyle J. McKay","fromEmail":"mackyle@gmail.com","sentAt":"2013-07-30T19:14:03Z","receivedAt":"2013-07-30T19:14:03Z","isPatch":true,"sender":{"key":"mackyle@gmail.com","avatar":"https://avatars.githubusercontent.com/u/813346?v=4"},"body":"On Jul 29, 2013, at 15:49, Junio C Hamano wrote:\n\n> \"git config --get-urlmatch $section[.$variable] $url\" is a way to\n> learn what the configured value for $section.$variable is for the\n> given URL, using the logic introduced by the http.<url>.config\n> topic.  In addition to $section.$variable, entries in the\n> configuration file(s) that match $section.<urlpattern>.$variable are\n> looked up and the one with <urlpattern> that matches the given $url\n> the best is used to answer the query.\n>\n> This can still be further refactored to remove code from  \n> http_options()\n> in http.c, I think.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> builtin/config.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++ \n> +++++++++\n> 1 file changed, 141 insertions(+)\n>\n> diff --git a/builtin/config.c b/builtin/config.c\n> index 12c5073..c1d32ae 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n[...]\n> +static int get_urlmatch(const char *var, const char *url)\n> +{\n> +\tconst char *section_tail;\n> +\tstruct string_list_item *item;\n> +\tstruct urlmatch_collect collect = { STRING_LIST_INIT_DUP };\n> +\n> +\tif (!url_normalize(url, &collect.url))\n> +\t\tdie(collect.url.err);\n\nThe value now stored in collect.url.url is never freed.\n\n> +\n> +\tsection_tail = strchr(var, '.');\n> +\tif (section_tail) {\n> +\t\tcollect.section = xmemdupz(var, section_tail - var);\n> +\t\tcollect.key = strrchr(var, '.') + 1;\n> +\t\tshow_keys = 0;\n> +\t} else {\n> +\t\tcollect.section = var;\n> +\t\tcollect.key = NULL;\n> +\t\tshow_keys = 1;\n> +\t}\n> +\n> +\tgit_config_with_options(urlmatch_collect, &collect,\n> +\t\t\t\tgiven_config_file, respect_includes);\n> +\n> +\tfor_each_string_list_item(item, &collect.vars) {\n> +\t\tstruct urlmatch_item *matched = item->util;\n> +\t\tstruct strbuf key = STRBUF_INIT;\n> +\t\tstruct strbuf buf = STRBUF_INIT;\n> +\n> +\t\tstrbuf_addstr(&key, collect.section);\n> +\t\tstrbuf_addch(&key, '.');\n> +\t\tstrbuf_addstr(&key, item->string);\n> +\t\tformat_config(&buf, key.buf,\n> +\t\t\t      matched->value_is_null ? NULL : matched->value.buf);\n> +\t\tfwrite(buf.buf, 1, buf.len, stdout);\n> +\t\tstrbuf_release(&key);\n> +\t\tstrbuf_release(&buf);\n> +\n> +\t\tstrbuf_release(&matched->value);\n> +\t}\n> +\tstring_list_clear(&collect.vars, 1);\n\nNeeds something like this here:\n\n+\tfree(collect.url.url);\n\n> +\n> +\t/*\n> +\t * section name may have been copied to replace the dot, in which\n> +\t * case it needs to be freed.  key name is either NULL (e.g. 'http'\n> +\t * alone) or points into var (e.g. 'http.savecookies'), and we do\n> +\t * not own the storage.\n> +\t */\n> +\tif (collect.section != var)\n> +\t\tfree((void *)collect.section);\n> +\treturn 0;\n> +}\n\nStill needed after 4/3 except it's now config.url.url instead.\n"},{"id":"224310","messageId":"CC3A0EB0-79FE-40C2-B1AC-E3B9683A3ED6@gmail.com","threadId":"34530","inReplyTo":"7v1u6gztf1.fsf_-_@alter.siamese.dyndns.org","subject":"Re: [PATCH 5/3] revert most of the http_options() change","fromName":"Kyle J. McKay","fromEmail":"mackyle@gmail.com","sentAt":"2013-07-30T19:14:24Z","receivedAt":"2013-07-30T19:14:24Z","isPatch":true,"sender":{"key":"mackyle@gmail.com","avatar":"https://avatars.githubusercontent.com/u/813346?v=4"},"body":"On Jul 29, 2013, at 19:13, Junio C Hamano wrote:\n\n> With the previous preparation step, the earlier 1bb00006 (config:\n> add support for http.<url>.* settings, 2013-07-21) that introduced\n> many repeated changes:\n>\n>        -if (!strcmp(\"http.key\", var)) {\n>        +if (!strcmp(\"key\", key)) {\n>        +       if (match_is_shorter(..., OPT_KEY_NAME))\n>        +               return 0;\n>                ... original processing for KEY_NAME ...\n>         }\n>\n> can be reverted.\n>\n> This allows us to also get rid of the \"repeating yourself to the\n> death\" enum http_option_type, and new code (like db/http-savecookies\n> patch) that wants to add a new configuration to the http.* subsystem\n> does not have to conflict with http.<urlpattern>.variable series at\n> all.\n>\n> This is more-or-less how I want the endgame to look like. Not even\n> compile tested, but it is getting late so I'll show it to the list\n> in case people may want to play with it and polish it while I am\n> away for the night ;-).\n>\n> If people can agree that this is going in the right direction,\n> perhaps we should rebuild Kyle's series without detouring of adding\n> and then yanking what 1bb00006 (config: add support for http.<url>.*\n> settings, 2013-07-21) did in the next cycle.\n>\n> http.c               | 181 ++++++++ \n> +------------------------------------------\n> test-url-normalize.c |   9 ++-\n> 2 files changed, 39 insertions(+), 151 deletions(-)\n>\n> diff --git a/http.c b/http.c\n> index a91a00b..c7f513b 100644\n> --- a/http.c\n> +++ b/http.c\n[...]\n> @@ -469,15 +342,23 @@ void http_init(struct remote *remote, const  \n> char *url, int proactive_auth)\n> {\n> \tchar *low_speed_limit;\n> \tchar *low_speed_time;\n> -\tstruct url_info info;\n> +\tchar *normalized_url;\n> +\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n> +\n> +\tconfig.fn = http_options;\n> +\tconfig.cascade_fn = git_default_config;\n> +\tconfig.item_alloc = NULL;\n> +\tconfig.item_clear = NULL;\n> +\tconfig.cb = NULL;\n\nMissing this:\n+\tconfig.section = \"http\";\n\n\n[...]\n> diff --git a/test-url-normalize.c b/test-url-normalize.c\n> index 0b809eb..fab94e5 100644\n> --- a/test-url-normalize.c\n> +++ b/test-url-normalize.c\n> @@ -15,8 +15,15 @@ static int run_http_options(const char *file,\n> {\n> \tstruct strbuf opt_lc;\n> \tsize_t i, len;\n> +\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n>\n> -\tif (git_config_with_options(http_options, (void *)info, file, 0))\n> +\tconfig.fn = http_options;\n> +\tconfig.cascade_fn = git_default_config;\n> +\tconfig.item_alloc = NULL;\n> +\tconfig.item_clear = NULL;\n> +\tconfig.cb = NULL;\n\n\nMissing this:\n+\tconfig.section = \"http\";\n\nWithout these it segfaults running the tests.\n\nHowever, now the tests that actually check the results using config  \nfiles are failing:\n\n> # failed 1 among 11 test(s)\n\nI'm looking at it now to see if I can fix the problem.\n"},{"id":"224313","messageId":"3C93D9D6-8FC3-4D94-AE6E-37150202314A@gmail.com","threadId":"34530","inReplyTo":"CC3A0EB0-79FE-40C2-B1AC-E3B9683A3ED6@gmail.com","subject":"Re: [PATCH 5/3] revert most of the http_options() change","fromName":"Kyle J. McKay","fromEmail":"mackyle@gmail.com","sentAt":"2013-07-30T19:41:37Z","receivedAt":"2013-07-30T19:41:37Z","isPatch":true,"sender":{"key":"mackyle@gmail.com","avatar":"https://avatars.githubusercontent.com/u/813346?v=4"},"body":"\nOn Jul 30, 2013, at 12:14, Kyle J. McKay wrote:\n\n> On Jul 29, 2013, at 19:13, Junio C Hamano wrote:\n>\n>> With the previous preparation step, the earlier 1bb00006 (config:\n>> add support for http.<url>.* settings, 2013-07-21) that introduced\n>> many repeated changes:\n>>\n>>       -if (!strcmp(\"http.key\", var)) {\n>>       +if (!strcmp(\"key\", key)) {\n>>       +       if (match_is_shorter(..., OPT_KEY_NAME))\n>>       +               return 0;\n>>               ... original processing for KEY_NAME ...\n>>        }\n>>\n>> can be reverted.\n>>\n>> This allows us to also get rid of the \"repeating yourself to the\n>> death\" enum http_option_type, and new code (like db/http-savecookies\n>> patch) that wants to add a new configuration to the http.* subsystem\n>> does not have to conflict with http.<urlpattern>.variable series at\n>> all.\n>>\n>> This is more-or-less how I want the endgame to look like. Not even\n>> compile tested, but it is getting late so I'll show it to the list\n>> in case people may want to play with it and polish it while I am\n>> away for the night ;-).\n>>\n>> If people can agree that this is going in the right direction,\n>> perhaps we should rebuild Kyle's series without detouring of adding\n>> and then yanking what 1bb00006 (config: add support for http.<url>.*\n>> settings, 2013-07-21) did in the next cycle.\n>>\n>> http.c               | 181 ++++++++ \n>> +------------------------------------------\n>> test-url-normalize.c |   9 ++-\n>> 2 files changed, 39 insertions(+), 151 deletions(-)\n>>\n>> diff --git a/http.c b/http.c\n>> index a91a00b..c7f513b 100644\n>> --- a/http.c\n>> +++ b/http.c\n> [...]\n>> @@ -469,15 +342,23 @@ void http_init(struct remote *remote, const  \n>> char *url, int proactive_auth)\n>> {\n>> \tchar *low_speed_limit;\n>> \tchar *low_speed_time;\n>> -\tstruct url_info info;\n>> +\tchar *normalized_url;\n>> +\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n>> +\n>> +\tconfig.fn = http_options;\n>> +\tconfig.cascade_fn = git_default_config;\n>> +\tconfig.item_alloc = NULL;\n>> +\tconfig.item_clear = NULL;\n>> +\tconfig.cb = NULL;\n>\n> Missing this:\n> +\tconfig.section = \"http\";\n>\n>\n> [...]\n>> diff --git a/test-url-normalize.c b/test-url-normalize.c\n>> index 0b809eb..fab94e5 100644\n>> --- a/test-url-normalize.c\n>> +++ b/test-url-normalize.c\n>> @@ -15,8 +15,15 @@ static int run_http_options(const char *file,\n>> {\n>> \tstruct strbuf opt_lc;\n>> \tsize_t i, len;\n>> +\tstruct urlmatch_config config = { STRING_LIST_INIT_DUP };\n\nAlso needs this:\n\n+\tmemcpy(&config.url, info, sizeof(struct url_info));\n\n>> -\tif (git_config_with_options(http_options, (void *)info, file, 0))\n>> +\tconfig.fn = http_options;\n>> +\tconfig.cascade_fn = git_default_config;\n>> +\tconfig.item_alloc = NULL;\n>> +\tconfig.item_clear = NULL;\n>> +\tconfig.cb = NULL;\n>\n>\n> Missing this:\n> +\tconfig.section = \"http\";\n>\n> Without these it segfaults running the tests.\n>\n> However, now the tests that actually check the results using config  \n> files are failing:\n>\n>> # failed 1 among 11 test(s)\n>\n> I'm looking at it now to see if I can fix the problem.\n\nAnd now all the t5200-url-normalize tests pass again.\n\nFYI, I couldn't get the patches to apply against next or pu without  \nsome minor tweaks that were just conflict resolutions having to do  \nwith git_config_with_options changing its signature.\n"},{"id":"224322","messageId":"7vy58nvjou.fsf@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"3C93D9D6-8FC3-4D94-AE6E-37150202314A@gmail.com","subject":"Re: [PATCH 5/3] revert most of the http_options() change","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-30T21:09:37Z","receivedAt":"2013-07-30T21:09:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Kyle J. McKay\" <mackyle@gmail.com> writes:\n\n> And now all the t5200-url-normalize tests pass again.\n>\n> FYI, I couldn't get the patches to apply against next or pu without\n> some minor tweaks that were just conflict resolutions having to do\n> with git_config_with_options changing its signature.\n\nThanks.\n\nI built these five patches directly on top of your series, i.e. on\ntop of cea9928d (docs: update http.<url>.* options documentation,\n2013-07-25).\n\nI'll rebuild the series with your fixes and I may even queue it to\n'pu', but with some random thoughts:\n\n * \"url-match.[ch]\" are ugly names.  I'd be happier with\n   \"urlmatch.[ch]\".\n\n * In the end result, http_options() looks mostly identical to that\n   of the 'master', but it got an extra \"void *matched\", only to\n   support \"git config --get-urlmatch\".  I however do not have to,\n   if I do a few things:\n\n   - Instead of implementing urlmatch_config_item that extends\n     urlmatch_item, have a separate string_list, keyed by the\n     variable names, and point the string_list with the generic cb\n     pointer I already have in urlmatch_config.  The fn() on the\n     \"git config\" side has to index this second string_list with the\n     variable and keep track of the value from the best candidate we\n     have seen so far.\n\n   - The above allows us to lose item_alloc and item_clear callback\n     functions from urlmatch_config, as we will not be doing the\n     structure inheritance to extend urlmatch_item.\n\n   - We still need cascade_fn callback, though.\n\n * With the above, http_options() does not have to change in the\n   series.  We could restructure the series perhaps this way:\n\n   - http.sslCertPasswordProtected parsing fix.\n\n   - Add urlmatch.[ch], which would be your \"config: improve support\n     for http.<url>.* settings\" and yesterday's \"url-match: split\n     out URL matching logic out of http.c\", and a half of\n     \"url-match: generalize configuration collection logic\".\n\n   - Update http.c to use urlmatch.[ch] to make http.c match the\n     result of the endgame patch [5/3], and add necessary end user\n     documentation to Documentation/config.txt.\n\n   - Add test-url-normalize and t/t5200\n\n   - Update builtin/config.c for \"--get-urlmatch\", to make\n     builtin/config.c match the result of the endgame patch [5/3],\n     add end user documentation to Documentation/git-config.txt.\n\n   - Add some tests for \"git config --get-urlmatch\".\n"},{"id":"224372","messageId":"51F9509F.60402@ramsay1.demon.co.uk","threadId":"34530","inReplyTo":"1375138150-19520-1-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 0/3] \"git config --get-urlmatch $section.$key $url\"","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-07-31T17:59:59Z","receivedAt":"2013-07-31T17:59:59Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"Junio C Hamano wrote:\n> So here is a bit of refactoring to extract the logic to find the\n> entry $section.<urlpattern>.$key from the configuration that best\n> matches the given $url to answer \"what value $section.$key should be\n> for $url?\" out of http.c (primarily because we never want to link\n> \"git cofnig\" with the cURL library), and use it from \"git config\" to\n> implement Peff's idea to extend \"git config\".\n> \n> The first step is a pure code movement, plus some renaming of the\n> functions.\n> \n> The second step is to factor out the code to handle --bool, --int, etc.\n> as a helper so that the new codepath can use it.\n> \n> The last step currently duplicates the logic in http_options(), but\n> we might want to refactor it further so that the two functions can\n> share more code.  We hopefully can get rid of test-url-normalize and\n> instead use \"git config --get-urlmatch\" in the tests that protect\n> the http.<url>.config topic.\n\nI haven't been following this topic too closely and I don't have any\nfeel for how long it will take to get to the end-game. However, unless\nthe removal of test-url-normalize is coming soon, could I request that\nyou apply my patch (or squash it into this series)? At present, I have\nto apply the patch before building the next and pu branches; OK it's not\ntoo onerous, but still ... :-P\n\n\nATB,\nRamsay Jones\n"},{"id":"224381","messageId":"7vzjt2ttjo.fsf@alter.siamese.dyndns.org","threadId":"34530","inReplyTo":"51F9509F.60402@ramsay1.demon.co.uk","subject":"Re: [PATCH 0/3] \"git config --get-urlmatch $section.$key $url\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-31T19:31:55Z","receivedAt":"2013-07-31T19:31:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:\n\n> Junio C Hamano wrote:\n>> So here is a bit of refactoring to extract the logic to find the\n>> entry $section.<urlpattern>.$key from the configuration that best\n>> matches the given $url to answer \"what value $section.$key should be\n>> for $url?\" out of http.c (primarily because we never want to link\n>> \"git cofnig\" with the cURL library), and use it from \"git config\" to\n>> implement Peff's idea to extend \"git config\".\n>> \n>> The first step is a pure code movement, plus some renaming of the\n>> functions.\n>> \n>> The second step is to factor out the code to handle --bool, --int, etc.\n>> as a helper so that the new codepath can use it.\n>> \n>> The last step currently duplicates the logic in http_options(), but\n>> we might want to refactor it further so that the two functions can\n>> share more code.  We hopefully can get rid of test-url-normalize and\n>> instead use \"git config --get-urlmatch\" in the tests that protect\n>> the http.<url>.config topic.\n>\n> I haven't been following this topic too closely and I don't have any\n> feel for how long it will take to get to the end-game. However, unless\n> the removal of test-url-normalize is coming soon, could I request that\n> you apply my patch (or squash it into this series)? At present, I have\n> to apply the patch before building the next and pu branches; OK it's not\n> too onerous, but still ... :-P\n\nWill squash in.  Thanks for a reminder.\n"}]}