# HG changeset patch # User David Soria Parra # Date 1413387496 25200 # Node ID a3a981563ce83a56614c74491cfe34160e374b94 # Parent 52f10a4d13dd502a073f1bcf6e05676905927b6e 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. diff -r 52f10a4d13dd -r a3a981563ce8 hgext/histedit.py --- a/hgext/histedit.py Wed Oct 15 08:18:26 2014 -0700 +++ b/hgext/histedit.py Wed Oct 15 08:38:16 2014 -0700 @@ -201,6 +201,24 @@ else: self.replacements = replacements + def read(self): + """Reads a state from file and returns a histeditstate object + """ + try: + fp = self.repo.vfs('histedit-state', 'r') + except IOError, err: + if err.errno != errno.ENOENT: + raise + raise util.Abort(_('no histedit in progress')) + + (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp) + + self.parentctx = self.repo[parentctxnode] + self.rules = rules + self.keep = keep + self.topmost = topmost + self.replacements = replacements + def write(self): fp = self.repo.vfs('histedit-state', 'w') pickle.dump((self.parentctx.node(), self.rules, self.keep, @@ -574,10 +592,12 @@ # rebuild state if goal == 'continue': - state = readstate(repo) + state = histeditstate(repo) + state.read() state = bootstrapcontinue(ui, state, opts) elif goal == 'abort': - state = readstate(repo) + state = histeditstate(repo) + state.read() mapping, tmpnodes, leafs, _ntm = processreplacement(repo, state) ui.debug('restore wc to old parent %s\n' % node.short(state.topmost)) # check whether we should update away @@ -640,8 +660,8 @@ parentctx = repo[root].parents()[0] - state = histeditstate(repo, parentctx, rules, keep, - topmost, replacements) + state = histeditstate(repo, parentctx, rules, keep, topmost, + replacements) while state.rules: state.write() @@ -782,21 +802,6 @@ raise util.Abort(_('cannot edit immutable changeset: %s') % root) return [c.node() for c in ctxs] -def readstate(repo): - """Reads a state from file and returns a histeditstate object - """ - try: - fp = repo.vfs('histedit-state', 'r') - except IOError, err: - if err.errno != errno.ENOENT: - raise - raise util.Abort(_('no histedit in progress')) - - (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp) - - return histeditstate(repo, repo[parentctxnode], rules, - keep, topmost, replacements) - def makedesc(c): """build a initial action line for a ctx `c` @@ -963,7 +968,8 @@ def summaryhook(ui, repo): if not os.path.exists(repo.join('histedit-state')): return - state = readstate(repo) + state = histeditstate(repo) + state.read() if state.rules: # i18n: column positioning for "hg summary" ui.write(_('hist: %s (histedit --continue)\n') %