Patchwork [4,of,6] vfs: extract the audit path logic into a submethod

login
register
mail settings
Submitter Boris Feld
Date Nov. 26, 2018, 6:22 p.m.
Message ID <7f04e7e8eea72eb588d9.1543256566@localhost.localdomain>
Download mbox | patch
Permalink /patch/36778/
State Accepted
Headers show

Comments

Boris Feld - Nov. 26, 2018, 6:22 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1498961184 -7200
#      Sun Jul 02 04:06:24 2017 +0200
# Node ID 7f04e7e8eea72eb588d9460df7c0f2b72941b760
# Parent  3d8d2de85c9afc06b7aad740aa1ad2c817d18dfa
# EXP-Topic vfs.audit-rename
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 7f04e7e8eea7
vfs: extract the audit path logic into a submethod

This will make it possible to apply it in more cases.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1029,12 +1029,12 @@  class localrepository(object):
                 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'
                 #
@@ -1043,7 +1043,7 @@  class localrepository(object):
                     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
 
@@ -1062,7 +1062,7 @@  class localrepository(object):
                 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
 
diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -337,6 +337,13 @@  class vfs(abstractvfs):
             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 @@  class vfs(abstractvfs):
         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: