path: root/gitweb/gitweb.perl
diff options
authorJakub Narebski <>2009-09-01 11:39:19 (GMT)
committerJunio C Hamano <>2009-09-01 15:34:25 (GMT)
commitc4ccf61f4caf8c293713586531b4a2ea709756c8 (patch)
treeb29a1b285c85904ddbf5da29b9a9b4fbbffd942d /gitweb/gitweb.perl
parente206d62a922d80f2d00427ddfb93435adbf1cc59 (diff)
gitweb: Create links leading to 'blame_incremental' using JavaScript
The new 'blame_incremental' view requires JavaScript to run. Not all web browsers implement JavaScript (e.g. text browsers such as Lynx), and not all users have JavaScript enabled. Therefore instead of unconditionally linking to 'blame_incremental' view, we use JavaScript to convert those links to lead to view utilizing JavaScript, by adding 'js=1' to link. Currently the only action that takes 'js=1' into account is 'blame', which then acts as if it was called as 'blame_incremental' action. Possible enhancement would be to do JavaScript redirect by setting window.location instead of modifying $format and $action in git_blame_common() subroutine. The only JavaScript-aware/using view is currently 'blame_incremental'. While at it move reading JavaScript to git_footer_html() subroutine. Note that in this view we do not add 'js=1' currently (even though perhaps we should; note that for consistency we should also add 'js=1' in links added by JavaScript part of 'blame_incremental'). This idea was originally implemented by Petr Baudis in but it added <script> element with fixBlameLinks() function in page header, to be added as onload event using 'onload' attribute of HTML 'body' element: <body onload="fixBlameLinks();">. This version adds script at then end of page (in the page footer), and uses JavaScript 'window.onload=fixLinks();'. Also in Petr version only links marked with 'blamelink' class were modified, and they were modified by replacing "a=blame" by "a=blame_incremental"... which doesn't work for path_info links, and might replace wrong part if there is "a=blame" in project name, ref name or file name. Slightly different solution was implemented by Martin Koegler in Here GitAddLinks() function was in gitweb.js file, not as contents of <script> element. It was also included in page header (in <head> element) though, which means waiting for a script to load (and run). It was smarter in that to "fix" (modify) link, it split URL, modified value of 'a' parameter, and then recreated modified link. It avoids trouble with "a=blame" as substring in project name or file name, but it doesn't work with path_info URL/link in the way it was written. Signed-off-by: Jakub Narebski <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'gitweb/gitweb.perl')
1 files changed, 19 insertions, 9 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6cdd8c3..4a63646 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -560,6 +560,8 @@ our @cgi_param_mapping = (
snapshot_format => "sf",
extra_options => "opt",
search_use_regexp => "sr",
+ # this must be last entry (for manipulation from JavaScript)
+ javascript => "js"
our %cgi_param_mapping = @cgi_param_mapping;
@@ -3242,6 +3244,18 @@ sub git_footer_html {
+ print qq!<script type="text/javascript" src="$javascript"></script>\n!;
+ if ($action eq 'blame_incremental') {
+ print qq!<script type="text/javascript">\n!.
+ qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
+ qq! "!. href() .qq!");\n!.
+ qq!</script>\n!;
+ } else {
+ print qq!<script type="text/javascript">\n!.
+ qq!window.onload = fixLinks;\n!.
+ qq!</script>\n!;
+ }
print "</body>\n" .
@@ -4793,6 +4807,10 @@ sub git_tag {
sub git_blame_common {
my $format = shift || 'porcelain';
+ if ($format eq 'porcelain' && $cgi->param('js')) {
+ $format = 'incremental';
+ $action = 'blame_incremental'; # for page title etc
+ }
# permissions
@@ -4872,7 +4890,7 @@ sub git_blame_common {
if ($format eq 'incremental') {
print "<noscript>\n<div class=\"error\"><center><b>\n".
"This page requires JavaScript to run.\n Use ".
- $cgi->a({-href => href(action=>'blame',-replay=>1)},
+ $cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},
'this page').
" instead.\n".
@@ -5003,14 +5021,6 @@ sub git_blame_common {
close $fd
or print "Reading blob failed\n";
- if ($format eq 'incremental') {
- print qq!<script type="text/javascript" src="$javascript"></script>\n!.
- qq!<script type="text/javascript">\n!.
- qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
- qq! "!. href() .qq!");\n!.
- qq!</script>\n!;
- }