+ $cl = classify $cur;
+ my $ty = $cl->{Type};
+ my $st = $cl->{SubType};
+ $prline->("$cl->{CommitId} $cl->{Type}");
+ $found{$ty. ( defined($st) ? "-$st" : '' )}++;
+ push @processed, $cl;
+ my $p0 = @{ $cl->{Parents} }==1 ? $cl->{Parents}[0]{CommitId} : undef;
+ if ($ty eq 'AddPatches') {
+ $cur = $p0;
+ $rewrite_from_here->();
+ next;
+ } elsif ($ty eq 'Packaging') {
+ push @brw_cl, $cl;
+ $cur = $p0;
+ next;
+ } elsif ($ty eq 'BreakwaterStart') {
+ $build_start->('FirstPackaging', $cur);
+ } elsif ($ty eq 'Upstream') {
+ push @upp_cl, $cl;
+ $cur = $p0;
+ next;
+ } elsif ($ty eq 'Mixed') {
+ my $queue = sub {
+ my ($q, $wh) = @_;
+ my $cls = { $cl, $xmsg->("split mixed commit: $wh part") };
+ push @$q, $cls;
+ };
+ $queue->(\@brw_cl, "debian");
+ $queue->(\@upp_cl, "upstream");
+ $rewrite_from_here->();
+ $cur = $p0;
+ next;
+ } elsif ($ty eq 'Pseudomerge') {
+ my $contrib = $cl->{Contributor}{CommitId};
+ print $report " Contributor=$contrib" if $report;
+ push @pseudomerges, $cl;
+ $rewrite_from_here->();
+ $cur = $contrib;
+ next;
+ } elsif ($ty eq 'BreakwaterUpstreamMerge') {
+ $build_start->("PreviousBreakwater", $cur);
+ } elsif ($ty eq 'DgitImportUnpatched') {
+ my $pm = $pseudomerges[-1];
+ if (defined $pm) {
+ # To an extent, this is heuristic. Imports don't have
+ # a useful history of the debian/ branch. We assume
+ # that the first pseudomerge after an import has a
+ # useful history of debian/, and ignore the histories
+ # from later pseudomerges. Often the first pseudomerge
+ # will be the dgit import of the upload to the actual
+ # suite intended by the non-dgit NMUer, and later
+ # pseudomerges may represent in-archive copies.
+ my $ovwrs = $pm->{Overwritten};
+ printf $report " PM=%s \@Overwr:%d", $pm, (scalar @$ovwrs)
+ if $report;
+ if (@$ovwrs != 1) {
+ return $bomb->();
+ }
+ my $ovwr = $ovwrs->[0]{CommitId};
+ printf $report " Overwr=%s", $ovwr if $report;
+ # This import has a tree which is just like a
+ # breakwater tree, but it has the wrong history. It
+ # ought to have the previous breakwater (which the
+ # pseudomerge overwrote) as an ancestor. That will
+ # make the history of the debian/ files correct. As
+ # for the upstream version: either it's the same as
+ # was ovewritten (ie, same as the previous
+ # breakwater), in which case that history is precisely
+ # right; or, otherwise, it was a non-gitish upload of a
+ # new upstream version. We can tell these apart by
+ # looking at the tree of the supposed upstream.
+ push @brw_cl, {
+ %$cl,
+ SpecialMethod => 'DgitImportDebianUpdate',
+ $xmsg->("convert dgit import: debian changes")
+ };
+ my $differs = (get_differs $ovwr, $cl->{Tree});
+ printf $report " Differs=%#x", $differs if $report;
+ if ($differs & D_UPS) {
+ printf $report " D_UPS" if $report;
+ # This will also trigger if a non-dgit git-based NMU
+ # deleted .gitignore (which is a thing that some of
+ # the existing git tools do if the user doesn't
+ # somehow tell them not to). Ah well.
+ push @brw_cl, {
+ %$cl,
+ SpecialMethod => 'DgitImportUpstreamUpdate',
+ $xmsg->("convert dgit import: upstream changes")
+ };
+ }
+ $prline->(" Import");
+ $rewrite_from_here->();
+ $upp_limit //= $#upp_cl; # further, deeper, patches discarded
+ $cur = $ovwr;
+ next;
+ } else {
+ # Everything is from this import. This kind of import
+ # is already in valid breakwater format, with the
+ # patches as commits.
+ printf $report " NoPM" if $report;
+ # last thing we processed will have been the first patch,
+ # if there is one; which is fine, so no need to rewrite
+ # on account of this import
+ $build_start->("ImportOrigin", $cur);
+ }
+ die "$ty ?";
+ } else {
+ return $bomb->();
+ }
+ }
+ $prprdelim->();
+ return if $nogenerate;
+
+ # Now we build it back up again
+
+ fresh_workarea();
+
+ my $rewriting = 0;
+
+ my $rm_tree_cached = sub {
+ my ($subdir) = @_;
+ runcmd @git, qw(rm --quiet -rf --cached --ignore-unmatch), $subdir;
+ };
+ my $read_tree_debian = sub {
+ my ($treeish) = @_;
+ $rm_tree_cached->(qw(debian));
+ runcmd @git, qw(read-tree --prefix=debian/), "$treeish:debian";
+ };
+ my $read_tree_upstream = sub {
+ my ($treeish) = @_;
+ runcmd @git, qw(read-tree), $treeish;
+ $read_tree_debian->($build);
+ };
+
+ my $committer_authline = calculate_committer_authline();