Mercurial > hg
comparison hgext/convert/subversion.py @ 28460:d6dbb0968c13
convert: fix relative import of stdlib module in subversion
Before this patch, import-checker reports "relative import of stdlib
module" error for importing Pool and SubversionException from svn.core
in subversion.py.
To fix this relative import of stdlib module, this patch adds prefix
'svn.core.' to Pool and SubversionException in source.
These 'svn.core.' relative accessing shouldn't cause performance
impact, because there are much more code paths accessing to
'svn.core.' relative properties.
BTW, in transport.py, this error is avoided by assignment below.
SubversionException = svn.core.SubversionException
But this can't be used in subversion.py case, because:
- such assignment in indented code block causes "don't use camelcase
in identifiers" error of check-code.py
- but it should be placed in indented block, because svn is None at
failure of importing subversion python binding libraries (=
examination of 'svn' is needed)
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 11 Mar 2016 21:55:44 +0900 |
parents | 3ea62e748a18 |
children | f106913c6a4e |
comparison
equal
deleted
inserted
replaced
28459:3ea62e748a18 | 28460:d6dbb0968c13 |
---|---|
41 # Subversion stuff. Works best with very recent Python SVN bindings | 41 # Subversion stuff. Works best with very recent Python SVN bindings |
42 # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing | 42 # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing |
43 # these bindings. | 43 # these bindings. |
44 | 44 |
45 try: | 45 try: |
46 from svn.core import ( | |
47 Pool, | |
48 SubversionException, | |
49 ) | |
50 import svn | 46 import svn |
51 import svn.client | 47 import svn.client |
52 import svn.core | 48 import svn.core |
53 import svn.ra | 49 import svn.ra |
54 import svn.delta | 50 import svn.delta |
55 from . import transport | 51 from . import transport |
56 import warnings | 52 import warnings |
57 warnings.filterwarnings('ignore', | 53 warnings.filterwarnings('ignore', |
58 module='svn.core', | 54 module='svn.core', |
59 category=DeprecationWarning) | 55 category=DeprecationWarning) |
56 svn.core.SubversionException # trigger import to catch error | |
60 | 57 |
61 except ImportError: | 58 except ImportError: |
62 svn = None | 59 svn = None |
63 | 60 |
64 class SvnPathNotFound(Exception): | 61 class SvnPathNotFound(Exception): |
101 return urllib.quote(s, "!$&'()*+,-./:=@_~") | 98 return urllib.quote(s, "!$&'()*+,-./:=@_~") |
102 | 99 |
103 def geturl(path): | 100 def geturl(path): |
104 try: | 101 try: |
105 return svn.client.url_from_path(svn.core.svn_path_canonicalize(path)) | 102 return svn.client.url_from_path(svn.core.svn_path_canonicalize(path)) |
106 except SubversionException: | 103 except svn.core.SubversionException: |
107 # svn.client.url_from_path() fails with local repositories | 104 # svn.client.url_from_path() fails with local repositories |
108 pass | 105 pass |
109 if os.path.isdir(path): | 106 if os.path.isdir(path): |
110 path = os.path.normpath(os.path.abspath(path)) | 107 path = os.path.normpath(os.path.abspath(path)) |
111 if os.name == 'nt': | 108 if os.name == 'nt': |
338 self.prevmodule = None | 335 self.prevmodule = None |
339 self.rootmodule = self.module | 336 self.rootmodule = self.module |
340 self.commits = {} | 337 self.commits = {} |
341 self.paths = {} | 338 self.paths = {} |
342 self.uuid = svn.ra.get_uuid(self.ra) | 339 self.uuid = svn.ra.get_uuid(self.ra) |
343 except SubversionException: | 340 except svn.core.SubversionException: |
344 ui.traceback() | 341 ui.traceback() |
345 svnversion = '%d.%d.%d' % (svn.core.SVN_VER_MAJOR, | 342 svnversion = '%d.%d.%d' % (svn.core.SVN_VER_MAJOR, |
346 svn.core.SVN_VER_MINOR, | 343 svn.core.SVN_VER_MINOR, |
347 svn.core.SVN_VER_MICRO) | 344 svn.core.SVN_VER_MICRO) |
348 raise NoRepo(_("%s does not look like a Subversion repository " | 345 raise NoRepo(_("%s does not look like a Subversion repository " |
399 def exists(self, path, optrev): | 396 def exists(self, path, optrev): |
400 try: | 397 try: |
401 svn.client.ls(self.url.rstrip('/') + '/' + quote(path), | 398 svn.client.ls(self.url.rstrip('/') + '/' + quote(path), |
402 optrev, False, self.ctx) | 399 optrev, False, self.ctx) |
403 return True | 400 return True |
404 except SubversionException: | 401 except svn.core.SubversionException: |
405 return False | 402 return False |
406 | 403 |
407 def getheads(self): | 404 def getheads(self): |
408 | 405 |
409 def isdir(path, revnum): | 406 def isdir(path, revnum): |
698 stop = svn.ra.get_latest_revnum(self.ra) | 695 stop = svn.ra.get_latest_revnum(self.ra) |
699 try: | 696 try: |
700 prevmodule = self.reparent('') | 697 prevmodule = self.reparent('') |
701 dirent = svn.ra.stat(self.ra, path.strip('/'), stop) | 698 dirent = svn.ra.stat(self.ra, path.strip('/'), stop) |
702 self.reparent(prevmodule) | 699 self.reparent(prevmodule) |
703 except SubversionException: | 700 except svn.core.SubversionException: |
704 dirent = None | 701 dirent = None |
705 if not dirent: | 702 if not dirent: |
706 raise SvnPathNotFound(_('%s not found up to revision %d') | 703 raise SvnPathNotFound(_('%s not found up to revision %d') |
707 % (path, stop)) | 704 % (path, stop)) |
708 | 705 |
970 latest = self.latest(self.module, firstrevnum - 1) | 967 latest = self.latest(self.module, firstrevnum - 1) |
971 if latest: | 968 if latest: |
972 firstcset.parents.append(latest) | 969 firstcset.parents.append(latest) |
973 except SvnPathNotFound: | 970 except SvnPathNotFound: |
974 pass | 971 pass |
975 except SubversionException as xxx_todo_changeme: | 972 except svn.core.SubversionException as xxx_todo_changeme: |
976 (inst, num) = xxx_todo_changeme.args | 973 (inst, num) = xxx_todo_changeme.args |
977 if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: | 974 if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: |
978 raise error.Abort(_('svn: branch has no revision %s') | 975 raise error.Abort(_('svn: branch has no revision %s') |
979 % to_revnum) | 976 % to_revnum) |
980 raise | 977 raise |
997 io.close() | 994 io.close() |
998 if isinstance(info, list): | 995 if isinstance(info, list): |
999 info = info[-1] | 996 info = info[-1] |
1000 mode = ("svn:executable" in info) and 'x' or '' | 997 mode = ("svn:executable" in info) and 'x' or '' |
1001 mode = ("svn:special" in info) and 'l' or mode | 998 mode = ("svn:special" in info) and 'l' or mode |
1002 except SubversionException as e: | 999 except svn.core.SubversionException as e: |
1003 notfound = (svn.core.SVN_ERR_FS_NOT_FOUND, | 1000 notfound = (svn.core.SVN_ERR_FS_NOT_FOUND, |
1004 svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND) | 1001 svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND) |
1005 if e.apr_err in notfound: # File not found | 1002 if e.apr_err in notfound: # File not found |
1006 return None, None | 1003 return None, None |
1007 raise | 1004 raise |
1012 return data, mode | 1009 return data, mode |
1013 | 1010 |
1014 def _iterfiles(self, path, revnum): | 1011 def _iterfiles(self, path, revnum): |
1015 """Enumerate all files in path at revnum, recursively.""" | 1012 """Enumerate all files in path at revnum, recursively.""" |
1016 path = path.strip('/') | 1013 path = path.strip('/') |
1017 pool = Pool() | 1014 pool = svn.core.Pool() |
1018 rpath = '/'.join([self.baseurl, quote(path)]).strip('/') | 1015 rpath = '/'.join([self.baseurl, quote(path)]).strip('/') |
1019 entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool) | 1016 entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool) |
1020 if path: | 1017 if path: |
1021 path += '/' | 1018 path += '/' |
1022 return ((path + p) for p, e in entries.iteritems() | 1019 return ((path + p) for p, e in entries.iteritems() |