switch to git-rev-list for commit reading
This way we don't need to parse the "grafts". Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Kay Sievers committed
Sep 13, 2005 at 02:21 UTC
25f422fb87014107bffb265483809909f300c537
1 file changed
+24
-25
gitweb.cgi
+24
-25
@@ -443,21 +443,28 @@ sub git_read_commit {
443
444
my @commit_lines;
445
my %co;
446
- my @parents;
446
447
if (defined $commit_text) {
448
@commit_lines = @$commit_text;
449
} else {
451
- open my $fd, "-|", "$gitbin/git-cat-file commit $commit_id" or return;
452
- @commit_lines = map { chomp; $_ } <$fd>;
450
+ $/ = "\0";
451
+ open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
452
+ @commit_lines = split '\n', <$fd>;
453
close $fd or return;
454
+ $/ = "\n";
455
+ pop @commit_lines;
456
}
457
+ my $header = shift @commit_lines;
458
+ if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
459
+ return;
460
+ }
461
+ ($co{'id'}, my @parents) = split ' ', $header;
462
+ $co{'parents'} = \@parents;
463
+ $co{'parent'} = $parents[0];
464
while (my $line = shift @commit_lines) {
465
last if $line eq "\n";
466
if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
467
$co{'tree'} = $1;
459
- } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
460
- push @parents, $1;
468
} elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
469
$co{'author'} = $1;
470
$co{'author_epoch'} = $2;
@@ -476,21 +483,9 @@ sub git_read_commit {
483
}
484
}
485
if (!defined $co{'tree'}) {
479
- return undef
486
+ return;
487
};
481
- if (!($commit_id =~ m/^[0-9a-fA-F]{40}$/)) {
482
- # lookup hash by textual id
483
- open my $fd, "-|", "$gitbin/git-rev-parse --verify $commit_id" or return;
484
- my $hash_id = <$fd>;
485
- close $fd or return;
486
- chomp $hash_id;
487
- $co{'id'} = $hash_id
488
- } else {
489
- $co{'id'} = $commit_id;
490
- }
491
- $co{'parents'} = \@parents;
492
- $co{'parent'} = $parents[0];
493
- $co{'comment'} = \@commit_lines;
488
+
489
foreach my $title (@commit_lines) {
490
if ($title ne "") {
491
$co{'title'} = chop_str($title, 80, 5);
@@ -515,6 +510,11 @@ sub git_read_commit {
510
last;
511
}
512
}
513
+ # remove added spaces
514
+ foreach my $line (@commit_lines) {
515
+ $line =~ s/^ //;
516
+ }
517
+ $co{'comment'} = \@commit_lines;
518
519
my $age = time - $co{'committer_epoch'};
520
$co{'age'} = $age;
@@ -2081,7 +2081,7 @@ sub git_search {
2081
my $alternate = 0;
2082
if ($commit_search) {
2083
$/ = "\0";
2084
- open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
2084
+ open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2085
while (my $commit_text = <$fd>) {
2086
if (!grep m/$searchtext/i, $commit_text) {
2087
next;
@@ -2093,8 +2093,7 @@ sub git_search {
2093
next;
2094
}
2095
my @commit_lines = split "\n", $commit_text;
2096
- my $commit = shift @commit_lines;
2097
- my %co = git_read_commit($commit, \@commit_lines);
2096
+ my %co = git_read_commit(undef, \@commit_lines);
2097
if (!%co) {
2098
next;
2099
}
@@ -2107,7 +2106,7 @@ sub git_search {
2106
print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2107
"<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2108
"<td>" .
2110
- $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
2109
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
2110
my $comment = $co{'comment'};
2111
foreach my $line (@$comment) {
2112
if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
@@ -2122,8 +2121,8 @@ sub git_search {
2121
}
2122
print "</td>\n" .
2123
"<td class=\"link\">" .
2125
- $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
2126
- " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
2124
+ $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
2125
+ " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
2126
print "</td>\n" .
2127
"</tr>\n";
2128
}