}
}
+sub _get_commit {
+ my($self, $c) = @_;
+
+ # Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD.
+ my $hash = $c->req->param('h')
+ || ($c->req->param('f') ? $c->model('Git')->hash_by_path($c->req->param('f')) : '')
+ || $c->model('Git')->head_hash
+ # XXX This could definitely use more context.
+ || Carp::croak("Couldn't find a hash for the commit object!");
+
+ my $commit = $c->model('Git')->get_object($hash)
+ or Carp::croak("Couldn't find a commit object for '$hash'!");
+
+ return $commit;
+}
+
=head2 index
Provides the project listing.
sub summary : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->model('Git')->head_hash);
+ my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
info => $c->model('Git')->project_info($c->model('Git')->project),
my ( $self, $c ) = @_;
$c->stash(
- commit => $c->model('Git')->get_object($c->model('Git')->head_hash),
+ commit => $self->_get_commit($c),
heads => [$c->model('Git')->heads],
action => 'heads',
);
$c->forward('View::SyntaxHighlight');
}
-=head2 reflog
-
-Expose the local reflog. This may go away.
-
-=cut
-
-sub reflog : Local {
- my ( $self, $c ) = @_;
-
- my @log = $c->model('Git')->reflog(
- '--since=yesterday'
- );
-
- $c->stash(
- log => \@log,
- action => 'reflog',
- );
-}
-
=head2 commit
Exposes a given commit.
sub commit : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
diff_tree => [$c->model('Git')->diff_tree($commit)],
sub commitdiff : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
diff_tree => [$c->model('Git')->diff_tree($commit)],
sub shortlog : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
# XXX Needs paging.
$c->stash(
commit => $commit,
sub tree : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
$c->stash(
# XXX Useful defaults needed ...
commit => $commit,
tree => $c->model('Git')->get_object($c->req->param('hb')),
- list_tree => [$c->model('Git')->list_tree($commit->sha1)],
+ tree_list => [$c->model('Git')->list_tree($commit->sha1)],
action => 'tree',
);
}
+=head2 reflog
+
+Expose the local reflog. This may go away.
+
+=cut
+
+sub reflog : Local {
+ my ( $self, $c ) = @_;
+
+ my @log = $c->model('Git')->reflog(
+ '--since=yesterday'
+ );
+
+ $c->stash(
+ log => \@log,
+ action => 'reflog',
+ );
+}
+
=head2 auto
Populate the header and footer. Perhaps not the best location.