From: Kevin Cernekee <cernekee@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 1/2] gitweb: fix #patchNN anchors when path_info is enabled
Date: Tue, 15 Mar 2011 19:15:54 -0700 [thread overview]
Message-ID: <3ef1af6874437043a4451bfbcae59b2b@localhost> (raw)
My configuration is as follows:
$feature{'pathinfo'}{'default'} = [1];
<Location /gitweb>
Options ExecCGI
SetHandler cgi-script
</Location>
GITWEB_{JS,CSS,LOGO,...} all start with gitweb-static/
gitweb.cgi renamed to /var/www/html/gitweb
This gives me simple, easy-to-read URLs that look like:
http://HOST/gitweb/myproject.git/commitdiff/0faa4a6ef921d8a233f30d66f9a3e1b24e8ec906
The problem is that in this configuration, PATH_INFO is used to set the
base URL:
<base href="http://HOST/gitweb">
This breaks the "patch" anchor links seen on the commitdiff pages,
because they are computed relative to the base URL:
http://HOST/gitweb#patch1
My solution is to add an "anchor" parameter to href(), so that the full
path is included in the patchNN links.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
gitweb/gitweb.perl | 31 +++++++++++++++++++++++++------
1 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1b9369d..3b6a90d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1199,6 +1199,7 @@ if (defined caller) {
# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
# -replay => 1 - start from a current view (replay with modifications)
# -path_info => 0|1 - don't use/use path_info URL (if possible)
+# -anchor - add #ANCHOR to end of URL
sub href {
my %params = @_;
# default is to use -absolute url() i.e. $my_uri
@@ -1314,6 +1315,10 @@ sub href {
# final transformation: trailing spaces must be escaped (URI-encoded)
$href =~ s/(\s+)$/CGI::escape($1)/e;
+ if (defined($params{'anchor'})) {
+ $href .= "#".esc_param($params{'anchor'});
+ }
+
return $href;
}
@@ -4334,8 +4339,10 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print "<td class=\"link\">" .
- $cgi->a({-href => "#patch$patchno"}, "patch") .
+ print $cgi->a({-href =>
+ href(action=>"commitdiff",
+ hash=>$hash, anchor=>"patch$patchno")},
+ "patch") .
" | " .
"</td>\n";
}
@@ -4432,7 +4439,10 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch");
+ print $cgi->a({-href =>
+ href(action=>"commitdiff",
+ hash=>$hash, anchor=>"patch$patchno")},
+ "patch");
print " | ";
}
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
@@ -4452,7 +4462,10 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch");
+ print $cgi->a({-href =>
+ href(action=>"commitdiff",
+ hash=>$hash, anchor=>"patch$patchno")},
+ "patch");
print " | ";
}
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
@@ -4494,7 +4507,10 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch") .
+ print $cgi->a({-href =>
+ href(action=>"commitdiff",
+ hash=>$hash, anchor=>"patch$patchno")},
+ "patch") .
" | ";
} elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
# "commit" view and modified file (not onlu mode changed)
@@ -4539,7 +4555,10 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch") .
+ print $cgi->a({-href =>
+ href(action=>"commitdiff",
+ hash=>$hash, anchor=>"patch$patchno")},
+ "patch") .
" | ";
} elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
# "commit" view and modified file (not only pure rename or copy)
--
1.7.4.1
next reply other threads:[~2011-03-16 2:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-16 2:15 Kevin Cernekee [this message]
2011-03-16 2:15 ` [PATCH 2/2] gitweb: introduce localtime feature Kevin Cernekee
2011-03-17 11:01 ` Jakub Narebski
2011-03-17 18:26 ` Junio C Hamano
2011-03-17 20:12 ` Kevin Cernekee
2011-03-17 22:30 ` Jakub Narebski
2011-03-17 10:43 ` [PATCH 1/2] gitweb: fix #patchNN anchors when path_info is enabled Jakub Narebski
2011-03-17 18:40 ` Junio C Hamano
2011-03-17 19:19 ` Jakub Narebski
2011-03-17 20:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3ef1af6874437043a4451bfbcae59b2b@localhost \
--to=cernekee@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).