diff options
Diffstat (limited to 'mercurial/wireproto.py')
-rw-r--r-- | mercurial/wireproto.py | 69 |
1 files changed, 26 insertions, 43 deletions
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py index 2b44fd6..51268fa 100644 --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -9,24 +9,24 @@ import urllib, tempfile, os, sys from i18n import _ from node import bin, hex import changegroup as changegroupmod -import peer, error, encoding, util, store -import discovery, phases +import repo, error, encoding, util, store +import pushkey as pushkeymod # abstract batching support class future(object): '''placeholder for a value to be set later''' def set(self, value): - if util.safehasattr(self, 'value'): + if hasattr(self, 'value'): raise error.RepoError("future is already set") self.value = value class batcher(object): '''base class for batches of commands submittable in a single request - All methods invoked on instances of this class are simply queued and - return a a future for the result. Once you call submit(), all the queued - calls are performed and the results set in their respective futures. + All methods invoked on instances of this class are simply queued and return a + a future for the result. Once you call submit(), all the queued calls are + performed and the results set in their respective futures. ''' def __init__(self): self.calls = [] @@ -51,17 +51,15 @@ class localbatch(batcher): class remotebatch(batcher): '''batches the queued calls; uses as few roundtrips as possible''' def __init__(self, remote): - '''remote must support _submitbatch(encbatch) and - _submitone(op, encargs)''' + '''remote must support _submitbatch(encbatch) and _submitone(op, encargs)''' batcher.__init__(self) self.remote = remote def submit(self): req, rsp = [], [] for name, args, opts, resref in self.calls: mtd = getattr(self.remote, name) - batchablefn = getattr(mtd, 'batchable', None) - if batchablefn is not None: - batchable = batchablefn(mtd.im_self, *args, **opts) + if hasattr(mtd, 'batchable'): + batchable = getattr(mtd, 'batchable')(mtd.im_self, *args, **opts) encargsorres, encresref = batchable.next() if encresref: req.append((name, encargsorres,)) @@ -98,14 +96,14 @@ def batchable(f): encresref = future() # Return encoded arguments and future: yield encargs, encresref - # Assuming the future to be filled with the result from the batched - # request now. Decode it: + # Assuming the future to be filled with the result from the batched request + # now. Decode it: yield decode(encresref.value) - The decorator returns a function which wraps this coroutine as a plain - method, but adds the original method as an attribute called "batchable", - which is used by remotebatch to split the call into separate encoding and - decoding phases. + The decorator returns a function which wraps this coroutine as a plain method, + but adds the original method as an attribute called "batchable", which is + used by remotebatch to split the call into separate encoding and decoding + phases. ''' def plain(*args, **opts): batchable = f(*args, **opts) @@ -149,7 +147,7 @@ def unescapearg(escaped): def todict(**args): return args -class wirepeer(peer.peerrepository): +class wirerepository(repo.repository): def batch(self): return remotebatch(self) @@ -236,20 +234,16 @@ class wirepeer(peer.peerrepository): if not self.capable('pushkey'): yield False, None f = future() - self.ui.debug('preparing pushkey for "%s:%s"\n' % (namespace, key)) yield todict(namespace=encoding.fromlocal(namespace), key=encoding.fromlocal(key), old=encoding.fromlocal(old), new=encoding.fromlocal(new)), f d = f.value - d, output = d.split('\n', 1) try: d = bool(int(d)) except ValueError: raise error.ResponseError( _('push failed (unexpected response):'), d) - for l in output.splitlines(True): - self.ui.status(_('remote: '), l) yield d @batchable @@ -257,7 +251,6 @@ class wirepeer(peer.peerrepository): if not self.capable('pushkey'): yield {}, None f = future() - self.ui.debug('preparing listkeys for "%s"\n' % namespace) yield todict(namespace=encoding.fromlocal(namespace)), f d = f.value r = {} @@ -341,10 +334,6 @@ class pusherr(object): def __init__(self, res): self.res = res -class ooberror(object): - def __init__(self, message): - self.message = message - def dispatch(repo, proto, command): func, spec = commands[command] args = proto.getargs(spec) @@ -386,8 +375,6 @@ def batch(repo, proto, cmds, others): result = func(repo, proto, *[data[k] for k in keys]) else: result = func(repo, proto) - if isinstance(result, ooberror): - return result res.append(escapearg(result)) return ';'.join(res) @@ -399,7 +386,7 @@ def between(repo, proto, pairs): return "".join(r) def branchmap(repo, proto): - branchmap = discovery.visiblebranchmap(repo) + branchmap = repo.branchmap() heads = [] for branch, nodes in branchmap.iteritems(): branchname = urllib.quote(encoding.fromlocal(branch)) @@ -418,8 +405,6 @@ def capabilities(repo, proto): caps = ('lookup changegroupsubset branchmap pushkey known getbundle ' 'unbundlehash batch').split() if _allowstream(repo.ui): - if repo.ui.configbool('server', 'preferuncompressed', False): - caps.append('stream-preferred') requiredformats = repo.requirements & repo.supportedformats # if our local revlogs are just revlogv1, add 'stream' cap if not requiredformats - set(('revlogv1',)): @@ -455,7 +440,7 @@ def getbundle(repo, proto, others): return streamres(proto.groupchunks(cg)) def heads(repo, proto): - h = discovery.visibleheads(repo) + h = repo.heads() return encodelist(h) + "\n" def hello(repo, proto): @@ -469,18 +454,14 @@ def hello(repo, proto): return "capabilities: %s\n" % (capabilities(repo, proto)) def listkeys(repo, proto, namespace): - d = repo.listkeys(encoding.tolocal(namespace)).items() + d = pushkeymod.list(repo, encoding.tolocal(namespace)).items() t = '\n'.join(['%s\t%s' % (encoding.fromlocal(k), encoding.fromlocal(v)) for k, v in d]) return t def lookup(repo, proto, key): try: - k = encoding.tolocal(key) - c = repo[k] - if c.phase() == phases.secret: - raise error.RepoLookupError(_("unknown revision '%s'") % k) - r = c.hex() + r = hex(repo.lookup(encoding.tolocal(key))) success = 1 except Exception, inst: r = str(inst) @@ -503,8 +484,9 @@ def pushkey(repo, proto, namespace, key, old, new): else: new = encoding.tolocal(new) # normal path - r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), - encoding.tolocal(old), new) + r = pushkeymod.push(repo, + encoding.tolocal(namespace), encoding.tolocal(key), + encoding.tolocal(old), new) return '%s\n' % int(r) def _allowstream(ui): @@ -558,7 +540,7 @@ def unbundle(repo, proto, heads): their_heads = decodelist(heads) def check_heads(): - heads = discovery.visibleheads(repo) + heads = repo.heads() heads_hash = util.sha1(''.join(sorted(heads))).digest() return (their_heads == ['force'] or their_heads == heads or their_heads == ['hashed', heads_hash]) @@ -587,7 +569,8 @@ def unbundle(repo, proto, heads): gen = changegroupmod.readbundle(fp, None) try: - r = repo.addchangegroup(gen, 'serve', proto._client()) + r = repo.addchangegroup(gen, 'serve', proto._client(), + lock=lock) except util.Abort, inst: sys.stderr.write("abort: %s\n" % inst) finally: |