[Bps-public-commit] Shipwright branch, master, updated. 6587719a9724bb25a06b4c9cd416e3571ca41145

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Aug 5 02:45:03 EDT 2009


The branch, master has been updated
       via  6587719a9724bb25a06b4c9cd416e3571ca41145 (commit)
       via  deb70787a549c55d69f76ab4534336d0cf18a599 (commit)
      from  a7bde2cb4a325222f7e9ae34f6bb1c5e7757bcdc (commit)

Summary of changes:
 lib/Shipwright/Backend/Base.pm |   35 +++++++++++++++++++--
 lib/Shipwright/Backend/Git.pm  |   65 +++++----------------------------------
 lib/Shipwright/Util.pm         |    8 ++--
 t/hello/git.t                  |    2 +-
 4 files changed, 46 insertions(+), 64 deletions(-)

- Log -----------------------------------------------------------------
commit deb70787a549c55d69f76ab4534336d0cf18a599
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Aug 5 14:44:02 2009 +0800

    generalize cloned_dir stuff: now it is local_dir

diff --git a/lib/Shipwright/Backend/Base.pm b/lib/Shipwright/Backend/Base.pm
index 54a644c..51eb50c 100644
--- a/lib/Shipwright/Backend/Base.pm
+++ b/lib/Shipwright/Backend/Base.pm
@@ -10,6 +10,7 @@ use File::Copy::Recursive qw/rcopy/;
 use File::Path qw/make_path remove_tree/;
 use List::MoreUtils qw/uniq firstidx/;
 use Module::Info;
+use MIME::Base64::URLSafe;
 
 our %REQUIRE_OPTIONS = ( import => [qw/source/] );
 
