threads / discuss / 44473

Feature request - show result of URL rewrites

Subject: Feature request - show result of URL rewrites

## tl;dr

3 messages between Nov 12, 2016 and Nov 13, 2016.

replies: 2people: 3as markdown or json

Git User· Nov 12, 2016, 17:49 UTC · lore
Hello
Hopefully this is the right place to submit feature requests - let me know if there's somewhere else I should use!
Git lets you rewrite URLs using "url.<base>.insteadOf"

https://stackoverflow.com/a/11383587 https://git-scm.com/docs/git-config

Can 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.
E.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.
Thanks
Dennis Kaarsemaker· Nov 12, 2016, 18:17 UTC · re: Git User · lore

Re: Feature request - show result of URL rewrites

On Sat, 2016-11-12 at 18:49 +0100, Git User wrote:
Show 17 quoted lines
> Hello
> 
> Hopefully this is the right place to submit feature requests - let me
> know if there's somewhere else I should use!
> 
> Git lets you rewrite URLs using "url.<base>.insteadOf"
> 
> https://stackoverflow.com/a/11383587
> https://git-scm.com/docs/git-config
> 
> Can 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.
> 
> E.g. you could have the option 'url.printRewrites [True/False]' which
> would print the line "Rewrote url 'git://github.com/git/git' to 'http
> s://github.com/git/git'" to terminal/stdout  when set to True.

Such a configuration would be superfluous, the GIT_TRACE and GIT_CURL_VERBOSE environment variables already provide all the debugging information you need here.

D.
Junio C Hamano· Nov 13, 2016, 01:46 UTC · re: Dennis Kaarsemaker · lore

Re: Feature request - show result of URL rewrites

Dennis Kaarsemaker <dennis@kaarsemaker.net> writes:
Show 13 quoted lines
>> Git lets you rewrite URLs using "url.<base>.insteadOf"
>>  ...
>> Can 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.
>> 
>> E.g. you could have the option 'url.printRewrites [True/False]' which
>> would print the line "Rewrote url 'git://github.com/git/git' to 'http
>> s://github.com/git/git'" to terminal/stdout  when set to True.
>
> Such a configuration would be superfluous, the GIT_TRACE and
> GIT_CURL_VERBOSE environment variables already provide all the
> debugging information you need here.

While i tend to agree with you that this kind of thing should not be a new "configuration" that you need to unset after you are done debugging, and should instead be done with a single-shot request mechanism like environment variables, I do not think your response is a fair and useful one. Perhaps it is fair for the original request that wants to have a knob to learn what the original was rewritten to, but then the original request did not aim high enough to get a useful feature, I would suspect.

GIT_TRACE or CURL_VERBOSE may show you the rewritten URL, and the end user (presumably) knows what the original URL s/he handed Git to go to, but I do not think these two are sufficient to find out what triggered one URL to be rewritten to the other URL, which probably is what the user wants to know the most.

Your response may become useful if remove.c::alias_url() is taught to react to GIT_TRACE (or some other debugging mechanism we already have), so that it reports what rule caused what URL to be rewritten to what other URL.

This is just to illustrate where to patch and not meant to even compile (e.g. "debug" is not even a variable defined anywhere), but starting from something like this, perhaps?

 remote.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/remote.c b/remote.c
index ad6c5424ed..09dca9468f 100644
--- a/remote.c
+++ b/remote.c
@@ -63,11 +63,9 @@ static int valid_remote(const struct remote *remote)
 static const char *alias_url(const char *url, struct rewrites *r)
 {
 	int i, j;
-	struct counted_string *longest;
-	int longest_i;
+	struct counted_string *longest = NULL;
+	int longest_i = -1, instead_of_j = -1;
 
-	longest = NULL;
-	longest_i = -1;
 	for (i = 0; i < r->rewrite_nr; i++) {
 		if (!r->rewrite[i])
 			continue;
@@ -77,12 +75,24 @@ static const char *alias_url(const char *url, struct rewrites *r)
 			     longest->len < r->rewrite[i]->instead_of[j].len)) {
 				longest = &(r->rewrite[i]->instead_of[j]);
 				longest_i = i;
+				instead_of_j = j;
 			}
 		}
 	}
 	if (!longest)
 		return url;
 
+	if (debug) {
+		fprintf(stderr, "rewriting %s to %s%s\n",
+			url,
+			r->rewrite[longest_i]->base, url + longest->len);
+		fprintf(stderr, "due to '%.*s.insteadof' = '%.*s'\n",
+			r->rewrite[longest_i]->baselen,
+			r->rewrite[longest_i]->base,
+			r->rewrite[longest_i]->instead_of[j].len,
+			r->rewrite[longest_i]->instead_of[j].s);
+	}
+
 	return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
 }
 

← back to recent threads