Gave ownership of URLs to Gitalist proper.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
index 4b2dcf2..dc79c49 100644 (file)
@@ -57,6 +57,22 @@ sub run_gitweb {
   }
 }
 
+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.
@@ -91,7 +107,7 @@ 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),
@@ -111,7 +127,7 @@ 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],
     action => 'heads',
   );
@@ -143,25 +159,6 @@ sub blob : Local {
   $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.
@@ -171,7 +168,7 @@ 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)],
@@ -189,7 +186,7 @@ Exposes a given diff of a 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)],
@@ -207,7 +204,7 @@ 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,
@@ -235,16 +232,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.