use DateTime;
use Path::Class;
use Gitalist::Git::Util;
+ use aliased 'Gitalist::Git::Object';
our $SHA1RE = qr/[0-9a-fA-F]{40}/;
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;
# Compatibility
-=head2 project_info
+=head2 info
Returns a hash containing properties of this project. The keys will
be:
=cut
- method project_info {
+ method info {
return {
name => $self->name,
description => $self->description,