comparison hgext/rebase.py @ 26360:b2415e94b2f5

rebase: avoid losing branch commits with --keepbranch (issue4835)
author timeless@mozdev.org
date Thu, 24 Sep 2015 17:51:05 -0400
parents 92409f8dff5d
children 4b0fc75f9403
comparison
equal deleted inserted replaced
26359:c545d51c901e 26360:b2415e94b2f5
429 if not collapsef: 429 if not collapsef:
430 merging = p2 != nullrev 430 merging = p2 != nullrev
431 editform = cmdutil.mergeeditform(merging, 'rebase') 431 editform = cmdutil.mergeeditform(merging, 'rebase')
432 editor = cmdutil.getcommiteditor(editform=editform, **opts) 432 editor = cmdutil.getcommiteditor(editform=editform, **opts)
433 newnode = concludenode(repo, rev, p1, p2, extrafn=extrafn, 433 newnode = concludenode(repo, rev, p1, p2, extrafn=extrafn,
434 editor=editor) 434 editor=editor,
435 keepbranches=keepbranchesf)
435 else: 436 else:
436 # Skip commit if we are collapsing 437 # Skip commit if we are collapsing
437 repo.dirstate.beginparentchange() 438 repo.dirstate.beginparentchange()
438 repo.setparents(repo[p1].node()) 439 repo.setparents(repo[p1].node())
439 repo.dirstate.endparentchange() 440 repo.dirstate.endparentchange()
479 if rebased not in skipped and state[rebased] > nullmerge: 480 if rebased not in skipped and state[rebased] > nullmerge:
480 commitmsg += '\n* %s' % repo[rebased].description() 481 commitmsg += '\n* %s' % repo[rebased].description()
481 editopt = True 482 editopt = True
482 editor = cmdutil.getcommiteditor(edit=editopt, editform=editform) 483 editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
483 newnode = concludenode(repo, rev, p1, external, commitmsg=commitmsg, 484 newnode = concludenode(repo, rev, p1, external, commitmsg=commitmsg,
484 extrafn=extrafn, editor=editor) 485 extrafn=extrafn, editor=editor,
486 keepbranches=keepbranchesf)
485 if newnode is None: 487 if newnode is None:
486 newrev = target 488 newrev = target
487 else: 489 else:
488 newrev = repo[newnode].rev() 490 newrev = repo[newnode].rev()
489 for oldrev in state.iterkeys(): 491 for oldrev in state.iterkeys():
559 raise util.Abort(_('unable to collapse on top of %s, there is more ' 561 raise util.Abort(_('unable to collapse on top of %s, there is more '
560 'than one external parent: %s') % 562 'than one external parent: %s') %
561 (max(targetancestors), 563 (max(targetancestors),
562 ', '.join(str(p) for p in sorted(parents)))) 564 ', '.join(str(p) for p in sorted(parents))))
563 565
564 def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None): 566 def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None,
567 keepbranches=False):
565 '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev 568 '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
566 but also store useful information in extra. 569 but also store useful information in extra.
567 Return node of committed revision.''' 570 Return node of committed revision.'''
568 dsguard = cmdutil.dirstateguard(repo, 'rebase') 571 dsguard = cmdutil.dirstateguard(repo, 'rebase')
569 try: 572 try:
570 repo.setparents(repo[p1].node(), repo[p2].node()) 573 repo.setparents(repo[p1].node(), repo[p2].node())
571 ctx = repo[rev] 574 ctx = repo[rev]
572 if commitmsg is None: 575 if commitmsg is None:
573 commitmsg = ctx.description() 576 commitmsg = ctx.description()
577 keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
574 extra = {'rebase_source': ctx.hex()} 578 extra = {'rebase_source': ctx.hex()}
575 if extrafn: 579 if extrafn:
576 extrafn(ctx, extra) 580 extrafn(ctx, extra)
577 581
578 backup = repo.ui.backupconfig('phases', 'new-commit') 582 backup = repo.ui.backupconfig('phases', 'new-commit')
579 try: 583 try:
580 targetphase = max(ctx.phase(), phases.draft) 584 targetphase = max(ctx.phase(), phases.draft)
581 repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase') 585 repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase')
586 if keepbranch:
587 repo.ui.setconfig('ui', 'allowemptycommit', True)
582 # Commit might fail if unresolved files exist 588 # Commit might fail if unresolved files exist
583 newnode = repo.commit(text=commitmsg, user=ctx.user(), 589 newnode = repo.commit(text=commitmsg, user=ctx.user(),
584 date=ctx.date(), extra=extra, editor=editor) 590 date=ctx.date(), extra=extra, editor=editor)
585 finally: 591 finally:
586 repo.ui.restoreconfig(backup) 592 repo.ui.restoreconfig(backup)