Mercurial > hg-stable
diff mercurial/scmutil.py @ 44554:13da36d77a3f
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
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 29 Feb 2020 12:58:13 +0530 |
parents | 9d2b2df2c2ba |
children | fdc802f29b2c |
line wrap: on
line diff
--- 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):