SVK

 view release on metacpan or  search on metacpan

lib/SVK/XD.pm  view on Meta::CPAN

    my ($repospath) = @_;
    $REPOS{$repospath} ||= SVN::Repos::open ($repospath, $REPOSPOOL);
}

=item find_repos

Given depotpath and an option about if the repository should be
opened. Returns an array of repository path, the path inside
repository, and the C<SVN::Repos> object if caller wants the
repository to be opened.

=cut

# DEPRECATED
sub find_repos {
    my ($self, $depotpath, $open) = @_;
    die loc("no depot spec") unless $depotpath;
    my ($depot, $path) = $depotpath =~ m|^/([^/]*)(/.*?)/?$|
	or die loc("%1 is not a depot path.\n", $depotpath);

    $path = Path::Class::foreign_dir('Unix', $path)->stringify;
    my $repospath = $self->{depotmap}{$depot} or die loc("No such depot: %1.\n", $depot);

    return ($repospath, $path, $open && _open_repos ($repospath));
}

sub find_depotpath {
    my ($self, $depotpath) = @_;
    die loc("no depot spec") unless $depotpath;
    my ($depotname, $path) = $depotpath =~ m|^/([^/]*)(/.*?)/?$|
	or die loc("%1 is not a depot path.\n", $depotpath);
    $path = Path::Class::foreign_dir('Unix', $path)->stringify;

    return ( $self->find_depot($depotname), $path );
}

sub find_depot {
    my ($self, $depotname) = @_;
    my $repospath = $self->{depotmap}{$depotname} or die loc("No such depot: %1.\n", $depotname);

    return SVK::Depot->new( { depotname => $depotname,
                              repospath => $repospath,
                              repos => _open_repos($repospath) } );
}

=item find_repos_from_co

Given the checkout path and an option about if the repository should
be opened. Returns an array of repository path, the path inside
repository, the absolute checkout path, the checkout info, and the
C<SVN::Repos> object if caller wants the repository to be opened.

=cut

sub find_repos_from_co {
    my ($self, $copath, $open) = @_;
    my $report = $copath;
    $copath = abs_path (File::Spec->canonpath ($copath));
    die loc("path %1 is not a checkout path.\n", $report)
	unless $copath;
    my ($cinfo, $coroot) = $self->{checkout}->get ($copath);
    die loc("path %1 is not a checkout path.\n", $copath) unless %$cinfo;
    my ($repospath, $path, $repos) = $self->find_repos ($cinfo->{depotpath}, $open);

    return ($repospath, abs2rel ($copath, $coroot => $path, '/'), $copath,
	    $cinfo, $repos);
}

=item find_repos_from_co_maybe

Like C<find_repos_from_co>, but falls back to see if the given path is
a depotpath. In that case, the checkout paths returned will be undef.

=cut

sub find_repos_from_co_maybe {
    my ($self, $target, $open) = @_;
    my ($repospath, $path, $copath, $cinfo, $repos);
    if (($repospath, $path, $repos) = eval { $self->find_repos ($target, $open) }) {
	return ($repospath, $path, undef, undef, $repos);
    }
    undef $@;
    return $self->find_repos_from_co ($target, $open);
}

=item find_depotname

=cut

sub find_depotname {
    my ($self, $target, $can_be_co) = @_;
    my ($cinfo);
    local $@;
    if ($can_be_co) {
	(undef, undef, $cinfo) = eval { $self->find_repos_from_co ($target, 0) };
	$target = $cinfo->{depotpath} unless $@;
    }

    $self->find_repos ($target, 0);
    return ($target =~ m|^/(.*?)/|);
}

=back

=cut

