@matheusbsbs / matheus-bagliano / commits / c83a77e4e1
Fork 0

gitweb: Do not parse refs by hand, use git-peek-remote instead

This is in response to Linus's work on packed refs. Additionally it makes gitweb work with symrefs, too. Do not parse refs by hand, using File::Find and reading individual heads to get hash of reference, but use git-peek-remote output instead. Assume that the hash for deref (with ^{}) always follows hash for ref, and that we have derefs only for tag objects; this removes call to git_get_type (and git-cat-file -t invocation) for tags, which speeds "summary" and "tags" views generation, but might slow generation of "heads" view a bit. For now, we do not save and use the deref hash. Remove git_get_hash_by_ref while at it, as git_get_refs_list was the only place it was used. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Sep 15, 2006 at 03:43 UTC c83a77e4e139303a8a830b2ba7802bed0b8fe9d9
1 file changed +19 -22
gitweb/gitweb.perl
+19 -22
@@ -676,19 +676,6 @@ sub git_get_hash_by_path {
676 ## ......................................................................
677 ## git utility functions, directly accessing git repository
678
679 -# assumes that PATH is not symref
680 -sub git_get_hash_by_ref {
681 - my $path = shift;
682 -
683 - open my $fd, "$projectroot/$path" or return undef;
684 - my $head = <$fd>;
685 - close $fd;
686 - chomp $head;
687 - if ($head =~ m/^[0-9a-fA-F]{40}$/) {
688 - return $head;
689 - }
690 -}
691 -
679 sub git_get_project_description {
680 my $path = shift;
681
@@ -1098,17 +1085,27 @@ sub git_get_refs_list {
1085 my @reflist;
1086
1087 my @refs;
1101 - my $pfxlen = length("$projectroot/$project/$ref_dir");
1102 - File::Find::find(sub {
1103 - return if (/^\./);
1104 - if (-f $_) {
1105 - push @refs, substr($File::Find::name, $pfxlen + 1);
1088 + open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1089 + or return;
1090 + while (my $line = <$fd>) {
1091 + chomp $line;
1092 + if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
1093 + push @refs, { hash => $1, name => $2 };
1094 + } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?(.*)\^\{\}$/ &&
1095 + $1 eq $refs[-1]{'name'}) {
1096 + # most likely a tag is followed by its peeled
1097 + # (deref) one, and when that happens we know the
1098 + # previous one was of type 'tag'.
1099 + $refs[-1]{'type'} = "tag";
1100 }
1107 - }, "$projectroot/$project/$ref_dir");
1101 + }
1102 + close $fd;
1103 +
1104 + foreach my $ref (@refs) {
1105 + my $ref_file = $ref->{'name'};
1106 + my $ref_id = $ref->{'hash'};
1107
1109 - foreach my $ref_file (@refs) {
1110 - my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1111 - my $type = git_get_type($ref_id) || next;
1108 + my $type = $ref->{'type'} || git_get_type($ref_id) || next;
1109 my %ref_item = parse_ref($ref_file, $ref_id, $type);
1110
1111 push @reflist, \%ref_item;