Patchwork [8,of,9] histedit: read state from histeditstate

login
register
mail settings
Submitter David Soria Parra
Date Oct. 16, 2014, 5:34 p.m.
Message ID <57e8a9f0368388c5bc3d.1413480884@davidsp-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/6338/
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 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.
Augie Fackler - Oct. 16, 2014, 6:36 p.m.
On Thu, Oct 16, 2014 at 10:34:44AM -0700, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <davidsp@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

nit: this docstring wants love

(for efficiency, I'll fix this in a followup)

> +        """
> +        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') %
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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') %