comparison hgext/histedit.py @ 22979:bb22cd700e0a

histedit: let the state expose a context but serialize correctly to nodes The histedit code often expects a context. However histedit hands around the tuple for the serialization and therefore hand over a parentctxnode. This leads to code having to return a context based on the parentctxnode. We let the state only return a context but correctly serialize and deserialze to a node.
author David Soria Parra <davidsp@fb.com>
date Wed, 15 Oct 2014 17:11:54 -0700
parents d4e764521249
children b3483bc1ec8c
comparison
equal deleted inserted replaced
22978:d4e764521249 22979:bb22cd700e0a
187 # m, mess = edit message without changing commit content 187 # m, mess = edit message without changing commit content
188 # 188 #
189 """) 189 """)
190 190
191 class histeditstate(object): 191 class histeditstate(object):
192 def __init__(self, repo, parentctxnode=None, rules=None, keep=None, 192 def __init__(self, repo, parentctx=None, rules=None, keep=None,
193 topmost=None, replacements=None): 193 topmost=None, replacements=None):
194 self.repo = repo 194 self.repo = repo
195 self.parentctxnode = parentctxnode
196 self.rules = rules 195 self.rules = rules
197 self.keep = keep 196 self.keep = keep
198 self.topmost = topmost 197 self.topmost = topmost
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 203
204 def write(self): 204 def write(self):
205 fp = self.repo.vfs('histedit-state', 'w') 205 fp = self.repo.vfs('histedit-state', 'w')
206 pickle.dump((self.parentctxnode, self.rules, self.keep, 206 pickle.dump((self.parentctx.node(), self.rules, self.keep,
207 self.topmost, self.replacements), fp) 207 self.topmost, self.replacements), fp)
208 fp.close() 208 fp.close()
209 209
210 def clear(self): 210 def clear(self):
211 self.repo.vfs.unlink('histedit-state') 211 self.repo.vfs.unlink('histedit-state')
567 keep = opts.get('keep', False) 567 keep = opts.get('keep', False)
568 568
569 # rebuild state 569 # rebuild state
570 if goal == 'continue': 570 if goal == 'continue':
571 state = readstate(repo) 571 state = readstate(repo)
572 parentctx = repo[state.parentctxnode] 572 state.parentctx, repl = bootstrapcontinue(ui, repo, state.parentctx,
573 parentctx, repl = bootstrapcontinue(ui, repo, parentctx, state.rules, 573 state.rules, opts)
574 opts)
575 state.replacements.extend(repl) 574 state.replacements.extend(repl)
576 state.parentctxnode = parentctx.node()
577 elif goal == 'abort': 575 elif goal == 'abort':
578 state = readstate(repo) 576 state = readstate(repo)
579 mapping, tmpnodes, leafs, _ntm = processreplacement(repo, 577 mapping, tmpnodes, leafs, _ntm = processreplacement(repo,
580 state.replacements) 578 state.replacements)
581 ui.debug('restore wc to old parent %s\n' % node.short(state.topmost)) 579 ui.debug('restore wc to old parent %s\n' % node.short(state.topmost))
582 # check whether we should update away 580 # check whether we should update away
583 parentnodes = [c.node() for c in repo[None].parents()] 581 parentnodes = [c.node() for c in repo[None].parents()]
584 for n in leafs | set([state.parentctxnode]): 582 for n in leafs | set([state.parentctx.node()]):
585 if n in parentnodes: 583 if n in parentnodes:
586 hg.clean(repo, state.topmost) 584 hg.clean(repo, state.topmost)
587 break 585 break
588 else: 586 else:
589 pass 587 pass
637 if l and not l.startswith('#')] 635 if l and not l.startswith('#')]
638 rules = verifyrules(rules, repo, ctxs) 636 rules = verifyrules(rules, repo, ctxs)
639 637
640 parentctx = repo[root].parents()[0] 638 parentctx = repo[root].parents()[0]
641 639
642 state = histeditstate(repo, parentctx.node(), rules, keep, 640 state = histeditstate(repo, parentctx, rules, keep,
643 topmost, replacements) 641 topmost, replacements)
644 642
645 while state.rules: 643 while state.rules:
646 state.write() 644 state.write()
647 action, ha = state.rules.pop(0) 645 action, ha = state.rules.pop(0)
648 ui.debug('histedit: processing %s %s\n' % (action, ha)) 646 ui.debug('histedit: processing %s %s\n' % (action, ha))
649 actfunc = actiontable[action] 647 actfunc = actiontable[action]
650 parentctx = repo[state.parentctxnode] 648 state.parentctx, replacement_ = actfunc(ui, repo, state.parentctx,
651 parentctx, replacement_ = actfunc(ui, repo, parentctx,
652 ha, opts) 649 ha, opts)
653 state.parentctxnode = parentctx.node()
654 state.replacements.extend(replacement_) 650 state.replacements.extend(replacement_)
655 651
656 hg.update(repo, state.parentctxnode) 652 hg.update(repo, state.parentctx.node())
657 653
658 mapping, tmpnodes, created, ntm = processreplacement(repo, 654 mapping, tmpnodes, created, ntm = processreplacement(repo,
659 state.replacements) 655 state.replacements)
660 if mapping: 656 if mapping:
661 for prec, succs in mapping.iteritems(): 657 for prec, succs in mapping.iteritems():
791 raise 787 raise
792 raise util.Abort(_('no histedit in progress')) 788 raise util.Abort(_('no histedit in progress'))
793 789
794 (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp) 790 (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp)
795 791
796 return histeditstate(repo, parentctxnode, rules, 792 return histeditstate(repo, repo[parentctxnode], rules,
797 keep, topmost, replacements) 793 keep, topmost, replacements)
798 794
799 def makedesc(c): 795 def makedesc(c):
800 """build a initial action line for a ctx `c` 796 """build a initial action line for a ctx `c`
801 797