use Dpkg::Version;
use POSIX;
-our $dgit_version = 'UNRELEASED'; ###substituted###
+our $our_version = 'UNRELEASED'; ###substituted###
our $isuite = 'unstable';
our $idistro;
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);
our %opts_opt_map = ('dget' => \@dget,
'dput' => \@dput,
'debsign' => \@debsign,
+ 'gpg' => \@gpg,
'sbuild' => \@sbuild,
'dpkg-source' => \@dpkgsource,
'dpkg-buildpackage' => \@dpkgbuildpackage,
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 @_;
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)";
}
}
}
}
+sub shell_cmd {
+ my ($first_shell, @cmd) = @_;
+ return qw(sh -ec), $first_shell.'; exec "$@"', 'x', @cmd;
+}
+
our $helpmsg = <<END;
main usages:
dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
sub parsechangelog {
my $c = Dpkg::Control::Hash->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;
$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";
}
}
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 () {
}
}
-our ($dsc_hash,$upload_hash);
+our ($dsc_hash,$lastpush_hash);
our $ud = '.git/dgit/unpack';
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 $!;
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 $!;
close C or die $!;
my $outputhash = make_commit qw(../commit.tmp);
my $cversion = getfield $clogp, 'Version';
- print "synthesised git commit from .dsc $cversion\n";
- if ($upload_hash) {
- runcmd @git, qw(reset --hard), $upload_hash;
+ progress "synthesised git commit from .dsc $cversion";
+ if ($lastpush_hash) {
+ runcmd @git, qw(reset --hard), $lastpush_hash;
runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
my $oversion = getfield $oldclogp, 'Version';
open C, ">../commit2.tmp" or die $!;
print C <<END or die $!;
tree $tree
-parent $upload_hash
+parent $lastpush_hash
parent $outputhash
author $authline
committer $authline
Last allegedly pushed/uploaded: $oversion (newer or same)
$later_warning_msg
END
- $outputhash = $upload_hash;
+ $outputhash = $lastpush_hash;
} else {
- $outputhash = $upload_hash;
+ $outputhash = $lastpush_hash;
}
}
chdir '../../../..' or die $!;
fail "existing file $f has hash $got but .dsc".
" demands hash $fi->{Hash}".
" (perhaps you should delete this file?)";
- print "using existing $f\n";
+ progress "using existing $f";
next;
} else {
die "$f $!" unless $!==&ENOENT;
$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;
}
}
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 = <H>;
- chomp $upload_hash;
- die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/;
+ $lastpush_hash = <H>;
+ 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 <<END or die $!;
Git commit in archive is behind the last version allegedly pushed/uploaded.
Commit referred to by archive: $dsc_hash
-Last allegedly pushed/uploaded: $upload_hash
+Last allegedly pushed/uploaded: $lastpush_hash
$later_warning_msg
END
- $hash = $upload_hash;
+ $hash = $lastpush_hash;
} else {
fail "archive's .dsc refers to ".$dsc_hash.
- " but this is an ancestor of ".$upload_hash;
+ " but this is an ancestor of ".$lastpush_hash;
}
- } else {
+ } elsif ($dsc) {
$hash = generate_commit_from_dsc();
+ } elsif ($lastpush_hash) {
+ # only in git, not in the archive yet
+ $hash = $lastpush_hash;
+ print STDERR <<END or die $!;
+
+Package not found in the archive, but has allegedly been pushed using dgit.
+$later_warning_msg
+END
+ } else {
+ print DEBUG "nothing found!\n";
+ if (defined $skew_warning_vsn) {
+ print STDERR <<END or die $!;
+
+Warning: relevant archive skew detected.
+Archive allegedly contains $skew_warning_vsn
+But we were not able to obtain any version from the archive or git.
+
+END
+ }
+ return 0;
}
print DEBUG "current hash=$hash\n";
- if ($upload_hash) {
+ if ($lastpush_hash) {
fail "not fast forward on last upload branch!".
" (archive's version left in DGIT_ARCHIVE)"
- unless is_fast_fwd($upload_hash, $hash);
+ unless is_fast_fwd($lastpush_hash, $hash);
+ }
+ if (defined $skew_warning_vsn) {
+ mkpath '.git/dgit';
+ print DEBUG "SKEW CHECK WANT $skew_warning_vsn\n";
+ my $clogf = ".git/dgit/changelog.tmp";
+ runcmd shell_cmd "exec >$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 <<END or die $!;
+
+Warning: archive skew detected. Using the available version:
+Archive allegedly contains $skew_warning_vsn
+We were able to obtain only $got_vsn
+
+END
+ }
}
- if ($upload_hash ne $hash) {
+ if ($lastpush_hash ne $hash) {
my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
if (!$dryrun) {
cmdoutput @upd_cmd;
close H or die $!;
runcmd @git, qw(remote add), 'origin', access_giturl();
if (check_for_git()) {
- print "fetching existing git history\n";
+ progress "fetching existing git history";
git_fetch_us();
runcmd_ordryrun @git, qw(fetch origin);
} else {
- print "starting new git history\n";
+ progress "starting new git history";
}
fetch_from_archive() or no_such_package;
runcmd @git, qw(reset --hard), lrref();
}
fail "unexpected output from git status (is tree clean?)" if $bad;
if (!%adds) {
- print "nothing quilty to commit, ok.\n";
+ progress "nothing quilty to commit, ok.";
return;
}
runcmd_ordryrun @git, qw(add), sort keys %adds;
my $m = "Commit Debian 3.0 (quilt) metadata";
- print "$m\n";
+ progress "$m";
runcmd_ordryrun @git, qw(commit -m), $m;
}
sub madformat ($) {
my ($format) = @_;
return 0 unless $format eq '3.0 (quilt)';
- print "Format \`$format', urgh\n";
+ progress "Format \`$format', urgh";
if ($noquilt) {
- print "Not doing any fixup of \`$format' due to --no-quilt-fixup";
+ progress "Not doing any fixup of \`$format' due to --no-quilt-fixup";
return 0;
}
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";
+ 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 $!;
# 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") {
($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();
}
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;
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 {
$isuite = getfield $clogp, 'Distribution';
}
canonicalise_suite();
- print "fetching from suite $csuite\n";
+ progress "fetching from suite $csuite";
} elsif (@ARGV==1) {
($isuite) = @ARGV;
canonicalise_suite();
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();
}
}
sub cmd_version {
- print "dgit version $dgit_version\n";
+ print "dgit version $our_version\n" or die $!;
+ exit 0;
}
sub parseopts () {
$sign=0;
} elsif (m/^--help$/) {
cmd_help();
+ } elsif (m/^--version$/) {
+ cmd_version();
} elsif (m/^--new$/) {
$new_package=1;
} elsif (m/^--(\w+)=(.*)/s &&