comparison hgext/rebase.py @ 19518:12843143663d stable

rebase: allow aborting when descendants detected With this, all aborts will succeed in removing the state, rather than leaving the user in 'what do I do now?' limbo.
author Matt Mackall <mpm@selenic.com>
date Thu, 01 Aug 2013 17:54:12 -0500
parents eab2ff59481e
children 5528c31c629c
comparison
equal deleted inserted replaced
19517:eab2ff59481e 19518:12843143663d
606 606
607 def abort(repo, originalwd, target, state): 607 def abort(repo, originalwd, target, state):
608 'Restore the repository to its original state' 608 'Restore the repository to its original state'
609 dstates = [s for s in state.values() if s != nullrev] 609 dstates = [s for s in state.values() if s != nullrev]
610 immutable = [d for d in dstates if not repo[d].mutable()] 610 immutable = [d for d in dstates if not repo[d].mutable()]
611 cleanup = True
611 if immutable: 612 if immutable:
612 repo.ui.warn(_("warning: can't clean up immutable changesets %s\n") 613 repo.ui.warn(_("warning: can't clean up immutable changesets %s\n")
613 % ', '.join(str(repo[r]) for r in immutable), 614 % ', '.join(str(repo[r]) for r in immutable),
614 hint=_('see hg help phases for details')) 615 hint=_('see hg help phases for details'))
616 cleanup = False
615 617
616 descendants = set() 618 descendants = set()
617 if dstates: 619 if dstates:
618 descendants = set(repo.changelog.descendants(dstates)) 620 descendants = set(repo.changelog.descendants(dstates))
619 if descendants - set(dstates): 621 if descendants - set(dstates):
620 repo.ui.warn(_("warning: new changesets detected on target branch, " 622 repo.ui.warn(_("warning: new changesets detected on target branch, "
621 "can't abort\n")) 623 "can't strip\n"))
622 return -1 624 cleanup = False
623 else: 625
626 if cleanup:
624 # Update away from the rebase if necessary 627 # Update away from the rebase if necessary
625 if not immutable and inrebase(repo, originalwd, state): 628 if inrebase(repo, originalwd, state):
626 merge.update(repo, repo[originalwd].rev(), False, True, False) 629 merge.update(repo, repo[originalwd].rev(), False, True, False)
627 630
628 # Strip from the first rebased revision 631 # Strip from the first rebased revision
629 rebased = filter(lambda x: x > -1 and x != target, state.values()) 632 rebased = filter(lambda x: x > -1 and x != target, state.values())
630 if rebased and not immutable: 633 if rebased:
631 strippoints = [c.node() for c in repo.set('roots(%ld)', rebased)] 634 strippoints = [c.node() for c in repo.set('roots(%ld)', rebased)]
632 # no backup of rebased cset versions needed 635 # no backup of rebased cset versions needed
633 repair.strip(repo.ui, repo, strippoints) 636 repair.strip(repo.ui, repo, strippoints)
634 clearstatus(repo) 637
635 repo.ui.warn(_('rebase aborted\n')) 638 clearstatus(repo)
636 return 0 639 repo.ui.warn(_('rebase aborted\n'))
640 return 0
637 641
638 def buildstate(repo, dest, rebaseset, collapse): 642 def buildstate(repo, dest, rebaseset, collapse):
639 '''Define which revisions are going to be rebased and where 643 '''Define which revisions are going to be rebased and where
640 644
641 repo: repo 645 repo: repo