chiark / gitweb /
rpush: Introduce more sophisticated protocol negotiation.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 23 Jul 2015 23:30:38 +0000 (00:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2015 18:54:45 +0000 (19:54 +0100)
dgit

diff --git a/dgit b/dgit
index 324a65f8a7c415702b62d11e15253ad6934b0ac9..8a54610198e745b3e5f750bf9e787596ee31d5cb 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -39,7 +39,8 @@ use Debian::Dgit;
 
 our $our_version = 'UNRELEASED'; ###substituted###
 
 
 our $our_version = 'UNRELEASED'; ###substituted###
 
-our $rpushprotovsn = 2;
+our @rpushprotovsn_support = qw(2);
+our $protovsn;
 
 our $isuite = 'unstable';
 our $idistro;
 
 our $isuite = 'unstable';
 our $idistro;
@@ -175,7 +176,9 @@ sub deliberately_not_fast_forward () {
 #---------- remote protocol support, common ----------
 
 # remote push initiator/responder protocol:
 #---------- remote protocol support, common ----------
 
 # remote push initiator/responder protocol:
-#  < dgit-remote-push-ready [optional extra info ignored by old initiators]
+#  $ dgit remote-push-build-host <n-rargs> <rargs>... <push-args>...
+#  where <rargs> is <push-host-dir> <supported-proto-vsn>,... ...
+#  < dgit-remote-push-ready <actual-proto-vsn>
 #
 #  > file parsed-changelog
 #  [indicates that output of dpkg-parsechangelog follows]
 #
 #  > file parsed-changelog
 #  [indicates that output of dpkg-parsechangelog follows]
@@ -2104,11 +2107,16 @@ sub cmd_remote_push_build_host {
     autoflush STDOUT 1;
 
     $vsnwant //= 1;
     autoflush STDOUT 1;
 
     $vsnwant //= 1;
-    fail "build host has dgit rpush protocol version".
-       " $rpushprotovsn but invocation host has $vsnwant"
-       unless grep { $rpushprotovsn eq $_ } split /,/, $vsnwant;
+    ($protovsn) = grep {
+       $vsnwant =~ m{^(?:.*,)?$_(?:,.*)?$}
+    } @rpushprotovsn_support;
 
 
-    responder_send_command("dgit-remote-push-ready $rpushprotovsn");
+    fail "build host has dgit rpush protocol versions ".
+       (join ",", @rpushprotovsn_support).
+        " but invocation host has $vsnwant"
+       unless defined $protovsn;
+
+    responder_send_command("dgit-remote-push-ready $protovsn");
 
     changedir $dir;
     &cmd_push;
 
     changedir $dir;
     &cmd_push;
@@ -2154,7 +2162,8 @@ sub cmd_rpush {
        $dir = nextarg;
     }
     $dir =~ s{^-}{./-};
        $dir = nextarg;
     }
     $dir =~ s{^-}{./-};
-    my @rargs = ($dir,$rpushprotovsn);
+    my @rargs = ($dir);
+    push @rargs, join ",", @rpushprotovsn_support;
     my @rdgit;
     push @rdgit, @dgit;
     push @rdgit, @ropts;
     my @rdgit;
     push @rdgit, @dgit;
     push @rdgit, @ropts;
@@ -2172,7 +2181,8 @@ sub cmd_rpush {
     }
     $i_child_pid = open2(\*RO, \*RI, @cmd);
     changedir $i_tmp;
     }
     $i_child_pid = open2(\*RO, \*RI, @cmd);
     changedir $i_tmp;
-    initiator_expect { m/^dgit-remote-push-ready/ };
+    ($protovsn) = initiator_expect { m/^dgit-remote-push-ready (\S+)/ };
+    die "$protovsn ?" unless grep { $_ eq $protovsn } @rpushprotovsn_support;
     for (;;) {
        my ($icmd,$iargs) = initiator_expect {
            m/^(\S+)(?: (.*))?$/;
     for (;;) {
        my ($icmd,$iargs) = initiator_expect {
            m/^(\S+)(?: (.*))?$/;