watchman: detect nested mercurial repositories and abort
authorBoris Feld <boris.feld@octobus.net>
Fri, 21 Dec 2018 17:10:07 +0100
changeset 41503 5125f0a9728b
parent 41502 18adb747a332
child 41504 09f1c17e24dd
watchman: detect nested mercurial repositories and abort Disable fsmonitor on nested mercurial repositories. Only depth one repositories are detected at the moment. Differential Revision: https://phab.mercurial-scm.org/D5587
hgext/fsmonitor/__init__.py
--- a/hgext/fsmonitor/__init__.py	Fri Dec 21 17:12:31 2018 +0100
+++ b/hgext/fsmonitor/__init__.py	Fri Dec 21 17:10:07 2018 +0100
@@ -367,6 +367,9 @@
         fexists = entry['exists']
         kind = getkind(fmode)
 
+        if '/.hg/' in fname or fname.endswith('/.hg'):
+            return bail('nested-repo-detected')
+
         if not fexists:
             # if marked as deleted and we don't already have a change
             # record, mark it as deleted.  If we already have an entry
@@ -740,6 +743,14 @@
             repo, node, branchmerge, force, ancestor, mergeancestor,
             labels, matcher, **kwargs)
 
+def repo_has_depth_one_nested_repo(repo):
+    for f in repo.wvfs.listdir():
+        if os.path.isdir(os.path.join(repo.root, f, '.hg')):
+            msg = 'fsmonitor: sub-repository %r detected, fsmonitor disabled\n'
+            repo.ui.debug(msg % f)
+            return True
+    return False
+
 def reposetup(ui, repo):
     # We don't work with largefiles or inotify
     exts = extensions.enabled()
@@ -757,6 +768,9 @@
         if repo.wvfs.exists('.hgsubstate') or repo.wvfs.exists('.hgsub'):
             return
 
+        if repo_has_depth_one_nested_repo(repo):
+            return
+
         fsmonitorstate = state.state(repo)
         if fsmonitorstate.mode == 'off':
             return