Patchwork [1,of,3] scmutil: factor out transaction name lookup in registersummarycallback()

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 4, 2017, 4:52 p.m.
Message ID <9fdbf99392971dc9ed2c.1507135963@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/24509/
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 1506844364 -7200
#      Sun Oct 01 09:52:44 2017 +0200
# Node ID 9fdbf99392971dc9ed2c711718c919397eedcf39
# Parent  2fd06499dc8e6a5a784b1334b925c289d7b54e4e
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 9fdbf9939297
# EXP-Topic pull-info-transaction
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.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1128,15 +1128,16 @@  class simplekeyvaluefile(object):
 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)