Merge branch 'kc/gitweb-pathinfo-w-anchor'

* kc/gitweb-pathinfo-w-anchor:
  gitweb: fix #patchNN anchors when path_info is enabled
This commit is contained in:
Junio C Hamano 2011-03-23 14:55:55 -07:00
commit cd3065f9e3

View File

@ -1199,11 +1199,15 @@ if (defined caller) {
# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base) # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
# -replay => 1 - start from a current view (replay with modifications) # -replay => 1 - start from a current view (replay with modifications)
# -path_info => 0|1 - don't use/use path_info URL (if possible) # -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 { sub href {
my %params = @_; my %params = @_;
# default is to use -absolute url() i.e. $my_uri # default is to use -absolute url() i.e. $my_uri
my $href = $params{-full} ? $my_url : $my_uri; my $href = $params{-full} ? $my_url : $my_uri;
# implicit -replay, must be first of implicit params
$params{-replay} = 1 if (keys %params == 1 && $params{-anchor});
$params{'project'} = $project unless exists $params{'project'}; $params{'project'} = $project unless exists $params{'project'};
if ($params{-replay}) { if ($params{-replay}) {
@ -1314,6 +1318,10 @@ sub href {
# final transformation: trailing spaces must be escaped (URI-encoded) # final transformation: trailing spaces must be escaped (URI-encoded)
$href =~ s/(\s+)$/CGI::escape($1)/e; $href =~ s/(\s+)$/CGI::escape($1)/e;
if ($params{-anchor}) {
$href .= "#".esc_param($params{-anchor});
}
return $href; return $href;
} }
@ -4335,7 +4343,8 @@ sub git_difftree_body {
# link to patch # link to patch
$patchno++; $patchno++;
print "<td class=\"link\">" . print "<td class=\"link\">" .
$cgi->a({-href => "#patch$patchno"}, "patch") . $cgi->a({-href => href(-anchor=>"patch$patchno")},
"patch") .
" | " . " | " .
"</td>\n"; "</td>\n";
} }
@ -4432,8 +4441,9 @@ sub git_difftree_body {
if ($action eq 'commitdiff') { if ($action eq 'commitdiff') {
# link to patch # link to patch
$patchno++; $patchno++;
print $cgi->a({-href => "#patch$patchno"}, "patch"); print $cgi->a({-href => href(-anchor=>"patch$patchno")},
print " | "; "patch") .
" | ";
} }
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
hash_base=>$hash, file_name=>$diff->{'file'})}, hash_base=>$hash, file_name=>$diff->{'file'})},
@ -4452,8 +4462,9 @@ sub git_difftree_body {
if ($action eq 'commitdiff') { if ($action eq 'commitdiff') {
# link to patch # link to patch
$patchno++; $patchno++;
print $cgi->a({-href => "#patch$patchno"}, "patch"); print $cgi->a({-href => href(-anchor=>"patch$patchno")},
print " | "; "patch") .
" | ";
} }
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'}, print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
hash_base=>$parent, file_name=>$diff->{'file'})}, hash_base=>$parent, file_name=>$diff->{'file'})},
@ -4494,7 +4505,8 @@ sub git_difftree_body {
if ($action eq 'commitdiff') { if ($action eq 'commitdiff') {
# link to patch # link to patch
$patchno++; $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'}) { } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
# "commit" view and modified file (not onlu mode changed) # "commit" view and modified file (not onlu mode changed)
@ -4539,7 +4551,8 @@ sub git_difftree_body {
if ($action eq 'commitdiff') { if ($action eq 'commitdiff') {
# link to patch # link to patch
$patchno++; $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'}) { } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
# "commit" view and modified file (not only pure rename or copy) # "commit" view and modified file (not only pure rename or copy)