X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=git-debrebase;h=bf9af61627bfc2f5bbd85c87417eec7e2a6c7d42;hp=6211fb633d85ecee3fcb2f6173dde3f9184d0a1f;hb=15406403f564b23f44124fd6cad61cf143ce2f84;hpb=acec8e4b8dc36601d94159bdac169b8f13e64913 diff --git a/git-debrebase b/git-debrebase index 6211fb63..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); @@ -39,7 +42,7 @@ our $us = qw(git-debrebase); sub badusage ($) { my ($m) = @_; print STDERR "bad usage: $m\n"; - exit 12; + finish 12; } sub cfg ($;$) { @@ -1332,7 +1335,7 @@ 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', \&snag; + do_stitch 'quick'; } sub cmd_conclude () { @@ -1345,7 +1348,59 @@ sub cmd_conclude () { badusage "no arguments allowed" if @ARGV; do_launder_head 'launder for git-debrebase quick'; - do_stitch 'quick', \&snag; + do_stitch 'quick'; +} + +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."; + } +} + +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 () { @@ -1421,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]', @@ -1534,3 +1585,5 @@ if (!@ARGV || $opt_defaultcmd_interactive || $ARGV[0] =~ m{^-}) { $cmdfn or badusage "unknown git-debrebase sub-operation $cmd"; $cmdfn->(); } + +finish 0;