Patchwork D1173: rebase: add support to output nodechanges

login
register
mail settings
Submitter phabricator
Date Oct. 17, 2017, 11:13 p.m.
Message ID <differential-rev-PHID-DREV-icwvazypccqxecsxoqp5-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25151/
State Superseded
Headers show

Comments

phabricator - Oct. 17, 2017, 11:13 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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 successor 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 nex cycle.
  
  Thanks to Jun for suggesting to use fm.data().

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/rebase.py
  tests/test-rebase-templates.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 17, 2017, 11:16 p.m.
pulkit added a comment.


  The previous discussion on this is at https://phab.mercurial-scm.org/D934.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 18, 2017, 7:01 a.m.
dlax accepted this revision.
dlax added a comment.


  Looks good to me, much nicer than the previous version.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, dlax
Cc: dlax, mercurial-devel
phabricator - Oct. 18, 2017, 8:08 p.m.
durin42 added a comment.


  Much improved, thanks.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, dlax
Cc: durin42, dlax, mercurial-devel
phabricator - Oct. 19, 2017, 3:03 p.m.
yuja added inline comments.

INLINE COMMENTS

> rebase.py:597
>      ('a', 'abort', False, _('abort an interrupted rebase'))] +
>       templateopts,
>      _('[-s REV | -b REV] [-d REV] [OPTION]'))

I'm surprised that the rebase command does have -T and --style
options from the very start. No idea how they would work, though.

> rebase.py:1549
> +    if fm:
> +        nodechanges = {hex(oldn): [hex(n) for n in newn]
> +                       for oldn, newn in replacements.iteritems()}

fm.hexfunc() could be used.

> rebase.py:1551
> +                       for oldn, newn in replacements.iteritems()}
> +        fm.data(nodechanges=nodechanges)
>  

Needs to wrap dict/list by fm.formatdict()/fm.formatlist()
to support -T "{user template}".

Can you send a follow up after 4.4 release?

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, dlax, durin42
Cc: yuja, durin42, dlax, mercurial-devel
phabricator - Oct. 19, 2017, 6:46 p.m.
pulkit added inline comments.

INLINE COMMENTS

> yuja wrote in rebase.py:597
> I'm surprised that the rebase command does have -T and --style
> options from the very start. No idea how they would work, though.

I am also surprised by this.

> yuja wrote in rebase.py:1551
> Needs to wrap dict/list by fm.formatdict()/fm.formatlist()
> to support -T "{user template}".
> 
> Can you send a follow up after 4.4 release?

Yeah sure. I will.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, dlax, durin42
Cc: yuja, durin42, dlax, mercurial-devel

Patch

diff --git a/tests/test-rebase-templates.t b/tests/test-rebase-templates.t
new file mode 100644
--- /dev/null
+++ b/tests/test-rebase-templates.t
@@ -0,0 +1,44 @@ 
+Testing templating for rebase command
+
+Setup
+
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > rebase=
+  > [experimental]
+  > evolution=createmarkers
+  > EOF
+
+  $ hg init repo
+  $ cd repo
+  $ for ch in a b c d; do echo foo > $ch; hg commit -Aqm "Added "$ch; done
+
+  $ hg log -G -T "{rev}:{node|short} {desc}"
+  @  3:62615734edd5 Added d
+  |
+  o  2:28ad74487de9 Added c
+  |
+  o  1:29becc82797a Added b
+  |
+  o  0:18d04c59bb5d Added a
+  
+Getting the JSON output for nodechanges
+
+  $ hg rebase -s 2 -d 0 -q -Tjson
+  [
+   {
+    "nodechanges": {"28ad74487de9599d00d81085be739c61fc340652": ["849767420fd5519cf0026232411a943ed03cc9fb"], "62615734edd52f06b6fb9c2beb429e4fe30d57b8": ["df21b32134ba85d86bca590cbe9b8b7cbc346c53"]}
+   }
+  ]
+
+  $ hg log -G -T "{rev}:{node|short} {desc}"
+  @  5:df21b32134ba Added d
+  |
+  o  4:849767420fd5 Added c
+  |
+  | o  1:29becc82797a Added b
+  |/
+  o  0:18d04c59bb5d Added a
+  
+  $ hg rebase -s 1 -d 5 -q -T "{nodechanges|json}"
+  {"29becc82797a4bc11ec8880b58eaecd2ab3e7760": ["d9d6773efc831c274eace04bc13e8e6412517139"]} (no-eol)
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -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'