scmutil: factor out building of transaction summary callback
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 04 Oct 2017 18:49:09 +0200
changeset 34620 b799f11644d8
parent 34619 18309380fb88
child 34621 5613fb1583d6
scmutil: factor out building of transaction summary callback In registersummarycallback(), we extra generic bits of the existing "reportsummary" function into a decorator which will be used in forthcoming changesets to add new summary callbacks.
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sun Oct 01 09:52:44 2017 +0200
+++ b/mercurial/scmutil.py	Wed Oct 04 18:49:09 2017 +0200
@@ -1206,13 +1206,23 @@
     def txmatch(sources):
         return any(txnname.startswith(source) for source in sources)
 
-    if txmatch(_reportobsoletedsource):
+    categories = []
+
+    def reportsummary(func):
+        """decorator for report callbacks."""
         reporef = weakref.ref(repo)
-        def reportsummary(tr):
-            """the actual callback reporting the summary"""
+        def wrapped(tr):
             repo = reporef()
+            func(repo, tr)
+        newcat = '%2i-txnreport' % len(categories)
+        otr.addpostclose(newcat, wrapped)
+        categories.append(newcat)
+        return wrapped
+
+    if txmatch(_reportobsoletedsource):
+        @reportsummary
+        def reportobsoleted(repo, tr):
             obsoleted = obsutil.getobsoleted(repo, tr)
             if obsoleted:
                 repo.ui.status(_('obsoleted %i changesets\n')
                                % len(obsoleted))
-        otr.addpostclose('00-txnreport', reportsummary)