@matheusbsbs / matheus-bagliano / commits / 120ddde2a8
Fork 0

gitweb: Make git_get_refs_list do work of git_get_references

Make git_get_refs_list do also work of git_get_references, to avoid calling git-peek-remote twice. Change meaning of git_get_refs_list meaning: it is now type, and not a full path, e.g. we now use git_get_refs_list("heads") instead of former git_get_refs_list("refs/heads"). Modify git_summary to use only one call to git_get_refs_list instead of one call to git_get_references and two to git_get_refs_list. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Sep 19, 2006 at 14:33 UTC 120ddde2a843e923944abd5d6e61f8625e820e92
1 file changed +42 -24
gitweb/gitweb.perl
+42 -24
@@ -1134,7 +1134,8 @@ sub parse_ls_tree_line ($;%) {
1134 ## parse to array of hashes functions
1135
1136 sub git_get_refs_list {
1137 - my $ref_dir = shift;
1137 + my $type = shift || "";
1138 + my %refs;
1139 my @reflist;
1140
1141 my @refs;
@@ -1142,14 +1143,21 @@ sub git_get_refs_list {
1143 or return;
1144 while (my $line = <$fd>) {
1145 chomp $line;
1145 - if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
1146 - push @refs, { hash => $1, name => $2 };
1147 - } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?(.*)\^\{\}$/ &&
1148 - $1 eq $refs[-1]{'name'}) {
1149 - # most likely a tag is followed by its peeled
1150 - # (deref) one, and when that happens we know the
1151 - # previous one was of type 'tag'.
1152 - $refs[-1]{'type'} = "tag";
1146 + if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?([^\^]+))(\^\{\})?$/) {
1147 + if (defined $refs{$1}) {
1148 + push @{$refs{$1}}, $2;
1149 + } else {
1150 + $refs{$1} = [ $2 ];
1151 + }
1152 +
1153 + if (! $4) { # unpeeled, direct reference
1154 + push @refs, { hash => $1, name => $3 }; # without type
1155 + } elsif ($3 eq $refs[-1]{'name'}) {
1156 + # most likely a tag is followed by its peeled
1157 + # (deref) one, and when that happens we know the
1158 + # previous one was of type 'tag'.
1159 + $refs[-1]{'type'} = "tag";
1160 + }
1161 }
1162 }
1163 close $fd;
@@ -1165,7 +1173,7 @@ sub git_get_refs_list {
1173 }
1174 # sort refs by age
1175 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1168 - return \@reflist;
1176 + return (\@reflist, \%refs);
1177 }
1178
1179 ## ----------------------------------------------------------------------
@@ -2129,14 +2137,14 @@ sub git_tags_body {
2137
2138 sub git_heads_body {
2139 # uses global variable $project
2132 - my ($taglist, $head, $from, $to, $extra) = @_;
2140 + my ($headlist, $head, $from, $to, $extra) = @_;
2141 $from = 0 unless defined $from;
2134 - $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2142 + $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2143
2144 print "<table class=\"heads\" cellspacing=\"0\">\n";
2145 my $alternate = 0;
2146 for (my $i = $from; $i <= $to; $i++) {
2139 - my $entry = $taglist->[$i];
2147 + my $entry = $headlist->[$i];
2148 my %tag = %$entry;
2149 my $curr = $tag{'id'} eq $head;
2150 if ($alternate) {
@@ -2306,7 +2314,19 @@ sub git_summary {
2314
2315 my $owner = git_get_project_owner($project);
2316
2309 - my $refs = git_get_references();
2317 + my ($reflist, $refs) = git_get_refs_list();
2318 +
2319 + my @taglist;
2320 + my @headlist;
2321 + foreach my $ref (@$reflist) {
2322 + if ($ref->{'name'} =~ s!^heads/!!) {
2323 + push @headlist, $ref;
2324 + } else {
2325 + $ref->{'name'} =~ s!^tags/!!;
2326 + push @taglist, $ref;
2327 + }
2328 + }
2329 +
2330 git_header_html();
2331 git_print_page_nav('summary','', $head);
2332
@@ -2336,17 +2356,15 @@ sub git_summary {
2356 git_shortlog_body(\@revlist, 0, 15, $refs,
2357 $cgi->a({-href => href(action=>"shortlog")}, "..."));
2358
2339 - my $taglist = git_get_refs_list("refs/tags");
2340 - if (defined @$taglist) {
2359 + if (@taglist) {
2360 git_print_header_div('tags');
2342 - git_tags_body($taglist, 0, 15,
2361 + git_tags_body(\@taglist, 0, 15,
2362 $cgi->a({-href => href(action=>"tags")}, "..."));
2363 }
2364
2346 - my $headlist = git_get_refs_list("refs/heads");
2347 - if (defined @$headlist) {
2365 + if (@headlist) {
2366 git_print_header_div('heads');
2349 - git_heads_body($headlist, $head, 0, 15,
2367 + git_heads_body(\@headlist, $head, 0, 15,
2368 $cgi->a({-href => href(action=>"heads")}, "..."));
2369 }
2370
@@ -2557,7 +2575,7 @@ sub git_tags {
2575 git_print_page_nav('','', $head,undef,$head);
2576 git_print_header_div('summary', $project);
2577
2560 - my $taglist = git_get_refs_list("refs/tags");
2578 + my ($taglist) = git_get_refs_list("tags");
2579 if (defined @$taglist) {
2580 git_tags_body($taglist);
2581 }
@@ -2570,9 +2588,9 @@ sub git_heads {
2588 git_print_page_nav('','', $head,undef,$head);
2589 git_print_header_div('summary', $project);
2590
2573 - my $taglist = git_get_refs_list("refs/heads");
2574 - if (defined @$taglist) {
2575 - git_heads_body($taglist, $head);
2591 + my ($headlist) = git_get_refs_list("heads");
2592 + if (defined @$headlist) {
2593 + git_heads_body($headlist, $head);
2594 }
2595 git_footer_html();
2596 }