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

Dan Villiom Podlaski Christiansen danchr at gmail.com
Sun Dec 26 05:51:25 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1293364216 -3600
# Node ID eb07bf508de5bb5647c0b3c1aab95c8fee51a6f7
# Parent  86eb1e8cce41ed6423698682adec8f9c71498dfd
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
@@ -1540,3 +1540,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