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

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 4, 2017, 4:52 p.m.
Message ID <211188885b0000b034eb.1507135964@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/24508/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 4, 2017, 4:52 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@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.

Patch

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)