Take format from the right parameter, default to tgz, check against
[catagits/Gitalist.git] / lib / Gitalist / Git / Project.pm
index 57d46bb..5ef414d 100644 (file)
@@ -26,9 +26,10 @@ 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 Gitalist::Git::Object::Blob;
-    use aliased 'Gitalist::Git::Object';
+    use Gitalist::Git::Object::Tree;
+    use Gitalist::Git::Object::Commit;
+    use Gitalist::Git::Object::Tag;
 
     our $SHA1RE = qr/[0-9a-fA-F]{40}/;
 
@@ -159,7 +160,7 @@ Each item is a L<Gitalist::Git::Object>.
 
 =head2 get_object ($sha1)
 
-Return a L<Gitalist::Git::Object> for the given sha1.
+Return an appropriate subclass of L<Gitalist::Git::Object> for the given sha1.
 
 =cut
     method get_object (NonEmptySimpleStr $sha1) {
@@ -168,12 +169,8 @@ Return a L<Gitalist::Git::Object> for the given sha1.
         }
         my $type = $self->run_cmd('cat-file', '-t', $sha1);
         chomp($type);
-        my $class = 'Gitalist::Git::Object';
-        use Moose::Autobox;
-        if ($type eq ['commit', 'blob']->any) {
-            $class .= '::' . ucfirst($type);
-        };
-        return $class->new(
+        my $class = 'Gitalist::Git::Object::' . ucfirst($type);
+        $class->new(
             project => $self,
             sha1 => $sha1,
             type => $type,
@@ -241,6 +238,19 @@ Returns a list of revs for the given head ($sha1).
         return @revs;
     }
 
+=head2 snapshot($head?, $format)
+
+Generate an archived snapshot of the repository.
+Returns a filehandle to read from.
+
+=cut
+
+method snapshot (Gitalist::Git::Object :$commit,
+                 NonEmptySimpleStr :$format
+               ) {
+               return $commit->snapshot;
+           }
+
 =head2 diff($commit, $patch?, $parent?, $file?)
 
 Generate a diff from a given L<Gitalist::Git::Object>.