From 5ccc45c714e700c97d52fa291daef03cd2492780 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 25 Mar 2018 17:11:41 +0100 Subject: git-debrebase: break out stitch() (nfc) Signed-off-by: Ian Jackson --- git-debrebase | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/git-debrebase b/git-debrebase index 29f06a3..1713246 100755 --- a/git-debrebase +++ b/git-debrebase @@ -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 () { -- cgit v1.2.3