chiark / gitweb /
push actually takes an optional suite, like it says in the synopsis.
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 0bf0585bd78c379c973276acb1681b5fcc37f114..b4c931687e43f40474792227d7c9cac94130993b 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -49,6 +49,7 @@ our (@git) = qw(git);
 our (@dget) = qw(dget);
 our (@dput) = qw(dput);
 our (@debsign) = qw(debsign);
+our (@gpg) = qw(gpg);
 our (@sbuild) = qw(sbuild -A);
 our (@dpkgbuildpackage) = qw(dpkg-buildpackage -i\.git/ -I.git);
 our (@dpkgsource) = qw(dpkg-source -i\.git/ -I.git);
@@ -59,6 +60,7 @@ our (@changesopts) = ('');
 our %opts_opt_map = ('dget' => \@dget,
                     'dput' => \@dput,
                     'debsign' => \@debsign,
+                     'gpg' => \@gpg,
                      'sbuild' => \@sbuild,
                      'dpkg-source' => \@dpkgsource,
                      'dpkg-buildpackage' => \@dpkgbuildpackage,
@@ -562,6 +564,18 @@ sub make_commit ($) {
     return cmdoutput @git, qw(hash-object -w -t commit), $file;
 }
 
+sub clogp_authline ($) {
+    my ($clogp) = @_;
+    my $author = getfield $clogp, 'Maintainer';
+    $author =~ s#,.*##ms;
+    my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
+    my $authline = "$author $date";
+    $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
+       fail "unexpected commit author line format \`$authline'".
+       " (was generated from changelog Maintainer field)";
+    return $authline;
+}
+
 sub generate_commit_from_dsc () {
     prep_ud();
     chdir $ud or die $!;
@@ -582,13 +596,7 @@ sub generate_commit_from_dsc () {
     my ($tree,$dir) = mktree_in_ud_from_only_subdir();
     runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
     my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
-    my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
-    my $author = getfield $clogp, 'Maintainer';
-    $author =~ s#,.*##ms;
-    my $authline = "$author $date";
-    $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
-       fail "unexpected commit author line format \`$authline'".
-           " (was generated from changelog Maintainer field)";
+    my $authline = clogp_authline $clogp;
     my $changes = getfield $clogp, 'Changes';
     open C, ">../commit.tmp" or die $!;
     print C <<END or die $!;
@@ -892,28 +900,106 @@ sub madformat ($) {
     return 1;
 }
 
-sub dopush () {
-    print DEBUG "actually entering push\n";
-    my $clogp = parsechangelog();
+sub push_parse_changelog ($) {
+    my ($clogpfn) = @_;
+
+    my $clogp = Dpkg::Control::Hash->new();
+    $clogp->load($clogpfn);
+
+    responder_send_file('parsed-changelog', $clogpfn);
+
     $package = getfield $clogp, 'Source';
     my $cversion = getfield $clogp, 'Version';
+    my $tag = debiantag($cversion);
+    runcmd @git, qw(check-ref-format), $tag;
+
     my $dscfn = dscfn($cversion);
-    stat "../$dscfn" or
-       fail "looked for .dsc $dscfn, but $!;".
-           " maybe you forgot to build";
-    $dsc = parsecontrol("../$dscfn","$dscfn");
-    my $dscpackage = getfield $dsc, 'Source';
-    my $format = getfield $dsc, 'Format';
+
+    return ($clogp, $cversion, $tag, $dscfn);
+}
+
+sub push_parse_dsc ($$) {
+    my ($dscfn,$dscfnwhat, $cversion) = @_;
+    $dsc = parsecontrol($dscfn,$dscfnwhat);
     my $dversion = getfield $dsc, 'Version';
+    my $dscpackage = getfield $dsc, 'Source';
     ($dscpackage eq $package && $dversion eq $cversion) or
        fail "$dsc is for $dscpackage $dversion".
            " but debian/changelog is for $package $cversion";
+}
+
+sub push_mktag ($$$$$$$$) {
+    my ($head,$clogp,$tag,
+       $dsc,$dscfn,
+       $changesfile,$changesfilewhat,
+       $tfn) = @_;
+
+    $dsc->{$ourdscfield[0]} = $head;
+    $dsc->save("$dscfn.tmp") or die $!;
+
+    my $changes = parsecontrol($changesfile,$changesfilewhat);
+    foreach my $field (qw(Source Distribution Version)) {
+       $changes->{$field} eq $clogp->{$field} or
+           fail "changes field $field \`$changes->{$field}'".
+               " does not match changelog \`$clogp->{$field}'";
+    }
+
+    # We make the git tag by hand because (a) that makes it easier
+    # to control the "tagger" (b) we can do remote signing
+    my $authline = clogp_authline $clogp;
+    open TO, '>', $tfn->('.tmp') or die $!;
+    print TO <<END or die $!;
+object $head
+type commit
+tag $tag
+tagger $authline
+
+$package release $cversion for $csuite [dgit]
+END
+    close TO or die $!;
+
+    my $tagobjfn = $tfn->('.tmp');
+    if ($sign) {
+       if (!defined $keyid) {
+           $keyid = access_cfg('keyid','RETURN-UNDEF');
+       }
+       unlink $tfn->('.tmp.asc') or $!==&ENOENT or die $!;
+       my @sign_cmd = (@gpg, qw(--detach-sign --armor));
+       push @sign_cmd, qw(-u),$keyid if defined $keyid;
+       push @sign_cmd, $tfn->('.tmp');
+       runcmd_ordryrun @sign_cmd;
+       if (!$dryrun) {
+           $tagobjfn = $tfn->('.signed.tmp');
+           runcmd shell_cmd "exec >$tagobjfn", qw(cat --),
+               $tfn->('.tmp'), $tfn->('.tmp.asc');
+       }
+    }
+
+    return ($tagobjfn);
+}
+
+sub dopush () {
+    print DEBUG "actually entering push\n";
+    prep_ud();
+
+    runcmd shell_cmd "exec >.git/dgit/changelog.822.tmp",
+        qw(dpkg-parsechangelog);
+
+    my ($clogp, $cversion, $tag, $dscfn) =
+       push_parse_changelog(".git/dgit/changelog.822.tmp");
+
+    stat "../$dscfn" or
+       fail "looked for .dsc $dscfn, but $!;".
+           " maybe you forgot to build";
+
+    push_parse_dsc("../$dscfn", $dscfn, $cversion);
+
+    my $format = getfield $dsc, 'Format';
     print DEBUG "format $format\n";
     if (madformat($format)) {
        commit_quilty_patch();
     }
     check_not_dirty();
-    prep_ud();
     chdir $ud or die $!;
     print "checking that $dscfn corresponds to HEAD\n";
     runcmd qw(dpkg-source -x --), "../../../../$dscfn";
@@ -937,8 +1023,6 @@ sub dopush () {
 #        map { lref($_).":".rref($_) }
 #        (uploadbranch());
     my $head = rev_parse('HEAD');
-    $dsc->{$ourdscfield[0]} = $head;
-    $dsc->save("../$dscfn.tmp") or die $!;
     if (!$changesfile) {
        my $multi = "../${package}_".(stripepoch $cversion)."_multi.changes";
        if (stat "$multi") {
@@ -954,14 +1038,18 @@ sub dopush () {
            ($changesfile) = @cs;
        }
     }
-    my $changes = parsecontrol($changesfile,$changesfile);
-    foreach my $field (qw(Source Distribution Version)) {
-       $changes->{$field} eq $clogp->{$field} or
-           fail "changes field $field \`$changes->{$field}'".
-               " does not match changelog \`$clogp->{$field}'";
-    }
-    my $tag = debiantag($dversion);
-    runcmd @git, qw(check-ref-format), $tag;
+
+    my ($tagobjfn) =
+       push_mktag($head,$clogp,$tag,
+                  $dsc,"../$dscfn",
+                  $changesfile,$changesfile,
+                  sub { ".git/dgit/tag$_[0]"; });
+
+    my $tag_obj_hash = cmdoutput @git, qw(hash-object -w -t tag), $tagobjfn;
+    runcmd_ordryrun @git, qw(verify-tag), $tag_obj_hash;
+    runcmd_ordryrun @git, qw(update-ref), "refs/tags/$tag", $tag_obj_hash;
+    runcmd_ordryrun @git, qw(tag -v --), $tag;
+
     if (!check_for_git()) {
        create_remote_git_repo();
     }
@@ -972,19 +1060,8 @@ sub dopush () {
     } else {
        print "[new .dsc left in $dscfn.tmp]\n";
     }
-    if ($sign) {
-       if (!defined $keyid) {
-           $keyid = access_cfg('keyid','RETURN-UNDEF');
-       }
-       my @tag_cmd = (@git, qw(tag -a -m),
-                      "$package release $dversion for $csuite [dgit]");
-       push @tag_cmd, $tag;
-       runcmd_ordryrun @tag_cmd;
-       
-
-       push @tag_cmd, qw(-u),$keyid if defined $keyid;
-       push @tag_cmd, qw(-u),$keyid if defined $keyid;
 
+    if ($sign) {
        my @debsign_cmd = @debsign;
        push @debsign_cmd, "-k$keyid" if defined $keyid;
        push @debsign_cmd, $changesfile;
@@ -994,7 +1071,7 @@ sub dopush () {
     my $host = access_cfg('upload-host','RETURN-UNDEF');
     my @hostarg = defined($host) ? ($host,) : ();
     runcmd_ordryrun @dput, @hostarg, $changesfile;
-    printdone "pushed and uploaded $dversion";
+    printdone "pushed and uploaded $cversion";
 }
 
 sub cmd_clone {
@@ -1065,15 +1142,24 @@ sub cmd_push {
     check_not_dirty();
     my $clogp = parsechangelog();
     $package = getfield $clogp, 'Source';
+    my $specsuite;
     if (@ARGV==0) {
-       $isuite = getfield $clogp, 'Distribution';
-       if ($new_package) {
-           local ($package) = $existing_package; # this is a hack
-           canonicalise_suite();
-       }
+    } elsif (@ARGV==1) {
+       ($specsuite) = (@ARGV);
     } else {
        badusage "incorrect arguments to dgit push";
     }
+    $isuite = getfield $clogp, 'Distribution';
+    if ($new_package) {
+       local ($package) = $existing_package; # this is a hack
+       canonicalise_suite();
+    }
+    if (defined $specsuite && $specsuite ne $isuite) {
+       canonicalise_suite();
+       $csuite eq $specsuite or
+           fail "dgit push: changelog specifies $isuite ($csuite)".
+               " but command line specifies $specsuite";
+    }
     if (check_for_git()) {
        git_fetch_us();
     }