diff --git a/mercurial/store.py b/mercurial/store.py --- a/mercurial/store.py +++ b/mercurial/store.py @@ -57,6 +57,23 @@ def decodedir(path): .replace(".i.hg/", ".i/") .replace(".hg.hg/", ".hg/")) +def _reserved(): + ''' characters that are problematic for filesystems + + * ascii escapes (0..31) + * ascii hi (126..255) + * windows specials + + these characters will be escaped by encodefunctions + ''' + winreserved = [ord(x) for x in '\\:*?"<>|'] + for x in range(32): + yield x + for x in range(126, 256): + yield x + for x in winreserved: + yield x + def _buildencodefun(): ''' >>> enc, dec = _buildencodefun() @@ -82,11 +99,10 @@ def _buildencodefun(): 'the\\x07quick\\xadshot' ''' e = '_' - winreserved = [ord(x) for x in '\\:*?"<>|'] cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) - for x in (range(32) + range(126, 256) + winreserved): + for x in _reserved(): cmap[chr(x)] = "~%02x" % x - for x in range(ord("A"), ord("Z") + 1) + [ord(e)]: + for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]: cmap[chr(x)] = e + chr(x).lower() dmap = {} for k, v in cmap.iteritems(): @@ -134,9 +150,8 @@ def _buildlowerencodefun(): >>> f('the\x07quick\xADshot') 'the~07quick~adshot' ''' - winreserved = [ord(x) for x in '\\:*?"<>|'] cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) - for x in (range(32) + range(126, 256) + winreserved): + for x in _reserved(): cmap[chr(x)] = "~%02x" % x for x in range(ord("A"), ord("Z") + 1): cmap[chr(x)] = chr(x).lower()