[PATCH 4 of 4 V3] dirstate: add exception when calling setparent without begin/end

Durham Goode durham at fb.com
Tue Sep 9 15:21:30 CDT 2014


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1409942264 25200
#      Fri Sep 05 11:37:44 2014 -0700
# Node ID 2328d9edda009ab9ae9da8156d96763ff1ef76fc
# Parent  af3352972f8fddfb0c5b755e6ceb2470a31e6f7c
dirstate: add exception when calling setparent without begin/end

Adds an exception when calling dirstate.setparent without having first called
dirstate.beginparentchange. This will prevent people from writing code that
modifies the dirstate parent without considering the transactionality of their
change.

This will break third party extensions that call setparents.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -256,6 +256,10 @@
 
         See localrepo.setparents()
         """
+        if self._parentwriters == 0:
+            raise util.Abort(_("cannot set dirstate parent without " +
+                " calling dirstate.begingparentchange"))
+
         self._dirty = self._dirtypl = True
         oldp2 = self._pl[1]
         self._pl = p1, p2


More information about the Mercurial-devel mailing list