changeset 40754:34f15db81cf0

vfs: extract the audit path logic into a submethod This will make it possible to apply it in more cases.
author Boris Feld <boris.feld@octobus.net>
date Sun, 02 Jul 2017 04:06:24 +0200
parents 9199548525fc
children e3792741e3fb
files mercurial/localrepo.py mercurial/vfs.py
diffstat 2 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu Nov 22 20:01:28 2018 +0100
+++ b/mercurial/localrepo.py	Sun Jul 02 04:06:24 2017 +0200
@@ -1030,12 +1030,12 @@
                 path = path[len(repo.path) + 1:]
             if path.startswith('cache/'):
                 msg = 'accessing cache with vfs instead of cachevfs: "%s"'
-                repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs")
+                repo.ui.develwarn(msg % path, stacklevel=3, config="cache-vfs")
             if path.startswith('journal.') or path.startswith('undo.'):
                 # journal is covered by 'lock'
                 if repo._currentlock(repo._lockref) is None:
                     repo.ui.develwarn('write with no lock: "%s"' % path,
-                                      stacklevel=2, config='check-locks')
+                                      stacklevel=3, config='check-locks')
             elif repo._currentlock(repo._wlockref) is None:
                 # rest of vfs files are covered by 'wlock'
                 #
@@ -1044,7 +1044,7 @@
                     if path.startswith(prefix):
                         return
                 repo.ui.develwarn('write with no wlock: "%s"' % path,
-                                  stacklevel=2, config='check-locks')
+                                  stacklevel=3, config='check-locks')
             return ret
         return checkvfs
 
@@ -1063,7 +1063,7 @@
                 path = path[len(repo.sharedpath) + 1:]
             if repo._currentlock(repo._lockref) is None:
                 repo.ui.develwarn('write with no lock: "%s"' % path,
-                                  stacklevel=3)
+                                  stacklevel=4)
             return ret
         return checksvfs
 
--- a/mercurial/vfs.py	Thu Nov 22 20:01:28 2018 +0100
+++ b/mercurial/vfs.py	Sun Jul 02 04:06:24 2017 +0200
@@ -337,6 +337,13 @@
             return
         os.chmod(name, self.createmode & 0o666)
 
+    def _auditpath(self, path, mode):
+        if self._audit:
+            r = util.checkosfilename(path)
+            if r:
+                raise error.Abort("%s: %r" % (r, path))
+            self.audit(path, mode=mode)
+
     def __call__(self, path, mode="r", atomictemp=False, notindexed=False,
                  backgroundclose=False, checkambig=False, auditpath=True):
         '''Open ``path`` file, which is relative to vfs root.
@@ -369,11 +376,7 @@
         cases (see also issue5418 and issue5584 for detail).
         '''
         if auditpath:
-            if self._audit:
-                r = util.checkosfilename(path)
-                if r:
-                    raise error.Abort("%s: %r" % (r, path))
-            self.audit(path, mode=mode)
+            self._auditpath(path, mode)
         f = self.join(path)
 
         if "b" not in mode: