[PATCH 2 of 3] convert: fix relative import of stdlib module in subversion

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Mar 11 08:00:22 EST 2016


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1457700944 -32400
#      Fri Mar 11 21:55:44 2016 +0900
# Node ID cc86ef8d2f0b7ebaf7b4de4692b8d4cfefe36f04
# Parent  59aa1b8645de514bf3f5da9e0c09e94321b92351
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)

diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -43,10 +43,6 @@ NoRepo = common.NoRepo
 # these bindings.
 
 try:
-    from svn.core import (
-        Pool,
-        SubversionException,
-    )
     import svn
     import svn.client
     import svn.core
@@ -102,7 +98,7 @@ def quote(s):
 def geturl(path):
     try:
         return svn.client.url_from_path(svn.core.svn_path_canonicalize(path))
-    except SubversionException:
+    except svn.core.SubversionException:
         # svn.client.url_from_path() fails with local repositories
         pass
     if os.path.isdir(path):
@@ -339,7 +335,7 @@ class svn_source(converter_source):
             self.commits = {}
             self.paths = {}
             self.uuid = svn.ra.get_uuid(self.ra)
-        except SubversionException:
+        except svn.core.SubversionException:
             ui.traceback()
             svnversion = '%d.%d.%d' % (svn.core.SVN_VER_MAJOR,
                                        svn.core.SVN_VER_MINOR,
@@ -400,7 +396,7 @@ class svn_source(converter_source):
             svn.client.ls(self.url.rstrip('/') + '/' + quote(path),
                                  optrev, False, self.ctx)
             return True
-        except SubversionException:
+        except svn.core.SubversionException:
             return False
 
     def getheads(self):
@@ -699,7 +695,7 @@ class svn_source(converter_source):
             prevmodule = self.reparent('')
             dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
             self.reparent(prevmodule)
-        except SubversionException:
+        except svn.core.SubversionException:
             dirent = None
         if not dirent:
             raise SvnPathNotFound(_('%s not found up to revision %d')
@@ -971,7 +967,7 @@ class svn_source(converter_source):
                             firstcset.parents.append(latest)
                 except SvnPathNotFound:
                     pass
-        except SubversionException as xxx_todo_changeme:
+        except svn.core.SubversionException as xxx_todo_changeme:
             (inst, num) = xxx_todo_changeme.args
             if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION:
                 raise error.Abort(_('svn: branch has no revision %s')
@@ -998,7 +994,7 @@ class svn_source(converter_source):
                 info = info[-1]
             mode = ("svn:executable" in info) and 'x' or ''
             mode = ("svn:special" in info) and 'l' or mode
-        except SubversionException as e:
+        except svn.core.SubversionException as e:
             notfound = (svn.core.SVN_ERR_FS_NOT_FOUND,
                 svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND)
             if e.apr_err in notfound: # File not found
@@ -1013,7 +1009,7 @@ class svn_source(converter_source):
     def _iterfiles(self, path, revnum):
         """Enumerate all files in path at revnum, recursively."""
         path = path.strip('/')
-        pool = Pool()
+        pool = svn.core.Pool()
         rpath = '/'.join([self.baseurl, quote(path)]).strip('/')
         entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool)
         if path:


More information about the Mercurial-devel mailing list