Patchwork [7,of,8,cleanup] histedt: use inheritance to overwrite the constraints in 'base'

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 26, 2016, 7:35 p.m.
Message ID <c4809d82bb0ae1b068a0.1472240132@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16465/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 26, 2016, 7:35 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1472238033 -7200
#      Fri Aug 26 21:00:33 2016 +0200
# Node ID c4809d82bb0ae1b068a0fdac1e1012d8182624df
# Parent  debc7d681908d1d1857be09c33869bb453310760
# EXP-Topic histedit.constraint
histedt: use inheritance to overwrite the constraints in 'base'

All actions but one actually have the same constraints when it comes to validate
the 'action.node' value. So we actually just add this code to a method that can
be overwritten in the one action where it matters.

The now unused 'contrains' related enum and class attribute will be cleaned up
in the next changeset.
timeless - Aug. 26, 2016, 8 p.m.
On Fri, Aug 26, 2016 at 3:35 PM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
> be overwritten in the one action where it matters.

overridden (we aren't writing over it, we're just ordering something
else to happen)

> The now unused 'contrains' related enum and class attribute will be cleaned up

constraints

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -414,27 +414,19 @@  class histeditaction(object):
         except error.RepoError:
             raise error.ParseError(_('unknown changeset %s listed')
                               % ha[:12])
-        for constraint in self.constraints:
-            if constraint not in _constraints.known():
-                raise error.ParseError(_('unknown constraint "%s"') %
-                        constraint)
-
         if self.node is not None:
-            constrs = self.constraints
-            if _constraints.noother in constrs and self.node not in expected:
-                raise error.ParseError(
-                    _('%s "%s" changeset was not a candidate')
-                     % (self.verb, node.short(self.node)),
-                    hint=_('only use listed changesets'))
-            if _constraints.forceother in constrs and self.node in expected:
-                raise error.ParseError(
-                    _('%s "%s" changeset was not an edited list candidate')
-                     % (self.verb, node.short(self.node)),
-                    hint=_('only use listed changesets'))
-            if _constraints.noduplicates in constrs and self.node in seen:
-                raise error.ParseError(_(
-                        'duplicated command for changeset %s') %
-                        node.short(self.node))
+            self._verifynodeconstraints(prev, expected, seen)
+
+    def _verifynodeconstraints(self, prev, expected, seen):
+        # by default command need a node in the edited list
+        if self.node not in expected:
+            raise error.ParseError(_('%s "%s" changeset was not a candidate')
+                                   % (self.verb, node.short(self.node)),
+                                   hint=_('only use listed changesets'))
+        # and only one command per node
+        if self.node in seen:
+            raise error.ParseError(_('duplicated command for changeset %s') %
+                                   node.short(self.node))
 
     def torule(self):
         """build a histedit rule line for an action
@@ -809,6 +801,13 @@  class base(histeditaction):
         basectx = self.repo['.']
         return basectx, []
 
+    def _verifynodeconstraints(self, prev, expected, seen):
+        # base can only be use with a node not in the edited set
+        if self.node in expected:
+            msg = _('%s "%s" changeset was not an edited list candidate')
+            raise error.ParseError(msg % (self.verb, node.short(self.node)),
+                                   hint=_('only use listed changesets'))
+
 @action(['_multifold'],
         _(
     """fold subclass used for when multiple folds happen in a row