[PATCH 07 of 10] store: let _auxencode() return the list of path segments

Adrian Buehlmann adrian at cadifra.com
Sat Sep 15 16:01:48 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1347738185 -7200
# Node ID 81a033bb29bcf70f217445984767a4886148df8f
# Parent  fb8658ad9e8df3613e1c96cdfc478de0c1c7d1d7
store: let _auxencode() return the list of path segments

so we can spare us splitting the path again in _hybridencode()

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -133,13 +133,13 @@
     doesn't need encoding.
 
     >>> _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'
+    ['~2efoo', 'au~78.txt', 'txt.aux', 'co~6e', 'pr~6e', 'nu~6c', 'foo~2e']
     >>> _auxencode('.com1com2/lpt9.lpt4.lpt1/conprn/com0/lpt0/foo.', False)
-    '.com1com2/lp~749.lpt4.lpt1/conprn/com0/lpt0/foo~2e'
+    ['.com1com2', 'lp~749.lpt4.lpt1', 'conprn', 'com0', 'lpt0', 'foo~2e']
     >>> _auxencode('foo. ', True)
-    'foo.~20'
+    ['foo.~20']
     >>> _auxencode(' .foo', True)
-    '~20.foo'
+    ['~20.foo']
     '''
     res = path.split('/')
     for i, n in enumerate(res):
@@ -162,7 +162,7 @@
         if n[-1] in '. ':
             # encode last period or space ('foo...' -> 'foo..~2e')
             res[i] = n[:-1] + "~%02x" % ord(n[-1])
-    return '/'.join(res)
+    return res
 
 _maxstorepathlen = 120
 _dirprefixlen = 8
@@ -203,12 +203,11 @@
     # escape directories ending with .i and .d
     path = encodedir(path)
     ndpath = path[len('data/'):]
-    res = 'data/' + auxencode(encodefilename(ndpath))
+    res = 'data/' + '/'.join(auxencode(encodefilename(ndpath)))
     if len(res) > _maxstorepathlen:
         digest = _sha(path).hexdigest()
-        aep = auxencode(lowerencode(ndpath))
-        _root, ext = os.path.splitext(aep)
-        parts = aep.split('/')
+        parts = auxencode(lowerencode(ndpath))
+        _root, ext = os.path.splitext(parts[-1])
         basename = parts[-1]
         sdirs = []
         for p in parts[:-1]:


More information about the Mercurial-devel mailing list