[svk-commit] r2768 - in trunk: lib/SVK t/bm
nobody at bestpractical.com
nobody at bestpractical.com
Mon Apr 28 05:10:04 EDT 2008
Author: clsung
Date: Mon Apr 28 05:09:52 2008
New Revision: 2768
Modified:
trunk/lib/SVK/Command/Branch.pm
trunk/lib/SVK/Project.pm
trunk/t/bm/prop-setup.t
Log:
- implement br --setup
- add $fromProp, to indicate if the project is loaded from properties
Modified: trunk/lib/SVK/Command/Branch.pm
==============================================================================
--- trunk/lib/SVK/Command/Branch.pm (original)
+++ trunk/lib/SVK/Command/Branch.pm Mon Apr 28 05:09:52 2008
@@ -58,6 +58,7 @@
use SVK::Project;
use SVK::Logger;
+our $fromProp;
use constant narg => undef;
sub options {
@@ -98,14 +99,14 @@
sub load_project {
my ($self, $target) = @_;
+ $fromProp = 0;
Carp::cluck unless $target->isa('SVK::Path') or $target->isa('SVK::Path::Checkout');
$target = $target->source if $target->isa('SVK::Path::Checkout');
- my $proj =
- SVK::Project->create_from_prop($target) ||
- SVK::Project->create_from_path(
- $target->depot,
- $target->path );
+ my $proj = SVK::Project->create_from_prop($target);
+ $fromProp = 1 if $proj;
+ $proj ||= SVK::Project->create_from_path(
+ $target->depot, $target->path );
return $proj;
}
@@ -127,7 +128,7 @@
my $proj = $self->load_project($target);
if (!$proj) {
- $logger->info( loc("No project branch founded.\n"));
+ $logger->info( loc("No project found.\n"));
return;
}
@@ -180,6 +181,11 @@
my $proj = $self->load_project($target);
+ if (!$proj) {
+ $logger->info( loc("No project found.\n"));
+ return;
+ }
+
delete $self->{from} if $self->{from} and $self->{from} eq 'trunk';
my $src_path = '/'.$proj->depot->depotname.'/'.
( $self->{from} ?
@@ -507,45 +513,79 @@
my $proj = $self->load_project($target);
- if (!$proj) {
- $logger->info( loc("New Project depotpath encountered: %1\n", $target->path));
- my ($trunk_path, $branch_path, $tag_path, $project_name);
+ if ($proj && $fromProp) {
+ $logger->info( loc("Project already set in properties: %1\n", $target->depotpath));
+ } else {
+ my ($trunk_path, $branch_path, $tag_path, $project_name, $preceding_path);
for my $path ($target->depot->mirror->entries) {
($trunk_path, $project_name) = $target->path =~ m{^$path(/?([^/]+).*)$};
+ $preceding_path = $path;
+ last if $trunk_path;
+ }
+ if (!$proj) {
+ $logger->info( loc("New Project depotpath encountered: %1\n", $target->path));
+ } else {
+ $logger->info( loc("Project detected in specified path.\n"));
+ $project_name = $proj->name;
+ $trunk_path = '/'.$proj->trunk;
+ $trunk_path =~ s#^/?$preceding_path##;
+ $branch_path = '/'.$proj->branch_location;
+ $branch_path =~ s{^/?$preceding_path}{};
+ $tag_path = '/'.$proj->tag_location;
+ $tag_path =~ s{^/?$preceding_path}{};
}
{
my $ans = get_prompt(
loc("It has no trunk, where is the trunk/? (press enter to use %1)\n=>", $trunk_path),
- qr/^(?:.*)/
+ qr/^(?:\/?[A-Za-z][-+.A-Za-z0-9]*:|$)/
+
);
if (length($ans)) {
$trunk_path = $ans;
last;
}
}
- $branch_path = $trunk_path.'/branches';
+ $branch_path ||= $trunk_path.'/branches';
{
my $ans = get_prompt(
loc("And where is the branches/? (%1)\n=> ", $branch_path),
- qr/^(?:.*)/
+ qr/^(?:\/?[A-Za-z][-+.A-Za-z0-9]*:|$)/
);
if (length($ans)) {
$branch_path = $ans;
last;
}
}
- $tag_path = $trunk_path.'/tags';
+ $tag_path ||= $trunk_path.'/tags';
{
my $ans = get_prompt(
- loc("And where is the tags/? (press enter to skip)"),
- qr/^(?:.*)/
+ loc("And where is the tags/? (%1) (or 's' to skip)", $tag_path),
+ qr/^(?:\/?[A-Za-z][-+.A-Za-z0-9]*:|$)/
);
if (length($ans)) {
$tag_path = $ans;
+ $tag_path = '' if lc($ans) eq 's';
last;
}
}
#XXX implement setting properties of project here
+ my ($anchor, $editor) = $self->get_dynamic_editor ($target);
+ my $baton = $editor->open_directory ('/', 0, $target->revision);
+ {
+ $editor->change_dir_prop ($baton, "svk:project:$project_name:path-trunk", $trunk_path);
+ $editor->change_dir_prop ($baton, "svk:project:$project_name:path-branches", $branch_path);
+ $editor->change_dir_prop ($baton, "svk:project:$project_name:path-tags", $tag_path);
+ }
+ $editor->close_directory ($baton);
+ $self->adjust_anchor ($editor);
+ $self->finalize_dynamic_editor ($editor);
+ my $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"));
+ } else {
+ $logger->info( loc("Project setup success.\n"));
+ }
return;
}
return;
Modified: trunk/lib/SVK/Project.pm
==============================================================================
--- trunk/lib/SVK/Project.pm (original)
+++ trunk/lib/SVK/Project.pm Mon Apr 28 05:09:52 2008
@@ -121,21 +121,6 @@
return \@branches;
}
-sub create_to_prop {
- my ($self, $pathobj, $project_name, @paths) = @_;
-
- my $fs = $pathobj->depot->repos->fs;
- my $root = $fs->revision_root( $fs->youngest_rev );
- my ($prop_path) = $root->node_prop('/','svm:mirror') =~ m/^(\S+)\s+$/;
- my $allprops = $root->node_proplist($prop_path);
-
- my %props;
- $props{'path-trunk'} = $paths[0];
- $props{'path-branches'} = $paths[1];
- $props{'path-tags'} = $paths[2] || '';
- return undef;
-}
-
sub create_from_prop {
my ($self, $pathobj) = @_;
@@ -159,6 +144,7 @@
map {
my $prop = $allprops->{'svk:project:'.$project_name.':'.$_};
$prop =~ s{/$}{};
+ $prop =~ s{^/}{};
$_ => $prop_path.'/'.$prop }
('path-trunk', 'path-branches', 'path-tags');
@@ -230,7 +216,7 @@
($trunk_path, $branch_path, $tag_path) =
map { $mirror_path.$project_name."/".$_ } ('trunk', 'branches', 'tags');
- map { '/'.$mirror_path.$project_name."/".$_ } ('trunk', 'branches', 'tags');
+# map { '/'.$mirror_path.$project_name."/".$_ } ('trunk', 'branches', 'tags');
# check trunk, branch, tag, these should be metadata-ed
# we check if the structure of mirror is correct, otherwise go again
for my $_path ($trunk_path, $branch_path, $tag_path) {
Modified: trunk/t/bm/prop-setup.t
==============================================================================
--- trunk/t/bm/prop-setup.t (original)
+++ trunk/t/bm/prop-setup.t Mon Apr 28 05:09:52 2008
@@ -2,7 +2,7 @@
# This test for trunk and/or branches are not in trunk/ and/or branches/ directories
use strict;
use SVK::Test;
-plan tests => 7;
+plan tests => 10;
our $output;
my ($xd, $svk) = build_test('test');
@@ -32,8 +32,8 @@
chdir($copath);
is_output ($svk, 'branch', ['--list', '//mirror/nomeans/A'], ['No project found.']);
-TODO: {
-local $TODO = 'Need to implement br --setup ';
+#TODO: {
+#local $TODO = 'Need to implement br --setup ';
$answer = ['','/A-b',''];
$svk->branch('--setup', '//mirror/nomeans/A');
is_output ($svk, 'branch', ['--list', '//mirror/nomeans/A'], []);
@@ -54,4 +54,4 @@
qr/Project detected in specified path./);
is_output ($svk, 'branch', ['--setup', '//mirror/nomeans/projectB'],
['Project already set in properties: //mirror/nomeans/projectB']);
-}
+#}
More information about the svk-commit
mailing list