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 => 'Str',
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->project_dir($self->path),
43 method _build_description {
46 $description = $self->path->file('description')->slurp;
53 my $owner = (getpwuid $self->path->stat->uid)[6];
58 method _build_last_change {
60 my $output = $self->run_cmd(
61 qw{ for-each-ref --format=%(committer)
62 --sort=-committerdate --count=1 refs/heads
64 if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) {
65 my $dt = DateTime->from_epoch(epoch => $epoch);
66 $dt->set_time_zone($tz);
74 Find the hash of a given head (defaults to HEAD).
78 method head_hash (Str $head?) {
79 my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' );
80 return unless defined $output;
82 my($sha1) = $output =~ /^($SHA1RE)$/;
88 Return an array of contents for a given tree.
89 The tree is specified by sha1, and defaults to HEAD.
90 The keys for each item will be:
99 method list_tree (Str $sha1?) {
100 $sha1 ||= $self->head_hash;
102 my $output = $self->run_cmd(qw/ls-tree -z/, $sha1);
103 return unless defined $output;
106 for my $line (split /\0/, $output) {
107 my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
108 push @ret, Object->new( mode => oct $mode,
120 my $dir = $self->path->stringify;
122 if -f dir($dir)->file('.git/HEAD');
130 Returns a hash containing properties of this project. The keys will
134 description (empty if .git/description is empty/unnamed)
143 description => $self->description,
144 owner => $self->owner,
145 last_change => $self->last_change,