chiark / gitweb /
git-debrebase: break out stitch() (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Mar 2018 16:11:41 +0000 (17:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jun 2018 15:07:01 +0000 (16:07 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
git-debrebase

index 29f06a3..1713246 100755 (executable)
@@ -1026,6 +1026,33 @@ sub record_ffq_auto () {
     }
 }
 
+sub stitch ($$$$$) {
+    my ($old_head, $ffq_prev, $gdrlast, $ffq_prev_commitish, $prose) = @_;
+
+    push @deferred_updates, "delete $ffq_prev $ffq_prev_commitish";
+
+    if (is_fast_fwd $old_head, $ffq_prev_commitish) {
+       my $differs = get_differs $old_head, $ffq_prev_commitish;
+       unless ($differs & ~D_PAT_ADD) {
+           # ffq-prev is ahead of us, and the only tree changes it has
+           # are possibly addition of things in debian/patches/.
+           # Just wind forwards rather than making a pointless pseudomerge.
+           push @deferred_updates,
+               "update $gdrlast $ffq_prev_commitish $git_null_obj";
+           update_head_checkout $old_head, $ffq_prev_commitish,
+               "stitch (fast forward)";
+           return;
+       }
+    }
+    fresh_workarea();
+    my $new_head = make_commit [ $old_head, $ffq_prev ], [
+       'Declare fast forward / record previous work',
+        "[git-debrebase pseudomerge: stitch$prose]",
+    ];
+    push @deferred_updates, "update $gdrlast $new_head $git_null_obj";
+    update_head $old_head, $new_head, "stitch";
+}
+
 sub cmd_new_upstream_v0 () {
     # automatically and unconditionally launders before rebasing
     # if rebase --abort is used, laundering has still been done
@@ -1246,8 +1273,8 @@ sub cmd_stitch () {
        fproblem $status, "could not check ffq-prev: $message";
        fproblems_maybe_bail();
     }
-    my $prev = $ffq_prev && git_get_ref $ffq_prev;
-    if (!$prev) {
+    my $ffq_prev_commitish = $ffq_prev && git_get_ref $ffq_prev;
+    if (!$ffq_prev_commitish) {
        fail "No ffq-prev to stitch." unless $opt_noop_ok;
        return;
     }
@@ -1255,26 +1282,7 @@ sub cmd_stitch () {
 
     keycommits $old_head, \&fproblem, \&fproblem, \&fproblem;
 
-    push @deferred_updates, "delete $ffq_prev $prev";
-
-    if (is_fast_fwd $old_head, $prev) {
-       my $differs = get_differs $old_head, $prev;
-       unless ($differs & ~D_PAT_ADD) {
-           # ffq-prev is ahead of us, and the only tree changes it has
-           # are possibly addition of things in debian/patches/.
-           # Just wind forwards rather than making a pointless pseudomerge.
-           push @deferred_updates, "update $gdrlast $prev $git_null_obj";
-           update_head_checkout $old_head, $prev, "stitch (fast forward)";
-           return;
-       }
-    }
-    fresh_workarea();
-    my $new_head = make_commit [ $old_head, $ffq_prev ], [
-       'Declare fast forward / record previous work',
-        "[git-debrebase pseudomerge: stitch$prose]",
-    ];
-    push @deferred_updates, "update $gdrlast $new_head $git_null_obj";
-    update_head $old_head, $new_head, "stitch";
+    stitch($old_head, $ffq_prev, $gdrlast, $ffq_prev_commitish, $prose);
 }
 
 sub cmd_convert_from_gbp () {