line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Revert stack to a prior revision |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Pinto::Action::Revert; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
633
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
6
|
1
|
|
|
1
|
|
6958
|
use MooseX::StrictConstructor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
3137
|
use MooseX::Types::Moose qw(Bool); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
8
|
1
|
|
|
1
|
|
4506
|
use MooseX::MarkAsMethods ( autoclean => 1 ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3509
|
use Pinto::Util qw(throw); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
89
|
|
11
|
1
|
|
|
1
|
|
7
|
use Pinto::Types qw(RevisionID RevisionHead); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.13'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
extends qw( Pinto::Action ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
with qw( Pinto::Role::Committable ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has revision => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => RevisionID | RevisionHead, |
30
|
|
|
|
|
|
|
default => undef, |
31
|
|
|
|
|
|
|
coerce => 1, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has force => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => Bool, |
37
|
|
|
|
|
|
|
default => 0, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub execute { |
43
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $stack = $self->stack; |
49
|
|
|
|
|
|
|
my $new_head = $stack->head; |
50
|
|
|
|
|
|
|
my $old_head = ($new_head->parents)[0]; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $rev = $self->revision |
53
|
|
|
|
|
|
|
? $self->repo->get_revision($self->revision) |
54
|
|
|
|
|
|
|
: ($old_head->parents)[0]; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
throw "Cannot revert past the root commit" |
57
|
|
|
|
|
|
|
if not $rev; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
throw "Revision $rev is the head of stack $stack" |
60
|
|
|
|
|
|
|
if $rev eq $old_head; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
throw "Revision $rev is not an ancestor of stack $stack" |
63
|
|
|
|
|
|
|
if !$rev->is_ancestor_of($old_head) && !$self->force; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$new_head->registrations_rs->delete; |
66
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
$stack->diff->is_different |
73
|
|
|
|
|
|
|
? $stack->mark_as_changed |
74
|
|
|
|
|
|
|
: throw "Revision $rev is identical to the head of stack $stack"; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub generate_message_title { |
82
|
4
|
|
|
4
|
0
|
12
|
my ($self) = @_; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# TODO: fix duplication... |
85
|
4
|
|
|
|
|
87
|
my $stack = $self->stack; |
86
|
4
|
|
|
|
|
77
|
my $new_head = $stack->head; |
87
|
4
|
|
|
|
|
185
|
my $old_head = ($new_head->parents)[0]; |
88
|
|
|
|
|
|
|
|
89
|
4
|
100
|
|
|
|
32799
|
my $rev = $self->revision |
90
|
|
|
|
|
|
|
? $self->repo->get_revision($self->revision) |
91
|
|
|
|
|
|
|
: ($old_head->parents)[0]; |
92
|
|
|
|
|
|
|
|
93
|
4
|
|
|
|
|
6072
|
return sprintf "Revert to %s: %s", $rev->uuid_prefix, $rev->message_title; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=for :stopwords Jeffrey Ryan Thalhammer |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Pinto::Action::Revert - Revert stack to a prior revision |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 VERSION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
version 0.13 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@stratopan.com> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
129
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |