diff hgext/histedit.py @ 35126:a9cc233de513

histedit: add support to output nodechanges using formatter The JSON output of nodechanges will help in automation and to improve editor integrations such as for Nuclide. Differential Revision: https://phab.mercurial-scm.org/D1348
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 28 Oct 2017 19:03:23 +0530
parents c4b769bc86da
children 8a0cac20a1ad
line wrap: on
line diff
--- a/hgext/histedit.py	Sat Oct 28 17:50:25 2017 +0530
+++ b/hgext/histedit.py	Sat Oct 28 19:03:23 2017 +0530
@@ -917,7 +917,8 @@
      ('o', 'outgoing', False, _('changesets not found in destination')),
      ('f', 'force', False,
       _('force outgoing even for unrelated repositories')),
-     ('r', 'rev', [], _('first revision to be edited'), _('REV'))],
+     ('r', 'rev', [], _('first revision to be edited'), _('REV'))] +
+    cmdutil.formatteropts,
      _("[OPTIONS] ([ANCESTOR] | --outgoing [URL])"))
 def histedit(ui, repo, *freeargs, **opts):
     """interactively edit changeset history
@@ -1095,6 +1096,8 @@
 
 def _histedit(ui, repo, state, *freeargs, **opts):
     opts = pycompat.byteskwargs(opts)
+    fm = ui.formatter('histedit', opts)
+    fm.startitem()
     goal = _getgoal(opts)
     revs = opts.get('rev', [])
     rules = opts.get('commands', '')
@@ -1117,7 +1120,8 @@
         _newhistedit(ui, repo, state, revs, freeargs, opts)
 
     _continuehistedit(ui, repo, state)
-    _finishhistedit(ui, repo, state)
+    _finishhistedit(ui, repo, state, fm)
+    fm.end()
 
 def _continuehistedit(ui, repo, state):
     """This function runs after either:
@@ -1164,7 +1168,7 @@
     state.write()
     ui.progress(_("editing"), None)
 
-def _finishhistedit(ui, repo, state):
+def _finishhistedit(ui, repo, state, fm):
     """This action runs when histedit is finishing its session"""
     repo.ui.pushbuffer()
     hg.update(repo, state.parentctxnode, quietempty=True)
@@ -1198,6 +1202,13 @@
     mapping = {k: v for k, v in mapping.items()
                if k in nodemap and all(n in nodemap for n in v)}
     scmutil.cleanupnodes(repo, mapping, 'histedit')
+    hf = fm.hexfunc
+    fl = fm.formatlist
+    fd = fm.formatdict
+    nodechanges = fd({hf(oldn): fl([hf(n) for n in newn], name='node')
+                      for oldn, newn in mapping.iteritems()},
+                     key="oldnode", value="newnodes")
+    fm.data(nodechanges=nodechanges)
 
     state.clear()
     if os.path.exists(repo.sjoin('undo')):