chiark / gitweb /
git-debrebase: provide breakwater command
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 17 Feb 2018 11:47:19 +0000 (11:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jun 2018 15:03:11 +0000 (16:03 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
git-debrebase

index 32737269a48120fa3f55720d8b778ca618ad3858..1a62852e19ac765a0ed1e2175d37104e59f048ac 100755 (executable)
@@ -28,6 +28,7 @@
 #
 #    git-debrebase [<options> --] [<git-rebase options...>]
 #    git-debrebase [<options>] analyse
 #
 #    git-debrebase [<options> --] [<git-rebase options...>]
 #    git-debrebase [<options>] analyse
+#    git-debrebase [<options>] breakwater      # prints breakwater tip only
 #    git-debrebase [<options>] launder         # prints breakwater tip etc.
 #    git-debrebase [<options>] stitch [--prose=<for commit message>]
 #    git-debrebase [<options>] downstream-rebase-launder-v0  # experimental
 #    git-debrebase [<options>] launder         # prints breakwater tip etc.
 #    git-debrebase [<options>] stitch [--prose=<for commit message>]
 #    git-debrebase [<options>] downstream-rebase-launder-v0  # experimental
@@ -508,6 +509,42 @@ sub classify ($) {
     return $unknown->("complex merge");
 }
 
     return $unknown->("complex merge");
 }
 
+sub breakwater_of ($) {
+    my ($head) = @_; # must be laundered
+    my $breakwater;
+    my $unclean = sub {
+       my ($why) = @_;
+       fail "branch needs laundering (run git-debrebase): $why";
+    };
+    for (;;) {
+       my $cl = classify $head;
+       my $ty = $cl->{Type};
+       if ($ty eq 'Packaging' or
+           $ty eq 'Changelog') {
+           $breakwater //= $head;
+       } elsif ($ty eq 'BreakwaterUpstreamMerge' or
+                $ty eq 'BreakwaterStart') {
+           $breakwater //= $head;
+           last;
+       } elsif ($ty eq 'Upstream') {
+           $unclean->("packaging change ($breakwater)".
+                      " follows upstream change (eg $head)")
+               if defined $breakwater;
+       } elsif ($ty eq 'Mixed') {
+           $unclean->('found mixed upstream/packaging commit ($head)');
+       } elsif ($ty eq 'Pseudomerge' or
+                $ty eq 'AddPatches') {
+           $unclean->("found interchange conversion commit ($ty, $head)");
+       } elsif ($ty eq 'DgitImportUnpatched') {
+           $unclean->("found dgit dsc import ($head)");
+       } else {
+           fail "found unprocessable commit, cannot cope: $head; $cl->{Why}";
+       }
+       $head = $cl->{Parents}[0]{CommitId};
+    }
+    return $breakwater;
+}
+
 sub walk ($;$$);
 sub walk ($;$$) {
     my ($input,
 sub walk ($;$$);
 sub walk ($;$$) {
     my ($input,
@@ -1133,6 +1170,12 @@ sub cmd_record_ffq_prev () {
     }
 }
 
     }
 }
 
+sub cmd_breakwater () {
+    badusage "no arguments allowed" if @ARGV;
+    my $bw = breakwater_of git_rev_parse 'HEAD';
+    print "$bw\n" or die $!;
+}
+
 sub cmd_stitch () {
     my $prose = '';
     GetOptions('prose=s', \$prose) or die badusage("bad options to stitch");
 sub cmd_stitch () {
     my $prose = '';
     GetOptions('prose=s', \$prose) or die badusage("bad options to stitch");