[PATCH 2 of 8] Add a method to dirstate to return case folding state

Adrian Buehlmann adrian at cadifra.com
Wed Apr 30 13:46:21 CDT 2008


Many thanks Paul! Some comments below:

On 30.04.2008 19:37, Paul Moore wrote:
> # HG changeset patch
> # User "Paul Moore <p.f.moore at gmail.com>"
> # Date 1209573926 -3600
> # Node ID 10e29dda3add46953b62a4b5ab01bdfe7de437ea
> # Parent  4c332d2df388086257be74380d53701631fd3a2e
> Add a method to dirstate to return case folding state

Any reason why you don't name that method? (more on this below)

> 
> This patch adds a method to the dirstate to check if the directory is on a
> casr folding filesystem. The result of the check is cached, so that it is
     ^
     typo

> computed only once per Mercurial invocation. It assumes that the whole
> dirstate is on the same filesystem (or at least that the case folding
> behaviour does not change across the whole dirstate).
> 
> diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> --- a/mercurial/dirstate.py
> +++ b/mercurial/dirstate.py
> @@ -66,11 +66,19 @@
>          elif name == '_checkexec':
>              self._checkexec = util.checkexec(self._root)
>              return self._checkexec
> +        elif name == '_casefold':
> +            self._casefold = not util.checkfolding(self._join('.hg'))
> +            return self._casefold
>          else:
>              raise AttributeError, name
>  
>      def _join(self, f):
>          return os.path.join(self._root, f)
> +
> +    def casefold(self):
> +        '''True if the working directory is on a filesystem that folds case.
> +        Assumed to be invariant over the whole working directory.'''
> +        return self._casefold

In my version of that patch (reposted below), I used the name "foldspaths" because
the folding a filesystem can do is more generic than just folding the *case*
of a path name (for example, I read somewhere that Mac OS X does some unicode
normalization folding, which for example has nothing to do with the case). So I fail to see
the point in trying to assert here to upper levels of the software that the filesystem
*only* folds _the case_ of a path.

What we do is, we detect that a file system folds paths (yes, we currently do that with
a case probe, but that's a low level detail). If we detect that, we use new util.fspath
to ask the filesystem for the target path of that folding when needed.
We do not care *what* that folding actually is in higher levels.

diff -r 626cb86a6523 mercurial/dirstate.py
--- a/mercurial/dirstate.py     Thu Apr 24 17:16:02 2008 +0200
+++ b/mercurial/dirstate.py     Sun Apr 27 21:56:28 2008 +0200
@@ -66,11 +66,19 @@
         elif name == '_checkexec':
             self._checkexec = util.checkexec(self._root)
             return self._checkexec
+        elif name == '_foldspaths':
+            self._foldspaths = not util.checkfolding(self._join('.hg'))
+            return self._foldspaths
         else:
             raise AttributeError, name

     def _join(self, f):
         return os.path.join(self._root, f)
+
+    def foldspaths(self):
+        '''True, if the working dir is on a file system that folds paths.
+        Assumed to be invariant and steady over the whole working dir.'''
+        return self._foldspaths

     def getcwd(self):
         cwd = os.getcwd()


More information about the Mercurial-devel mailing list