X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=5f923aaaef02234c9d17cfe4425e38bfdcbf20fa;hp=809d0b9d06fc713de3d6eb70ea689007576a0aed;hb=e9358173d8338dd0e6f37a6779ac863579d33b6e;hpb=5c9ed5c0a77935dca8bb6f0c1cf6181d2ee54e48 diff --git a/dgit b/dgit index 809d0b9d..5f923aaa 100755 --- a/dgit +++ b/dgit @@ -67,6 +67,7 @@ our $rmchanges; our $overwrite_version; # undef: not specified; '': check changelog our $quilt_mode; our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|dpm|unapplied'; +our $split_brain_save; our $we_are_responder; our $initiator_tempdir; our $patches_applied_dirtily = 00; @@ -2868,6 +2869,11 @@ sub clone ($) { } setup_new_tree(); runcmd @git, qw(reset --hard), lrref(); + runcmd qw(bash -ec), <<'END'; + set -o pipefail + git ls-tree -r --name-only -z HEAD | \ + xargs -0r touch -r . -- +END printdone "ready for work in $dstdir"; } @@ -2981,6 +2987,18 @@ sub madformat_wantfixup ($) { return 1; } +sub maybe_split_brain_save ($$$) { + my ($headref, $dgitview, $msg) = @_; + # => message fragment "$saved" describing disposition of $dgitview + return "commit id $dgitview" unless defined $split_brain_save; + my @cmd = (shell_cmd "cd ../../../..", + @git, qw(update-ref -m), + "dgit --dgit-view-save $msg HEAD=$headref", + $split_brain_save, $dgitview); + runcmd @cmd; + return "and left in $split_brain_save"; +} + # An "infopair" is a tuple [ $thing, $what ] # (often $thing is a commit hash; $what is a description) @@ -3141,6 +3159,8 @@ END_OVERWR Make fast forward from $i_arch_v->[0] END_MAKEFF + maybe_split_brain_save $maintview, $r, "pseudomerge"; + progress "Made pseudo-merge of $i_arch_v->[0] into dgit view."; return $r; } @@ -4159,9 +4179,10 @@ END runcmd @git, qw(update-ref -m), $cachekey, "refs/$splitbraincache", $dgitview; - progress "dgit view: created (commit id $dgitview)"; - changedir '.git/dgit/unpack/work'; + + my $saved = maybe_split_brain_save $headref, $dgitview, "converted"; + progress "dgit view: created ($saved)"; } sub quiltify ($$$$) { @@ -4631,8 +4652,9 @@ sub quilt_check_splitbrain_cache ($$) { my $cachehit = $1; quilt_fixup_mkwork($headref); + my $saved = maybe_split_brain_save $headref, $cachehit, "cache-hit"; if ($cachehit ne $headref) { - progress "dgit view: found cached (commit id $cachehit)"; + progress "dgit view: found cached ($saved)"; runcmd @git, qw(checkout -q -b dgit-view), $cachehit; $split_brain = 1; return ($cachehit, $splitbrain_cachekey); @@ -5276,11 +5298,31 @@ sub cmd_quilt_fixup { } sub cmd_import_dsc { + my $needsig = 0; + + while (@ARGV) { + last unless $ARGV[0] =~ m/^-/; + $_ = shift @ARGV; + last if m/^--?$/; + if (m/^--require-valid-signature$/) { + $needsig = 1; + } else { + badusage "unknown dgit import-dsc sub-option \`$_'"; + } + } + badusage "usage: dgit import-dsc .../PATH/TO/.DSC BRANCH" unless @ARGV==2; my ($dscfn, $dstbranch) = @ARGV; badusage "dry run makes no sense with import-dsc" unless act_local(); + my $force = $dstbranch =~ s/^\+// ? +1 : + $dstbranch =~ s/^\.\.// ? -1 : + 0; + my $info = $force ? " $&" : ''; + $info = "$dscfn$info"; + + my $specbranch = $dstbranch; $dstbranch = "refs/heads/$dstbranch" unless $dstbranch =~ m#^refs/#; $dstbranch = cmdoutput @git, qw(check-ref-format --normalize), $dstbranch; @@ -5291,10 +5333,31 @@ sub cmd_import_dsc { fail "$dstbranch is checked out - will not update it" if defined $chead and $chead eq $dstbranch; + my $oldhash = git_get_ref $dstbranch; + open D, "<", $dscfn or fail "open import .dsc ($dscfn): $!"; $dscdata = do { local $/ = undef; ; }; D->error and fail "read $dscfn: $!"; close C; + + # we don't normally need this so import it here + use Dpkg::Source::Package; + my $dp = new Dpkg::Source::Package filename => $dscfn, + require_valid_signature => $needsig; + { + local $SIG{__WARN__} = sub { + print STDERR $_[0]; + return unless $needsig; + fail "import-dsc signature check failed"; + }; + if (!$dp->is_signed()) { + warn "$us: warning: importing unsigned .dsc\n"; + } else { + my $r = $dp->check_signature(); + die "->check_signature => $r" if $needsig && $r; + } + } + parse_dscdata(); my $dgit_commit = $dsc->{$ourdscfield[0]}; @@ -5312,13 +5375,27 @@ Your git tree does not have that object. Try `git fetch' from a plausible server (browse.dgit.d.o? alioth?), and try the import-dsc again. END } - @cmd = (@git, qw(update-ref -m), "dgit import-dsc (Dgit): $dscfn", + if ($oldhash && !is_fast_fwd $oldhash, $dgit_commit) { + if ($force > 0) { + progress "Not fast forward, forced update."; + } else { + fail "Not fast forward to $dgit_commit"; + } + } + @cmd = (@git, qw(update-ref -m), "dgit import-dsc (Dgit): $info", $dstbranch, $dgit_commit); runcmd @cmd; progress "dgit: import-dsc updated git ref $dstbranch"; return 0; } + fail < 0) { + progress "Import, forced update - synthetic orphan git history."; + } elsif ($force < 0) { + progress "Import, merging."; + my $tree = cmdoutput @git, qw(rev-parse), "$newhash:"; + my $version = getfield $dsc, 'Version'; + $newhash = make_commit_text <