[svk-commit] r2812 - in trunk/lib/SVK: .

nobody at bestpractical.com nobody at bestpractical.com
Tue May 6 22:10:18 EDT 2008


Author: clsung
Date: Tue May  6 22:10:18 2008
New Revision: 2812

Modified:
   trunk/lib/SVK/Command/Branch.pm
   trunk/lib/SVK/Util.pm

Log:
- add is_depotpath() for just validate the format of given string
- now --checkout support in non-checkout directory, if project depotpath specified
  - ref: http://task.hm/E9Y9

Modified: trunk/lib/SVK/Command/Branch.pm
==============================================================================
--- trunk/lib/SVK/Command/Branch.pm	(original)
+++ trunk/lib/SVK/Command/Branch.pm	Tue May  6 22:10:18 2008
@@ -314,7 +314,7 @@
 package SVK::Command::Branch::remove;
 use base qw( SVK::Command::Delete SVK::Command::Branch );
 use SVK::I18N;
-use SVK::Util qw( is_uri );
+use SVK::Util qw( is_uri is_depotpath);
 use SVK::Logger;
 
 sub lock { $_[0]->lock_target ($_[1]); };
@@ -330,7 +330,7 @@
 
     my $project_path = pop @arg if $#arg > 0;
     # if specified project path at the end
-    $project_path = '' unless $project_path =~ m|^/([^/]*)(/.*?)/?$|;
+    $project_path = '' unless is_depotpath($project_path);
     return ($self->arg_co_maybe ($project_path), @arg);
 }
 
@@ -456,12 +456,31 @@
 use base qw( SVK::Command::Checkout SVK::Command::Branch );
 use SVK::I18N;
 use SVK::Logger;
+use SVK::Util qw( is_depotpath );
 
 sub parse_arg {
     my ($self, @arg) = @_;
-    return if $#arg < 0 or $#arg > 1;
+    return if $#arg < 0 or $#arg > 2;
+
+    my $branch_name = shift(@arg);
+    my ($project_path, $checkout_path) = ('','');
+    if (is_depotpath($arg[$#arg])) {
+	$project_path = pop(@arg);
+    }
+    $checkout_path = pop(@arg);
+    $checkout_path = $branch_name unless $checkout_path;
+    
+    if (@arg) { # this must be a project path, or error it
+	$project_path = pop(@arg);
+	if (!is_depotpath($project_path)) {
+	    $logger->info(
+		loc("No avaliable Projects found in %1.\n", $project_path )
+	    );
+	    return;
+	}
+    }
 
-    my $target = $self->arg_co_maybe ('');
+    my $target = $self->arg_co_maybe ($project_path);
     my $proj = $self->load_project($target);
 
     if (!$proj) {
@@ -471,9 +490,8 @@
 	return ;
     }
 
-    my $branch_name = shift(@arg);
     my $newtarget_path = $proj->branch_path($branch_name, $self->{local});
-    unshift @arg, $newtarget_path;
+    unshift @arg, $newtarget_path, $checkout_path;
     return $self->SUPER::parse_arg(@arg);
 }
 
@@ -685,7 +703,7 @@
  branch --create BRANCH [--local] [--switch-to] [DEPOTPATH]
  branch --move BRANCH1 BRANCH2
  branch --merge BRANCH1 BRANCH2 ... TARGET
- branch --checkout BRANCH [PATH]
+ branch --checkout BRANCH [PATH] [DEPOTPATH]
  branch --delete BRANCH1 BRANCH2 ...
  branch --setup DEPOTPATH
  branch --push [--from BRANCH]

Modified: trunk/lib/SVK/Util.pm
==============================================================================
--- trunk/lib/SVK/Util.pm	(original)
+++ trunk/lib/SVK/Util.pm	Tue May  6 22:10:18 2008
@@ -68,7 +68,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_path_inside
+    is_symlink is_executable is_uri can_run is_path_inside is_depotpath
 
     uri_escape uri_unescape
 
@@ -1040,6 +1040,16 @@
     return $uri;
 }
 
+=head3 is_depotpath($path)
+
+Check if a string is a valid depotpath.
+
+=cut
+
+sub is_depotpath {
+    ($_[0] =~ m|^/([^/]*)(/.*?)/?$|)
+}
+
 1;
 
 __END__


More information about the svk-commit mailing list