chiark / gitweb /
Tag change: Calculate desired tag format
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 24 Jul 2016 17:56:14 +0000 (18:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 Jul 2016 21:55:01 +0000 (22:55 +0100)
Introduce machinery for deciding what format tag to make, during push.
The computation is slightly ad-hoc.

Currently it always returns `old' and does as before, so no overall
functional change with existing configs and existing command lines.

Reserve protocol version 4 for new tag support.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit
dgit.1

diff --git a/dgit b/dgit
index ba3a2e485524f7b4924404ef59bc6410d721f42b..352e5b16c21b7b0db4b13fefd3d383db5f214e43 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -39,7 +39,7 @@ use Debian::Dgit;
 
 our $our_version = 'UNRELEASED'; ###substituted###
 
-our @rpushprotovsn_support = qw(3 2);
+our @rpushprotovsn_support = qw(3 2); # 4 is new tag format
 our $protovsn;
 
 our $isuite = 'unstable';
@@ -65,6 +65,8 @@ our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|unapplied';
 our $we_are_responder;
 our $initiator_tempdir;
 our $patches_applied_dirtily = 00;
+our $tagformat;
+our $tagformatfn;
 
 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
 
@@ -134,7 +136,7 @@ our $instead_distro;
 
 sub debiantag ($$) {
     my ($v,$distro) = @_;
-    return debiantag_old $v, $distro;
+    return $tagformatfn->($v, $distro);
 }
 
 sub lbranch () { return "$branchprefix/$csuite"; }
@@ -501,10 +503,12 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               'dgit.default.ssh' => 'ssh',
               'dgit.default.archive-query' => 'madison:',
               'dgit.default.sshpsql-dbname' => 'service=projectb',
+              'dgit.default.dgit-tag-format' => 'old,new',
               'dgit-distro.debian.archive-query' => 'ftpmasterapi:',
               'dgit-distro.debian.git-check' => 'url',
               'dgit-distro.debian.git-check-suffix' => '/info/refs',
               'dgit-distro.debian.new-private-pushers' => 't',
+              'dgit-distro.debian.dgit-tag-format' => 'old',
               'dgit-distro.debian/push.git-url' => '',
               'dgit-distro.debian/push.git-host' => 'push.dgit.debian.org',
               'dgit-distro.debian/push.git-user-force' => 'dgit',
@@ -1235,6 +1239,32 @@ sub create_remote_git_repo () {
     }
 }
 
+sub select_tagformat () {
+    # sets $tagformatfn
+    return if $tagformatfn && !$tagformat;
+    die 'bug' if $tagformatfn && $tagformat;
+    # ... $tagformat assigned after previous select_tagformat
+
+    my (@supported) = split /\,/, access_cfg('dgit-tag-format');
+    printdebug "select_tagformat supported @supported\n";
+
+    $tagformat //= [ $supported[0], "distro access configuration", 0 ];
+    printdebug "select_tagformat specified @$tagformat\n";
+
+    my ($fmt,$why,$override) = @$tagformat;
+
+    fail "target distro supports tag formats @supported".
+       " but have to use $fmt ($why)"
+       unless $override
+           or grep { $_ eq $fmt } @supported;
+
+    $tagformat = undef;
+    $tagformatfn = ${*::}{"debiantag_$fmt"};
+
+    fail "trying to use unknown tag format \`$fmt' ($why) !"
+       unless $tagformatfn;
+}
+
 our ($dsc_hash,$lastpush_hash);
 
 our $ud = '.git/dgit/unpack';
@@ -1993,6 +2023,7 @@ END
     prep_ud();
 
     access_giturl(); # check that success is vaguely likely
+    select_tagformat();
 
     my $clogpfn = ".git/dgit/changelog.822.tmp";
     runcmd shell_cmd "exec >$clogpfn", qw(dpkg-parsechangelog);
@@ -2338,7 +2369,7 @@ sub cmd_remote_push_build_host {
        unless defined $protovsn;
 
     responder_send_command("dgit-remote-push-ready $protovsn");
-
+    rpush_handle_protovsn_bothends();
     changedir $dir;
     &cmd_push;
 }
@@ -2347,6 +2378,17 @@ sub cmd_remote_push_responder { cmd_remote_push_build_host(); }
 # ... for compatibility with proto vsn.1 dgit (just so that user gets
 #     a good error message)
 
+sub rpush_handle_protovsn_bothends () {
+    if ($protovsn < 4) {
+       fail "rpush negotiated protocol version $protovsn".
+           " which supports old tag format only".
+           " but trying to use new format (".$tagformat->[1].")"
+           if $tagformat && $tagformat->[0] ne 'old';
+       $tagformat = ['old', "rpush negotiated protocol $protovsn", 0];
+    }
+    select_tagformat();
+}
+
 our $i_tmp;
 
 sub i_cleanup {
@@ -2405,6 +2447,7 @@ sub cmd_rpush {
     ($protovsn) = initiator_expect { m/^dgit-remote-push-ready (\S+)/ };
     die "$protovsn ?" unless grep { $_ eq $protovsn } @rpushprotovsn_support;
     $supplementary_message = '' unless $protovsn >= 3;
+    rpush_handle_protovsn_bothends();
     for (;;) {
        my ($icmd,$iargs) = initiator_expect {
            m/^(\S+)(?: (.*))?$/;
@@ -3797,6 +3840,11 @@ sub parseopts () {
            } elsif (m/^--deliberately-($deliberately_re)$/s) {
                push @ropts, $_;
                push @deliberatelies, $&;
+           } elsif (m/^--dgit-tag-format=(old|new)$/s) {
+               # undocumented, for testing
+               push @ropts, $_;
+               $tagformat = [ $1, 'command line', 1 ];
+               # 1 menas overrides distro configuration
            } elsif (m/^--always-split-source-build$/s) {
                # undocumented, for testing
                push @ropts, $_;
diff --git a/dgit.1 b/dgit.1
index 87367c259869aa0a6190c504b354b5eade0647e6..87ad0fce4b8f589f38ec85d378567d632cf9ffca 100644 (file)
--- a/dgit.1
+++ b/dgit.1
@@ -746,6 +746,8 @@ or when pushing and
 .TP
 .BI dgit-distro. distro .archive-query-default-component
 .TP
+.BI dgit-distro. distro .dgit-tag-format
+.TP
 .BI dgit-distro. distro .ssh
 .TP
 .BI dgit-distro. distro .sshpsql-dbname