Fix bug in revid caching.
[jelmer/subvertpy.git] / __init__.py
index fd496934f404d2625944b99fd010a636f762d72b..ba74d16a0450b84abcc309e7970f556f3af8c476 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2005-2006 Jelmer Vernooij <jelmer@samba.org>
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,27 +22,22 @@ import sys
 import unittest
 import bzrlib
 
-__version__ = '0.3.0'
-required_bzr_version = (0,15)
+from bzrlib.trace import warning
+
+__version__ = '0.4.0'
+COMPATIBLE_BZR_VERSIONS = [(0, 15), (0, 16), (0, 17)]
 
 def check_bzrlib_version(desired):
     """Check that bzrlib is compatible.
 
-    If version is < desired version, assume incompatible.
-    If version == desired version, assume completely compatible
-    If version == desired version + 1, assume compatible, with deprecations
+    If version is < all compatible version, assume incompatible.
+    If version is compatible version + 1, assume compatible, with deprecations
     Otherwise, assume incompatible.
     """
-    desired_plus = (desired[0], desired[1]+1)
     bzrlib_version = bzrlib.version_info[:2]
-    if bzrlib_version == desired:
+    if bzrlib_version in desired:
         return
-    try:
-        from bzrlib.trace import warning
-    except ImportError:
-        # get the message out any way we can
-        from warnings import warn as warning
-    if bzrlib_version < desired:
+    if bzrlib_version < desired[0]:
         warning('Installed bzr version %s is too old to be used with bzr-svn'
                 ' %s.' % (bzrlib.__version__, __version__))
         # Not using BzrNewError, because it may not exist.
@@ -51,43 +46,21 @@ def check_bzrlib_version(desired):
         warning('bzr-svn is not up to date with installed bzr version %s.'
                 ' \nThere should be a newer version of bzr-svn available.' 
                 % (bzrlib.__version__))
-        if bzrlib_version != desired_plus:
+        if not (bzrlib_version[0], bzrlib_version[1]-1) in desired:
             raise Exception, 'Version mismatch'
 
 def check_subversion_version():
     """Check that Subversion is compatible.
 
     """
-    from bzrlib.trace import warning
-    try:
-        from svn.delta import svn_delta_invoke_txdelta_window_handler
-    except:
-        warning('Installed Subversion version does not have updated Python bindings. See the bzr-svn README for details.')
+    import svn.delta
+    if not hasattr(svn.delta, 'svn_delta_invoke_txdelta_window_handler'):
+        warning('Installed Subversion version does not have updated Python '
+                'bindings. See the bzr-svn README for details.')
         raise bzrlib.errors.BzrError("incompatible python subversion bindings")
 
-def check_pysqlite_version():
-    """Check that sqlite library is compatible.
-
-    """
-    from bzrlib.trace import warning
-    try:
-        try:
-            import sqlite3
-        except ImportError:
-            from pysqlite2 import dbapi2 as sqlite3
-    except:
-        warning('Needs at least Python2.5 or Python2.4 with the pysqlite2 module')
-        raise bzrlib.errors.BzrError("missing sqlite library")
-
-    if (sqlite3.sqlite_version_info[0] < 3 or 
-            (sqlite3.sqlite_version_info[0] == 3 and 
-             sqlite3.sqlite_version_info[1] < 3)):
-        warning('Needs at least sqlite 3.3.x')
-        raise bzrlib.errors.BzrError("incompatible sqlite library")
-
-check_bzrlib_version(required_bzr_version)
+check_bzrlib_version(COMPATIBLE_BZR_VERSIONS)
 check_subversion_version()
-check_pysqlite_version()
 
 import branch
 import convert
@@ -103,20 +76,18 @@ from bzrlib.bzrdir import BzrDirFormat
 
 from bzrlib.repository import InterRepository
 
-from fetch import InterSvnRepository
+from fetch import InterFromSvnRepository
+from commit import InterToSvnRepository
 
 BzrDirFormat.register_control_format(format.SvnFormat)
 
 import svn.core
-subr_version = svn.core.svn_subr_version()
+_subr_version = svn.core.svn_subr_version()
 
-if subr_version.major == 1 and subr_version.minor < 4:
-    from bzrlib.trace import warning
-    warning('Subversion version too old for working tree support.')
-else:
-    BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
+BzrDirFormat.register_control_format(checkout.SvnWorkingTreeDirFormat)
 
-InterRepository.register_optimiser(InterSvnRepository)
+InterRepository.register_optimiser(InterFromSvnRepository)
+InterRepository.register_optimiser(InterToSvnRepository)
 
 from bzrlib.branch import Branch
 from bzrlib.commands import Command, register_command, display_command, Option
@@ -142,7 +113,9 @@ class cmd_svn_import(Command):
     takes_args = ['from_location', 'to_location?']
     takes_options = [Option('trees', help='Create working trees'),
                      Option('shared', help='Create shared repository'),
-                     Option('all', help='Convert all revisions, even those not in current branch history (implies --shared)'),
+                     Option('all', 
+                         help='Convert all revisions, even those not in '
+                              'current branch history (implies --shared)'),
                      Option('scheme', type=get_scheme,
                          help='Branching scheme (none, trunk, or trunk-INT)')]
 
@@ -199,18 +172,16 @@ register_command(cmd_svn_upgrade)
 
 
 def test_suite():
-    from unittest import TestSuite, TestLoader
+    from unittest import TestSuite
     import tests
-
     suite = TestSuite()
-
     suite.addTest(tests.test_suite())
-
     return suite
 
 if __name__ == '__main__':
     print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins "
           "to use it.\n")
+    runner = unittest.TextTestRunner()
+    runner.run(test_suite())
 else:
-    sys.path.append(os.path.dirname(__file__))
-
+    sys.path.append(os.path.dirname(os.path.abspath(__file__)))