Permalink
Browse files

Add more info and update the ID.

Change IDs now include the parent ID in their hash values, as well as the list
of dependencies and the note. The old ID and info is preserved in `old_info`
and `old_id`.
  • Loading branch information...
theory committed Nov 21, 2012
1 parent 14ddc70 commit af71fe67ea8c506a338a4b34f00a94332d4d746b
Showing with 103 additions and 14 deletions.
  1. +36 −1 lib/App/Sqitch/Plan/Change.pm
  2. +52 −4 t/change.t
  3. +15 −9 t/plan.t
@@ -101,12 +101,18 @@ has info => (
lazy => 1,
default => sub {
my $self = shift;
my $reqs = join "\n + ", map { $_->as_string } $self->requires;
my $confs = join "\n - ", map { $_->as_string } $self->conflicts;
return join "\n", (
'project ' . $self->project,
( $self->uri ? ( 'uri ' . $self->uri->canonical ) : () ),
'change ' . $self->format_name,
( $self->parent ? ( 'parent ' . $self->parent->id ) : () ),
'planner ' . $self->format_planner,
'date ' . $self->timestamp->as_string,
( $reqs ? "requires\n + $reqs" : ()),
( $confs ? "conflicts\n - $confs" : ()),
( $self->note ? ('', $self->note) : ()),
);
}
);
@@ -124,6 +130,35 @@ has id => (
}
);

has old_info => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
my $self = shift;
return join "\n", (
'project ' . $self->project,
( $self->uri ? ( 'uri ' . $self->uri->canonical ) : () ),
'change ' . $self->format_name,
'planner ' . $self->format_planner,
'date ' . $self->timestamp->as_string,
);
}
);

has old_id => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
my $content = encode_utf8 shift->old_info;
require Digest::SHA1;
return Digest::SHA1->new->add(
'change ' . length($content) . "\0" . $content
)->hexdigest;
}
);

