comparison hgext/histedit.py @ 17664:4eb13b619785

histedit: factorise node stripping logic Create a function dedicated to stripping a group of node. All existing duplicated code is replaced by call to this function. This new function take care of stripping known and relevant node only.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 26 Sep 2012 14:46:08 +0200
parents c6de8c696644
children b65533958b85
comparison
equal deleted inserted replaced
17663:c6de8c696644 17664:4eb13b619785
480 raise util.Abort(_('no arguments allowed with --abort')) 480 raise util.Abort(_('no arguments allowed with --abort'))
481 (parentctxnode, created, replaced, tmpnodes, 481 (parentctxnode, created, replaced, tmpnodes,
482 existing, rules, keep, tip, replacemap) = readstate(repo) 482 existing, rules, keep, tip, replacemap) = readstate(repo)
483 ui.debug('restore wc to old tip %s\n' % node.hex(tip)) 483 ui.debug('restore wc to old tip %s\n' % node.hex(tip))
484 hg.clean(repo, tip) 484 hg.clean(repo, tip)
485 ui.debug('should strip created nodes %s\n' % 485 cleanupnode(ui, repo, 'created', created)
486 ', '.join([node.short(n) for n in created])) 486 cleanupnode(ui, repo, 'temp', tmpnodes)
487 ui.debug('should strip temp nodes %s\n' %
488 ', '.join([node.short(n) for n in tmpnodes]))
489 for nodes in (created, tmpnodes):
490 lock = None
491 try:
492 lock = repo.lock()
493 for n in reversed(nodes):
494 try:
495 repair.strip(ui, repo, n)
496 except error.LookupError:
497 pass
498 finally:
499 lockmod.release(lock)
500 os.unlink(os.path.join(repo.path, 'histedit-state')) 487 os.unlink(os.path.join(repo.path, 'histedit-state'))
501 return 488 return
502 else: 489 else:
503 cmdutil.bailifchanged(repo) 490 cmdutil.bailifchanged(repo)
504 if os.path.exists(os.path.join(repo.path, 'histedit-state')): 491 if os.path.exists(os.path.join(repo.path, 'histedit-state')):
602 589
603 if not keep: 590 if not keep:
604 if replacemap: 591 if replacemap:
605 movebookmarks(ui, repo, replacemap, tmpnodes, created) 592 movebookmarks(ui, repo, replacemap, tmpnodes, created)
606 # TODO update mq state 593 # TODO update mq state
607 594 cleanupnode(ui, repo, 'replaced', replaced)
608 ui.debug('should strip replaced nodes %s\n' % 595
609 ', '.join([node.short(n) for n in replaced])) 596 cleanupnode(ui, repo, 'temp', tmpnodes)
610 lock = None
611 try:
612 lock = repo.lock()
613 for n in sorted(replaced, key=lambda x: repo[x].rev()):
614 try:
615 repair.strip(ui, repo, n)
616 except error.LookupError:
617 pass
618 finally:
619 lockmod.release(lock)
620
621 ui.debug('should strip temp nodes %s\n' %
622 ', '.join([node.short(n) for n in tmpnodes]))
623 lock = None
624 try:
625 lock = repo.lock()
626 for n in reversed(tmpnodes):
627 try:
628 repair.strip(ui, repo, n)
629 except error.LookupError:
630 pass
631 finally:
632 lockmod.release(lock)
633 os.unlink(os.path.join(repo.path, 'histedit-state')) 597 os.unlink(os.path.join(repo.path, 'histedit-state'))
634 if os.path.exists(repo.sjoin('undo')): 598 if os.path.exists(repo.sjoin('undo')):
635 os.unlink(repo.sjoin('undo')) 599 os.unlink(repo.sjoin('undo'))
636 600
637 601
745 newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1] 709 newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1]
746 copybms(oldtip, newtip) 710 copybms(oldtip, newtip)
747 711
748 for old, new in sorted(replacemap.iteritems()): 712 for old, new in sorted(replacemap.iteritems()):
749 copybms(old, new) 713 copybms(old, new)
714
715 def cleanupnode(ui, repo, name, nodes):
716 """strip a group of nodes from the repository
717
718 The set of node to strip may contains unknown nodes."""
719 ui.debug('should strip %s nodes %s\n' %
720 (name, ', '.join([node.short(n) for n in nodes])))
721 lock = None
722 try:
723 lock = repo.lock()
724 # Find all node that need to be stripped
725 # (we hg %lr instead of %ln to silently ignore unknown item
726 nm = repo.changelog.nodemap
727 nodes = [n for n in nodes if n in nm]
728 roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
729 for c in roots:
730 # We should process node in reverse order to strip tip most first.
731 # but this trigger a bug in changegroup hook.
732 # This would reduce bundle overhead
733 repair.strip(ui, repo, c)
734 finally:
735 lockmod.release(lock)
736