comparison mercurial/posix.py @ 15563:b61fa7481a68 stable

posix: fix HFS+ percent-encoding folding We use 'ignore' rather than 'replace' so we don't have to deal with u+FFFD in UTF-8 round-trip.
author Matt Mackall <mpm@selenic.com>
date Wed, 23 Nov 2011 14:22:37 -0800
parents 1fa41d1f1351
children 2ebe3d0ce91d
comparison
equal deleted inserted replaced
15554:0c0ed2b3082d 15563:b61fa7481a68
174 def normcase(path): 174 def normcase(path):
175 try: 175 try:
176 u = path.decode('utf-8') 176 u = path.decode('utf-8')
177 except UnicodeDecodeError: 177 except UnicodeDecodeError:
178 # percent-encode any characters that don't round-trip 178 # percent-encode any characters that don't round-trip
179 p2 = path.decode('utf-8', 'replace').encode('utf-8') 179 p2 = path.decode('utf-8', 'ignore').encode('utf-8')
180 s = "" 180 s = ""
181 for a, b in zip(path, p2): 181 pos = 0
182 if a != b: 182 for c in path:
183 s += "%%%02X" % ord(a) 183 if p2[pos:pos + 1] == c:
184 s += c
185 pos += 1
184 else: 186 else:
185 s += a 187 s += "%%%02X" % ord(c)
186 u = s.decode('utf-8') 188 u = s.decode('utf-8')
187 189
188 # Decompose then lowercase (HFS+ technote specifies lower) 190 # Decompose then lowercase (HFS+ technote specifies lower)
189 return unicodedata.normalize('NFD', u).lower().encode('utf-8') 191 return unicodedata.normalize('NFD', u).lower().encode('utf-8')
190 192