##// END OF EJS Templates
histedit: use state object where necessary...
David Soria Parra -
r22977:29ae3b19 default
parent child Browse files
Show More
@@ -560,20 +560,27 b' def _histedit(ui, repo, *freeargs, **opt'
560 560 _('histedit requires exactly one ancestor revision'))
561 561
562 562
563 replacements = []
564 keep = opts.get('keep', False)
565
566 # rebuild state
563 567 if goal == 'continue':
564 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
565 parentctx = repo[parentctxnode]
566 parentctx, repl = bootstrapcontinue(ui, repo, parentctx, rules, opts)
567 replacements.extend(repl)
568 state = readstate(repo)
569 parentctx = repo[state.parentctxnode]
570 parentctx, repl = bootstrapcontinue(ui, repo, parentctx, state.rules,
571 opts)
572 state.replacements.extend(repl)
573 state.parentctxnode = parentctx.node()
568 574 elif goal == 'abort':
569 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
570 mapping, tmpnodes, leafs, _ntm = processreplacement(repo, replacements)
571 ui.debug('restore wc to old parent %s\n' % node.short(topmost))
575 state = readstate(repo)
576 mapping, tmpnodes, leafs, _ntm = processreplacement(repo,
577 state.replacements)
578 ui.debug('restore wc to old parent %s\n' % node.short(state.topmost))
572 579 # check whether we should update away
573 580 parentnodes = [c.node() for c in repo[None].parents()]
574 for n in leafs | set([parentctxnode]):
581 for n in leafs | set([state.parentctxnode]):
575 582 if n in parentnodes:
576 hg.clean(repo, topmost)
583 hg.clean(repo, state.topmost)
577 584 break
578 585 else:
579 586 pass
@@ -599,7 +606,6 b' def _histedit(ui, repo, *freeargs, **opt'
599 606 'exactly one common root'))
600 607 root = rr[0].node()
601 608
602 keep = opts.get('keep', False)
603 609 revs = between(repo, root, topmost, keep)
604 610 if not revs:
605 611 raise util.Abort(_('%s is not an ancestor of working directory') %
@@ -629,20 +635,25 b' def _histedit(ui, repo, *freeargs, **opt'
629 635 rules = verifyrules(rules, repo, ctxs)
630 636
631 637 parentctx = repo[root].parents()[0]
632 replacements = []
633 638
639 state = histeditstate(repo, parentctx.node(), rules, keep,
640 topmost, replacements)
634 641
635 while rules:
636 writestate(repo, parentctx.node(), rules, keep, topmost, replacements)
637 action, ha = rules.pop(0)
642 while state.rules:
643 state.write()
644 action, ha = state.rules.pop(0)
638 645 ui.debug('histedit: processing %s %s\n' % (action, ha))
639 646 actfunc = actiontable[action]
640 parentctx, replacement_ = actfunc(ui, repo, parentctx, ha, opts)
641 replacements.extend(replacement_)
647 parentctx = repo[state.parentctxnode]
648 parentctx, replacement_ = actfunc(ui, repo, parentctx,
649 ha, opts)
650 state.parentctxnode = parentctx.node()
651 state.replacements.extend(replacement_)
642 652
643 hg.update(repo, parentctx.node())
653 hg.update(repo, state.parentctxnode)
644 654
645 mapping, tmpnodes, created, ntm = processreplacement(repo, replacements)
655 mapping, tmpnodes, created, ntm = processreplacement(repo,
656 state.replacements)
646 657 if mapping:
647 658 for prec, succs in mapping.iteritems():
648 659 if not succs:
@@ -657,7 +668,7 b' def _histedit(ui, repo, *freeargs, **opt'
657 668
658 669 if not keep:
659 670 if mapping:
660 movebookmarks(ui, repo, mapping, topmost, ntm)
671 movebookmarks(ui, repo, mapping, state.topmost, ntm)
661 672 # TODO update mq state
662 673 if obsolete.isenabled(repo, obsolete.createmarkersopt):
663 674 markers = []
@@ -767,23 +778,20 b' def between(repo, old, new, keep):'
767 778 raise util.Abort(_('cannot edit immutable changeset: %s') % root)
768 779 return [c.node() for c in ctxs]
769 780
770
771 def writestate(repo, parentnode, rules, keep, topmost, replacements):
772 fp = open(os.path.join(repo.path, 'histedit-state'), 'w')
773 pickle.dump((parentnode, rules, keep, topmost, replacements), fp)
774 fp.close()
775
776 781 def readstate(repo):
777 """Returns a tuple of (parentnode, rules, keep, topmost, replacements).
782 """Reads a state from file and returns a histeditstate object
778 783 """
779 784 try:
780 fp = open(os.path.join(repo.path, 'histedit-state'))
785 fp = repo.vfs('histedit-state', 'r')
781 786 except IOError, err:
782 787 if err.errno != errno.ENOENT:
783 788 raise
784 789 raise util.Abort(_('no histedit in progress'))
785 return pickle.load(fp)
790
791 (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp)
786 792
793 return histeditstate(repo, parentctxnode, rules,
794 keep, topmost, replacements)
787 795
788 796 def makedesc(c):
789 797 """build a initial action line for a ctx `c`
@@ -950,12 +958,12 b' def cleanupnode(ui, repo, name, nodes):'
950 958 def summaryhook(ui, repo):
951 959 if not os.path.exists(repo.join('histedit-state')):
952 960 return
953 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
954 if rules:
961 state = readstate(repo)
962 if state.rules:
955 963 # i18n: column positioning for "hg summary"
956 964 ui.write(_('hist: %s (histedit --continue)\n') %
957 965 (ui.label(_('%d remaining'), 'histedit.remaining') %
958 len(rules)))
966 len(state.rules)))
959 967
960 968 def extsetup(ui):
961 969 cmdutil.summaryhooks.add('histedit', summaryhook)
General Comments 0
You need to be logged in to leave comments. Login now