Patchwork [6,of,6] histedit: delete all non-actionclass related code

login
register
mail settings
Submitter Durham Goode
Date April 15, 2015, 10:55 p.m.
Message ID <7607f9b638415c00ccf7.1429138556@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8701/
State Accepted
Headers show

Comments

Durham Goode - April 15, 2015, 10:55 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1428139008 25200
#      Sat Apr 04 02:16:48 2015 -0700
# Node ID 7607f9b638415c00ccf7fb84fbb972d438339cef
# Parent  bf0fdb475857f76b895f799f18ad235a7cb923f2
histedit: delete all non-actionclass related code

Now that all actions have been migrated to the class format, we can delete all
the unnecessary code that supported the old function format.
Augie Fackler - April 16, 2015, 5:48 p.m.
On Apr 15, 2015, at 6:55 PM, Durham Goode <durham@fb.com> wrote:

> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1428139008 25200
> #      Sat Apr 04 02:16:48 2015 -0700
> # Node ID 7607f9b638415c00ccf7fb84fbb972d438339cef
> # Parent  bf0fdb475857f76b895f799f18ad235a7cb923f2
> histedit: delete all non-actionclass related code

Queued these. Nice cleanups.

Change 6 is a work of art. You may want to hang it on the refrigerator or similar. ;)

