# HG changeset patch # User Denis Laxalde # Date 2017-10-04 16:49:09 # Node ID b799f11644d82fdf9103ed602659b59affc53458 # Parent 18309380fb88d648011e84cb2042ba1c907d536f 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. diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1206,13 +1206,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)