387 _('unresolved conflicts (see hg ' |
387 _('unresolved conflicts (see hg ' |
388 'resolve, then hg rebase --continue)')) |
388 'resolve, then hg rebase --continue)')) |
389 finally: |
389 finally: |
390 ui.setconfig('ui', 'forcemerge', '', 'rebase') |
390 ui.setconfig('ui', 'forcemerge', '', 'rebase') |
391 if not collapsef: |
391 if not collapsef: |
392 merging = repo[p2].rev() != nullrev |
392 merging = p2 != nullrev |
393 editform = cmdutil.mergeeditform(merging, 'rebase') |
393 editform = cmdutil.mergeeditform(merging, 'rebase') |
394 editor = cmdutil.getcommiteditor(editform=editform, **opts) |
394 editor = cmdutil.getcommiteditor(editform=editform, **opts) |
395 newnode = concludenode(repo, rev, p1, p2, extrafn=extrafn, |
395 newnode = concludenode(repo, rev, p1, p2, extrafn=extrafn, |
396 editor=editor) |
396 editor=editor) |
397 else: |
397 else: |
541 |
541 |
542 def rebasenode(repo, rev, p1, state, collapse, target): |
542 def rebasenode(repo, rev, p1, state, collapse, target): |
543 'Rebase a single revision' |
543 'Rebase a single revision' |
544 # Merge phase |
544 # Merge phase |
545 # Update to target and merge it with local |
545 # Update to target and merge it with local |
546 if repo['.'].rev() != repo[p1].rev(): |
546 if repo['.'].rev() != p1: |
547 repo.ui.debug(" update to %d:%s\n" % (repo[p1].rev(), repo[p1])) |
547 repo.ui.debug(" update to %d:%s\n" % (p1, repo[p1])) |
548 merge.update(repo, p1, False, True, False) |
548 merge.update(repo, p1, False, True, False) |
549 else: |
549 else: |
550 repo.ui.debug(" already in target\n") |
550 repo.ui.debug(" already in target\n") |
551 repo.dirstate.write() |
551 repo.dirstate.write() |
552 repo.ui.debug(" merge against %d:%s\n" % (repo[rev].rev(), repo[rev])) |
552 repo.ui.debug(" merge against %d:%s\n" % (rev, repo[rev])) |
553 if repo[rev].rev() == repo[min(state)].rev(): |
553 if rev == min(state): |
554 # Case (1) initial changeset of a non-detaching rebase. |
554 # Case (1) initial changeset of a non-detaching rebase. |
555 # Let the merge mechanism find the base itself. |
555 # Let the merge mechanism find the base itself. |
556 base = None |
556 base = None |
557 elif not repo[rev].p2(): |
557 elif not repo[rev].p2(): |
558 # Case (2) detaching the node with a single parent, use this parent |
558 # Case (2) detaching the node with a single parent, use this parent |
559 base = repo[rev].p1().node() |
559 base = repo[rev].p1().rev() |
560 else: |
560 else: |
561 # In case of merge, we need to pick the right parent as merge base. |
561 # In case of merge, we need to pick the right parent as merge base. |
562 # |
562 # |
563 # Imagine we have: |
563 # Imagine we have: |
564 # - M: currently rebase revision in this step |
564 # - M: currently rebase revision in this step |
581 # - changes from A to D (with include changes between unrelated A and B |
581 # - changes from A to D (with include changes between unrelated A and B |
582 # plus changes induced by rebase) |
582 # plus changes induced by rebase) |
583 # Which does not represent anything sensible and creates a lot of |
583 # Which does not represent anything sensible and creates a lot of |
584 # conflicts. |
584 # conflicts. |
585 for p in repo[rev].parents(): |
585 for p in repo[rev].parents(): |
586 if state.get(p.rev()) == repo[p1].rev(): |
586 if state.get(p.rev()) == p1: |
587 base = p.node() |
587 base = p.rev() |
588 break |
588 break |
589 else: # fallback when base not found |
589 else: # fallback when base not found |
590 base = None |
590 base = None |
591 |
591 |
592 # Raise because this function is called wrong (see issue 4106) |
592 # Raise because this function is called wrong (see issue 4106) |
593 raise AssertionError('no base found to rebase on ' |
593 raise AssertionError('no base found to rebase on ' |
594 '(rebasenode called wrong)') |
594 '(rebasenode called wrong)') |
595 if base is not None: |
595 if base is not None: |
596 repo.ui.debug(" detach base %d:%s\n" % (repo[base].rev(), repo[base])) |
596 repo.ui.debug(" detach base %d:%s\n" % (base, repo[base])) |
597 # When collapsing in-place, the parent is the common ancestor, we |
597 # When collapsing in-place, the parent is the common ancestor, we |
598 # have to allow merging with it. |
598 # have to allow merging with it. |
599 stats = merge.update(repo, rev, True, True, False, base, collapse, |
599 stats = merge.update(repo, rev, True, True, False, base, collapse, |
600 labels=['dest', 'source']) |
600 labels=['dest', 'source']) |
601 if collapse: |
601 if collapse: |
833 cleanup = False |
833 cleanup = False |
834 |
834 |
835 if cleanup: |
835 if cleanup: |
836 # Update away from the rebase if necessary |
836 # Update away from the rebase if necessary |
837 if inrebase(repo, originalwd, state): |
837 if inrebase(repo, originalwd, state): |
838 merge.update(repo, repo[originalwd].rev(), False, True, False) |
838 merge.update(repo, originalwd, False, True, False) |
839 |
839 |
840 # Strip from the first rebased revision |
840 # Strip from the first rebased revision |
841 rebased = filter(lambda x: x > -1 and x != target, state.values()) |
841 rebased = filter(lambda x: x > -1 and x != target, state.values()) |
842 if rebased: |
842 if rebased: |
843 strippoints = [c.node() for c in repo.set('roots(%ld)', rebased)] |
843 strippoints = [c.node() for c in repo.set('roots(%ld)', rebased)] |