Remove Repository->list_tree.
Zachary Stevens [Sat, 26 Jun 2010 19:50:26 +0000 (20:50 +0100)]
The list is available via Tree->tree, so use that instead.

lib/Gitalist/Controller/Fragment/Ref.pm
lib/Gitalist/Git/Object/Commit.pm
lib/Gitalist/Git/Repository.pm
t/02git_Repository.t
t/02git_object.t

index e03bb22..3485d24 100644 (file)
@@ -48,13 +48,13 @@ after tree => sub {
     my ( $self, $c ) = @_;
     my $repository = $c->stash->{Repository};
     my $commit  = $c->stash->{Commit};
-    my $tree    = $c->stash->{filename}
+    my $tree_obj    = $c->stash->{filename}
       ? $repository->get_object($commit->sha_by_path($c->stash->{filename}))
-      : $repository->get_object($commit->tree_sha1)
+      : $commit->tree->[0]
     ;
     $c->stash(
-        tree      => $tree,
-        tree_list => [$repository->list_tree($tree->sha1)],
+        tree      => $tree_obj,
+        tree_list => $tree_obj->tree,
     );
 };
 
index 5d3cdd3..e9350a9 100644 (file)
@@ -23,6 +23,10 @@ class Gitalist::Git::Object::Commit
                                       ],
                          );
 
+        method _build_tree {
+            return [$self->repository->get_object($self->tree_sha1)];
+        }
+
         method sha_by_path ($path) {
             $path =~ s{/+$}();
             # FIXME should this really just take the first result?
index 06d3914..ffc0e89 100644 (file)
@@ -88,12 +88,6 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
         return $sha1;
     }
 
-    method list_tree (SHA1 $sha1?) {
-        $sha1 ||= $self->head_hash;
-        my $object = $self->get_object($sha1);
-        return @{$object->tree};
-    }
-
     method get_object (NonEmptySimpleStr $sha1) {
         unless (is_SHA1($sha1)) {
             $sha1 = $self->head_hash($sha1);
@@ -377,12 +371,6 @@ Hashref of ArrayRefs for each reference.
 
 Return the sha1 for HEAD, or any specified head.
 
-=head2 list_tree ($sha1?)
-
-Return an array of contents for a given tree.
-The tree is specified by sha1, and defaults to HEAD.
-Each item is a L<Gitalist::Git::Object>.
-
 =head2 get_object ($sha1)
 
 Return an appropriate subclass of L<Gitalist::Git::Object> for the given sha1.
index 0d4de4b..e60f0bf 100644 (file)
@@ -58,9 +58,6 @@ is($proj->head_hash, '36c6c6708b8360d7023e8a1649c45bcf9b3bd818', 'head_hash for
 is($proj->head_hash('refs/heads/master'), '36c6c6708b8360d7023e8a1649c45bcf9b3bd818', 'head_hash for refs/heads/master is correct');
 is($proj->head_hash('rafs/head/mister'), undef, 'head_hash for rafs/head/mister is undef');
 
-is(scalar $proj->list_tree, 2, 'expected number of entries in tree');
-isa_ok(($proj->list_tree)[1], 'Gitalist::Git::Object');
-
 # Return an ::Object from a sha1
 my $obj1 = $proj->get_object('729a7c3f6ba5453b42d16a43692205f67fb23bc1');
 isa_ok($obj1, 'Gitalist::Git::Object::Tree');
index 6e71fca..f3dd216 100644 (file)
@@ -65,6 +65,7 @@ my $commit_obj = Gitalist::Git::Object::Commit->new(
     sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e',
 );
 isa_ok($commit_obj, 'Gitalist::Git::Object::Commit', "commit object");
+isa_ok($commit_obj->tree->[0], 'Gitalist::Git::Object::Tree');
 my ($tree, $patch) = $commit_obj->diff(
     patch => 1,
 );