[PATCH 8 of 8] Fix for issue 593 (It's possible to introduce case collisions on Windows)

Paul Moore p.f.moore at gmail.com
Wed Apr 30 12:37:30 CDT 2008


# HG changeset patch
# User "Paul Moore <p.f.moore at gmail.com>"
# Date 1209573991 -3600
# Node ID 9dda5c21ed62143d99edd699b016a6ee2bf071eb
# Parent  59147a0139586cfb4780e284122b712c67b4fd88
Fix for issue 593 (It's possible to introduce case collisions on Windows)

Fixed by using the fspath value returned from cmdutil.walk to check against
the exact case stored in the filesystem. Also correct an issue where lexists
on a case insensitive filesystem reports that file a exists when the name
stored is actually A.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -276,12 +276,19 @@
     mapping = {}
     for src, abs, fsabs, rel, exact in walk(repo, pats, opts):
         target = repo.wjoin(abs)
-        if src == 'f' and abs not in repo.dirstate:
-            add.append(abs)
-            mapping[abs] = rel, exact
+        if src == 'f' and fsabs not in repo.dirstate:
+            add.append(fsabs)
+            mapping[fsabs] = rel, exact
             if repo.ui.verbose or not exact:
-                repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
-        if repo.dirstate[abs] != 'r' and (not util.lexists(target)
+                repo.ui.status(_('adding %s\n') % ((pats and rel) or fsabs))
+
+        # The check below uses util.lexists to check for the existence of the
+	# file in the filesystem. On case-folding systems, this may report
+	# that the file exists when in fact it has a different case.
+        # To trap this, we check if fspath returns the same name as we are
+        # checking (if not, there's a case difference)
+        if repo.dirstate[abs] != 'r' and (not (util.lexists(target) and
+            util.fspath(abs, root=repo.root) == abs)
             or (os.path.isdir(target) and not os.path.islink(target))):
             remove.append(abs)
             mapping[abs] = rel, exact


More information about the Mercurial-devel mailing list