chiark / gitweb /
dgit: Drop an obsolete xxx comment
[dgit.git] / git-debrebase
index 4046425e5fa92ffd66235a68e7833279af97370f..f4602d54be75d6a8ab16d24b5e8f63cdf0249faa 100755 (executable)
@@ -255,6 +255,20 @@ sub read_tree_subdir ($$) {
     runcmd @git, qw(read-tree), "--prefix=$subdir/", $new_tree_object;
 }
 
+sub read_tree_debian ($) {
+    my ($treeish) = @_;
+    read_tree_subdir 'debian', "$treeish:debian";
+    rm_subdir_cached 'debian/patches';
+}
+
+sub read_tree_upstream ($) {
+    my ($treeish) = @_;
+    my $save = cmdoutput @git, qw(write-tree --prefix=debian/);
+    runcmd @git, qw(read-tree), $treeish;
+    read_tree_subdir 'debian', $save;
+    rm_subdir_cached 'debian/patches';
+};
+
 sub make_commit ($$) {
     my ($parents, $message_paras) = @_;
     my $tree = cmdoutput @git, qw(write-tree);
@@ -310,6 +324,22 @@ sub any_snags () {
     return $snags_forced || $snags_tripped;
 }
 
+sub gbp_pq_export ($$$) {
+    my ($bname, $base, $tip) = @_;
+    # must be run in a workarea.  $bname and patch-queue/$bname
+    # ought not to exist.  Leaves you on patch-queue/$bname with
+    # the patches staged but not committed.
+    runcmd @git, qw(checkout -q -b), $bname, $base;
+    runcmd @git, qw(checkout -q -b), "patch-queue/$bname", $tip;
+    my @gbp_cmd = (qw(gbp pq export));
+    my $r = system shell_cmd 'exec >../gbp-pq-err 2>&1', @gbp_cmd;
+    if ($r) {
+       { local ($!,$?); copy('../gbp-pq-err', \*STDERR); }
+       failedcmd @gbp_cmd;
+    }
+    runcmd @git, qw(add -f debian/patches);
+}
+
 # classify returns an info hash like this
 #   CommitId => $objid
 #   Hdr => # commit headers, including 1 final newline
@@ -661,14 +691,15 @@ sub keycommits ($;$$$$) {
     return ($anchor, $breakwater);
 }
 
-sub walk ($;$$);
-sub walk ($;$$) {
+sub walk ($;$$$);
+sub walk ($;$$$) {
     my ($input,
-       $nogenerate,$report) = @_;
+       $nogenerate,$report, $report_lprefix) = @_;
     # => ($tip, $breakwater_tip, $last_anchor)
     # (or nothing, if $nogenerate)
 
     printdebug "*** WALK $input ".($nogenerate//0)." ".($report//'-')."\n";
+    $report_lprefix //= '';
 
     # go through commits backwards
     # we generate two lists of commits to apply:
@@ -700,7 +731,7 @@ sub walk ($;$$) {
 
     my $prline = sub {
        return unless $report;
-       print $report $prdelim, @_;
+       print $report $prdelim, $report_lprefix, @_;
        $prdelim = "\n";
     };
 
@@ -850,17 +881,6 @@ sub walk ($;$$) {
 
     my $rewriting = 0;
 
-    my $read_tree_debian = sub {
-       my ($treeish) = @_;
-       read_tree_subdir 'debian', "$treeish:debian";
-        rm_subdir_cached 'debian/patches';
-    };
-    my $read_tree_upstream = sub {
-       my ($treeish) = @_;
-       runcmd @git, qw(read-tree), $treeish;
-       $read_tree_debian->($build);
-    };
-
     $#upp_cl = $upp_limit if defined $upp_limit;
  
     my $committer_authline = calculate_committer_authline();
@@ -886,9 +906,9 @@ sub walk ($;$$) {
            printdebug "WALK BUILD ".($cltree//'undef').
                " $method (rewriting=$rewriting)\n";
            if ($method eq 'Debian') {
-               $read_tree_debian->($cltree);
+               read_tree_debian($cltree);
            } elsif ($method eq 'Upstream') {
-               $read_tree_upstream->($cltree);
+               read_tree_upstream($cltree);
            } elsif ($method eq 'StartRewrite') {
                $rewriting = 1;
                next;
@@ -896,12 +916,12 @@ sub walk ($;$$) {
                $breakwater = $build;
                next;
            } elsif ($method eq 'DgitImportDebianUpdate') {
-               $read_tree_debian->($cltree);
+               read_tree_debian($cltree);
            } elsif ($method eq 'DgitImportUpstreamUpdate') {
                confess unless $rewriting;
                my $differs = (get_differs $build, $cltree);
                next unless $differs & D_UPS;
-               $read_tree_upstream->($cltree);
+               read_tree_upstream($cltree);
                push @parents, map { $_->{CommitId} } @{ $cl->{OrigParents} };
            } else {
                confess "$method ?";
@@ -975,6 +995,18 @@ sub update_head_postlaunder ($$$) {
     runcmd @git, qw(rm --quiet --ignore-unmatch -rf debian/patches);
 }
 
+sub currently_rebasing() {
+    foreach (qw(rebase-merge rebase-apply)) {
+       return 1 if stat_exists "$maindir_gitdir/$_";
+    }
+    return 0;
+}
+
+sub bail_if_rebasing() {
+    fail "you are in the middle of a git-rebase already"
+       if currently_rebasing();
+}
+
 sub do_launder_head ($) {
     my ($reflogmsg) = @_;
     my $old = get_head();
@@ -1114,6 +1146,7 @@ sub record_ffq_prev_deferred () {
     # if "deferred", will have added something about that to
     #   @deferred_update_messages, and also maybe printed (already)
     #   some messages about ff checks
+    bail_if_rebasing();
     my $currentval = get_head();
 
     my ($status,$message, $ffq_prev,$gdrlast) = ffq_check $currentval;
@@ -1137,6 +1170,7 @@ sub record_ffq_auto () {
 }
 
 sub ffq_prev_info () {
+    bail_if_rebasing();
     # => ($ffq_prev, $gdrlast, $ffq_prev_commitish)
     my ($status, $message, $current, $ffq_prev, $gdrlast)
        = ffq_prev_branchinfo();
@@ -1547,6 +1581,7 @@ sub cmd_status () {
            print "  not git-debrebase (diverged since last stitch)\n"
        }
     }
+    print "you are currently rebasing\n" if currently_rebasing();
 }
 
 sub cmd_stitch () {
@@ -1578,6 +1613,9 @@ sub cmd_conclude () {
 }
 
 sub cmd_scrap () {
+    if (currently_rebasing()) {
+       runcmd @git, qw(rebase --abort);
+    }
     my ($ffq_prev, $gdrlast, $ffq_prev_commitish) = ffq_prev_info();
     if (!$ffq_prev_commitish) {
        fail "No ongoing git-debrebase session." unless $opt_noop_ok;
@@ -1599,15 +1637,7 @@ sub make_patches_staged ($) {
     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;
-       my @gbp_cmd = (qw(gbp pq export));
-       my $r = system shell_cmd 'exec >../gbp-pq-err 2>&1', @gbp_cmd;
-       if ($r) {
-           { local ($!,$?); copy('../gbp-pq-err', \*STDERR); }
-           failedcmd @gbp_cmd;
-       }
-       runcmd @git, qw(add -f debian/patches);
+       gbp_pq_export 'bw', $secret_bw, $secret_head;
     };
 }
 
@@ -1633,6 +1663,7 @@ sub cmd_make_patches () {
     getoptions("make-patches",
               'quiet-would-amend!', \$opt_quiet_would_amend);
     badusage "no arguments allowed" if @ARGV;
+    bail_if_rebasing();
     my $old_head = get_head();
     my $new = make_patches $old_head;
     my $d = get_differs $old_head, $new;