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
}
}
+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;
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;
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,
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
: $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
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";
return $output;
}
+
+ method get_gpp_object (NonEmptySimpleStr $sha1) {
+ return $self->_gpp->get_object($sha1) || undef;
+ }
+
} # end class