1# BEGIN BPS TAGGED BLOCK {{{ 2# COPYRIGHT: 3# 4# This software is Copyright (c) 2003-2008 Best Practical Solutions, LLC 5# <clkao@bestpractical.com> 6# 7# (Except where explicitly superseded by other copyright notices) 8# 9# 10# LICENSE: 11# 12# 13# This program is free software; you can redistribute it and/or 14# modify it under the terms of either: 15# 16# a) Version 2 of the GNU General Public License. You should have 17# received a copy of the GNU General Public License along with this 18# program. If not, write to the Free Software Foundation, Inc., 51 19# Franklin Street, Fifth Floor, Boston, MA 02110-1301 or visit 20# their web page on the internet at 21# http://www.gnu.org/copyleft/gpl.html. 22# 23# b) Version 1 of Perl's "Artistic License". You should have received 24# a copy of the Artistic License with this package, in the file 25# named "ARTISTIC". The license is also available at 26# http://opensource.org/licenses/artistic-license.php. 27# 28# This work is distributed in the hope that it will be useful, but 29# WITHOUT ANY WARRANTY; without even the implied warranty of 30# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31# General Public License for more details. 32# 33# CONTRIBUTION SUBMISSION POLICY: 34# 35# (The following paragraph is not intended to limit the rights granted 36# to you to modify and distribute this software under the terms of the 37# GNU General Public License and is only of importance to you if you 38# choose to contribute your changes and enhancements to the community 39# by submitting them to Best Practical Solutions, LLC.) 40# 41# By intentionally submitting any modifications, corrections or 42# derivatives to this work, or any other work intended for use with SVK, 43# to Best Practical Solutions, LLC, you confirm that you are the 44# copyright holder for those contributions and you grant Best Practical 45# Solutions, LLC a nonexclusive, worldwide, irrevocable, royalty-free, 46# perpetual, license to use, copy, create derivative works based on 47# those contributions, and sublicense and distribute those contributions 48# and any derivatives thereof. 49# 50# END BPS TAGGED BLOCK }}} 51package SVK::Depot; 52use strict; 53use SVK::Version; our $VERSION = $SVK::VERSION; 54 55use base 'Class::Accessor::Fast'; 56 57__PACKAGE__->mk_accessors(qw(repos repospath depotname)); 58 59=head1 NAME 60 61SVK::Depot - Depot class in SVK 62 63=head1 SYNOPSIS 64 65=head1 DESCRIPTION 66 67=over 68 69=item mirror 70 71Returns the mirror catalog object associated with the current depot. 72 73=cut 74 75sub mirror { 76 my $self = shift; 77 return SVK::MirrorCatalog->new 78 ( { repos => $self->repos, 79 depot => $self, 80 revprop => ['svk:signature'] }); 81} 82 83=item find_local_mirror($uuid, $path, [$rev]) 84 85Returns the path on the current depot that has the mirror of C<$uuid:$path>. 86If C<$rev> is given, returns the local revision as well. 87 88=cut 89 90sub find_local_mirror { 91 my ($self, $uuid, $path, $rev) = @_; 92 my $myuuid = $self->repos->fs->get_uuid; 93 return if $uuid eq $myuuid; 94 95 my ($m, $mpath) = $self->_has_local("$uuid:$path"); 96 return ($m->path.$mpath, 97 $rev ? $m->find_local_rev($rev) : $rev) if $m; 98 return; 99} 100 101sub _has_local { 102 my ($self, $spec) = @_; 103 for my $path ($self->mirror->entries) { 104 my $m = $self->mirror->get($path); 105 my $mspec = $m->spec; 106 my $mpath = $spec; 107 return ($m, '') if $mpath eq $mspec; 108 next unless $mpath =~ s{^\Q$mspec\E/}{/}; 109 110 # the common usage for $mpath is $m->path . $mpath, so if the 111 # mirror is anchored on /, we need to get rid of the leading / 112 # in $mpath. 113 $mpath = substr($mpath, 1) if $m->path eq '/'; 114 $mpath = '' if $mpath eq '/'; # XXX: why still need this? 115 return ($m, $mpath); 116 } 117 return; 118} 119 1201; 121