Patchwork [4,of,9] histedit: let the state expose a context but serialize correctly to nodes

login
register
mail settings
Submitter David Soria Parra
Date Oct. 16, 2014, 5:34 p.m.
Message ID <4e8e8f316476d1ab7bf0.1413480880@davidsp-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/6341/
State Accepted
Headers show

Comments

David Soria Parra - Oct. 16, 2014, 5:34 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1413418314 25200
#      Wed Oct 15 17:11:54 2014 -0700
# Node ID 4e8e8f316476d1ab7bf0f9feed6f11d4bae12f59
# Parent  51b72a68f2fa4aa18ceb24f344f47612bf8f9d2e
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.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -189,13 +189,13 @@ 
 """)
 
 class histeditstate(object):
-    def __init__(self, repo, parentctxnode=None, rules=None, keep=None,
+    def __init__(self, repo, parentctx=None, rules=None, keep=None,
             topmost=None, replacements=None):
         self.repo = repo
-        self.parentctxnode = parentctxnode
         self.rules = rules
         self.keep = keep
         self.topmost = topmost
+        self.parentctx = parentctx
         if replacements is None:
             self.replacements = []
         else:
@@ -203,7 +203,7 @@ 
 
     def write(self):
         fp = self.repo.vfs('histedit-state', 'w')
-        pickle.dump((self.parentctxnode, self.rules, self.keep,
+        pickle.dump((self.parentctx.node(), self.rules, self.keep,
             self.topmost, self.replacements), fp)
         fp.close()
 
@@ -569,11 +569,9 @@ 
     # rebuild state
     if goal == 'continue':
         state = readstate(repo)
-        parentctx = repo[state.parentctxnode]
-        parentctx, repl = bootstrapcontinue(ui, repo, parentctx, state.rules,
-                opts)
+        state.parentctx, repl = bootstrapcontinue(ui, repo, state.parentctx,
+                state.rules, opts)
         state.replacements.extend(repl)
-        state.parentctxnode = parentctx.node()
     elif goal == 'abort':
         state = readstate(repo)
         mapping, tmpnodes, leafs, _ntm = processreplacement(repo,
@@ -581,7 +579,7 @@ 
         ui.debug('restore wc to old parent %s\n' % node.short(state.topmost))
         # check whether we should update away
         parentnodes = [c.node() for c in repo[None].parents()]
-        for n in leafs | set([state.parentctxnode]):
+        for n in leafs | set([state.parentctx.node()]):
             if n in parentnodes:
                 hg.clean(repo, state.topmost)
                 break
@@ -639,7 +637,7 @@ 
 
         parentctx = repo[root].parents()[0]
 
-        state = histeditstate(repo, parentctx.node(), rules, keep,
+        state = histeditstate(repo, parentctx, rules, keep,
                     topmost, replacements)
 
     while state.rules:
@@ -647,13 +645,11 @@ 
         action, ha = state.rules.pop(0)
         ui.debug('histedit: processing %s %s\n' % (action, ha))
         actfunc = actiontable[action]
-        parentctx = repo[state.parentctxnode]
-        parentctx, replacement_ = actfunc(ui, repo, parentctx,
+        state.parentctx, replacement_ = actfunc(ui, repo, state.parentctx,
                 ha, opts)
-        state.parentctxnode = parentctx.node()
         state.replacements.extend(replacement_)
 
-    hg.update(repo, state.parentctxnode)
+    hg.update(repo, state.parentctx.node())
 
     mapping, tmpnodes, created, ntm = processreplacement(repo,
             state.replacements)
@@ -793,7 +789,7 @@ 
 
     (parentctxnode, rules, keep, topmost, replacements) = pickle.load(fp)
 
-    return histeditstate(repo, parentctxnode, rules,
+    return histeditstate(repo, repo[parentctxnode], rules,
         keep, topmost, replacements)
 
 def makedesc(c):