3 class Gitalist::Git::Project {
4 # FIXME, use Types::Path::Class and coerce
5 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
9 has name => ( isa => NonEmptySimpleStr,
11 has path => ( isa => "Path::Class::Dir",
14 has description => ( isa => NonEmptySimpleStr,
18 has owner => ( isa => NonEmptySimpleStr,
22 has last_change => ( isa => 'DateTime',
28 method _build_description {
29 my $description = $self->path->file('description')->slurp;
35 my $owner = (getpwuid $self->path->stat->uid)[6];
40 method _build_last_change {
42 my $output = $self->run_cmd(
43 qw{ for-each-ref --format=%(committer)
44 --sort=-committerdate --count=1 refs/heads
46 if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) {
47 my $dt = DateTime->from_epoch(epoch => $epoch);
48 $dt->set_time_zone($tz);
57 Call out to the C<git> binary and return a string consisting of the output.
61 method run_cmd (@args) {
62 unshift @args, ( '--git-dir' => $self->path );
63 print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
65 open my $fh, '-|', $self->_git, @args
66 or die "failed to run git command";
67 binmode $fh, ':encoding(UTF-8)';
69 my $output = do { local $/ = undef; <$fh> };
75 has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
78 my $git = File::Which::which('git');
82 Could not find a git executable.
83 Please specify the which git executable to use in gitweb.yml
89 has _gpp => ( isa => 'Git::PurePerl', is => 'rw', lazy_build => 1 );
92 my $gpp = Git::PurePerl->new(gitdir => $self->path);
96 method project_dir (Path::Class::Dir $project) {
97 my $dir = $project->stringify;
99 if -f dir($dir)->file('.git/HEAD');
108 Returns a hash containing properties of this project. The keys will
112 description (empty if .git/description is empty/unnamed)
118 method project_info {
121 description => $self->description,
122 owner => $self->owner,
123 last_change => $self->last_change,