SVK

 view release on metacpan or  search on metacpan

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

use SVK::Logger;

sub options {
    ($_[0]->SUPER::options,
     'q|quiet'         => 'quiet',
     'r|revision=s' => 'rev');
}

sub parse_arg {
    my ($self, @arg) = @_;
    return if @arg < 1;

    push @arg, '' if @arg == 1;

    my $dst = pop(@arg);
    die loc ("Copy destination can't be URI.\n")
	if is_uri ($dst);

    die loc ("More than one URI found.\n")
	if (grep {is_uri($_)} @arg) > 1;
    my @src;

    if ( my $target = eval { $self->{xd}->target_from_copath_maybe($dst) }) {
        $dst = $target;
	# don't allow new uri in source when target is copath
	@src = (map {$self->arg_co_maybe
			 ($_, $dst->isa('SVK::Path::Checkout')
			  ? loc ("path '%1' is already a checkout", $dst->report)
			  : undef)} @arg);
    }
    else {
	@src = (map {$self->arg_co_maybe ($_)} @arg);
        # Asking the user for copy destination.
        # In this case, first magically promote ourselves to "cp -p".
        # (otherwise it hurts when user types //deep/directory/name)
        $self->{parent} = 1;

        # -- make a sane default here for mirroring --
        my $default = undef;
        if (@src == 1 and $src[0]->path =~ m{/mirror/([^/]+)$}) {
            $default = "/" . $src[0]->depotname . "/$1";
        }

        my $path = $self->prompt_depotpath("copy", $default);

        if ($dst eq '.') {
            $self->{_checkout_path} = (splitdir($path))[-1];
        }
        else {
            $self->{_checkout_path} = $dst;
        }

        $dst = $self->arg_depotpath("$path/");
    }

    return (@src, $dst);
}

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

sub handle_co_item {
    my ($self, $src, $dst) = @_;
    $src = $src->as_depotpath;
    die loc ("Path %1 does not exist.\n", $src->path_anchor)
	if $src->root->check_path ($src->path_anchor) == $SVN::Node::none;
    my ($copath, $report) = ($dst->copath, $dst->report);
    die loc ("Path %1 already exists.\n", $copath)
	if -e $copath;
    my ($entry, $schedule) = $self->{xd}->get_entry($copath, 1);
    $src->normalize; $src->anchorify;
    $self->ensure_parent($dst);
    $dst->anchorify;

    my $notify = $self->{quiet} ? SVK::Notify->new(quiet => 1) : undef;
    # if SVK::Merge could take src being copath to do checkout_delta
    # then we have 'svk cp copath... copath' for free.
    # XXX: use editor::file when svkup branch is merged
    my ($editor, $inspector, %cb) = $dst->get_editor
	( ignore_checksum => 1, quiet => 1,
	  check_only => $self->{check_only},
	  update => 1, ignore_keywords => 1,
	);
    SVK::Merge->new (%$self, repos => $dst->repos, nodelay => 1,
		     report => $report, notify => $notify,
		     base => $src->new (path => '/', revision => 0),
		     src => $src, dst => $dst)
	    ->run
		($editor, %cb, inspector => $inspector);

    $self->{xd}{checkout}->store
	($copath, { revision => undef });
    # XXX: can the schedule be something other than delete ?
    $self->{xd}{checkout}->store ($copath, {'.schedule' => $schedule ? 'replace' : 'add',
					    scheduleanchor => $copath,
					    '.copyfrom' => $src->path,
					    '.copyfrom_rev' => $src->revision});
}

sub handle_direct_item {
    my ($self, $editor, $anchor, $m, $src, $dst, $other_call) = @_;
    $src->normalize;
    # if we have targets, ->{path} must exist
    if (!$self->{parent} && $dst->{targets} && !$dst->root->check_path ($dst->path_anchor)) {
	die loc ("Parent directory %1 doesn't exist, use -p.\n", $dst->report);
    }
    my ($path, $rev) = ($src->path, $src->revision);
    my $baton = $editor->add_directory (abs2rel ($dst->path, $anchor => undef, '/'), 0, $path, $rev);
    $other_call->($baton) if $other_call;
    $editor->close_directory($baton);
    $editor->adjust_last_anchor;
}

sub _unmodified {
    my ($self, $target) = @_;
    my (@modified, @unknown);
    $target = $self->{xd}->target_condensed($target); # anchor
    $self->{xd}->checkout_delta
	( $target->for_checkout_delta,



( run in 1.361 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )