+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';
+}
+