X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=1838f2fb9e7849ff8d62013cd67ddb6a4375fd81;hp=a21cddec32952c26243ae029a9edd490cb39d3a3;hb=6cda33aa05897023e2a7b300dcbbf04a7d146bb7;hpb=985e8045f860fb0be72b56b6859034b8c8746db9 diff --git a/dgit b/dgit index a21cddec..1838f2fb 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; @@ -129,7 +131,7 @@ sub url_get { return $r->decoded_content(); } -our ($dscdata,$dscurl,$dsc); +our ($dscdata,$dscurl,$dsc,$skew_warning_vsn); sub printcmd { my $fh = shift @_; @@ -207,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 { @@ -332,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; @@ -442,18 +450,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 () { @@ -484,7 +493,7 @@ sub create_remote_git_repo () { } } -our ($dsc_hash,$upload_hash); +our ($dsc_hash,$lastpush_hash); our $ud = '.git/dgit/unpack'; @@ -513,21 +522,19 @@ sub mktree_in_ud_from_only_subdir () { } sub dsc_files_info () { - foreach my $csum (qw(Sha256 Sha1 MD5)) { - my $fname = $csum eq 'MD5' ? 'Files' : "Checksums-$csum"; + 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; - my $digest = uc $csum; - if (!eval "use Digest::$digest; 1;") { - print DEBUG "ignoring $fname because $@\n"; - next; - } + 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 "Digest::$digest->new;" or die $@; + my $digester = eval "$module"."->$method;" or die $@; push @out, { Hash => $1, Bytes => $2, @@ -597,8 +604,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'; @@ -609,7 +616,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; } @@ -651,8 +668,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; } } @@ -673,69 +689,112 @@ sub is_fast_fwd ($$) { } 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 <$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 <', $descfn or die "$descfn: $!"; $msg =~ s/\n/\n /g; @@ -1191,6 +1252,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) { @@ -1203,7 +1269,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 && @@ -1233,7 +1301,7 @@ sub parseopts () { if (s/^-n/-/) { $dryrun=1; } elsif (s/^-h/-/) { - helponly(); + cmd_help(); } elsif (s/^-D/-/) { open DEBUG, ">&STDERR" or die $!; $debug++;