* Rename $snags_checked to $snags_summarised and make it a counter
of the snags we have summarised in snags_maybe_bail.
* Introduce all_snags_summarised, which uses arithmetic to see if
we have had new snags since the most recent snags_maybe_bail,
* Use this in run_deferred_updates rather than the existing
approach; this means we can crash if there were new snags for
which we should have bailed.
* Make snags_maybe_bail not produce a redundant identical summary.
* Initialise counters to 0 so arithmetic does not give undef warnings.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
in_workarea sub { playtree_setup };
}
in_workarea sub { playtree_setup };
}
-our $snags_forced;
-our $snags_tripped;
-our $snags_checked;
+our $snags_forced = 0;
+our $snags_tripped = 0;
+our $snags_summarised = 0;
our @deferred_updates;
our @deferred_update_messages;
our @deferred_updates;
our @deferred_update_messages;
+sub all_snags_summarised () {
+ $snags_forced + $snags_tripped == $snags_summarised;
+}
sub run_deferred_updates ($) {
my ($mrest) = @_;
sub run_deferred_updates ($) {
my ($mrest) = @_;
- confess 'dangerous internal error' if
- !$snags_checked || $snags_tripped || $snags_forced;
+ confess 'dangerous internal error' unless all_snags_summarised();
my @upd_cmd = (@git, qw(update-ref --stdin -m), "debrebase: $mrest");
debugcmd '>|', @upd_cmd;
my @upd_cmd = (@git, qw(update-ref --stdin -m), "debrebase: $mrest");
debugcmd '>|', @upd_cmd;
+# Important: all mainline code must call snags_maybe_bail after
+# any point where snag might be called, but before making changes
+# (eg before any call to run_deferred_updates). snags_maybe_bail
+# may be called more than once if necessary (but this is not ideal
+# because then the messages about number of snags may be confusing).
sub snags_maybe_bail () {
sub snags_maybe_bail () {
+ return if all_snags_summarised();
if ($snags_forced) {
printf STDERR
"%s: snags: %d overriden by individual -f options\n",
$us, $snags_forced;
if ($snags_forced) {
printf STDERR
"%s: snags: %d overriden by individual -f options\n",
$us, $snags_forced;
}
if ($snags_tripped) {
if ($opt_force) {
printf STDERR
"%s: snags: %d overriden by global --force\n",
$us, $snags_tripped;
}
if ($snags_tripped) {
if ($opt_force) {
printf STDERR
"%s: snags: %d overriden by global --force\n",
$us, $snags_tripped;
} else {
fail sprintf
"%s: snags: %d blockers (you could -f<tag>, or --force)",
$us, $snags_tripped;
}
}
} else {
fail sprintf
"%s: snags: %d blockers (you could -f<tag>, or --force)",
$us, $snags_tripped;
}
}
+ $snags_summarised = $snags_forced + $snags_tripped;
}
sub any_snags () {
return $snags_forced || $snags_tripped;
}
sub any_snags () {
return $snags_forced || $snags_tripped;