##// END OF EJS Templates
histedit: make verification configurable...
Mateusz Kwapich -
r27082:4898e442 default
parent child Browse files
Show More
@@ -334,6 +334,24 b' class histeditaction(object):'
334 raise error.Abort(_('unknown changeset %s listed') % rulehash[:12])
334 raise error.Abort(_('unknown changeset %s listed') % rulehash[:12])
335 return cls(state, node)
335 return cls(state, node)
336
336
337 def constraints(self):
338 """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 """
344
345 return set(['noduplicates', 'noother'])
346
347 def nodetoverify(self):
348 """Returns a node associated with the action that will be used for
349 verification purposes.
350
351 If the action doesn't correspond to node it should return None
352 """
353 return self.node
354
337 def run(self):
355 def run(self):
338 """Runs the action. The default behavior is simply apply the action's
356 """Runs the action. The default behavior is simply apply the action's
339 rulectx onto the current parentctx."""
357 rulectx onto the current parentctx."""
@@ -810,7 +828,7 b' def _histedit(ui, repo, state, *freeargs'
810 f.close()
828 f.close()
811 rules = [l for l in (r.strip() for r in rules.splitlines())
829 rules = [l for l in (r.strip() for r in rules.splitlines())
812 if l and not l.startswith('#')]
830 if l and not l.startswith('#')]
813 rules = verifyrules(rules, repo, [repo[c] for [_a, c] in state.rules])
831 rules = verifyrules(rules, state, [repo[c] for [_a, c] in state.rules])
814 state.rules = rules
832 state.rules = rules
815 state.write()
833 state.write()
816 return
834 return
@@ -891,7 +909,7 b' def _histedit(ui, repo, state, *freeargs'
891 f.close()
909 f.close()
892 rules = [l for l in (r.strip() for r in rules.splitlines())
910 rules = [l for l in (r.strip() for r in rules.splitlines())
893 if l and not l.startswith('#')]
911 if l and not l.startswith('#')]
894 rules = verifyrules(rules, repo, ctxs)
912 rules = verifyrules(rules, state, ctxs)
895
913
896 parentctxnode = repo[root].parents()[0].node()
914 parentctxnode = repo[root].parents()[0].node()
897
915
@@ -1039,34 +1057,42 b' def ruleeditor(repo, ui, rules, editcomm'
1039
1057
1040 return rules
1058 return rules
1041
1059
1042 def verifyrules(rules, repo, ctxs):
1060 def verifyrules(rules, state, ctxs):
1043 """Verify that there exists exactly one edit rule per given changeset.
1061 """Verify that there exists exactly one edit rule per given changeset.
1044
1062
1045 Will abort if there are to many or too few rules, a malformed rule,
1063 Will abort if there are to many or too few rules, a malformed rule,
1046 or a rule on a changeset outside of the user-given range.
1064 or a rule on a changeset outside of the user-given range.
1047 """
1065 """
1066 known_constraints = ['noother', 'noduplicates']
1048 parsed = []
1067 parsed = []
1049 expected = set(c.hex() for c in ctxs)
1068 expected = set(c.hex() for c in ctxs)
1050 seen = set()
1069 seen = set()
1051 for r in rules:
1070 for r in rules:
1052 if ' ' not in r:
1071 if ' ' not in r:
1053 raise error.Abort(_('malformed line "%s"') % r)
1072 raise error.Abort(_('malformed line "%s"') % r)
1054 action, rest = r.split(' ', 1)
1073 verb, rest = r.split(' ', 1)
1055 ha = rest.strip().split(' ', 1)[0]
1074
1056 try:
1075 if verb not in actiontable or verb.startswith('_'):
1057 ha = repo[ha].hex()
1076 raise error.Abort(_('unknown action "%s"') % verb)
1058 except error.RepoError:
1077 action = actiontable[verb].fromrule(state, rest)
1059 raise error.Abort(_('unknown changeset %s listed') % ha[:12])
1078 constraints = action.constraints()
1060 if ha not in expected:
1079 for constraint in constraints:
1061 raise error.Abort(
1080 if constraint not in known_constraints:
1062 _('may not use changesets other than the ones listed'))
1081 error.Abort(_('unknown constraint "%s"') % constraint)
1063 if ha in seen:
1082
1064 raise error.Abort(_('duplicated command for changeset %s') %
1083 nodetoverify = action.nodetoverify()
1065 ha[:12])
1084 if nodetoverify is not None:
1066 seen.add(ha)
1085 ha = node.hex(nodetoverify)
1067 if action not in actiontable or action.startswith('_'):
1086 if 'noother' in constraints and ha not in expected:
1068 raise error.Abort(_('unknown action "%s"') % action)
1087 raise error.Abort(
1069 parsed.append([action, ha])
1088 _('may not use "%s" with changesets '
1089 'other than the ones listed') % verb)
1090 if 'noduplicates' in constraints and ha in seen:
1091 raise error.Abort(_('duplicated command for changeset %s') %
1092 ha[:12])
1093 seen.add(ha)
1094 rest = ha
1095 parsed.append([verb, rest])
1070 missing = sorted(expected - seen) # sort to stabilize output
1096 missing = sorted(expected - seen) # sort to stabilize output
1071 if missing:
1097 if missing:
1072 raise error.Abort(_('missing rules for changeset %s') %
1098 raise error.Abort(_('missing rules for changeset %s') %
@@ -175,7 +175,7 b' Test that extra revisions are detected'
175 > pick c8e68270e35a 3 four
175 > pick c8e68270e35a 3 four
176 > pick 08d98a8350f3 4 five
176 > pick 08d98a8350f3 4 five
177 > EOF
177 > EOF
178 abort: may not use changesets other than the ones listed
178 abort: may not use "pick" with changesets other than the ones listed
179 [255]
179 [255]
180
180
181 Test malformed line
181 Test malformed line
@@ -281,7 +281,7 b' try with --rev'
281 > pick de71b079d9ce e
281 > pick de71b079d9ce e
282 > pick 38b92f448761 c
282 > pick 38b92f448761 c
283 > EOF
283 > EOF
284 abort: may not use changesets other than the ones listed
284 abort: may not use "pick" with changesets other than the ones listed
285 $ hg log --graph
285 $ hg log --graph
286 @ changeset: 7:803ef1c6fcfd
286 @ changeset: 7:803ef1c6fcfd
287 | tag: tip
287 | tag: tip
General Comments 0
You need to be logged in to leave comments. Login now