D6350: rust-dirstate: call parse/pack bindings from Python

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Wed May 15 14:16:12 EDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG9c6c0f736e1d: rust-dirstate: call parse/pack bindings from Python (authored by Alphare, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6350?vs=15033&id=15116

REVISION DETAIL
  https://phab.mercurial-scm.org/D6350

AFFECTED FILES
  mercurial/dirstate.py
  tests/fakedirstatewritetime.py

CHANGE DETAILS

diff --git a/tests/fakedirstatewritetime.py b/tests/fakedirstatewritetime.py
--- a/tests/fakedirstatewritetime.py
+++ b/tests/fakedirstatewritetime.py
@@ -16,6 +16,12 @@
 )
 from mercurial.utils import dateutil
 
+try:
+    from mercurial import rustext
+    rustext.__name__  # force actual import (see hgdemandimport)
+except ImportError:
+    rustext = None
+
 configtable = {}
 configitem = registrar.configitem(configtable)
 
@@ -51,16 +57,22 @@
     # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
     fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
 
-    orig_pack_dirstate = parsers.pack_dirstate
+    if rustext is not None:
+        orig_module = rustext.dirstate
+        orig_pack_dirstate = rustext.dirstate.pack_dirstate
+    else:
+        orig_module = parsers
+        orig_pack_dirstate = parsers.pack_dirstate
+
     orig_dirstate_getfsnow = dirstate._getfsnow
     wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)
 
-    parsers.pack_dirstate = wrapper
+    orig_module.pack_dirstate = wrapper
     dirstate._getfsnow = lambda *args: fakenow
     try:
         return func()
     finally:
-        parsers.pack_dirstate = orig_pack_dirstate
+        orig_module.pack_dirstate = orig_pack_dirstate
         dirstate._getfsnow = orig_dirstate_getfsnow
 
 def _poststatusfixup(orig, workingctx, status, fixup):
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -27,6 +27,12 @@
     util,
 )
 
+try:
+    from . import rustext
+    rustext.__name__  # force actual import (see hgdemandimport)
+except ImportError:
+    rustext = None
+
 parsers = policy.importmod(r'parsers')
 
 propertycache = util.propertycache
@@ -1465,7 +1471,12 @@
         # parsing the dirstate.
         #
         # (we cannot decorate the function directly since it is in a C module)
-        parse_dirstate = util.nogc(parsers.parse_dirstate)
+        if rustext is not None:
+            parse_dirstate = rustext.dirstate.parse_dirstate
+        else:
+            parse_dirstate = parsers.parse_dirstate
+
+        parse_dirstate = util.nogc(parse_dirstate)
         p = parse_dirstate(self._map, self.copymap, st)
         if not self._dirtyparents:
             self.setparents(*p)
@@ -1476,7 +1487,12 @@
         self.get = self._map.get
 
     def write(self, st, now):
-        st.write(parsers.pack_dirstate(self._map, self.copymap,
+        if rustext is not None:
+            pack_dirstate = rustext.dirstate.pack_dirstate
+        else:
+            pack_dirstate = parsers.pack_dirstate
+
+        st.write(pack_dirstate(self._map, self.copymap,
                                        self.parents(), now))
         st.close()
         self._dirtyparents = False



To: Alphare, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list