Start conversion to new model
[catagits/Gitalist.git] / lib / Gitalist / Git / Project.pm
index 3fdce70..eda7d6d 100644 (file)
@@ -6,6 +6,7 @@ class Gitalist::Git::Project {
     use DateTime;
     use Path::Class;
     use Gitalist::Git::Util;
+    use aliased 'Gitalist::Git::Object';
 
     our $SHA1RE = qr/[0-9a-fA-F]{40}/;
     
@@ -79,8 +80,41 @@ Find the hash of a given head (defaults to HEAD).
         return $sha1;
     }
 
-    method project_dir (Path::Class::Dir $project) {
-        my $dir = $project->stringify;
+=head2 list_tree
+
+Return an array of contents for a given tree.
+The tree is specified by sha1, and defaults to HEAD.
+The keys for each item will be:
+
+       mode
+       type
+       object
+       file
+
+=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;
+    }
+
+
+    method project_dir {
+        my $dir = $self->path->stringify;
         $dir .= '/.git'
             if -f dir($dir)->file('.git/HEAD');
         return $dir;
@@ -88,7 +122,7 @@ Find the hash of a given head (defaults to HEAD).
 
     # Compatibility
 
-=head2 project_info
+=head2 info
 
 Returns a hash containing properties of this project. The keys will
 be:
@@ -100,7 +134,7 @@ be:
 
 =cut
 
-    method project_info {
+    method info {
         return {
             name => $self->name,
             description => $self->description,