Fixed links in the wrapper template and added stubs for the next actions to be implem...
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
index 0a7e807..9ec74e1 100644 (file)
@@ -117,10 +117,11 @@ sub summary : Local {
   $c->stash(
     commit    => $commit,
     info      => $c->model('Git')->project_info($c->model('Git')->project),
-    log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1, count => 16)],
+    log_lines => [$c->model('Git')->list_revs(
+      sha1 => $commit->sha1, count => Gitalist->config->{paging}{summary}
+    )],
     refs      => $c->model('Git')->references,
     heads     => [$c->model('Git')->heads],
-    HEAD      => $c->model('Git')->head_hash,
     action    => 'summary',
   );
 }
@@ -137,7 +138,6 @@ sub heads : Local {
   $c->stash(
     commit => $self->_get_commit($c),
     heads  => [$c->model('Git')->heads],
-    HEAD   => $c->model('Git')->head_hash,
     action => 'heads',
   );
 }
@@ -184,14 +184,17 @@ sub blobdiff : Local {
   my $commit = $self->_get_commit($c);
   my $filename = $c->req->param('f')
               || croak("No file specified!");
-  my @diff = $c->model('Git')->diff(
-    $commit->parent_sha1, $commit->sha1, '--', $filename
+  my($tree, $patch) = $c->model('Git')->diff(
+    commit => $commit,
+    parent => $c->req->param('hp') || '',
+    file   => $filename,
+    patch  => 1,
   );
   $c->stash(
     commit    => $commit,
-    diff      => \@diff,
+    diff      => $patch,
     # XXX Hack hack hack, see View::SyntaxHighlight
-    blobs     => [$diff[0]->{diff}],
+    blobs     => [$patch->[0]->{diff}],
     language  => 'Diff',
     action    => 'blobdiff',
   );
@@ -211,7 +214,7 @@ sub commit : Local {
   my $commit = $self->_get_commit($c);
   $c->stash(
       commit      => $commit,
-      diff_tree   => [$c->model('Git')->diff_tree($commit)],
+      diff_tree   => ($c->model('Git')->diff(commit => $commit))[0],
       branches_on => [$c->model('Git')->refs_for($commit->sha1)],
       action      => 'commit',
   );
@@ -227,13 +230,17 @@ sub commitdiff : Local {
   my ( $self, $c ) = @_;
 
   my $commit = $self->_get_commit($c);
-  my @difflist = $c->model('Git')->diff($commit->parent_sha1, $commit->sha1);
+  my($tree, $patch) = $c->model('Git')->diff(
+      commit => $commit,
+      parent => $c->req->param('hp') || '',
+      patch  => 1,
+  );
   $c->stash(
     commit    => $commit,
-    diff_tree => [$c->model('Git')->diff_tree($commit)],
-    diff      => \@difflist,
+    diff_tree => $tree,
+    diff      => $patch,
     # XXX Hack hack hack, see View::SyntaxHighlight
-    blobs     => [map $_->{diff}, @difflist],
+    blobs     => [map $_->{diff}, @$patch],
     language  => 'Diff',
     action    => 'commitdiff',
   );
@@ -250,13 +257,23 @@ Expose an abbreviated log of a given sha1.
 sub shortlog : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $self->_get_commit($c);
-  # XXX Needs paging.
+  my $commit  = $self->_get_commit($c);
+  my %logargs = (
+      sha1   => $commit->sha1,
+      count  => Gitalist->config->{paging}{log},
+      ($c->req->param('f') ? (file => $c->req->param('f')) : ())
+  );
+
+  my $page = $c->req->param('pg') || 0;
+  $logargs{skip} = $c->req->param('pg') * $logargs{count}
+    if $c->req->param('pg');
+
   $c->stash(
       commit    => $commit,
-      log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1)],
+      log_lines => [$c->model('Git')->list_revs(%logargs)],
       refs      => $c->model('Git')->references,
       action    => 'shortlog',
+      page      => $page + 1,
   );
 }
 
@@ -308,6 +325,14 @@ sub reflog : Local {
   );
 }
 
+sub search : Local {
+    Carp::croak "Not implemented.";
+}
+
+sub search_help : Local {
+    Carp::croak "Not implemented.";
+}
+
 =head2 auto
 
 Populate the header and footer. Perhaps not the best location.
@@ -317,10 +342,6 @@ 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);
@@ -409,7 +430,7 @@ sub header {
 
   if(defined $project) {
     $c->stash(
-      search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
+      search_text => ( $c->req->param('s') || $c->req->param('searchtext') || ''),
       search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
           || $c->req->param('h')  || $c->req->param('hash')
           || 'HEAD' ),
@@ -508,7 +529,10 @@ Attempt to render a view, if needed.
 
 =cut
 
-sub end : ActionClass('RenderView') {}
+sub end : ActionClass('RenderView') {
+  # Give every view the current HEAD.
+  $_[1]->stash->{HEAD} = $_[1]->model('Git')->head_hash;
+}
 
 =head1 AUTHOR