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

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 26, 2016, 7:35 p.m.
Message ID <ad3f66039cf36f09eadd.1472240127@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16463/
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 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.
timeless - Aug. 26, 2016, 7:53 p.m.
On Fri, Aug 26, 2016 at 3:35 PM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
> histedit: make 'constraints' a class attribut instead of a method

attribute

Patch

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"') %