From: Zachary Stevens Date: Thu, 12 Nov 2009 20:07:08 +0000 (+0000) Subject: Make Project->heads an attribute. X-Git-Tag: 0.000000_01~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c65cccc21bba60a22b059f281ba4ca9b3a322d9b;p=catagits%2FGitalist.git Make Project->heads an attribute. --- diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm index 60779e8..8a23613 100644 --- a/lib/Gitalist/Controller/Root.pm +++ b/lib/Gitalist/Controller/Root.pm @@ -122,7 +122,7 @@ sub summary : Local { my $project = $c->stash->{Project}; $c->detach('error_404') unless $project; my $commit = $self->_get_object($c); - my @heads = $project->heads; + my @heads = @{$project->heads}; my $maxitems = Gitalist->config->{paging}{summary} || 10; $c->stash( commit => $commit, @@ -148,7 +148,7 @@ sub heads : Local { my $project = $c->stash->{Project}; $c->stash( commit => $self->_get_object($c), - heads => [$project->heads], + heads => $project->heads, action => 'heads', ); } diff --git a/lib/Gitalist/Git/Project.pm b/lib/Gitalist/Git/Project.pm index 4862b46..853f0c5 100644 --- a/lib/Gitalist/Git/Project.pm +++ b/lib/Gitalist/Git/Project.pm @@ -129,11 +129,13 @@ Return the sha1 for HEAD, or any specified head. =head2 heads -Returns a list of hashes containing the name and sha1 of all heads. +ArrayRef of hashes containing the name and sha1 of all heads. =cut - method heads { + has heads => ( isa => ArrayRef[HashRef], is => 'ro', lazy_build => 1); + + method _build_heads { my @revlines = $self->run_cmd_list(qw/for-each-ref --sort=-committerdate /, '--format=%(objectname)%00%(refname)%00%(committer)', 'refs/heads'); my @ret; for my $line (@revlines) { @@ -150,12 +152,12 @@ Returns a list of hashes containing the name and sha1 of all heads. } } - return @ret; + return \@ret; } =head2 references -Returns a hash of references. +Hashref of ArrayRefs for each reference. =cut diff --git a/t/02git_project.t b/t/02git_project.t index be0f9a6..90c8b38 100644 --- a/t/02git_project.t +++ b/t/02git_project.t @@ -23,7 +23,10 @@ isa_ok($proj->last_change, 'DateTime', 'last_change'); is($proj->info->{name}, qw/repo1/, 'repo name in info hash'); -my @heads = $proj->heads; +my %references = %{$proj->references}; +ok(keys %references >= 2, '->references hash has elements'); +is($references{'36c6c6708b8360d7023e8a1649c45bcf9b3bd818'}->[0], 'heads/master', 'reference looks ok'); +my @heads = @{$proj->heads}; ok(scalar @heads > 1, '->heads list has more than one element'); my %head = %{$heads[1]}; ok(keys %head == 3, '->heads[1] has the right number of keys');