Patchwork [4,of,4,V2] dirstate: add exception when calling setparent without begin/end

login
register
mail settings
Submitter Durham Goode
Date Sept. 5, 2014, 10:47 p.m.
Message ID <ddf78c1242c15dd36462.1409957236@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/5709/
State Superseded
Headers show

Comments

Durham Goode - Sept. 5, 2014, 10:47 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1409942264 25200
#      Fri Sep 05 11:37:44 2014 -0700
# Node ID ddf78c1242c15dd36462d867c5675935b60a6adb
# Parent  5d236cbefff41e9c80de2965dc6e42a913428738
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.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -243,6 +243,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