changeset 4766:95cbb6b74790

convert: activate subversion engine Fail gracefully if the subversion python bindings are not installed. Support --rev option to convert as well as URL@rev.
author Brendan Cully <brendan@kublai.com>
date Sun, 01 Jul 2007 20:30:04 -0700
parents b6a1f2c46c6c
children 2d0a823cbba5
files hgext/convert/__init__.py hgext/convert/subversion.py
diffstat 2 files changed, 35 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/__init__.py	Sun Jul 01 23:56:11 2007 +0200
+++ b/hgext/convert/__init__.py	Sun Jul 01 20:30:04 2007 -0700
@@ -9,21 +9,21 @@
 from cvs import convert_cvs
 from git import convert_git
 from hg import convert_mercurial
+from subversion import convert_svn
 
 import os, shutil
 from mercurial import hg, ui, util, commands
 
 commands.norepo += " convert"
 
-converters = [convert_cvs, convert_git, convert_mercurial]
+converters = [convert_cvs, convert_git, convert_svn, convert_mercurial]
 
 def convertsource(ui, path, rev=None):
     for c in converters:
+        if not hasattr(c, 'getcommit'):
+            continue
         try:
-            converter = c(ui, path, rev=rev)
-            if not isinstance(converter, converter_source):
-                raise util.Abort('%s: cannot read from this repository type' % path)
-            return converter
+            return c(ui, path, rev=rev)
         except NoRepo:
             pass
     raise util.Abort('%s: unknown repository type' % path)
@@ -32,11 +32,10 @@
     if not os.path.isdir(path):
         raise util.Abort("%s: not a directory" % path)
     for c in converters:
+        if not hasattr(c, 'putcommit'):
+            continue
         try:
-            converter = c(ui, path)
-            if not isinstance(converter, converter_sink):
-                raise util.Abort('%s: cannot write to this repository type' % path)
-            return converter
+            return c(ui, path)
         except NoRepo:
             pass
     raise util.Abort('%s: unknown repository type' % path)
--- a/hgext/convert/subversion.py	Sun Jul 01 23:56:11 2007 +0200
+++ b/hgext/convert/subversion.py	Sun Jul 01 20:30:04 2007 -0700
@@ -11,15 +11,19 @@
 # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing
 # these bindings.
 
-from svn.core import SubversionException, Pool
-import svn.core
-import svn.ra
-import svn.delta
-import svn
-import transport
 from cStringIO import StringIO
 
-from common import NoRepo, commit, converter_source, recode, nocommitmsg
+from common import NoRepo, commit, converter_source
+
+try:
+    from svn.core import SubversionException, Pool
+    import svn.core
+    import svn.ra
+    import svn.delta
+    import svn
+    import transport
+except ImportError:
+    pass
 
 class CompatibilityException(Exception): pass
 
@@ -74,16 +78,29 @@
 
 # SVN conversion code stolen from bzr-svn and tailor
 class convert_svn(converter_source):
-    def __init__(self, ui, url):
+    def __init__(self, ui, url, rev=None):
+        try:
+            SubversionException
+        except NameError:
+            msg = 'subversion python bindings could not be loaded\n'
+            ui.warn(msg)
+            raise NoRepo(msg)
+
         self.ui = ui
         self.encoding = locale.getpreferredencoding()
+        latest = None
+        if rev:
+            try:
+                latest = int(rev)
+            except ValueError:
+                raise util.Abort('svn: revision %s is not an integer' % rev)
         try:
             # Support file://path@rev syntax. Useful e.g. to convert
             # deleted branches.
             url, latest = url.rsplit("@", 1)
             latest = int(latest)
         except ValueError, e:
-            latest = None
+            pass
         self.url = url
         self.encoding = 'UTF-8' # Subversion is always nominal UTF-8
         try:
@@ -368,7 +385,7 @@
                 # '2007-01-04T17:35:00.902377Z'
                 date = util.parsedate(date[:18] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
 
-                log = message and self.recode(message) or nocommitmsg
+                log = message and self.recode(message)
                 author = author and self.recode(author) or ''
 
                 cset = commit(author=author,
@@ -506,6 +523,3 @@
 
         self.reparent(self.module)
         return [path + "/" + c for c in children]
-
-    def recode(self, s):
-        return recode(self.encoding, s)