gitweb: There can be empty patches (in git_patchset_body)
[gitweb.git] / gitweb / gitweb.perl
index f9994d941740107855dc49b7276619193dd20a90..2ead917a9401cddecc5335c72fc0cf4233a3c4d5 100755 (executable)
 use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
 
+BEGIN {
+       CGI->compile() if $ENV{MOD_PERL};
+}
+
 our $cgi = new CGI;
 our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
@@ -1271,7 +1275,7 @@ sub parse_tag {
 }
 
 sub parse_commit_text {
-       my ($commit_text) = @_;
+       my ($commit_text, $withparents) = @_;
        my @commit_lines = split '\n', $commit_text;
        my %co;
 
@@ -1281,13 +1285,12 @@ sub parse_commit_text {
        if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
                return;
        }
-       $co{'id'} = $header;
-       my @parents;
+       ($co{'id'}, my @parents) = split ' ', $header;
        while (my $line = shift @commit_lines) {
                last if $line eq "\n";
                if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
                        $co{'tree'} = $1;
-               } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
+               } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
                        push @parents, $1;
                } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
                        $co{'author'} = $1;
@@ -1373,12 +1376,13 @@ sub parse_commit {
        local $/ = "\0";
 
        open my $fd, "-|", git_cmd(), "rev-list",
+               "--parents",
                "--header",
                "--max-count=1",
                $commit_id,
                "--",
                or die_error(undef, "Open git-rev-list failed");
-       %co = parse_commit_text(<$fd>);
+       %co = parse_commit_text(<$fd>, 1);
        close $fd;
 
        return %co;
@@ -1391,35 +1395,13 @@ sub parse_commits {
        $maxcount ||= 1;
        $skip ||= 0;
 
-       # Delete once rev-list supports the --skip option
-       if ($skip > 0) {
-               open my $fd, "-|", git_cmd(), "rev-list",
-                       ($arg ? ($arg) : ()),
-                       ("--max-count=" . ($maxcount + $skip)),
-                       $commit_id,
-                       "--",
-                       ($filename ? ($filename) : ())
-                       or die_error(undef, "Open git-rev-list failed");
-               while (my $line = <$fd>) {
-                       if ($skip-- <= 0) {
-                               chomp $line;
-                               my %co = parse_commit($line);
-                               push @cos, \%co;
-                       }
-               }
-               close $fd;
-
-               return wantarray ? @cos : \@cos;
-       }
-
        local $/ = "\0";
 
        open my $fd, "-|", git_cmd(), "rev-list",
                "--header",
                ($arg ? ($arg) : ()),
                ("--max-count=" . $maxcount),
-               # Add once rev-list supports the --skip option
-               # ("--skip=" . $skip),
+               ("--skip=" . $skip),
                $commit_id,
                "--",
                ($filename ? ($filename) : ())
@@ -1733,6 +1715,7 @@ sub git_header_html {
        }
        print $cgi->header(-type=>$content_type, -charset => 'utf-8',
                           -status=> $status, -expires => $expires);
+       my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
        print <<EOF;
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -1741,7 +1724,7 @@ sub git_header_html {
 <!-- git core binaries version $git_version -->
 <head>
 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
-<meta name="generator" content="gitweb/$version git/$git_version"/>
+<meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
 <meta name="robots" content="index, nofollow"/>
 <title>$title</title>
 EOF
@@ -2291,7 +2274,7 @@ sub git_difftree_body {
                        my $mode_chnge = "";
                        if ($diff{'from_mode'} != $diff{'to_mode'}) {
                                $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
-                               if ($from_file_type != $to_file_type) {
+                               if ($from_file_type ne $to_file_type) {
                                        $mode_chnge .= " from $from_file_type to $to_file_type";
                                }
                                if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
@@ -2544,7 +2527,7 @@ sub git_patchset_body {
                print "<div class=\"diff from_file\">$patch_line</div>\n";
 
                $patch_line = <$fd>;
-               #last PATCH unless $patch_line;
+               last PATCH unless $patch_line;
                chomp $patch_line;
 
                #assert($patch_line =~ m/^+++/) if DEBUG;
@@ -3012,7 +2995,7 @@ sub git_project_index {
 
        foreach my $pr (@projects) {
                if (!exists $pr->{'owner'}) {
-                       $pr->{'owner'} = get_file_owner("$projectroot/$project");
+                       $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}");
                }
 
                my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});