# HG changeset patch # User Simon Law # Date 1187641735 14400 # Node ID d865dae2261bcd7beb4f7a694e024906f2b88068 # Parent 8648e7ba97e87928872aa1f27ec2f5b7eb888447 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 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]