[svk-commit] r2185 - in trunk/lib/SVK: . Command Root

clkao at bestpractical.com clkao at bestpractical.com
Sun Nov 19 05:33:26 EST 2006


Author: clkao
Date: Sun Nov 19 05:33:25 2006
New Revision: 2185

Modified:
   trunk/lib/SVK/Command/Copy.pm
   trunk/lib/SVK/Editor/Rename.pm
   trunk/lib/SVK/Editor/View.pm
   trunk/lib/SVK/Merge.pm
   trunk/lib/SVK/Root/View.pm
   trunk/lib/SVK/Util.pm

Log:
cleanup is_path_insdie.

Modified: trunk/lib/SVK/Command/Copy.pm
==============================================================================
--- trunk/lib/SVK/Command/Copy.pm	(original)
+++ trunk/lib/SVK/Command/Copy.pm	Sun Nov 19 05:33:25 2006
@@ -2,7 +2,7 @@
 use strict;
 use SVK::Version;  our $VERSION = $SVK::VERSION;
 use base qw( SVK::Command::Mkdir );
-use SVK::Util qw( get_anchor get_prompt abs2rel splitdir is_uri make_path );
+use SVK::Util qw( get_anchor get_prompt abs2rel splitdir is_uri make_path is_path_inside);
 use SVK::I18N;
 use SVK::Logger;
 
@@ -175,14 +175,13 @@
 	    my $cpdst = $dst->new;
 	    # implicit target for "cp x y z dir/"
 	    if (-d $cpdst->copath) {
-		# XXX: _path_inside should be refactored in to SVK::Util
-		if ( substr($cpdst->path_anchor, 0, length($_->path_anchor)+1) eq $_->path_anchor."/") {
-		    die loc("Invalid argument: copying directory %1 into itself.\n", $_->report);
-		}
 		if ($_->path_anchor eq $cpdst->path_anchor) {
 		    $logger->warn(loc("Ignoring %1 as source.", $_->report));
 		    next;
 		}
+		if ( is_path_inside($cpdst->path_anchor, $_->path_anchor) ) {
+		    die loc("Invalid argument: copying directory %1 into itself.\n", $_->report);
+		}
 		$cpdst->descend ($_->path_anchor =~ m|/([^/]+)/?$|)
 	    }
 	    die loc ("Path %1 already exists.\n", $cpdst->report)

Modified: trunk/lib/SVK/Editor/Rename.pm
==============================================================================
--- trunk/lib/SVK/Editor/Rename.pm	(original)
+++ trunk/lib/SVK/Editor/Rename.pm	Sun Nov 19 05:33:25 2006
@@ -3,6 +3,7 @@
 use SVK::Version;  our $VERSION = $SVK::VERSION;
 use base qw(SVK::Editor::Patch);
 use SVK::I18N;
+use SVK::Util 'is_path_inside';
 
 =head1 NAME
 
@@ -35,19 +36,13 @@
 
 =cut
 
