| 1 | # ABSTRACT: Revert stack to a prior revision | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Action::Revert; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MooseX::Types::Moose qw(Bool); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Pinto::Util qw(throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Pinto::Types qw(RevisionID RevisionHead); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | extends qw( Pinto::Action ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | with qw( Pinto::Role::Committable ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | has revision => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | isa => RevisionID | RevisionHead, | ||||||||||||||||||||||||||||
| 30 | default => undef, | ||||||||||||||||||||||||||||
| 31 | coerce => 1, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | has force => ( | |||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||
| 36 | isa => Bool, | ||||||||||||||||||||||||||||
| 37 | default => 0, | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # Remember that the Committable role has already moved the head | ||||||||||||||||||||||||||||
| 46 | # forward to a new revision which is a duplicate of the last head. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $stack = $self->stack; | |||||||||||||||||||||||||||
| 49 | 0 | my $new_head = $stack->head; | |||||||||||||||||||||||||||
| 50 | 0 | my $old_head = ($new_head->parents)[0]; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $rev = $self->revision | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | ? $self->repo->get_revision($self->revision) | ||||||||||||||||||||||||||||
| 54 | : ($old_head->parents)[0]; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | throw "Cannot revert past the root commit" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | if not $rev; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | throw "Revision $rev is the head of stack $stack" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | if $rev eq $old_head; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | throw "Revision $rev is not an ancestor of stack $stack" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rev->is_ancestor_of($old_head) or $self->force
MC/DC0%0/2
$rev->is_ancestor_of($old_head) or $self->force
$rev->is_ancestor_of($old_head)
$self->force
Truth table0%0/3
A or B
A= $rev->is_ancestor_of($old_head)B= $self->force
| |||||||||||||||||||||||||||||
| 63 | if !$rev->is_ancestor_of($old_head) && !$self->force; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $new_head->registrations_rs->delete; | |||||||||||||||||||||||||||
| 66 | 0 | $stack->duplicate_registrations(to => $new_head, from => $rev); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # We must explicitly mark the stack as changed, snce we injected the | ||||||||||||||||||||||||||||
| 69 | # registrations directly. But it is possible that the new state is | ||||||||||||||||||||||||||||
| 70 | # exactly the same as the old state. So we use the diff to be sure. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $stack->diff->is_different | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | ? $stack->mark_as_changed | ||||||||||||||||||||||||||||
| 74 | : throw "Revision $rev is identical to the head of stack $stack"; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | return 1; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub generate_message_title { | ||||||||||||||||||||||||||
|
Subroutine
generate_message_title: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # TODO: fix duplication... | ||||||||||||||||||||||||||||
| 85 | 0 | my $stack = $self->stack; | |||||||||||||||||||||||||||
| 86 | 0 | my $new_head = $stack->head; | |||||||||||||||||||||||||||
| 87 | 0 | my $old_head = ($new_head->parents)[0]; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $rev = $self->revision | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | ? $self->repo->get_revision($self->revision) | ||||||||||||||||||||||||||||
| 91 | : ($old_head->parents)[0]; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | return sprintf "Revert to %s: %s", $rev->uuid_prefix, $rev->message_title; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||