# HG changeset patch # User Yuya Nishihara # Date 2015-09-13 09:01:01 # Node ID 61efe9ef6ad4dba85760d6aa82c61d45b2609d3c # Parent 44918682093fa10692b114a3a98e778d33e7f381 obsstore: fast path to check if obsstore is empty diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -67,7 +67,7 @@ The header is followed by the markers. M 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 @@ class obsstore(object): 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,