Skip to contentSkip to conversation

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

PATCH In review Kir Kolyshkin 4 participants 6 messages Aug 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
gitweb/gitweb.perl | 2 ++

1 file changed, 2 insertions(+)
gitweb/gitweb.perl +0 -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;
}
#1 lore raw
Quoted 1 line · Kir Kolyshkin

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>. :-)

Signature · 4 lines
				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."
#2 lore raw
Quoted 7 lines · Petr Baudis
Quoted 2 lines · Kir Kolyshkin

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.

#3 lore raw
Quoted 6 lines · Kir Kolyshkin
Quoted 5 lines · Petr Baudis
Quoted 2 lines · Kir Kolyshkin

Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.

Quoted 6 lines
Quoted 2 lines

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

Signature · 4 lines
				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."
#4 lore raw
In reply to Kir Kolyshkin
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kir" == Kir Kolyshkin <[email protected]> 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.

Signature · 3 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
#5 lore raw
In reply to Kir Kolyshkin
Quoted 5 lines · Kir Kolyshkin

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

gitweb/gitweb.perl 2006-11-21 22:49:14.000000000 +0100

Quoted 10 lines

Slightly tested on http://git.openvz.org/. Applicable to git-1.4.4.

---
 gitweb/gitweb.perl |    2 ++
 1 file changed, 2 insertions(+)
gitweb/gitweb.perl 2006-11-21 22:49:14.000000000 +0100 renamed from gitweb/gitweb.perl 2006-11-15 08:22:27.000000000 +0100 +0 -0
@@ -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.

gitweb/gitweb.perl 2006-11-21 22:49:14.000000000 +0100 line 834

Quoted 7 lines
gitweb/gitweb.perl 2006-11-21 22:49:14.000000000 +0100 renamed from gitweb/gitweb.perl 2006-11-15 08:22:27.000000000 +0100 +2 -0
                      $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 (!).

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git