--- a/mercurial/store.py Sun Apr 17 01:44:09 2011 +0200
+++ b/mercurial/store.py Sun Apr 17 17:55:34 2011 +0200
@@ -14,6 +14,14 @@
# This avoids a collision between a file named foo and a dir named
# foo.i or foo.d
def encodedir(path):
+ '''
+ >>> encodedir('data/foo.i')
+ 'data/foo.i'
+ >>> encodedir('data/foo.i/bla.i')
+ 'data/foo.i.hg/bla.i'
+ >>> encodedir('data/foo.i.hg/bla.i')
+ 'data/foo.i.hg.hg/bla.i'
+ '''
if not path.startswith('data/'):
return path
return (path
@@ -22,6 +30,14 @@
.replace(".d/", ".d.hg/"))
def decodedir(path):
+ '''
+ >>> decodedir('data/foo.i')
+ 'data/foo.i'
+ >>> decodedir('data/foo.i.hg/bla.i')
+ 'data/foo.i/bla.i'
+ >>> decodedir('data/foo.i.hg.hg/bla.i')
+ 'data/foo.i.hg/bla.i'
+ '''
if not path.startswith('data/') or ".hg/" not in path:
return path
return (path
@@ -30,6 +46,29 @@
.replace(".hg.hg/", ".hg/"))
def _buildencodefun():
+ '''
+ >>> enc, dec = _buildencodefun()
+
+ >>> enc('nothing/special.txt')
+ 'nothing/special.txt'
+ >>> dec('nothing/special.txt')
+ 'nothing/special.txt'
+
+ >>> enc('HELLO')
+ '_h_e_l_l_o'
+ >>> dec('_h_e_l_l_o')
+ 'HELLO'
+
+ >>> enc('hello:world?')
+ 'hello~3aworld~3f'
+ >>> dec('hello~3aworld~3f')
+ 'hello:world?'
+
+ >>> enc('the\x07quick\xADshot')
+ 'the~07quick~adshot'
+ >>> dec('the~07quick~adshot')
+ 'the\\x07quick\\xadshot'
+ '''
e = '_'
win_reserved = [ord(x) for x in '\\:*?"<>|']
cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
@@ -58,6 +97,17 @@
encodefilename, decodefilename = _buildencodefun()
def _build_lower_encodefun():
+ '''
+ >>> f = _build_lower_encodefun()
+ >>> f('nothing/special.txt')
+ 'nothing/special.txt'
+ >>> f('HELLO')
+ 'hello'
+ >>> f('hello:world?')
+ 'hello~3aworld~3f'
+ >>> f('the\x07quick\xADshot')
+ 'the~07quick~adshot'
+ '''
win_reserved = [ord(x) for x in '\\:*?"<>|']
cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
for x in (range(32) + range(126, 256) + win_reserved):
@@ -72,6 +122,23 @@
com1 com2 com3 com4 com5 com6 com7 com8 com9
lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
def _auxencode(path, dotencode):
+ '''
+ Encodes filenames containing names reserved by Windows or which end in
+ period or space. Does not touch other single reserved characters c.
+ Specifically, c in '\\:*?"<>|' or ord(c) <= 31 are *not* encoded here.
+ Additionally encodes space or period at the beginning, if dotencode is
+ True.
+ path is assumed to be all lowercase.
+
+ >>> _auxencode('.foo/aux.txt/txt.aux/con/prn/nul/foo.', True)
+ '~2efoo/au~78.txt/txt.aux/co~6e/pr~6e/nu~6c/foo~2e'
+ >>> _auxencode('.com1com2/lpt9.lpt4.lpt1/conprn/foo.', False)
+ '.com1com2/lp~749.lpt4.lpt1/conprn/foo~2e'
+ >>> _auxencode('foo. ', True)
+ 'foo.~20'
+ >>> _auxencode(' .foo', True)
+ '~20.foo'
+ '''
res = []
for n in path.split('/'):
if n:
--- a/tests/test-doctest.py Sun Apr 17 01:44:09 2011 +0200
+++ b/tests/test-doctest.py Sun Apr 17 17:55:34 2011 +0200
@@ -13,6 +13,9 @@
import mercurial.match
doctest.testmod(mercurial.match)
+import mercurial.store
+doctest.testmod(mercurial.store)
+
import mercurial.url
doctest.testmod(mercurial.url)