[PATCH 3 of 3] Add a normalize() method to dirstate

Paul Moore p.f.moore at gmail.com
Thu May 22 15:20:25 CDT 2008


2008/5/21 Matt Mackall <mpm at selenic.com>:
>
> On Wed, 2008-05-21 at 22:49 +0100, Paul Moore wrote:
>> +    def normalize(self, path):
>> +        if not self._folding or path in self._map:
>> +            return path
>> +        elif path in self._folded:
>> +            return self._folded[path]
>> +        elif os.path.exists(path):
>> +            return self._folded.setdefault(path, util.fspath(path, self._root))
>
> What if another variant of path is in self._map?

But I thought that self._map was the actual dirstate contents, and
hence case sensitive? So given a pathname, we normalize it by
returning it unchanged if we're on a case sensitive filesystem, or if
the case matches the dirstate (regardless of the filesystem). It's
only if the path as given isn't in the dirstate, *and* it exists in
the filesystem, that we need to return the form actually stored in the
filesystem.

> I think what's needed rather than _folding or _folded is something like:

Well, _folding tells us if we're on a case-insensitive system where we
don't need any of this - so it's an optimization shortcut, and _folded
is simply a cache of the results, so again it's for optimization.

Having said that, _folded can probably be keyed on
os.path.normcase(os.path.normpath(path)) rather than just on path, so
that we hit the cache in more cases.

(I hope I explained that right - I basically lifted the normalize
function from a message of yours,
http://www.selenic.com/pipermail/mercurial-devel/2008-May/006106.html
. Before you suggested it, I was just using fspath directly, and
ignoring _map).

Paul.


More information about the Mercurial-devel mailing list