# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1281549827 -7200 # Node ID 703f33576ad89d023c9252151afb2263b14308e4 # Parent 0b4e323ebedd3b5a98e6211be098e3961f251b8d svnwrap: add runtime override for choice of Subversion bindings By setting the `HGSUBVERSION_BINDINGS environment variable to either `SWIG' or `Subvertpy', the choice of bindings can be forced at runtime. (For ease of use, the comparison is case-insensitive.) Examples: % HGSUBVERSION_BINDINGS=swig hg version --svn Mercurial Distributed SCM (version 1.6+172-b25e1ced9861) ... hgsubversion: 1.1.2+43-276742da2d85 Subversion: 1.6.12 bindings: SWIG % HGSUBVERSION_BINDINGS=subvertpy hg version --svn Mercurial Distributed SCM (version 1.6+172-b25e1ced9861) ... hgsubversion: 1.1.2+43-276742da2d85 Subversion: 1.6.12 bindings: Subvertpy 0.7.4 % HGSUBVERSION_BINDINGS=none hg version --svn Mercurial Distributed SCM (version 1.6+172-b25e1ced9861) ... abort: cannot use hgsubversion; bindings disabled using HGSUBVERSION_BINDINGS! diff --git a/hgsubversion/help/subversion.rst b/hgsubversion/help/subversion.rst --- a/hgsubversion/help/subversion.rst +++ b/hgsubversion/help/subversion.rst @@ -178,3 +178,11 @@ Please note that some of these options m as well, and when done so, will override the configuration. If an authormap, filemap or branchmap is specified, its contents will be read and stored for use in future pulls. + +Finally, the following environment variables can be used for testing a +deployment of hgsubversion: + + HGSUBVERSION_BINDINGS + By default, hgsubversion will use Subvertpy, but fall back to the SWIG + bindings. Set this variable to either ``SWIG`` or ``Subvertpy`` (case- + insensitive) to force that set of bindings. diff --git a/hgsubversion/svnwrap/__init__.py b/hgsubversion/svnwrap/__init__.py --- a/hgsubversion/svnwrap/__init__.py +++ b/hgsubversion/svnwrap/__init__.py @@ -8,11 +8,26 @@ present. from common import * -try: +import os + +choice = os.environ.get('HGSUBVERSION_BINDINGS', '').lower() + +if choice == 'subvertpy': from subvertpy_wrapper import * -except ImportError, e: +elif choice == 'swig': + from svn_swig_wrapper import * +elif choice == 'none': + # useful for verifying that demandimport works properly + raise ImportError('cannot use hgsubversion; ' + 'bindings disabled using HGSUBVERSION_BINDINGS') +else: try: - from svn_swig_wrapper import * - except ImportError: - # propagate the subvertpy error; it's easier to install - import subvertpy_wrapper + from subvertpy_wrapper import * + except ImportError, e: + try: + from svn_swig_wrapper import * + except ImportError: + # propagate the subvertpy error; it's easier to install + raise e + +del os, choice