[PATCH 3 of 9] histedit: add verify() to histeditaction

Mateusz Kwapich mitrandir at fb.com
Wed Dec 2 14:22:55 CST 2015


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1449087541 28800
#      Wed Dec 02 12:19:01 2015 -0800
# Node ID 9de112c4ad9af076221545fc36e09e5b13e639be
# Parent  bd6573e0e6afe2416572343d38547917e3205ac0
histedit: add verify() to histeditaction

This commits splits the parsing of the histedit rule from its semantic analysis.
It's necessary because sometimes we want to do first without doing the former (reading the
histedit state).

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -346,13 +346,18 @@
     def fromrule(cls, state, rule):
         """Parses the given rule, returning an instance of the histeditaction.
         """
-        repo = state.repo
         rulehash = rule.strip().split(' ', 1)[0]
+        return cls(state, node.bin(rulehash))
+
+    def verify(self):
+        """ Verifies semantic correctness of the rule"""
+        repo = self.repo
+        ha = node.hex(self.node)
         try:
-            node = repo[rulehash].node()
+            self.node = repo[ha].node()
         except error.RepoError:
-            raise error.Abort(_('unknown changeset %s listed') % rulehash[:12])
-        return cls(state, node)
+            raise error.Abort(_('unknown changeset %s listed')
+                              % ha[:12])
 
     def constraints(self):
         """Return a set of constrains that this action should be verified for
@@ -1175,6 +1180,7 @@
         if verb not in actiontable or verb.startswith('_'):
             raise error.Abort(_('unknown action "%s"') % verb)
         action = actiontable[verb].fromrule(state, rest)
+        action.verify()
         constraints = action.constraints()
         for constraint in constraints:
             if constraint not in _constraints.known():


More information about the Mercurial-devel mailing list