X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FController%2FRoot.pm;h=ff5efac078c691cd000d7dbf715974b8fc5a7441;hb=0ee97fecd5bcbf5c315cee1988e3abd66a1b0840;hp=2a9dba3649ff987b0427fe089e3ad947fe16deca;hpb=790ce598d0ac726b53efa513bb4993a71880a6a5;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm index 2a9dba3..ff5efac 100644 --- a/lib/Gitalist/Controller/Root.pm +++ b/lib/Gitalist/Controller/Root.pm @@ -57,6 +57,25 @@ sub run_gitweb { } } +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. @@ -91,12 +110,14 @@ A summary of what's happening in the repo. 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', ); } @@ -111,8 +132,9 @@ sub heads : Local { 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', ); } @@ -143,40 +165,39 @@ sub blob : Local { $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', ); } @@ -189,11 +210,12 @@ Expose an abbreviated log of a given sha1. 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', ); } @@ -217,16 +239,35 @@ The tree of a given 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.