Show More
@@ -181,6 +181,18 b' from mercurial.i18n import _' | |||||
181 | cmdtable = {} |
|
181 | cmdtable = {} | |
182 | command = cmdutil.command(cmdtable) |
|
182 | command = cmdutil.command(cmdtable) | |
183 |
|
183 | |||
|
184 | class _constraints(object): | |||
|
185 | # aborts if there are multiple rules for one node | |||
|
186 | noduplicates = 'noduplicates' | |||
|
187 | # abort if the node does belong to edited stack | |||
|
188 | forceother = 'forceother' | |||
|
189 | # abort if the node doesn't belong to edited stack | |||
|
190 | noother = 'noother' | |||
|
191 | ||||
|
192 | @classmethod | |||
|
193 | def known(cls): | |||
|
194 | return set([v for k, v in cls.__dict__.items() if k[0] != '_']) | |||
|
195 | ||||
184 | # Note for extension authors: ONLY specify testedwith = 'internal' for |
|
196 | # Note for extension authors: ONLY specify testedwith = 'internal' for | |
185 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
197 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | |
186 | # be specifying the version(s) of Mercurial they are tested with, or |
|
198 | # be specifying the version(s) of Mercurial they are tested with, or | |
@@ -336,14 +348,8 b' class histeditaction(object):' | |||||
336 |
|
348 | |||
337 | def constraints(self): |
|
349 | def constraints(self): | |
338 | """Return a set of constrains that this action should be verified for |
|
350 | """Return a set of constrains that this action should be verified for | |
339 |
|
||||
340 | Available constraints: |
|
|||
341 | noduplicates - aborts if there are multiple rules for one node |
|
|||
342 | noother - abort if the node doesn't belong to edited stack |
|
|||
343 | forceother - abort if the node does belong to edited stack |
|
|||
344 | """ |
|
351 | """ | |
345 |
|
352 | return set([_constraints.noduplicates, _constraints.noother]) | ||
346 | return set(['noduplicates', 'noother']) |
|
|||
347 |
|
353 | |||
348 | def nodetoverify(self): |
|
354 | def nodetoverify(self): | |
349 | """Returns a node associated with the action that will be used for |
|
355 | """Returns a node associated with the action that will be used for | |
@@ -648,7 +654,7 b' class fold(histeditaction):' | |||||
648 |
|
654 | |||
649 | class base(histeditaction): |
|
655 | class base(histeditaction): | |
650 | def constraints(self): |
|
656 | def constraints(self): | |
651 |
return set([ |
|
657 | return set([_constraints.forceother]) | |
652 |
|
658 | |||
653 | def run(self): |
|
659 | def run(self): | |
654 | if self.repo['.'].node() != self.node: |
|
660 | if self.repo['.'].node() != self.node: | |
@@ -1087,7 +1093,6 b' def verifyrules(rules, state, ctxs):' | |||||
1087 | Will abort if there are to many or too few rules, a malformed rule, |
|
1093 | Will abort if there are to many or too few rules, a malformed rule, | |
1088 | or a rule on a changeset outside of the user-given range. |
|
1094 | or a rule on a changeset outside of the user-given range. | |
1089 | """ |
|
1095 | """ | |
1090 | known_constraints = ['noother', 'noduplicates'] |
|
|||
1091 | parsed = [] |
|
1096 | parsed = [] | |
1092 | expected = set(c.hex() for c in ctxs) |
|
1097 | expected = set(c.hex() for c in ctxs) | |
1093 | seen = set() |
|
1098 | seen = set() | |
@@ -1101,21 +1106,21 b' def verifyrules(rules, state, ctxs):' | |||||
1101 | action = actiontable[verb].fromrule(state, rest) |
|
1106 | action = actiontable[verb].fromrule(state, rest) | |
1102 | constraints = action.constraints() |
|
1107 | constraints = action.constraints() | |
1103 | for constraint in constraints: |
|
1108 | for constraint in constraints: | |
1104 |
if constraint not in |
|
1109 | if constraint not in _constraints.known(): | |
1105 | error.Abort(_('unknown constraint "%s"') % constraint) |
|
1110 | error.Abort(_('unknown constraint "%s"') % constraint) | |
1106 |
|
1111 | |||
1107 | nodetoverify = action.nodetoverify() |
|
1112 | nodetoverify = action.nodetoverify() | |
1108 | if nodetoverify is not None: |
|
1113 | if nodetoverify is not None: | |
1109 | ha = node.hex(nodetoverify) |
|
1114 | ha = node.hex(nodetoverify) | |
1110 |
if |
|
1115 | if _constraints.noother in constraints and ha not in expected: | |
1111 | raise error.Abort( |
|
1116 | raise error.Abort( | |
1112 | _('may not use "%s" with changesets ' |
|
1117 | _('may not use "%s" with changesets ' | |
1113 | 'other than the ones listed') % verb) |
|
1118 | 'other than the ones listed') % verb) | |
1114 |
if |
|
1119 | if _constraints.forceother in constraints and ha in expected: | |
1115 | raise error.Abort( |
|
1120 | raise error.Abort( | |
1116 | _('may not use "%s" with changesets ' |
|
1121 | _('may not use "%s" with changesets ' | |
1117 | 'within the edited list') % verb) |
|
1122 | 'within the edited list') % verb) | |
1118 |
if |
|
1123 | if _constraints.noduplicates in constraints and ha in seen: | |
1119 | raise error.Abort(_('duplicated command for changeset %s') % |
|
1124 | raise error.Abort(_('duplicated command for changeset %s') % | |
1120 | ha[:12]) |
|
1125 | ha[:12]) | |
1121 | seen.add(ha) |
|
1126 | seen.add(ha) |
General Comments 0
You need to be logged in to leave comments.
Login now