##// END OF EJS Templates
wireprotov2: implement commands as a generator of objects...
wireprotov2: implement commands as a generator of objects Previously, wire protocol version 2 inherited version 1's model of having separate types to represent the results of different wire protocol commands. As I implemented more powerful commands in future commits, I found I was using a common pattern of returning a special type to hold a generator. This meant the command function required a closure to do most of the work. That made logic flow more difficult to follow. I also noticed that many commands were effectively a sequence of objects to be CBOR encoded. I think it makes sense to define version 2 commands as generators. This way, commands can simply emit the data structures they wish to send to the client. This eliminates the need for a closure in command functions and removes encoding from the bodies of commands. As part of this commit, the handling of response objects has been moved into the serverreactor class. This puts the reactor in the driver's seat with regards to CBOR encoding and error handling. Having error handling in the function that emits frames is particularly important because exceptions in that function can lead to things getting in a bad state: I'm fairly certain that uncaught exceptions in the frame generator were causing deadlocks. I also introduced a dedicated error type for explicit error reporting in command handlers. This will be used in subsequent commits. There's still a bit of work to be done here, especially around formalizing the error handling "protocol." I've added yet another TODO to track this so we don't forget. Test output changed because we're using generators and no longer know we are at the end of the data until we hit the end of the generator. This means we can't emit the end-of-stream flag until we've exhausted the generator. Hence the introduction of 0-sized end-of-stream frames. Differential Revision: https://phab.mercurial-scm.org/D4472

File last commit:

r37386:cdccfe20 default
r39595:07b58266 default
Show More
autodiff.py
52 lines | 1.5 KiB | text/x-python | PythonLexer
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 # Extension dedicated to test patch.diff() upgrade modes
Gregory Szorc
tests/autodiff.py: use absolute_import
r27281
from __future__ import absolute_import
from mercurial import (
error,
patch,
Pulkit Goyal
py3: use pycompat.byteskwargs() in tests/autodiff.py...
r37386 pycompat,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
Gregory Szorc
tests/autodiff.py: use absolute_import
r27281 scmutil,
)
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189
Gregory Szorc
tests: declare commands using decorator
r21254 cmdtable = {}
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 command = registrar.command(cmdtable)
Gregory Szorc
tests: declare commands using decorator
r21254
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 @command(b'autodiff',
[(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')],
b'[OPTION]... [FILE]...')
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 def autodiff(ui, repo, *pats, **opts):
Pulkit Goyal
py3: use pycompat.byteskwargs() in tests/autodiff.py...
r37386 opts = pycompat.byteskwargs(opts)
Siddharth Agarwal
tests/autodiff.py: explicitly only honor feature diffopts...
r23692 diffopts = patch.difffeatureopts(ui, opts)
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 git = opts.get(b'git', b'no')
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 brokenfiles = set()
losedatafn = None
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 if git in (b'yes', b'no'):
diffopts.git = git == b'yes'
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 diffopts.upgrade = False
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 elif git == b'auto':
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 diffopts.git = False
diffopts.upgrade = True
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 elif git == b'warn':
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 diffopts.git = False
diffopts.upgrade = True
def losedatafn(fn=None, **kwargs):
brokenfiles.add(fn)
return True
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 elif git == b'abort':
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 diffopts.git = False
diffopts.upgrade = True
def losedatafn(fn=None, **kwargs):
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 raise error.Abort(b'losing data for %s' % fn)
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 else:
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 raise error.Abort(b'--git must be yes, no or auto')
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189
Martin von Zweigbergk
tests: use context-return revpair() in autodiff...
r37275 ctx1, ctx2 = scmutil.revpair(repo, [])
m = scmutil.match(ctx2, pats, opts)
it = patch.diff(repo, ctx1.node(), ctx2.node(), match=m, opts=diffopts,
Patrick Mezard
patch: support diff data loss detection and upgrade...
r10189 losedatafn=losedatafn)
for chunk in it:
ui.write(chunk)
for fn in sorted(brokenfiles):
Pulkit Goyal
tests: make autodiff.py work on Python 3...
r35599 ui.write((b'data lost for: %s\n' % fn))