[PATCH 2 of 2] copy shared command options to prevent duplicates (issue2772)

Idan Kamara idankk86 at gmail.com
Thu May 26 11:57:43 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1306428989 -10800
# Node ID c0b716bb34d346c3c76589e3537430934898d0bd
# Parent  838230858bfba5abfa76e9ed3b57ef0681cba1a2
copy shared command options to prevent duplicates (issue2772)

If a command reuses another commands option it should copy them
to prevent possible duplicates.

This can happen if the same options are shared between two commands
and a new option is added to both commands (like --mq).

Also, a new test was added that loads all extensions in hgext/
and checks for duplicate options.

diff -r 838230858bfb -r c0b716bb34d3 hgext/mq.py
--- a/hgext/mq.py	Thu May 26 19:00:47 2011 +0300
+++ b/hgext/mq.py	Thu May 26 19:56:29 2011 +0300
@@ -3270,7 +3270,7 @@
     entry = extensions.wrapcommand(commands.table, 'init', mqinit)
     entry[1].extend(mqopt)
 
-    nowrap = set(commands.norepo.split(" ") + ['qrecord'])
+    nowrap = set(commands.norepo.split(" "))
 
     def dotable(cmdtable):
         for cmd in cmdtable.keys():
diff -r 838230858bfb -r c0b716bb34d3 hgext/record.py
--- a/hgext/record.py	Thu May 26 19:00:47 2011 +0300
+++ b/hgext/record.py	Thu May 26 19:56:29 2011 +0300
@@ -345,7 +345,7 @@
                if h[0].special() or len(h) > 1], [])
 
 @command("record",
-         commands.table['^commit|ci'][1], # same options as commit
+         commands.table['^commit|ci'][1][:], # same options as commit
           _('hg record [OPTION]... [FILE]...'))
 def record(ui, repo, *pats, **opts):
     '''interactively select changes to commit
diff -r 838230858bfb -r c0b716bb34d3 mercurial/commands.py
--- a/mercurial/commands.py	Thu May 26 19:00:47 2011 +0300
+++ b/mercurial/commands.py	Thu May 26 19:56:29 2011 +0300
@@ -2085,7 +2085,7 @@
         ui.write(' source   %s\n' % v[0])
         ui.write(' revision %s\n' % v[1])
 
- at command('debugwalk', walkopts, _('[OPTION]... [FILE]...'))
+ at command('debugwalk', walkopts[:], _('[OPTION]... [FILE]...'))
 def debugwalk(ui, repo, *pats, **opts):
     """show how files match on given patterns"""
     m = scmutil.match(repo, pats, opts)
@@ -2235,7 +2235,7 @@
                  switch_parent=opts.get('switch_parent'),
                  opts=patch.diffopts(ui, opts))
 
- at command('^forget', walkopts, _('[OPTION]... FILE...'))
+ at command('^forget', walkopts[:], _('[OPTION]... FILE...'))
 def forget(ui, repo, *pats, **opts):
     """forget the specified files on the next commit
 
diff -r 838230858bfb -r c0b716bb34d3 tests/test-duplicateoptions.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-duplicateoptions.py	Thu May 26 19:56:29 2011 +0300
@@ -0,0 +1,30 @@
+import os
+from mercurial import ui, commands, extensions
+
+hgrc = open(os.environ["HGRCPATH"], 'w')
+hgrc.write('[extensions]\n')
+
+ignore = set(['__init__.py', 'win32text.py'])
+
+if os.name != 'nt':
+    ignore.add('win32mbcs.py')
+
+# list all extensions in hgext/ and write them to hgrc
+exts = [os.path.splitext(f)[0] for f in os.listdir(os.environ["TESTDIR"] + "/../hgext/")
+        if os.path.splitext(f)[1] == '.py' and f not in ignore]
+
+map(lambda x: hgrc.write(x + '=\n'), exts)
+hgrc.close()
+
+u = ui.ui()
+extensions.loadall(u)
+
+for cmd, entry in commands.table.iteritems():
+    seenshort = set()
+    seenlong = set()
+    for option in entry[1]:
+        if (option[0] and option[0] in seenshort) or \
+           (option[1] and option[1] in seenlong):
+            print "command '" + cmd + "' has duplicate option " + str(option)
+        seenshort.add(option[0])
+        seenlong.add(option[1])
diff -r 838230858bfb -r c0b716bb34d3 tests/test-qrecord.t
--- a/tests/test-qrecord.t	Thu May 26 19:00:47 2011 +0300
+++ b/tests/test-qrecord.t	Thu May 26 19:56:29 2011 +0300
@@ -136,6 +136,7 @@
    -X --exclude PATTERN [+]  exclude names matching the given patterns
    -m --message TEXT         use text as commit message
    -l --logfile FILE         read commit message from file
+      --mq                   operate on patch repository
   
   [+] marked option can be specified multiple times
   


More information about the Mercurial-devel mailing list