my $committer_authline = calculate_committer_authline();
+ my $need_rewrite = 0;
+
in_workarea sub {
mkdir $rd or $!==EEXIST or die $!;
-
my $current_method;
- foreach my $cl (qw(Debian), @deb_cl, qw(Upstream), @ups_cl) {
+ foreach my $cl (qw(Debian), (reverse @deb_cl),
+ qw(Upstream), (reverse @ups_cl)) {
if (!ref $cl) {
$current_method = $cl;
next;
} elsif ($method eq 'DgitImportDebianUpdate') {
$read_tree_debian->($cltree);
$rm_tree_cached(qw(debian/patches));
+ $need_rewrite = 1;
} elsif ($method eq 'DgitImportUpstreamUpdate') {
$read_tree_upstream->($cltree);
push @parents, map { $_->{CommitId} } @{ $cl->{OrigParents} };
+ $need_rewrite = 1;
} else {
confess "$method ?";
}
my $newtree = cmdoutput @git, qw(write-tree);
- my $ch = $cl->{Msg};
+ my $ch = $cl->{Hdr};
$ch =~ s{^tree .*}{tree $newtree}m or confess "$ch ?";
- $ch =~ s{^committer .*$}{$committer_authline}m or confess "$ch ?";
- open CD, ">", "$rd/m" or die $!;
- print CD $ch, "\n", $cl->{Msg}; or die $!;
- close CD or die $!;
- my $newcommit = cmdoutput @git, qw(hash-object -t commit), "$rd/m";
- $build = $newcommit;
+ $ch =~ s{^parent .*\n}{}m;
+ $ch =~ s{(?=^author}{
+ map { "parent $_\n" } @parents
+ }me or confess "$ch ?";
+ foreach my $rewrite ($need_rewrite ? 1 : qw(0 1)) {
+ if ($rewrite) {
+ $ch =~ s{^committer .*$}{$committer_authline}m
+ or confess "$ch ?";
+ $need_rewrite = 1;
+ }
+ my $cf = "$rd/m$rewrite"
+ open CD, ">", $cf or die $!;
+ print CD $ch, "\n", $cl->{Msg}; or die $!;
+ close CD or die $!;
+ my @cmd = (@git, qw(hash-object));
+ push @cmd, qw(-w) if $rewrite;
+ push @cmd, qw(-t commit), $cf;
+ my $newcommit = cmdoutput @cmd;
+ next unless $rewrite or $newcommit eq $cl->{CommitId};
+ $build = $newcommit;
+ last;
+ }
}
};