Patchwork [2,of,2] vfs: add a 'split' method

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 15, 2014, 9:48 p.m.
Message ID <7f6ac2c061acbf204c1f.1418680137@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7122/
State Accepted
Commit 783b466fb2c332da52806e7aec3006daebb80482
Delegated to: Augie Fackler
Headers show

Comments

Pierre-Yves David - Dec. 15, 2014, 9:48 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

In the same for, we replace the use of 'os.path.split' in the same go.
Augie Fackler - Dec. 16, 2014, 3:56 p.m.
On Mon, Dec 15, 2014 at 01:48:57PM -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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)