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;
10 our $SHA1RE = qr/[0-9a-fA-F]{40}/;
12 has name => ( isa => NonEmptySimpleStr,
14 has path => ( isa => "Path::Class::Dir",
17 has description => ( isa => NonEmptySimpleStr,
21 has owner => ( isa => NonEmptySimpleStr,
25 has last_change => ( isa => 'DateTime',
29 has _util => ( isa => 'Gitalist::Git::Util',
32 handles => [ 'run_cmd' ],
36 my $util = Gitalist::Git::Util->new(
37 gitdir => $self->path,
42 method _build_description {
43 my $description = $self->path->file('description')->slurp;
49 my $owner = (getpwuid $self->path->stat->uid)[6];
54 method _build_last_change {
56 my $output = $self->run_cmd(
57 qw{ for-each-ref --format=%(committer)
58 --sort=-committerdate --count=1 refs/heads
60 if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) {
61 my $dt = DateTime->from_epoch(epoch => $epoch);
62 $dt->set_time_zone($tz);
70 Find the hash of a given head (defaults to HEAD).
74 method head_hash (Str $head?) {
75 my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' );
76 return unless defined $output;
78 my($sha1) = $output =~ /^($SHA1RE)$/;
82 method project_dir (Path::Class::Dir $project) {
83 my $dir = $project->stringify;
85 if -f dir($dir)->file('.git/HEAD');
93 Returns a hash containing properties of this project. The keys will
97 description (empty if .git/description is empty/unnamed)
103 method project_info {
106 description => $self->description,
107 owner => $self->owner,
108 last_change => $self->last_change,