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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Fri Jul 31 02:51:27 EDT 2009


The branch, master has been updated
       via  b3f0fef3590b9d1dbde6d877d569c7ae53832790 (commit)
      from  2f5b032809ff06fad17a6fc05f9ff34bb1501f4a (commit)

Summary of changes:
 lib/Shipwright/Script/List.pm |   48 ++++++++++++++++++++++++++++++++++------
 lib/Shipwright/Source/Git.pm  |   27 +++++++++++++++++------
 share/bin/shipwright-builder  |    8 +++++-
 3 files changed, 66 insertions(+), 17 deletions(-)

- Log -----------------------------------------------------------------
commit b3f0fef3590b9d1dbde6d877d569c7ae53832790
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 31 14:50:57 2009 +0800

    complete the git version support

diff --git a/lib/Shipwright/Script/List.pm b/lib/Shipwright/Script/List.pm
index 52afd78..3efbf83 100644
--- a/lib/Shipwright/Script/List.pm
+++ b/lib/Shipwright/Script/List.pm
@@ -8,6 +8,9 @@ use base qw/App::CLI::Command Class::Accessor::Fast Shipwright::Script/;
 __PACKAGE__->mk_accessors(qw/with_latest_version only_update/);
 
 use Shipwright;
+use Cwd qw/getcwd/;
+use File::Temp qw/tempdir/;
+use File::Spec::Functions qw/catdir/;
 
 sub options {
     (
@@ -58,11 +61,12 @@ sub run {
                 $latest_version->{ $map->{$module} } =
                   $self->_latest_version( name => $module );
             }
-
             for my $name ( keys %$source ) {
                 next if exists $latest_version->{$name};
-                if ( $source->{$name} =~ m{^(sv[nk]|shipwright):} ) {
-                    for my $branch ( keys %{ $source->{$name} } ) {
+                for my $branch ( keys %{ $source->{$name} } ) {
+                    if ( $source->{$name}{$branch} =~
+                        m{^(sv[nk]|git|shipwright):} )
+                    {
                         $latest_version->{$name}{$branch} =
                           $self->_latest_version(
                             url => $source->{$name}{$branch} );
@@ -187,20 +191,48 @@ sub _latest_version {
             $args{url} =~ s!/[^/]+$!!;
         }
 
-        # has url, meaning svn or svk
+        # has url, meaning svn, svk or git
         if ( $args{url} =~ /^svn[:+]/ ) {
             $args{url} =~ s{^svn:(?!//)}{};
             $cmd = [ $ENV{'SHIPWRIGHT_SVN'}, 'info', $args{url} ];
+            $cmd = [ $ENV{'SHIPWRIGHT_SVK'}, 'info', $args{url} ];
+            ($out) = Shipwright::Util->run( $cmd, 1 );    # ignore failure
+            if ( $out =~ /^Revision:\s*(\d+)/m ) {
+                return $1;
+            }
         }
         elsif ( $args{url} =~ m{^(svk:|//)} ) {
             $args{url} =~ s/^svk://;
             $cmd = [ $ENV{'SHIPWRIGHT_SVK'}, 'info', $args{url} ];
+            ($out) = Shipwright::Util->run( $cmd, 1 );    # ignore failure
+            if ( $out =~ /^Revision:\s*(\d+)/m ) {
+                return $1;
+            }
         }
-
-        ($out) = Shipwright::Util->run( $cmd, 1 );    # ignore failure
-        if ( $out =~ /^Revision:\s*(\d+)/m ) {
-            return $1;
+        elsif ( $args{url} =~ /^git:/ ) {
+            $args{url} =~ s{^git:(?!//)}{};
+
+         # TODO XXX is there a better way that we can get latest version of git?
+         # current way is not too heavy: it needs clone and log
+
+            my $cwd = getcwd();
+            my $dir = tempdir(
+                'shipwright_list_git_XXXXXX',
+                CLEANUP => 1,
+                TMPDIR  => 1
+            );
+            my $path = catdir( $dir, 'git' );
+            Shipwright::Util->run(
+                [ $ENV{SHIPWRIGHT_GIT}, 'clone', $args{url}, $path, ] );
+            chdir $path;
+            ($out) = Shipwright::Util->run( [ $ENV{SHIPWRIGHT_GIT}, 'log' ] );
+            chdir $cwd;
+
+            if ( $out =~ /^commit\s+(\w+)/m ) {
+                return $1;
+            }
         }
+
     }
     elsif ( $args{name} ) {
 
diff --git a/lib/Shipwright/Source/Git.pm b/lib/Shipwright/Source/Git.pm
index be19e4e..22a1265 100644
--- a/lib/Shipwright/Source/Git.pm
+++ b/lib/Shipwright/Source/Git.pm
@@ -7,6 +7,7 @@ use File::Spec::Functions qw/catdir/;
 use File::Path qw/remove_tree/;
 
 use base qw/Shipwright::Source::Base/;
+use Cwd qw/getcwd/;
 
 =head2 new
 
@@ -50,14 +51,26 @@ sub _run {
     my $self   = shift;
     my $source = $self->source;
 
-    my @cmds = (
-        [
-            $ENV{'SHIPWRIGHT_GIT'}, 'clone', $self->source,
-            catdir( $self->download_directory, $self->name ),
-        ],
-    );
+    my $path = catdir( $self->download_directory, $self->name );
+    my @cmds = ( [ $ENV{'SHIPWRIGHT_GIT'}, 'clone', $self->source, $path, ] );
 
-# TODO handle the version stuff
+    # work out the version stuff
+    push @cmds, sub {
+        my $cwd = getcwd();
+        chdir $path;
+        if ( $self->version ) {
+            Shipwright::Util->run(
+                [ $ENV{'SHIPWRIGHT_GIT'}, 'checkout', $self->version ] );
+        }
+        else {
+            my ($out) = Shipwright::Util->run(
+                [ $ENV{'SHIPWRIGHT_GIT'}, 'log' ] );
+            if ( $out =~ /^commit\s+(\w+)/m ) {
+                $self->version($1);
+            }
+        }
+        chdir $cwd;
+    };
 
     push @cmds, sub {
         remove_tree( catdir( $self->download_directory, $self->name, '.git' ) );
diff --git a/share/bin/shipwright-builder b/share/bin/shipwright-builder
index 7d37673..68e3884 100755
--- a/share/bin/shipwright-builder
+++ b/share/bin/shipwright-builder
@@ -575,7 +575,7 @@ sub wrap_bin {
 
         my $wrap_file = catfile( $wrap_dir, $file );
         my $tmp = $File::Find::dir;
-        $tmp =~ s/$args{'install-base'}//g;
+        $tmp =~ s/\Q$args{'install-base'}\E//g;
         my $wrapped_depth =
           scalar( splitdir($File::Find::dir) ) -
           scalar( splitdir( $args{'install-base'} ) ) - 2;
@@ -830,7 +830,7 @@ sub process_tmp_dists {
 }
 
 # this's a simpler version compared to shipwright's source part, only
-# dir, svn and svk are supported currently.
+# dir, svn, svk and git are supported currently.
 # warn: dist in svn and svk must be a dir instead of a compressed file.
 
 sub cmd {
@@ -847,6 +847,10 @@ sub cmd {
         $source =~ s/^svk://i;
         return "svk co $source tmp_dists/$name";
     }
+    elsif ( $source =~ m{^git:}i ) {
+        $source =~ s{^git:(?!//)}{}i;
+        return "git clone $source tmp_dists/$name";
+    }
 
     return;
 }

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



More information about the Bps-public-commit mailing list