[svk-commit] r2876 - in trunk: lib/SVK t/bm

nobody at bestpractical.com nobody at bestpractical.com
Mon May 12 21:49:39 EDT 2008


Author: clsung
Date: Mon May 12 21:49:38 2008
New Revision: 2876

Modified:
   trunk/lib/SVK/Command/Branch.pm
   trunk/lib/SVK/Project.pm
   trunk/t/bm/checkout.t

Log:
- dst_path in ::Branch
- better --checkout
  - --project <pname> or //mirror/project
- now --setup try to write props on remote first
- refine --info

Modified: trunk/lib/SVK/Command/Branch.pm
==============================================================================
--- trunk/lib/SVK/Command/Branch.pm	(original)
+++ trunk/lib/SVK/Command/Branch.pm	Mon May 12 21:49:38 2008
@@ -166,6 +166,16 @@
     return grep { m/$match/ } @{ $proj->branches };
 }
 
+sub dst_path {
+    my ( $self, $proj, $branch_name ) = @_;
+
+    if ( $self->{tag} ) {
+        $proj->tag_path($branch_name);
+    } else {
+        $proj->branch_path($branch_name, $self->{local});
+    }
+}
+
 package SVK::Command::Branch::list;
 use base qw(SVK::Command::Branch);
 use SVK::I18N;
@@ -280,16 +290,6 @@
     return;
 }
 
-sub dst_path {
-    my ( $self, $proj, $branch_name ) = @_;
-
-    if ( $self->{tag} ) {
-        $proj->tag_path($branch_name);
-    } else {
-        $proj->branch_path($branch_name, $self->{local});
-    }
-}
-
 package SVK::Command::Branch::move;
 use base qw( SVK::Command::Move SVK::Command::Smerge SVK::Command::Delete SVK::Command::Branch::create );
 use SVK::I18N;
@@ -566,9 +566,22 @@
 	}
     }
 
-    my $target = $self->arg_co_maybe ($project_path);
-    my $proj = $self->load_project($target);
-
+    my ($target, $proj);
+    eval { 
+	$target = $self->arg_co_maybe($project_path);
+    };
+    if ($@) { # then it means we must have a project
+	my @depots =  sort keys %{ $self->{xd}{depotmap} };
+	foreach my $depot (@depots) {
+	    $depot =~ s{/}{}g;
+	    $target = eval { $self->arg_depotpath("/$depot/") };
+	    next if ($@);
+	    $proj = SVK::Project->create_from_prop($target, $self->{project});
+	    last if ($proj) ;
+	}
+    } else {
+	$proj = $self->load_project($target, $self->{project});
+    }
     if (!$proj) {
         $logger->info(
             loc("Project not found. use 'svk branch --setup mirror_path' to initial one.\n")
@@ -694,7 +707,8 @@
     }
 
     undef $self->{recursive};
-    return map {$self->arg_co_maybe ($proj->branch_path($_))} @arg;
+    $self->{local}++ if ($target->_to_pclass("/local")->subsumes($target->path));
+    return map {$self->arg_co_maybe ($self->dst_path($proj,$_))} @arg;
 }
 
 package SVK::Command::Branch::setup;
@@ -703,6 +717,17 @@
 use SVK::Util qw( is_uri get_prompt );
 use SVK::Logger;
 
+sub can_write_remote_proj_prop {
+    my ($self, $remote_depot, %arg) = @_;
+    eval {
+	for my $key (keys %arg) {
+	    $self->do_propset($key,$arg{$key}, $remote_depot);
+	}
+    };
+    return 1 if ($@);
+    return 0;
+}
+
 sub parse_arg {
     my ($self, @arg) = @_;
     return if $#arg != 0;
@@ -714,7 +739,6 @@
     return ($self->arg_co_maybe ($dst));
 }
 
