repair: forbid strip from inside a transaction
authorPierre-Yves David <pierre-yves.david@fb.com>
Sat, 23 May 2015 21:18:47 -0700
changeset 25300 678d0bfdd31a
parent 25299 4f07fb1d7fbb
child 25301 caaf4045eca8
repair: forbid strip from inside a transaction Stripping inside a transaction will (at best) crash or (at worst) result in very unexpected results. We explicitly forbid it early.
mercurial/repair.py
tests/test-devel-warnings.t
--- a/mercurial/repair.py	Wed May 27 12:14:10 2015 -0400
+++ b/mercurial/repair.py	Sat May 23 21:18:47 2015 -0700
@@ -151,6 +151,12 @@
 
     mfst = repo.manifest
 
+    curtr = repo.currenttransaction()
+    if curtr is not None:
+        del curtr  # avoid carrying reference to transaction for nothing
+        msg = _('programming error: cannot strip from inside a transaction')
+        raise util.Abort(msg, hint=_('contact your extension maintainer'))
+
     tr = repo.transaction("strip")
     offset = len(tr.entries)
 
--- a/tests/test-devel-warnings.t	Wed May 27 12:14:10 2015 -0400
+++ b/tests/test-devel-warnings.t	Sat May 23 21:18:47 2015 -0700
@@ -3,7 +3,7 @@
   > """A small extension that acquire locks in the wrong order
   > """
   > 
-  > from mercurial import cmdutil
+  > from mercurial import cmdutil, repair
   > 
   > cmdtable = {}
   > command = cmdutil.command(cmdtable)
@@ -38,6 +38,15 @@
   >     wl = repo.wlock(wait=False)
   >     wl.release()
   >     lo.release()
+  > 
+  > @command('stripintr', [], '')
+  > def stripintr(ui, repo):
+  >     lo = repo.lock()
+  >     tr = repo.transaction('foobar')
+  >     try:
+  >         repair.strip(repo.ui, repo, [repo['.'].node()])
+  >     finally:
+  >         lo.release()
   > EOF
 
   $ cat << EOF >> $HGRCPATH
@@ -87,4 +96,14 @@
    $TESTTMP/buggylocking.py:* in buggylocking (glob)
   $ hg properlocking
   $ hg nowaitlocking
+
+  $ echo a > a
+  $ hg add a
+  $ hg commit -m a
+  $ hg stripintr
+  saved backup bundle to $TESTTMP/lock-checker/.hg/strip-backup/cb9a9f314b8b-cc5ccb0b-backup.hg (glob)
+  abort: programming error: cannot strip from inside a transaction
+  (contact your extension maintainer)
+  [255]
+
   $ cd ..