[PATCH 10 of 11] util: extend fspath, search for the file among all files in directory

Simon Heimberg simohe at besonet.ch
Fri Aug 7 14:43:08 CDT 2009


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1249671996 -7200
# Node ID f2d55e3789c6b5be6d28e0fea7d2a9f8e7e87e50
# Parent  7111ac2bf7c978859746e3ab4f2f92c7d9b8fae7
util: extend fspath, search for the file among all files in directory

for finding folded paths. Examples:
- 'Ä' ('A\xcc\x88') for Ä ('\xc3\x84', A umlaut) on hfs
- 'A' for 'A.' on ntfs

tested on linux with vfat

diff -r 7111ac2bf7c9 -r f2d55e3789c6 mercurial/util.py
--- a/mercurial/util.py	Mit Jul 29 14:44:05 2009 +0200
+++ b/mercurial/util.py	Fre Aug 07 21:06:36 2009 +0200
@@ -687,8 +687,19 @@
                 result.append(n)
                 break
         else:
-            # Cannot happen, as the file exists!
-            result.append(part)
+            # happens on some filesystems (hfs, ntfs)
+            if not hasattr(os.path, 'samestat'):
+                result.append(part)
+            else:
+                st = os.stat(os.path.join(dir,part))
+                for n in contents:
+                    st2 = os.stat(os.path.join(dir, n))
+                    if st == st2:
+                        result.append(n)
+                        break
+                else:
+                    #should not happen, file existed
+                    result.append(part)
         dir = os.path.join(dir, lpart)
 
     return ''.join(result)



More information about the Mercurial-devel mailing list