# HG changeset patch
# User Paul Moore
# Date 1212776609 -3600
# Node ID 9865e15febd05e844470174b49496137b344d4e4
# Parent 33045179d079860a21fd86d34560bd6c4e9c06a9
Add a normalize() method to dirstate
This method returns the normalised form of a path. This is
- the form in the dirstate, if available, or
- the form on disk, if available, or
- the form passed on the command line
normalize() is called on the type-'f' result of statwalk.
This fixes issues 910 and 1092
diff -r 33045179d079 -r 9865e15febd0 mercurial/dirstate.py
--- a/mercurial/dirstate.py Fri Jun 06 19:23:23 2008 +0100
+++ b/mercurial/dirstate.py Fri Jun 06 19:23:29 2008 +0100
@@ -31,6 +31,13 @@
elif name == '_copymap':
self._read()
return self._copymap
+ elif name == '_foldmap':
+ _foldmap = {}
+ for name in self._map:
+ norm = os.path.normcase(os.path.normpath(name))
+ _foldmap[norm] = name
+ self._foldmap = _foldmap
+ return self._foldmap
elif name == '_branch':
try:
self._branch = (self._opener("branch").read().strip()
@@ -69,6 +76,12 @@
elif name == '_folding':
self._folding = not util.checkfolding(self._join('.hg'))
return self._folding
+ elif name == 'normalize':
+ if self._folding:
+ self.normalize = self._normalize
+ else:
+ self.normalize = lambda x: x
+ return self.normalize
else:
raise AttributeError, name
@@ -167,7 +180,7 @@
dmap[f] = e # we hold onto e[4] because making a subtuple is slow
def invalidate(self):
- for a in "_map _copymap _branch _pl _dirs _ignore".split():
+ for a in "_map _copymap _foldmap _branch _pl _dirs _ignore".split():
if a in self.__dict__:
delattr(self, a)
self._dirty = False
@@ -320,6 +333,16 @@
except KeyError:
self._ui.warn(_("not in dirstate: %s\n") % f)
+ def _normalize(self, path):
+ normpath = os.path.normcase(os.path.normpath(path))
+ if normpath in self._foldmap:
+ return self._foldmap[normpath]
+ elif os.path.exists(path):
+ self._foldmap[normpath] = util.fspath(path, self._root)
+ return self._foldmap[normpath]
+ else:
+ return path
+
def clear(self):
self._map = {}
if "_dirs" in self.__dict__:
@@ -561,7 +584,7 @@
known[nf] = 1
if match(nf):
if supported(ff, st.st_mode, verbose=True):
- yield 'f', nf, st
+ yield 'f', self.normalize(nf), st
elif ff in dc:
yield 'm', nf, st