]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.pl
v021
[Gitweb] / gitweb.pl
index 94df76535ded53b6fc1afff7ea971acf6a06d67d858568537a1307c312a54e29..c52c549b6622dade7dc6356d836ff45b1856744473131ee2222ac9e6c9c7a003 100755 (executable)
--- a/gitweb.pl
+++ b/gitweb.pl
@@ -90,7 +90,7 @@ $project =~ s#\/\.+##g;
 
 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
 
-sub git_header {
+sub git_header_html {
        print $cgi->header(-type => 'text/html; charset: utf-8');
 print <<EOF;
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -109,7 +109,7 @@ print <<EOF;
                div.head2 a:visited { color:#0000cc; }
                div.head2 a:hover { color:#880000; }
                div.head2 a:active { color:#880000; }
-               div.shortlog { padding:8px; background-color: #D9D8D1; font-weight:bold; }
+               div.title { padding:8px; background-color: #D9D8D1; font-weight:bold; }
                table { padding:0px; margin:0px; width:100%; }
                tr { vertical-align:top; }
                td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
@@ -144,11 +144,50 @@ EOF
        print "</div>\n";
 }
 
-sub git_footer {
+sub git_footer_html {
        print "</div>";
        print $cgi->end_html();
 }
 
+sub git_head {
+       open my $fd, "$projectroot/$project/.git/HEAD";
+       my $head = <$fd>;
+       close $fd;
+       chomp $head;
+       return $head;
+}
+
+sub git_commit {
+       my $commit = shift;
+       my %co;
+       my @parents;
+
+       open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
+       while (my $line = <$fd>) {
+               chomp($line);
+               last if $line eq "";
+               if ($line =~ m/^tree (.*)$/) {
+                       $co{'tree'} = $1;
+               } elsif ($line =~ m/^parent (.*)$/) {
+                       push @parents, $1;
+               } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
+                       $co{'committer'} = $1;
+                       $co{'committer_time'} = $2;
+                       $co{'committer_timezone'} = $3;
+               } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
+                       $co{'author'} = $1;
+                       $co{'author_time'} = $2;
+                       $co{'author_timezone'} = $3;
+               }
+       }
+       $co{'parents'} = \@parents;
+       my (@comment) = map { chomp; $_ } <$fd>;
+       $co{'comment'} = \@comment;
+       $co{'title'} = $comment[0];
+       close $fd;
+       return %co;
+}
+
 sub git_diff {
        my $old_name = shift || "/dev/null";
        my $new_name = shift || "/dev/null";
@@ -217,7 +256,7 @@ if ($project eq "") {
        opendir(my $fd, "$projectroot/$defaultprojects");
        my (@path) = grep(!/^\./, readdir($fd));
        closedir($fd);
-       git_header();
+       git_header_html();
        print "<div class=\"head2\">\n";
        print "<br/><br/>\n";
        foreach my $line (@path) {
@@ -226,12 +265,12 @@ if ($project eq "") {
                }
        }
        print "</div><br/>";
-       git_footer();
+       git_footer_html();
        exit;
 }
 
 if ($action eq "blob") {
-       git_header();
+       git_header_html();
        print "<br/><br/>\n";
        print "<pre>\n";
        open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
@@ -243,19 +282,15 @@ if ($action eq "blob") {
        close $fd;
        print "</pre>\n";
        print "<br/>";
-       git_footer();
+       git_footer_html();
 } elsif ($action eq "tree") {
        if ($hash eq "") {
-               open my $fd, "$projectroot/$project/.git/HEAD";
-               my $head = <$fd>;
-               chomp $head;
-               close $fd;
-               $hash = $head;
+               $hash = git_head();
        }
        open my $fd, "-|", "$gitbin/ls-tree", $hash;
        my (@entries) = map { chomp; $_ } <$fd>;
        close $fd;
-       git_header();
+       git_header_html();
        print "<br/><br/>\n";
        print "<pre>\n";
        foreach my $line (@entries) {
@@ -272,18 +307,14 @@ if ($action eq "blob") {
        }
        print "</pre>\n";
        print "<br/>";
-       git_footer();
+       git_footer_html();
 } elsif ($action eq "log" || $action eq "rss") {
-       open my $fd, "$projectroot/$project/.git/HEAD";
-       my $head = <$fd>;
-       chomp $head;
-       close $fd;
-       open $fd, "-|", "$gitbin/rev-tree", $head;
+       open my $fd, "-|", "$gitbin/rev-tree", git_head();
        my (@revtree) = reverse sort map { chomp; $_ } <$fd>;
        close $fd;
 
        if ($action eq "log") {
-               git_header();
+               git_header_html();
                print "<div class=\"head2\">\n";
                print "view  ";
                print $cgi->a({-href => "$myself/$project/log"}, "last day") . " | ";
@@ -313,45 +344,9 @@ if ($action eq "blob") {
                my $time = $1;
                my $commit = $2;
                my $parent = $3;
-               my @parents;
-               my ($author, $author_time, $author_timezone);
-               my ($committer, $committer_time, $committer_timezone);
-               my $tree;
-               my $comment;
-               my $shortlog;
-               open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
-               while (my $line = <$fd>) {
-                       chomp($line);
-                       last if $line eq "";
-                       if ($line =~ m/^tree (.*)$/) {
-                               $tree = $1;
-                       } elsif ($line =~ m/^parent (.*)$/) {
-                               push @parents, $1;
-                       } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
-                               $committer = $1;
-                               $committer_time = $2;
-                               $committer_timezone = $3;
-                       } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
-                               $author = $1;
-                               $author_time = $2;
-                               $author_timezone = $3;
-                       }
-               }
-               $shortlog = <$fd>;
-               chomp($shortlog);
-               $shortlog = escapeHTML($shortlog);
-               $comment = $shortlog . "<br/>";
-               while (my $line = <$fd>) {
-                               chomp($line);
-                               if ($line =~ m/signed-off-by:/i) {
-                                       $comment .= '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
-                               } else {
-                                       $comment .= escapeHTML($line) . "<br/>\n";
-                               }
-               }
-               close $fd;
 
-               my $age = time-$committer_time;
+               my %co = git_commit($commit);
+               my $age = time - $co{'committer_time'};
                my $age_string;
                if ($age > 60*60*24*365*2) {
                        $age_string = int $age/60/60/24/365;
@@ -383,20 +378,21 @@ if ($action eq "blob") {
                        }
                        print "<tr>\n";
                        print "<td class=\"head1\">" . $age_string . "</td>\n";
-                       print "<td class=\"head1\">" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $shortlog) . "</td>";
+                       print "<td class=\"head1\">" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $co{'title'}) . "</td>";
                        print "</tr>\n";
                        print "<tr>\n";
                        print "<td class=\"head3\">";
                        print $cgi->a({-href => "$myself/$project/commitdiff/$commit"}, "view diff") . "<br/>\n";
                        print $cgi->a({-href => "$myself/$project/commit/$commit"}, "view commit") . "<br/>\n";
-                       print $cgi->a({-href => "$myself/$project/tree/$tree"}, "view tree") . "<br/>\n";
+                       print $cgi->a({-href => "$myself/$project/tree/$co{'tree'}"}, "view tree") . "<br/>\n";
                        print "</td>\n";
                        print "<td class=\"head2\">\n";
-                       print "author &nbsp; &nbsp;" . escapeHTML($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]<br/>\n";
-                       print "committer " . escapeHTML($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]<br/>\n";
+                       print "author &nbsp; &nbsp;" . escapeHTML($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
+                       print "committer " . escapeHTML($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
                        print "commit &nbsp; &nbsp;$commit<br/>\n";
-                       print "tree &nbsp; &nbsp; &nbsp;$tree<br/>\n";
-                       foreach my $par (@parents) {
+                       print "tree &nbsp; &nbsp; &nbsp;$co{'tree'}<br/>\n";
+                       my $parents  = $co{'parents'};
+                       foreach my $par (@$parents) {
                                print "parent &nbsp; &nbsp;$par<br/>\n";
                        }
                        print "</td>";
@@ -404,20 +400,27 @@ if ($action eq "blob") {
                        print "<tr>\n";
                        print "<td></td>\n";
                        print "<td>\n";
-                       print "$comment<br/><br/>\n";
+                       my $comment = $co{'comment'};
+                       foreach my $line (@$comment) {
+                               if ($line =~ m/signed-off-by:/i) {
+                                       print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
+                               } else {
+                                       print escapeHTML($line) . "<br/>\n";
+                               }
+                       }
+                       print "<br/><br/>\n";
                        print "</td>";
                        print "</tr>\n";
                } elsif ($action eq "rss") {
-                       if ($i < 12) {
-                               print "<item>\n\t<title>$age_string: $shortlog</title>\n";
-                               print "\t<link> " . $cgi->url() . "/$project/commit/$commit</link>\n";
-                               print "</item>\n";
-                       }
+                       last if ($i >= 12);
+                       print "<item>\n\t<title>$age_string: " . escapeHTML($co{'title'}) . "</title>\n";
+                       print "\t<link> " . $cgi->url() . "/$project/commit/$commit</link>\n";
+                       print "</item>\n";
                }
        }
        if ($action eq "log") {
                print "</table>\n";
-               git_footer();
+               git_footer_html();
        } elsif ($action eq "rss") {
                print "</channel></rss>";
        }
@@ -431,18 +434,18 @@ if ($action eq "blob") {
                        $parent = $1;
                }
        }
-       my $shortlog = <$fd>;
-       $shortlog = escapeHTML($shortlog);
+       my $title = <$fd>;
+       $title = escapeHTML($title);
        close $fd;
 
        open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
        my (@difftree) = map { chomp; $_ } <$fd>;
        close $fd;
 
-       git_header();
+       git_header_html();
        print "<div class=\"head2\">\n";
        print "view " . $cgi->a({-href => "$myself/$project/commitdiff/$hash"}, "diff") . "</div><br/><br/>\n";
-       print "<div class=\"shortlog\">$shortlog<br/></div>\n";
+       print "<div class=\"title\">$title<br/></div>\n";
        print "<pre>\n";
        foreach my $line (@difftree) {
                # '*100644->100644      blob    9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596      net/ipv4/route.c'
@@ -468,15 +471,15 @@ if ($action eq "blob") {
        }
        print "</pre>\n";
        print "<br/>";
-       git_footer();
+       git_footer_html();
 } elsif ($action eq "blobdiff") {
-       git_header();
+       git_header_html();
        print "<br/><br/>\n";
        print "<pre>\n";
        git_diff($hash, $hash_parent, $hash, $hash_parent);
        print "</pre>\n";
        print "<br/>";
-       git_footer();
+       git_footer_html();
 } elsif ($action eq "commitdiff") {
        my $parent = "";
        open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
@@ -487,18 +490,18 @@ if ($action eq "blob") {
                        $parent = $1;
                }
        }
-       my $shortlog = <$fd>;
-       $shortlog = escapeHTML($shortlog);
+       my $title = <$fd>;
+       $title = escapeHTML($title);
        close $fd;
 
        open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
        my (@difftree) = map { chomp; $_ } <$fd>;
        close $fd;
 
-       git_header();
+       git_header_html();
        print "<div class=\"head2\">\n";
        print "view " . $cgi->a({-href => "$myself/$project/commit/$hash"}, "commit") . "</div><br/><br/>\n";
-       print "<div class=\"shortlog\">$shortlog<br/></div>\n";
+       print "<div class=\"title\">$title<br/></div>\n";
        print "<pre>\n";
        foreach my $line (@difftree) {
                # '*100644->100644      blob    8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154      Makefile'
@@ -521,5 +524,5 @@ if ($action eq "blob") {
        }
        print "</pre>\n";
        print "<br/>";
-       git_footer();
+       git_footer_html();
 }
This page took 0.285047 seconds and 4 git commands to generate.