[svk-commit] r2804 - in trunk/lib/SVK: .
nobody at bestpractical.com
nobody at bestpractical.com
Tue May 6 12:26:58 EDT 2008
Author: clsung
Date: Tue May 6 12:26:54 2008
New Revision: 2804
Modified:
trunk/lib/SVK/Command/Branch.pm
trunk/lib/SVK/Project.pm
Log:
- add branch_path() in Project.pm
- return the branch path by the given branch_name
- including local branches
- implement inverse layout project detection
- see also prop-setup-inverse-layout.t
Modified: trunk/lib/SVK/Command/Branch.pm
==============================================================================
--- trunk/lib/SVK/Command/Branch.pm (original)
+++ trunk/lib/SVK/Command/Branch.pm Tue May 6 12:26:54 2008
@@ -192,7 +192,7 @@
sub run {
- my ($self, $target, $branch_path) = @_;
+ my ($self, $target, $branch_name) = @_;
my $proj = $self->load_project($target);
@@ -202,15 +202,8 @@
}
delete $self->{from} if $self->{from} and $self->{from} eq 'trunk';
- my $src_path = '/'.$proj->depot->depotname.'/'.
- ( $self->{from} ?
- $proj->branch_location .'/'. $self->{from}.'/'
- :
- $proj->trunk
- );
- my $newbranch_path = '/'.$proj->depot->depotname.'/'.
- ( $self->{local} ? $proj->local_root : $proj->branch_location ).
- '/'.$branch_path.'/';
+ my $src_path = $proj->branch_path($self->{from} ? $self->{from} : 'trunk');
+ my $newbranch_path = $proj->branch_path($branch_name, $self->{local});
my $src = $self->arg_uri_maybe($src_path);
die loc("Invalid --from argument") if
@@ -218,15 +211,15 @@
my $dst = $self->arg_uri_maybe($newbranch_path);
$SVN::Node::none == $dst->root->check_path($dst->path)
or die loc("Project branch already exists: %1 %2\n",
- $branch_path, $self->{local} ? '(in local)' : '');
+ $branch_name, $self->{local} ? '(in local)' : '');
$self->{parent} = 1;
- $self->{message} ||= "- Create branch $branch_path";
+ $self->{message} ||= "- Create branch $branch_name";
my $ret = $self->SUPER::run($src, $dst);
if (!$ret) {
$logger->info( loc("Project branch created: %1%2%3\n",
- $branch_path,
+ $branch_name,
$self->{local} ? ' (in local)' : '',
$self->{from} ? " (from $self->{from})" : '',
)
@@ -347,13 +340,7 @@
@dsts = map { $self->expand_branch($proj, $_) } @dsts;
@dsts = grep { defined($_) } map {
- my $target_path = '/'.$proj->depot->depotname.'/'.
- ($self->{local} ?
- $proj->local_root."/$_"
- :
- ($_ ne 'trunk' ?
- $proj->branch_location . "/$_" : $proj->trunk)
- );
+ my $target_path = $proj->branch_path($_, $self->{local});
my $target = $self->arg_uri_maybe($target_path);
$target = $target->root->check_path($target->path) ? $target : undef;
@@ -480,14 +467,8 @@
return ;
}
- my $branch_path = shift(@arg);
- my $newtarget_path = '/'.$proj->depot->depotname.'/'.
- ($self->{local} ?
- $proj->local_root."/$branch_path"
- :
- ($branch_path ne 'trunk' ?
- $proj->branch_location . "/$branch_path/" : $proj->trunk)
- );
+ my $branch_name = shift(@arg);
+ my $newtarget_path = $proj->branch_path($branch_name, $self->{local});
unshift @arg, $newtarget_path;
return $self->SUPER::parse_arg(@arg);
}
@@ -520,13 +501,7 @@
my $proj = $self->load_project($target);
- my $newtarget_path = '/'.$proj->depot->depotname.'/'.
- ($self->{local} ?
- $proj->local_root."/$new_path"
- :
- ($new_path ne 'trunk' ?
- $proj->branch_location . "/$new_path/" : $proj->trunk)
- );
+ my $newtarget_path = $proj->branch_path($new_path, $self->{local});
$self->SUPER::run(
$self->arg_uri_maybe($newtarget_path),
Modified: trunk/lib/SVK/Project.pm
==============================================================================
--- trunk/lib/SVK/Project.pm (original)
+++ trunk/lib/SVK/Project.pm Tue May 6 12:26:54 2008
@@ -200,6 +200,25 @@
});
}
+sub _check_project_path {
+ my ($self, $path_obj, $trunk_path, $branch_path, $tag_path) = @_;
+
+ my $checked_result = 1;
+ # 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) {
+ unless ($path_obj->root->check_path($_path) == $SVN::Node::dir) {
+ if ($tag_path eq $_path) { # tags directory is optional
+ $checked_result = 2; # no tags
+ }
+ else {
+ return 0;
+ }
+ }
+ }
+ return $checked_result;
+}
+
# this is heuristics guessing of project and should be replaced
# eventually when we can define project meta data.
sub _find_project_path {
@@ -208,7 +227,22 @@
my ($mirror_path,$project_name);
my ($trunk_path, $branch_path, $tag_path);
my $depotname = $path_obj->depot->depotname;
- my ($path) = $path_obj->depotpath =~ m{^/$depotname/(.*?)(?:/(?:trunk|branches/.*?|tags/.*?))?/?$};
+ # Finding inverse layout first
+ my ($path) = $path_obj->depotpath =~ m{^/$depotname/(.+?/(?:trunk|branches|tags)/[^/]+)};
+ if ($path) {
+ ($mirror_path, $project_name) = # always assume the last entry the projectname
+ $path =~ m{^(.*/)?(?:trunk|branches|tags)/(.+)$};
+ if ($project_name) {
+ ($trunk_path, $branch_path, $tag_path) =
+ map { $mirror_path.$_.'/'.$project_name } ('trunk', 'branches', 'tags');
+ my $result = $self->_check_project_path ($path_obj, $trunk_path, $branch_path, $tag_path);
+ $tag_path = '' if $result == 2;
+ return ($project_name, $trunk_path, $branch_path, $tag_path) if $result > 0;
+ }
+ $project_name = '';
+ }
+ # not found in inverse layout, else
+ ($path) = $path_obj->depotpath =~ m{^/$depotname/(.*?)(?:/(?:trunk|branches/.*?|tags/.*?))?/?$};
if ($path =~ m{^local/([^/]+)/?}) { # guess if in local branch
# should only be 1 entry
@@ -224,23 +258,12 @@
($trunk_path, $branch_path, $tag_path) =
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) {
- unless ($path_obj->root->check_path($_path) == $SVN::Node::dir) {
- if ($tag_path eq $_path) { # tags directory is optional
- undef $tag_path;
- }
- else {
- undef $project_name;
- }
- }
- }
+ my $result = $self->_check_project_path ($path_obj, $trunk_path, $branch_path, $tag_path);
# if not the last entry, then the mirror_path should contains
# trunk/branches/tags, otherwise no need to test
($path) = $mirror_path =~ m{^(.+(?=/(?:trunk|branches|tags)))}
- unless $project_name;
+ unless $result != 0;
+ $tag_path = '' if $result == 2;
return undef unless $path;
}
return ($project_name, $trunk_path, $branch_path, $tag_path);
@@ -255,4 +278,17 @@
if grep { $_ eq $name } @{$self->tags};
return ;
}
+
+sub branch_path {
+ my ($self, $bname, $is_local) = @_;
+ my $branch_path = '/'.$self->depot->depotname.'/'.
+ ($is_local ?
+ $self->local_root."/$bname"
+ :
+ ($bname ne 'trunk' ?
+ $self->branch_location . "/$bname" : $self->trunk)
+ );
+ return $branch_path;
+}
+
1;
More information about the svk-commit
mailing list