Code

Merge branch 'kc/gitweb-pathinfo-w-anchor'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2011 21:55:55 +0000 (14:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2011 21:55:55 +0000 (14:55 -0700)
* kc/gitweb-pathinfo-w-anchor:
  gitweb: fix #patchNN anchors when path_info is enabled

1  2 
gitweb/gitweb.perl

diff --combined gitweb/gitweb.perl
index 9dccfb01d6634febbb51fbadf10bed07bd97c804,f275adbcf1ee2d5eb19d37e64cc32e657cf48f2a..0178633b265c32d3fbd6bfe32499c10354dd6a3c
@@@ -1199,11 -1199,15 +1199,15 @@@ 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;
  
+       # implicit -replay, must be first of implicit params
+       $params{-replay} = 1 if (keys %params == 1 && $params{-anchor});
        $params{'project'} = $project unless exists $params{'project'};
  
        if ($params{-replay}) {
        # 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;
  }
  
@@@ -4335,7 -4343,8 +4343,8 @@@ sub git_difftree_body 
                                # link to patch
                                $patchno++;
                                print "<td class=\"link\">" .
-                                     $cgi->a({-href => "#patch$patchno"}, "patch") .
+                                     $cgi->a({-href => href(-anchor=>"patch$patchno")},
+                                             "patch") .
                                      " | " .
                                      "</td>\n";
                        }
                        if ($action eq 'commitdiff') {
                                # link to patch
                                $patchno++;
-                               print $cgi->a({-href => "#patch$patchno"}, "patch");
-                               print " | ";
+                               print $cgi->a({-href => href(-anchor=>"patch$patchno")},
+                                             "patch") .
+                                     " | ";
                        }
                        print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
                                                     hash_base=>$hash, file_name=>$diff->{'file'})},
                        if ($action eq 'commitdiff') {
                                # link to patch
                                $patchno++;
-                               print $cgi->a({-href => "#patch$patchno"}, "patch");
-                               print " | ";
+                               print $cgi->a({-href => href(-anchor=>"patch$patchno")},
+                                             "patch") .
+                                     " | ";
                        }
                        print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
                                                     hash_base=>$parent, file_name=>$diff->{'file'})},
                        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)
                        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)
@@@ -4906,6 -4919,7 +4919,6 @@@ sub git_log_body 
                next if !%co;
                my $commit = $co{'id'};
                my $ref = format_ref_marker($refs, $commit);
 -              my %ad = parse_date($co{'author_epoch'});
                git_print_header_div('commit',
                               "<span class=\"age\">$co{'age_string'}</span>" .
                               esc_html($co{'title'}) . $ref,
@@@ -7063,7 -7077,7 +7076,7 @@@ sub git_feed 
        if (defined($commitlist[0])) {
                %latest_commit = %{$commitlist[0]};
                my $latest_epoch = $latest_commit{'committer_epoch'};
 -              %latest_date   = parse_date($latest_epoch);
 +              %latest_date   = parse_date($latest_epoch, $latest_commit{'comitter_tz'});
                my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
                if (defined $if_modified) {
                        my $since;
@@@ -7194,7 -7208,7 +7207,7 @@@ XM
                if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
                        last;
                }
 -              my %cd = parse_date($co{'author_epoch'});
 +              my %cd = parse_date($co{'author_epoch'}, $co{'author_tz'});
  
                # get list of changed files
                open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,