Patchwork [09,of,10] histedit: protect again duplicated entry

login
register
mail settings
Submitter Pierre-Yves David
Date April 18, 2013, 3:29 p.m.
Message ID <9de585ccdbc97f1e6cb5.1366298964@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/1422/
State Accepted, archived
Headers show

Comments

Pierre-Yves David - April 18, 2013, 3:29 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1366291344 -7200
#      Thu Apr 18 15:22:24 2013 +0200
# Node ID 9de585ccdbc97f1e6cb551a086d4087e2c208ca3
# Parent  5f2a7385734ad42ee819ae82ea4354feca17ce76
histedit: protect again duplicated entry

Before this change one would issue rules with duplicated entry. For this to
happen some other changeset had to be missing to maintain the rules length.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -715,10 +715,11 @@  def verifyrules(rules, repo, ctxs):
     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 = []
     expected = set(str(c) for c in ctxs)
+    seen = set()
     if len(rules) != len(expected):
         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)
@@ -729,10 +730,13 @@  def verifyrules(rules, repo, ctxs):
         except error.RepoError:
             raise util.Abort(_('unknown changeset %s listed') % ha)
         if ha not in expected:
             raise util.Abort(
                 _('may not use changesets other than the ones listed'))
+        if ha in seen:
+            raise util.Abort(_('duplicated command for changeset %s') % ha)
+        seen.add(ha)
         if action not in actiontable:
             raise util.Abort(_('unknown action "%s"') % action)
         parsed.append([action, ha])
     return parsed
 
diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
--- a/tests/test-histedit-arguments.t
+++ b/tests/test-histedit-arguments.t
@@ -122,10 +122,23 @@  Test unknown command
   > pick 08d98a8350f3 4 five
   > EOF
   abort: unknown action "coin"
   [255]
 
+Test duplicated changeset
+---------------------------------------
+
+So one is missing and one appear twice.
+
+  $ HGEDITOR=cat hg histedit "tip^^" --commands - << EOF
+  > pick eb57da33312f 2 three
+  > pick eb57da33312f 2 three
+  > pick 08d98a8350f3 4 five
+  > EOF
+  abort: duplicated command for changeset eb57da33312f
+  [255]
+
 Test short version of command
 ---------------------------------------
 
 Note: we use various number of white space between command name and changeset
 short hash. This test issue3893.