Patchwork [3,of,5,RFC] obsstore: fast path to check if obsstore is empty

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 23, 2015, 5:48 a.m.
Message ID <13a9dacedbbee19365dd.1442987284@mimosa>
Download mbox | patch
Permalink /patch/10590/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 23, 2015, 5:48 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1442134861 -32400
#      Sun Sep 13 18:01:01 2015 +0900
# Node ID 13a9dacedbbee19365ddd911020a74e8ba392f0e
# Parent  3e6c365f6630059e4c1ee4fbf7ce2aa557e1821f
obsstore: fast path to check if obsstore is empty
Pierre-Yves David - Sept. 23, 2015, 8:59 a.m.
On 09/22/2015 10:48 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1442134861 -32400
> #      Sun Sep 13 18:01:01 2015 +0900
> # Node ID 13a9dacedbbee19365ddd911020a74e8ba392f0e
> # Parent  3e6c365f6630059e4c1ee4fbf7ce2aa557e1821f
> 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'):

The first three are pushed to the clowncopter, thanks.

Patch

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,