SVK

 view release on metacpan or  search on metacpan

lib/SVK/Command/Move.pm  view on Meta::CPAN

# perpetual, license to use, copy, create derivative works based on
# those contributions, and sublicense and distribute those contributions
# and any derivatives thereof.
# 
# END BPS TAGGED BLOCK }}}
package SVK::Command::Move;
use strict;
use SVK::Version;  our $VERSION = $SVK::VERSION;
use base qw( SVK::Command::Copy );
use SVK::Util qw ( abs2rel );
use SVK::I18N;

sub lock {
    my $self = shift;
    $self->lock_coroot(@_);
}

sub handle_direct_item {
    my $self = shift;
    my ($editor, $anchor, $m, $src, $dst) = @_;
    my ($srcm) = $self->under_mirror ($src);
    my $call;
    if ($srcm && $srcm->path eq $src->path) {
	# XXX: this should be in svk::mirror
	my $props = $src->root->node_proplist($src->path);
	# this is very annoying: for inejecting an additional
	# editor call, has to give callback to Command::Copy's
	# handle_direct_item
	$call = sub {
	    $editor->change_dir_prop($_[0], $_, $props->{$_},
				     )
 		for grep { m/^svm:/ } keys %$props;
	};
	push @{$self->{post_process_mirror}}, [$src->path, $dst->path];
    }
    $self->SUPER::handle_direct_item (@_, $call);

    $editor->delete_entry(abs2rel ($src->path, $anchor => undef, '/'),
                          $src->revision, 0);
    $self->adjust_anchor ($editor);
}

sub handle_co_item {
    my ($self, $src, $dst) = @_;
    $self->SUPER::handle_co_item ($src->new, $dst); # might be modified
    $self->{xd}->do_delete($src);
}

sub run {
    my $self = shift;
    my $src = $_[0];
    my $ret = $self->SUPER::run(@_);
    if ($self->{post_process_mirror}) {
	# XXX: also should set svm:incomplete revprop
	# should be in SVK::Mirror as well
	my $mstring = $src->root->node_prop('/', 'svm:mirror');
	for (@{$self->{post_process_mirror}}) {
	    my ($from, $to) = @$_;
	    $mstring =~ s/^\Q$from\E$/$to/;
	}
	my $cmd = $self->command('propset', { revision => undef,
					      message => 'svk: fix-up for mirror move' });
	$cmd->run('svm:mirror', $mstring, $src->new(path => '/'));
    }
    return $ret;
}

__DATA__

=head1 NAME

SVK::Command::Move - Move a file or directory

=head1 SYNOPSIS

 move DEPOTPATH1 DEPOTPATH2

=head1 OPTIONS

 -r [--revision] REV    : act on revision REV instead of the head revision
 -p [--parent]          : create intermediate directories as required
 -q [--quiet]           : print as little as possible
 -m [--message] MESSAGE : specify commit message MESSAGE
 -F [--file] FILENAME   : read commit message from FILENAME
 --template             : use the specified message as the template to edit
 --encoding ENC         : treat -m/-F value as being in charset encoding ENC
 -P [--patch] NAME      : instead of commit, save this change as a patch
 -S [--sign]            : sign this change
 -C [--check-only]      : try operation but make no changes
 --direct               : commit directly even if the path is mirrored



( run in 0.887 second using v1.01-cache-2.11-cpan-71847e10f99 )