[Bps-public-commit] Shipwright branch, master, updated. 43376f38c063be77fbeb351e6d4db8fe5f57f478

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Aug 5 22:41:19 EDT 2009


The branch, master has been updated
       via  43376f38c063be77fbeb351e6d4db8fe5f57f478 (commit)
      from  ce9880a812882ba784113c86d051525de2cba7c4 (commit)

Summary of changes:
 lib/Shipwright/Backend/SVK.pm |   89 +++++++++++++++++++++--------------------
 lib/Shipwright/Backend/SVN.pm |   72 ++++++++++++++++-----------------
 2 files changed, 80 insertions(+), 81 deletions(-)

- Log -----------------------------------------------------------------
commit 43376f38c063be77fbeb351e6d4db8fe5f57f478
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Aug 6 10:41:11 2009 +0800

    keep a checked out version for svn and svk backends too

diff --git a/lib/Shipwright/Backend/SVK.pm b/lib/Shipwright/Backend/SVK.pm
index 289b611..1e715fd 100644
--- a/lib/Shipwright/Backend/SVK.pm
+++ b/lib/Shipwright/Backend/SVK.pm
@@ -5,7 +5,6 @@ use strict;
 use Carp;
 use File::Spec::Functions qw/catfile/;
 use Shipwright::Util;
-use File::Temp qw/tempdir/;
 use File::Copy::Recursive qw/rcopy/;
 use File::Path qw/remove_tree/;
 
@@ -41,6 +40,7 @@ sub initialize {
         _initialize => 1,
         comment     => 'created project',
     );
