# HG changeset patch # User Pierre-Yves David # Date 2015-09-23 21:00:16 # Node ID 4e7b0bf9f0b1a2e12930e5e542ac5a7d84823bc2 # Parent e75da738add5e02386834f220c214c695a626d1a unbundle20: allow registering handlers for stream level parameters As a comment in the code have been asking for, it is now possible to register piece of code that handle parameters for the stream. I've been wondering is such function should be class methods or not. I eventually went for externally decorated methods to stick with the culture of extensibility from an extensions that apply to bundle2. diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -661,13 +661,15 @@ class unbundle20(unpackermixin): raise ValueError('empty parameter name') if name[0] not in string.letters: raise ValueError('non letter first character: %r' % name) - # Some logic will be later added here to try to process the option for - # a dict of known parameter. - if name[0].islower(): - indebug(self.ui, "ignoring unknown parameter %r" % name) + try: + handler = b2streamparamsmap[name.lower()] + except KeyError: + if name[0].islower(): + indebug(self.ui, "ignoring unknown parameter %r" % name) + else: + raise error.BundleUnknownFeatureError(params=(name,)) else: - raise error.BundleUnknownFeatureError(params=(name,)) - + handler(self, name, value) def iterparts(self): """yield all parts contained in the stream""" @@ -700,6 +702,16 @@ class unbundle20(unpackermixin): formatmap = {'20': unbundle20} +b2streamparamsmap = {} + +def b2streamparamhandler(name): + """register a handler for a stream level parameter""" + def decorator(func): + assert name not in formatmap + b2streamparamsmap[name] = func + return func + return decorator + class bundlepart(object): """A bundle2 part contains application level payload