Straightened up the model test and corresponding code.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
index ef231b3..bcdc3d0 100644 (file)
@@ -46,11 +46,11 @@ sub run_gitweb {
       $action->();
     };
     $capture->stop();
-    
+
     use Data::Dumper;
     die Dumper($@)
       if $@;
-  
+
     my $output = join '', $capture->read;
     $c->stash->{gitweb_output} = $output;
     $c->stash->{template} = 'gitweb.tt2';
@@ -58,9 +58,9 @@ sub run_gitweb {
 }
 
 sub _get_commit {
-  my($self, $c) = @_;
+  my($self, $c, $haveh) = @_;
 
-  my $h = $c->req->param('h');
+  my $h = $haveh || $c->req->param('h') || '';
   my $f = $c->req->param('f');
   my $m = $c->model('Git');
 
@@ -71,7 +71,7 @@ sub _get_commit {
           # XXX This could definitely use more context.
           || Carp::croak("Couldn't find a hash for the commit object!");
 
-    
+
   (my $pd = $m->project_dir( $m->project )) =~ s{/\.git$}();
   my $commit = $m->get_object($hash)
     or Carp::croak("Couldn't find a commit object for '$hash' in '$pd'!");
@@ -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',
   );
@@ -266,7 +273,7 @@ sub shortlog : Local {
       log_lines => [$c->model('Git')->list_revs(%logargs)],
       refs      => $c->model('Git')->references,
       action    => 'shortlog',
-      page      => $page + 1,
+      page      => $page,
   );
 }
 
@@ -289,12 +296,14 @@ The tree of a given commit.
 sub tree : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $self->_get_commit($c);
+  my $commit = $self->_get_commit($c, $c->req->param('hb'));
+  my $tree   = $c->model('Git')->get_object($c->req->param('h') || $commit->tree_sha1);
   $c->stash(
       # XXX Useful defaults needed ...
       commit    => $commit,
-      tree      => $c->model('Git')->get_object($c->req->param('hb')),
-      tree_list => [$c->model('Git')->list_tree($commit->sha1)],
+      tree      => $tree,
+      tree_list => [$c->model('Git')->list_tree($tree->sha1)],
+         path      => $c->req->param('f') || '',
       action    => 'tree',
   );
 }
@@ -318,6 +327,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.
@@ -415,7 +432,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' ),