[PATCH 8 of 9] histedit: read state from histeditstate

David Soria Parra davidsp at fb.com
Thu Oct 16 12:34:44 CDT 2014


# HG changeset patch
# User David Soria Parra <davidsp at fb.com>
# Date 1413387496 25200
#      Wed Oct 15 08:38:16 2014 -0700
# Node ID 57e8a9f0368388c5bc3db11a13c8a17a72c6b184
# Parent  974fda127d6af8d24e816e1e2b647f36df28c7a8
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 --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -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') %


More information about the Mercurial-devel mailing list