]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: don't use pathinfo for global actions
[Gitweb] / gitweb.perl
index e9847469b36a70376e7904c5f1165913f9bb46e6218517d93a698cb4da77dc09..c579eff8a3782e8663b43c43c62af47f72e0350c6cb848c213cbf5db5c9dd719 100755 (executable)
@@ -508,6 +508,7 @@ our %actions = (
        "history" => \&git_history,
        "log" => \&git_log,
        "patch" => \&git_patch,
        "history" => \&git_history,
        "log" => \&git_log,
        "patch" => \&git_patch,
+       "patches" => \&git_patches,
        "rss" => \&git_rss,
        "atom" => \&git_atom,
        "search" => \&git_search,
        "rss" => \&git_rss,
        "atom" => \&git_atom,
        "search" => \&git_search,
@@ -834,7 +835,7 @@ sub href (%) {
        }
 
        my $use_pathinfo = gitweb_check_feature('pathinfo');
        }
 
        my $use_pathinfo = gitweb_check_feature('pathinfo');
-       if ($use_pathinfo) {
+       if ($use_pathinfo and defined $params{'project'}) {
                # try to put as many parameters as possible in PATH_INFO:
                #   - project name
                #   - action
                # try to put as many parameters as possible in PATH_INFO:
                #   - project name
                #   - action
@@ -849,7 +850,7 @@ sub href (%) {
                $href =~ s,/$,,;
 
                # Then add the project name, if present
                $href =~ s,/$,,;
 
                # Then add the project name, if present
-               $href .= "/".esc_url($params{'project'}) if defined $params{'project'};
+               $href .= "/".esc_url($params{'project'});
                delete $params{'project'};
 
                # since we destructively absorb parameters, we keep this
                delete $params{'project'};
 
                # since we destructively absorb parameters, we keep this
@@ -2151,8 +2152,9 @@ sub git_get_projects_list {
 
                                my $subdir = substr($File::Find::name, $pfxlen + 1);
                                # we check related file in $projectroot
 
                                my $subdir = substr($File::Find::name, $pfxlen + 1);
                                # we check related file in $projectroot
-                               if (check_export_ok("$projectroot/$filter/$subdir")) {
-                                       push @list, { path => ($filter ? "$filter/" : '') . $subdir };
+                               my $path = ($filter ? "$filter/" : '') . $subdir;
+                               if (check_export_ok("$projectroot/$path")) {
+                                       push @list, { path => $path };
                                        $File::Find::prune = 1;
                                }
                        },
                                        $File::Find::prune = 1;
                                }
                        },
@@ -5017,6 +5019,15 @@ sub git_log {
 
        my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
 
 
        my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
 
+       my ($patch_max) = gitweb_get_feature('patches');
+       if ($patch_max) {
+               if ($patch_max < 0 || @commitlist <= $patch_max) {
+                       $paging_nav .= " &sdot; " .
+                               $cgi->a({-href => href(action=>"patches", -replay=>1)},
+                                       "patches");
+               }
+       }
+
        git_header_html();
        git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
 
        git_header_html();
        git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
 
@@ -5096,6 +5107,11 @@ sub git_commit {
                        } @$parents ) .
                        ')';
        }
                        } @$parents ) .
                        ')';
        }
+       if (gitweb_check_feature('patches')) {
+               $formats_nav .= " | " .
+                       $cgi->a({-href => href(action=>"patch", -replay=>1)},
+                               "patch");
+       }
 
        if (!defined $parent) {
                $parent = "--root";
 
        if (!defined $parent) {
                $parent = "--root";
@@ -5372,11 +5388,11 @@ sub git_blobdiff_plain {
 }
 
 sub git_commitdiff {
 }
 
 sub git_commitdiff {
-       my $format = shift || 'html';
+       my %params = @_;
+       my $format = $params{-format} || 'html';
 
 
-       my $patch_max;
+       my ($patch_max) = gitweb_get_feature('patches');
        if ($format eq 'patch') {
        if ($format eq 'patch') {
-               ($patch_max) = gitweb_get_feature('patches');
                die_error(403, "Patch view not allowed") unless $patch_max;
        }
 
                die_error(403, "Patch view not allowed") unless $patch_max;
        }
 
@@ -5394,6 +5410,11 @@ sub git_commitdiff {
                $formats_nav =
                        $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
                                "raw");
                $formats_nav =
                        $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
                                "raw");
+               if ($patch_max) {
+                       $formats_nav .= " | " .
+                               $cgi->a({-href => href(action=>"patch", -replay=>1)},
+                                       "patch");
+               }
 
                if (defined $hash_parent &&
                    $hash_parent ne '-c' && $hash_parent ne '--cc') {
 
                if (defined $hash_parent &&
                    $hash_parent ne '-c' && $hash_parent ne '--cc') {
@@ -5489,7 +5510,15 @@ sub git_commitdiff {
                        }
                        push @commit_spec, '-n', "$hash_parent..$hash";
                } else {
                        }
                        push @commit_spec, '-n', "$hash_parent..$hash";
                } else {
-                       push @commit_spec, '-1', '--root', $hash;
+                       if ($params{-single}) {
+                               push @commit_spec, '-1';
+                       } else {
+                               if ($patch_max > 0) {
+                                       push @commit_spec, "-$patch_max";
+                               }
+                               push @commit_spec, "-n";
+                       }
+                       push @commit_spec, '--root', $hash;
                }
                open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
                        '--stdout', @commit_spec
                }
                open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
                        '--stdout', @commit_spec
@@ -5580,12 +5609,16 @@ sub git_commitdiff {
 }
 
 sub git_commitdiff_plain {
 }
 
 sub git_commitdiff_plain {
-       git_commitdiff('plain');
+       git_commitdiff(-format => 'plain');
 }
 
 # format-patch-style patches
 sub git_patch {
 }
 
 # format-patch-style patches
 sub git_patch {
-       git_commitdiff('patch');
+       git_commitdiff(-format => 'patch', -single=> 1);
+}
+
+sub git_patches {
+       git_commitdiff(-format => 'patch');
 }
 
 sub git_history {
 }
 
 sub git_history {
@@ -5938,6 +5971,14 @@ sub git_shortlog {
                        $cgi->a({-href => href(-replay=>1, page=>$page+1),
                                 -accesskey => "n", -title => "Alt-n"}, "next");
        }
                        $cgi->a({-href => href(-replay=>1, page=>$page+1),
                                 -accesskey => "n", -title => "Alt-n"}, "next");
        }
+       my $patch_max = gitweb_check_feature('patches');
+       if ($patch_max) {
+               if ($patch_max < 0 || @commitlist <= $patch_max) {
+                       $paging_nav .= " &sdot; " .
+                               $cgi->a({-href => href(action=>"patches", -replay=>1)},
+                                       "patches");
+               }
+       }
 
        git_header_html();
        git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
 
        git_header_html();
        git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
@@ -6206,8 +6247,8 @@ XML
                }
 
                my $path = esc_html(chop_str($proj{'path'}, 25, 5));
                }
 
                my $path = esc_html(chop_str($proj{'path'}, 25, 5));
-               my $rss  = "$my_url?p=$proj{'path'};a=rss";
-               my $html = "$my_url?p=$proj{'path'};a=summary";
+               my $rss  = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
+               my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
                print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
        }
        print <<XML;
                print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
        }
        print <<XML;
This page took 0.286162 seconds and 4 git commands to generate.