scmutil: factor out transaction name lookup in registersummarycallback()
authorDenis Laxalde <denis.laxalde@logilab.fr>
Sun, 01 Oct 2017 09:52:44 +0200
changeset 34619 18309380fb88
parent 34618 37b4375b1221
child 34620 b799f11644d8
scmutil: factor out transaction name lookup in registersummarycallback() Add an inner txmatch function in registersummarycallback() factoring out the logic to determine if the transaction matches a particular sources set. We'll reuse this function to add some new report logic in the new changeset.
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Wed Oct 11 05:23:45 2017 +0200
+++ b/mercurial/scmutil.py	Sun Oct 01 09:52:44 2017 +0200
@@ -1203,15 +1203,16 @@
 def registersummarycallback(repo, otr, txnname=''):
     """register a callback to issue a summary after the transaction is closed
     """
-    for source in _reportobsoletedsource:
-        if txnname.startswith(source):
-            reporef = weakref.ref(repo)
-            def reportsummary(tr):
-                """the actual callback reporting the summary"""
-                repo = reporef()
-                obsoleted = obsutil.getobsoleted(repo, tr)
-                if obsoleted:
-                    repo.ui.status(_('obsoleted %i changesets\n')
-                                   % len(obsoleted))
-            otr.addpostclose('00-txnreport', reportsummary)
-            break
+    def txmatch(sources):
+        return any(txnname.startswith(source) for source in sources)
+
+    if txmatch(_reportobsoletedsource):
+        reporef = weakref.ref(repo)
+        def reportsummary(tr):
+            """the actual callback reporting the summary"""
+            repo = reporef()
+            obsoleted = obsutil.getobsoleted(repo, tr)
+            if obsoleted:
+                repo.ui.status(_('obsoleted %i changesets\n')
+                               % len(obsoleted))
+        otr.addpostclose('00-txnreport', reportsummary)