-sub _path_inside {
-    my ($path, $parent) = @_;
-    return 1 if $path eq $parent;
-    return substr ($path, 0, length ($parent)+1) eq "$parent/";
-}
-
 sub rename_check {
     my ($self, $path, $nocache) = @_;
     return $self->{rename_cache}{$path}
 	if exists $self->{rename_cache}{$path};
     for (@{$self->{rename_map}}) {
 	my ($from, $to) = @$_;
-	if (_path_inside ($path, $from)) {
+	if (is_path_inside($path, $from)) {
 	    my $newpath = $path;
 	    $newpath =~ s/^\Q$from\E/$to/;
 	    $newpath = $self->rename_check ($newpath, 1);

Modified: trunk/lib/SVK/Editor/View.pm
==============================================================================
--- trunk/lib/SVK/Editor/View.pm	(original)
+++ trunk/lib/SVK/Editor/View.pm	Sun Nov 19 05:33:25 2006
@@ -3,8 +3,7 @@
 use SVK::Version;  our $VERSION = $SVK::VERSION;
 use base qw(SVK::Editor::Rename);
 use SVK::I18N;
-
-*_path_inside = *SVK::Editor::Rename::_path_inside;
+use SVK::Util 'is_path_inside';
 
 sub rename_check {
     my ($self, $path) = @_;
@@ -12,7 +11,7 @@
 	if length $self->{prefix};
     for (@{$self->{rename_map}}) {
 	my ($from, $to) = @$_;
-	if (_path_inside ($path, $from)) {
+	if (is_path_inside($path, $from)) {
 	    my $newpath = $path;
 	    $newpath =~ s/^\Q$from\E/$to/;
 	    return $newpath;

Modified: trunk/lib/SVK/Merge.pm
==============================================================================
--- trunk/lib/SVK/Merge.pm	(original)
+++ trunk/lib/SVK/Merge.pm	Sun Nov 19 05:33:25 2006
@@ -1,6 +1,6 @@
 package SVK::Merge;
 use strict;
-use SVK::Util qw(traverse_history);
+use SVK::Util qw(traverse_history is_path_inside);
 use SVK::I18N;
 use SVK::Editor::Merge;
 use SVK::Editor::Rename;
@@ -376,7 +376,7 @@
 	$entries->{$_} = [$action , $action eq 'D' ? (-1) : $root->copied_from ($_)];
 	# anchor is copied
 	if ($action eq 'A' && $entries->{$_}[1] != -1 &&
-	    ($path eq $_ || "$_/" eq substr ($path, 0, length($_)+1))) {
+	    (is_path_inside($path, $_))) {
 	    $path =~ s/^\Q$_\E/$entries->{$_}[2]/;
 	    $$pathref = $path;
 	}

Modified: trunk/lib/SVK/Root/View.pm
==============================================================================
--- trunk/lib/SVK/Root/View.pm	(original)
+++ trunk/lib/SVK/Root/View.pm	Sun Nov 19 05:33:25 2006
@@ -7,6 +7,7 @@
 __PACKAGE__->mk_accessors(qw(view));
 
 use Scalar::Util 'weaken';
+use SVK::Util 'is_path_inside';
 
 sub txn_root {
     my ($self, $pool) = @_;
@@ -28,18 +29,11 @@
 	     $path );
 }
 
-# XXX: stolen from Editor::Rename, kill these
-sub _path_inside {
-    my ($path, $parent) = @_;
-    return 1 if $path eq $parent;
-    return substr ($path, 0, length ($parent)+1) eq "$parent/";
-}
-
 sub rename_check {
     my ($self, $path, $map) = @_;
     for (@$map) {
 	my ($from, $to) = @$_;
-	if (_path_inside ($path, $from)) {
+	if (is_path_inside($path, $from)) {
 	    my $newpath = $path;
 	    $newpath =~ s/^\Q$from\E/$to/;
 	    return $newpath;

Modified: trunk/lib/SVK/Util.pm
==============================================================================
--- trunk/lib/SVK/Util.pm	(original)
+++ trunk/lib/SVK/Util.pm	Sun Nov 19 05:33:25 2006
@@ -18,7 +18,7 @@
     move_path make_path splitpath splitdir tmpdir tmpfile get_depot_anchor
     catdepot abs_path_noexist 
 
-    is_symlink is_executable is_uri can_run
+    is_symlink is_executable is_uri can_run is_path_inside
 
     str2time time2str reformat_svn_date
 
@@ -926,6 +926,19 @@
     return
 }
 
+=head3 is_path_inside($path, $parent)
+
+Returns true if unix path C<$path> is inside C<$parent>.
+If they are the same, return true as well.
+
+=cut
+
+sub is_path_inside {
+    my ($path, $parent) = @_;
+    return 1 if $path eq $parent;
+    return substr ($path, 0, length ($parent)+1) eq "$parent/";
+}
+
 1;
 
 __END__


More information about the svk-commit mailing list