chiark / gitweb /
implement initiator_expect
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 66f08c1d87eb6ed1b71c7c1941742cf146ad29da..381b7311946f2e7cf6dac556f3bbed1e026c6684 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -125,7 +125,7 @@ sub fetchspec () {
     return  "+".rrref().":".lrref();
 }
 
-our $ua;
+#---------- remote protocol support, common ----------
 
 # remote push initiator/responder protocol:
 #  < dgit-remote-push-ready [optional extra info ignored by old initiators]
@@ -160,24 +160,6 @@ our $ua;
 #
 #  > complete
 
-sub responder_send_command ($) {
-    my ($command) = @_;
-    return unless $we_are_responder;
-    # called even without $we_are_responder
-    print DEBUG "<< $command\n";
-    print $command, "\n" or die $!;
-}    
-
-sub progress {
-    if ($we_are_responder) {
-       my $m = join '', @_;
-       responder_send_command "progress ".length($m) or die $!;
-       print $m or die $!;
-    } else {
-       print @_, "\n";
-    }
-}
-
 sub badproto ($$) {
     my ($fh, $m) = @_;
     fail "connection lost: $!" if $fh->error;
@@ -222,6 +204,16 @@ sub protocol_receive_file ($$) {
     }
 }
 
+#---------- remote protocol support, responder ----------
+
+sub responder_send_command ($) {
+    my ($command) = @_;
+    return unless $we_are_responder;
+    # called even without $we_are_responder
+    print DEBUG "<< $command\n";
+    print $command, "\n" or die $!;
+}    
+
 sub responder_send_file ($$) {
     my ($keyword, $ourfn) = @_;
     return unless $we_are_responder;
@@ -239,6 +231,27 @@ sub responder_receive_files ($@) {
     protocol_expect \*STDIN, { m/^files-end$/ };
 }
 
+#---------- remote protocol support, initiator ----------
+
+sub initiator_expect (&) {
+    my ($match) = @_;
+    protocol_expect \*RO, &$match;
+}
+
+#---------- end remote code ----------
+
+sub progress {
+    if ($we_are_responder) {
+       my $m = join '', @_;
+       responder_send_command "progress ".length($m) or die $!;
+       print $m or die $!;
+    } else {
+       print @_, "\n";
+    }
+}
+
+our $ua;
+
 sub url_get {
     if (!$ua) {
        $ua = LWP::UserAgent->new();
@@ -1325,6 +1338,8 @@ sub cmd_push {
     dopush();
 }
 
+#---------- remote commands' implementation ----------
+
 sub cmd_remote_push_responder {
     my ($nrargs) = shift @ARGV;
     my (@rargs) = @ARGV[0..$nrargs-1];
@@ -1365,6 +1380,8 @@ sub cmd_rpush {
     }
 }
 
+#---------- building etc. ----------
+
 our $version;
 our $sourcechanges;
 our $dscfn;
@@ -1533,6 +1550,8 @@ sub cmd_quilt_fixup {
     build_maybe_quilt_fixup();
 }
 
+#---------- argument parsing and main program ----------
+
 sub cmd_version {
     print "dgit version $our_version\n" or die $!;
     exit 0;