[PATCH 2 of 3 V4] repovfs: add a ward to check if locks are properly taken

Yuya Nishihara yuya at tcha.org
Fri Jul 14 11:17:03 EDT 2017


On Fri, 14 Jul 2017 16:01:49 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1499769497 -7200
> #      Tue Jul 11 12:38:17 2017 +0200
> # Node ID cea0a88164c6d003b43fe542ec12def2662c1273
> # Parent  201d9cbd64a276db278552a8924206afb67b1a4c
> # EXP-Topic vfs.ward
> repovfs: add a ward to check if locks are properly taken

> +    def _getvfsward(self, origfunc):
> +        """build a ward for self.vfs"""
> +        rref = weakref.ref(self)
> +        def checkvfs(path, mode=None):
> +            ret = origfunc(path, mode=mode)
> +            repo = rref()
> +            if (repo is None
> +                or not util.safehasattr(repo, '_wlockref')
> +                or not util.safehasattr(repo, '_lockref')):
> +                return
> +            if mode in (None, 'r', 'rb'):
> +                return
> +            if path.startswith(repo.path):
> +                # truncate name relative to the repository (.hg)
> +                path = path[len(repo.path) + 1:]
> +            if path.startswith('journal.'):
> +                # journal is covered by 'lock'
> +                if repo._currentlock(repo._lockref) is None:
> +                    repo.ui.develwarn('write with no lock: "%s"' % path,
> +                                      stacklevel=2)
> +            elif repo._currentlock(repo._wlockref) is None:
> +                # rest of vfs files are covered by 'wlock'
> +                #
> +                # exclude special files
> +                for prefix in self._wlockfreeprefix:
> +                    if path.startswith(prefix):
> +                        return
> +                repo.ui.develwarn('write with no wlock: "%s"' % path,
> +                                  stacklevel=2)
> +            return ret

Nit: this function should do either "return" or "return ret" consistently.


More information about the Mercurial-devel mailing list