From: Giuseppe Bilotta Date: Thu, 13 Nov 2008 22:49:11 GMT Subject: [PATCH v2 05/11] gitweb: git_split_heads_body function. Message-ID: <1226616555-24503-6-git-send-email-giuseppe.bilotta@gmail.com> In-Reply-To: <1226616555-24503-5-git-send-email-giuseppe.bilotta@gmail.com> The purpose of this function is to split a headlist into groups determined by the leading part of the refname, and call git_heads_body() on each group. Signed-off-by: Giuseppe Bilotta --- gitweb/gitweb.perl | 33 ++++++++++++++++++++++++++++++++- 1 files changed, 32 insertions(+), 1 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index a736f2a..836b6ba 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4271,6 +4271,37 @@ sub git_tags_body { print "\n"; } +sub git_split_heads_body { + my ($headlist, $head, $from, $to, $extra) = @_; + my %headlists; + my $leader; my $list; my @list; + + # Split @$headlist into a hash of lists + map { + my %ref = %$_; + $ref{'hname'} = $ref{'name'}; + if ($ref{'name'} =~ /\//) { + $ref{'name'} =~ s!^([^/]+)/!!; + $leader = $1; + } else { + $leader = "\000"; + } + if (defined $headlists{$leader}) { + @list = @{$headlists{$leader}} + } else { + @list = () + } + push @list, \%ref; + $headlists{$leader} = [@list]; + } @$headlist; + + foreach $leader (sort(keys %headlists)) { + print "$leader
\n" unless $leader eq "\000"; + $list = $headlists{$leader}; + git_heads_body($list, $head, $from, $to, $extra); + } +} + sub git_heads_body { # uses global variable $project my ($headlist, $head, $from, $to, $extra) = @_; @@ -4541,7 +4572,7 @@ sub git_summary { if (@remotelist) { git_print_header_div('remotes'); - git_heads_body(\@remotelist, $head, 0, 15, + git_split_heads_body(\@remotelist, $head, 0, 15, $#remotelist <= 15 ? undef : $cgi->a({-href => href(action=>"heads")}, "...")); } -- 1.5.6.5