[PATCH 2 of 8 cleanup] histedit: make 'constraints' a class attribut instead of a method

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Aug 26 15:35:27 EDT 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1472236498 -7200
#      Fri Aug 26 20:34:58 2016 +0200
# Node ID ad3f66039cf36f09eadd31460009aef9454ad39c
# Parent  971ddb8990c6617925d3403dd4865ca77be3db59
# EXP-Topic histedit.constraint
histedit: make 'constraints' a class attribut instead of a method

There does not seems to be a reason for this to be a method. So we initialise
the class attribute once and for all at creation time and drop the instance
method.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -392,6 +392,8 @@ class histeditaction(object):
         self.repo = state.repo
         self.node = node
 
+    constraints = set([_constraints.noduplicates, _constraints.noother])
+
     @classmethod
     def fromrule(cls, state, rule):
         """Parses the given rule, returning an instance of the histeditaction.
@@ -434,11 +436,6 @@ class histeditaction(object):
         """
         return "%s\n%s" % (self.verb, node.hex(self.node))
 
-    def constraints(self):
-        """Return a set of constrains that this action should be verified for
-        """
-        return set([_constraints.noduplicates, _constraints.noother])
-
     def run(self):
         """Runs the action. The default behavior is simply apply the action's
         rulectx onto the current parentctx."""
@@ -776,8 +773,7 @@ class fold(histeditaction):
         return repo[n], replacements
 
 class base(histeditaction):
-    def constraints(self):
-        return set([_constraints.forceother])
+    constraints = set([_constraints.forceother])
 
     def run(self):
         if self.repo['.'].node() != self.node:
@@ -1383,7 +1379,7 @@ def verifyactions(actions, state, ctxs):
     for action in actions:
         action.verify(prev)
         prev = action
-        constraints = action.constraints()
+        constraints = action.constraints
         for constraint in constraints:
             if constraint not in _constraints.known():
                 raise error.ParseError(_('unknown constraint "%s"') %


More information about the Mercurial-devel mailing list