diff hgext/histedit.py @ 29880:a485ec066867

histedt: use inheritance to override 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 'contraints' related enum and class attribute will be cleaned up in the next changeset.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 26 Aug 2016 21:00:33 +0200
parents b566c5992e07
children 12f8bef59bfa
line wrap: on
line diff
--- a/hgext/histedit.py	Fri Aug 26 20:54:52 2016 +0200
+++ b/hgext/histedit.py	Fri Aug 26 21:00:33 2016 +0200
@@ -414,27 +414,19 @@
         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:
+            self._verifynodeconstraints(prev, expected, seen)
 
-        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))
+    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 @@
         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