X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=357ccc3ac96e0faaa1be3502f364cf03b7d81bd5;hp=46099d2ed664a610a35c8ae83d3a604ad8982c80;hb=f8607d8ff99642d610d2bc338eb831aae4baba2b;hpb=a72a7496720612dfaa7c4a12a00f8e484fe53004 diff --git a/dgit b/dgit index 46099d2e..357ccc3a 100755 --- a/dgit +++ b/dgit @@ -28,6 +28,8 @@ use File::Basename; use Dpkg::Version; use POSIX; +our $our_version = 'UNRELEASED'; ###substituted### + our $isuite = 'unstable'; our $idistro; our $package; @@ -47,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); @@ -57,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, @@ -116,20 +120,24 @@ sub fetchspec () { our $ua; +sub progress { + print @_, "\n"; +} + sub url_get { if (!$ua) { $ua = LWP::UserAgent->new(); $ua->env_proxy; } my $what = $_[$#_]; - print "downloading $what...\n"; + progress "downloading $what..."; my $r = $ua->get(@_) or die $!; return undef if $r->code == 404; $r->is_success or fail "failed to fetch $what: ".$r->status_line; return $r->decoded_content(); } -our ($dscdata,$dscurl,$dsc); +our ($dscdata,$dscurl,$dsc,$skew_warning_vsn); sub printcmd { my $fh = shift @_; @@ -168,9 +176,9 @@ sub runcmd { sub printdone { if (!$dryrun) { - print "dgit ok: @_\n"; + progress "dgit ok: @_"; } else { - print "would be ok: @_ (but dry run only)\n"; + progress "would be ok: @_ (but dry run only)"; } } @@ -207,6 +215,11 @@ sub runcmd_ordryrun { } } +sub shell_cmd { + my ($first_shell, @cmd) = @_; + return qw(sh -ec), $first_shell.'; exec "$@"', 'x', @cmd; +} + our $helpmsg = <new(); my $p = new IO::Handle; - my @cmd = (qw(dpkg-parsechangelog)); + my @cmd = (qw(dpkg-parsechangelog), @_); open $p, '-|', @cmd or die $!; $c->parse($p); $?=0; $!=0; close $p or failedcmd @cmd; @@ -432,7 +445,7 @@ sub canonicalise_suite () { $csuite = archive_query('canonicalise_suite'); if ($isuite ne $csuite) { # madison canonicalises for us - print "canonical suite name for $isuite is $csuite\n"; + progress "canonical suite name for $isuite is $csuite"; } } @@ -443,16 +456,19 @@ sub get_archive_dsc () { my ($vsn,$subpath) = @$vinfo; $dscurl = access_cfg('mirror').$subpath; $dscdata = url_get($dscurl); - next unless defined $dscdata; + if (!$dscdata) { + $skew_warning_vsn = $vsn if !defined $skew_warning_vsn; + next; + } my $dscfh = new IO::File \$dscdata, '<' or die $!; print DEBUG Dumper($dscdata) if $debug>1; $dsc = parsecontrolfh($dscfh,$dscurl, allow_pgp=>1); print DEBUG Dumper($dsc) if $debug>1; my $fmt = getfield $dsc, 'Format'; fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt}; - return $dsc; + return; } - return undef; + $dsc = undef; } sub check_for_git () { @@ -483,7 +499,7 @@ sub create_remote_git_repo () { } } -our ($dsc_hash,$upload_hash); +our ($dsc_hash,$lastpush_hash); our $ud = '.git/dgit/unpack'; @@ -552,6 +568,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 $!; @@ -572,13 +600,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 <>../changelogold.tmp'; my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog'); my $oversion = getfield $oldclogp, 'Version'; @@ -606,7 +628,7 @@ END open C, ">../commit2.tmp" or die $!; print C <{Hash}". " (perhaps you should delete this file?)"; - print "using existing $f\n"; + progress "using existing $f"; next; } else { die "$f $!" unless $!==&ENOENT; @@ -658,8 +680,7 @@ sub ensure_we_have_orig () { $origurl .= "/$f"; die "$f ?" unless $f =~ m/^${package}_/; die "$f ?" if $f =~ m#/#; - runcmd_ordryrun qw(sh -ec),'cd ..; exec "$@"','x', - @dget,'--',$origurl; + runcmd_ordryrun shell_cmd 'cd ..', @dget,'--',$origurl; } } @@ -686,62 +707,106 @@ sub git_fetch_us () { sub fetch_from_archive () { # ensures that lrref() is what is actually in the archive, # one way or another - get_archive_dsc() or return 0; - foreach my $field (@ourdscfield) { - $dsc_hash = $dsc->{$field}; - last if defined $dsc_hash; - } - if (defined $dsc_hash) { - $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'"; - $dsc_hash = $&; - print "last upload to archive specified git hash\n"; + get_archive_dsc(); + + if ($dsc) { + foreach my $field (@ourdscfield) { + $dsc_hash = $dsc->{$field}; + last if defined $dsc_hash; + } + if (defined $dsc_hash) { + $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'"; + $dsc_hash = $&; + progress "last upload to archive specified git hash"; + } else { + progress "last upload to archive has NO git hash"; + } } else { - print "last upload to archive has NO git hash\n"; + progress "no version available from the archive"; } my $lrref_fn = ".git/".lrref(); if (open H, $lrref_fn) { - $upload_hash = ; - chomp $upload_hash; - die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/; + $lastpush_hash = ; + chomp $lastpush_hash; + die "$lrref_fn $lastpush_hash ?" unless $lastpush_hash =~ m/^\w+$/; } elsif ($! == &ENOENT) { - $upload_hash = ''; + $lastpush_hash = ''; } else { die "$lrref_fn $!"; } - print DEBUG "previous reference hash=$upload_hash\n"; + print DEBUG "previous reference hash=$lastpush_hash\n"; my $hash; if (defined $dsc_hash) { fail "missing git history even though dsc has hash -". " could not find commit $dsc_hash". " (should be in ".access_giturl()."#".rrref().")" - unless $upload_hash; + unless $lastpush_hash; $hash = $dsc_hash; ensure_we_have_orig(); - if ($dsc_hash eq $upload_hash) { - } elsif (is_fast_fwd($dsc_hash,$upload_hash)) { + if ($dsc_hash eq $lastpush_hash) { + } elsif (is_fast_fwd($dsc_hash,$lastpush_hash)) { print STDERR <$clogf", + @git, qw(cat-file blob), "$hash:debian/changelog"; + my $gotclogp = parsechangelog("-l$clogf"); + my $got_vsn = getfield $gotclogp, 'Version'; + print DEBUG "SKEW CHECK GOT $got_vsn\n"; + if (version_compare_string($got_vsn, $skew_warning_vsn) < 0) { + print STDERR <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 <('.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"; + progress "checking that $dscfn corresponds to HEAD"; runcmd qw(dpkg-source -x --), "../../../../$dscfn"; my ($tree,$dir) = mktree_in_ud_from_only_subdir(); chdir '../../../..' or die $!; @@ -883,8 +1026,7 @@ sub dopush () { # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git", # map { lref($_).":".rref($_) } # (uploadbranch()); - $dsc->{$ourdscfield[0]} = rev_parse('HEAD'); - $dsc->save("../$dscfn.tmp") or die $!; + my $head = rev_parse('HEAD'); if (!$changesfile) { my $multi = "../${package}_".(stripepoch $cversion)."_multi.changes"; if (stat "$multi") { @@ -900,13 +1042,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); + + 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(); } @@ -915,17 +1062,10 @@ sub dopush () { if (!$dryrun) { rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!"; } else { - print "[new .dsc left in $dscfn.tmp]\n"; + progress "[new .dsc left in $dscfn.tmp]"; } + if ($sign) { - if (!defined $keyid) { - $keyid = access_cfg('keyid','RETURN-UNDEF'); - } - my @tag_cmd = (@git, qw(tag -s -m), - "$package release $dversion for $csuite [dgit]"); - push @tag_cmd, qw(-u),$keyid if defined $keyid; - push @tag_cmd, $tag; - runcmd_ordryrun @tag_cmd; my @debsign_cmd = @debsign; push @debsign_cmd, "-k$keyid" if defined $keyid; push @debsign_cmd, $changesfile; @@ -935,7 +1075,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 { @@ -979,7 +1119,7 @@ sub fetchpullargs () { $isuite = getfield $clogp, 'Distribution'; } canonicalise_suite(); - print "fetching from suite $csuite\n"; + progress "fetching from suite $csuite"; } elsif (@ARGV==1) { ($isuite) = @ARGV; canonicalise_suite(); @@ -1006,15 +1146,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(); } @@ -1055,6 +1204,7 @@ sub build_maybe_quilt_fixup () { my $ncommits = 3; my $patchname = "auto-$version-$headref-$time"; my $msg = cmdoutput @git, qw(log), "-n$ncommits"; + mkpath '.git/dgit'; my $descfn = ".git/dgit/quilt-description.tmp"; open O, '>', $descfn or die "$descfn: $!"; $msg =~ s/\n/\n /g; @@ -1198,6 +1348,11 @@ sub cmd_quilt_fixup { build_maybe_quilt_fixup(); } +sub cmd_version { + print "dgit version $our_version\n" or die $!; + exit 0; +} + sub parseopts () { my $om; while (@ARGV) { @@ -1210,7 +1365,9 @@ sub parseopts () { } elsif (m/^--no-sign$/) { $sign=0; } elsif (m/^--help$/) { - helponly(); + cmd_help(); + } elsif (m/^--version$/) { + cmd_version(); } elsif (m/^--new$/) { $new_package=1; } elsif (m/^--(\w+)=(.*)/s && @@ -1240,7 +1397,7 @@ sub parseopts () { if (s/^-n/-/) { $dryrun=1; } elsif (s/^-h/-/) { - helponly(); + cmd_help(); } elsif (s/^-D/-/) { open DEBUG, ">&STDERR" or die $!; $debug++;