}
}
+sub _get_commit {
+ my($self, $c) = @_;
+
+ my $h = $c->req->param('h');
+ my $f = $c->req->param('f');
+
+ # Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD.
+ my $hash = ($h =~ /[^a-f0-9]/ ? $c->model('Git')->head_hash($h) : $h)
+ || ($f && $c->model('Git')->hash_by_path($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),
- log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1, count => 17)],
+ log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1, count => 16)],
+ refs => $c->model('Git')->references,
heads => [$c->model('Git')->heads],
+ HEAD => $c->model('Git')->head_hash,
action => 'summary',
);
}
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],
+ HEAD => $c->model('Git')->head_hash,
action => 'heads',
);
}
$c->forward('View::SyntaxHighlight');
}
-=head2 reflog
+=head2 commit
-Expose the local reflog. This may go away.
+Exposes a given commit.
=cut
-sub reflog : Local {
+sub commit : Local {
my ( $self, $c ) = @_;
- my @log = $c->model('Git')->reflog(
- '--since=yesterday'
- );
-
+ my $commit = $self->_get_commit($c);
$c->stash(
- log => \@log,
- action => 'reflog',
+ commit => $commit,
+ diff_tree => [$c->model('Git')->diff_tree($commit)],
+ branches_on => [$c->model('Git')->refs_for($commit->sha1)],
+ action => 'commit',
);
}
-=head2 commit
+=head2 commitdiff
-Exposes a given commit.
+Exposes a given diff of a commit.
=cut
-sub commit : Local {
+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)],
- branches_on => [$c->model('Git')->refs_for($commit->sha1)],
- action => 'commit',
+ diff => [$c->model('Git')->diff($commit->parent_sha1, $commit->sha1)],
+ action => 'commitdiff',
);
}
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,
- log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1)],
+ log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1)],
+ refs => $c->model('Git')->references,
action => 'shortlog',
);
}
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.