+ $co{'parents'} = \@parents;
+ $co{'parent'} = $parents[0];
+ my (@comment) = map { chomp; $_ } <$fd>;
+ $co{'comment'} = \@comment;
+ $co{'title'} = $comment[0];
+ close $fd;
+ return %co;
+}
+
+sub git_diff_html {
+ my $from_name = shift || "/dev/null";
+ my $to_name = shift || "/dev/null";
+ my $from = shift;
+ my $to = shift;
+
+ 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 ($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;
+ $from_label = "a/$from_name";
+ }
+
+ # create tmp to-file
+ 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;
+ $to_label = "b/$to_name";
+ }
+
+ open my $fd, "-|", "/usr/bin/diff", "-L", $from_label, "-L", $to_label, "-u", "-p", $from_tmp, $to_tmp;
+ print "<span style =\"color: #000099;\">===== ";
+ if ($from ne "") {
+ print $cgi->a({-href => "$my_uri/$project/blob/$from"}, $from);
+ } else {
+ print $from_name;
+ }
+ print " vs ";
+ if ($to ne "") {
+ print $cgi->a({-href => "$my_uri/$project/blob/$to"}, $to);
+ } else {
+ print $to_name;
+ }
+ print " =====</span>\n";
+ while (my $line = <$fd>) {
+ my $char = substr($line,0,1);
+ print '<span style ="color: #008800;">' if $char eq '+';
+ print '<span style ="color: #CC0000;">' if $char eq '-';
+ print '<span style ="color: #990099;">' if $char eq '@';
+ print escapeHTML($line);
+ print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
+ }
+ close $fd;
+
+ 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;