X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=git-debrebase;h=f6d379ac81b036e4be6682e1a25b9c24a9b867ef;hb=236890b58b8255d8d540b5cbd326228489bd0363;hp=6259dfe8076bf83b0dab5b00973b28529e1a2afd;hpb=b33a6ea64a28a1122d75ce3a0d4808211e0734d3;p=dgit.git
diff --git a/git-debrebase b/git-debrebase
index 6259dfe8..f6d379ac 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 8;
}
sub cfg ($;$) {
@@ -99,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 $!;
@@ -227,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) {
@@ -241,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)",
@@ -1076,6 +1086,8 @@ sub stitch ($$$$$) {
}
}
fresh_workarea();
+ # We make pseudomerges with L as the contributing parent.
+ # This makes git rev-list --first-parent work properly.
my $new_head = make_commit [ $old_head, $ffq_prev ], [
'Declare fast forward / record previous work',
"[git-debrebase pseudomerge: $prose]",
@@ -1325,7 +1337,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 () {
@@ -1338,7 +1350,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 () {
@@ -1414,14 +1478,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]',
@@ -1527,3 +1587,5 @@ if (!@ARGV || $opt_defaultcmd_interactive || $ARGV[0] =~ m{^-}) {
$cmdfn or badusage "unknown git-debrebase sub-operation $cmd";
$cmdfn->();
}
+
+finish 0;