mercurial/bundle2.py
changeset 20890 ec7fc110faee
parent 20889 deed5edb72de
child 20891 1c6cd23fc221
--- a/mercurial/bundle2.py	Mon Mar 24 12:25:33 2014 -0700
+++ b/mercurial/bundle2.py	Mon Mar 24 15:51:00 2014 -0700
@@ -148,8 +148,23 @@
     """
     return '>'+('BB'*nbparams)
 
+parthandlermapping = {}
 
-parthandlermapping = {}
+def parthandler(parttype):
+    """decorator that register a function as a bundle2 part handler
+
+    eg::
+
+        @parthandler('myparttype')
+        def myparttypehandler(...):
+            '''process a part of type "my part".'''
+            ...
+    """
+    def _decorator(func):
+        assert parttype not in parthandlermapping
+        parthandlermapping[parttype] = func
+        return func
+    return _decorator
 
 def processbundle(repo, stream):
     """This function process a bundle, apply effect to/from a repo