Commits

Augie Fackler committed ecf475e

Move parsing and verification to its own function for clarity.

Comments (0)

Files changed (1)

 
     revs = between(repo, parent, tip)
 
+    ctxs = [repo[r] for r in revs]
     rules = '\n'.join([('pick %s %s' % (c.hex()[:12],
                                      c.description().splitlines()[0]))[:80]
-                       for c in (repo[r] for r in revs)])
+                       for c in ctxs])
 
     rules += editcomment % (node.hex(parent)[:12], node.hex(tip)[:12], )
 
     rules = ui.edit(rules, ui.username())
 
     parentctx = repo[parent].parents()[0]
-    first = True
+
+    rules = [l for l in (r.strip() for r in rules.splitlines()) if l and not l[0] == '#']
+    rules = verifyrules(rules, repo, ctxs)
+
     replaced = []
     tmpnodes = []
-    for r in rules.splitlines():
-        r = r.strip()
-        if not r or r[0] == '#':
-            continue
-        action, ha, junk = r.split(' ', 2)
-        if action not in actiontable:
-            raise util.Abort('unknown action "%s"' % action)
-        if first and action == 's' or action == 'squash':
-            raise util.Abort('cannot (s)quash as first action')
-        else:
-            first = False
+    for action, ha in rules:
         parentctx, replaced_, tmpnodes_ = actiontable[action](ui, repo,
                                                               parentctx, ha,
                                                               opts)
         repair.strip(ui, repo, n)
 
 
+def verifyrules(rules, repo, ctxs):
+    """Verify that there exists exactly one edit rule per given changeset.
+
+    Will abort if there are to many or too few rules, a malformed rule,
+    or a rule on a changeset outside of the user-given range.
+    """
+    parsed = []
+    first = True
+    if len(rules) != len(ctxs):
+        raise util.Abort('must specify a rule for each changeset once')
+    for r in rules:
+        if ' ' not in r:
+            raise util.Abort('malformed line "%s"' % r)
+        action, rest = r.split(' ', 1)
+        if ' ' in rest.strip():
+            ha, rest = rest.split(' ', 1)
+        else:
+            ha = r.strip()
+        try:
+            if repo[ha] not in ctxs:
+                raise util.Abort('may not use changesets other than the ones listed')
+        except error.RepoError:
+            raise util.Abort('unknown changeset %s listed' % ha)
+        if action not in actiontable:
+            raise util.Abort('unknown action "%s"' % action)
+        parsed.append([action, ha])
+    return parsed
+
+
 cmdtable = {
     "histedit":
         (histedit,