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';
our $SHA1RE = qr/[0-9a-fA-F]{40}/;
=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)
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';
+ use Moose::Autobox;
+ if ($type eq ['commit', 'blob']->any) {
+ $class .= '::' . ucfirst($type);
+ };
+ return $class->new(
project => $self,
sha1 => $sha1,
+ type => $type,
);
}
Int :$count?,
Int :$skip?,
HashRef :$search?,
- NonEmptySimpleStr :$file?
- ) {
+ NonEmptySimpleStr :$file? ) {
$sha1 = $self->head_hash($sha1)
if !$sha1 || $sha1 !~ $SHA1RE;
my @search_opts;
- if($search) {
+ if ($search) {
$search->{type} = 'grep'
if $search->{type} eq 'commit';
@search_opts = (
= $self->run_cmd(qw(log -g), @logargs)
=~ /(^commit.+?(?:(?=^commit)|(?=\z)))/msg;
-# commit 02526fc15beddf2c64798a947fecdd8d11bf993d
-# Reflog: HEAD@{14} (The Git Server <git@git.dev.venda.com>)
-# Reflog message: push
-# Author: Foo Barsby <fbarsby@example.com>
-# Date: Thu Sep 17 12:26:05 2009 +0100
-#
-# Merge branch 'abc123'
+ # commit 02526fc15beddf2c64798a947fecdd8d11bf993d
+ # Reflog: HEAD@{14} (The Git Server <git@git.dev.venda.com>)
+ # Reflog message: push
+ # Author: Foo Barsby <fbarsby@example.com>
+ # Date: Thu Sep 17 12:26:05 2009 +0100
+ #
+ # Merge branch 'abc123'
return map {
# XXX Stuff like this makes me want to switch to Git::PurePerl
}
method _build_description {
- return $self->gpp->description;
+ my $description = "";
+ eval {
+ $description = $self->path->file('description')->slurp;
+ chomp $description;
+ };
+ return $description;
}
method _build_owner {
# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
my @reflist = $self->run_cmd_list(qw(show-ref --dereference))
- or return;
+ or return;
my %refs;
- for(@reflist) {
- push @{$refs{$1}}, $2
- if m!^($SHA1RE)\srefs/(.*)$!;
- }
+ for (@reflist) {
+ push @{$refs{$1}}, $2
+ if m!^($SHA1RE)\srefs/(.*)$!;
+ }
- return \%refs;
+ return \%refs;
}
## Private methods