hgext/rebase.py
changeset 28185 c7e8948627f3
parent 28136 5853878bbc2a
child 28188 6411140aeda9
equal deleted inserted replaced
28184:11c2f8af09c2 28185:c7e8948627f3
   261                 ui.warn(_('tool option will be ignored\n'))
   261                 ui.warn(_('tool option will be ignored\n'))
   262 
   262 
   263             try:
   263             try:
   264                 (originalwd, target, state, skipped, collapsef, keepf,
   264                 (originalwd, target, state, skipped, collapsef, keepf,
   265                  keepbranchesf, external, activebookmark) = restorestatus(repo)
   265                  keepbranchesf, external, activebookmark) = restorestatus(repo)
       
   266                 collapsemsg = restorecollapsemsg(repo)
   266             except error.RepoLookupError:
   267             except error.RepoLookupError:
   267                 if abortf:
   268                 if abortf:
   268                     clearstatus(repo)
   269                     clearstatus(repo)
       
   270                     clearcollapsemsg(repo)
   269                     repo.ui.warn(_('rebase aborted (no revision is removed,'
   271                     repo.ui.warn(_('rebase aborted (no revision is removed,'
   270                                    ' only broken state is cleared)\n'))
   272                                    ' only broken state is cleared)\n'))
   271                     return 0
   273                     return 0
   272                 else:
   274                 else:
   273                     msg = _('cannot continue inconsistent rebase')
   275                     msg = _('cannot continue inconsistent rebase')
   386                             _('changesets'), total)
   388                             _('changesets'), total)
   387                 p1, p2, base = defineparents(repo, rev, target, state,
   389                 p1, p2, base = defineparents(repo, rev, target, state,
   388                                              targetancestors)
   390                                              targetancestors)
   389                 storestatus(repo, originalwd, target, state, collapsef, keepf,
   391                 storestatus(repo, originalwd, target, state, collapsef, keepf,
   390                             keepbranchesf, external, activebookmark)
   392                             keepbranchesf, external, activebookmark)
       
   393                 storecollapsemsg(repo, collapsemsg)
   391                 if len(repo[None].parents()) == 2:
   394                 if len(repo[None].parents()) == 2:
   392                     repo.ui.debug('resuming interrupted rebase\n')
   395                     repo.ui.debug('resuming interrupted rebase\n')
   393                 else:
   396                 else:
   394                     try:
   397                     try:
   395                         ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
   398                         ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
   507                 updatebookmarks(repo, targetnode, nstate, currentbookmarks, tr)
   510                 updatebookmarks(repo, targetnode, nstate, currentbookmarks, tr)
   508                 if activebookmark not in repo._bookmarks:
   511                 if activebookmark not in repo._bookmarks:
   509                     # active bookmark was divergent one and has been deleted
   512                     # active bookmark was divergent one and has been deleted
   510                     activebookmark = None
   513                     activebookmark = None
   511         clearstatus(repo)
   514         clearstatus(repo)
       
   515         clearcollapsemsg(repo)
   512 
   516 
   513         ui.note(_("rebase completed\n"))
   517         ui.note(_("rebase completed\n"))
   514         util.unlinkpath(repo.sjoin('undo'), ignoremissing=True)
   518         util.unlinkpath(repo.sjoin('undo'), ignoremissing=True)
   515         if skipped:
   519         if skipped:
   516             ui.note(_("%d revisions have been skipped\n") % len(skipped))
   520             ui.note(_("%d revisions have been skipped\n") % len(skipped))
   843         if v in nstate:
   847         if v in nstate:
   844             # update the bookmarks for revs that have moved
   848             # update the bookmarks for revs that have moved
   845             marks[k] = nstate[v]
   849             marks[k] = nstate[v]
   846             bookmarks.deletedivergent(repo, [targetnode], k)
   850             bookmarks.deletedivergent(repo, [targetnode], k)
   847     marks.recordchange(tr)
   851     marks.recordchange(tr)
       
   852 
       
   853 def storecollapsemsg(repo, collapsemsg):
       
   854     'Store the collapse message to allow recovery'
       
   855     collapsemsg = collapsemsg or ''
       
   856     f = repo.vfs("last-message.txt", "w")
       
   857     f.write("%s\n" % collapsemsg)
       
   858     f.close()
       
   859 
       
   860 def clearcollapsemsg(repo):
       
   861     'Remove collapse message file'
       
   862     util.unlinkpath(repo.join("last-message.txt"), ignoremissing=True)
       
   863 
       
   864 def restorecollapsemsg(repo):
       
   865     'Restore previously stored collapse message'
       
   866     try:
       
   867         f = repo.vfs("last-message.txt")
       
   868         collapsemsg = f.readline().strip()
       
   869         f.close()
       
   870     except IOError as err:
       
   871         if err.errno != errno.ENOENT:
       
   872             raise
       
   873         raise error.Abort(_('no rebase in progress'))
       
   874     return collapsemsg
   848 
   875 
   849 def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches,
   876 def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches,
   850                 external, activebookmark):
   877                 external, activebookmark):
   851     'Store the current status to allow recovery'
   878     'Store the current status to allow recovery'
   852     f = repo.vfs("rebasestate", "w")
   879     f = repo.vfs("rebasestate", "w")
  1003         if activebookmark and activebookmark in repo._bookmarks:
  1030         if activebookmark and activebookmark in repo._bookmarks:
  1004             bookmarks.activate(repo, activebookmark)
  1031             bookmarks.activate(repo, activebookmark)
  1005 
  1032 
  1006     finally:
  1033     finally:
  1007         clearstatus(repo)
  1034         clearstatus(repo)
       
  1035         clearcollapsemsg(repo)
  1008         repo.ui.warn(_('rebase aborted\n'))
  1036         repo.ui.warn(_('rebase aborted\n'))
  1009     return 0
  1037     return 0
  1010 
  1038 
  1011 def buildstate(repo, dest, rebaseset, collapse, obsoletenotrebased):
  1039 def buildstate(repo, dest, rebaseset, collapse, obsoletenotrebased):
  1012     '''Define which revisions are going to be rebased and where
  1040     '''Define which revisions are going to be rebased and where