Mercurial > hg
comparison hgext/histedit.py @ 27202:2226cd4f32ed
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).
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Wed, 02 Dec 2015 12:19:01 -0800 |
parents | dcb536d2e138 |
children | b6a0f0895a25 |
comparison
equal
deleted
inserted
replaced
27201:dcb536d2e138 | 27202:2226cd4f32ed |
---|---|
344 | 344 |
345 @classmethod | 345 @classmethod |
346 def fromrule(cls, state, rule): | 346 def fromrule(cls, state, rule): |
347 """Parses the given rule, returning an instance of the histeditaction. | 347 """Parses the given rule, returning an instance of the histeditaction. |
348 """ | 348 """ |
349 repo = state.repo | |
350 rulehash = rule.strip().split(' ', 1)[0] | 349 rulehash = rule.strip().split(' ', 1)[0] |
350 return cls(state, node.bin(rulehash)) | |
351 | |
352 def verify(self): | |
353 """ Verifies semantic correctness of the rule""" | |
354 repo = self.repo | |
355 ha = node.hex(self.node) | |
351 try: | 356 try: |
352 node = repo[rulehash].node() | 357 self.node = repo[ha].node() |
353 except error.RepoError: | 358 except error.RepoError: |
354 raise error.Abort(_('unknown changeset %s listed') % rulehash[:12]) | 359 raise error.Abort(_('unknown changeset %s listed') |
355 return cls(state, node) | 360 % ha[:12]) |
356 | 361 |
357 def constraints(self): | 362 def constraints(self): |
358 """Return a set of constrains that this action should be verified for | 363 """Return a set of constrains that this action should be verified for |
359 """ | 364 """ |
360 return set([_constraints.noduplicates, _constraints.noother]) | 365 return set([_constraints.noduplicates, _constraints.noother]) |
1173 verb, rest = r.split(' ', 1) | 1178 verb, rest = r.split(' ', 1) |
1174 | 1179 |
1175 if verb not in actiontable or verb.startswith('_'): | 1180 if verb not in actiontable or verb.startswith('_'): |
1176 raise error.Abort(_('unknown action "%s"') % verb) | 1181 raise error.Abort(_('unknown action "%s"') % verb) |
1177 action = actiontable[verb].fromrule(state, rest) | 1182 action = actiontable[verb].fromrule(state, rest) |
1183 action.verify() | |
1178 constraints = action.constraints() | 1184 constraints = action.constraints() |
1179 for constraint in constraints: | 1185 for constraint in constraints: |
1180 if constraint not in _constraints.known(): | 1186 if constraint not in _constraints.known(): |
1181 raise error.Abort(_('unknown constraint "%s"') % constraint) | 1187 raise error.Abort(_('unknown constraint "%s"') % constraint) |
1182 | 1188 |