hgext/rebase.py
changeset 15214 231aac5280ba
parent 15132 81f76098211e
child 15219 9d58569a8b92
equal deleted inserted replaced
15213:15f15f3b405d 15214:231aac5280ba
    13 For more information:
    13 For more information:
    14 http://mercurial.selenic.com/wiki/RebaseExtension
    14 http://mercurial.selenic.com/wiki/RebaseExtension
    15 '''
    15 '''
    16 
    16 
    17 from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks
    17 from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks
    18 from mercurial import extensions, copies, patch
    18 from mercurial import extensions, patch
    19 from mercurial.commands import templateopts
    19 from mercurial.commands import templateopts
    20 from mercurial.node import nullrev
    20 from mercurial.node import nullrev
    21 from mercurial.lock import release
    21 from mercurial.lock import release
    22 from mercurial.i18n import _
    22 from mercurial.i18n import _
    23 import os, errno
    23 import os, errno
   213                         if stats and stats[3] > 0:
   213                         if stats and stats[3] > 0:
   214                             raise util.Abort(_('unresolved conflicts (see hg '
   214                             raise util.Abort(_('unresolved conflicts (see hg '
   215                                         'resolve, then hg rebase --continue)'))
   215                                         'resolve, then hg rebase --continue)'))
   216                     finally:
   216                     finally:
   217                         ui.setconfig('ui', 'forcemerge', '')
   217                         ui.setconfig('ui', 'forcemerge', '')
   218                 updatedirstate(repo, rev, target, p2)
   218                 cmdutil.duplicatecopies(repo, rev, target, p2)
   219                 if not collapsef:
   219                 if not collapsef:
   220                     newrev = concludenode(repo, rev, p1, p2, extrafn=extrafn)
   220                     newrev = concludenode(repo, rev, p1, p2, extrafn=extrafn)
   221                 else:
   221                 else:
   222                     # Skip commit if we are collapsing
   222                     # Skip commit if we are collapsing
   223                     repo.dirstate.setparents(repo[p1].node())
   223                     repo.dirstate.setparents(repo[p1].node())
   298                 if external != nullrev:
   298                 if external != nullrev:
   299                     raise util.Abort(_('unable to collapse, there is more '
   299                     raise util.Abort(_('unable to collapse, there is more '
   300                             'than one external parent'))
   300                             'than one external parent'))
   301                 external = p.rev()
   301                 external = p.rev()
   302     return external
   302     return external
   303 
       
   304 def updatedirstate(repo, rev, p1, p2):
       
   305     """Keep track of renamed files in the revision that is going to be rebased
       
   306     """
       
   307     # Here we simulate the copies and renames in the source changeset
       
   308     cop, diver = copies.copies(repo, repo[rev], repo[p1], repo[p2], True)
       
   309     m1 = repo[rev].manifest()
       
   310     m2 = repo[p1].manifest()
       
   311     for k, v in cop.iteritems():
       
   312         if k in m1:
       
   313             if v in m1 or v in m2:
       
   314                 repo.dirstate.copy(v, k)
       
   315                 if v in m2 and v not in m1 and k in m2:
       
   316                     repo.dirstate.remove(v)
       
   317 
   303 
   318 def concludenode(repo, rev, p1, p2, commitmsg=None, extrafn=None):
   304 def concludenode(repo, rev, p1, p2, commitmsg=None, extrafn=None):
   319     'Commit the changes and store useful information in extra'
   305     'Commit the changes and store useful information in extra'
   320     try:
   306     try:
   321         repo.dirstate.setparents(repo[p1].node(), repo[p2].node())
   307         repo.dirstate.setparents(repo[p1].node(), repo[p2].node())