[cig-commits] commit: Refactor the findcmd compatibility system to prefer the newer syntax.

Mercurial hg at geodynamics.org
Mon Nov 24 11:27:07 PST 2008


changeset:   57:d865dae2261b
user:        Simon Law <simon at akoha.org>
date:        Mon Aug 20 16:28:55 2007 -0400
files:       forest.py
description:
Refactor the findcmd compatibility system to prefer the newer syntax.

The code's usage of findcmd() looks like Mercurial tip, so merging this
extension will become easier.


diff -r 8648e7ba97e8 -r d865dae2261b forest.py
--- a/forest.py	Wed Aug 15 10:50:30 2007 -0400
+++ b/forest.py	Mon Aug 20 16:28:55 2007 -0400
@@ -48,27 +48,35 @@ import os
 import os
 import re
 
-from mercurial import commands, hg, node, util
+from mercurial import cmdutil, commands, hg, node, util
 from mercurial import localrepo, sshrepo, sshserver, httprepo, statichttprepo
 from mercurial.hgweb import hgweb_mod
-try:
-    _findcmd = commands.findcmd
-except AttributeError:
-    from mercurial import cmdutil
-    _findcmd = cmdutil.findcmd
 from mercurial.i18n import gettext as _
 from mercurial.repo import RepoError
 
+# For backwards compatibility, we need the following function definition.
+# If we didn't want that, we'd have just written:
+#     from mercurial.commands import 
+def findcmd(ui, cmd, table):
+    """Find and execute mercurial.*.findcmd(ui, cmd[, table])."""
+    try:
+        return findcmd.findcmd(ui, cmd, table)
+    except TypeError:
+        return findcmd.findcmd(ui, cmd)
+try:
+    findcmd.findcmd = cmdutil.findcmd
+    findcmd.__doc__ = cmdutil.findcmd.__doc__
+except AttributeError:
+    findcmd.findcmd = commands.findcmd
+    findcmd.__doc__ = commands.findcmd.__doc__
+
 cmdtable = None
 
 commands.norepo += " fclone fseed"
 
 
 def cmd_options(ui, cmd, remove=None):
-    try:
-        aliases, spec = _findcmd(ui, cmd, commands.table)
-    except TypeError:
-        aliases, spec = _findcmd(ui, cmd)
+    aliases, spec = findcmd(ui, cmd, commands.table)
     res = list(spec[1])
     if remove is not None:
         res = [opt for opt in res if opt[0] not in remove]



More information about the CIG-COMMITS mailing list