Patchwork [8,of,9] repair: move check for existing transaction earlier

login
register
mail settings
Submitter via Mercurial-devel
Date June 19, 2017, 8:48 p.m.
Message ID <f3febdbec4cbfb75deca.1497905280@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21514/
State Accepted
Headers show

Comments

via Mercurial-devel - June 19, 2017, 8:48 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1497903480 25200
#      Mon Jun 19 13:18:00 2017 -0700
# Node ID f3febdbec4cbfb75deca3ed73525f573d9566f13
# Parent  8b6444932695a274c93a06bc3744f99b849d3fab
repair: move check for existing transaction earlier

Several benefits:

 * Gets close the comment describing it
 * Splits off unrelated comment about "backup" argument
 * Error checking is customarily done early
 * If we added an early return to the method, it would still
   consistently fail if there was an existing transaction (so
   we would find and fix that case quickly)

One test needs updating with for this change, because we no longer
create the backup bundle before we fail. I don't see much reason to
create that backup bundle. If some command was adding content and then
trying to strip it as well within the transaction, we would have a
backup for the user, but the risk of that not being discovered in
development seems very small.

Patch

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -79,6 +79,9 @@ 
     # This function requires the caller to lock the repo, but it operates
     # within a transaction of its own, and thus requires there to be no current
     # transaction when it is called.
+    if repo.currenttransaction() is not None:
+        raise error.ProgrammingError('cannot strip from inside a transaction')
+
     # Simple way to maintain backwards compatibility for this
     # argument.
     if backup in ['none', 'strip']:
@@ -168,9 +171,6 @@ 
 
     mfst = repo.manifestlog._revlog
 
-    if repo.currenttransaction() is not None:
-        raise error.ProgrammingError('cannot strip from inside a transaction')
-
     try:
         with repo.transaction("strip") as tr:
             offset = len(tr.entries)
diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t
--- a/tests/test-devel-warnings.t
+++ b/tests/test-devel-warnings.t
@@ -108,7 +108,6 @@ 
   $ hg add a
   $ hg commit -m a
   $ hg stripintr 2>&1 | egrep -v '^(\*\*|  )'
-  saved backup bundle to $TESTTMP/lock-checker/.hg/strip-backup/*-backup.hg (glob)
   Traceback (most recent call last):
   mercurial.error.ProgrammingError: cannot strip from inside a transaction