Daizu
view release on metacpan or search on metacpan
lib/Daizu/Wc.pm view on Meta::CPAN
branch_path => $branch_path,
);
my $reporter = $cms->{ra}->do_update($revnum, $branch_path, 1, $editor);
$reporter->set_path('', 0, 1, undef);
$reporter->finish_report;
return $class->new($cms, $wc_id);
}
=item $wc-E<gt>id
Return the ID number of the working copy.
=cut
sub id { $_[0]->{id} }
=item $wc-E<gt>current_revision
Return the number of the revision which the working copy is currently
updated to.
=cut
sub current_revision
{
my ($self) = @_;
return db_select($self->{cms}{db}, working_copy => $self->{id},
'current_revision');
}
=item $wc-E<gt>file_at_path($path)
Return a L<Daizu::File> object representing the file or directory which
currently resides at C<$path> in the working copy. Dies if there is no
such file.
=cut
sub file_at_path
{
my ($self, $path) = @_;
my $file_id = db_row_id($self->{cms}{db}, 'wc_file',
wc_id => $self->{id},
path => $path,
);
croak "no file at '$path' in working copy $self->{id}"
unless defined $file_id;
return Daizu::File->new($self->{cms}, $file_id);
}
=item $wc->update($revnum)
Update a database working copy to revision C<$revnum>. This is done in a
transaction, which will be rolled back if anything goes wrong, leaving the
WC in its original state. C<$revnum> can be C<undef> to update to the most
recent revision available.
=cut
sub update
{
my ($self, $revnum) = @_;
return transactionally($self->{cms}{db}, \&_update_txn, $self, $revnum);
}
sub _update_txn
{
my ($self, $revnum) = @_;
my $cms = $self->{cms};
my $db = $cms->{db};
my $latest_revnum = $cms->load_revision($revnum);
$revnum = $latest_revnum unless defined $revnum;
my $cur_revnum = $self->current_revision;
return $cur_revnum
if $cur_revnum >= $revnum;
my $editor = Daizu::Wc::UpdateEditor->new(
cms => $self->{cms},
db => $db,
wc_id => $self->{id},
revnum => $revnum,
branch_id => $self->{branch_id},
branch_path => $self->{branch_path},
);
my $reporter = $cms->{ra}->do_update($revnum, $self->{branch_path}, 1,
$editor);
$reporter->set_path('', $cur_revnum, 0, undef);
$reporter->finish_report;
db_update($db, working_copy => $self->{id},
current_revision => $revnum,
);
$db->do(q{
update wc_file
set cur_revnum = ?
where cur_revnum is not null
and not modified
and not deleted
}, undef, $revnum);
return $revnum;
}
=item $wc-E<gt>add_file($path, $data)
TODO - this method isn't safe to use yet, and will corrupt the working copy.
=cut
sub add_file
{
my ($self, $path, $data) = @_;
my $wc_id = $self->{id};
croak "you're not allowed to make changes in the live working copy"
if $wc_id == $self->{cms}{live_wc_id};
my $db = $self->{cms}{db};
( run in 3.163 seconds using v1.01-cache-2.11-cpan-0fb53d1c279 )