comparison hgext/histedit.py @ 22983:a3a981563ce8

histedit: read state from histeditstate Read the state in histeditstate. This allows us to correctly update internal variables when necessary without having to recreate a new state. When we read a state in _histedit state while we will already have state passed from histedit(), we can read the state in place and don't have to merge two histeditstates.
author David Soria Parra <davidsp@fb.com>
date Wed, 15 Oct 2014 08:38:16 -0700
parents 52f10a4d13dd
children e0b5f5e3afe8
comparison
equal deleted inserted replaced
22982:52f10a4d13dd 22983:a3a981563ce8
198 self.parentctx = parentctx 198 self.parentctx = parentctx
199 if replacements is None: 199 if replacements is None:
200 self.replacements = [] 200 self.replacements = []
201 else: 201 else:
202 self.replacements = replacements 202 self.replacements = replacements
203
204 def read(self):
205 """Reads a state from file and returns a histeditstate object
206 """
207 try:
208 fp = self.repo.vfs('histedit-state', 'r')
209 except IOError, err:
210 if err.errno != errno.ENOENT:
211 raise
212 raise util.Abort(_('no histedit in progress'))
213
214 (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp)
215
216 self.parentctx = self.repo[parentctxnode]
217 self.rules = rules
218 self.keep = keep
219 self.topmost = topmost
220 self.replacements = replacements
203 221
204 def write(self): 222 def write(self):
205 fp = self.repo.vfs('histedit-state', 'w') 223 fp = self.repo.vfs('histedit-state', 'w')
206 pickle.dump((self.parentctx.node(), self.rules, self.keep, 224 pickle.dump((self.parentctx.node(), self.rules, self.keep,
207 self.topmost, self.replacements), fp) 225 self.topmost, self.replacements), fp)
572 replacements = [] 590 replacements = []
573 keep = opts.get('keep', False) 591 keep = opts.get('keep', False)
574 592
575 # rebuild state 593 # rebuild state
576 if goal == 'continue': 594 if goal == 'continue':
577 state = readstate(repo) 595 state = histeditstate(repo)
596 state.read()
578 state = bootstrapcontinue(ui, state, opts) 597 state = bootstrapcontinue(ui, state, opts)
579 elif goal == 'abort': 598 elif goal == 'abort':
580 state = readstate(repo) 599 state = histeditstate(repo)
600 state.read()
581 mapping, tmpnodes, leafs, _ntm = processreplacement(repo, state) 601 mapping, tmpnodes, leafs, _ntm = processreplacement(repo, state)
582 ui.debug('restore wc to old parent %s\n' % node.short(state.topmost)) 602 ui.debug('restore wc to old parent %s\n' % node.short(state.topmost))
583 # check whether we should update away 603 # check whether we should update away
584 parentnodes = [c.node() for c in repo[None].parents()] 604 parentnodes = [c.node() for c in repo[None].parents()]
585 for n in leafs | set([state.parentctx.node()]): 605 for n in leafs | set([state.parentctx.node()]):
638 if l and not l.startswith('#')] 658 if l and not l.startswith('#')]
639 rules = verifyrules(rules, repo, ctxs) 659 rules = verifyrules(rules, repo, ctxs)
640 660
641 parentctx = repo[root].parents()[0] 661 parentctx = repo[root].parents()[0]
642 662
643 state = histeditstate(repo, parentctx, rules, keep, 663 state = histeditstate(repo, parentctx, rules, keep, topmost,
644 topmost, replacements) 664 replacements)
645 665
646 while state.rules: 666 while state.rules:
647 state.write() 667 state.write()
648 action, ha = state.rules.pop(0) 668 action, ha = state.rules.pop(0)
649 ui.debug('histedit: processing %s %s\n' % (action, ha)) 669 ui.debug('histedit: processing %s %s\n' % (action, ha))
779 raise util.Abort(_('cannot edit history that contains merges')) 799 raise util.Abort(_('cannot edit history that contains merges'))
780 root = ctxs[0] # list is already sorted by repo.set 800 root = ctxs[0] # list is already sorted by repo.set
781 if not root.mutable(): 801 if not root.mutable():
782 raise util.Abort(_('cannot edit immutable changeset: %s') % root) 802 raise util.Abort(_('cannot edit immutable changeset: %s') % root)
783 return [c.node() for c in ctxs] 803 return [c.node() for c in ctxs]
784
785 def readstate(repo):
786 """Reads a state from file and returns a histeditstate object
787 """
788 try:
789 fp = repo.vfs('histedit-state', 'r')
790 except IOError, err:
791 if err.errno != errno.ENOENT:
792 raise
793 raise util.Abort(_('no histedit in progress'))
794
795 (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp)
796
797 return histeditstate(repo, repo[parentctxnode], rules,
798 keep, topmost, replacements)
799 804
800 def makedesc(c): 805 def makedesc(c):
801 """build a initial action line for a ctx `c` 806 """build a initial action line for a ctx `c`
802 807
803 line are in the form: 808 line are in the form:
961 release(lock) 966 release(lock)
962 967
963 def summaryhook(ui, repo): 968 def summaryhook(ui, repo):
964 if not os.path.exists(repo.join('histedit-state')): 969 if not os.path.exists(repo.join('histedit-state')):
965 return 970 return
966 state = readstate(repo) 971 state = histeditstate(repo)
972 state.read()
967 if state.rules: 973 if state.rules:
968 # i18n: column positioning for "hg summary" 974 # i18n: column positioning for "hg summary"
969 ui.write(_('hist: %s (histedit --continue)\n') % 975 ui.write(_('hist: %s (histedit --continue)\n') %
970 (ui.label(_('%d remaining'), 'histedit.remaining') % 976 (ui.label(_('%d remaining'), 'histedit.remaining') %
971 len(state.rules))) 977 len(state.rules)))