diff hgext/rebase.py @ 34883:c858afe9c59b

rebase: add support to output nodechanges This patch adds support to rebase to show the changes in node once the rebase is complete. This will be extremely helpful for automation purposes and editors such as Nuclide. The output is a dictionary of predecessor hash as key and a list of successors' hashes. The successors one is a list as there can be many successors for a single predecessor in case of split and it will good to have a generic output format. This patch adds tests for the same. A new file is created for the patch as existing files related to rebase has their own purpose and there will be more formatter support coming for rebase in next cycle. Thanks to Jun for suggesting to use fm.data(). Differential Revision: https://phab.mercurial-scm.org/D1173
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 18 Oct 2017 04:31:46 +0530
parents 29f52e7966dd
children ddf37b6b8c3d
line wrap: on
line diff
--- a/hgext/rebase.py	Tue Oct 17 13:20:25 2017 -0700
+++ b/hgext/rebase.py	Wed Oct 18 04:31:46 2017 +0530
@@ -21,6 +21,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import (
+    hex,
     nullid,
     nullrev,
     short,
@@ -501,6 +502,8 @@
 
     def _finishrebase(self):
         repo, ui, opts = self.repo, self.ui, self.opts
+        fm = ui.formatter('rebase', opts)
+        fm.startitem()
         if self.collapsef and not self.keepopen:
             p1, p2, _base = defineparents(repo, min(self.state), self.destmap,
                                           self.state, self.skipped,
@@ -551,7 +554,7 @@
             if self.collapsef:
                 collapsedas = newnode
         clearrebased(ui, repo, self.destmap, self.state, self.skipped,
-                     collapsedas, self.keepf)
+                     collapsedas, self.keepf, fm=fm)
 
         clearstatus(repo)
         clearcollapsemsg(repo)
@@ -561,6 +564,7 @@
         if self.skipped:
             skippedlen = len(self.skipped)
             ui.note(_("%d revisions have been skipped\n") % skippedlen)
+        fm.end()
 
         if (self.activebookmark and self.activebookmark in repo._bookmarks and
             repo['.'].node() == repo._bookmarks[self.activebookmark]):
@@ -1517,7 +1521,7 @@
     return originalwd, destmap, state
 
 def clearrebased(ui, repo, destmap, state, skipped, collapsedas=None,
-                 keepf=False):
+                 keepf=False, fm=None):
     """dispose of rebased revision at the end of the rebase
 
     If `collapsedas` is not None, the rebase was a collapse whose result if the
@@ -1541,6 +1545,10 @@
                     succs = (newnode,)
                 replacements[oldnode] = succs
     scmutil.cleanupnodes(repo, replacements, 'rebase', moves)
+    if fm:
+        nodechanges = {hex(oldn): [hex(n) for n in newn]
+                       for oldn, newn in replacements.iteritems()}
+        fm.data(nodechanges=nodechanges)
 
 def pullrebase(orig, ui, repo, *args, **opts):
     'Call rebase after pull if the latter has been invoked with --rebase'