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.
--- a/mercurial/scmutil.py Sun Oct 01 09:52:44 2017 +0200
+++ b/mercurial/scmutil.py Wed Oct 04 18:49:09 2017 +0200
@@ -1206,13 +1206,23 @@
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)