gitweb: start to generate PATH_INFO URLs.
[gitweb.git] / gitweb / gitweb.perl
index 9550bd74efa63c959cb502e8c4c962e92634001c..10e803a97fa411ad014fbe476e55ec83d2e9f6b6 100755 (executable)
                'sub' => \&feature_pickaxe,
                'override' => 0,
                'default' => [1]},
+
+       'pathinfo' => {
+               'override' => 0,
+               'default' => [0]},
 );
 
 sub gitweb_check_feature {
@@ -155,6 +159,13 @@ sub feature_snapshot {
        return ($ctype, $suffix, $command);
 }
 
+sub gitweb_have_snapshot {
+       my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
+       my $have_snapshot = (defined $ctype && defined $suffix);
+
+       return $have_snapshot;
+}
+
 # To enable system wide have in $GITWEB_CONFIG
 # $feature{'pickaxe'}{'default'} = [1];
 # To have project specific config enable override in $GITWEB_CONFIG
@@ -368,6 +379,7 @@ sub evaluate_path_info {
 
 sub href(%) {
        my %params = @_;
+       my $href = $my_uri;
 
        my @mapping = (
                project => "p",
@@ -386,6 +398,19 @@ (%)
 
        $params{'project'} = $project unless exists $params{'project'};
 
+       my ($use_pathinfo) = gitweb_check_feature('pathinfo');
+       if ($use_pathinfo) {
+               # use PATH_INFO for project name
+               $href .= "/$params{'project'}" if defined $params{'project'};
+               delete $params{'project'};
+
+               # Summary just uses the project path URL
+               if (defined $params{'action'} && $params{'action'} eq 'summary') {
+                       delete $params{'action'};
+               }
+       }
+
+       # now encode the parameters explicitly
        my @result = ();
        for (my $i = 0; $i < @mapping; $i += 2) {
                my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
@@ -393,7 +418,9 @@ (%)
                        push @result, $symbol . "=" . esc_param($params{$name});
                }
        }
-       return "$my_uri?" . join(';', @result);
+       $href .= "?" . join(';', @result) if scalar @result;
+
+       return $href;
 }
 
 
@@ -657,7 +684,7 @@ sub format_subject_html {
 
        if (length($short) < length($long)) {
                return $cgi->a({-href => $href, -class => "list subject",
-                               -title => $long},
+                               -title => decode("utf8", $long, Encode::FB_DEFAULT)},
                       esc_html($short) . $extra);
        } else {
                return $cgi->a({-href => $href, -class => "list subject"},
@@ -1665,9 +1692,9 @@ sub git_print_tree_entry {
                                      "history");
                }
                print " | " .
-                     $cgi->a({-href => href(action=>"blob_plain",
-                                            hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
-                             "raw");
+                       $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
+                                              file_name=>"$basedir$t->{'name'}")},
+                               "raw");
                print "</td>\n";
 
        } elsif ($t->{'type'} eq "tree") {
@@ -2013,9 +2040,9 @@ sub git_shortlog_body {
                                          href(action=>"commit", hash=>$commit), $ref);
                print "</td>\n" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
                      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
-                     $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
+                     $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . " | " .
+                     $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
                print "</td>\n" .
                      "</tr>\n";
        }
@@ -2064,9 +2091,8 @@ sub git_history_body {
                                          href(action=>"commit", hash=>$commit), $ref);
                print "</td>\n" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
-                     $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
-                     $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
+                     $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
+                     $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
 
                if ($ftype eq 'blob') {
                        my $blob_current = git_get_hash_by_path($hash_base, $file_name);
@@ -2653,7 +2679,7 @@ sub git_blob_plain {
        print $cgi->header(
                -type => "$type",
                -expires=>$expires,
-               -content_disposition => 'inline; filename="' . quotemeta($save_as) . '"');
+               -content_disposition => 'inline; filename="' . "$save_as" . '"');
        undef $/;
        binmode STDOUT, ':raw';
        print <$fd>;
@@ -2737,17 +2763,16 @@ sub git_blob {
 }
 
 sub git_tree {
-       my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
-       my $have_snapshot = (defined $ctype && defined $suffix);
+       my $have_snapshot = gitweb_have_snapshot();
 
+       if (!defined $hash_base) {
+               $hash_base = "HEAD";
+       }
        if (!defined $hash) {
-               $hash = git_get_head_hash($project);
                if (defined $file_name) {
-                       my $base = $hash_base || $hash;
-                       $hash = git_get_hash_by_path($base, $file_name, "tree");
-               }
-               if (!defined $hash_base) {
-                       $hash_base = $hash;
+                       $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
+               } else {
+                       $hash = $hash_base;
                }
        }
        $/ = "\0";
@@ -2814,7 +2839,6 @@ sub git_tree {
 }
 
 sub git_snapshot {
-
        my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
        my $have_snapshot = (defined $ctype && defined $suffix);
        if (!$have_snapshot) {
@@ -2830,7 +2854,7 @@ sub git_snapshot {
        print $cgi->header(
                -type => 'application/x-tar',
                -content_encoding => $ctype,
-               -content_disposition => 'inline; filename="' . quotemeta($filename) . '"',
+               -content_disposition => 'inline; filename="' . "$filename" . '"',
                -status => '200 OK');
 
        my $git_command = git_cmd_str();
@@ -2924,12 +2948,10 @@ sub git_commit {
        my $refs = git_get_references();
        my $ref = format_ref_marker($refs, $co{'id'});
 
-       my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
-       my $have_snapshot = (defined $ctype && defined $suffix);
+       my $have_snapshot = gitweb_have_snapshot();
 
        my @views_nav = ();
        if (defined $file_name && defined $co{'parent'}) {
-               my $parent = $co{'parent'};
                push @views_nav,
                        $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
                                "blame");
@@ -3141,7 +3163,7 @@ sub git_blobdiff {
                        -type => 'text/plain',
                        -charset => 'utf-8',
                        -expires => $expires,
-                       -content_disposition => 'inline; filename="' . quotemeta($file_name) . '.patch"');
+                       -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
 
                print "X-Git-Url: " . $cgi->self_url() . "\n\n";
 
@@ -3244,7 +3266,7 @@ sub git_commitdiff {
                        -type => 'text/plain',
                        -charset => 'utf-8',
                        -expires => $expires,
-                       -content_disposition => 'inline; filename="' . quotemeta($filename) . '"');
+                       -content_disposition => 'inline; filename="' . "$filename" . '"');
                my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
                print <<TEXT;
 From: $co{'author'}