]> asedeno.scripts.mit.edu Git - git.git/blobdiff - gitweb/gitweb.perl
gitweb: Silence 'Variable VAR may be unavailable' warnings
[git.git] / gitweb / gitweb.perl
index 077eb2f4ca3b597c155a464567f0235a129daa50..64eaa759966c5992c5c2ab6f8e663e109a0e2cc8 100755 (executable)
@@ -35,6 +35,10 @@ our $GIT = "++GIT_BINDIR++/git";
 #our $projectroot = "/pub/scm";
 our $projectroot = "++GITWEB_PROJECTROOT++";
 
+# fs traversing limit for getting project list
+# the number is relative to the projectroot
+our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
+
 # target of the home link on top of all pages
 our $home_link = $my_uri || "/";
 
@@ -471,9 +475,6 @@ if (defined $searchtype) {
 our $searchtext = $cgi->param('s');
 our $search_regexp;
 if (defined $searchtext) {
-       if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
-               die_error(undef, "Invalid search parameter");
-       }
        if (length($searchtext) < 2) {
                die_error(undef, "At least two characters are required for search parameter");
        }
@@ -1512,16 +1513,25 @@ sub git_get_projects_list {
                # remove the trailing "/"
                $dir =~ s!/+$!!;
                my $pfxlen = length("$dir");
+               my $pfxdepth = ($dir =~ tr!/!!);
 
                File::Find::find({
                        follow_fast => 1, # follow symbolic links
                        follow_skip => 2, # ignore duplicates
                        dangling_symlinks => 0, # ignore dangling symlinks, silently
                        wanted => sub {
+                               # global variables
+                               our $project_maxdepth;
+                               our $projectroot;
                                # skip project-list toplevel, if we get it.
                                return if (m!^[/.]$!);
                                # only directories can be git repositories
                                return unless (-d $_);
+                               # don't traverse too deep (Find is super slow on os x)
+                               if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
+                                       $File::Find::prune = 1;
+                                       return;
+                               }
 
                                my $subdir = substr($File::Find::name, $pfxlen + 1);
                                # we check related file in $projectroot
@@ -2812,7 +2822,7 @@ sub git_difftree_body {
              "diff_tree\">\n";
 
        # header only for combined diff in 'commitdiff' view
-       my $has_header = @parents > 1 && $action eq 'commitdiff';
+       my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
        if ($has_header) {
                # table header
                print "<thead><tr>\n" .
@@ -3194,44 +3204,10 @@ sub git_patchset_body {
                                }
                        } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
                                 $patch_idx > $#$difftree);
+
                        # modifies %from, %to hashes
                        parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
-                       if ($diffinfo->{'nparents'}) {
-                               # combined diff
-                               $from{'file'} = [];
-                               $from{'href'} = [];
-                               fill_from_file_info($diffinfo, @hash_parents)
-                                       unless exists $diffinfo->{'from_file'};
-                               for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
-                                       $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
-                                       if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
-                                               $from{'href'}[$i] = href(action=>"blob",
-                                                                        hash_base=>$hash_parents[$i],
-                                                                        hash=>$diffinfo->{'from_id'}[$i],
-                                                                        file_name=>$from{'file'}[$i]);
-                                       } else {
-                                               $from{'href'}[$i] = undef;
-                                       }
-                               }
-                       } else {
-                               $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
-                               if ($diffinfo->{'status'} ne "A") { # not new (added) file
-                                       $from{'href'} = href(action=>"blob", hash_base=>$hash_parent,
-                                                            hash=>$diffinfo->{'from_id'},
-                                                            file_name=>$from{'file'});
-                               } else {
-                                       delete $from{'href'};
-                               }
-                       }
 
-                       $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
-                       if (!is_deleted($diffinfo)) { # file exists in result
-                               $to{'href'} = href(action=>"blob", hash_base=>$hash,
-                                                  hash=>$diffinfo->{'to_id'},
-                                                  file_name=>$to{'file'});
-                       } else {
-                               delete $to{'href'};
-                       }
                        # this is first patch for raw difftree line with $patch_idx index
                        # we index @$difftree array from 0, but number patches from 1
                        print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
@@ -3422,7 +3398,7 @@ sub git_project_list_body {
                      "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
                                        -class => "list", -title => $pr->{'descr_long'}},
                                        esc_html($pr->{'descr'})) . "</td>\n" .
-                     "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
+                     "<td><i>" . esc_html(chop_str($pr->{'owner'}, 15)) . "</i></td>\n";
                print "<td class=\"". age_class($pr->{'age'}) . "\">" .
                      (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
                      "<td class=\"link\">" .
@@ -3798,7 +3774,7 @@ sub git_summary {
        print "<div class=\"title\">&nbsp;</div>\n";
        print "<table cellspacing=\"0\">\n" .
              "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
-             "<tr><td>owner</td><td>$owner</td></tr>\n";
+             "<tr><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
        if (defined $cd{'rfc2822'}) {
                print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
        }
@@ -5366,7 +5342,7 @@ sub git_feed {
 
        # log/feed of current (HEAD) branch, log of given branch, history of file/directory
        my $head = $hash || 'HEAD';
-       my @commitlist = parse_commits($head, 150);
+       my @commitlist = parse_commits($head, 150, 0, undef, $file_name);
 
        my %latest_commit;
        my %latest_date;