X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=207b5d09b6898258608f096cdc205a56ea36641e;hp=55c2b243d3b6dfa1d11909d3242acf533883028c;hb=631c9e09a7fd22a5847173978c3d1357c1db74ea;hpb=a17b1a3b36a31ac8def26e0a5aeca865873c9374 diff --git a/dgit b/dgit index 55c2b243..207b5d09 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'; @@ -67,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'; @@ -83,7 +89,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]; } @@ -118,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 @_; @@ -196,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) @@ -219,7 +248,7 @@ sub badusage { exit 8; } -sub helponly () { +sub cmd_help () { print $helpmsg or die $!; exit 0; } @@ -236,6 +265,7 @@ our %defcfg = ('dgit.default.distro' => '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,13 +351,30 @@ 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; return $c; } +sub git_get_ref ($) { + my ($refname) = @_; + my $got = cmdoutput_errok @git, qw(show-ref --), $refname; + if (!defined $got) { + $?==256 or fail "git show-ref failed (status $?)"; + print DEBUG "ref $refname= [show-ref exited 1]\n"; + return ''; + } + if ($got =~ m/^(\w+) \Q$refname\E$/m) { + print DEBUG "ref $refname=$1\n"; + return $1; + } else { + print DEBUG "ref $refname= [no match]\n"; + return ''; + } +} + our %rmad; sub archive_query ($) { @@ -399,7 +446,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; @@ -431,18 +478,19 @@ sub get_archive_dsc () { my ($vsn,$subpath) = @$vinfo; $dscurl = access_cfg('mirror').$subpath; $dscdata = url_get($dscurl); - next unless defined $dscdata; - $dscurl = access_cfg('mirror').$subpath; - $dscdata = url_get($dscurl); + 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 () { @@ -473,7 +521,7 @@ sub create_remote_git_repo () { } } -our ($dsc_hash,$upload_hash); +our ($dsc_hash,$lastpush_hash); our $ud = '.git/dgit/unpack'; @@ -501,16 +549,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 +632,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 +644,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 +696,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_local shell_cmd 'cd ..', @dget,'--',$origurl; } } @@ -630,76 +706,116 @@ 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_local @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"; - } else { - print "last upload to archive has NO git hash\n"; - } + get_archive_dsc(); - 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+$/; - } elsif ($! == &ENOENT) { - $upload_hash = ''; + 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 { - die "$lrref_fn $!"; + print "no version available from the archive\n"; } - print DEBUG "previous reference hash=$upload_hash\n"; + + $lastpush_hash = git_get_ref(lrref()); + 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; + fail "missing remote git history even though dsc has hash -". + " could not find ref ".lrref(). + " (should have been fetched from ".access_giturl()."#".rrref().")" + 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); @@ -723,7 +839,7 @@ sub clone ($) { if (check_for_git()) { print "fetching existing git history\n"; git_fetch_us(); - runcmd @git, qw(fetch origin); + runcmd_ordryrun_local @git, qw(fetch origin); } else { print "starting new git history\n"; } @@ -742,12 +858,13 @@ 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"; } sub check_not_dirty () { + return if $ignoredirty; my @cmd = (@git, qw(diff --quiet HEAD)); printcmd(\*DEBUG,"+",@cmd) if $debug>0; $!=0; $?=0; system @cmd; @@ -762,31 +879,30 @@ sub check_not_dirty () { sub commit_quilty_patch () { my $output = cmdoutput @git, qw(status --porcelain); my %adds; - my $bad=0; foreach my $l (split /\n/, $output) { next unless $l =~ m/\S/; if ($l =~ m{^(?:\?\?| M) (.pc|debian/patches)}) { $adds{$1}++; - } else { - print STDERR "git status: $l\n"; - $bad++; } } - fail "unexpected output from git status (is tree clean?)" if $bad; if (!%adds) { 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 ($) { 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 +953,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 +978,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 { @@ -871,11 +988,14 @@ sub dopush () { if (!defined $keyid) { $keyid = access_cfg('keyid','RETURN-UNDEF'); } - my @tag_cmd = (@git, qw(tag -s -m), - "Release $dversion for $csuite [dgit]"); - push @tag_cmd, qw(-u),$keyid if defined $keyid; + my @tag_cmd = (@git, qw(tag -m), + "$package release $dversion for $csuite [dgit]"); + 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; @@ -953,7 +1073,7 @@ sub cmd_pull { sub cmd_push { parseopts(); badusage "-p is not allowed with dgit push" if defined $package; - runcmd @git, qw(diff --quiet HEAD); + check_not_dirty(); my $clogp = parsechangelog(); $package = getfield $clogp, 'Source'; if (@ARGV==0) { @@ -969,7 +1089,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 +1125,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; @@ -1021,7 +1145,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") { @@ -1052,42 +1176,50 @@ sub quilt_fixup_editor () { exit 0; } -sub cmd_build { - # we pass further options and args to git-buildpackage - badusage "-p is not allowed with dgit build" if defined $package; - badusage "dgit build implies --clean=dpkg-source" if defined $package; +sub build_prep () { + badusage "-p is not allowed when building" if defined $package; + check_not_dirty(); my $clogp = parsechangelog(); $isuite = getfield $clogp, 'Distribution'; $package = getfield $clogp, 'Source'; $version = getfield $clogp, 'Version'; build_maybe_quilt_fixup(); +} + +sub cmd_build { + badusage "dgit build implies --clean=dpkg-source" + if $cleanmode ne 'dpkg-source'; + build_prep(); + runcmd_ordryrun_local @dpkgbuildpackage, qw(-us -uc), changesopts(), @ARGV; + printdone "build successful\n"; +} + +sub cmd_git_build { + badusage "dgit git-build implies --clean=dpkg-source" + if $cleanmode ne 'dpkg-source'; + build_prep(); 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(); } push @cmd, changesopts(); - runcmd_ordryrun @cmd, @ARGV; + runcmd_ordryrun_local @cmd, @ARGV; printdone "build successful\n"; } sub build_source { - badusage "-p is not allowed with this action" if defined $package; - check_not_dirty(); - my $clogp = parsechangelog(); - $package = getfield $clogp, 'Source'; - $isuite = getfield $clogp, 'Distribution'; - $version = getfield $clogp, 'Version'; - $sourcechanges = "${package}_${version}_source.changes"; + build_prep(); + $sourcechanges = "${package}_".(stripepoch $version)."_source.changes"; $dscfn = dscfn($version); - build_maybe_quilt_fixup(); 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 ?"; @@ -1095,9 +1227,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(); @@ -1113,8 +1245,8 @@ sub cmd_build_source { sub cmd_sbuild { build_source(); chdir ".." or die $!; - my $pat = "${package}_${version}_*.changes"; - if (!$dryrun) { + my $pat = "${package}_".(stripepoch $version)."_*.changes"; + if ($dryrun <= 1) { stat $dscfn or fail "$dscfn (in parent directory): $!"; stat $sourcechanges or fail "$sourcechanges (in parent directory): $!"; foreach my $cf (glob $pat) { @@ -1124,8 +1256,8 @@ sub cmd_sbuild { } runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn; runcmd_ordryrun @mergechanges, glob $pat; - my $multichanges = "${package}_${version}_multi.changes"; - if (!$dryrun) { + my $multichanges = "${package}_".(stripepoch $version)."_multi.changes"; + if ($dryrun <= 1) { stat $multichanges or fail "$multichanges: $!"; } printdone "build successful, results in $multichanges\n" or die $!; @@ -1138,6 +1270,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) { @@ -1146,11 +1283,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$/) { - helponly(); + cmd_help(); + } elsif (m/^--version$/) { + cmd_version(); } elsif (m/^--new$/) { $new_package=1; } elsif (m/^--(\w+)=(.*)/s && @@ -1168,15 +1309,21 @@ 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 \`$_'"; } } else { while (m/^-./s) { if (s/^-n/-/) { + $dryrun=2; + } elsif (s/^-L/-/) { $dryrun=1; } elsif (s/^-h/-/) { - helponly(); + cmd_help(); } elsif (s/^-D/-/) { open DEBUG, ">&STDERR" or die $!; $debug++; @@ -1211,8 +1358,11 @@ if ($ENV{$fakeeditorenv}) { quilt_fixup_editor(); } +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;