memoize('cfg');
+sub dd ($) {
+ my ($v) = @_;
+ my $dd = new Data::Dumper [ $v ];
+ Terse $dd 1; Indent $dd 0; Useqq $dd 1;
+ return Dump $dd;
+}
+
sub get_commit ($) {
my ($objid) = @_;
my $data = git_cat_file $objid, 'commit';
runcmd @git, qw(read-tree), "--prefix=$subdir/", $new_tree_object;
}
+sub make_commit ($$) {
+ my ($parents, $message_paras) = @_;
+ my $tree = cmdoutput @git, qw(write-tree);
+ my @cmd = (@git, qw(commit-tree), $tree);
+ push @cmd, qw(-p), $_ foreach @$parents;
+ push @cmd, qw(-m), $_ foreach @$message_paras;
+ return cmdoutput @cmd;
+}
+
# classify returns an info hash like this
# CommitId => $objid
# Hdr => # commit headers, including 1 final newline
foreach my $ph (@ph) {
push @$p_ref, {
- Ix => $#$p_ref,
+ Ix => scalar @$p_ref,
CommitId => $ph,
};
}
my ($type, @rest) = @_;
$r = { %$r, Type => $type, @rest };
if ($debuglevel) {
- my $dd = new Data::Dumper [ $r ];
- Terse $dd 1; Indent $dd 0; Useqq $dd 1;
- printdebug " = $type ".(Dump $dd)."\n";
+ printdebug " = $type ".(dd $r)."\n";
}
return $r;
};
if (@p == 2 &&
!$haspatches &&
!$p[$prevbrw]{IsOrigin} && # breakwater never starts with an origin
- !($p[$prevbrw]{Differs} & ~DS_DEB) &&
- !($p[!$prevbrw]{Differs} & ~D_UPS)) {
+ !($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] ]);
}
# => ($tip, $breakwater_tip, $last_upstream_merge_in_breakwater)
# (or nothing, if $nogenerate)
+ printdebug "*** WALK $input ".($nogenerate//0)." ".($report//'-')."\n";
+
# go through commits backwards
# we generate two lists of commits to apply:
# breakwater branch and upstream patches
printf $report " PM=%s \@Overwr:%d", $pm, (scalar @$ovwrs)
if $report;
if (@$ovwrs != 1) {
+ printdebug "*** WALK BOMB DgitImportUnpatched\n";
return $bomb->();
}
my $ovwr = $ovwrs->[0]{CommitId};
}
die "$ty ?";
} else {
+ printdebug "*** WALK BOMB unrecognised\n";
return $bomb->();
}
}
$prprdelim->();
+
+ printdebug "*** WALK prep done cur=$cur".
+ " brw $#brw_cl upp $#upp_cl proc $#processed pm $#pseudomerges\n";
+
return if $nogenerate;
# Now we build it back up again
die sprintf "internal error %#x %s %s", $final_check, $build, $input
if $final_check & ~D_PAT_ADD;
- return ($build, $breakwater, $last_upstream_update);
+ my @r = ($build, $breakwater, $last_upstream_update);
+ printdebug "*** WALK RETURN @r\n";
+ return @r
}
sub get_head () { return git_rev_parse qw(HEAD); }
update_head $old, $new, $mrest;
}
+sub update_head_postlaunder ($$$) {
+ my ($old, $tip, $reflogmsg) = @_;
+ update_head $old, $tip, $reflogmsg;
+ # no tree changes except debian/patches
+ runcmd @git, qw(rm --quiet --ignore-unmatch -rf debian/patches);
+}
+
sub cmd_launder () {
badusage "no arguments to launder allowed" if @ARGV;
my $old = get_head();
my ($tip,$breakwater,$last_upstream_merge) = walk $old;
- update_head $old, $tip, 'launder';
- # no tree changes except debian/patches
- runcmd @git, qw(rm --quiet --ignore-unmatch -rf debian/patches);
+ update_head_postlaunder $old, $tip, 'launder';
printf "# breakwater tip\n%s\n", $breakwater;
printf "# working tip\n%s\n", $tip;
printf "# last upstream merge\n%s\n", $last_upstream_merge;
my ($n, @x) = @_; # may be ''
my $pc = $pieces{$n} //= {
Name => $n,
- Desc => ($n ? "upstream piece $n" : "upstream (main piece"),
+ Desc => ($n ? "upstream piece \`$n'" : "upstream (main piece"),
};
while (my $k = shift @x) { $pc->{$k} = shift @x; }
+ $pc;
};
my @newpieces;
foreach my $pc (values %pieces) {
if (!$pc->{Old}) {
- $problem->("introducing upstream piece $pc->{Name}");
+ $problem->("introducing upstream piece \`$pc->{Name}'");
} elsif (!$pc->{New}) {
- $problem->("dropping upstream piece $pc->{Name}");
+ $problem->("dropping upstream piece \`$pc->{Name}'");
} elsif (!is_fast_fwd $pc->{Old}, $pc->{New}) {
$problem->("not fast forward: $pc->{Name} $pc->{Old}..$pc->{New}");
}
}
+ printdebug "%pieces = ", (dd \%pieces), "\n";
+ printdebug "\@newpieces = ", (dd \@newpieces), "\n";
+
if ($problems) {
if ($opt_force) {
printf STDERR
if (@newpieces > 1) {
# need to make the upstream subtree merge commit
- my $us_tree = cmdoutput @git, qw(write-tree);
- my @cmd = (@git, qw(commit-tree), $us_tree);
- push @cmd, qw(-p), $_ foreach @upstream_merge_parents;
- push @cmd, qw(-m), "Combine upstreams for $new_upstream_version";
- push @cmd, qw(-m),
- "[git-debrebase new-upstream combine . ".
- (join " ", map { $_->{Name} } @newpieces[1..$#newpieces]).
- "]";
- $new_upstream = cmdoutput @cmd;
+ $new_upstream = make_commit \@upstream_merge_parents,
+ [ "Combine upstreams for $new_upstream_version",
+ ("[git-debrebase new-upstream combine . ".
+ (join " ", map { $_->{Name} } @newpieces[1..$#newpieces]).
+ "]"),
+ ];
}
# $new_upstream is either the single upstream commit, or the
read_tree_subdir 'debian', "$old_bw:debian";
# index now contains the breakwater merge contents
-
- my $bw_tree = cmdoutput @git, qw(write_tree);
- my @cmd = (@git, qw(commit-tree), $bw_tree);
- push @cmd, qw(-p), $old_bw, qw(-p), $new_upstream;
- push @cmd, qw(-m), "Update to upstream $new_upstream_version";
- push @cmd, qw(-m),
- "[git-debrebase new-upstream breakwater $new_upstream_version]";
- $new_bw = cmdoutput @git;
+ $new_bw = make_commit [ $old_bw, $new_upstream ],
+ [ "Update to upstream $new_upstream_version",
+ "[git-debrebase new-upstream breakwater $new_upstream_version]",
+ ];
# Now we have to add a changelog stanza so the Debian version
# is right.
-
die if unlink "debian";
- die unless $!==ENOTEMPTY;
- unlink "debian/changelog" or die $!;
+ die $! unless $!==ENOENT or $!==ENOTEMPTY;
+ unlink "debian/changelog" or $!==ENOENT or die $!;
+ mkdir "debian" or die $!;
open CN, ">", "debian/changelog" or die $!;
my $oldclog = git_cat_file ":debian/changelog";
$oldclog =~ m/^($package_re) \(\S+\) / or
runcmd @git, qw(update-index --add --replace), 'debian/changelog';
# Now we have the final new breakwater branch in the index
-
- $bw_tree = cmdoutput @git, qw(write_tree);
- @cmd = (@git, qw(commit-tree), $bw_tree);
- push @cmd, qw(-p), $new_bw;
- push @cmd, qw(-m),
- "Update changelog for new upstream $new_upstream_version";
- push @cmd, qw(-m),
- "[git-debrebase new-upstream changelog $new_upstream_version]";
- $new_bw = cmdoutput @git;
+ $new_bw = make_commit [ $new_bw ],
+ [ "Update changelog for new upstream $new_upstream_version",
+ "[git-debrebase new-upstream changelog $new_upstream_version]",
+ ];
};
# we have constructed the new breakwater. we now need to commit to
# the laundering output, because git-rebase can't easily be made
# to make a replay list which is based on some other branch
- update_head $old_head, $old_laundered_tip, 'launder for new upstream';
+ update_head_postlaunder $old_head, $old_laundered_tip,
+ 'launder for new upstream';
my @cmd = (@git, qw(rebase --onto), $new_bw, $old_bw);
runcmd @cmd;