changeset 607:b5f1b629c629

svn_swig_wrapper: improved handling of missing or outdated bindings. Instead of aborting with a generic message when Subversion bindings are missing, provide a helpful message. Also, the version check is refactored to make it easier to bump our requirements in the future. Finally, error messages are shorten so they fit in 80 columns along with the standard `abort: ' prefix.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 30 Apr 2010 17:35:36 +0200
parents 789eec0a339c
children d1de8bb6e11f
files hgsubversion/svnwrap/svn_swig_wrapper.py
diffstat 1 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svnwrap/svn_swig_wrapper.py
+++ b/hgsubversion/svnwrap/svn_swig_wrapper.py
@@ -14,22 +14,29 @@ warnings.filterwarnings('ignore',
                         module='svn.core',
                         category=DeprecationWarning)
 
-from svn import client
-from svn import core
-from svn import delta
-from svn import ra
-
 from mercurial import util as hgutil
 
+required_bindings = (1, 5, 0)
+
+try:
+    from svn import client
+    from svn import core
+    from svn import delta
+    from svn import ra
+
+    current_bindings = (core.SVN_VER_MAJOR, core.SVN_VER_MINOR,
+                        core.SVN_VER_MICRO)
+except ImportError:
+    raise ImportError('Subversion %d.%d.%d or later required, '
+                      'but no bindings were found' % required_bindings)
+
+if current_bindings < required_bindings: #pragma: no cover
+    raise ImportError('Subversion %d.%d.%d or later required, '
+                      'but bindings for %d.%d.%d found' %
+                      (required_bindings + current_bindings))
+
 def version():
-    return '%d.%d.%d' % (core.SVN_VER_MAJOR, core.SVN_VER_MINOR,
-                         core.SVN_VER_MICRO)
-
-if (core.SVN_VER_MAJOR, core.SVN_VER_MINOR,
-    core.SVN_VER_MICRO) < (1, 5, 0): #pragma: no cover
-    raise ImportError, ('You must have Subversion 1.5.0 or newer and '
-                        'matching SWIG bindings. You appear to'
-                        ' have %s' % version())
+    return '%d.%d.%d' % current_bindings
 
 class SubversionRepoCanNotReplay(Exception):
     """Exception raised when the svn server is too old to have replay.