@@ -176,7 +177,7 @@ sub import {
                 && not $args{overwrite} )
             {
                 $self->log->warn(
-"path scripts/$name alreay exists, need to set overwrite arg to overwrite"
+"path /scripts/$name alreay exists, need to set overwrite arg to overwrite"
                 );
             }
             else {
@@ -666,7 +667,7 @@ sub requires {
     my %args = @_;
     my $name = $args{name};
 
-    return $self->_yml( catfile( 'scripts', $name, 'require.yml' ) );
+    return $self->_yml( "/scripts/$name/require.yml" );
 }
 
 =item check_repository
@@ -866,7 +867,35 @@ sub has_branch_support {
     return;
 }
 
-*_cmd = *_update_file = *_update_dir = *_subclass_method;
+*_initialize_local_dir = *_cmd = *_update_file = *_update_dir =
+  *_subclass_method;
+
+=item local_dir
+
+for vcs backend, we made a local checkout/clone version, which will live here
+
+=cut
+
+sub local_dir {
+    my $self      = shift;
+    my $need_init = shift;
+    my $base_dir =
+      catdir( Shipwright::Util->shipwright_user_root(), 'backends' );
+    make_path( $base_dir ) unless -e $base_dir;
+    my $target = catdir( $base_dir, urlsafe_b64encode( $self->repository ) );
+
+# if explicitly defined $need_init, we should do exactly what it asks
+# else, if the $target is not existed yet, we do the init thing
+    if ( defined $need_init ) {
+        if ( $need_init ) {
+            $self->_initialize_local_dir;
+        }
+    }
+    elsif ( !-e $target ) {
+        $self->_initialize_local_dir;
+    }
+    return $target;
+}
 
 =back
 
diff --git a/lib/Shipwright/Backend/Git.pm b/lib/Shipwright/Backend/Git.pm
index e87bc13..8a0e90d 100644
--- a/lib/Shipwright/Backend/Git.pm
+++ b/lib/Shipwright/Backend/Git.pm
@@ -10,7 +10,6 @@ use File::Copy::Recursive qw/rcopy/;
 use Cwd qw/getcwd/;
 use Shipwright::Backend::FS;
 use File::Path qw/remove_tree make_path/;
-use MIME::Base64::URLSafe;
 
 our %REQUIRE_OPTIONS = ( import => [qw/source/] );
 
@@ -49,63 +48,17 @@ sub initialize {
     chdir $path;
     Shipwright::Util->run( [ $ENV{'SHIPWRIGHT_GIT'}, '--bare', 'init' ] );
 
-    $self->initialize_cloned_dir;
-    rcopy( $dir, $self->cloned_dir )
+    $self->_initialize_local_dir;
+    rcopy( $dir, $self->local_dir )
       or confess "can't copy $dir to " . $path . ": $!";
     $self->commit( comment => 'create project' );
     chdir $cwd;
 }
 
-=item cloned_dir
-
-since nearly all the time we need to clone first to use git, it's good that
-we keep a cloned dir.
-returns the cloned_dir
-
-=cut
-
-sub cloned_dir {
-    my $self      = shift;
-    my $need_init = shift;
-    my $base_dir  = $self->cloned_base_dir;
-    my $target = catdir( $base_dir, 'clone.git' );
-
-# if explicitly defined $need_init, we should do exactly what it asks
-# else, if the $target is not existed yet, we do the init thing
-    if ( defined $need_init ) {
-        if ( $need_init ) {
-            $self->initialize_cloned_dir;
-        }
-        else {
-            return $target;
-        }
-    }
-    elsif ( !-e $target ) {
-        $self->initialize_cloned_dir;
-    }
-    return $target;
-}
-
-=item cloned_base_dir
-
-=cut
-
-sub cloned_base_dir {
-    my $self = shift;
-    my $dir  = catdir( Shipwright::Util->shipwright_user_root(),
-        'repositories', urlsafe_b64encode( $self->repository ) );
-    make_path($dir) unless -e $dir;
-    return $dir;
-}
-
-=item initialize_cloned_dir
-
-=cut
-
-sub initialize_cloned_dir {
+sub _initialize_local_dir {
     my $self = shift;
     # the 0 is very important, or it may results in recursion
-    my $target = $self->cloned_dir( 0 ); 
+    my $target = $self->local_dir( 0 ); 
     remove_tree( $target ) if -e $target;
 
     Shipwright::Util->run(
@@ -149,7 +102,7 @@ sub check_repository {
 =item fs_backend
 
 git's local clone is nearly the same as a fs backend, this returns
-a Shipwright::Backend::FS object which reflects the cloned_dir repository.
+a Shipwright::Backend::FS object which reflects the local_dir repository.
 
 =cut
 
@@ -157,9 +110,9 @@ sub fs_backend {
     my $self = shift;
     return $self->{fs_backend} if $self->{fs_backend};
     # XXX TODO not a great place to clone, need refactor
-    my $cloned_dir = $self->cloned_dir;
+    my $local_dir = $self->local_dir;
     $self->{fs_backend} = Shipwright::Backend::FS->new(
-        repository => $self->cloned_dir,
+        repository => $self->local_dir,
     );
     return $self->{fs_backend};
 }
@@ -222,9 +175,9 @@ sub commit {
     my %args =
       ( comment => 'comment', @_ );    # git doesn't allow comment to be blank
 
-    if ( $self->cloned_dir ) {
+    if ( $self->local_dir ) {
         my $cwd = getcwd;
-        chdir $self->cloned_dir or return;
+        chdir $self->local_dir or return;
 
         Shipwright::Util->run( [ $ENV{'SHIPWRIGHT_GIT'}, 'add', '-f', '.' ] );
 
diff --git a/t/hello/git.t b/t/hello/git.t
index ef7f024..dad0b14 100644
--- a/t/hello/git.t
+++ b/t/hello/git.t
@@ -36,7 +36,7 @@ SKIP: {
     $shipwright->backend->initialize();
 
 
-    my $cloned_dir = $shipwright->backend->cloned_dir;
+    my $cloned_dir = $shipwright->backend->local_dir;
     my $dh;
     opendir $dh, $cloned_dir or die $!;
     my @dirs = grep { /^[^.]/ } sort readdir( $dh );

commit 6587719a9724bb25a06b4c9cd416e3571ca41145
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Aug 5 14:44:30 2009 +0800

    make perl happy

diff --git a/lib/Shipwright/Util.pm b/lib/Shipwright/Util.pm
index 9b78456..ff3cc73 100644
--- a/lib/Shipwright/Util.pm
+++ b/lib/Shipwright/Util.pm
@@ -159,23 +159,23 @@ open $null_fh, '>', '/dev/null';
 $cpan_log_path = catfile( tmpdir(), 'shipwright_cpan.log');
 
 open $cpan_fh, '>>', $cpan_log_path;
-$stdout_fh = select;
+$stdout_fh = CORE::select();
 
 sub select {
     my $self = shift;
     my $type = shift;
 
     if ( $type eq 'null' ) {
-        select $null_fh;
+        CORE::select $null_fh;
     }
     elsif ( $type eq 'stdout' ) {
-        select $stdout_fh;
+        CORE::select $stdout_fh;
     }
     elsif ( $type eq 'cpan' ) {
         warn "CPAN related output will be at $cpan_log_path\n"
           unless $cpan_fh_flag;
         $cpan_fh_flag = 1;
-        select $cpan_fh;
+        CORE::select $cpan_fh;
     }
     else {
         confess "unknown type: $type";

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



More information about the Bps-public-commit mailing list