3 class Gitalist::Git::Project {
4 # FIXME, use Types::Path::Class and coerce
5 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
8 use Gitalist::Git::Util;
9 use aliased 'Gitalist::Git::Object';
11 our $SHA1RE = qr/[0-9a-fA-F]{40}/;
13 has name => ( isa => NonEmptySimpleStr,
15 has path => ( isa => "Path::Class::Dir",
18 has description => ( isa => NonEmptySimpleStr,
22 has owner => ( isa => NonEmptySimpleStr,
26 has last_change => ( isa => 'DateTime',
30 has _util => ( isa => 'Gitalist::Git::Util',
33 handles => [ 'run_cmd' ],
37 my $util = Gitalist::Git::Util->new(
38 gitdir => $self->path,
43 method _build_description {
44 my $description = $self->path->file('description')->slurp;
50 my $owner = (getpwuid $self->path->stat->uid)[6];
55 method _build_last_change {
57 my $output = $self->run_cmd(
58 qw{ for-each-ref --format=%(committer)
59 --sort=-committerdate --count=1 refs/heads
61 if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) {
62 my $dt = DateTime->from_epoch(epoch => $epoch);
63 $dt->set_time_zone($tz);
71 Find the hash of a given head (defaults to HEAD).
75 method head_hash (Str $head?) {
76 my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' );
77 return unless defined $output;
79 my($sha1) = $output =~ /^($SHA1RE)$/;
85 Return an array of contents for a given tree.
86 The tree is specified by sha1, and defaults to HEAD.
87 The keys for each item will be:
96 method list_tree (Str $sha1?) {
97 $sha1 ||= $self->head_hash;
99 my $output = $self->run_cmd(qw/ls-tree -z/, $sha1);
100 return unless defined $output;
103 for my $line (split /\0/, $output) {
104 my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
105 push @ret, Object->new( mode => oct $mode,
116 my $dir = $self->path->stringify;
118 if -f dir($dir)->file('.git/HEAD');
126 Returns a hash containing properties of this project. The keys will
130 description (empty if .git/description is empty/unnamed)
139 description => $self->description,
140 owner => $self->owner,
141 last_change => $self->last_change,