chiark / gitweb /
Tag change: Double check agreement in rpush protocol
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 352e5b16c21b7b0db4b13fefd3d383db5f214e43..a2771c5c81843bff4c01612b98c0afe4a54eff86 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -65,6 +65,7 @@ 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_want;
 our $tagformat;
 our $tagformatfn;
 
@@ -245,6 +246,7 @@ sub quiltmode_splitbrain () {
 #
 #  > param head HEAD
 #  > param csuite SUITE
+#  > param tagformat old|new
 #
 #  > previously REFNAME=OBJNAME       # if --deliberately-not-fast-forward
 #                                     # goes into tag, for replay prevention
@@ -1241,24 +1243,25 @@ 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
+    return if $tagformatfn && !$tagformat_want;
+    die 'bug' if $tagformatfn && $tagformat_want;
+    # ... $tagformat_want 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";
+    $tagformat_want //= [ $supported[0], "distro access configuration", 0 ];
+    printdebug "select_tagformat specified @$tagformat_want\n";
 
-    my ($fmt,$why,$override) = @$tagformat;
+    my ($fmt,$why,$override) = @$tagformat_want;
 
     fail "target distro supports tag formats @supported".
        " but have to use $fmt ($why)"
        unless $override
            or grep { $_ eq $fmt } @supported;
 
-    $tagformat = undef;
+    $tagformat_want = undef;
+    $tagformat = $fmt;
     $tagformatfn = ${*::}{"debiantag_$fmt"};
 
     fail "trying to use unknown tag format \`$fmt' ($why) !"
@@ -2107,6 +2110,7 @@ END
     responder_send_file('changes',$changesfile);
     responder_send_command("param head $head");
     responder_send_command("param csuite $csuite");
+    responder_send_command("param tagformat $tagformat");
 
     if (deliberately_not_fast_forward) {
        git_for_each_ref(lrfetchrefs, sub {
@@ -2382,9 +2386,9 @@ 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];
+           " but trying to use new format (".$tagformat_want->[1].")"
+           if $tagformat_want && $tagformat_want->[0] ne 'old';
+       $tagformat_want = ['old', "rpush negotiated protocol $protovsn", 0];
     }
     select_tagformat();
 }
@@ -2552,6 +2556,13 @@ sub i_want_signed_tag {
     my $head = $i_param{'head'};
     die if $head =~ m/[^0-9a-f]/ || $head !~ m/^../;
 
+    select_tagformat();
+    if ($protovsn >= 4) {
+       my $p = $i_param{'tagformat'} // '<undef>';
+       $p eq $tagformat
+           or badproto \*RO, "tag format mismatch: $p vs. $tagformat";
+    }
+
     die unless $i_param{'csuite'} =~ m/^$suite_re$/;
     $csuite = $&;
     push_parse_dsc $i_dscfn, 'remote dsc', $i_version;
@@ -2880,7 +2891,8 @@ sub quiltify ($$$$) {
            die "$quilt_mode ?";
        }
 
-       my $time = time;
+       my $time = $ENV{'GIT_COMMITTER_DATE'} || time;
+       $time =~ s/\s.*//; # trim timezone from GIT_COMMITTER_DATE
        my $ncommits = 3;
        my $msg = cmdoutput @git, qw(log), "-n$ncommits";
 
@@ -3843,7 +3855,7 @@ sub parseopts () {
            } elsif (m/^--dgit-tag-format=(old|new)$/s) {
                # undocumented, for testing
                push @ropts, $_;
-               $tagformat = [ $1, 'command line', 1 ];
+               $tagformat_want = [ $1, 'command line', 1 ];
                # 1 menas overrides distro configuration
            } elsif (m/^--always-split-source-build$/s) {
                # undocumented, for testing