# HG changeset patch # User FUJIWARA Katsunori # Date 2011-12-16 12:21:08 # Node ID c51c9dc13a586926a1398f51e65a26167a033688 # Parent f63e4004737202dd6757c8395dab00813b73885d cygwin: add cygwin specific normcase logic in cygwin environment, mount point part of path is treated as case sensitive, even though underlying NTFS is case insensitive. this patch preserves mount point part of specified path, only if it is absolute one. there is no easy way to get list of current mount points from python program, other than to execute "mount" external command, because cygwin does not store current mount points into Unix/Linux like /etc/XXXtab file. so, this patch introduces cygwinmountpoints variable to list mount points to be preserved case. this allows some other extensions to customize mount point configuration. diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -238,6 +238,38 @@ else: # Fallback to the likely inadequate Python builtin function. realpath = os.path.realpath +if sys.platform == 'cygwin': + # workaround for cygwin, in which mount point part of path is + # treated as case sensitive, even though underlying NTFS is case + # insensitive. + + # default mount points + cygwinmountpoints = sorted([ + "/usr/bin", + "/usr/lib", + "/cygdrive", + ], reverse=True) + + # use upper-ing as normcase as same as NTFS workaround + def normcase(path): + pathlen = len(path) + if (pathlen == 0) or (path[0] != os.sep): + # treat as relative + return encodingupper(path) + + # to preserve case of mountpoint part + for mp in cygwinmountpoints: + if not path.startswith(mp): + continue + + mplen = len(mp) + if mplen == pathlen: # mount point itself + return mp + if path[mplen] == os.sep: + return mp + encodingupper(path[mplen:]) + + return encodingupper(path) + def shellquote(s): if os.sys.platform == 'OpenVMS': return '"%s"' % s