| 1 | package VCI::VCS::Git::Committable; | ||
| 2 | use Moose::Role; | ||
| 3 | |||
| 4 | has 'x_one_of' => (is => 'ro', isa => 'ArrayRef[Str]', | ||
| 5 | predicate => 'has_x_one_of'); | ||
| 6 | |||
| 7 | sub _build_revision { | ||
| 8 | my $self = shift; | ||
| 9 | |||
| 10 | # When we have a moved or copied file in a "whatchanged", it can | ||
| 11 | # have more than one parent rev. If it does, then we have to figure | ||
| 12 | # out which revision the copied/moved file actually came from. | ||
| 13 | if ($self->has_x_one_of) { | ||
| 14 | my $one_of = $self->x_one_of; | ||
| 15 | return $one_of->[0] if @$one_of == 1; | ||
| 16 | my $path = $self->path->stringify; | ||
| 17 | foreach my $rev (@$one_of) { | ||
| 18 | my $result = eval { | ||
| 19 | $self->project->x_do('rev-parse', ["$rev:$path"]) | ||
| 20 | }; | ||
| 21 | return $rev if defined $result; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | my $head_rev = $self->project->x_do('rev-list', | ||
| 26 | ['--all', '--max-count=1', '--', $self->path->stringify], 1); | ||
| 27 | chomp($head_rev); | ||
| 28 | return $head_rev; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub _build_time { | ||
| 32 | my $self = shift; | ||
| 33 | my $time = $self->project->x_do('log', ['-1', '--pretty=format:%cD', '--', | ||
| 34 | $self->path->stringify], 1); | ||
| 35 | chomp($time); | ||
| 36 | $time =~ s/^\w{3}, //; | ||
| 37 | return $time; | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; |