[PATCH 2 of 7] scmutil: add the remappedvfs class

Yuya Nishihara yuya at tcha.org
Sun Nov 29 08:14:54 CST 2015


On Tue, 24 Nov 2015 18:22:26 -0600, Angel Ezquerra wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra at gmail.com>
> # Date 1445731304 -3600
> #      Sun Oct 25 01:01:44 2015 +0100
> # Node ID d7b08e9f7782fdc21663dff41149c054862276f5
> # Parent  6b3bf294c85ce407f2bf2f6f18eb07a85aa3ab54
> scmutil: add the remappedvfs class
> 
> The remappedvfs class is derived from the regular vfs class. It lets you
> customize the vfs join.method which in turn lets you, for example, map certain
> files to alternative paths.
> 
> This class will be used in follow up patches which will introduce a "full share"
> mode for the share extension. It will make it possible to create a vfs object
> that accesses the files on the shared repository path except for the limited set
> of files that must be accessed from the share target repository.
> 
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -543,6 +543,30 @@
>          else:
>              return self.base
>  
> +class remappedvfs(vfs):
> +    """vfs subclass that lets you customize its join function
> +
> +    This can be used, for example to remap files to alternative paths"""
> +    def __init__(self, *args, **kwargs):
> +        # This class' __init__ method adds a joinfn keyword argument on top of
> +        # the regular vfs class __init__ method arguments.
> +        # This new joinfn argument lets you provide a custom join function which
> +        # which will be used instead of the regular vfs class join method.
> +        # The custom join function can fall back to the default join method
> +        # by returning None.
> +        self._defaultjoinfn = super(remappedvfs, self).join
> +        self._joinfn = kwargs.get('joinfn', self._defaultjoinfn)
> +        # remove the joinfn argument before calling the parent's constructor
> +        if 'joinfn' in kwargs:
> +            del kwargs['joinfn']
> +        super(remappedvfs, self).__init__(*args, **kwargs)

I think if a path is redirected to outside of self.base by joinfn(), this vfs
object can't be used. For example, _cansymlink is calculated from self.base,
auditor is created for self.base, etc.

> +    def join(self, path):
> +        joinedpath = self._joinfn(path)
> +        if joinedpath is not None:
> +            return joinedpath
> +        return self._defaultjoinfn(path)

join() accepts more than one path components.


More information about the Mercurial-devel mailing list