From: Kay Sievers Date: Tue, 13 Sep 2005 00:21:59 +0000 (+0200) Subject: switch to git-rev-list for commit reading X-Git-Tag: v1.4.0~1^2~54 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=25f422fb87014107bffb265483809909f300c537;p=git.git switch to git-rev-list for commit reading This way we don't need to parse the "grafts". Signed-off-by: Kay Sievers --- diff --git a/gitweb.cgi b/gitweb.cgi index fa5b6355a..53980efeb 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -443,21 +443,28 @@ sub git_read_commit { my @commit_lines; my %co; - my @parents; if (defined $commit_text) { @commit_lines = @$commit_text; } else { - open my $fd, "-|", "$gitbin/git-cat-file commit $commit_id" or return; - @commit_lines = map { chomp; $_ } <$fd>; + $/ = "\0"; + open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return; + @commit_lines = split '\n', <$fd>; close $fd or return; + $/ = "\n"; + pop @commit_lines; } + my $header = shift @commit_lines; + if (!($header =~ m/^[0-9a-fA-F]{40}/)) { + return; + } + ($co{'id'}, my @parents) = split ' ', $header; + $co{'parents'} = \@parents; + $co{'parent'} = $parents[0]; 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})$/) { - push @parents, $1; } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { $co{'author'} = $1; $co{'author_epoch'} = $2; @@ -476,21 +483,9 @@ sub git_read_commit { } } if (!defined $co{'tree'}) { - return undef + return; }; - if (!($commit_id =~ m/^[0-9a-fA-F]{40}$/)) { - # lookup hash by textual id - open my $fd, "-|", "$gitbin/git-rev-parse --verify $commit_id" or return; - my $hash_id = <$fd>; - close $fd or return; - chomp $hash_id; - $co{'id'} = $hash_id - } else { - $co{'id'} = $commit_id; - } - $co{'parents'} = \@parents; - $co{'parent'} = $parents[0]; - $co{'comment'} = \@commit_lines; + foreach my $title (@commit_lines) { if ($title ne "") { $co{'title'} = chop_str($title, 80, 5); @@ -515,6 +510,11 @@ sub git_read_commit { last; } } + # remove added spaces + foreach my $line (@commit_lines) { + $line =~ s/^ //; + } + $co{'comment'} = \@commit_lines; my $age = time - $co{'committer_epoch'}; $co{'age'} = $age; @@ -2081,7 +2081,7 @@ sub git_search { my $alternate = 0; if ($commit_search) { $/ = "\0"; - open my $fd, "-|", "$gitbin/git-rev-list --header $hash"; + open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next; while (my $commit_text = <$fd>) { if (!grep m/$searchtext/i, $commit_text) { next; @@ -2093,8 +2093,7 @@ sub git_search { next; } my @commit_lines = split "\n", $commit_text; - my $commit = shift @commit_lines; - my %co = git_read_commit($commit, \@commit_lines); + my %co = git_read_commit(undef, \@commit_lines); if (!%co) { next; } @@ -2107,7 +2106,7 @@ sub git_search { print "$co{'age_string_date'}\n" . "" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "\n" . "" . - $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "" . escapeHTML(chop_str($co{'title'}, 50)) . "
"); + $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "" . escapeHTML(chop_str($co{'title'}, 50)) . "
"); my $comment = $co{'comment'}; foreach my $line (@$comment) { if ($line =~ m/^(.*)($searchtext)(.*)$/i) { @@ -2122,8 +2121,8 @@ sub git_search { } print "\n" . "" . - $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . - " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree"); + $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") . + " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree"); print "\n" . "\n"; }