> Now that all actions have been migrated to the class format, we can delete all
> the unnecessary code that supported the old function format.
> 
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -157,7 +157,6 @@ try:
> except ImportError:
>     import pickle
> import errno
> -import inspect
> import os
> import sys
> 
> @@ -760,12 +759,8 @@ def _histedit(ui, repo, state, *freeargs
>         state.write()
>         action, ha = state.rules.pop(0)
>         ui.debug('histedit: processing %s %s\n' % (action, ha[:12]))
> -        act = actiontable[action]
> -        if inspect.isclass(act):
> -            actobj = act.fromrule(state, ha)
> -            parentctx, replacement_ = actobj.run()
> -        else:
> -            parentctx, replacement_ = act(ui, state, ha, opts)
> +        actobj = actiontable[action].fromrule(state, ha)
> +        parentctx, replacement_ = actobj.run()
>         state.parentctxnode = parentctx.node()
>         state.replacements.extend(replacement_)
>     state.write()
> @@ -806,62 +801,20 @@ def _histedit(ui, repo, state, *freeargs
>     if os.path.exists(repo.sjoin('undo')):
>         os.unlink(repo.sjoin('undo'))
> 
> -def gatherchildren(repo, ctx):
> -    # is there any new commit between the expected parent and "."
> -    #
> -    # note: does not take non linear new change in account (but previous
> -    #       implementation didn't used them anyway (issue3655)
> -    newchildren = [c.node() for c in repo.set('(%d::.)', ctx)]
> -    if ctx.node() != node.nullid:
> -        if not newchildren:
> -            return []
> -        newchildren.pop(0)  # remove ctx
> -    return newchildren
> -
> def bootstrapcontinue(ui, state, opts):
> -    repo, parentctxnode = state.repo, state.parentctxnode
> +    repo = state.repo
>     action, currentnode = state.rules.pop(0)
> 
> +    actobj = actiontable[action].fromrule(state, currentnode)
> +
>     s = repo.status()
> -    replacements = []
> +    if s.modified or s.added or s.removed or s.deleted:
> +        actobj.continuedirty()
> +        s = repo.status()
> +        if s.modified or s.added or s.removed or s.deleted:
> +            raise util.Abort(_("working copy still dirty"))
> 
> -    act = actiontable[action]
> -    if inspect.isclass(act):
> -        actobj = act.fromrule(state, currentnode)
> -        if s.modified or s.added or s.removed or s.deleted:
> -            actobj.continuedirty()
> -            s = repo.status()
> -            if s.modified or s.added or s.removed or s.deleted:
> -                raise util.Abort(_("working copy still dirty"))
> -
> -        parentctx, replacements_ = actobj.continueclean()
> -        replacements.extend(replacements_)
> -    else:
> -        parentctx = repo[parentctxnode]
> -        ctx = repo[currentnode]
> -        newchildren = gatherchildren(repo, parentctx)
> -        # Commit dirty working directory if necessary
> -        new = None
> -        if s.modified or s.added or s.removed or s.deleted:
> -            # prepare the message for the commit to comes
> -            message = ctx.description()
> -            editor = cmdutil.getcommiteditor()
> -            commit = commitfuncfor(repo, ctx)
> -            new = commit(text=message, user=ctx.user(), date=ctx.date(),
> -                         extra=ctx.extra(), editor=editor)
> -            if new is not None:
> -                newchildren.append(new)
> -
> -        # track replacements
> -        if ctx.node() not in newchildren:
> -            # note: new children may be empty when the changeset is dropped.
> -            # this happen e.g during conflicting pick where we revert content
> -            # to parent.
> -            replacements.append((ctx.node(), tuple(newchildren)))
> -
> -        if newchildren:
> -            # otherwise update "parentctx" before proceeding further
> -            parentctx = repo[newchildren[-1]]
> +    parentctx, replacements = actobj.continueclean()
> 
>     state.parentctxnode = parentctx.node()
>     state.replacements.extend(replacements)

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -157,7 +157,6 @@  try:
 except ImportError:
     import pickle
 import errno
-import inspect
 import os
 import sys
 
@@ -760,12 +759,8 @@  def _histedit(ui, repo, state, *freeargs
         state.write()
         action, ha = state.rules.pop(0)
         ui.debug('histedit: processing %s %s\n' % (action, ha[:12]))
-        act = actiontable[action]
-        if inspect.isclass(act):
-            actobj = act.fromrule(state, ha)
-            parentctx, replacement_ = actobj.run()
-        else:
-            parentctx, replacement_ = act(ui, state, ha, opts)
+        actobj = actiontable[action].fromrule(state, ha)
+        parentctx, replacement_ = actobj.run()
         state.parentctxnode = parentctx.node()
         state.replacements.extend(replacement_)
     state.write()
@@ -806,62 +801,20 @@  def _histedit(ui, repo, state, *freeargs
     if os.path.exists(repo.sjoin('undo')):
         os.unlink(repo.sjoin('undo'))
 
-def gatherchildren(repo, ctx):
-    # is there any new commit between the expected parent and "."
-    #
-    # note: does not take non linear new change in account (but previous
-    #       implementation didn't used them anyway (issue3655)
-    newchildren = [c.node() for c in repo.set('(%d::.)', ctx)]
-    if ctx.node() != node.nullid:
-        if not newchildren:
-            return []
-        newchildren.pop(0)  # remove ctx
-    return newchildren
-
 def bootstrapcontinue(ui, state, opts):
-    repo, parentctxnode = state.repo, state.parentctxnode
+    repo = state.repo
     action, currentnode = state.rules.pop(0)
 
+    actobj = actiontable[action].fromrule(state, currentnode)
+
     s = repo.status()
-    replacements = []
+    if s.modified or s.added or s.removed or s.deleted:
+        actobj.continuedirty()
+        s = repo.status()
+        if s.modified or s.added or s.removed or s.deleted:
+            raise util.Abort(_("working copy still dirty"))
 
-    act = actiontable[action]
-    if inspect.isclass(act):
-        actobj = act.fromrule(state, currentnode)
-        if s.modified or s.added or s.removed or s.deleted:
-            actobj.continuedirty()
-            s = repo.status()
-            if s.modified or s.added or s.removed or s.deleted:
-                raise util.Abort(_("working copy still dirty"))
-
-        parentctx, replacements_ = actobj.continueclean()
-        replacements.extend(replacements_)
-    else:
-        parentctx = repo[parentctxnode]
-        ctx = repo[currentnode]
-        newchildren = gatherchildren(repo, parentctx)
-        # Commit dirty working directory if necessary
-        new = None
-        if s.modified or s.added or s.removed or s.deleted:
-            # prepare the message for the commit to comes
-            message = ctx.description()
-            editor = cmdutil.getcommiteditor()
-            commit = commitfuncfor(repo, ctx)
-            new = commit(text=message, user=ctx.user(), date=ctx.date(),
-                         extra=ctx.extra(), editor=editor)
-            if new is not None:
-                newchildren.append(new)
-
-        # track replacements
-        if ctx.node() not in newchildren:
-            # note: new children may be empty when the changeset is dropped.
-            # this happen e.g during conflicting pick where we revert content
-            # to parent.
-            replacements.append((ctx.node(), tuple(newchildren)))
-
-        if newchildren:
-            # otherwise update "parentctx" before proceeding further
-            parentctx = repo[newchildren[-1]]
+    parentctx, replacements = actobj.continueclean()
 
     state.parentctxnode = parentctx.node()
     state.replacements.extend(replacements)