Introduce ::Object::Commit.
[catagits/Gitalist.git] / lib / Gitalist / Git / Project.pm
index 1548e00..36615f0 100644 (file)
@@ -26,6 +26,7 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
     use MooseX::Types::Moose qw/Str Maybe Bool HashRef ArrayRef/;
     use List::MoreUtils qw/any zip/;
     use DateTime;
+    use Gitalist::Git::Object::Commit;
     use aliased 'Gitalist::Git::Object';
 
     our $SHA1RE = qr/[0-9a-fA-F]{40}/;
@@ -151,21 +152,8 @@ Each item is a L<Gitalist::Git::Object>.
 =cut
     method list_tree (Str $sha1?) {
         $sha1 ||= $self->head_hash;
-
-        my $output = $self->run_cmd(qw/ls-tree -z/, $sha1);
-        return unless defined $output;
-
-        my @ret;
-        for my $line (split /\0/, $output) {
-            my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
-            push @ret, Object->new( mode => oct $mode,
-                                    type => $type,
-                                    sha1 => $object,
-                                    file => $file,
-                                    project => $self,
-                                  );
-        }
-        return @ret;
+        my $object = $self->get_object($sha1);
+        return @{$object->tree};
     }
 
 =head2 get_object ($sha1)
@@ -177,7 +165,13 @@ Return a L<Gitalist::Git::Object> for the given sha1.
         unless ( $self->_is_valid_rev($sha1) ) {
             $sha1 = $self->head_hash($sha1);
         }
-        return Object->new(
+        my $type = $self->run_cmd('cat-file', '-t', $sha1);
+        chomp($type);
+        my $class = 'Gitalist::Git::Object';
+        if ($type eq 'commit') {
+            $class .= '::' . ucfirst($type);
+        };
+        return $class->new(
             project => $self,
             sha1 => $sha1,
         );
@@ -316,13 +310,12 @@ FIXME Should this return objects?
     }
 
     method _build_description {
+        my $description = "";
         eval {
-            return $self->gpp->description;
+            $description = $self->path->file('description')->slurp;
+            chomp $description;
         };
-        if ($@) {
-            return "Unnamed repository.";
-        }
-
+        return $description;
     }
 
     method _build_owner {