comparison 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
comparison
equal deleted inserted replaced
34882:e9f320a40b44 34883:c858afe9c59b
19 import errno 19 import errno
20 import os 20 import os
21 21
22 from mercurial.i18n import _ 22 from mercurial.i18n import _
23 from mercurial.node import ( 23 from mercurial.node import (
24 hex,
24 nullid, 25 nullid,
25 nullrev, 26 nullrev,
26 short, 27 short,
27 ) 28 )
28 from mercurial import ( 29 from mercurial import (
499 (desc, repo[self.state[rev]])) 500 (desc, repo[self.state[rev]]))
500 return pos 501 return pos
501 502
502 def _finishrebase(self): 503 def _finishrebase(self):
503 repo, ui, opts = self.repo, self.ui, self.opts 504 repo, ui, opts = self.repo, self.ui, self.opts
505 fm = ui.formatter('rebase', opts)
506 fm.startitem()
504 if self.collapsef and not self.keepopen: 507 if self.collapsef and not self.keepopen:
505 p1, p2, _base = defineparents(repo, min(self.state), self.destmap, 508 p1, p2, _base = defineparents(repo, min(self.state), self.destmap,
506 self.state, self.skipped, 509 self.state, self.skipped,
507 self.obsoletenotrebased) 510 self.obsoletenotrebased)
508 editopt = opts.get('edit') 511 editopt = opts.get('edit')
549 collapsedas = None 552 collapsedas = None
550 if not self.keepf: 553 if not self.keepf:
551 if self.collapsef: 554 if self.collapsef:
552 collapsedas = newnode 555 collapsedas = newnode
553 clearrebased(ui, repo, self.destmap, self.state, self.skipped, 556 clearrebased(ui, repo, self.destmap, self.state, self.skipped,
554 collapsedas, self.keepf) 557 collapsedas, self.keepf, fm=fm)
555 558
556 clearstatus(repo) 559 clearstatus(repo)
557 clearcollapsemsg(repo) 560 clearcollapsemsg(repo)
558 561
559 ui.note(_("rebase completed\n")) 562 ui.note(_("rebase completed\n"))
560 util.unlinkpath(repo.sjoin('undo'), ignoremissing=True) 563 util.unlinkpath(repo.sjoin('undo'), ignoremissing=True)
561 if self.skipped: 564 if self.skipped:
562 skippedlen = len(self.skipped) 565 skippedlen = len(self.skipped)
563 ui.note(_("%d revisions have been skipped\n") % skippedlen) 566 ui.note(_("%d revisions have been skipped\n") % skippedlen)
567 fm.end()
564 568
565 if (self.activebookmark and self.activebookmark in repo._bookmarks and 569 if (self.activebookmark and self.activebookmark in repo._bookmarks and
566 repo['.'].node() == repo._bookmarks[self.activebookmark]): 570 repo['.'].node() == repo._bookmarks[self.activebookmark]):
567 bookmarks.activate(repo, self.activebookmark) 571 bookmarks.activate(repo, self.activebookmark)
568 572
1515 if parents and all((state.get(p) == p for p in parents)): 1519 if parents and all((state.get(p) == p for p in parents)):
1516 state[rev] = rev 1520 state[rev] = rev
1517 return originalwd, destmap, state 1521 return originalwd, destmap, state
1518 1522
1519 def clearrebased(ui, repo, destmap, state, skipped, collapsedas=None, 1523 def clearrebased(ui, repo, destmap, state, skipped, collapsedas=None,
1520 keepf=False): 1524 keepf=False, fm=None):
1521 """dispose of rebased revision at the end of the rebase 1525 """dispose of rebased revision at the end of the rebase
1522 1526
1523 If `collapsedas` is not None, the rebase was a collapse whose result if the 1527 If `collapsedas` is not None, the rebase was a collapse whose result if the
1524 `collapsedas` node. 1528 `collapsedas` node.
1525 1529
1539 succs = () 1543 succs = ()
1540 else: 1544 else:
1541 succs = (newnode,) 1545 succs = (newnode,)
1542 replacements[oldnode] = succs 1546 replacements[oldnode] = succs
1543 scmutil.cleanupnodes(repo, replacements, 'rebase', moves) 1547 scmutil.cleanupnodes(repo, replacements, 'rebase', moves)
1548 if fm:
1549 nodechanges = {hex(oldn): [hex(n) for n in newn]
1550 for oldn, newn in replacements.iteritems()}
1551 fm.data(nodechanges=nodechanges)
1544 1552
1545 def pullrebase(orig, ui, repo, *args, **opts): 1553 def pullrebase(orig, ui, repo, *args, **opts):
1546 'Call rebase after pull if the latter has been invoked with --rebase' 1554 'Call rebase after pull if the latter has been invoked with --rebase'
1547 ret = None 1555 ret = None
1548 if opts.get('rebase'): 1556 if opts.get('rebase'):