Tidied up the /blob action and the commit-nav.tt2 links.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
index 6b946ab..06c0a8e 100644 (file)
@@ -27,7 +27,6 @@ Gitalist::Controller::Root - Root Controller for Gitalist
 =cut
 
 use IO::Capture::Stdout;
-use File::Slurp qw(slurp);
 
 =head2 run_gitweb
 
@@ -92,13 +91,21 @@ The blob action i.e the contents of a file.
 sub blob : Local {
   my ( $self, $c ) = @_;
 
+  my $h  = $c->req->param('h')
+       || $c->model('Git')->hash_by_path($c->req->param('f'))
+       || die "No file or sha1 provided.";
+  my $hb = $c->req->param('hb')
+       || $c->model('Git')->head_hash
+       || die "Couldn't discern the corresponding head.";
+
   $c->stash(
-    blob   => $c->model('GPP')->get_object($c->req->param('h'))->content,
-    action => 'blob',
+    blob     => $c->model('Git')->get_object($h)->content,
+    head     => $c->model('Git')->get_object($hb),
+    filename => $c->req->param('f') || '',
+    action   => 'blob',
   );
 
-  $c->forward('View::Syntax')
-    if $c->req->param('f') and $c->req->param('f') =~ /\.p[lm]$/;
+  $c->forward('View::SyntaxHighlight');
 }
 
 =head2 reflog
@@ -130,7 +137,7 @@ sub commit : Local {
   my ( $self, $c ) = @_;
 
   $c->stash(
-      commit => $c->model('GPP')->get_object($c->req->param('h')),
+      commit => $c->model('Git')->get_object($c->req->param('h')),
       action => 'commit',
   );
 }
@@ -144,6 +151,10 @@ Populate the header and footer. Perhaps not the best location.
 sub auto : Private {
     my($self, $c) = @_;
 
+    # XXX Temp hack until a decent solution is invented.
+    $c->model('Git')->project($c->req->param('p'))
+      if $c->req->param('p');
+
     # Yes, this is hideous.
     $self->header($c);
     $self->footer($c);