Mercurial > public > mercurial-scm > hg
comparison mercurial/posix.py @ 15711:c51c9dc13a58
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.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 16 Dec 2011 21:21:08 +0900 |
parents | 2ebe3d0ce91d |
children | a814f8fcc65a |
comparison
equal
deleted
inserted
replaced
15710:f63e40047372 | 15711:c51c9dc13a58 |
---|---|
236 return os.path.realpath('./' + path) | 236 return os.path.realpath('./' + path) |
237 else: | 237 else: |
238 # Fallback to the likely inadequate Python builtin function. | 238 # Fallback to the likely inadequate Python builtin function. |
239 realpath = os.path.realpath | 239 realpath = os.path.realpath |
240 | 240 |
241 if sys.platform == 'cygwin': | |
242 # workaround for cygwin, in which mount point part of path is | |
243 # treated as case sensitive, even though underlying NTFS is case | |
244 # insensitive. | |
245 | |
246 # default mount points | |
247 cygwinmountpoints = sorted([ | |
248 "/usr/bin", | |
249 "/usr/lib", | |
250 "/cygdrive", | |
251 ], reverse=True) | |
252 | |
253 # use upper-ing as normcase as same as NTFS workaround | |
254 def normcase(path): | |
255 pathlen = len(path) | |
256 if (pathlen == 0) or (path[0] != os.sep): | |
257 # treat as relative | |
258 return encodingupper(path) | |
259 | |
260 # to preserve case of mountpoint part | |
261 for mp in cygwinmountpoints: | |
262 if not path.startswith(mp): | |
263 continue | |
264 | |
265 mplen = len(mp) | |
266 if mplen == pathlen: # mount point itself | |
267 return mp | |
268 if path[mplen] == os.sep: | |
269 return mp + encodingupper(path[mplen:]) | |
270 | |
271 return encodingupper(path) | |
272 | |
241 def shellquote(s): | 273 def shellquote(s): |
242 if os.sys.platform == 'OpenVMS': | 274 if os.sys.platform == 'OpenVMS': |
243 return '"%s"' % s | 275 return '"%s"' % s |
244 else: | 276 else: |
245 return "'%s'" % s.replace("'", "'\\''") | 277 return "'%s'" % s.replace("'", "'\\''") |