+    $self->_initialize_local_dir;
 }
 
 sub _svnroot {
@@ -123,19 +123,17 @@ sub _cmd {
             }
 
             if ( $self->info( path => $path ) ) {
-                my $tmp_dir =
-                  tempdir( 'shipwright_backend_svk_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
                 @cmd = (
-                    sub { remove_tree( $tmp_dir ) },
-                    [ $ENV{'SHIPWRIGHT_SVK'}, 'checkout', $self->repository . $path, $tmp_dir ],
-                    sub { remove_tree( $tmp_dir ) },
-                    sub { rcopy( $source, $tmp_dir ) },
+                    sub {
+                        $self->_sync_local_dir( $path );
+                        remove_tree( $self->local_dir . $path );
+                        rcopy( $source, $self->local_dir . $path, );
+                    },
                     [
-                        $ENV{'SHIPWRIGHT_SVK'},      'commit',
-                        '--import', $tmp_dir,
-                        '-m',       $args{comment}
+                        $ENV{'SHIPWRIGHT_SVK'}, 'commit',
+                        '--import',             $self->local_dir . $path,
+                        '-m',                   $args{comment}
                     ],
-                    [ $ENV{'SHIPWRIGHT_SVK'}, 'checkout', '-d', $tmp_dir ],
                 );
             }
             else {
@@ -146,6 +144,7 @@ sub _cmd {
                 ];
             }
         }
+
     }
     elsif ( $type eq 'commit' ) {
         @cmd = [
@@ -163,8 +162,8 @@ sub _cmd {
     }
     elsif ( $type eq 'delete' ) {
         @cmd = [
-            $ENV{'SHIPWRIGHT_SVK'}, 'delete', '-m',
-            'delete repository',
+            $ENV{'SHIPWRIGHT_SVK'}, 'delete',
+            '-m',                   'delete repository',
             $self->repository . $args{path},
         ];
     }
@@ -196,24 +195,21 @@ sub _yml {
     my $path = shift;
     my $yml  = shift;
 
-    $path = '/' . $path unless $path =~ m{^/};
-
-    my ($f) = $path =~ m{.*/(.*)$};
+    my $file = catfile( $self->local_dir . $path );
 
     if ($yml) {
-        my $dir =
-          tempdir( 'shipwright_backend_svk_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
-        my $file = catfile( $dir, $f );
-
-        $self->checkout( path => $path, target => $file );
-
+        if ( $path =~ /scripts/ ) {
+            $self->_sync_local_dir('/scripts');
+        }
+        else {
+            $self->_sync_local_dir($path);
+        }
         Shipwright::Util::DumpFile( $file, $yml );
         $self->commit( path => $file, comment => "updated $path" );
-        $self->checkout( detach => 1, target => $file );
     }
     else {
-        my ($out) =
-          Shipwright::Util->run( [ $ENV{'SHIPWRIGHT_SVK'}, 'cat', $self->repository . $path ] );
+        my ($out) = Shipwright::Util->run(
+            [ $ENV{'SHIPWRIGHT_SVN'}, 'cat', $self->_svnroot . $path ] );
         return Shipwright::Util::Load($out);
     }
 }
@@ -276,21 +272,14 @@ sub _update_file {
     my $path   = shift;
     my $latest = shift;
 
-    my $dir =
-      tempdir( 'shipwright_backend_svk_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
-    my $file = catfile( $dir, $path );
-
-    $self->checkout(
-        path   => $path,
-        target => $file,
-    );
+    my $file = $self->local_dir . $path;
+    $self->_sync_local_dir( $path );
 
     rcopy( $latest, $file ) or confess "can't copy $latest to $file: $!";
     $self->commit(
         path    => $file,
         comment => "updated $path",
     );
-    $self->checkout( detach => 1, target => $file );
 }
 
 sub _update_dir {
@@ -298,22 +287,34 @@ sub _update_dir {
     my $path   = shift;
     my $latest = shift;
 
-    my $dir =
-      tempdir( 'shipwright_backend_svk_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
-    rmdir $dir;
-
-    $self->checkout(
-        path   => $path,
-        target => $dir,
-    );
-
+    $self->_sync_local_dir( $path );
+    my $dir = $self->local_dir . $path;
+    remove_tree( $dir );
     rcopy( $latest, $dir ) or confess "can't copy $latest to $dir: $!";
     $self->commit(
         path    => $dir,
         comment => "updated $path",
         import  => 1,
     );
-    $self->checkout( detach => 1, target => $dir );
+}
+
+sub _initialize_local_dir {
+    my $self = shift;
+    # the 0 is very important, or it may results in recursion
+    my $target = $self->local_dir( 0 ); 
+    remove_tree( $target ) if -e $target;
+
+    Shipwright::Util->run(
+        [ $ENV{'SHIPWRIGHT_SVK'}, 'checkout', $self->repository, $target ] );
+    return $target;
+}
+
+sub _sync_local_dir {
+    my $self = shift;
+    my $path = shift || '';
+
+    Shipwright::Util->run(
+        [ $ENV{'SHIPWRIGHT_SVK'}, 'update', $self->local_dir . $path ] );
 }
 
 =back
diff --git a/lib/Shipwright/Backend/SVN.pm b/lib/Shipwright/Backend/SVN.pm
index d1504fd..2f1398e 100644
--- a/lib/Shipwright/Backend/SVN.pm
+++ b/lib/Shipwright/Backend/SVN.pm
@@ -5,7 +5,6 @@ use strict;
 use Carp;
 use File::Spec::Functions qw/catfile/;
 use Shipwright::Util;
-use File::Temp qw/tempdir/;
 use File::Copy::Recursive qw/rcopy/;
 
 our %REQUIRE_OPTIONS = ( import => [qw/source/] );
@@ -132,8 +131,8 @@ sub _cmd {
     }
     elsif ( $type eq 'delete' ) {
         @cmd = [
-            $ENV{'SHIPWRIGHT_SVN'}, 'delete', '-m',
-            'delete ' . $args{path},
+            $ENV{'SHIPWRIGHT_SVN'}, 'delete',
+            '-m',                   'delete ' . $args{path},
             $self->repository . $args{path},
         ];
     }
@@ -165,30 +164,21 @@ sub _yml {
     my $path = shift;
     my $yml  = shift;
 
-    $path = '/' . $path unless $path =~ m{^/};
-
-    my ( $p_dir, $f );
-    if ( $path =~ m{(.*)/(.*)$} ) {
-        $p_dir = $1;
-        $f     = $2;
-    }
+    my $file = $self->local_dir . $path;
 
     if ($yml) {
-        my $dir =
-          tempdir( 'shipwright_backend_svn_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
-        my $file = catfile( $dir, $f );
-
-        $self->checkout(
-            path   => $p_dir,
-            target => $dir,
-        );
-
+        if ( $path =~ /scripts/ ) {
+            $self->_sync_local_dir('/scripts');
+        }
+        else {
+            $self->_sync_local_dir($path);
+        }
         Shipwright::Util::DumpFile( $file, $yml );
         $self->commit( path => $file, comment => "updated $path" );
     }
     else {
-        my ($out) =
-          Shipwright::Util->run( [ $ENV{'SHIPWRIGHT_SVN'}, 'cat', $self->repository . $path ] );
+        my ($out) = Shipwright::Util->run(
+            [ $ENV{'SHIPWRIGHT_SVN'}, 'cat', $self->repository . $path ] );
         return Shipwright::Util::Load($out);
     }
 }
@@ -249,22 +239,13 @@ sub _update_file {
     my $path   = shift;
     my $latest = shift;
 
-    if ( $path =~ m{(.*)/(.*)$} ) {
-        my $dir =
-          tempdir( 'shipwright_backend_svn_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
-        my $file = catfile( $dir, $2 );
-
-        $self->checkout(
-            path   => $1,
-            target => $dir,
-        );
-
-        rcopy( $latest, $file ) or confess "can't copy $latest to $file: $!";
-        $self->commit(
-            path    => $file,
-            comment => "updated $path",
-        );
-    }
+    $self->_sync_local_dir( $path );
+    my $file = $self->local_dir . $path;
+    rcopy( $latest, $file ) or confess "can't copy $latest to $file: $!";
+    $self->commit(
+        path => $file,
+        comment => "updated $path",
+    );
 }
 
 sub _update_dir {
@@ -276,6 +257,23 @@ sub _update_dir {
     $self->import( path => $path, source => $latest, _initialize => 1 );
 }
 
+sub _initialize_local_dir {
+    my $self = shift;
+    # the 0 is very important, or it may results in recursion
+    my $target = $self->local_dir( 0 ); 
+    remove_tree( $target ) if -e $target;
+
+    Shipwright::Util->run(
+        [ $ENV{'SHIPWRIGHT_SVN'}, 'checkout', $self->repository, $target ] );
+    return $target;
+}
+
+sub _sync_local_dir {
+    my $self = shift;
+    my $path = shift || '';
+    Shipwright::Util->run(
+        [ $ENV{'SHIPWRIGHT_SVN'}, 'update', $self->local_dir . $path ], 1 );
+}
 
 =back
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list