has timestamp => (
is => 'ro',
isa => 'App::Sqitch::DateTime',
@@ -186,7 +221,7 @@ sub format_dependencies {
my $self = shift;
my $deps = join(
' ',
map { $_->as_plan_string} $self->requires, $self->conflicts
map { $_->as_plan_string } $self->requires, $self->conflicts
) or return '';
return "[$deps]";
}
@@ -31,6 +31,10 @@ $ENV{SQITCH_SYSTEM_CONFIG} = 'nonexistent.sys';

can_ok $CLASS, qw(
name
info
id
old_info
old_id
lspace
rspace
note
@@ -116,6 +120,19 @@ is $change->as_string, "foo $ts " . $change->format_planner,
'should stringify to "foo" + planner';
is $change->since_tag, undef, 'Since tag should be undef';
is $change->parent, undef, 'Parent should be undef';
is $change->old_info, join("\n",
'project change',
'change foo',
'planner ' . $change->format_planner,
'date ' . $change->timestamp->as_string,
), 'Old change info should be correct';
is $change->old_id, do {
my $content = $change->old_info;
Digest::SHA1->new->add(
'change ' . length($content) . "\0" . $content
)->hexdigest;
},'Old change ID should be correct';

is $change->info, join("\n",
'project change',
'change foo',
@@ -186,13 +203,29 @@ ok $change2->is_revert, 'It should be a revert change';
is $change2->action, 'revert', 'It should say so';
is $change2->since_tag, $tag, 'It should have a since tag';
is $change2->parent, $change, 'It should have a parent';
is $change2->info, join("\n",
is $change2->old_info, join("\n",
'project change',
'uri https://github.com/theory/sqitch/',
'change yo/howdy',
'planner Barack Obama <potus@whitehouse.gov>',
'date 2012-07-16T17:25:07Z'
), 'Info should include since tag';
), 'Old info should not since tag';

is $change2->info, join("\n",
'project change',
'uri https://github.com/theory/sqitch/',
'change yo/howdy',
'parent ' . $change->id,
'planner Barack Obama <potus@whitehouse.gov>',
'date 2012-07-16T17:25:07Z',
'requires',
' + foo',
' + bar',
' + @baz',
'conflicts',
' - dr_evil',
'', 'blah blah blah'
), 'Info should include parent and dependencies';

# Check tags.
is_deeply [$change2->tags], [], 'Should have no tags';
@@ -291,20 +324,35 @@ ok $change2 = $CLASS->new(
name => '阱阪阬',
plan => $plan2,
), 'Create change with UTF-8 name';
is $change2->old_info, join("\n",
'project ' . 'multi',
'uri ' . $uri->canonical,
'change ' . '阱阪阬',
'planner ' . $change2->format_planner,
'date ' . $change2->timestamp->as_string,
), 'The name should be decoded text in old info';

is $change2->old_id, do {
my $content = Encode::encode_utf8 $change2->old_info;
Digest::SHA1->new->add(
'change ' . length($content) . "\0" . $content
)->hexdigest;
},'Old change ID should be hashed from encoded UTF-8';

is $change2->info, join("\n",
'project ' . 'multi',
'uri ' . $uri->canonical,
'change ' . '阱阪阬',
'planner ' . $change2->format_planner,
'date ' . $change2->timestamp->as_string,
), 'The name should be decoded text';
), 'The name should be decoded text in info';

is $change2->id, do {
my $content = Encode::encode_utf8 $change2->info;
Digest::SHA1->new->add(
'change ' . length($content) . "\0" . $content
)->hexdigest;
},'Change ID should be hahsed from encoded UTF-8';
},'Change ID should be hashed from encoded UTF-8';

##############################################################################
# Test note_prompt().
@@ -1454,10 +1454,16 @@ $mocker->unmock('check_changes');
can_ok $CLASS, 'check_changes';
my @deps;
my $mock_change = Test::MockModule->new('App::Sqitch::Plan::Change');
$mock_change->mock(requires => sub { @{ shift(@deps)->{requires} } });
my $i = 0;
my $j = 0;
$mock_change->mock(requires => sub {
my $reqs = caller eq 'App::Sqitch::Plan' ? $deps[$i++] : $deps[$j++];
@{ $reqs->{requires} };
});

sub changes {
clear;
$i = $j = 0;
map {
change { name => $_ };
} @_;
@@ -1467,22 +1473,22 @@ sub changes {
$project = 'foo';
my %ddep = ( requires => [], conflicts => [] );
@deps = ({%ddep}, {%ddep}, {%ddep});
cmp_deeply [$plan->check_changes({}, changes qw(this that other))],
[changes qw(this that other)], 'Should get original order when no dependencies';
cmp_deeply [map { $_->name } $plan->check_changes({}, changes qw(this that other))],
[qw(this that other)], 'Should get original order when no dependencies';

@deps = ({%ddep}, {%ddep}, {%ddep});
cmp_deeply [$plan->check_changes('foo', changes qw(this that other))],
[changes qw(this that other)], 'Should get original order when no prepreqs';
cmp_deeply [map { $_->name } $plan->check_changes('foo', changes qw(this that other))],
[qw(this that other)], 'Should get original order when no prepreqs';

# Have that require this.
@deps = ({%ddep}, {%ddep, requires => [dep 'this']}, {%ddep});
cmp_deeply [$plan->check_changes('foo', changes qw(this that other))],
[changes qw(this that other)], 'Should get original order when that requires this';
cmp_deeply [map { $_->name }$plan->check_changes('foo', changes qw(this that other))],
[qw(this that other)], 'Should get original order when that requires this';

# Have other require that.
@deps = ({%ddep}, {%ddep, requires => [dep 'this']}, {%ddep, requires => [dep 'that']});
cmp_deeply [$plan->check_changes('foo', changes qw(this that other))],
[changes qw(this that other)], 'Should get original order when other requires that';
cmp_deeply [map { $_->name } $plan->check_changes('foo', changes qw(this that other))],
[qw(this that other)], 'Should get original order when other requires that';

my $deperr = sub {
join "\n ", __n(

0 comments on commit af71fe6

Please sign in to comment.