sub target_condensed {
    my ($self, @paths) = @_;
    return unless @paths;
    my $anchor;
    for my $path (@paths) {
	unless (defined $anchor) {
	    $anchor = $path->clone;
	    $anchor->copath_anchor(Path::Class::dir($anchor->copath_anchor));
	}
	my ($cinfo, $schedule) = $self->get_entry($anchor->copath_anchor, 1);
	while ($cinfo->{scheduleanchor} || !-d $anchor->copath_anchor ||
	       $schedule eq 'add' || $schedule eq 'delete' || $schedule eq 'replace' ||
	       !( $anchor->copath_anchor->subsumes($path->copath_anchor)) ) {
	    $anchor->anchorify;
	    $anchor->copath_anchor(Path::Class::dir($anchor->copath_anchor));
	    ($cinfo, $schedule) = $self->get_entry($anchor->copath_anchor, 1);
	}
	push @{$anchor->source->{targets}}, abs2rel($path->copath, $anchor->copath => undef, '/') unless $anchor->path eq $path->path;
    }

    my $root = $anchor->create_xd_root;
    until ($root->check_path($anchor->path_anchor) == $SVN::Node::dir) {
	$anchor->anchorify;
    }

    delete $anchor->{cinfo};
    return $anchor;
}

# simliar to command::arg_copath, but still return a target when
# basepath doesn't exist, arg_copath should be gradually deprecated
sub target_from_copath_maybe {
    my ($self, $arg) = @_;

    my $rev = $arg =~ s/\@(\d+)$// ? $1 : undef;
    my ($repospath, $path, $depotpath, $copath, $repos, $view);
    unless (($repospath, $path, $repos) = eval { $self->find_repos ($arg, 1) }) {
	$arg = File::Spec->canonpath($arg);
	$copath = abs_path_noexist($arg);
	my ($cinfo, $coroot) = $self->{checkout}->get ($copath);
	die loc("path %1 is not a checkout path.\n", $copath) unless %$cinfo;
	($repospath, $path, $repos) = $self->find_repos ($cinfo->{depotpath}, 1);
	my ($view_rev, $subpath);
	if (($view, $view_rev, $subpath) = $path =~ m{^/\^([\w/\-_]+)(?:\@(\d+)(.*))?$}) {
	    ($path, $view) = SVK::Command->create_view ($repos, $view, $view_rev, $subpath);
	}

	$path = abs2rel ($copath, $coroot => $path, '/');

	($depotpath) = $cinfo->{depotpath} =~ m|^/(.*?)/|;
        $rev = $cinfo->{revision} unless defined $rev;
	$depotpath = "/$depotpath$path";
    }

    from_native ($path, 'path', $self->{encoding});
    undef $@;
    my $ret = $self->create_path_object
	( repos => $repos,
	  repospath => $repospath,
	  depotpath => $depotpath || $arg,
	  copath_anchor => $copath,
	  report => $arg,
	  path => $path,
	  view => $view,
	  revision => $rev,
	);
    $ret = $ret->as_depotpath unless defined $copath;
    return $ret;
}

=head2 create_path_object

Creates and returns a new path object. It can be either L<SVK::Path::Checkout>,
L<SVK::Path::View> or L<SVK::Path>.

Takes a hash with arguments.

If "copath_anchor" argument is defined then L<SVK::Path::Checkout> is created
and other arguments are used to build its L<SVK::Path::Checkout/source>
using this method. If "revision" argument is not defined then the one checkout
path is based on is used.

If "view" argument is defined then L<SVK::Path::View> is created
and other arguments are used to build its L<SVK::Path::Checkout/source> using
this method.

Otherwise L<SVK::Path> is created.

Depot can be passed as L<SVK::Depot> object in "depot" argument or using
"depotname", "repospath" and "repos" arguments. Object takes precendence.

=cut

sub create_path_object {
    my ($self, %arg) = @_;
    if (my $depotpath = delete $arg{depotpath}) {
	($arg{depotname}) = $depotpath =~ m!^/([^/]*)!;
    }

    if (defined (my $copath = delete $arg{copath_anchor})) {
	require SVK::Path::Checkout;
	my $report = delete $arg{report};
        $arg{'revision'} = ($self->get_entry( $copath ))[0]->{'revision'}
            unless defined $arg{'revision'};
	return SVK::Path::Checkout->real_new
	    ({ xd => $self,
	       report => $report,
	       copath_anchor => $copath,



( run in 2.150 seconds using v1.01-cache-2.11-cpan-d8267643d1d )