threads / patch / 43337

patchRe: [PATCH] gitweb: make HTML links out of http/https URLs in changelogs

Subject: Re: [PATCH] gitweb: make HTML links out of http/https URLs in changelogs

## tl;dr

6 messages between Nov 21, 2006 and Nov 22, 2006. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

Kir Kolyshkin· Nov 21, 2006, 22:02 UTC · lore

[PATCH] gitweb: make HTML links out of http/https URLs in changelogs

It is a common practice to put links to bugzillas, mailing lists, etc. in git log entries. The fact that gitweb doesn't make HTML links out of that URLs makes following those URLs inconvenient. This patch fixes that problem, trying to address cases when URL is enclosed in round or square brackets.

Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
---
 gitweb/gitweb.perl |    2 ++
 1 file changed, 2 insertions(+)

--- git-1.4.4/gitweb/gitweb.perl 2006-11-15 08:22:27.000000000 +0100 +++ git-1.4.4-my/gitweb/gitweb.perl 2006-11-21 22:49:14.000000000 +0100

Show changes to diff +2 −0
@@ -828,6 +828,8 @@
 			$line =~ s/$hash_text/$link/;
 		}
 	}
+	# make HTML links out of http(s) URLs
+	$line =~ s/(http[s]?:\/\/[^[:space:]\]\)]+)/<a href="\1">\1<\/a>/g;
 	return $line;
 }
 
Jakub Narebski· Nov 21, 2006, 22:28 UTC · re: Kir Kolyshkin · lore
Kir Kolyshkin wrote:
Show 5 quoted lines
> It is a common practice to put links to bugzillas, mailing lists, etc. 
> in git log entries. The fact that gitweb doesn't make HTML links out of 
> that URLs makes following those URLs inconvenient. This patch fixes that 
> problem, trying to address cases when URL is enclosed in round or square 
> brackets.

Preliminary committags support was sent as an RFC patch on git mailing list once. Hyperlinking plain text http, https, ftp, ftps links etc. is a special case of committag. That wha is implemented now, namely hyperlinking commitsha to commit view is also special case of comittag.

And I plan to implement it, only later. But you are welcome to do it instead.

gitweb-xmms2 http://git.xmms.se/?p=gitweb-xmms2.git has xmms2 related
committags support (links to xmms2 Mantis bugtracker from BUG(n) and
FEATURE(n))
 
Show 10 quoted lines
> Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.
> 
> Signed-off-by: Kir Kolyshkin <kir@openvz.org>
> ---
>  gitweb/gitweb.perl |    2 ++
>  1 file changed, 2 insertions(+)
> 
> --- git-1.4.4/gitweb/gitweb.perl      2006-11-15 08:22:27.000000000 +0100
> +++ git-1.4.4-my/gitweb/gitweb.perl   2006-11-21 22:49:14.000000000 +0100
> @@ -828,6 +828,8 @@

Could you please send patches created by git tools, namely git-format-patch, or if you really need to send GNU diff patches, use -p option? It really helps in patch review.

Show 7 quoted lines
>                       $line =~ s/$hash_text/$link/;
>               }
>       }
> +     # make HTML links out of http(s) URLs
> +     $line =~ s/(http[s]?:\/\/[^[:space:]\]\)]+)/<a href="\1">\1<\/a>/g;
>       return $line;
>  }
Wont work correctly if commit message has sha1 of commit in it; it would be
changed to 
 <a href="$my_uri?p=$project;a=commit;h=$hash_text" class="text">$hash_text</a>
then the code you added will add hyperlink in place of href value (!).
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Randal L. Schwartz· Nov 21, 2006, 23:55 UTC · re: Kir Kolyshkin · lore
>>>>> "Kir" == Kir Kolyshkin <kir@openvz.org> writes:

Kir> + # make HTML links out of http(s) URLs Kir> + $line =~ s/(http[s]?:\/\/[^[:space:]\]\)]+)/<a href="\1">\1<\/a>/g;

Perl tip of the day:

On the right side of s///, you want $1, not \1, because \1 accidentally works, but \10 (instead of the proper $10) will give you a control-h. Ick.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
Petr Baudis· Nov 22, 2006, 00:06 UTC · re: Kir Kolyshkin · lore
On Tue, Nov 21, 2006 at 11:02:36PM CET, Kir Kolyshkin wrote:
> Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.

...but in git's gitweb view it will make this <a href="http://git.openvz.org/.">http://git.openvz.org/.</a>. :-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
The meaning of Stonehenge in Traflamadorian, when viewed from above, is:
"Replacement part being rushed with all possible speed."
Kir Kolyshkin· Nov 22, 2006, 09:00 UTC · re: Petr Baudis · lore
Petr Baudis wrote:
Show 7 quoted lines
> On Tue, Nov 21, 2006 at 11:02:36PM CET, Kir Kolyshkin wrote:
>   
>> Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.
>>     
>
> ...but in git's gitweb view it will make this <a
> href="http://git.openvz.org/.">http://git.openvz.org/.</a>. :-)

Not a problem actually since "." means "current directory", so it will work fine (and I have checked that) :) Sure there is a room for improvement for this regex -- and I am collecting those.

Petr Baudis· Nov 22, 2006, 20:56 UTC · re: Kir Kolyshkin · lore
On Wed, Nov 22, 2006 at 10:00:05AM CET, Kir Kolyshkin wrote:
Show 12 quoted lines
> Petr Baudis wrote:
> >On Tue, Nov 21, 2006 at 11:02:36PM CET, Kir Kolyshkin wrote:
> >  
> >>Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.
> >>    
> >
> >...but in git's gitweb view it will make this <a
> >href="http://git.openvz.org/.">http://git.openvz.org/.</a>. :-)
> Not a problem actually since "." means "current directory", so it will 
> work fine (and I have checked that) :)
> Sure there is a room for improvement for this regex -- and I am 
> collecting those.

But "http://git.openvz.org/index.html." might not work so fine, nor "http://git.openvz.org/,"...

Bad URLs matchers which don't snip unlikely (!= invalid!) characters from the end of the URL are my pet peeve. ;-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
The meaning of Stonehenge in Traflamadorian, when viewed from above, is:
"Replacement part being rushed with all possible speed."

← back to recent threads