use File::Basename qw(basename);
binmode STDOUT, ':utf8';
+BEGIN {
+ CGI->compile() if $ENV{MOD_PERL};
+}
+
our $cgi = new CGI;
our $version = "++GIT_VERSION++";
our $my_url = $cgi->url();
}
sub parse_commit_text {
- my ($commit_text) = @_;
+ my ($commit_text, $withparents) = @_;
my @commit_lines = split '\n', $commit_text;
my %co;
if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
return;
}
- $co{'id'} = $header;
- my @parents;
+ ($co{'id'}, my @parents) = split ' ', $header;
while (my $line = shift @commit_lines) {
last if $line eq "\n";
if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
$co{'tree'} = $1;
- } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
+ } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
push @parents, $1;
} elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
$co{'author'} = $1;
local $/ = "\0";
open my $fd, "-|", git_cmd(), "rev-list",
+ "--parents",
"--header",
"--max-count=1",
$commit_id,
"--",
or die_error(undef, "Open git-rev-list failed");
- %co = parse_commit_text(<$fd>);
+ %co = parse_commit_text(<$fd>, 1);
close $fd;
return %co;
$maxcount ||= 1;
$skip ||= 0;
- # Delete once rev-list supports the --skip option
- if ($skip > 0) {
- open my $fd, "-|", git_cmd(), "rev-list",
- ($arg ? ($arg) : ()),
- ("--max-count=" . ($maxcount + $skip)),
- $commit_id,
- "--",
- ($filename ? ($filename) : ())
- or die_error(undef, "Open git-rev-list failed");
- while (my $line = <$fd>) {
- if ($skip-- <= 0) {
- chomp $line;
- my %co = parse_commit($line);
- push @cos, \%co;
- }
- }
- close $fd;
-
- return wantarray ? @cos : \@cos;
- }
-
local $/ = "\0";
open my $fd, "-|", git_cmd(), "rev-list",
"--header",
($arg ? ($arg) : ()),
("--max-count=" . $maxcount),
- # Add once rev-list supports the --skip option
- # ("--skip=" . $skip),
+ ("--skip=" . $skip),
$commit_id,
"--",
($filename ? ($filename) : ())
}
print $cgi->header(-type=>$content_type, -charset => 'utf-8',
-status=> $status, -expires => $expires);
+ my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
print <<EOF;
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- git core binaries version $git_version -->
<head>
<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
-<meta name="generator" content="gitweb/$version git/$git_version"/>
+<meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
<meta name="robots" content="index, nofollow"/>
<title>$title</title>
EOF
my $mode_chnge = "";
if ($diff{'from_mode'} != $diff{'to_mode'}) {
$mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
- if ($from_file_type != $to_file_type) {
+ if ($from_file_type ne $to_file_type) {
$mode_chnge .= " from $from_file_type to $to_file_type";
}
if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
my $patch_line;
my $diffinfo;
my (%from, %to);
- my ($from_id, $to_id);
print "<div class=\"patchset\">\n";
PATCH:
while ($patch_line) {
my @diff_header;
+ my ($from_id, $to_id);
# git diff header
#assert($patch_line =~ m/^diff /) if DEBUG;
while ($patch_line = <$fd>) {
chomp $patch_line;
- last EXTENDED_HEADER if ($patch_line =~ m/^--- /);
+ last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
$from_id = $1;
$from{'href'} = href(action=>"blob", hash_base=>$hash_parent,
hash=>$diffinfo->{'from_id'},
file_name=>$from{'file'});
+ } else {
+ delete $from{'href'};
}
if ($diffinfo->{'status'} ne "D") { # not deleted file
$to{'href'} = href(action=>"blob", hash_base=>$hash,
hash=>$diffinfo->{'to_id'},
file_name=>$to{'file'});
+ } else {
+ delete $to{'href'};
}
# this is first patch for raw difftree line with $patch_idx index
# we index @$difftree array from 0, but number patches from 1
# match <path>
if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
$patch_line .= $cgi->a({-href=>$from{'href'}, -class=>"path"},
- esc_path($from{'file'}));
+ esc_path($from{'file'}));
}
if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
- $patch_line = $cgi->a({-href=>$to{'href'}, -class=>"path"},
- esc_path($to{'file'}));
+ $patch_line .= $cgi->a({-href=>$to{'href'}, -class=>"path"},
+ esc_path($to{'file'}));
}
# match <mode>
if ($patch_line =~ m/\s(\d{6})$/) {
# from-file/to-file diff header
$patch_line = $last_patch_line;
+ last PATCH unless $patch_line;
+ next PATCH if ($patch_line =~ m/^diff /);
#assert($patch_line =~ m/^---/) if DEBUG;
- if ($from{'href'}) {
+ if ($from{'href'} && $patch_line =~ m!^--- "?a/!) {
$patch_line = '--- a/' .
$cgi->a({-href=>$from{'href'}, -class=>"path"},
esc_path($from{'file'}));
chomp $patch_line;
#assert($patch_line =~ m/^+++/) if DEBUG;
- if ($to{'href'}) {
+ if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
$patch_line = '+++ b/' .
$cgi->a({-href=>$to{'href'}, -class=>"path"},
esc_path($to{'file'}));
sub git_history_body {
# Warning: assumes constant type (blob or tree) during history
- my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
+ my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
$from = 0 unless defined $from;
- $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
+ $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
print "<table class=\"history\" cellspacing=\"0\">\n";
my $alternate = 1;
for (my $i = $from; $i <= $to; $i++) {
- if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
- next;
- }
-
- my $commit = $1;
- my %co = parse_commit($commit);
+ my %co = %{$commitlist->[$i]};
if (!%co) {
next;
}
+ my $commit = $co{'id'};
my $ref = format_ref_marker($refs, $commit);
print "<tr class=\"light\">\n";
}
$alternate ^= 1;
- print "<td><i>$tag{'age'}</i></td>\n" .
- "<td>" .
+ if (defined $tag{'age'}) {
+ print "<td><i>$tag{'age'}</i></td>\n";
+ } else {
+ print "<td></td>\n";
+ }
+ print "<td>" .
$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
-class => "list name"}, esc_html($tag{'name'})) .
"</td>\n" .
foreach my $pr (@projects) {
if (!exists $pr->{'owner'}) {
- $pr->{'owner'} = get_file_owner("$projectroot/$project");
+ $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}");
}
my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
esc_html($rev));
print "</td>\n";
}
+ open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
+ or die_error("could not open git-rev-parse");
+ my $parent_commit = <$dd>;
+ close $dd;
+ chomp($parent_commit);
my $blamed = href(action => 'blame',
file_name => $meta->{'filename'},
- hash_base => $full_rev);
+ hash_base => $parent_commit);
print "<td class=\"linenr\">";
print $cgi->a({ -href => "$blamed#l$orig_lineno",
-id => "l$lineno",
$ftype = git_get_type($hash);
}
- open my $fd, "-|",
- git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
- or die_error(undef, "Open git-rev-list-failed");
- my @revlist = map { chomp; $_ } <$fd>;
- close $fd
- or die_error(undef, "Reading git-rev-list failed");
+ my @commitlist = parse_commits($hash_base, 101, (100 * $page), "--full-history", $file_name);
my $paging_nav = '';
if ($page > 0) {
$paging_nav .= "first";
$paging_nav .= " ⋅ prev";
}
- if ($#revlist >= (100 * ($page+1)-1)) {
+ if ($#commitlist >= 100) {
$paging_nav .= " ⋅ " .
$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
file_name=>$file_name, page=>$page+1),
$paging_nav .= " ⋅ next";
}
my $next_link = '';
- if ($#revlist >= (100 * ($page+1)-1)) {
+ if ($#commitlist >= 100) {
$next_link =
$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
file_name=>$file_name, page=>$page+1),
- -title => "Alt-n"}, "next");
+ -accesskey => "n", -title => "Alt-n"}, "next");
}
git_header_html();
git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
git_print_page_path($file_name, $ftype, $hash_base);
- git_history_body(\@revlist, ($page * 100), $#revlist,
+ git_history_body(\@commitlist, 0, 99,
$refs, $hash_base, $ftype, $next_link);
git_footer_html();
}
my $refs = git_get_references();
- my @commitlist = parse_commits($head, 101, (100 * $page));
+ my @commitlist = parse_commits($hash, 101, (100 * $page));
my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, (100 * ($page+1)));
my $next_link = '';
# log/feed of current (HEAD) branch, log of given branch, history of file/directory
my $head = $hash || 'HEAD';
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150",
- $head, "--", (defined $file_name ? $file_name : ())
- or die_error(undef, "Open git-rev-list failed");
- my @revlist = map { chomp; $_ } <$fd>;
- close $fd or die_error(undef, "Reading git-rev-list failed");
+ my @commitlist = parse_commits($head, 150);
my %latest_commit;
my %latest_date;
# browser (feed reader) prefers text/xml
$content_type = 'text/xml';
}
- if (defined($revlist[0])) {
- %latest_commit = parse_commit($revlist[0]);
+ if (defined($commitlist[0])) {
+ %latest_commit = %{$commitlist[0]};
%latest_date = parse_date($latest_commit{'author_epoch'});
print $cgi->header(
-type => $content_type,
}
# contents
- for (my $i = 0; $i <= $#revlist; $i++) {
- my $commit = $revlist[$i];
- my %co = parse_commit($commit);
+ for (my $i = 0; $i <= $#commitlist; $i++) {
+ my %co = %{$commitlist[$i]};
+ my $commit = $co{'id'};
# we read 150, we always show 30 and the ones more recent than 48 hours
if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
last;
my %cd = parse_date($co{'author_epoch'});
# get list of changed files
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
+ open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
$co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
or next;
my @difftree = map { chomp; $_ } <$fd>;