]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.pl
v031
[Gitweb] / gitweb.pl
index 8aa6fdada256c44bf4855883e4252887416c995f57cad2dd684e19c6c00f2bdd..7820d7dfedd38868c912cb0887a23e93a455393d7e66b7fdd95b376ffc7c96a3 100755 (executable)
--- a/gitweb.pl
+++ b/gitweb.pl
@@ -2,7 +2,7 @@
 
 # gitweb.pl - simple web interface to track changes in git repositories
 #
-# Version 025
+# Version 031
 #
 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
 # (C) 2005, Christian Gierke <ch@gierke.de>
@@ -32,40 +32,40 @@ my $hash_parent = "";
 my $view_back = 1;
 
 # get values from url
-if ($my_url_parm =~ m#/(.+)/commit/([0-9a-fA-F]+)$#) {
+if ($my_url_parm =~ m#/+(.+)/+commit/+([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "commit";
        $hash = $2;
-} elsif ($my_url_parm =~ m#/(.+)/commitdiff/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/+commitdiff/+([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "commitdiff";
        $hash = $2;
-} elsif ($my_url_parm =~ m#/(.+)/blobdiff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/+blobdiff/+([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "blobdiff";
        $hash = $2;
        $hash_parent = $3;
-} elsif ($my_url_parm =~ m#/(.+)/blob/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/+blob/+([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "blob";
        $hash = $2;
-} elsif ($my_url_parm =~ m#/(.+)/tree/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/+tree/+([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "tree";
        $hash = $2;
-} elsif ($my_url_parm =~ m#/(.+)/log/([0-9]+)$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/+log/+([0-9]+)$#) {
        $project = $1;
        $action = "log";
        $view_back = $2;
-} elsif ($my_url_parm =~ m#/(.+)/log$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/+log$#) {
        $project = $1;
        $action = "log";
        $view_back = 1;
-} elsif ($my_url_parm =~ m#/(.+)/rss$#) {
+} elsif ($my_url_parm =~ m#/+(.+)/rss$#) {
        $project = $1;
        $action = "rss";
        $view_back = 1;
-} elsif ($my_url_parm =~ m#/git-logo.png$#) {
+} elsif ($my_url_parm =~ m#/+git-logo.png$#) {
        print $cgi->header(-type => 'image/png', -expires => '+1d');
        print   "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
                "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
@@ -151,8 +151,8 @@ EOF
 }
 
 sub git_footer_html {
-       print "</div>";
-       print $cgi->end_html();
+       print "</div>\n";
+       print "</body>\n</html>";
 }
 
 sub git_head {
@@ -195,55 +195,54 @@ sub git_commit {
        return %co;
 }
 
-sub git_diff {
-       my $old_name = shift || "/dev/null";
-       my $new_name = shift || "/dev/null";
-       my $old = shift;
-       my $new = shift;
+sub git_diff_html {
+       my $from_name = shift || "/dev/null";
+       my $to_name = shift || "/dev/null";
+       my $from = shift;
+       my $to = shift;
 
-       my $tmp_old = "/dev/null";
-       my $tmp_new = "/dev/null";
-       my $old_label = "/dev/null";
-       my $new_label = "/dev/null";
+       my $from_tmp = "/dev/null";
+       my $to_tmp = "/dev/null";
+       my $from_label = "/dev/null";
+       my $to_label = "/dev/null";
+       my $pid = $$;
 
        # create temp from-file
-       if ($old ne "") {
-               open my $fd2, "> $gittmp/$old";
-               open my $fd, "-|", "$gitbin/cat-file", "blob", $old;
-               while (my $line = <$fd>) {
-                       print $fd2 $line;
-               }
+       if ($from ne "") {
+               $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
+               open my $fd2, "> $from_tmp";
+               open my $fd, "-|", "$gitbin/cat-file", "blob", $from;
+               my @file = <$fd>;
+               print $fd2 @file;
                close $fd2;
                close $fd;
-               $tmp_old = "$gittmp/$old";
-               $old_label = "a/$old_name";
+               $from_label = "a/$from_name";
        }
 
        # create tmp to-file
-       if ($new ne "") {
-               open my $fd2, "> $gittmp/$new";
-               open my $fd, "-|", "$gitbin/cat-file", "blob", $new;
-               while (my $line = <$fd>) {
-                       print $fd2 $line;
-               }
+       if ($to ne "") {
+               $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
+               open my $fd2, "> $to_tmp";
+               open my $fd, "-|", "$gitbin/cat-file", "blob", $to;
+               my @file = <$fd>;
+               print $fd2 @file;
                close $fd2;
                close $fd;
-               $tmp_new = "$gittmp/$new";
-               $new_label = "b/$new_name";
+               $to_label = "b/$to_name";
        }
 
-       open my $fd, "-|", "/usr/bin/diff", "-L", $old_label, "-L", $new_label, "-u", "-p", $tmp_old, $tmp_new;
+       open my $fd, "-|", "/usr/bin/diff", "-L", $from_label, "-L", $to_label, "-u", "-p", $from_tmp, $to_tmp;
        print "<span style =\"color: #000099;\">===== ";
-       if ($old ne "") {
-               print $cgi->a({-href => "$my_uri/$project/blob/$old"}, $old);
+       if ($from ne "") {
+               print $cgi->a({-href => "$my_uri/$project/blob/$from"}, $from);
        } else {
-               print $old_name;
+               print $from_name;
        }
        print " vs ";
-       if ($new ne "") {
-               print $cgi->a({-href => "$my_uri/$project/blob/$new"}, $new);
+       if ($to ne "") {
+               print $cgi->a({-href => "$my_uri/$project/blob/$to"}, $to);
        } else {
-               print $new_name;
+               print $to_name;
        }
        print " =====</span>\n";
        while (my $line = <$fd>) {
@@ -255,10 +254,29 @@ sub git_diff {
                print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
        }
        close $fd;
-       unlink("$gittmp/$new");
-       unlink("$gittmp/$old");
+
+       if ($from ne "") {
+               unlink("$from_tmp");
+       }
+       if ($to ne "") {
+               unlink("$to_tmp");
+       }
+}
+
+sub mode_str {
+       my $perms = oct shift;
+       my $modestr;
+       if ($perms & 040000) { $modestr .= 'd' } else { $modestr .= '-' };
+       for (my $i = 0; $i < 3; $i++) {
+               if ($perms & 0400) { $modestr .= 'r' } else { $modestr .= '-' };
+               if ($perms & 0200) { $modestr .= 'w' } else { $modestr .= '-' };
+               if ($perms & 0100) { $modestr .= 'x' } else { $modestr .= '-' };
+               $perms <<= 3;
+       }
+       return $modestr;
 }
 
+# show list of default projects
 if ($project eq "") {
        opendir(my $fd, "$projectroot/$defaultprojects");
        my (@path) = grep(!/^\./, readdir($fd));
@@ -303,21 +321,22 @@ if ($action eq "blob") {
        foreach my $line (@entries) {
                #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
                $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
+               my $t_mode = $1;
                my $t_type = $2;
                my $t_hash = $3;
                my $t_name = $4;
                if ($t_type eq "blob") {
-                       print "BLOB\t" . $cgi->a({-href => "$my_uri/$project/blob/$3"}, $4) . "\n";
+                       print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri/$project/blob/$t_hash"}, $t_name) . "\n";
                } elsif ($t_type eq "tree") {
-                       print "TREE\t" . $cgi->a({-href => "$my_uri/$project/tree/$3"}, $4) . "\n";
+                       print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri/$project/tree/$t_hash"}, $t_name) . "\n";
                }
        }
        print "</pre>\n";
        print "<br/>";
        git_footer_html();
 } elsif ($action eq "log" || $action eq "rss") {
-       open my $fd, "-|", "$gitbin/rev-tree", git_head();
-       my (@revtree) = reverse sort map { chomp; $_ } <$fd>;
+       open my $fd, "-|", "$gitbin/rev-list", git_head();
+       my (@revtree) = map { chomp; $_ } <$fd>;
        close $fd;
 
        if ($action eq "log") {
@@ -344,12 +363,7 @@ if ($action eq "blob") {
        }
 
        for (my $i = 0; $i <= $#revtree; $i++) {
-               my $rev = $revtree[$i];
-               # '1114106118 755e3010ee10dadf42a8a80770e1b115fb038d9b:1 2af17b4854036a1c2ec6c101d93c8dd1ed80d24e:1'
-               last if !($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/);
-               my $time = $1;
-               my $commit = $2;
-               my $parent = $3;
+               my $commit = $revtree[$i];
 
                my %co = git_commit($commit);
                my $age = time - $co{'committer_time'};
@@ -401,7 +415,7 @@ if ($action eq "blob") {
                        print "<td>\n";
                        my $comment = $co{'comment'};
                        foreach my $line (@$comment) {
-                               if ($line =~ m/signed-off-by:/i) {
+                               if ($line =~ m/^(signed-off|acked)-by:/i) {
                                        print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
                                } else {
                                        print escapeHTML($line) . "<br/>\n";
@@ -462,7 +476,7 @@ if ($action eq "blob") {
        print "<td>\n";
        my $comment = $co{'comment'};
        foreach my $line (@$comment) {
-               if ($line =~ m/signed-off-by:/i) {
+               if ($line =~ m/(signed-off|acked)-by:/i) {
                        print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
                } else {
                        print escapeHTML($line) . "<br/>\n";
@@ -483,16 +497,18 @@ if ($action eq "blob") {
                my $type = $3;
                my $id = $4;
                my $file = $5;
+               $mode =~ m/^([0-7]{6})/;
+               my $modestr = mode_str($1);
                if ($type eq "blob") {
                        if ($op eq "+") {
-                               print "added\t" . $cgi->a({-href => "$my_uri/$project/blob/$id"}, $file) . "\n";
+                               print "added\t$modestr " . $cgi->a({-href => "$my_uri/$project/blob/$id"}, $file) . "\n";
                        } elsif ($op eq "-") {
-                               print "removed\t" . $cgi->a({-href => "$my_uri/$project/blob/$id"}, $file) . "\n";
+                               print "removed\t$modestr " . $cgi->a({-href => "$my_uri/$project/blob/$id"}, $file) . "\n";
                        } elsif ($op eq "*") {
                                $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
                                my $old = $1;
                                my $new = $2;
-                               print "changed\t" . $cgi->a({-href => "$my_uri/$project/blobdiff/$old/$new"}, $file) . "\n";
+                               print "changed\t$modestr " . $cgi->a({-href => "$my_uri/$project/blobdiff/$old/$new"}, $file) . "\n";
                        }
                }
        }
@@ -503,7 +519,7 @@ if ($action eq "blob") {
        git_header_html();
        print "<br/><br/>\n";
        print "<pre>\n";
-       git_diff($hash, $hash_parent, $hash, $hash_parent);
+       git_diff_html($hash, $hash_parent, $hash, $hash_parent);
        print "</pre>\n";
        print "<br/>";
        git_footer_html();
@@ -530,12 +546,12 @@ if ($action eq "blob") {
                my $file = $5;
                if ($type eq "blob") {
                        if ($op eq "+") {
-                               git_diff("", $file, "", $id);
+                               git_diff_html("", $file, "", $id);
                        } elsif ($op eq "-") {
-                               git_diff($file, "", $id, "");
+                               git_diff_html($file, "", $id, "");
                        } elsif ($op eq "*") {
                                $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
-                               git_diff($file, $file, $1, $2);
+                               git_diff_html($file, $file, $1, $2);
                        }
                }
        }
This page took 0.312157 seconds and 4 git commands to generate.