From bcaec0456e20d69fd35784543c6d80401f4d6754 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 25 Aug 2017 11:26:31 +0100 Subject: [PATCH] git-debrebase: downstream-rebase-launder-v0 first cut --- git-debrebase | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/git-debrebase b/git-debrebase index a1d277e5..c3ff3afb 100755 --- a/git-debrebase +++ b/git-debrebase @@ -716,6 +716,51 @@ sub cmd_analyse () { STDOUT->error and die $!; } +sub cmd_downstream_rebase_launder_v0 () { + badusage "needs 1 argument, the baseline" unless @ARGV=0; + my ($base) = @ARGV; + $base = git_rev_parse $base; + my $old_head = get_head(); + my $current = $old_head; + my $topmost_keep; + for (;;) { + if ($current eq $base) { + $topmust_keep //= $current; + print "$current BASE: stopping\n"; + last; + } + my $cl = classify $current; + print " $current $cl->{Type}"; + my $keep = 0; + my $p0 = $cl->{Parents}[0]{CommitId}; + if ($cl->{Type} eq 'Pseudomerge') { + $current = $cl->{Contributor}{CommitId}; + print " ^".($cl->{Contributor}{Ix}+1); + } elsif ($cl->{Type} eq 'AddPatches' or + $cl->{Type} eq 'Changelog') { + print " strip"; + $current = $p0; + } else { + print " keep"; + $current = $p0; + $keep = 1; + } + print "\n"; + if ($keep) { + $topmost_keep //= $current; + } else { + die "to-be stripped changes not on top of the branch\n" + if $topmost_unstripped; + } + } + if ($topmost_keep eq $old_head) { + print "unchanged\n"; + } else { + print "updating to $topmost_keep\n"; + update_head $old_head, $topmost_keep, 'downstream-rebase-launder-v0'; + } +} + GetOptions("D+" => \$debuglevel) or die badusage "bad options\n"; initdebug('git-debrebase '); enabledebug if $debuglevel; -- 2.30.2