# HG changeset patch # User Dirkjan Ochtman # Date 1239210743 -7200 # Node ID a9134fa28d150d3e40bc4d3df9c04bbda026752e # Parent 1272e87546ed74c9dba86c29d7fd6cdd12e79807 Move svncommand code into __init__.py. diff --git a/__init__.py b/__init__.py --- a/__init__.py +++ b/__init__.py @@ -16,7 +16,7 @@ import os from mercurial import commands from mercurial import hg -from mercurial import util as mutil +from mercurial import util as hgutil from svn import core @@ -25,6 +25,8 @@ import svncommands import tag_repo import util +from util import svn_subcommands, svn_commands_nourl + def reposetup(ui, repo): if not util.is_svn_repo(repo): return @@ -34,13 +36,39 @@ def reposetup(ui, repo): def svn(ui, repo, subcommand, *args, **opts): '''see detailed help for list of subcommands''' + + # guess command if prefix + if subcommand not in svn_subcommands: + candidates = [] + for c in svn_subcommands: + if c.startswith(subcommand): + candidates.append(c) + if len(candidates) == 1: + subcommand = candidates[0] + + path = os.path.dirname(repo.path) try: - return svncommand.svncmd(ui, repo, subcommand, *args, **opts) + commandfunc = svn_subcommands[subcommand] + if commandfunc not in svn_commands_nourl: + opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read() + return commandfunc(ui, args=args, hg_repo_path=path, repo=repo, **opts) except core.SubversionException, e: if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: - raise mutil.Abort('It appears svn does not trust the ssl cert for this site.\n' + raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n' 'Please try running svn ls on that url first.') raise + except TypeError: + tb = traceback.extract_tb(sys.exc_info()[2]) + if len(tb) == 1: + ui.status('Bad arguments for subcommand %s\n' % subcommand) + else: + raise + except KeyError, e: + tb = traceback.extract_tb(sys.exc_info()[2]) + if len(tb) == 1: + ui.status('Unknown subcommand %s\n' % subcommand) + else: + raise def svn_fetch(ui, svn_url, hg_repo_path=None, **opts): @@ -61,7 +89,7 @@ def svn_fetch(ui, svn_url, hg_repo_path= res = svncommands.pull(ui, svn_url, hg_repo_path, **opts) except core.SubversionException, e: if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: - raise mutil.Abort('It appears svn does not trust the ssl cert for this site.\n' + raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n' 'Please try running svn ls on that url first.') raise if (res is None or res == 0) and should_update: diff --git a/svncommand.py b/svncommand.py deleted file mode 100644 --- a/svncommand.py +++ /dev/null @@ -1,41 +0,0 @@ -import os -import sys -import traceback - -from util import svn_subcommands, svn_commands_nourl -# dirty trick to force demandimport to run my decorator anyway. -from svncommands import pull, diff, rebuildmeta -from utility_commands import print_wc_url -# shut up, pyflakes, we must import those -__x = [print_wc_url, pull, diff, rebuildmeta] - - -def svncmd(ui, repo, subcommand, *args, **opts): - if subcommand not in svn_subcommands: - candidates = [] - for c in svn_subcommands: - if c.startswith(subcommand): - candidates.append(c) - if len(candidates) == 1: - subcommand = candidates[0] - path = os.path.dirname(repo.path) - try: - commandfunc = svn_subcommands[subcommand] - if commandfunc not in svn_commands_nourl: - opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read() - return commandfunc(ui, args=args, - hg_repo_path=path, - repo=repo, - **opts) - except TypeError: - tb = traceback.extract_tb(sys.exc_info()[2]) - if len(tb) == 1: - ui.status('Bad arguments for subcommand %s\n' % subcommand) - else: - raise - except KeyError, e: - tb = traceback.extract_tb(sys.exc_info()[2]) - if len(tb) == 1: - ui.status('Unknown subcommand %s\n' % subcommand) - else: - raise