hgext/rebase.py
branchstable
changeset 49366 288de6f5d724
parent 49306 2e726c934fcd
child 49448 cfff73cab721
equal deleted inserted replaced
49364:e8ea403b1c46 49366:288de6f5d724
    12 
    12 
    13 For more information:
    13 For more information:
    14 https://mercurial-scm.org/wiki/RebaseExtension
    14 https://mercurial-scm.org/wiki/RebaseExtension
    15 '''
    15 '''
    16 
    16 
    17 from __future__ import absolute_import
    17 
    18 
       
    19 import errno
       
    20 import os
    18 import os
    21 
    19 
    22 from mercurial.i18n import _
    20 from mercurial.i18n import _
    23 from mercurial.node import (
    21 from mercurial.node import (
    24     nullrev,
    22     nullrev,
   158     return cmdutil.format_changeset_summary(
   156     return cmdutil.format_changeset_summary(
   159         ctx.repo().ui, ctx, command=b'rebase'
   157         ctx.repo().ui, ctx, command=b'rebase'
   160     )
   158     )
   161 
   159 
   162 
   160 
   163 class rebaseruntime(object):
   161 class rebaseruntime:
   164     """This class is a container for rebase runtime state"""
   162     """This class is a container for rebase runtime state"""
   165 
   163 
   166     def __init__(self, repo, ui, inmemory=False, dryrun=False, opts=None):
   164     def __init__(self, repo, ui, inmemory=False, dryrun=False, opts=None):
   167         if opts is None:
   165         if opts is None:
   168             opts = {}
   166             opts = {}
   242         f.write(b'%d\n' % int(self.collapsef))
   240         f.write(b'%d\n' % int(self.collapsef))
   243         f.write(b'%d\n' % int(self.keepf))
   241         f.write(b'%d\n' % int(self.keepf))
   244         f.write(b'%d\n' % int(self.keepbranchesf))
   242         f.write(b'%d\n' % int(self.keepbranchesf))
   245         f.write(b'%s\n' % (self.activebookmark or b''))
   243         f.write(b'%s\n' % (self.activebookmark or b''))
   246         destmap = self.destmap
   244         destmap = self.destmap
   247         for d, v in pycompat.iteritems(self.state):
   245         for d, v in self.state.items():
   248             oldrev = repo[d].hex()
   246             oldrev = repo[d].hex()
   249             if v >= 0:
   247             if v >= 0:
   250                 newrev = repo[v].hex()
   248                 newrev = repo[v].hex()
   251             else:
   249             else:
   252                 newrev = b"%d" % v
   250                 newrev = b"%d" % v
   504         if tr:
   502         if tr:
   505             # When using single transaction, store state when transaction
   503             # When using single transaction, store state when transaction
   506             # commits.
   504             # commits.
   507             self.storestatus(tr)
   505             self.storestatus(tr)
   508 
   506 
   509         cands = [k for k, v in pycompat.iteritems(self.state) if v == revtodo]
   507         cands = [k for k, v in self.state.items() if v == revtodo]
   510         p = repo.ui.makeprogress(
   508         p = repo.ui.makeprogress(
   511             _(b"rebasing"), unit=_(b'changesets'), total=len(cands)
   509             _(b"rebasing"), unit=_(b'changesets'), total=len(cands)
   512         )
   510         )
   513 
   511 
   514         def progress(ctx):
   512         def progress(ctx):
  1335             bpbase[bp] = bpbase.get(bp, []) + [b]
  1333             bpbase[bp] = bpbase.get(bp, []) + [b]
  1336         if None in bpbase:
  1334         if None in bpbase:
  1337             # emulate the old behavior, showing "nothing to rebase" (a better
  1335             # emulate the old behavior, showing "nothing to rebase" (a better
  1338             # behavior may be abort with "cannot find branching point" error)
  1336             # behavior may be abort with "cannot find branching point" error)
  1339             bpbase.clear()
  1337             bpbase.clear()
  1340         for bp, bs in pycompat.iteritems(bpbase):  # calculate roots
  1338         for bp, bs in bpbase.items():  # calculate roots
  1341             roots += list(repo.revs(b'children(%d) & ancestors(%ld)', bp, bs))
  1339             roots += list(repo.revs(b'children(%d) & ancestors(%ld)', bp, bs))
  1342 
  1340 
  1343         rebaseset = repo.revs(b'%ld::', roots)
  1341         rebaseset = repo.revs(b'%ld::', roots)
  1344 
  1342 
  1345         if not rebaseset:
  1343         if not rebaseset:
  1939     """Restore previously stored collapse message"""
  1937     """Restore previously stored collapse message"""
  1940     try:
  1938     try:
  1941         f = repo.vfs(b"last-message.txt")
  1939         f = repo.vfs(b"last-message.txt")
  1942         collapsemsg = f.readline().strip()
  1940         collapsemsg = f.readline().strip()
  1943         f.close()
  1941         f.close()
  1944     except IOError as err:
  1942     except FileNotFoundError:
  1945         if err.errno != errno.ENOENT:
       
  1946             raise
       
  1947         if isabort:
  1943         if isabort:
  1948             # Oh well, just abort like normal
  1944             # Oh well, just abort like normal
  1949             collapsemsg = b''
  1945             collapsemsg = b''
  1950         else:
  1946         else:
  1951             raise error.Abort(_(b'missing .hg/last-message.txt for rebase'))
  1947             raise error.Abort(_(b'missing .hg/last-message.txt for rebase'))
  2102     if fm:
  2098     if fm:
  2103         hf = fm.hexfunc
  2099         hf = fm.hexfunc
  2104         fl = fm.formatlist
  2100         fl = fm.formatlist
  2105         fd = fm.formatdict
  2101         fd = fm.formatdict
  2106         changes = {}
  2102         changes = {}
  2107         for oldns, newn in pycompat.iteritems(replacements):
  2103         for oldns, newn in replacements.items():
  2108             for oldn in oldns:
  2104             for oldn in oldns:
  2109                 changes[hf(oldn)] = fl([hf(n) for n in newn], name=b'node')
  2105                 changes[hf(oldn)] = fl([hf(n) for n in newn], name=b'node')
  2110         nodechanges = fd(changes, key=b"oldnode", value=b"newnodes")
  2106         nodechanges = fd(changes, key=b"oldnode", value=b"newnodes")
  2111         fm.data(nodechanges=nodechanges)
  2107         fm.data(nodechanges=nodechanges)
  2112     if keepf:
  2108     if keepf:
  2256     except error.RepoLookupError:
  2252     except error.RepoLookupError:
  2257         # i18n: column positioning for "hg summary"
  2253         # i18n: column positioning for "hg summary"
  2258         msg = _(b'rebase: (use "hg rebase --abort" to clear broken state)\n')
  2254         msg = _(b'rebase: (use "hg rebase --abort" to clear broken state)\n')
  2259         ui.write(msg)
  2255         ui.write(msg)
  2260         return
  2256         return
  2261     numrebased = len([i for i in pycompat.itervalues(state) if i >= 0])
  2257     numrebased = len([i for i in state.values() if i >= 0])
  2262     # i18n: column positioning for "hg summary"
  2258     # i18n: column positioning for "hg summary"
  2263     ui.write(
  2259     ui.write(
  2264         _(b'rebase: %s, %s (rebase --continue)\n')
  2260         _(b'rebase: %s, %s (rebase --continue)\n')
  2265         % (
  2261         % (
  2266             ui.label(_(b'%d rebased'), b'rebase.rebased') % numrebased,
  2262             ui.label(_(b'%d rebased'), b'rebase.rebased') % numrebased,