histedit: convert pick action into a class
authorDurham Goode <durham@fb.com>
Sat, 04 Apr 2015 11:39:08 -0700
changeset 24767 477e76936b1d
parent 24766 cfb8f5e3ca49
child 24768 342671704344
histedit: convert pick action into a class This converts the pick action into a histeditclass instance, as part of an ongoing effort to refactor histedit for maintainability and robustness. The test output changed because previously pick would only report the commit disappearing if there were no merge conflicts. Now that we've unified the normal and the --continue flows, they act the same and we get the warning even after --continue.
hgext/histedit.py
tests/test-histedit-fold-non-commute.t
tests/test-histedit-non-commute.t
--- a/hgext/histedit.py	Sat Apr 04 11:37:08 2015 -0700
+++ b/hgext/histedit.py	Sat Apr 04 11:39:08 2015 -0700
@@ -487,28 +487,14 @@
                          editor=editor)
     return repo.commitctx(new)
 
-def pick(ui, state, ha, opts):
-    repo, ctxnode = state.repo, state.parentctxnode
-    ctx = repo[ctxnode]
-    oldctx = repo[ha]
-    if oldctx.parents()[0] == ctx:
-        ui.debug('node %s unchanged\n' % ha[:12])
-        return oldctx, []
-    hg.update(repo, ctx.node())
-    stats = applychanges(ui, repo, oldctx, opts)
-    if stats and stats[3] > 0:
-        raise error.InterventionRequired(_('Fix up the change and run '
-                                           'hg histedit --continue'))
-    # drop the second merge parent
-    commit = commitfuncfor(repo, oldctx)
-    n = commit(text=oldctx.description(), user=oldctx.user(),
-               date=oldctx.date(), extra=oldctx.extra())
-    if n is None:
-        ui.warn(_('%s: empty changeset\n') % ha[:12])
-        return ctx, []
-    new = repo[n]
-    return new, [(oldctx.node(), (n,))]
+class pick(histeditaction):
+    def run(self):
+        rulectx = self.repo[self.node]
+        if rulectx.parents()[0].node() == self.state.parentctxnode:
+            self.repo.ui.debug('node %s unchanged\n' % node.short(self.node))
+            return rulectx, []
 
+        return super(pick, self).run()
 
 def edit(ui, state, ha, opts):
     repo, ctxnode = state.repo, state.parentctxnode
@@ -939,7 +925,7 @@
             else:
                 message = ctx.description()
             editopt = action in ('e', 'edit', 'm', 'mess')
-            canonaction = {'e': 'edit', 'm': 'mess', 'p': 'pick'}
+            canonaction = {'e': 'edit', 'm': 'mess'}
             editform = 'histedit.%s' % canonaction.get(action, action)
             editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
             commit = commitfuncfor(repo, ctx)
--- a/tests/test-histedit-fold-non-commute.t	Sat Apr 04 11:37:08 2015 -0700
+++ b/tests/test-histedit-fold-non-commute.t	Sat Apr 04 11:39:08 2015 -0700
@@ -132,6 +132,7 @@
   $ hg resolve --mark e
   (no more unresolved files)
   $ hg histedit --continue 2>&1 | fixbundle
+  7b4e2f4b7bcd: empty changeset
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
@@ -274,6 +275,7 @@
   $ hg resolve --mark e
   (no more unresolved files)
   $ hg histedit --continue 2>&1 | fixbundle
+  7b4e2f4b7bcd: empty changeset
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
--- a/tests/test-histedit-non-commute.t	Sat Apr 04 11:37:08 2015 -0700
+++ b/tests/test-histedit-non-commute.t	Sat Apr 04 11:39:08 2015 -0700
@@ -170,6 +170,7 @@
   $ hg resolve --mark e
   (no more unresolved files)
   $ hg histedit --continue 2>&1 | fixbundle
+  7b4e2f4b7bcd: empty changeset
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
@@ -253,6 +254,7 @@
   $ hg resolve --mark e
   (no more unresolved files)
   $ hg histedit --continue 2>&1 | fixbundle
+  7b4e2f4b7bcd: empty changeset
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved