[PATCH 2 of 3] scmutil: factor out building of transaction summary callback

Denis Laxalde denis at laxalde.org
Wed Oct 4 12:52:44 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1507135749 -7200
#      Wed Oct 04 18:49:09 2017 +0200
# Node ID 211188885b0000b034eb168806d485b3b28c3112
# Parent  9fdbf99392971dc9ed2c711718c919397eedcf39
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 211188885b00
# EXP-Topic pull-info-transaction
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.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1131,13 +1131,23 @@ def registersummarycallback(repo, otr, t
     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)


More information about the Mercurial-devel mailing list