chiark / gitweb /
git-debrebase: break out fproblem
[dgit.git] / git-debrebase
index b57e42833cee4a5562d2cf8510d62620ad6c44e0..b83cceb365acaaa1ec253a13a506db4f1e919b40 100755 (executable)
@@ -252,6 +252,26 @@ sub make_commit ($$) {
     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
@@ -853,13 +873,6 @@ sub cmd_new_upstream_v0 () {
     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) {
@@ -873,35 +886,25 @@ sub cmd_new_upstream_v0 () {
                $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;