Re: Feature request - show result of URL rewrites

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dennis Kaarsemaker <dennis@xxxxxxxxxxxxxxx> 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);
 }
 



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]