[PATCH 4 of 6 V2] fsmonitor: avoid needless instantiation of dirstate

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon Jul 10 10:18:17 EDT 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1499695792 -32400
#      Mon Jul 10 23:09:52 2017 +0900
# Node ID 65cdc2a0e356d131cd6675316adbb9d4b9a06845
# Parent  826ccec0e5c33bedeb95f6f60b397e3565b209ec
fsmonitor: avoid needless instantiation of dirstate

Using repo.local() instead of util.safehasattr(repo, 'dirstate') also
avoids executing setup procedures for remote repository (including
statichttprepo).

This is reason why this patch also removes a part of subsequent
comment, and try/except for AttributeError at accessing to repo.wvfs.

diff --git a/hgext/fsmonitor/__init__.py b/hgext/fsmonitor/__init__.py
--- a/hgext/fsmonitor/__init__.py
+++ b/hgext/fsmonitor/__init__.py
@@ -677,16 +677,12 @@ def reposetup(ui, repo):
                       'extension and has been disabled.\n') % ext)
             return
 
-    if util.safehasattr(repo, 'dirstate'):
-        # We don't work with subrepos either. Note that we can get passed in
-        # e.g. a statichttprepo, which throws on trying to access the substate.
-        # XXX This sucks.
-        try:
-            # if repo[None].substate can cause a dirstate parse, which is too
-            # slow. Instead, look for a file called hgsubstate,
-            if repo.wvfs.exists('.hgsubstate') or repo.wvfs.exists('.hgsub'):
-                return
-        except AttributeError:
+    if repo.local():
+        # We don't work with subrepos either.
+        #
+        # if repo[None].substate can cause a dirstate parse, which is too
+        # slow. Instead, look for a file called hgsubstate,
+        if repo.wvfs.exists('.hgsubstate') or repo.wvfs.exists('.hgsub'):
             return
 
         fsmonitorstate = state.state(repo)


More information about the Mercurial-devel mailing list