changeset 29879:b566c5992e07

histedit: move constraint verification to the 'action.verify' method Action has a method dedicated to verifying its validity. So we move code related to constrains into that method. This requires a bit more context to the 'verify' method in the same fashion we were passing the 'prev' argument. This is an extra step before we can simplify the constraint handling code further.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 26 Aug 2016 20:54:52 +0200
parents d7de02efa47e
children a485ec066867
files hgext/histedit.py
diffstat 1 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Fri Aug 26 20:54:32 2016 +0200
+++ b/hgext/histedit.py	Fri Aug 26 20:54:52 2016 +0200
@@ -405,7 +405,7 @@
             raise error.ParseError("invalid changeset %s" % rulehash)
         return cls(state, rev)
 
-    def verify(self, prev):
+    def verify(self, prev, expected, seen):
         """ Verifies semantic correctness of the rule"""
         repo = self.repo
         ha = node.hex(self.node)
@@ -414,6 +414,27 @@
         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))
 
     def torule(self):
         """build a histedit rule line for an action
@@ -661,9 +682,9 @@
 @action(['fold', 'f'],
         _('use commit, but combine it with the one above'))
 class fold(histeditaction):
-    def verify(self, prev):
+    def verify(self, prev, expected, seen):
         """ Verifies semantic correctness of the fold rule"""
-        super(fold, self).verify(prev)
+        super(fold, self).verify(prev, expected, seen)
         repo = self.repo
         if not prev:
             c = repo[self.node].parents()[0]
@@ -1377,29 +1398,9 @@
     seen = set()
     prev = None
     for action in actions:
-        action.verify(prev)
+        action.verify(prev, expected, seen)
         prev = action
-        constrs = action.constraints
-        for constraint in constrs:
-            if constraint not in _constraints.known():
-                raise error.ParseError(_('unknown constraint "%s"') %
-                        constraint)
-
         if action.node is not None:
-            if _constraints.noother in constrs and action.node not in expected:
-                raise error.ParseError(
-                    _('%s "%s" changeset was not a candidate')
-                     % (action.verb, node.short(action.node)),
-                    hint=_('only use listed changesets'))
-            if _constraints.forceother in constrs and action.node in expected:
-                raise error.ParseError(
-                    _('%s "%s" changeset was not an edited list candidate')
-                     % (action.verb, node.short(action.node)),
-                    hint=_('only use listed changesets'))
-            if _constraints.noduplicates in constrs and action.node in seen:
-                raise error.ParseError(_(
-                        'duplicated command for changeset %s') %
-                        node.short(action.node))
             seen.add(action.node)
     missing = sorted(expected - seen)  # sort to stabilize output