X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=git-debrebase;h=bf9af61627bfc2f5bbd85c87417eec7e2a6c7d42;hp=7a49dd767a22a69a1ddbaf4948136638fe2b020c;hb=223328e90bbec5bd8a0c55bf1a0f0f609e8154ac;hpb=d740305a9c26a80521480a1242f13e55b6928621 diff --git a/git-debrebase b/git-debrebase index 7a49dd76..bf9af616 100755 --- a/git-debrebase +++ b/git-debrebase @@ -18,6 +18,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +END { $? = $Debian::Dgit::ExitStatus::desired // -1; }; +use Debian::Dgit::ExitStatus; + use strict; use Debian::Dgit qw(:DEFAULT :playground); @@ -32,13 +35,14 @@ use Dpkg::Version; use File::FnMatch qw(:fnmatch); our ($opt_force, $opt_noop_ok, @opt_anchors); +our ($opt_defaultcmd_interactive); our $us = qw(git-debrebase); sub badusage ($) { my ($m) = @_; print STDERR "bad usage: $m\n"; - exit 12; + finish 12; } sub cfg ($;$) { @@ -98,12 +102,18 @@ sub fresh_workarea () { in_workarea sub { playtree_setup }; } +our $snags_forced; +our $snags_tripped; +our $snags_checked; our @deferred_updates; our @deferred_update_messages; sub run_deferred_updates ($) { my ($mrest) = @_; + confess 'dangerous internal error' if + !$snags_checked || $snags_tripped || $snags_forced; + my @upd_cmd = (@git, qw(update-ref --stdin -m), "debrebase: $mrest"); debugcmd '>|', @upd_cmd; open U, "|-", @upd_cmd or die $!; @@ -226,8 +236,6 @@ sub make_commit ($$) { } our @snag_force_opts; -our $snags_forced; -our $snags_tripped; sub snag ($$) { my ($tag,$msg) = @_; if (grep { $_ eq $tag } @snag_force_opts) { @@ -240,16 +248,19 @@ sub snag ($$) { } sub snags_maybe_bail () { + $snags_checked++; if ($snags_forced) { printf STDERR "%s: snags: %d overriden by individual -f options\n", $us, $snags_forced; + $snags_forced=0; } if ($snags_tripped) { if ($opt_force) { printf STDERR "%s: snags: %d overriden by global --force\n", $us, $snags_tripped; + $snags_tripped=0; } else { fail sprintf "%s: snags: %d blockers (you could -f, or --force)", @@ -395,6 +406,15 @@ sub classify ($) { # BreakwaterStart commits are also anchors in the terminology # of git-debrebase(5), but they are untagged (and always # manually generated). + # + # We cannot not tolerate any tagged linear commit (ie, + # BreakwaterStart commits tagged `[anchor:') because such a + # thing could result from an erroneous linearising raw git + # rebase of a merge anchor. That would represent a corruption + # of the branch. and we want to detect and reject the results + # of such corruption before it makes it out anywhere. If we + # reject it here then we avoid making the pseudomerge which + # would be needed to push it. my $badanchor = sub { $unknown->("git-debrebase \`anchor' but @_"); }; @p == 2 or return $badanchor->("has other than two parents"); @@ -550,7 +570,7 @@ sub keycommits ($;$$$) { $breakwater = undef; } elsif ($ty eq 'Mixed') { $x->($unclean, 'mixed', - 'found mixed upstream/packaging commit ($head)'); + "found mixed upstream/packaging commit ($head)"); $clogonly = undef; $breakwater = undef; } elsif ($ty eq 'Pseudomerge' or @@ -891,6 +911,7 @@ sub do_launder_head ($) { my $old = get_head(); record_ffq_auto(); my ($tip,$breakwater) = walk $old; + snags_maybe_bail(); update_head_postlaunder $old, $tip, $reflogmsg; return ($tip,$breakwater); } @@ -906,8 +927,9 @@ sub cmd_launder_v0 () { } sub defaultcmd_rebase () { + push @ARGV, @{ $opt_defaultcmd_interactive // [] }; my ($tip,$breakwater) = do_launder_head 'launder for rebase'; - runcmd @git, qw(rebase), @ARGV, $breakwater; + runcmd @git, qw(rebase), @ARGV, $breakwater if @ARGV; } sub cmd_analyse () { @@ -1072,6 +1094,22 @@ sub stitch ($$$$$) { update_head $old_head, $new_head, "stitch: $prose"; } +sub do_stitch ($;$) { + my ($prose, $unclean) = @_; + + my ($ffq_prev, $gdrlast, $ffq_prev_commitish) = ffq_prev_info(); + if (!$ffq_prev_commitish) { + fail "No ffq-prev to stitch." unless $opt_noop_ok; + return; + } + my $dangling_head = get_head(); + + keycommits $dangling_head, $unclean,$unclean,$unclean; + snags_maybe_bail(); + + stitch($dangling_head, $ffq_prev, $gdrlast, $ffq_prev_commitish, $prose); +} + sub cmd_new_upstream_v0 () { # automatically and unconditionally launders before rebasing # if rebase --abort is used, laundering has still been done @@ -1217,6 +1255,10 @@ sub cmd_new_upstream_v0 () { "[git-debrebase anchor: new upstream $new_upstream_version, merge]", ]; + my $clogsignoff = cmdoutput qw(git show), + '--pretty=format:%an <%ae> %aD', + $new_bw; + # Now we have to add a changelog stanza so the Debian version # is right. die if unlink "debian"; @@ -1233,7 +1275,7 @@ $p ($new_version) UNRELEASED; urgency=medium * Update to new upstream version $new_upstream_version. - -- + -- $clogsignoff END close CN or die $!; @@ -1286,17 +1328,79 @@ sub cmd_stitch () { my $prose = 'stitch'; GetOptions('prose=s', \$prose) or die badusage("bad options to stitch"); badusage "no arguments allowed" if @ARGV; + do_stitch $prose, 0; +} +sub cmd_prepush () { cmd_stitch(); } + +sub cmd_quick () { + badusage "no arguments allowed" if @ARGV; + do_launder_head 'launder for git-debrebase quick'; + do_stitch 'quick'; +} +sub cmd_conclude () { my ($ffq_prev, $gdrlast, $ffq_prev_commitish) = ffq_prev_info(); if (!$ffq_prev_commitish) { - fail "No ffq-prev to stitch." unless $opt_noop_ok; + fail "No ongoing git-debrebase session." unless $opt_noop_ok; return; } - my $old_head = get_head(); + my $dangling_head = get_head(); + + badusage "no arguments allowed" if @ARGV; + do_launder_head 'launder for git-debrebase quick'; + do_stitch 'quick'; +} - keycommits $old_head, \&snag, \&snag, \&snag; +sub make_patches_staged ($) { + my ($head) = @_; + # Produces the patches that would result from $head if it were + # laundered. + my ($secret_head, $secret_bw, $last_anchor) = walk $head; + fresh_workarea(); + in_workarea sub { + runcmd @git, qw(checkout -q -b bw), $secret_bw; + runcmd @git, qw(checkout -q -b patch-queue/bw), $secret_head; + runcmd qw(gbp pq export); + runcmd @git, qw(add debian/patches); + }; +} + +sub make_patches ($) { + my ($head) = @_; + keycommits $head, 0, \&snag; + make_patches_staged $head; + my $out; + in_workarea sub { + my $ptree = cmdoutput @git, qw(write-tree --prefix=debian/patches/); + runcmd @git, qw(read-tree), $head; + read_tree_subdir 'debian/patches', $ptree; + $out = make_commit [$head], [ + 'Commit patch queue (exported by git-debrebase)', + '[git-debrebase: export and commit patches]', + ]; + }; + my $d = get_differs $head, $out; + if ($d == 0) { + return undef; # nothing to do + } elsif ($d == D_PAT_ADD) { + return $out; # OK + } else { + fail "Patch export produced patch amendments". + " (abandoned output commit $out).". + " Try laundering first."; + } +} - stitch($old_head, $ffq_prev, $gdrlast, $ffq_prev_commitish, $prose); +sub cmd_make_patches () { + badusage "no arguments allowed" if @ARGV; + my $old_head = get_head(); + my $new = make_patches $old_head; + snags_maybe_bail(); + if (!$new) { + fail "No (more) patches to export." unless $opt_noop_ok; + return; + } + update_head_checkout $old_head, $new, 'make-patches'; } sub cmd_convert_from_gbp () { @@ -1372,14 +1476,10 @@ sub cmd_convert_to_gbp () { badusage "no arguments allowed" if @ARGV; my $head = get_head(); my (undef, undef, undef, $ffq, $gdrlast) = ffq_prev_branchinfo(); - my ($anchor, $bw) = keycommits $head, 0; - fresh_workarea(); + keycommits $head, 0; my $out; + make_patches_staged $head; in_workarea sub { - runcmd @git, qw(checkout -q -b bw), $bw; - runcmd @git, qw(checkout -q -b patch-queue/bw), $head; - runcmd qw(gbp pq export); - runcmd @git, qw(add debian/patches); $out = make_commit ['HEAD'], [ 'Commit patch queue (converted from git-debrebase format)', '[git-debrebase convert-to-gbp: commit patches]', @@ -1389,6 +1489,7 @@ sub cmd_convert_to_gbp () { push @deferred_updates, "delete $ffq"; push @deferred_updates, "delete $gdrlast"; } + snags_maybe_bail(); update_head_checkout $head, $out, "convert to gbp (v0)"; print < \$debuglevel, 'noop-ok', => \$opt_noop_ok, 'f=s' => \@snag_force_opts, 'anchor=s' => \@opt_anchors, - 'force!') or die badusage "bad options\n"; + 'force!', + '-i:s' => sub { + my ($opt,$val) = @_; + badusage "git-debrebase: no cuddling to -i for git-rebase" + if length $val; + die if $opt_defaultcmd_interactive; # should not happen + $opt_defaultcmd_interactive = [ qw(-i) ]; + # This access to @ARGV is excessive familiarity with + # Getopt::Long, but there isn't another sensible + # approach. '-i=s{0,}' does not work with bundling. + push @$opt_defaultcmd_interactive, @ARGV; + @ARGV=(); + }) or die badusage "bad options\n"; initdebug('git-debrebase '); enabledebug if $debuglevel; @@ -1461,7 +1574,7 @@ $rd = fresh_playground "$playprefix/misc"; @opt_anchors = map { git_rev_parse $_ } @opt_anchors; -if (!@ARGV || $ARGV[0] =~ m{^-}) { +if (!@ARGV || $opt_defaultcmd_interactive || $ARGV[0] =~ m{^-}) { defaultcmd_rebase(); } else { my $cmd = shift @ARGV; @@ -1472,3 +1585,5 @@ if (!@ARGV || $ARGV[0] =~ m{^-}) { $cmdfn or badusage "unknown git-debrebase sub-operation $cmd"; $cmdfn->(); } + +finish 0;