Code

Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Feb 2012 08:14:17 +0000 (00:14 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Feb 2012 08:14:17 +0000 (00:14 -0800)
* maint:
  Update draft release notes to 1.7.9.2
  gitweb: Fix 'grep' search for multiple matches in file

1  2 
gitweb/gitweb.perl
t/t9500-gitweb-standalone-no-errors.sh

diff --combined gitweb/gitweb.perl
index 3fc7380a5ea510b705eb49542c3e698b0dddb02c,c876e0fb4e04cd339db0a6a4c15ae5f2570ac1c9..16d376075ea8bb47271aaeffebacf56fd41e713b
@@@ -760,7 -760,6 +760,7 @@@ our @cgi_param_mapping = 
        search_use_regexp => "sr",
        ctag => "by_tag",
        diff_style => "ds",
 +      project_filter => "pf",
        # this must be last entry (for manipulation from JavaScript)
        javascript => "js"
  );
@@@ -977,7 -976,7 +977,7 @@@ sub evaluate_path_info 
  
  our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
       $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
 -     $searchtext, $search_regexp);
 +     $searchtext, $search_regexp, $project_filter);
  sub evaluate_and_validate_params {
        our $action = $input_params{'action'};
        if (defined $action) {
                }
        }
  
 +      our $project_filter = $input_params{'project_filter'};
 +      if (defined $project_filter) {
 +              if (!validate_pathname($project_filter)) {
 +                      die_error(404, "Invalid project_filter parameter");
 +              }
 +      }
 +
        our $file_name = $input_params{'file_name'};
        if (defined $file_name) {
                if (!validate_pathname($file_name)) {
@@@ -1131,10 -1123,8 +1131,10 @@@ sub dispatch 
        if (!defined $action) {
                if (defined $hash) {
                        $action = git_get_type($hash);
 +                      $action or die_error(404, "Object does not exist");
                } elsif (defined $hash_base && defined $file_name) {
                        $action = git_get_type("$hash_base:$file_name");
 +                      $action or die_error(404, "File or directory does not exist");
                } elsif (defined $project) {
                        $action = 'summary';
                } else {
@@@ -2401,7 -2391,7 +2401,7 @@@ sub get_feed_info 
        return unless (defined $project);
        # some views should link to OPML, or to generic project feed,
        # or don't have specific feed yet (so they should use generic)
 -      return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
 +      return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);
  
        my $branch;
        # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
@@@ -2837,9 -2827,10 +2837,9 @@@ sub git_get_project_url_list 
  
  sub git_get_projects_list {
        my $filter = shift || '';
 +      my $paranoid = shift;
        my @list;
  
 -      $filter =~ s/\.git$//;
 -
        if (-d $projects_list) {
                # search in directory
                my $dir = $projects_list;
                my $pfxlen = length("$dir");
                my $pfxdepth = ($dir =~ tr!/!!);
                # when filtering, search only given subdirectory
 -              if ($filter) {
 +              if ($filter && !$paranoid) {
                        $dir .= "/$filter";
                        $dir =~ s!/+$!!;
                }
                                }
  
                                my $path = substr($File::Find::name, $pfxlen + 1);
 +                              # paranoidly only filter here
 +                              if ($paranoid && $filter && $path !~ m!^\Q$filter\E/!) {
 +                                      next;
 +                              }
                                # we check related file in $projectroot
                                if (check_export_ok("$projectroot/$path")) {
                                        push @list, { path => $path };
@@@ -3742,12 -3729,7 +3742,12 @@@ sub run_highlighter 
  sub get_page_title {
        my $title = to_utf8($site_name);
  
 -      return $title unless (defined $project);
 +      unless (defined $project) {
 +              if (defined $project_filter) {
 +                      $title .= " - projects in '" . esc_path($project_filter) . "'";
 +              }
 +              return $title;
 +      }
        $title .= " - " . to_utf8($project);
  
        return $title unless (defined $action);
@@@ -3841,27 -3823,12 +3841,27 @@@ sub print_header_links 
        }
  }
  
 +sub print_nav_breadcrumbs_path {
 +      my $dirprefix = undef;
 +      while (my $part = shift) {
 +              $dirprefix .= "/" if defined $dirprefix;
 +              $dirprefix .= $part;
 +              print $cgi->a({-href => href(project => undef,
 +                                           project_filter => $dirprefix,
 +                                           action => "project_list")},
 +                            esc_html($part)) . " / ";
 +      }
 +}
 +
  sub print_nav_breadcrumbs {
        my %opts = @_;
  
        print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
        if (defined $project) {
 -              print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
 +              my @dirname = split '/', $project;
 +              my $projectbasename = pop @dirname;
 +              print_nav_breadcrumbs_path(@dirname);
 +              print $cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename));
                if (defined $action) {
                        my $action_print = $action ;
                        if (defined $opts{-action_extra}) {
                        print " / $opts{-action_extra}";
                }
                print "\n";
 +      } elsif (defined $project_filter) {
 +              print_nav_breadcrumbs_path(split '/', $project_filter);
        }
  }
  
@@@ -3998,11 -3963,9 +3998,11 @@@ sub git_footer_html 
                }
  
        } else {
 -              print $cgi->a({-href => href(project=>undef, action=>"opml"),
 +              print $cgi->a({-href => href(project=>undef, action=>"opml",
 +                                           project_filter => $project_filter),
                              -class => $feed_class}, "OPML") . " ";
 -              print $cgi->a({-href => href(project=>undef, action=>"project_index"),
 +              print $cgi->a({-href => href(project=>undef, action=>"project_index",
 +                                           project_filter => $project_filter),
                              -class => $feed_class}, "TXT") . "\n";
        }
        print "</div>\n"; # class="page_footer"
@@@ -5160,34 -5123,6 +5160,34 @@@ sub git_patchset_body 
  
  # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  
 +sub git_project_search_form {
 +      my ($searchtext, $search_use_regexp);
 +
 +      my $limit = '';
 +      if ($project_filter) {
 +              $limit = " in '$project_filter/'";
 +      }
 +
 +      print "<div class=\"projsearch\">\n";
 +      print $cgi->startform(-method => 'get', -action => $my_uri) .
 +            $cgi->hidden(-name => 'a', -value => 'project_list')  . "\n";
 +      print $cgi->hidden(-name => 'pf', -value => $project_filter). "\n"
 +              if (defined $project_filter);
 +      print $cgi->textfield(-name => 's', -value => $searchtext,
 +                            -title => "Search project by name and description$limit",
 +                            -size => 60) . "\n" .
 +            "<span title=\"Extended regular expression\">" .
 +            $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
 +                           -checked => $search_use_regexp) .
 +            "</span>\n" .
 +            $cgi->submit(-name => 'btnS', -value => 'Search') .
 +            $cgi->end_form() . "\n" .
 +            $cgi->a({-href => href(project => undef, searchtext => undef,
 +                                   project_filter => $project_filter)},
 +                    esc_html("List all projects$limit")) . "<br />\n";
 +      print "</div>\n";
 +}
 +
  # fills project list info (age, description, owner, category, forks)
  # for each project in the list, removing invalid projects from
  # returned list
@@@ -5915,9 -5850,10 +5915,10 @@@ sub git_search_files 
        my $alternate = 1;
        my $matches = 0;
        my $lastfile = '';
+       my $file_href;
        while (my $line = <$fd>) {
                chomp $line;
-               my ($file, $file_href, $lno, $ltext, $binary);
+               my ($file, $lno, $ltext, $binary);
                last if ($matches++ > 1000);
                if ($line =~ /^Binary file (.+) matches$/) {
                        $file = $1;
@@@ -6044,7 -5980,7 +6045,7 @@@ sub git_project_list 
                die_error(400, "Unknown order parameter");
        }
  
 -      my @list = git_get_projects_list();
 +      my @list = git_get_projects_list($project_filter, $strict_export);
        if (!@list) {
                die_error(404, "No projects found");
        }
                insert_file($home_text);
                print "</div>\n";
        }
 -      print $cgi->startform(-method => "get") .
 -            "<p class=\"projsearch\">Search:\n" .
 -            $cgi->textfield(-name => "s", -value => $searchtext, -override => 1) . "\n" .
 -            "</p>" .
 -            $cgi->end_form() . "\n";
 +
 +      git_project_search_form($searchtext, $search_use_regexp);
        git_project_list_body(\@list, $order);
        git_footer_html();
  }
@@@ -6067,9 -6006,7 +6068,9 @@@ sub git_forks 
                die_error(400, "Unknown order parameter");
        }
  
 -      my @list = git_get_projects_list($project);
 +      my $filter = $project;
 +      $filter =~ s/\.git$//;
 +      my @list = git_get_projects_list($filter);
        if (!@list) {
                die_error(404, "No forks found");
        }
  }
  
  sub git_project_index {
 -      my @projects = git_get_projects_list();
 +      my @projects = git_get_projects_list($project_filter, $strict_export);
        if (!@projects) {
                die_error(404, "No projects found");
        }
@@@ -6128,9 -6065,7 +6129,9 @@@ sub git_summary 
  
        if ($check_forks) {
                # find forks of a project
 -              @forklist = git_get_projects_list($project);
 +              my $filter = $project;
 +              $filter =~ s/\.git$//;
 +              @forklist = git_get_projects_list($filter);
                # filter out forks of forks
                @forklist = filter_forks_from_projects_list(\@forklist)
                        if (@forklist);
@@@ -7921,7 -7856,7 +7922,7 @@@ sub git_atom 
  }
  
  sub git_opml {
 -      my @list = git_get_projects_list();
 +      my @list = git_get_projects_list($project_filter, $strict_export);
        if (!@list) {
                die_error(404, "No projects found");
        }
                -content_disposition => 'inline; filename="opml.xml"');
  
        my $title = esc_html($site_name);
 +      my $filter = " within subdirectory ";
 +      if (defined $project_filter) {
 +              $filter .= esc_html($project_filter);
 +      } else {
 +              $filter = "";
 +      }
        print <<XML;
  <?xml version="1.0" encoding="utf-8"?>
  <opml version="1.0">
  <head>
 -  <title>$title OPML Export</title>
 +  <title>$title OPML Export$filter</title>
  </head>
  <body>
  <outline text="git RSS feeds">
index 0f771c673d58009e2bcde45254d4b4e9fa68efb9,3e4fdbe5624f1d1a197b0a1a450524b6d1095b0b..40a1cb571e4a6ac285398054962c139a316d4306
@@@ -474,14 -474,6 +474,14 @@@ test_expect_success 
        'path_info: project/branch:dir/' \
        'gitweb_run "" "/.git/master:foo/"'
  
 +test_expect_success \
 +      'path_info: project/branch (non-existent)' \
 +      'gitweb_run "" "/.git/non-existent"'
 +
 +test_expect_success \
 +      'path_info: project/branch:filename (non-existent branch)' \
 +      'gitweb_run "" "/.git/non-existent:non-existent"'
 +
  test_expect_success \
        'path_info: project/branch:file (non-existent)' \
        'gitweb_run "" "/.git/master:non-existent"'
@@@ -637,6 -629,45 +637,45 @@@ test_expect_success 
        'config override: tree view, features enabled in repo config (2)' \
        'gitweb_run "p=.git;a=tree"'
  
+ # ----------------------------------------------------------------------
+ # searching
+ cat >>gitweb_config.perl <<\EOF
+ # enable search
+ $feature{'search'}{'default'} = [1];
+ $feature{'grep'}{'default'} = [1];
+ $feature{'pickaxe'}{'default'} = [1];
+ EOF
+ test_expect_success \
+       'search: preparation' \
+       'echo "1st MATCH" >>file &&
+        echo "2nd MATCH" >>file &&
+        echo "MATCH" >>bar &&
+        git add file bar &&
+        git commit -m "Added MATCH word"'
+ test_expect_success \
+       'search: commit author' \
+       'gitweb_run "p=.git;a=search;h=HEAD;st=author;s=A+U+Thor"'
+ test_expect_success \
+       'search: commit message' \
+       'gitweb_run "p=.git;a=search;h=HEAD;st=commitr;s=MATCH"'
+ test_expect_success \
+       'search: grep' \
+       'gitweb_run "p=.git;a=search;h=HEAD;st=grep;s=MATCH"'
+ test_expect_success \
+       'search: pickaxe' \
+       'gitweb_run "p=.git;a=search;h=HEAD;st=pickaxe;s=MATCH"'
+ test_expect_success \
+       'search: projects' \
+       'gitweb_run "a=project_list;s=.git"'
  # ----------------------------------------------------------------------
  # non-ASCII in README.html