# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1582961293 -19800 # Node ID 13da36d77a3f4529a1530fc9846d8323f638333f # Parent 36f08ae87ef687be53a59bd87376bcfbe4479205 scmutil: add option to register summary callbacks as transaction validators We have a list of summary callbacks which are run after the transaction is closed to show what has changed and what not. This patch makes it possible to register those callbacks as transaction validators so that we can show summary before committing the transaction and prompt user to accept the changes. The goal of this is to implement `pull --confirm`. Differential Revision: https://phab.mercurial-scm.org/D8199 diff -r 36f08ae87ef6 -r 13da36d77a3f mercurial/scmutil.py --- a/mercurial/scmutil.py Sat Feb 29 12:56:37 2020 +0530 +++ b/mercurial/scmutil.py Sat Feb 29 12:58:13 2020 +0530 @@ -1900,8 +1900,11 @@ _reportstroubledchangesets = True -def registersummarycallback(repo, otr, txnname=b''): +def registersummarycallback(repo, otr, txnname=b'', as_validator=False): """register a callback to issue a summary after the transaction is closed + + If as_validator is true, then the callbacks are registered as transaction + validators instead """ def txmatch(sources): @@ -1927,7 +1930,10 @@ func(repo, tr) newcat = b'%02i-txnreport' % len(categories) - otr.addpostclose(newcat, wrapped) + if as_validator: + otr.addvalidator(newcat, wrapped) + else: + otr.addpostclose(newcat, wrapped) categories.append(newcat) return wrapped @@ -1942,6 +1948,8 @@ if cgheads: htext = _(b" (%+d heads)") % cgheads msg = _(b"added %d changesets with %d changes to %d files%s\n") + if as_validator: + msg = _(b"adding %d changesets with %d changes to %d files%s\n") assert repo is not None # help pytype repo.ui.status(msg % (cgchangesets, cgrevisions, cgfiles, htext)) @@ -1954,7 +1962,10 @@ if newmarkers: repo.ui.status(_(b'%i new obsolescence markers\n') % newmarkers) if obsoleted: - repo.ui.status(_(b'obsoleted %i changesets\n') % len(obsoleted)) + msg = _(b'obsoleted %i changesets\n') + if as_validator: + msg = _(b'obsoleting %i changesets\n') + repo.ui.status(msg % len(obsoleted)) if obsolete.isenabled( repo, obsolete.createmarkersopt @@ -2057,9 +2068,10 @@ ] if not published: return - repo.ui.status( - _(b'%d local changesets published\n') % len(published) - ) + msg = _(b'%d local changesets published\n') + if as_validator: + msg = _(b'%d local changesets will be published\n') + repo.ui.status(msg % len(published)) def getinstabilitymessage(delta, instability):