]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Better processing format string in custom links in navbar
[Gitweb] / gitweb.perl
index 66596b57f57deecd851690d49a00ebae5815e34b3a86d7af79dcf7aa7028b460..b580067a3c6a76f935304223dd3fff1b7bc381ffbd0d31e65a3fdc2af0f34796 100755 (executable)
@@ -291,10 +291,10 @@ our %feature = (
 
        # The 'default' value consists of a list of triplets in the form
        # (label, link, position) where position is the label after which
-       # to inster the link and link is a format string where %n expands
+       # to insert the link and link is a format string where %n expands
        # to the project name, %f to the project path within the filesystem,
        # %h to the current hash (h gitweb parameter) and %b to the current
-       # hash base (hb gitweb parameter).
+       # hash base (hb gitweb parameter); %% expands to %.
 
        # To enable system wide have in $GITWEB_CONFIG e.g.
        # $feature{'actions'}{'default'} = [('graphiclog',
@@ -2867,14 +2867,19 @@ sub git_print_page_nav {
        $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
 
        my @actions = gitweb_check_feature('actions');
+       my %repl = (
+               '%' => '%',
+               'n' => $project,         # project name
+               'f' => $git_dir,         # project path within filesystem
+               'h' => $treehead || '',  # current hash ('h' parameter)
+               'b' => $treebase || '',  # hash base ('hb' parameter)
+       );
        while (@actions) {
-               my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
+               my ($label, $link, $pos) = splice(@actions,0,3);
+               # insert
                @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
                # munch munch
-               $link =~ s#%n#$project#g;
-               $link =~ s#%f#$git_dir#g;
-               $treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;
-               $treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;
+               $link =~ s/%([%nfhb])/$repl{$1}/g;
                $arg{$label}{'_href'} = $link;
        }
 
@@ -3796,11 +3801,14 @@ sub git_project_list_body {
                my $pr = $projects[$i];
 
                next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
-               # Weed out forks
+               next if $searchtext and not $pr->{'path'} =~ /$searchtext/
+                       and not $pr->{'descr_long'} =~ /$searchtext/;
+               # Weed out forks or non-matching entries of search
                if ($check_forks) {
                        my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#;
                        $forkbase="^$forkbase" if $forkbase;
-                       next if not $tagfilter and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
+                       next if not $searchtext and not $tagfilter and $show_ctags
+                               and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
                }
 
                if ($alternate) {
@@ -4137,6 +4145,11 @@ sub git_project_list {
                close $fd;
                print "</div>\n";
        }
+       print $cgi->startform(-method => "get") .
+             "<p class=\"projsearch\">Search:\n" .
+             $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
+             "</p>" .
+             $cgi->end_form() . "\n";
        git_project_list_body(\@list, $order);
        git_footer_html();
 }
This page took 0.216316 seconds and 4 git commands to generate.