+sub git_diff {
+ my $old_name = shift || "/dev/null";
+ my $new_name = shift || "/dev/null";
+ my $old = shift;
+ my $new = shift;
+
+ my $tmp_old = "/dev/null";
+ my $tmp_new = "/dev/null";
+ my $old_label = "/dev/null";
+ my $new_label = "/dev/null";
+
+ # 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;
+ }
+ close $fd2;
+ close $fd;
+ $tmp_old = "$gittmp/$old";
+ $old_label = "a/$old_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;
+ }
+ close $fd2;
+ close $fd;
+ $tmp_new = "$gittmp/$new";
+ $new_label = "b/$new_name";
+ }
+
+ open my $fd, "-|", "/usr/bin/diff", "-L", $old_label, "-L", $new_label, "-u", "-p", $tmp_old, $tmp_new;
+ print '<div class="diff_head">===== ';
+ if ($old ne "") {
+ print $cgi->a({-href => "$myself?project=$project;action=blob;hash=$old"}, $old);
+ } else {
+ print $old_name;
+ }
+ print " vs ";
+ if ($new ne "") {
+ print $cgi->a({-href => "$myself?project=$project;action=blob;hash=$new"}, $new);
+ } else {
+ print $new_name;
+ }
+ print ' =====</div>';
+ while (my $line = <$fd>) {
+ my $char = substr($line,0,1);
+ print '<div class="add">' if $char eq '+';
+ print '<div class="subtract">' if $char eq '-';
+ print '<div class="diff_line">' if $char eq '@';
+ print escapeHTML($line);
+ print '</div>' if $char eq '+' or $char eq '-' or $char eq '@';
+ }
+ close $fd;
+ unlink("$gittmp/$new");
+ unlink("$gittmp/$old");
+}
+