[Bps-public-commit] r9812 - in bpsbuilder/BPB/lib/BPB: Backend
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue Dec 4 04:46:42 EST 2007
Author: sunnavy
Date: Tue Dec 4 04:46:36 2007
New Revision: 9812
Modified:
bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
bpsbuilder/BPB/lib/BPB/Script/Checkout.pm
bpsbuilder/BPB/lib/BPB/Script/Export.pm
bpsbuilder/BPB/lib/BPB/Script/Import.pm
Log:
initial support for import, checkout, export with version
Modified: bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend/SVK.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Backend/SVK.pm Tue Dec 4 04:46:36 2007
@@ -47,9 +47,10 @@
for (qw/bpb main deps/) {
mkdir File::Spec->catfile( $dir, $_ );
}
- open my $order, '>', File::Spec->catfile( $dir, 'bpb', 'order.yml' );
- print $order '';
+ open my $order, '>', File::Spec->catfile( $dir, 'bpb', 'order.yml' );
+ open my $version, '>', File::Spec->catfile( $dir, 'bpb', 'version.yml' );
close $order;
+ close $version;
$self->import( source => $dir, _initialize => 1 );
}
@@ -63,8 +64,16 @@
my %args = @_;
my $cmd = $self->_cmd( import => %args );
$self->_run($cmd);
- $self->add_to_order( source => $args{source} )
- if $args{category} && $args{category} eq 'dependance';
+
+ if ( $args{category} ) {
+ if ( $args{category} eq 'dependance' ) {
+ $self->_update_order( source => $args{source} );
+ }
+ elsif ( $args{category} eq 'main' ) {
+ $self->_update_version( version => $args{version} )
+ if $args{version};
+ }
+ }
}
=head2 export
@@ -118,6 +127,14 @@
else {
my $path = $self->_absolute_path( $args{category}, $args{path} );
$cmd = join ' ', $self->command, 'checkout', $path, $args{target};
+
+ if ( $args{version} ) {
+ my $revision =
+ $self->_version_to_revision( version => $args{version} );
+ croak 'no such version' unless $revision;
+ $cmd .= ' --revision ' . $revision;
+ }
+
}
}
elsif ( $type eq 'import' ) {
@@ -151,11 +168,11 @@
return join ' ', $cmd, @{ $args{extra} };
}
-sub add_to_order {
+sub _update_order {
my $self = shift;
my %args = @_;
my $name = $args{source};
- my $dir = tempdir( CLEANUP => 0 );
+ my $dir = tempdir( CLEANUP => 1 );
my $file = File::Spec->catfile( $dir, 'order.yml' );
$self->checkout(
@@ -178,6 +195,64 @@
$self->checkout( detach => 1, path => $file );
}
+sub _update_version {
+ my $self = shift;
+ my %args = @_;
+ my $version = $args{version};
+
+ my $dir = tempdir( CLEANUP => 0 );
+ my $file = File::Spec->catfile( $dir, 'version.yml' );
+
+ $self->checkout(
+ category => 'bpb',
+ path => 'version.yml',
+ target => $file,
+ );
+
+ my $yml = BPB::Config::LoadFile($file) || {};
+
+ $yml->{$version} =
+ $self->_current_revision + 1; # the 1 is for the update version.yml
+ BPB::Config::DumpFile( $file, $yml );
+ $self->commit(
+ path => $file,
+ comment => "added version" . $yml->{$version}
+ );
+ $self->checkout( detach => 1, path => $file );
+}
+
+sub _current_revision {
+ my $self = shift;
+ my $cmd = join ' ', $self->command, 'info', $self->_absolute_path;
+ my @info = `$cmd`;
+ for (@info) {
+ if (/Revision: (\d+)/) {
+ return $1;
+ }
+ }
+ return;
+}
+
+sub _version_to_revision {
+ my $self = shift;
+ my %args = @_;
+ my $version = $args{version};
+
+ my $dir = tempdir( CLEANUP => 1 );
+ my $file = File::Spec->catfile( $dir, 'version.yml' );
+
+ $self->export(
+ category => 'bpb',
+ path => 'version.yml',
+ target => $file,
+ );
+
+ my $yml = BPB::Config::LoadFile($file) || {};
+
+ return $yml->{$version};
+
+}
+
sub cat {
my $self = shift;
my %args = @_;
Modified: bpsbuilder/BPB/lib/BPB/Script/Checkout.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Checkout.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Script/Checkout.pm Tue Dec 4 04:46:36 2007
@@ -5,28 +5,29 @@
use Carp;
use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config moniker category path target/);
+__PACKAGE__->mk_accessors(qw/config moniker category path target version/);
use BPB;
sub options {
- ( 'k|moniker=s' => 'moniker',
- 'c|config=s' => 'config',
- 'g|category=s' => 'category',
- 'p|path=s' => 'path',
- 't|target=s' => 'target',
- )
+ (
+ 'k|moniker=s' => 'moniker',
+ 'c|config=s' => 'config',
+ 'g|category=s' => 'category',
+ 'p|path=s' => 'path',
+ 't|target=s' => 'target',
+ 'v|version=s' => 'version',
+ );
}
-
sub run {
my $self = shift;
my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
- $bpb->backend->checkout( map { $_, $self->$_ } qw/category path target/ );
+ $bpb->backend->checkout( map { $_, $self->$_ }
+ qw/category path target version/ );
}
-
1;
__END__
Modified: bpsbuilder/BPB/lib/BPB/Script/Export.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Export.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Script/Export.pm Tue Dec 4 04:46:36 2007
@@ -5,28 +5,28 @@
use Carp;
use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config moniker category path target/);
+__PACKAGE__->mk_accessors(qw/config moniker category path target version/);
use BPB;
sub options {
- ( 'k|moniker=s' => 'moniker',
- 'c|config=s' => 'config',
- 'g|category=s' => 'category',
- 'p|path=s' => 'path',
- 't|target=s' => 'target',
- )
+ (
+ 'k|moniker=s' => 'moniker',
+ 'c|config=s' => 'config',
+ 'g|category=s' => 'category',
+ 'p|path=s' => 'path',
+ 't|target=s' => 'target',
+ 'v|version=s' => 'version',
+ );
}
-
sub run {
my $self = shift;
my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
- $bpb->backend->export( map { $_, $self->$_ } qw/category path target/ );
-
+ $bpb->backend->export( map { $_, $self->$_ }
+ qw/category path target version/ );
}
-
1;
__END__
Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm Tue Dec 4 04:46:36 2007
@@ -5,7 +5,7 @@
use Carp;
use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config moniker category comment source/);
+__PACKAGE__->mk_accessors(qw/config moniker category comment source version/);
use BPB;
use File::Spec;
@@ -18,6 +18,7 @@
'g|category=s' => 'category',
'm|comment=s' => 'comment',
's|source=s' => 'source',
+ 'v|version=s' => 'version',
);
}
@@ -27,7 +28,7 @@
$self->source( $source ) if $source;
my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
$self->import_req( $self->source, $bpb );
- $bpb->backend->import( map { $_, $self->$_ } qw/category comment source/ );
+ $bpb->backend->import( map { $_, $self->$_ } qw/category comment source version/ );
}
my %imported;
More information about the Bps-public-commit
mailing list