X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=123c2d513ae2cc05f3f3dd82a90c06a3b64202bd;hp=3cb47804fdd854f7cd42524b17c4d0d5175da270;hb=07cb0f6806a69f80bd3c70abb4beff83babe4cac;hpb=3759f1f708f46004df69810a4c7e07714bf00ecc diff --git a/dgit b/dgit index 3cb47804..123c2d51 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; @@ -36,6 +38,8 @@ our $sign = 1; our $dryrun = 0; our $changesfile; our $new_package = 0; +our $ignoredirty = 0; +our $noquilt = 0; our $existing_package = 'dpkg'; our $cleanmode = 'dpkg-source'; @@ -83,7 +87,16 @@ sub debiantag ($) { return "debian/$v"; } -sub dscfn ($) { return "${package}_$_[0].dsc"; } +sub stripepoch ($) { + my ($vsn) = @_; + $vsn =~ s/^\d+\://; + return $vsn; +} + +sub dscfn ($) { + my ($vsn) = @_; + return "${package}_".(stripepoch $vsn).".dsc"; +} sub changesopts () { return @changesopts[1..$#changesopts]; } @@ -196,6 +209,11 @@ sub runcmd_ordryrun { } } +sub shell_cmd { + my ($first_shell, @cmd) = @_; + return qw(sh -ec), $first_shell.'; exec "$@"', 'x', @cmd; +} + our $helpmsg = < 'debian', 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org', 'dgit-distro.debian.sshdakls-dir' => '/srv/ftp-master.debian.org/ftp/dists', + 'dgit-distro.debian.upload-host' => 'ftp-master', # for dput 'dgit-distro.debian.mirror' => 'http://ftp.debian.org/debian/'); sub cfg { @@ -321,7 +340,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; @@ -399,7 +418,7 @@ sub madison_parse ($) { } $5 eq 'source' or die "$rmad ?"; my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1); - my $subpath = "/pool/$component/$prefix/$package/${package}_$vsn.dsc"; + my $subpath = "/pool/$component/$prefix/$package/".dscfn($vsn); push @out, [$vsn,$subpath,$newsuite]; } return sort { -version_compare_string($a->[0],$b->[0]); } @out; @@ -432,17 +451,15 @@ sub get_archive_dsc () { $dscurl = access_cfg('mirror').$subpath; $dscdata = url_get($dscurl); next unless defined $dscdata; - $dscurl = access_cfg('mirror').$subpath; - $dscdata = url_get($dscurl); 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 () { @@ -473,7 +490,7 @@ sub create_remote_git_repo () { } } -our ($dsc_hash,$upload_hash); +our ($dsc_hash,$lastpush_hash); our $ud = '.git/dgit/unpack'; @@ -501,16 +518,35 @@ sub mktree_in_ud_from_only_subdir () { return ($tree,$dir); } -sub dsc_files () { - my $field = $dsc->{'Checksums-Sha256'} || $dsc->{Files}; - defined $field or - fail "missing both Checksums-Sha256 and Files in ". +sub dsc_files_info () { + foreach my $csumi (['Checksums-Sha256','Digest::SHA', 'new(256)'], + ['Checksums-Sha1', 'Digest::SHA', 'new(1)'], + ['Files', 'Digest::MD5', 'new()']) { + my ($fname, $module, $method) = @$csumi; + my $field = $dsc->{$fname}; + next unless defined $field; + eval "use $module; 1;" or die $@; + my @out; + foreach (split /\n/, $field) { + next unless m/\S/; + m/^(\w+) (\d+) (\S+)$/ or + fail "could not parse .dsc $fname line \`$_'"; + my $digester = eval "$module"."->$method;" or die $@; + push @out, { + Hash => $1, + Bytes => $2, + Filename => $3, + Digester => $digester, + }; + } + return @out; + } + fail "missing any supported Checksums-* or Files field in ". $dsc->get_option('name'); - map { - m/^\w+ \d+ (\S+)$/ or - fail "could not parse .dsc Files/Checksums line \`$_'"; - $1; - } grep m/\S/, split /\n/, $field; +} + +sub dsc_files () { + map { $_->{Filename} } dsc_files_info(); } sub is_orig_file ($) { @@ -565,8 +601,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'; @@ -577,7 +613,7 @@ END open C, ">../commit2.tmp" or die $!; print C <{Filename}; next unless is_orig_file($f); - if (stat "../$f") { - die "$f ?" unless -f _; + if (open F, "<", "../$f") { + $fi->{Digester}->reset(); + $fi->{Digester}->addfile(*F); + F->error and die $!; + my $got = $fi->{Digester}->hexdigest(); + $got eq $fi->{Hash} or + fail "existing file $f has hash $got but .dsc". + " demands hash $fi->{Hash}". + " (perhaps you should delete this file?)"; + print "using existing $f\n"; + next; } else { die "$f $!" unless $!==&ENOENT; } @@ -619,8 +665,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; } } @@ -630,74 +675,96 @@ sub rev_parse ($) { sub is_fast_fwd ($$) { my ($ancestor,$child) = @_; - my $mb = cmdoutput @git, qw(merge-base), $ancestor, $child; - return rev_parse($mb) eq rev_parse($ancestor); + my @cmd = (@git, qw(merge-base), $ancestor, $child); + my $mb = cmdoutput_errok @cmd; + if (defined $mb) { + return rev_parse($mb) eq rev_parse($ancestor); + } else { + $?==256 or failedcmd @cmd; + return 0; + } } sub git_fetch_us () { - badusage "cannot dry run with fetch" if $dryrun; - runcmd @git, qw(fetch),access_giturl(),fetchspec(); + runcmd_ordryrun @git, qw(fetch),access_giturl(),fetchspec(); } 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 = $&; + 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 <0; $!=0; $?=0; system @cmd; @@ -787,6 +855,10 @@ sub madformat ($) { my ($format) = @_; return 0 unless $format eq '3.0 (quilt)'; print "Format \`$format', urgh\n"; + if ($noquilt) { + print "Not doing any fixup of \`$format' due to --no-quilt-fixup"; + return 0; + } return 1; } @@ -837,12 +909,12 @@ sub dopush () { $dsc->{$ourdscfield[0]} = rev_parse('HEAD'); $dsc->save("../$dscfn.tmp") or die $!; if (!$changesfile) { - my $multi = "../${package}_${cversion}_multi.changes"; + my $multi = "../${package}_".(stripepoch $cversion)."_multi.changes"; if (stat "$multi") { $changesfile = $multi; } else { $!==&ENOENT or die "$multi: $!"; - my $pat = "${package}_${cversion}_*.changes"; + my $pat = "${package}_".(stripepoch $cversion)."_*.changes"; my @cs = glob "../$pat"; fail "failed to find unique changes file". " (looked for $pat in .., or $multi);". @@ -862,6 +934,7 @@ sub dopush () { create_remote_git_repo(); } runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref(); + runcmd_ordryrun @git, qw(update-ref -m), 'dgit push', lrref(), 'HEAD'; if (!$dryrun) { rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!"; } else { @@ -872,7 +945,7 @@ sub dopush () { $keyid = access_cfg('keyid','RETURN-UNDEF'); } my @tag_cmd = (@git, qw(tag -s -m), - "Release $dversion for $csuite [dgit]"); + "$package release $dversion for $csuite [dgit]"); push @tag_cmd, qw(-u),$keyid if defined $keyid; push @tag_cmd, $tag; runcmd_ordryrun @tag_cmd; @@ -969,7 +1042,10 @@ sub cmd_push { git_fetch_us(); } if (fetch_from_archive()) { - is_fast_fwd(lrref(), 'HEAD') or die; + is_fast_fwd(lrref(), 'HEAD') or + fail "dgit push: HEAD is not a descendant". + " of the archive's version.\n". + "$us: To overwrite it, use git-merge -s ours ".lrref()."."; } else { $new_package or fail "package appears to be new in this suite;". @@ -1002,6 +1078,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; @@ -1077,7 +1154,7 @@ sub cmd_git_build { my @cmd = (qw(git-buildpackage -us -uc --git-no-sign-tags), "--git-builder=@dpkgbuildpackage"); - unless (grep { m/^--git-debian-branch/ } @ARGV) { + unless (grep { m/^--git-debian-branch|^--git-ignore-branch/ } @ARGV) { canonicalise_suite(); push @cmd, "--git-debian-branch=".lbranch(); } @@ -1088,7 +1165,7 @@ sub cmd_git_build { sub build_source { build_prep(); - $sourcechanges = "${package}_${version}_source.changes"; + $sourcechanges = "${package}_".(stripepoch $version)."_source.changes"; $dscfn = dscfn($version); if ($cleanmode eq 'dpkg-source') { runcmd_ordryrun (@dpkgbuildpackage, qw(-us -uc -S)), changesopts(); @@ -1120,7 +1197,7 @@ sub cmd_build_source { sub cmd_sbuild { build_source(); chdir ".." or die $!; - my $pat = "${package}_${version}_*.changes"; + my $pat = "${package}_".(stripepoch $version)."_*.changes"; if (!$dryrun) { stat $dscfn or fail "$dscfn (in parent directory): $!"; stat $sourcechanges or fail "$sourcechanges (in parent directory): $!"; @@ -1131,7 +1208,7 @@ sub cmd_sbuild { } runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn; runcmd_ordryrun @mergechanges, glob $pat; - my $multichanges = "${package}_${version}_multi.changes"; + my $multichanges = "${package}_".(stripepoch $version)."_multi.changes"; if (!$dryrun) { stat $multichanges or fail "$multichanges: $!"; } @@ -1145,6 +1222,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) { @@ -1157,7 +1239,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 && @@ -1175,6 +1259,10 @@ sub parseopts () { $cleanmode = $1; } elsif (m/^--clean=(.*)$/s) { badusage "unknown cleaning mode \`$1'"; + } elsif (m/^--ignore-dirty$/s) { + $ignoredirty = 1; + } elsif (m/^--no-quilt-fixup$/s) { + $noquilt = 1; } else { badusage "unknown long option \`$_'"; } @@ -1183,7 +1271,7 @@ sub parseopts () { if (s/^-n/-/) { $dryrun=1; } elsif (s/^-h/-/) { - helponly(); + cmd_help(); } elsif (s/^-D/-/) { open DEBUG, ">&STDERR" or die $!; $debug++; @@ -1218,6 +1306,8 @@ if ($ENV{$fakeeditorenv}) { quilt_fixup_editor(); } +delete $ENV{'DGET_UNPACK'}; + parseopts(); print STDERR "DRY RUN ONLY\n" if $dryrun; if (!@ARGV) {