changeset 26310:61efe9ef6ad4

obsstore: fast path to check if obsstore is empty
author Yuya Nishihara <yuya@tcha.org>
date Sun, 13 Sep 2015 18:01:01 +0900
parents 44918682093f
children 60dd8e3977f0
files mercurial/obsolete.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/obsolete.py	Sun Sep 13 17:52:37 2015 +0900
+++ b/mercurial/obsolete.py	Sun Sep 13 18:01:01 2015 +0900
@@ -67,7 +67,7 @@
 comment associated with each format for details.
 
 """
-import struct
+import errno, struct
 import util, base85, node, parsers
 import phases
 from i18n import _
@@ -531,6 +531,15 @@
         return len(self._all)
 
     def __nonzero__(self):
+        if not self._cached('_all'):
+            try:
+                return self.svfs.stat('obsstore').st_size > 1
+            except OSError as inst:
+                if inst.errno != errno.ENOENT:
+                    raise
+                # just build an empty _all list if no obsstore exists, which
+                # avoids further stat() syscalls
+                pass
         return bool(self._all)
 
     def create(self, transaction, prec, succs=(), flag=0, parents=None,