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.
--- 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)