[PATCH 2 of 2] vfs: add a 'split' method

Augie Fackler raf at durin42.com
Tue Dec 16 09:56:55 CST 2014


On Mon, Dec 15, 2014 at 01:48:57PM -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1418679154 28800
> #      Mon Dec 15 13:32:34 2014 -0800
> # Node ID 7f6ac2c061acbf204c1fe62feb7fbd9d11101f10
> # Parent  85b532e6228482d7d7723827254fe01c7ea753cf
> vfs: add a 'split' method
>
> This method have the same behavior as the 'os.path.split' function. But having
> it in vfs will allow handling of tricky encoding situation in the future.

For some reason this description reads clearly to me even though the
previous one didn't. Once we sort out patch 1, I'll take these.

>
> In the same for, we replace the use of 'os.path.split' in the same go.
>
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -266,10 +266,16 @@ class abstractvfs(object):
>
>          The vfs base is not injected so that path stay relative. This exists
>          to allow handling of strange encoding if needed."""
>          return os.path.join(*paths)
>
> +    def split(self, path):
> +        """split top most element of a path (as os.path.split would do)
> +
> +        This exists to allow handling of strange encoding if needed."""
> +        return os.path.split(path)
> +
>      def lexists(self, path=None):
>          return os.path.lexists(self.join(path))
>
>      def lstat(self, path=None):
>          return os.lstat(self.join(path))
> diff --git a/mercurial/transaction.py b/mercurial/transaction.py
> --- a/mercurial/transaction.py
> +++ b/mercurial/transaction.py
> @@ -10,11 +10,10 @@
>  #
>  # This software may be used and distributed according to the terms of the
>  # GNU General Public License version 2 or any later version.
>
>  from i18n import _
> -import os
>  import errno
>  import error, util
>
>  version = 2
>
> @@ -196,13 +195,13 @@ class transaction(object):
>              msg = 'cannot use transaction.addbackup inside "group"'
>              raise RuntimeError(msg)
>
>          if file in self.map or file in self._backupmap:
>              return
> -        dirname, filename = os.path.split(file)
> +        vfs = self._vfsmap[location]
> +        dirname, filename = vfs.split(file)
>          backupfilename = "%s.backup.%s" % (self.journal, filename)
> -        vfs = self._vfsmap[location]
>          backupfile = vfs.reljoin(dirname, backupfilename)
>          if vfs.exists(file):
>              filepath = vfs.join(file)
>              backuppath = vfs.join(backupfile)
>              util.copyfiles(filepath, backuppath, hardlink=hardlink)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list