use Fcntl ':mode';
my $cgi = new CGI;
-my $version = "227";
+my $version = "234";
my $my_url = $cgi->url();
my $my_uri = $cgi->url(-absolute => 1);
my $rss_link = "";
my $hash = $cgi->param('h');
if (defined $hash) {
- if ($hash =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
- undef $hash;
- die_error(undef, "Non-canonical hash parameter.");
- }
- if ($hash =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
- undef $hash;
- die_error(undef, "Invalid character in hash parameter.");
+ if (!($hash =~ m/^[0-9a-fA-F]{40}$/)) {
+ if ($hash =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
+ undef $hash;
+ die_error(undef, "Non-canonical hash parameter.");
+ }
+ if ($hash =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
+ undef $hash;
+ die_error(undef, "Invalid character in hash parameter.");
+ }
+ # replace branch-name with hash
+ my $branchlist = git_read_refs("refs/heads");
+ foreach my $entry (@$branchlist) {
+ my %branch = %$entry;
+ if ($branch{'name'} eq $hash) {
+ $hash = $branch{'id'};
+ last;
+ }
+ }
}
}
}
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
if ($age > 60*60*24*7*2) {
- $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon, $mday;
+ $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
$co{'age_string_age'} = $co{'age_string'};
} else {
$co{'age_string_date'} = $co{'age_string'};
- $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon, $mday;
+ $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
}
return %co;
}
}
}
+sub format_log_line_html {
+ my $line = shift;
+
+ $line = escapeHTML($line);
+ $line =~ s/ / /g;
+ if ($line =~ m/([0-9a-fA-F]{40})/) {
+ my $hash_text = $1;
+ if (git_get_type($hash_text) eq "commit") {
+ my $link = $cgi->a({-class => "list", -href => "$my_uri?p=$project;a=commit;h=$hash_text"}, $hash_text);
+ $line =~ s/$hash_text/$link/;
+ }
+ }
+ return $line;
+}
+
sub date_str {
my $epoch = shift;
my $tz = shift || "-0000";
if ($i-- > 0) {
print "<td><i>$tag{'age'}</i></td>\n" .
"<td>" .
- $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'name'}", -class => "list"}, "<b>" .
+ $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}", -class => "list"}, "<b>" .
escapeHTML($tag{'name'}) . "</b>") .
"</td>\n" .
"<td class=\"link\">" .
- $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'name'}"}, $tag{'type'});
+ $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
if ($tag{'type'} eq "commit") {
- print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log");
+ print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
}
print "</td>\n" .
"</tr>";
$alternate ^= 1;
print "<td><i>$tag{'age'}</i></td>\n" .
"<td>" .
- $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"},
+ $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}", -class => "list"},
"<b>" . escapeHTML($tag{'name'}) . "</b>") .
"</td>\n" .
"<td class=\"link\">" .
- $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'name'}"}, $tag{'type'});
+ $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
if ($tag{'type'} eq "commit") {
print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log");
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
}
print "</td>\n" .
"</tr>";
} else {
$empty = 0;
}
- print escapeHTML($line) . "<br/>\n";
+ print format_log_line_html($line) . "<br/>\n";
}
if (!$empty) {
print "<br/>\n";
print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
} else {
$signed = 0;
- print escapeHTML($line) . "<br/>\n";
+ print format_log_line_html($line) . "<br/>\n";
}
}
print "</div>\n";
print "<tr class=\"light\">\n";
}
$alternate ^= 1;
- if ($status eq "N") {
+ if ($status eq "A") {
my $mode_chng = "";
if (S_ISREG(oct $to_mode)) {
$mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
} else {
$empty = 0;
}
- print escapeHTML($line) . "<br/>\n";
+ print format_log_line_html($line) . "<br/>\n";
}
print "<br/>\n";
foreach my $line (@difftree) {
my $to_id = $4;
my $status = $5;
my $file = $6;
- if ($status eq "N") {
+ if ($status eq "A") {
print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
$cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
"</div>\n";
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
+ # try to figure out the next tag after this commit
+ my $tagname;
+ my %taghash;
+ my $tags = git_read_refs("refs/tags");
+ foreach my $entry (@$tags) {
+ my %tag = %$entry;
+ $taghash{$tag{'id'}} = $tag{'name'};
+ }
+ open $fd, "-|", "$gitbin/git-rev-list HEAD";
+ while (my $commit = <$fd>) {
+ chomp $commit;
+ if ($taghash{$commit}) {
+ $tagname = $taghash{$commit};
+ }
+ if ($commit eq $hash) {
+ last;
+ }
+ }
+ close $fd;
+
+ print $cgi->header(-type => "text/plain", -charset => 'utf-8');
my %co = git_read_commit($hash);
my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
- print $cgi->header(-type => "text/plain", -charset => 'utf-8');
my $comment = $co{'comment'};
- print "Author: $co{'author'}\n" .
+ print "From: $co{'author'}\n" .
"Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
- "Source: $my_url?p=$project;a=commitdiff;h=$hash\n" .
+ "Subject: $co{'title'}\n";
+ if (defined $tagname) {
+ print "X-Git-Tag: $tagname\n";
+ }
+ print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
"\n";
+
foreach my $line (@$comment) {;
print " $line\n";
}
- print "\n";
+ print "---\n\n";
+
foreach my $line (@difftree) {
$line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
my $from_id = $3;
my $to_id = $4;
my $status = $5;
my $file = $6;
- if ($status eq "N") {
+ if ($status eq "A") {
git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
} elsif ($status eq "D") {
git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
print "<table cellspacing=\"0\">\n";
my $alternate = 0;
while (my $line = <$fd>) {
- if ($line =~ m/^([0-9a-fA-F]{40}) /){
+ if ($line =~ m/^([0-9a-fA-F]{40})/){
$commit = $1;
next;
}