{"thread":{"id":"44473","subject":"Feature request - show result of URL rewrites","startedAt":"2016-11-12T17:56:17Z","lastAt":"2016-11-13T01:47:08Z","messageCount":3,"participants":["Git User","Dennis Kaarsemaker","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"305861","messageId":"284668531.626.1478972994238.JavaMail.root@ichabod","threadId":"44473","inReplyTo":null,"subject":"Feature request - show result of URL rewrites","fromName":"Git User","fromEmail":"git.user@mailfence.com","sentAt":"2016-11-12T17:49:54Z","receivedAt":"2016-11-12T17:56:17Z","isPatch":false,"sender":{"key":"git.user@mailfence.com","avatar":null},"body":"Hello\n\nHopefully this is the right place to submit feature requests - let me know if there's somewhere else I should use!\n\nGit lets you rewrite URLs using \"url.<base>.insteadOf\"\n\nhttps://stackoverflow.com/a/11383587\nhttps://git-scm.com/docs/git-config\n\nCan you add a git-config option to show the result of this rewriting whenever this occurs, as debugging more complicated rules can be difficult/wasn't obvious without Wireshark.\n\nE.g. you could have the option 'url.printRewrites [True/False]' which would print the line \"Rewrote url 'git://github.com/git/git' to 'https://github.com/git/git'\" to terminal/stdout  when set to True.\n\nThanks\n"},{"id":"305862","messageId":"1478974642.3227.4.camel@kaarsemaker.net","threadId":"44473","inReplyTo":"284668531.626.1478972994238.JavaMail.root@ichabod","subject":"Re: Feature request - show result of URL rewrites","fromName":"Dennis Kaarsemaker","fromEmail":"dennis@kaarsemaker.net","sentAt":"2016-11-12T18:17:22Z","receivedAt":"2016-11-12T18:17:32Z","isPatch":false,"sender":{"key":"dennis@kaarsemaker.net","avatar":"https://avatars.githubusercontent.com/u/200649?v=4"},"body":"On Sat, 2016-11-12 at 18:49 +0100, Git User wrote:\n> Hello\n> \n> Hopefully this is the right place to submit feature requests - let me\n> know if there's somewhere else I should use!\n> \n> Git lets you rewrite URLs using \"url.<base>.insteadOf\"\n> \n> https://stackoverflow.com/a/11383587\n> https://git-scm.com/docs/git-config\n> \n> Can you add a git-config option to show the result of this rewriting\n> whenever this occurs, as debugging more complicated rules can be\n> difficult/wasn't obvious without Wireshark.\n> \n> E.g. you could have the option 'url.printRewrites [True/False]' which\n> would print the line \"Rewrote url 'git://github.com/git/git' to 'http\n> s://github.com/git/git'\" to terminal/stdout  when set to True.\n\nSuch a configuration would be superfluous, the GIT_TRACE and\nGIT_CURL_VERBOSE environment variables already provide all the\ndebugging information you need here.\n\nD.\n"},{"id":"305870","messageId":"xmqqinrsywvh.fsf@gitster.mtv.corp.google.com","threadId":"44473","inReplyTo":"1478974642.3227.4.camel@kaarsemaker.net","subject":"Re: Feature request - show result of URL rewrites","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-11-13T01:46:58Z","receivedAt":"2016-11-13T01:47:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dennis Kaarsemaker <dennis@kaarsemaker.net> writes:\n\n>> Git lets you rewrite URLs using \"url.<base>.insteadOf\"\n>>  ...\n>> Can you add a git-config option to show the result of this rewriting\n>> whenever this occurs, as debugging more complicated rules can be\n>> difficult/wasn't obvious without Wireshark.\n>> \n>> E.g. you could have the option 'url.printRewrites [True/False]' which\n>> would print the line \"Rewrote url 'git://github.com/git/git' to 'http\n>> s://github.com/git/git'\" to terminal/stdout  when set to True.\n>\n> Such a configuration would be superfluous, the GIT_TRACE and\n> GIT_CURL_VERBOSE environment variables already provide all the\n> debugging information you need here.\n\nWhile i tend to agree with you that this kind of thing should not be\na new \"configuration\" that you need to unset after you are done\ndebugging, and should instead be done with a single-shot request\nmechanism like environment variables, I do not think your response\nis a fair and useful one.  Perhaps it is fair for the original\nrequest that wants to have a knob to learn what the original was\nrewritten to, but then the original request did not aim high enough\nto get a useful feature, I would suspect.\n\nGIT_TRACE or CURL_VERBOSE may show you the rewritten URL, and the\nend user (presumably) knows what the original URL s/he handed Git to\ngo to, but I do not think these two are sufficient to find out what\ntriggered one URL to be rewritten to the other URL, which probably\nis what the user wants to know the most.\n\nYour response may become useful if remove.c::alias_url() is taught\nto react to GIT_TRACE (or some other debugging mechanism we already\nhave), so that it reports what rule caused what URL to be rewritten\nto what other URL.\n\nThis is just to illustrate where to patch and not meant to even\ncompile (e.g. \"debug\" is not even a variable defined anywhere), but\nstarting from something like this, perhaps?\n\n remote.c | 18 ++++++++++++++----\n 1 file changed, 14 insertions(+), 4 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex ad6c5424ed..09dca9468f 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -63,11 +63,9 @@ static int valid_remote(const struct remote *remote)\n static const char *alias_url(const char *url, struct rewrites *r)\n {\n \tint i, j;\n-\tstruct counted_string *longest;\n-\tint longest_i;\n+\tstruct counted_string *longest = NULL;\n+\tint longest_i = -1, instead_of_j = -1;\n \n-\tlongest = NULL;\n-\tlongest_i = -1;\n \tfor (i = 0; i < r->rewrite_nr; i++) {\n \t\tif (!r->rewrite[i])\n \t\t\tcontinue;\n@@ -77,12 +75,24 @@ static const char *alias_url(const char *url, struct rewrites *r)\n \t\t\t     longest->len < r->rewrite[i]->instead_of[j].len)) {\n \t\t\t\tlongest = &(r->rewrite[i]->instead_of[j]);\n \t\t\t\tlongest_i = i;\n+\t\t\t\tinstead_of_j = j;\n \t\t\t}\n \t\t}\n \t}\n \tif (!longest)\n \t\treturn url;\n \n+\tif (debug) {\n+\t\tfprintf(stderr, \"rewriting %s to %s%s\\n\",\n+\t\t\turl,\n+\t\t\tr->rewrite[longest_i]->base, url + longest->len);\n+\t\tfprintf(stderr, \"due to '%.*s.insteadof' = '%.*s'\\n\",\n+\t\t\tr->rewrite[longest_i]->baselen,\n+\t\t\tr->rewrite[longest_i]->base,\n+\t\t\tr->rewrite[longest_i]->instead_of[j].len,\n+\t\t\tr->rewrite[longest_i]->instead_of[j].s);\n+\t}\n+\n \treturn xstrfmt(\"%s%s\", r->rewrite[longest_i]->base, url + longest->len);\n }\n \n"}]}