return cmdoutput @cmd;
}
+our $fproblems;
+sub fproblem ($) {
+ my ($msg) = @_;
+ $fproblems++;
+ print STDERR "git-debrebase: safety catch tripped: $msg\n";
+}
+sub fproblems_maybe_bail () {
+ if ($fproblems) {
+ if ($opt_force) {
+ printf STDERR
+ "safety catch trips (%d) overriden by --force\n",
+ $fproblems;
+ } else {
+ fail sprintf
+ "safety catch trips (%d) (you could --force)",
+ $fproblems;
+ }
+ }
+}
+
# classify returns an info hash like this
# CommitId => $objid
# Hdr => # commit headers, including 1 final newline
my $old_upstream = parsecommit
$old_upstream_update_cl->{OrigParents}[0]{CommitId};
- my $problems = 0;
- my $problem = sub {
- my ($msg) = @_;
- $problems++;
- print STDERR "preflight check failed: $msg\n";
- };
-
$piece->('', Old => $old_upstream->{CommitId});
if ($old_upstream->{Msg} =~ m{^\[git-debrebase }m) {
if ($old_upstream->{Msg} =~
- m{^\[git-debrebase new-upstream combine \.((?: $extra_orig_namepart_re)+)\]}
+ m{^\[git-debrebase (?:\w*-)?upstream combine \.((?: $extra_orig_namepart_re)+)\]}
) {
my @oldpieces = ('', split / /, $1);
my $parentix = -1 + scalar @{ $old_upstream->{Parents} };
$piece->($n, Old => $old_upstream->{CommitId}.'^'.$parentix);
}
} else {
- $problem->("previous upstream $old_upstream->{CommitId} is from".
- " git-debrebase but not a \`new-upstream combine' commit");
+ fproblem "previous upstream $old_upstream->{CommitId} is from".
+ " git-debrebase but not an \`upstream combine' commit";
}
}
foreach my $pc (values %pieces) {
if (!$pc->{Old}) {
- $problem->("introducing upstream piece \`$pc->{Name}'");
+ fproblem "introducing upstream piece \`$pc->{Name}'";
} elsif (!$pc->{New}) {
- $problem->("dropping upstream piece \`$pc->{Name}'");
+ fproblem "dropping upstream piece \`$pc->{Name}'";
} elsif (!is_fast_fwd $pc->{Old}, $pc->{New}) {
- $problem->("not fast forward: $pc->{Name} $pc->{Old}..$pc->{New}");
+ fproblem "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
- "preflight check failures (%d) overriden by --force\n",
- $problems;
- } else {
- fail sprintf
- "preflight check failures (%d) (you could --force)",
- $problems;
- }
- }
+ fproblems_maybe_bail();
my $new_bw;