comparison hgext/histedit.py @ 17663:c6de8c696644

histedit: extract bookmark logic in a dedicated function This lighten the main function and will help to see future changes to this bookmark logic.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 26 Sep 2012 14:19:19 +0200
parents 4f2390e3f4b0
children 4eb13b619785
comparison
equal deleted inserted replaced
17662:4f2390e3f4b0 17663:c6de8c696644
600 600
601 hg.update(repo, parentctx.node()) 601 hg.update(repo, parentctx.node())
602 602
603 if not keep: 603 if not keep:
604 if replacemap: 604 if replacemap:
605 ui.note(_('histedit: Should update metadata for the following ' 605 movebookmarks(ui, repo, replacemap, tmpnodes, created)
606 'changes:\n')) 606 # TODO update mq state
607
608 def copybms(old, new):
609 if old in tmpnodes or old in created:
610 # can't have any metadata we'd want to update
611 return
612 while new in replacemap:
613 new = replacemap[new]
614 ui.note(_('histedit: %s to %s\n') % (node.short(old),
615 node.short(new)))
616 octx = repo[old]
617 marks = octx.bookmarks()
618 if marks:
619 ui.note(_('histedit: moving bookmarks %s\n') %
620 ', '.join(marks))
621 for mark in marks:
622 repo._bookmarks[mark] = new
623 bookmarks.write(repo)
624
625 # We assume that bookmarks on the tip should remain
626 # tipmost, but bookmarks on non-tip changesets should go
627 # to their most reasonable successor. As a result, find
628 # the old tip and new tip and copy those bookmarks first,
629 # then do the rest of the bookmark copies.
630 oldtip = sorted(replacemap.keys(), key=repo.changelog.rev)[-1]
631 newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1]
632 copybms(oldtip, newtip)
633
634 for old, new in sorted(replacemap.iteritems()):
635 copybms(old, new)
636 # TODO update mq state
637 607
638 ui.debug('should strip replaced nodes %s\n' % 608 ui.debug('should strip replaced nodes %s\n' %
639 ', '.join([node.short(n) for n in replaced])) 609 ', '.join([node.short(n) for n in replaced]))
640 lock = None 610 lock = None
641 try: 611 try:
741 raise util.Abort(_('unknown changeset %s listed') % ha) 711 raise util.Abort(_('unknown changeset %s listed') % ha)
742 if action not in actiontable: 712 if action not in actiontable:
743 raise util.Abort(_('unknown action "%s"') % action) 713 raise util.Abort(_('unknown action "%s"') % action)
744 parsed.append([action, ha]) 714 parsed.append([action, ha])
745 return parsed 715 return parsed
716
717 def movebookmarks(ui, repo, replacemap, tmpnodes, created):
718 """Move bookmark from old to newly created node"""
719 ui.note(_('histedit: Should update metadata for the following '
720 'changes:\n'))
721
722 def copybms(old, new):
723 if old in tmpnodes or old in created:
724 # can't have any metadata we'd want to update
725 return
726 while new in replacemap:
727 new = replacemap[new]
728 ui.note(_('histedit: %s to %s\n') % (node.short(old),
729 node.short(new)))
730 octx = repo[old]
731 marks = octx.bookmarks()
732 if marks:
733 ui.note(_('histedit: moving bookmarks %s\n') %
734 ', '.join(marks))
735 for mark in marks:
736 repo._bookmarks[mark] = new
737 bookmarks.write(repo)
738
739 # We assume that bookmarks on the tip should remain
740 # tipmost, but bookmarks on non-tip changesets should go
741 # to their most reasonable successor. As a result, find
742 # the old tip and new tip and copy those bookmarks first,
743 # then do the rest of the bookmark copies.
744 oldtip = sorted(replacemap.keys(), key=repo.changelog.rev)[-1]
745 newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1]
746 copybms(oldtip, newtip)
747
748 for old, new in sorted(replacemap.iteritems()):
749 copybms(old, new)