X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=3c13d79f66182a9579b6f56268161f6c9d9e3716;hp=37e83641324dbcdb30d9ecc4b0f4c7b7c0fb9964;hb=c36579b521a6e6da1992e0bad826cd83560308d1;hpb=b1704c2f1daaabb296b2fa562692f1d2c1c3c510 diff --git a/dgit b/dgit index 37e83641..3c13d79f 100755 --- a/dgit +++ b/dgit @@ -71,6 +71,8 @@ our $keyid; our $debug = 0; open DEBUG, ">/dev/null" or die $!; +autoflush STDOUT 1; + our $remotename = 'dgit'; our @ourdscfield = qw(Dgit Vcs-Dgit-Master); our $branchprefix = 'dgit'; @@ -131,7 +133,7 @@ sub url_get { return $r->decoded_content(); } -our ($dscdata,$dscurl,$dsc); +our ($dscdata,$dscurl,$dsc,$skew_warning_vsn); sub printcmd { my $fh = shift @_; @@ -209,6 +211,19 @@ sub runcmd_ordryrun { } } +sub runcmd_ordryrun_local { + if ($dryrun <= 1) { + runcmd @_; + } else { + dryrun_report @_; + } +} + +sub shell_cmd { + my ($first_shell, @cmd) = @_; + return qw(sh -ec), $first_shell.'; exec "$@"', 'x', @cmd; +} + our $helpmsg = < sign tag and package with instead of default --dry-run -n do not change anything, but go through the motions + --damp-run -L like --dry-run but make local changes, without signing --new -N allow introducing a new package --debug -D increase debug level -c= set git config option (used directly by dgit too) @@ -335,7 +351,7 @@ sub getfield ($$) { 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; @@ -445,16 +461,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 () { @@ -485,7 +504,7 @@ sub create_remote_git_repo () { } } -our ($dsc_hash,$upload_hash); +our ($dsc_hash,$lastpush_hash); our $ud = '.git/dgit/unpack'; @@ -596,8 +615,8 @@ END 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; + 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'; @@ -608,7 +627,7 @@ END open C, ">../commit2.tmp" or die $!; print C <{$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 = $&; + print "last upload to archive specified git hash\n"; + } else { + print "last upload to archive has NO git hash\n"; + } } else { - print "last upload to archive has NO git hash\n"; + print "no version available from the archive\n"; } 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 < 1; mkdir $dstdir or die "$dstdir $!"; chdir "$dstdir" or die "$dstdir $!"; runcmd @git, qw(init -q); @@ -769,7 +831,7 @@ sub clone ($) { if (check_for_git()) { print "fetching existing git history\n"; git_fetch_us(); - runcmd_ordryrun @git, qw(fetch origin); + runcmd_ordryrun_local @git, qw(fetch origin); } else { print "starting new git history\n"; } @@ -788,7 +850,7 @@ sub fetch () { sub pull () { fetch(); - runcmd_ordryrun @git, qw(merge -m),"Merge from $csuite [dgit]", + runcmd_ordryrun_local @git, qw(merge -m),"Merge from $csuite [dgit]", lrref(); printdone "fetched to ".lrref()." and merged into HEAD"; } @@ -824,10 +886,10 @@ sub commit_quilty_patch () { print "nothing quilty to commit, ok.\n"; return; } - runcmd_ordryrun @git, qw(add), sort keys %adds; + runcmd_ordryrun_local @git, qw(add), sort keys %adds; my $m = "Commit Debian 3.0 (quilt) metadata"; print "$m\n"; - runcmd_ordryrun @git, qw(commit -m), $m; + runcmd_ordryrun_local @git, qw(commit -m), $m; } sub madformat ($) { @@ -923,11 +985,14 @@ sub dopush () { if (!defined $keyid) { $keyid = access_cfg('keyid','RETURN-UNDEF'); } - my @tag_cmd = (@git, qw(tag -s -m), + my @tag_cmd = (@git, qw(tag -m), "$package release $dversion for $csuite [dgit]"); - push @tag_cmd, qw(-u),$keyid if defined $keyid; + if ($dryrun != 1) { + push @tag_cmd, qw(-s); + push @tag_cmd, qw(-u),$keyid if defined $keyid; + } push @tag_cmd, $tag; - runcmd_ordryrun @tag_cmd; + runcmd_ordryrun_local @tag_cmd; my @debsign_cmd = @debsign; push @debsign_cmd, "-k$keyid" if defined $keyid; push @debsign_cmd, $changesfile; @@ -1077,7 +1142,7 @@ END local $ENV{'EDITOR'} = cmdoutput qw(realpath --), $0; local $ENV{'VISUAL'} = $ENV{'EDITOR'}; local $ENV{$fakeeditorenv} = cmdoutput qw(realpath --), $descfn; - runcmd_ordryrun @dpkgsource, qw(--commit .), $patchname; + runcmd_ordryrun_local @dpkgsource, qw(--commit .), $patchname; } if (!open P, '>>', ".pc/applied-patches") { @@ -1122,7 +1187,7 @@ sub cmd_build { badusage "dgit build implies --clean=dpkg-source" if $cleanmode ne 'dpkg-source'; build_prep(); - runcmd_ordryrun @dpkgbuildpackage, qw(-us -uc), changesopts(), @ARGV; + runcmd_ordryrun_local @dpkgbuildpackage, qw(-us -uc), changesopts(), @ARGV; printdone "build successful\n"; } @@ -1138,7 +1203,7 @@ sub cmd_git_build { push @cmd, "--git-debian-branch=".lbranch(); } push @cmd, changesopts(); - runcmd_ordryrun @cmd, @ARGV; + runcmd_ordryrun_local @cmd, @ARGV; printdone "build successful\n"; } @@ -1147,10 +1212,11 @@ sub build_source { $sourcechanges = "${package}_".(stripepoch $version)."_source.changes"; $dscfn = dscfn($version); if ($cleanmode eq 'dpkg-source') { - runcmd_ordryrun (@dpkgbuildpackage, qw(-us -uc -S)), changesopts(); + runcmd_ordryrun_local (@dpkgbuildpackage, qw(-us -uc -S)), + changesopts(); } else { if ($cleanmode eq 'git') { - runcmd_ordryrun @git, qw(clean -xdf); + runcmd_ordryrun_local @git, qw(clean -xdf); } elsif ($cleanmode eq 'none') { } else { die "$cleanmode ?"; @@ -1158,9 +1224,9 @@ sub build_source { my $pwd = cmdoutput qw(env - pwd); my $leafdir = basename $pwd; chdir ".." or die $!; - runcmd_ordryrun @dpkgsource, qw(-b --), $leafdir; + runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir; chdir $pwd or die $!; - runcmd_ordryrun qw(sh -ec), + runcmd_ordryrun_local qw(sh -ec), 'exec >$1; shift; exec "$@"','x', "../$sourcechanges", @dpkggenchanges, qw(-S), changesopts(); @@ -1177,7 +1243,7 @@ sub cmd_sbuild { build_source(); chdir ".." or die $!; my $pat = "${package}_".(stripepoch $version)."_*.changes"; - if (!$dryrun) { + if ($dryrun <= 1) { stat $dscfn or fail "$dscfn (in parent directory): $!"; stat $sourcechanges or fail "$sourcechanges (in parent directory): $!"; foreach my $cf (glob $pat) { @@ -1188,7 +1254,7 @@ sub cmd_sbuild { runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn; runcmd_ordryrun @mergechanges, glob $pat; my $multichanges = "${package}_".(stripepoch $version)."_multi.changes"; - if (!$dryrun) { + if ($dryrun <= 1) { stat $multichanges or fail "$multichanges: $!"; } printdone "build successful, results in $multichanges\n" or die $!; @@ -1203,6 +1269,7 @@ sub cmd_quilt_fixup { sub cmd_version { print "dgit version $our_version\n" or die $!; + exit 0; } sub parseopts () { @@ -1213,11 +1280,15 @@ sub parseopts () { last if m/^--?$/; if (m/^--/) { if (m/^--dry-run$/) { + $dryrun=2; + } elsif (m/^--damp-run$/) { $dryrun=1; } elsif (m/^--no-sign$/) { $sign=0; } elsif (m/^--help$/) { cmd_help(); + } elsif (m/^--version$/) { + cmd_version(); } elsif (m/^--new$/) { $new_package=1; } elsif (m/^--(\w+)=(.*)/s && @@ -1245,6 +1316,8 @@ sub parseopts () { } else { while (m/^-./s) { if (s/^-n/-/) { + $dryrun=2; + } elsif (s/^-L/-/) { $dryrun=1; } elsif (s/^-h/-/) { cmd_help(); @@ -1285,7 +1358,8 @@ if ($ENV{$fakeeditorenv}) { delete $ENV{'DGET_UNPACK'}; parseopts(); -print STDERR "DRY RUN ONLY\n" if $dryrun; +print STDERR "DRY RUN ONLY\n" if $dryrun > 1; +print STDERR "DAMP RUN - WILL MAKE LOCAL (UNSIGNED) CHANGES\n" if $dryrun == 1; if (!@ARGV) { print STDERR $helpmsg or die $!; exit 8;