hgext/rebase.py
changeset 44053 894c91c2e363
parent 44051 436d106de670
child 44090 2f0a44c69e07
equal deleted inserted replaced
44052:b74270da5eee 44053:894c91c2e363
   796                 updateifonnodes.update(self.destmap.values())
   796                 updateifonnodes.update(self.destmap.values())
   797                 updateifonnodes.add(self.originalwd)
   797                 updateifonnodes.add(self.originalwd)
   798                 shouldupdate = repo[b'.'].rev() in updateifonnodes
   798                 shouldupdate = repo[b'.'].rev() in updateifonnodes
   799 
   799 
   800                 # Update away from the rebase if necessary
   800                 # Update away from the rebase if necessary
   801                 if shouldupdate or needupdate(repo, self.state):
   801                 if shouldupdate:
   802                     mergemod.update(
   802                     mergemod.update(
   803                         repo, self.originalwd, branchmerge=False, force=True
   803                         repo, self.originalwd, branchmerge=False, force=True
   804                     )
   804                     )
   805 
   805 
   806                 # Strip from the first rebased revision
   806                 # Strip from the first rebased revision
  1054                         b'either enable obsmarkers to allow unstable '
  1054                         b'either enable obsmarkers to allow unstable '
  1055                         b'revisions or use --keep to keep original '
  1055                         b'revisions or use --keep to keep original '
  1056                         b'changesets'
  1056                         b'changesets'
  1057                     ),
  1057                     ),
  1058                 )
  1058                 )
  1059             if needupdate(repo, rbsrt.state):
  1059             # update to the current working revision
  1060                 # update to the current working revision
  1060             # to clear interrupted merge
  1061                 # to clear interrupted merge
  1061             hg.updaterepo(repo, rbsrt.originalwd, overwrite=True)
  1062                 hg.updaterepo(repo, rbsrt.originalwd, overwrite=True)
       
  1063             rbsrt._finishrebase()
  1062             rbsrt._finishrebase()
  1064             return 0
  1063             return 0
  1065     elif inmemory:
  1064     elif inmemory:
  1066         try:
  1065         try:
  1067             # in-memory merge doesn't support conflicts, so if we hit any, abort
  1066             # in-memory merge doesn't support conflicts, so if we hit any, abort
  1922     if tr:
  1921     if tr:
  1923         tr.removefilegenerator(b'rebasestate')
  1922         tr.removefilegenerator(b'rebasestate')
  1924     repo.vfs.unlinkpath(b"rebasestate", ignoremissing=True)
  1923     repo.vfs.unlinkpath(b"rebasestate", ignoremissing=True)
  1925 
  1924 
  1926 
  1925 
  1927 def needupdate(repo, state):
       
  1928     '''check whether we should `update --clean` away from a merge, or if
       
  1929     somehow the working dir got forcibly updated, e.g. by older hg'''
       
  1930     parents = [p.rev() for p in repo[None].parents()]
       
  1931 
       
  1932     # Are we in a merge state at all?
       
  1933     if len(parents) < 2:
       
  1934         return False
       
  1935 
       
  1936     # We should be standing on the first as-of-yet unrebased commit.
       
  1937     firstunrebased = min(
       
  1938         [old for old, new in pycompat.iteritems(state) if new == nullrev]
       
  1939     )
       
  1940     if firstunrebased in parents:
       
  1941         return True
       
  1942 
       
  1943     return False
       
  1944 
       
  1945 
       
  1946 def sortsource(destmap):
  1926 def sortsource(destmap):
  1947     """yield source revisions in an order that we only rebase things once
  1927     """yield source revisions in an order that we only rebase things once
  1948 
  1928 
  1949     If source and destination overlaps, we should filter out revisions
  1929     If source and destination overlaps, we should filter out revisions
  1950     depending on other revisions which hasn't been rebased yet.
  1930     depending on other revisions which hasn't been rebased yet.