comparison hgext/convert/bzr.py @ 28411:098bb5660580

convert: bzr use absolute_import
author timeless <timeless@mozdev.org>
date Wed, 02 Mar 2016 16:32:52 +0000
parents aaa33ec3c951
children d62b00318c19
comparison
equal deleted inserted replaced
28410:48b04018c897 28411:098bb5660580
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 # This module is for handling 'bzr', that was formerly known as Bazaar-NG; 8 # This module is for handling 'bzr', that was formerly known as Bazaar-NG;
9 # it cannot access 'bar' repositories, but they were never used very much 9 # it cannot access 'bar' repositories, but they were never used very much
10 from __future__ import absolute_import
10 11
11 import os 12 import os
12 from mercurial import demandimport, error 13 from mercurial import (
14 demandimport,
15 error
16 )
17 from mercurial.i18n import _
18 from . import common
19
13 # these do not work with demandimport, blacklist 20 # these do not work with demandimport, blacklist
14 demandimport.ignore.extend([ 21 demandimport.ignore.extend([
15 'bzrlib.transactions', 22 'bzrlib.transactions',
16 'bzrlib.urlutils', 23 'bzrlib.urlutils',
17 'ElementPath', 24 'ElementPath',
18 ]) 25 ])
19 26
20 from mercurial.i18n import _
21 from mercurial import error
22 from common import NoRepo, commit, converter_source
23
24 try: 27 try:
25 # bazaar imports 28 # bazaar imports
26 from bzrlib import bzrdir, revision, errors 29 from bzrlib import (
30 bzrdir,
31 errors,
32 revision,
33 )
27 from bzrlib.revisionspec import RevisionSpec 34 from bzrlib.revisionspec import RevisionSpec
28 except ImportError: 35 except ImportError:
29 pass 36 pass
30 37
31 supportedkinds = ('file', 'symlink') 38 supportedkinds = ('file', 'symlink')
32 39
33 class bzr_source(converter_source): 40 class bzr_source(common.converter_source):
34 """Reads Bazaar repositories by using the Bazaar Python libraries""" 41 """Reads Bazaar repositories by using the Bazaar Python libraries"""
35 42
36 def __init__(self, ui, path, revs=None): 43 def __init__(self, ui, path, revs=None):
37 super(bzr_source, self).__init__(ui, path, revs=revs) 44 super(bzr_source, self).__init__(ui, path, revs=revs)
38 45
39 if not os.path.exists(os.path.join(path, '.bzr')): 46 if not os.path.exists(os.path.join(path, '.bzr')):
40 raise NoRepo(_('%s does not look like a Bazaar repository') 47 raise common.NoRepo(_('%s does not look like a Bazaar repository')
41 % path) 48 % path)
42 49
43 try: 50 try:
44 # access bzrlib stuff 51 # access bzrlib stuff
45 bzrdir 52 bzrdir
46 except NameError: 53 except NameError:
47 raise NoRepo(_('Bazaar modules could not be loaded')) 54 raise common.NoRepo(_('Bazaar modules could not be loaded'))
48 55
49 path = os.path.abspath(path) 56 path = os.path.abspath(path)
50 self._checkrepotype(path) 57 self._checkrepotype(path)
51 try: 58 try:
52 self.sourcerepo = bzrdir.BzrDir.open(path).open_repository() 59 self.sourcerepo = bzrdir.BzrDir.open(path).open_repository()
53 except errors.NoRepositoryPresent: 60 except errors.NoRepositoryPresent:
54 raise NoRepo(_('%s does not look like a Bazaar repository') 61 raise common.NoRepo(_('%s does not look like a Bazaar repository')
55 % path) 62 % path)
56 self._parentids = {} 63 self._parentids = {}
57 64
58 def _checkrepotype(self, path): 65 def _checkrepotype(self, path):
59 # Lightweight checkouts detection is informational but probably 66 # Lightweight checkouts detection is informational but probably
60 # fragile at API level. It should not terminate the conversion. 67 # fragile at API level. It should not terminate the conversion.
158 self._parentids[version] = parents 165 self._parentids[version] = parents
159 166
160 branch = self.recode(rev.properties.get('branch-nick', u'default')) 167 branch = self.recode(rev.properties.get('branch-nick', u'default'))
161 if branch == 'trunk': 168 if branch == 'trunk':
162 branch = 'default' 169 branch = 'default'
163 return commit(parents=parents, 170 return common.commit(parents=parents,
164 date='%d %d' % (rev.timestamp, -rev.timezone), 171 date='%d %d' % (rev.timestamp, -rev.timezone),
165 author=self.recode(rev.committer), 172 author=self.recode(rev.committer),
166 desc=self.recode(rev.message), 173 desc=self.recode(rev.message),
167 branch=branch, 174 branch=branch,
168 rev=version) 175 rev=version)