comparison hgext/convert/subversion.py @ 4759: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 81b170c41986
comparison
equal deleted inserted replaced
4758:b6a1f2c46c6c 4759:95cbb6b74790
9 9
10 # Subversion stuff. Works best with very recent Python SVN bindings 10 # Subversion stuff. Works best with very recent Python SVN bindings
11 # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing 11 # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing
12 # these bindings. 12 # these bindings.
13 13
14 from svn.core import SubversionException, Pool
15 import svn.core
16 import svn.ra
17 import svn.delta
18 import svn
19 import transport
20 from cStringIO import StringIO 14 from cStringIO import StringIO
21 15
22 from common import NoRepo, commit, converter_source, recode, nocommitmsg 16 from common import NoRepo, commit, converter_source
17
18 try:
19 from svn.core import SubversionException, Pool
20 import svn.core
21 import svn.ra
22 import svn.delta
23 import svn
24 import transport
25 except ImportError:
26 pass
23 27
24 class CompatibilityException(Exception): pass 28 class CompatibilityException(Exception): pass
25 29
26 nbRevisionsPerFetch = 50 30 nbRevisionsPerFetch = 50
27 31
72 def __repr__(self): 76 def __repr__(self):
73 return self.__str__() 77 return self.__str__()
74 78
75 # SVN conversion code stolen from bzr-svn and tailor 79 # SVN conversion code stolen from bzr-svn and tailor
76 class convert_svn(converter_source): 80 class convert_svn(converter_source):
77 def __init__(self, ui, url): 81 def __init__(self, ui, url, rev=None):
82 try:
83 SubversionException
84 except NameError:
85 msg = 'subversion python bindings could not be loaded\n'
86 ui.warn(msg)
87 raise NoRepo(msg)
88
78 self.ui = ui 89 self.ui = ui
79 self.encoding = locale.getpreferredencoding() 90 self.encoding = locale.getpreferredencoding()
91 latest = None
92 if rev:
93 try:
94 latest = int(rev)
95 except ValueError:
96 raise util.Abort('svn: revision %s is not an integer' % rev)
80 try: 97 try:
81 # Support file://path@rev syntax. Useful e.g. to convert 98 # Support file://path@rev syntax. Useful e.g. to convert
82 # deleted branches. 99 # deleted branches.
83 url, latest = url.rsplit("@", 1) 100 url, latest = url.rsplit("@", 1)
84 latest = int(latest) 101 latest = int(latest)
85 except ValueError, e: 102 except ValueError, e:
86 latest = None 103 pass
87 self.url = url 104 self.url = url
88 self.encoding = 'UTF-8' # Subversion is always nominal UTF-8 105 self.encoding = 'UTF-8' # Subversion is always nominal UTF-8
89 try: 106 try:
90 self.transport = transport.SvnRaTransport(url = url) 107 self.transport = transport.SvnRaTransport(url = url)
91 self.ra = self.transport.ra 108 self.ra = self.transport.ra
366 # Example SVN datetime. Includes microseconds. 383 # Example SVN datetime. Includes microseconds.
367 # ISO-8601 conformant 384 # ISO-8601 conformant
368 # '2007-01-04T17:35:00.902377Z' 385 # '2007-01-04T17:35:00.902377Z'
369 date = util.parsedate(date[:18] + " UTC", ["%Y-%m-%dT%H:%M:%S"]) 386 date = util.parsedate(date[:18] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
370 387
371 log = message and self.recode(message) or nocommitmsg 388 log = message and self.recode(message)
372 author = author and self.recode(author) or '' 389 author = author and self.recode(author) or ''
373 390
374 cset = commit(author=author, 391 cset = commit(author=author,
375 date=util.datestr(date), 392 date=util.datestr(date),
376 desc=log, 393 desc=log,
504 self.reparent(self.module) 521 self.reparent(self.module)
505 return _find_children_fallback(path, revnum) 522 return _find_children_fallback(path, revnum)
506 523
507 self.reparent(self.module) 524 self.reparent(self.module)
508 return [path + "/" + c for c in children] 525 return [path + "/" + c for c in children]
509
510 def recode(self, s):
511 return recode(self.encoding, s)