chiark / gitweb /
git-debrebase: downstream-rebase-launder-v0 first cut
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Aug 2017 10:26:31 +0000 (11:26 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jun 2018 11:25:49 +0000 (12:25 +0100)
git-debrebase

index a1d277e..c3ff3af 100755 (executable)
@@ -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;