mercurial/pushkey.py
author Augie Fackler <augie@google.com>
Fri, 06 Mar 2015 21:29:47 -0500
changeset 24226 b992769dd1be
parent 22953 b1d694d3975e
child 25969 7b200566e474
permissions -rw-r--r--
manifest: use custom C implementation of lazymanifest This version is actually lazy, unlike the pure-python version. The latter could stand to be optimized if anyone actually wants to use it seriously. I put no work into it. Before any of my related changes on mozilla-central: perfmanifest tip ! wall 0.268805 comb 0.260000 user 0.260000 sys 0.000000 (best of 37) perftags ! result: 162 ! wall 0.007099 comb 0.000000 user 0.000000 sys 0.000000 (best of 401) perfstatus ! wall 0.415680 comb 0.420000 user 0.260000 sys 0.160000 (best of 24) hgperf export tip ! wall 0.142118 comb 0.140000 user 0.140000 sys 0.000000 (best of 67) after all of my changes on mozilla-central: ./hg: perfmanifest tip ! wall 0.232640 comb 0.230000 user 0.220000 sys 0.010000 (best of 43) perftags ! result: 162 ! wall 0.007057 comb 0.010000 user 0.000000 sys 0.010000 (best of 395) perfstatus ! wall 0.415503 comb 0.420000 user 0.280000 sys 0.140000 (best of 24) hgperf export tip ! wall 0.025096 comb 0.030000 user 0.030000 sys 0.000000 (best of 102) so it's no real change in performance on perf{manifest,tags,status}, but is a huge win on 'hgperf export tip'. There's a little performance work that could still be done here: fastdelta() could be done significantly more intelligently by using the internal state of the lazymanifest type in C, but that seems like good future work.

# pushkey.py - dispatching for pushing and pulling keys
#
# Copyright 2010 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

import bookmarks, phases, obsolete, encoding

def _nslist(repo):
    n = {}
    for k in _namespaces:
        n[k] = ""
    if not obsolete.isenabled(repo, obsolete.exchangeopt):
        n.pop('obsolete')
    return n

_namespaces = {"namespaces": (lambda *x: False, _nslist),
               "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks),
               "phases": (phases.pushphase, phases.listphases),
               "obsolete": (obsolete.pushmarker, obsolete.listmarkers),
              }

def register(namespace, pushkey, listkeys):
    _namespaces[namespace] = (pushkey, listkeys)

def _get(namespace):
    return _namespaces.get(namespace, (lambda *x: False, lambda *x: {}))

def push(repo, namespace, key, old, new):
    '''should succeed iff value was old'''
    pk = _get(namespace)[0]
    return pk(repo, key, old, new)

def list(repo, namespace):
    '''return a dict'''
    lk = _get(namespace)[1]
    return lk(repo)

encode = encoding.fromlocal

decode = encoding.tolocal

def encodekeys(keys):
    """encode the content of a pushkey namespace for exchange over the wire"""
    return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys])

def decodekeys(data):
    """decode the content of a pushkey namespace from exchange over the wire"""
    result = {}
    for l in data.splitlines():
        k, v = l.split('\t')
        result[decode(k)] = decode(v)
    return result