[PATCH] V13 of experiment for a simpler path encoding for hashed paths (for "fncache2")

Adrian Buehlmann adrian at cadifra.com
Sat Sep 29 18:25:50 CDT 2012


On 2012-09-30 00:30, Adrian Buehlmann wrote:
> cutdirs in Python
> 
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -185,6 +185,41 @@
>  _dirprefixlen = 8
>  _maxshortdirslen = 8 * (_dirprefixlen + 1) - 4
> 
> +_encchar = ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
> +            "~!~#$%&'()~+,-~~0123456789~;~=~~"
> +            "@abcdefghijklmnopqrstuvwxyz[~]^_"
> +            "`abcdefghijklmnopqrstuvwxyz{~}~~"
> +            "~abcdefghijklmnopqrstuvwxyz{~}~~"
> +            "~!~#$%&'()~+,-~~0123456789~;~=~~"
> +            "@abcdefghijklmnopqrstuvwxyz[~]^_"
> +            "`abcdefghijklmnopqrstuvwxyz{~}~~")
> +
> +def _foldencode(f): # preserves size
> +    f = ''.join([_encchar[ord(c)] for c in f])
> +    l = len(f)
> +    if l == 3 and f[:3] in _winres3:
                      ^^^^
                      unneeded

       if l == 3 and f in _winres3:

> +        f = f[:2] + '~'
> +    if (l == 4 and f[3] <= '9' and f[3] >= '0'
> +               and f[:3] in _winres4):
> +        f = f[:3] + '~'
> +    return f
> +
> +def cutdirs(path):
> +    parts = []
> +    totallen = 0
> +    for s in path.split('/'):
> +        if len(s) > 8:
> +            s = s[:8]
> +        if totallen:
> +            newlen = totallen + 1 + len(s)
> +        else:
> +            newlen = len(s)
> +        if newlen > _maxstorepathlen - 40:
> +            break
> +        parts.append(s)
> +        totallen = newlen
> +    return '/'.join(map(_foldencode, parts))

def cutdirs(path):
    spaceleft = _maxstorepathlen - 40;
    parts = []
    for s in path.split('/'):
        if len(s) > 8:
            s = s[:8]
        if parts:
            spaceleft -= 1 # for '/'
        spaceleft -= len(s)
        if spaceleft < 0:
            break
        parts.append(s)
    return '/'.join(map(_foldencode, parts))


More information about the Mercurial-devel mailing list