-
 sub run {
     my ($self, $target) = @_;
 
@@ -818,17 +842,19 @@
 	#XXX implement setting properties of project here
 	$self->{message} = "- Setup properties for project $project_name";
 	# always set to local first
-	#$self->do_propset("svk:project:$project_name:path-trunk",$trunk_path, $local_root);
-	#$self->do_propset("svk:project:$project_name:path-branches",$branch_path, $local_root);
-	#$self->do_propset("svk:project:$project_name:path-tags",$tag_path, $local_root);
-	#$self->do_propset("svk:project:$project_name:root",$preceding_path, $local_root);
 	my $root_depot = $self->arg_depotpath('/'.$target->depot->depotname.$preceding_path);
-	if (1) { # how do we ask user to push to remote?
-	    $self->do_propset("svk:project:$project_name:path-trunk",$trunk_path, $root_depot);
-	    $self->do_propset("svk:project:$project_name:path-branches",$branch_path, $root_depot);
-	    $self->do_propset("svk:project:$project_name:path-tags",$tag_path, $root_depot);
+	my $ret = $self->can_write_remote_proj_prop($root_depot,
+	    "svk:project:$project_name:path-trunk" => $trunk_path,
+	    "svk:project:$project_name:path-branches" => $branch_path,
+	    "svk:project:$project_name:path-tags" => $tag_path);
+	if ($ret) { # we have problem to write to remote
+	    $self->do_propset("svk:project:$project_name:path-trunk",$trunk_path, $local_root);
+	    $self->do_propset("svk:project:$project_name:path-branches",$branch_path, $local_root);
+	    $self->do_propset("svk:project:$project_name:path-tags",$tag_path, $local_root);
+	    $self->do_propset("svk:project:$project_name:root",$preceding_path, $local_root);
+	    $logger->info( loc("Can't write project props to remote server. Save in local instead."));
 	}
-	my $proj = SVK::Project->create_from_prop($target);
+	$proj = SVK::Project->create_from_prop($target);
 	# XXX: what if it still failed here? How to rollback the prop commits?
 	if (!$proj) {
 	    $logger->info( loc("Project setup failed.\n"));
@@ -862,12 +888,19 @@
 
     my $proj = $self->load_project($target);
 
+    # local
     $self->{branch_name} = $arg if $arg;
     $self->{branch_name} = $proj->branch_name($target->path, 1)
 	unless $arg;
 
     # check existence of remote branch
-    my $dst = $self->arg_depotpath($proj->branch_path($self->{branch_name}));
+    my $dst;
+#    if ($arg) { # user specify a new target branch
+	$dst = $self->arg_depotpath($proj->branch_path($self->{branch_name}));
+#    } else { # otherwise, merge back to its ancestor
+#	my $copy_ancestor = ($target->copy_ancestors)[0]->[0];
+#	$dst = $self->arg_depotpath('/'.$target->depotname.$copy_ancestor);
+#    }
     if ($SVN::Node::none != $dst->root->check_path($dst->path)) {
 	$self->{go_smerge} = $dst->depotpath if $target->related_to($dst);
     }

Modified: trunk/lib/SVK/Project.pm
==============================================================================
--- trunk/lib/SVK/Project.pm	(original)
+++ trunk/lib/SVK/Project.pm	Mon May 12 21:49:38 2008
@@ -130,7 +130,7 @@
 
     my $fs              = $pathobj->depot->repos->fs;
     my $root            = $fs->revision_root( $fs->youngest_rev );
-    my @all_mirrors     = split "\n", $root->node_prop('/','svm:mirror');
+    my @all_mirrors     = split "\n", $root->node_prop('/','svm:mirror') || '';
     my $prop_path = '/';
     foreach my $m_path (@all_mirrors) {
         if ($pathobj->path =~ m/^$m_path/) {

Modified: trunk/t/bm/checkout.t
==============================================================================
--- trunk/t/bm/checkout.t	(original)
+++ trunk/t/bm/checkout.t	Mon May 12 21:49:38 2008
@@ -27,8 +27,8 @@
 is_output ($svk, 'branch', ['--list', '//mirror/MyProject'],
     ['feature/foo']);
 
-is_output ($svk, 'branch', ['--checkout', 'feature/foo'],
-    [qr/path \S+ is not a checkout path./]);
+is_output_like ($svk, 'branch', ['--checkout', 'feature/foo'],
+    qr'Project not found.');
 
 chdir($copath."/A");
 is_output_like ($svk, 'branch', ['--checkout', 'feature/foo', '//mirror/MyProject'],


More information about the svk-commit mailing list