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