From: Kevin Cernekee <cernekee@gmail.com>
To: Jakub Narebski <jnareb@gmail.com>, Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH v2 1/3] gitweb: fix #patchNN anchors when path_info is enabled
Date: Thu, 17 Mar 2011 12:38:29 -0700 [thread overview]
Message-ID: <c8621826e0576e3e31240b0205e7e3d0@localhost> (raw)
When $feature{'pathinfo'} is used, gitweb sets the base URL to something
like:
<base href="http://HOST/gitweb.cgi">
This breaks the "patch" anchor links seen on the commitdiff pages,
because they are computed relative to the base URL:
http://HOST/gitweb.cgi#patch1
Instead, they should look like:
http://HOST/gitweb.cgi/myproject.git/commitdiff/35a9811ef9d68eae9afd76bede121da4f89b448c#patch1
Add an "-anchor" parameter to href(), so that the full path is included
in the patch link.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
gitweb/gitweb.perl | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0779f12..57a3caf 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1199,11 +1199,13 @@ 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 ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone
sub href {
my %params = @_;
# default is to use -absolute url() i.e. $my_uri
my $href = $params{-full} ? $my_url : $my_uri;
+ $params{-replay} = 1 if ($params{-anchor} && keys %params == 1);
$params{'project'} = $project unless exists $params{'project'};
if ($params{-replay}) {
@@ -1314,6 +1316,10 @@ sub href {
# final transformation: trailing spaces must be escaped (URI-encoded)
$href =~ s/(\s+)$/CGI::escape($1)/e;
+ if ($params{-anchor}) {
+ $href .= "#".esc_param($params{-anchor});
+ }
+
return $href;
}
@@ -4334,8 +4340,9 @@ 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(-anchor=>"patch$patchno")},
+ "patch") .
" | " .
"</td>\n";
}
@@ -4432,7 +4439,8 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch");
+ print $cgi->a({-href =>
+ href(-anchor=>"patch$patchno")}, "patch");
print " | ";
}
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
@@ -4452,7 +4460,8 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch");
+ print $cgi->a({-href =>
+ href(-anchor=>"patch$patchno")}, "patch");
print " | ";
}
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
@@ -4494,7 +4503,9 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch") .
+ print $cgi->a({-href =>
+ href(-anchor=>"patch$patchno")},
+ "patch") .
" | ";
} elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
# "commit" view and modified file (not onlu mode changed)
@@ -4539,7 +4550,9 @@ sub git_difftree_body {
if ($action eq 'commitdiff') {
# link to patch
$patchno++;
- print $cgi->a({-href => "#patch$patchno"}, "patch") .
+ print $cgi->a({-href =>
+ href(-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-17 19:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-17 19:38 Kevin Cernekee [this message]
2011-03-17 19:38 ` [PATCH v2 2/3] gitweb: introduce localtime feature Kevin Cernekee
2011-03-18 14:40 ` [PATCH v3 " Jakub Narebski
2011-03-18 18:24 ` Junio C Hamano
2011-03-18 21:58 ` Jakub Narebski
2011-03-18 22:42 ` Junio C Hamano
2011-03-17 19:38 ` [PATCH 3/3] gitweb: show alternate author/committer times Kevin Cernekee
2011-03-18 17:46 ` [PATCH 3/3 (alternate)] gitweb: Mark "atnight" author/committer times also for 'localtime' Jakub Narebski
2011-03-18 19:07 ` Kevin Cernekee
2011-03-18 20:48 ` Junio C Hamano
2011-03-18 22:28 ` Jakub Narebski
2011-03-19 1:25 ` Junio C Hamano
2011-03-18 12:59 ` [PATCH v3 1/3] gitweb: fix #patchNN anchors when path_info is enabled Jakub Narebski
2011-03-18 15:25 ` Kevin Cernekee
2011-03-18 16:00 ` [PATCH v3 (amend) " Jakub Narebski
2011-03-18 16:57 ` [PATCH v3 " Junio C Hamano
2011-03-18 17:18 ` Jakub Narebski
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=c8621826e0576e3e31240b0205e7e3d0@localhost \
--to=cernekee@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
/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).