git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Feature request - show result of URL rewrites
@ 2016-11-12 17:49 Git User
  2016-11-12 18:17 ` Dennis Kaarsemaker
  0 siblings, 1 reply; 3+ messages in thread
From: Git User @ 2016-11-12 17:49 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Feature request - show result of URL rewrites
  2016-11-12 17:49 Feature request - show result of URL rewrites Git User
@ 2016-11-12 18:17 ` Dennis Kaarsemaker
  2016-11-13  1:46   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Dennis Kaarsemaker @ 2016-11-12 18:17 UTC (permalink / raw)
  To: Git User, git

On Sat, 2016-11-12 at 18:49 +0100, Git User wrote:
> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Feature request - show result of URL rewrites
  2016-11-12 18:17 ` Dennis Kaarsemaker
@ 2016-11-13  1:46   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2016-11-13  1:46 UTC (permalink / raw)
  To: Dennis Kaarsemaker; +Cc: Git User, git

Dennis Kaarsemaker <dennis@kaarsemaker.net> writes:

>> 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);
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-13  1:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-12 17:49 Feature request - show result of URL rewrites Git User
2016-11-12 18:17 ` Dennis Kaarsemaker
2016-11-13  1:46   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).