pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8199

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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):



To: pulkit, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to