Remove Repository->list_tree.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Fragment / Ref.pm
index f110803..3485d24 100644 (file)
@@ -15,20 +15,21 @@ sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
 
 sub _diff {
     my ($self, $c) = @_;
-    my $commit = $c->stash->{Commit};
-    my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : ();
-    my($tree, $patch) = $c->stash->{Repository}->diff(
-        commit => $commit,
-        parent => $c->stash->{parent},
-        patch  => 1,
-        %filename,
+    my %diff_args = ( patch => 1 );
+    foreach my $arg qw/filename parent/ {
+        if (defined $c->stash->{$arg}) {
+            $diff_args{$arg} = $c->stash->{$arg};
+        };
+    };
+    my ($tree, $patch) = $c->stash->{Commit}->diff(
+        %diff_args,
     );
     $c->stash(
       diff_tree => $tree,
       diff      => $patch,
       # XXX Hack hack hack, see View::SyntaxHighlight
       blobs     => [map $_->{diff}, @$patch],
-      %filename,
+      %diff_args,
     );
 }
 
@@ -47,13 +48,13 @@ after tree => sub {
     my ( $self, $c ) = @_;
     my $repository = $c->stash->{Repository};
     my $commit  = $c->stash->{Commit};
-    my $tree    = $c->stash->{filename}
-      ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
-      : $repository->get_object($commit->tree_sha1)
+    my $tree_obj    = $c->stash->{filename}
+      ? $repository->get_object($commit->sha_by_path($c->stash->{filename}))
+      : $commit->tree->[0]
     ;
     $c->stash(
-        tree      => $tree,
-        tree_list => [$repository->list_tree($tree->sha1)],
+        tree      => $tree_obj,
+        tree_list => $tree_obj->tree,
     );
 };
 
@@ -97,12 +98,8 @@ after history => sub {
        ($filename ? (file => $filename) : ())
     );
 
-    my $file = $repository->get_object(
-        $repository->hash_by_path(
-            $repository->head_hash,
-            $filename
-        )
-    );
+    my $commit = $repository->get_object('HEAD');
+    my $file = $repository->get_object($commit->sha_by_path($filename));
 
     my $page = $c->req->param('pg') || 0;
     $logargs{skip} = $c->req->param('pg') * $logargs{count}
@@ -127,9 +124,13 @@ after file_commit_info => sub {
        file   => $c->stash->{filename},
     );
 
-    my $json_obj = $commit
-                 ? { sha1 => $commit->sha1, comment => $c->stash->{short_cmt}->($commit->comment) }
-                 : { };
+    my $json_obj = !$commit
+                 ? { }
+                 : {
+                     sha1    => $commit->sha1,
+                     comment => $c->stash->{short_cmt}->($commit->comment),
+                     age     => $c->stash->{time_since}->($commit->authored_time),
+                 };
 
     $c->response->content_type('application/json');
     # XXX Make use of the json branch