[Bps-public-commit] git-sync branch, master, updated. e41863d1e900a0c3711178b32e69b358eb6edf5b

Alex M Vandiver alexmv at bestpractical.com
Sat Nov 21 19:13:48 EST 2009


The branch, master has been updated
       via  e41863d1e900a0c3711178b32e69b358eb6edf5b (commit)
       via  34dc03fc3a19b5904e0642ebde6484b93dbf3460 (commit)
       via  9a483fbc411bb95a8bccfecc48f3ddac96c90f85 (commit)
      from  784b144a03a0246a1a9c2832e90c8fc5b7766e57 (commit)

Summary of changes:
 git-sync |   56 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 49 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit 9a483fbc411bb95a8bccfecc48f3ddac96c90f85
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 16:47:10 2009 -0500

    Rename confusingly-named new() function to clone()

diff --git a/git-sync b/git-sync
index 4a2cba9..f49b306 100755
--- a/git-sync
+++ b/git-sync
@@ -116,10 +116,10 @@ sub sync_all_github {
             if (-e $root) {
                 update($root, 1);
             } else {
-                my $auth = new($root => "git\@github.com:$acct/$reponame.git" => $config{email});
+                my $auth = clone($root => "git\@github.com:$acct/$reponame.git" => $config{email});
                 unless ($auth) {
                     printf "  %-40s ", "...trying again, anonymously";
-                    new($root => "git://github.com/$acct/$reponame.git" => $config{email});
+                    clone($root => "git://github.com/$acct/$reponame.git" => $config{email});
                 }
             }
         }
@@ -166,7 +166,7 @@ sub sync_all_remote {
                 print $verbose ? colored("[ sync.ignore set ]\n", "dark") : "\r" and next
                     if defined $ignore and $ignore eq 'true';
 
-                new($into => "$config{host}:$path/$reponame", $config{email});
+                clone($into => "$config{host}:$path/$reponame", $config{email});
             }
         }
     }
@@ -266,7 +266,7 @@ sub update {
 
 }
 
-sub new {
+sub clone {
     # Path to clone into, path to clone from, user
     my ($into, $from, $email) = @_;
     local $?;

commit 34dc03fc3a19b5904e0642ebde6484b93dbf3460
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 16:50:20 2009 -0500

    Comment a confusingly too-magical line

diff --git a/git-sync b/git-sync
index f49b306..dfdd457 100755
--- a/git-sync
+++ b/git-sync
@@ -203,7 +203,7 @@ sub update {
     } else {
         my $ret = eval { $repo->command( [qw/remote update --prune/], STDERR => 0 ); } unless $pretend;
     }
-    kill $? & 127, $$ if $? & 127;
+    kill $? & 127, $$ if $? & 127; # Propagate the signal it died with, if any
 
     my $error = $@; chomp $error;
     print colored("[ Fetch failed! $error]\n", "bold red") and return if $@;
@@ -235,7 +235,7 @@ sub update {
         print logs($repo, $branch => $tracking);
 
         my $pull = $pretend ? "" : `git pull --stat`;
-        kill $? & 127, $$ if $? & 127;
+        kill $? & 127, $$ if $? & 127; # Propagate the signal it died with, if any
 
         # This line will always be present, and is content-free
         $pull =~ s/^First, rewinding head.*?\n//m;
@@ -279,7 +279,7 @@ sub clone {
         print colored( "Error: $@\n", "red") if ($verbose);
         return undef;
     }
-    kill $? & 127, $$ if $? & 127;
+    kill $? & 127, $$ if $? & 127; # Propagate the signal it died with, if any
 
     Git::command( config => "--file", "$into/.git/config", "user.email", $email )
           if $email;

commit e41863d1e900a0c3711178b32e69b358eb6edf5b
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 19:10:57 2009 -0500

    Add support for SSH master connections
    
    SSH master connections remove the overhead of re-creating the ssh
    connection every time `git remote update` is called; instead, the
    existing master connection is used to tunnel a new connection, which
    is nearly instantaneous.
    
    To enable SSH master connections, add the following to ~/.ssh/config:
    
        Host *
        ControlMaster auto
        ControlPath ~/.ssh/master-%r@%h:%p

diff --git a/git-sync b/git-sync
index dfdd457..7dfe92f 100755
--- a/git-sync
+++ b/git-sync
@@ -144,6 +144,8 @@ sub sync_all_remote {
             unless eval { File::Path::mkpath($config{into}) };
     }
 
+    my $pid = start_master($config{host});
+
     my @paths = ref $config{path} ? @{$config{path}} : ($config{path});
     for my $path (@paths) {
         my @list = `ssh $config{host} ls $path`;
@@ -170,6 +172,46 @@ sub sync_all_remote {
             }
         }
     }
+
+    # Shut down master connection
+    system "ssh", "-O", "exit", $config{host}
+        if $pid and kill 0, $pid;
+}
+
+sub start_master {
+    my ($host) = @_;
+    printf colored("  %-40s ", "dark"), "Starting ssh master connection";
+    my $status = `ssh -O check $host 2>&1`;
+    if ( $status =~ /^Master running/) {
+        print colored( "[ Already running ]\n", "dark");
+        return;
+    } elsif ( $status =~ /^No ControlPath/) {
+        print colored( "[ Not configured -- see ControlPath in sshd_config(5) ]\n", "yellow" );
+        return;
+    }
+
+
+    local $SIG{USR1} = sub {
+        die "Failed to set up SSH master connection\n";
+    };
+
+    my $parent = $$;
+    my $pid    = fork;
+    die "Fork failed: $!" unless $pid >= 0;
+    if ( not $pid ) {
+
+        # Start the master
+        system("ssh", "-x", "-M", "-N", $host);
+
+        # Signal the parent when we're done; we're still waiting,
+        # we'll catch this and abort.
+        kill 'USR1', $parent;
+        exit;
+    }
+
+    sleep 1 while (`ssh -O check $host 2>&1` !~ /Master running/);
+    print colored( "[ Done ]\n", "green" );
+    return $pid;
 }
 
 sub already {

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



More information about the Bps-public-commit mailing list