X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=git-debrebase;h=bf9af61627bfc2f5bbd85c87417eec7e2a6c7d42;hp=52a06d37c17ccecbc9ab3241c63c03375031262f;hb=223328e90bbec5bd8a0c55bf1a0f0f609e8154ac;hpb=9fe0302b9d3652f4423ab12a4db18145c6b7b13c;ds=sidebyside diff --git a/git-debrebase b/git-debrebase index 52a06d37..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 ($;$) { @@ -1348,17 +1351,58 @@ sub cmd_conclude () { do_stitch 'quick'; } -sub make_patches_staged ($$) { - my ($bw, $head) = @_; +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), $bw; - runcmd @git, qw(checkout -q -b patch-queue/bw), $head; + 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 () { badusage "needs 1 optional argument, the upstream git rev" unless @ARGV<=1; @@ -1432,9 +1476,9 @@ 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; + keycommits $head, 0; my $out; - make_patches_staged $bw, $head; + make_patches_staged $head; in_workarea sub { $out = make_commit ['HEAD'], [ 'Commit patch queue (converted from git-debrebase format)', @@ -1541,3 +1585,5 @@ if (!@ARGV || $opt_defaultcmd_interactive || $ARGV[0] =~ m{^-}) { $cmdfn or badusage "unknown git-debrebase sub-operation $cmd"; $cmdfn->(); } + +finish 0;