[PATCH 8 of 8] revlog: disable lazy parsers when running under PyPy

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Dec 24 18:35:37 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1293200636 -3600
# Node ID 244e1f304faac009e4e55579f6c8a35141793be7
# Parent  d281ff54afa4e11534aee921102706c477c13322
revlog: disable lazy parsers when running under PyPy

Using the lazy parsers mean that it becomes fairly difficult to
determine when files should be closed. As PyPy tends to delay garbage
collection of file descriptors just too long for our taste, we risk
exhausting file descriptors when opening many revlogs. With this
change, Mercurial running under PyPy is able to verify the Mercurial
repository itself.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -455,10 +455,12 @@ class revlog(object):
         if shallowroot:
             v |= REVLOGSHALLOW
 
+        nonlazy = ("nonlazy" in getattr(self.opener, 'options', {})
+                   or util.ispypy())
         i = ''
         try:
             f = self.opener(self.indexfile)
-            if "nonlazy" in getattr(self.opener, 'options', {}):
+            if nonlazy:
                 i = f.read()
             else:
                 i = f.read(_prereadsize)
@@ -495,7 +497,7 @@ class revlog(object):
             if not self._chunkcache:
                 self._chunkclear()
 
-            if "nonlazy" in getattr(self.opener, 'options', {}):
+            if nonlazy:
                 f.close()
 
         # add the magic null revision at -1 (if it hasn't been done already)
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1524,3 +1524,8 @@ def parsebool(s):
     If s is not a valid boolean, returns None.
     """
     return _booleans.get(s.lower(), None)
+
+def ispypy():
+    """Return True when running under the PyPy VM."""
+    # The PyPy developers recommend this technique for detecting it.
+    return '__pypy__' in sys.builtin_module_names


More information about the Mercurial-devel mailing list