From: Zachary Stevens Date: Sun, 8 Nov 2009 04:19:12 +0000 (+0000) Subject: Convert summary page to new model. X-Git-Tag: 0.000000_01~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4111e151275bf52fdd69fcf250c19cc1a8c1514f;p=catagits%2FGitalist.git Convert summary page to new model. --- diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm index 798e267..23220ef 100644 --- a/lib/Gitalist/Controller/Root.pm +++ b/lib/Gitalist/Controller/Root.pm @@ -121,18 +121,27 @@ A summary of what's happening in the repo. sub summary : Local { my ( $self, $c ) = @_; - + $c->stash(current_model => 'GitRepos'); + warn("project is " . $c->stash->{project}); + my $project; + eval { + $project = $c->model()->project($c->stash->{project}); + }; + if ($@) { + $c->detach('error_404'); + } my $commit = $self->_get_commit($c); $c->stash( commit => $commit, - info => $c->model()->project_info($c->model()->project), - log_lines => [$c->model()->list_revs( - sha1 => $commit->sha1, count => Gitalist->config->{paging}{summary} + info => $project->info, + log_lines => [$project->list_revs( + sha1 => $commit->sha1, + count => Gitalist->config->{paging}{summary} || 50 )], - refs => $c->model()->references, - heads => [$c->model()->heads], + refs => $project->references, + heads => [$project->heads], action => 'summary', - ); +); } =head2 heads @@ -593,6 +602,15 @@ sub end : ActionClass('RenderView') { } } +sub error_404 :Private { + my ($self, $c) = @_; + $c->response->status(404); + $c->stash( + title => 'Page not found', + content => 'Page not found', + ) +} + sub age_string { my $age = shift; my $age_str; diff --git a/lib/Gitalist/Git/Project.pm b/lib/Gitalist/Git/Project.pm index cf3ac4c..9ce7e5a 100644 --- a/lib/Gitalist/Git/Project.pm +++ b/lib/Gitalist/Git/Project.pm @@ -3,7 +3,7 @@ use MooseX::Declare; class Gitalist::Git::Project { # FIXME, use Types::Path::Class and coerce use MooseX::Types::Common::String qw/NonEmptySimpleStr/; - use MooseX::Types::Moose qw/Str Maybe Bool/; + use MooseX::Types::Moose qw/Str Maybe Bool HashRef/; use DateTime; use MooseX::Types::Path::Class qw/Dir/; use Gitalist::Git::Util; @@ -31,7 +31,7 @@ class Gitalist::Git::Project { has _util => ( isa => 'Gitalist::Git::Util', is => 'ro', lazy_build => 1, - handles => [ 'run_cmd' ], + handles => [ 'run_cmd', 'get_gpp_object' ], ); has project_dir => ( isa => Dir, @@ -125,6 +125,28 @@ class Gitalist::Git::Project { return @ret; } + method references { + return $self->{references} + if $self->{references}; + + # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 + # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} + my $cmdout = $self->run_cmd(qw(show-ref --dereference)) + or return; + my @reflist = $cmdout ? split(/\n/, $cmdout) : (); + my %refs; + for(@reflist) { + push @{$refs{$1}}, $2 + if m!^($SHA1RE)\srefs/(.*)$!; + } + + return $self->{references} = \%refs; +} + + method valid_rev (Str $rev) { + return ($rev =~ /^($SHA1RE)$/); + } + =head2 head_hash @@ -219,6 +241,50 @@ The keys for each item will be: : $3; } + method list_revs ( NonEmptySimpleStr :$sha1!, + Int :$count?, + Int :$skip?, + HashRef :$search?, + NonEmptySimpleStr :$file? + ) { + $sha1 = $self->head_hash($sha1) + if !$sha1 || $sha1 !~ $SHA1RE; + + my @search_opts; + if($search) { + $search->{type} = 'grep' + if $search->{type} eq 'commit'; + @search_opts = ( + # This seems a little fragile ... + qq[--$search->{type}=$search->{text}], + '--regexp-ignore-case', + $search->{regexp} ? '--extended-regexp' : '--fixed-strings' + ); + } + + my $output = $self->run_cmd( + 'rev-list', + '--header', + (defined $count ? "--max-count=$count" : ()), + (defined $skip ? "--skip=$skip" : ()), + @search_opts, + $sha1, + '--', + ($file ? $file : ()), + ); + return unless $output; + + my @revs = $self->parse_rev_list($output); + + return @revs; + } + + method parse_rev_list ($output) { + return + map $self->get_gpp_object($_), + grep $self->valid_rev($_), + map split(/\n/, $_, 6), split /\0/, $output; + } # Compatibility diff --git a/lib/Gitalist/Git/Util.pm b/lib/Gitalist/Git/Util.pm index af3717c..a38eb70 100644 --- a/lib/Gitalist/Git/Util.pm +++ b/lib/Gitalist/Git/Util.pm @@ -31,7 +31,7 @@ EOR method run_cmd (@args) { unshift @args, ( '--git-dir' => $self->gitdir ); - print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/; +# print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/; open my $fh, '-|', $self->_git, @args or die "failed to run git command"; @@ -42,4 +42,9 @@ EOR return $output; } + + method get_gpp_object (NonEmptySimpleStr $sha1) { + return $self->_gpp->get_object($sha1) || undef; + } + } # end class