| 1 | package VCI::VCS::Git::Project; | ||
| 2 | use Moose; | ||
| 3 | |||
| 4 | use Cwd qw(abs_path); | ||
| 5 | use Git (); | ||
| 6 | |||
| 7 | extends 'VCI::Abstract::Project'; | ||
| 8 | |||
| 9 | has 'x_git' => (is => 'ro', isa => 'Git', lazy_build => 1); | ||
| 10 | |||
| 11 | sub BUILD { | ||
| 12 | my $self = shift; | ||
| 13 | $self->_name_never_ends_with_slash(); | ||
| 14 | $self->_name_never_starts_with_slash(); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub _build_x_git { | ||
| 18 | my $self = shift; | ||
| 19 | my $repo = Git->repository(abs_path($self->repository->root) . '/' | ||
| 20 | . $self->name); | ||
| 21 | if ($self->vci->debug) { | ||
| 22 | print STDERR "Connected to Git, Version: " . $repo->version . "\n"; | ||
| 23 | } | ||
| 24 | return $repo; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub x_do { | ||
| 28 | my ($self, $command, $args, $as_string) = @_; | ||
| 29 | $args ||= []; | ||
| 30 | my $git = $self->x_git; | ||
| 31 | if ($self->vci->debug) { | ||
| 32 | print STDERR "Calling [" . $git->exec_path . "/git $command " | ||
| 33 | . join(' ', @$args) . "] on [" . $git->repo_path . "]\n"; | ||
| 34 | } | ||
| 35 | if ($as_string) { | ||
| 36 | return scalar $git->command($command, @$args); | ||
| 37 | } | ||
| 38 | return [$git->command($command, @$args)]; | ||
| 39 | } | ||
| 40 | |||
| 41 | # Because git is so fast with individual operations, we don't pull in | ||
| 42 | # every log detail for the whole history with this, like we do for other | ||
| 43 | # drivers. We just get the list of revision IDs and then the commits can | ||
| 44 | # populate themselves. | ||
| 45 | sub _build_history { | ||
| 46 | my $self = shift; | ||
| 47 | my $lines = $self->x_do('log', | ||
| 48 | ['--pretty=format:%H%n%cD%n%cn <%ce>%n%an <%ae>%n', '--reverse', '-m'], | ||
| 49 | 1); | ||
| 50 | my @messages = split("\n\n", $lines); | ||
| 51 | my @commits; | ||
| 52 | foreach my $message (@messages) { | ||
| 53 | my ($id, $time, $committer, $author) = split("\n", $message); | ||
| 54 | # Times start with "Wed" or "Thu", etc., which Date::Parse can't handle. | ||
| 55 | $time =~ s/^\w{3}, //; | ||
| 56 | push(@commits, $self->commit_class->new(revision => $id, | ||
| 57 | time => $time, committer => $committer, author => $author, | ||
| 58 | project => $self)); | ||
| 59 | } | ||
| 60 | return $self->history_class->new(commits => \@commits, project => $self); | ||
| 61 | } | ||
| 62 | |||
| 63 | __PACKAGE__->meta->make_immutable; | ||
| 64 | |||
| 65 | 1; |