X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FProject.pm;h=eda7d6d92268d6a2949b92e9d9b0f7db2d024941;hb=7b0f7465b94acf7a928f382f4fa26c491c280445;hp=3fdce700e6aaf6e0c1a844af68d617873133b3d9;hpb=4baaeeef25fc50f1a3bf14abce71c713ccd891ec;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Project.pm b/lib/Gitalist/Git/Project.pm index 3fdce70..eda7d6d 100644 --- a/lib/Gitalist/Git/Project.pm +++ b/lib/Gitalist/Git/Project.pm @@ -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,