- # How to decide about l/r ordering of breakwater merges ? git
- # --topo-order prefers to expand 2nd parent first. There's
- # already an easy rune to look for debian/ history anyway (git log
- # debian/) so debian breakwater branch should be 1st parent; that
- # way also there's also an easy rune to look for the upstream
- # patches (--topo-order).
-
- # The above tells us which way *we* will generate them. But we
- # might encounter ad-hoc breakwater merges generated manually,
- # which might be the other way around. In principle, in some odd
- # situations, a breakwater merge might have two identical parents.
- # In that case we guess which way round it is (ie, which parent
- # has the upstream history). The order of the 2-iteration loop
- # controls which guess we make.
-
- foreach my $prevbrw (qw(0 1)) {
- if (@p == 2 &&
- !$haspatches &&
- !$p[$prevbrw]{IsOrigin} && # breakwater never starts with an origin
- !($p[!$prevbrw]{Differs} & ~DS_DEB) && # no non-debian changess
- !($p[$prevbrw]{Differs} & ~D_UPS)) { # no non-upstream changes
- return $classify->(qw(BreakwaterUpstreamMerge),
- OrigParents => [ $p[!$prevbrw] ]);
+sub keycommits ($;$$$$) {
+ my ($head, $furniture, $unclean, $trouble, $fatal) = @_;
+ # => ($anchor, $breakwater)
+
+ # $unclean->("unclean-$tagsfx", $msg, $cl)
+ # $furniture->("unclean-$tagsfx", $msg, $cl)
+ # $dgitimport->("unclean-$tagsfx", $msg, $cl))
+ # is callled for each situation or commit that
+ # wouldn't be found in a laundered branch
+ # $furniture is for furniture commits such as might be found on an
+ # interchange branch (pseudomerge, d/patches, changelog)
+ # $trouble is for things whnich prevent the return of
+ # anchor and breakwater information; if that is ignored,
+ # then keycommits returns (undef, undef) instead.
+ # $fatal is for unprocessable commits, and should normally cause
+ # a failure. If ignored, agaion, (undef, undef) is returned.
+ #
+ # If a callback is undef, fail is called instead.
+ # If a callback is defined but false, the situation is ignored.
+ # Callbacks may say:
+ # no warnings qw(exiting); last;
+ # if the answer is no longer wanted.
+
+ my ($anchor, $breakwater);
+ my $clogonly;
+ my $cl;
+ $fatal //= sub { fail $_[2]; };
+ my $x = sub {
+ my ($cb, $tagsfx, $mainwhy, $xwhy) = @_;
+ my $why = $mainwhy.$xwhy;
+ my $m = "branch needs laundering (run git-debrebase): $why";
+ fail $m unless defined $cb;
+ return unless $cb;
+ $cb->("unclean-$tagsfx", $why, $cl, $mainwhy);
+ };
+ for (;;) {
+ $cl = classify $head;
+ my $ty = $cl->{Type};
+ if ($ty eq 'Packaging') {
+ $breakwater //= $clogonly;
+ $breakwater //= $head;
+ } elsif ($ty eq 'Changelog') {
+ # this is going to count as the tip of the breakwater
+ # only if it has no upstream stuff before it
+ $clogonly //= $head;
+ } elsif ($ty eq 'Anchor' or
+ $ty eq 'TreatAsAnchor' or
+ $ty eq 'BreakwaterStart') {
+ $anchor = $head;
+ $breakwater //= $clogonly;
+ $breakwater //= $head;
+ last;
+ } elsif ($ty eq 'Upstream') {
+ $x->($unclean, 'ordering',
+ "packaging change ($breakwater) follows upstream change"," (eg $head)")
+ if defined $breakwater;
+ $clogonly = undef;
+ $breakwater = undef;
+ } elsif ($ty eq 'Mixed') {
+ $x->($unclean, 'mixed',
+ "found mixed upstream/packaging commit"," ($head)");
+ $clogonly = undef;
+ $breakwater = undef;
+ } elsif ($ty eq 'Pseudomerge' or
+ $ty eq 'AddPatches') {
+ $x->($furniture, (lc $ty),
+ "found interchange bureaucracy commit ($ty)"," ($head)");
+ } elsif ($ty eq 'DgitImportUnpatched') {
+ $x->($trouble, 'dgitimport',
+ "found dgit dsc import ($head)");
+ return (undef,undef);
+ } else {
+ $x->($fatal, 'unprocessable',
+ "found unprocessable commit, cannot cope: $cl->{Why}",
+ " ($head)");
+ return (undef,undef);