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!
This commit is contained in:
Dan Villiom Podlaski Christiansen 2010-08-11 20:03:47 +02:00
parent 758d2945c3
commit 7bc9b7dc45
2 changed files with 29 additions and 6 deletions

View File

@ -178,3 +178,11 @@ Please note that some of these options may be specified as command line options
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.

View File

@ -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