hgext/convert/subversion.py
changeset 43077 687b865b95ad
parent 43076 2372284d9457
child 43085 eef9a2d67051
--- a/hgext/convert/subversion.py	Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/convert/subversion.py	Sun Oct 06 09:48:39 2019 -0400
@@ -54,7 +54,7 @@
     import warnings
 
     warnings.filterwarnings(
-        'ignore', module='svn.core', category=DeprecationWarning
+        b'ignore', module=b'svn.core', category=DeprecationWarning
     )
     svn.core.SubversionException  # trigger import to catch error
 
@@ -80,16 +80,16 @@
     >>> revsplit(b'bad')
     ('', '', 0)
     """
-    parts = rev.rsplit('@', 1)
+    parts = rev.rsplit(b'@', 1)
     revnum = 0
     if len(parts) > 1:
         revnum = int(parts[1])
-    parts = parts[0].split('/', 1)
-    uuid = ''
-    mod = ''
-    if len(parts) > 1 and parts[0].startswith('svn:'):
+    parts = parts[0].split(b'/', 1)
+    uuid = b''
+    mod = b''
+    if len(parts) > 1 and parts[0].startswith(b'svn:'):
         uuid = parts[0][4:]
-        mod = '/' + parts[1]
+        mod = b'/' + parts[1]
     return uuid, mod, revnum
 
 
@@ -101,7 +101,7 @@
     # so we can extend it safely with new components. The "safe"
     # characters were taken from the "svn_uri__char_validity" table in
     # libsvn_subr/path.c.
-    return urlreq.quote(s, "!$&'()*+,-./:=@_~")
+    return urlreq.quote(s, b"!$&'()*+,-./:=@_~")
 
 
 def geturl(path):
@@ -113,11 +113,11 @@
     if os.path.isdir(path):
         path = os.path.normpath(os.path.abspath(path))
         if pycompat.iswindows:
-            path = '/' + util.normpath(path)
+            path = b'/' + util.normpath(path)
         # Module URL is later compared with the repository URL returned
         # by svn API, which is UTF-8.
         path = encoding.tolocal(path)
-        path = 'file://%s' % quote(path)
+        path = b'file://%s' % quote(path)
     return svn.core.svn_path_canonicalize(path)
 
 
@@ -188,7 +188,7 @@
     """
     if svn is None:
         raise error.Abort(
-            _('debugsvnlog could not load Subversion python ' 'bindings')
+            _(b'debugsvnlog could not load Subversion python ' b'bindings')
         )
 
     args = decodeargs(ui.fin.read())
@@ -208,8 +208,8 @@
             except EOFError:
                 raise error.Abort(
                     _(
-                        'Mercurial failed to run itself, check'
-                        ' hg executable is in PATH'
+                        b'Mercurial failed to run itself, check'
+                        b' hg executable is in PATH'
                     )
                 )
             try:
@@ -217,7 +217,7 @@
             except (TypeError, ValueError):
                 if entry is None:
                     break
-                raise error.Abort(_("log stream exception '%s'") % entry)
+                raise error.Abort(_(b"log stream exception '%s'") % entry)
             yield entry
 
     def close(self):
@@ -270,7 +270,7 @@
 # looking for several svn-specific files and directories in the given
 # directory.
 def filecheck(ui, path, proto):
-    for x in ('locks', 'hooks', 'format', 'db'):
+    for x in (b'locks', b'hooks', b'format', b'db'):
         if not os.path.exists(os.path.join(path, x)):
             return False
     return True
@@ -282,16 +282,16 @@
 def httpcheck(ui, path, proto):
     try:
         opener = urlreq.buildopener()
-        rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path), 'rb')
+        rsp = opener.open(b'%s://%s/!svn/ver/0/.svn' % (proto, path), b'rb')
         data = rsp.read()
     except urlerr.httperror as inst:
         if inst.code != 404:
             # Except for 404 we cannot know for sure this is not an svn repo
             ui.warn(
                 _(
-                    'svn: cannot probe remote repository, assume it could '
-                    'be a subversion repository. Use --source-type if you '
-                    'know better.\n'
+                    b'svn: cannot probe remote repository, assume it could '
+                    b'be a subversion repository. Use --source-type if you '
+                    b'know better.\n'
                 )
             )
             return True
@@ -299,38 +299,38 @@
     except Exception:
         # Could be urlerr.urlerror if the URL is invalid or anything else.
         return False
-    return '<m:human-readable errcode="160013">' in data
+    return b'<m:human-readable errcode="160013">' in data
 
 
 protomap = {
-    'http': httpcheck,
-    'https': httpcheck,
-    'file': filecheck,
+    b'http': httpcheck,
+    b'https': httpcheck,
+    b'file': filecheck,
 }
 
 
 def issvnurl(ui, url):
     try:
-        proto, path = url.split('://', 1)
-        if proto == 'file':
+        proto, path = url.split(b'://', 1)
+        if proto == b'file':
             if (
                 pycompat.iswindows
-                and path[:1] == '/'
+                and path[:1] == b'/'
                 and path[1:2].isalpha()
-                and path[2:6].lower() == '%3a/'
+                and path[2:6].lower() == b'%3a/'
             ):
-                path = path[:2] + ':/' + path[6:]
+                path = path[:2] + b':/' + path[6:]
             path = urlreq.url2pathname(path)
     except ValueError:
-        proto = 'file'
+        proto = b'file'
         path = os.path.abspath(url)
-    if proto == 'file':
+    if proto == b'file':
         path = util.pconvert(path)
     check = protomap.get(proto, lambda *args: False)
-    while '/' in path:
+    while b'/' in path:
         if check(ui, path, proto):
             return True
-        path = path.rsplit('/', 1)[0]
+        path = path.rsplit(b'/', 1)[0]
     return False
 
 
@@ -353,35 +353,35 @@
         super(svn_source, self).__init__(ui, repotype, url, revs=revs)
 
         if not (
-            url.startswith('svn://')
-            or url.startswith('svn+ssh://')
+            url.startswith(b'svn://')
+            or url.startswith(b'svn+ssh://')
             or (
                 os.path.exists(url)
-                and os.path.exists(os.path.join(url, '.svn'))
+                and os.path.exists(os.path.join(url, b'.svn'))
             )
             or issvnurl(ui, url)
         ):
             raise NoRepo(
-                _("%s does not look like a Subversion repository") % url
+                _(b"%s does not look like a Subversion repository") % url
             )
         if svn is None:
-            raise MissingTool(_('could not load Subversion python bindings'))
+            raise MissingTool(_(b'could not load Subversion python bindings'))
 
         try:
             version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
             if version < (1, 4):
                 raise MissingTool(
                     _(
-                        'Subversion python bindings %d.%d found, '
-                        '1.4 or later required'
+                        b'Subversion python bindings %d.%d found, '
+                        b'1.4 or later required'
                     )
                     % version
                 )
         except AttributeError:
             raise MissingTool(
                 _(
-                    'Subversion python bindings are too old, 1.4 '
-                    'or later required'
+                    b'Subversion python bindings are too old, 1.4 '
+                    b'or later required'
                 )
             )
 
@@ -391,14 +391,14 @@
         try:
             # Support file://path@rev syntax. Useful e.g. to convert
             # deleted branches.
-            at = url.rfind('@')
+            at = url.rfind(b'@')
             if at >= 0:
                 latest = int(url[at + 1 :])
                 url = url[:at]
         except ValueError:
             pass
         self.url = geturl(url)
-        self.encoding = 'UTF-8'  # Subversion is always nominal UTF-8
+        self.encoding = b'UTF-8'  # Subversion is always nominal UTF-8
         try:
             self.transport = transport.SvnRaTransport(url=self.url)
             self.ra = self.transport.ra
@@ -414,15 +414,15 @@
             self.uuid = svn.ra.get_uuid(self.ra)
         except svn.core.SubversionException:
             ui.traceback()
-            svnversion = '%d.%d.%d' % (
+            svnversion = b'%d.%d.%d' % (
                 svn.core.SVN_VER_MAJOR,
                 svn.core.SVN_VER_MINOR,
                 svn.core.SVN_VER_MICRO,
             )
             raise NoRepo(
                 _(
-                    "%s does not look like a Subversion repository "
-                    "to libsvn version %s"
+                    b"%s does not look like a Subversion repository "
+                    b"to libsvn version %s"
                 )
                 % (self.url, svnversion)
             )
@@ -431,29 +431,29 @@
             if len(revs) > 1:
                 raise error.Abort(
                     _(
-                        'subversion source does not support '
-                        'specifying multiple revisions'
+                        b'subversion source does not support '
+                        b'specifying multiple revisions'
                     )
                 )
             try:
                 latest = int(revs[0])
             except ValueError:
                 raise error.Abort(
-                    _('svn: revision %s is not an integer') % revs[0]
+                    _(b'svn: revision %s is not an integer') % revs[0]
                 )
 
-        trunkcfg = self.ui.config('convert', 'svn.trunk')
+        trunkcfg = self.ui.config(b'convert', b'svn.trunk')
         if trunkcfg is None:
-            trunkcfg = 'trunk'
-        self.trunkname = trunkcfg.strip('/')
-        self.startrev = self.ui.config('convert', 'svn.startrev')
+            trunkcfg = b'trunk'
+        self.trunkname = trunkcfg.strip(b'/')
+        self.startrev = self.ui.config(b'convert', b'svn.startrev')
         try:
             self.startrev = int(self.startrev)
             if self.startrev < 0:
                 self.startrev = 0
         except ValueError:
             raise error.Abort(
-                _('svn: start revision %s is not an integer') % self.startrev
+                _(b'svn: start revision %s is not an integer') % self.startrev
             )
 
         try:
@@ -461,12 +461,14 @@
         except SvnPathNotFound:
             self.head = None
         if not self.head:
-            raise error.Abort(_('no revision found in module %s') % self.module)
+            raise error.Abort(
+                _(b'no revision found in module %s') % self.module
+            )
         self.last_changed = self.revnum(self.head)
 
         self._changescache = (None, None)
 
-        if os.path.exists(os.path.join(url, '.svn/entries')):
+        if os.path.exists(os.path.join(url, b'.svn/entries')):
             self.wc = url
         else:
             self.wc = None
@@ -484,7 +486,7 @@
     def exists(self, path, optrev):
         try:
             svn.client.ls(
-                self.url.rstrip('/') + '/' + quote(path),
+                self.url.rstrip(b'/') + b'/' + quote(path),
                 optrev,
                 False,
                 self.ctx,
@@ -499,61 +501,62 @@
             return kind == svn.core.svn_node_dir
 
         def getcfgpath(name, rev):
-            cfgpath = self.ui.config('convert', 'svn.' + name)
-            if cfgpath is not None and cfgpath.strip() == '':
+            cfgpath = self.ui.config(b'convert', b'svn.' + name)
+            if cfgpath is not None and cfgpath.strip() == b'':
                 return None
-            path = (cfgpath or name).strip('/')
+            path = (cfgpath or name).strip(b'/')
             if not self.exists(path, rev):
-                if self.module.endswith(path) and name == 'trunk':
+                if self.module.endswith(path) and name == b'trunk':
                     # we are converting from inside this directory
                     return None
                 if cfgpath:
                     raise error.Abort(
-                        _('expected %s to be at %r, but not found')
+                        _(b'expected %s to be at %r, but not found')
                         % (name, path)
                     )
                 return None
-            self.ui.note(_('found %s at %r\n') % (name, path))
+            self.ui.note(_(b'found %s at %r\n') % (name, path))
             return path
 
         rev = optrev(self.last_changed)
-        oldmodule = ''
-        trunk = getcfgpath('trunk', rev)
-        self.tags = getcfgpath('tags', rev)
-        branches = getcfgpath('branches', rev)
+        oldmodule = b''
+        trunk = getcfgpath(b'trunk', rev)
+        self.tags = getcfgpath(b'tags', rev)
+        branches = getcfgpath(b'branches', rev)
 
         # If the project has a trunk or branches, we will extract heads
         # from them. We keep the project root otherwise.
         if trunk:
-            oldmodule = self.module or ''
-            self.module += '/' + trunk
+            oldmodule = self.module or b''
+            self.module += b'/' + trunk
             self.head = self.latest(self.module, self.last_changed)
             if not self.head:
                 raise error.Abort(
-                    _('no revision found in module %s') % self.module
+                    _(b'no revision found in module %s') % self.module
                 )
 
         # First head in the list is the module's head
         self.heads = [self.head]
         if self.tags is not None:
-            self.tags = '%s/%s' % (oldmodule, (self.tags or 'tags'))
+            self.tags = b'%s/%s' % (oldmodule, (self.tags or b'tags'))
 
         # Check if branches bring a few more heads to the list
         if branches:
-            rpath = self.url.strip('/')
+            rpath = self.url.strip(b'/')
             branchnames = svn.client.ls(
-                rpath + '/' + quote(branches), rev, False, self.ctx
+                rpath + b'/' + quote(branches), rev, False, self.ctx
             )
             for branch in sorted(branchnames):
-                module = '%s/%s/%s' % (oldmodule, branches, branch)
+                module = b'%s/%s/%s' % (oldmodule, branches, branch)
                 if not isdir(module, self.last_changed):
                     continue
                 brevid = self.latest(module, self.last_changed)
                 if not brevid:
-                    self.ui.note(_('ignoring empty branch %s\n') % branch)
+                    self.ui.note(_(b'ignoring empty branch %s\n') % branch)
                     continue
                 self.ui.note(
-                    _('found branch %s at %d\n') % (branch, self.revnum(brevid))
+                    _(b'found branch %s at %d\n')
+                    % (branch, self.revnum(brevid))
                 )
                 self.heads.append(brevid)
 
@@ -561,14 +564,14 @@
             if len(self.heads) > 1:
                 raise error.Abort(
                     _(
-                        'svn: start revision is not supported '
-                        'with more than one branch'
+                        b'svn: start revision is not supported '
+                        b'with more than one branch'
                     )
                 )
             revnum = self.revnum(self.heads[0])
             if revnum < self.startrev:
                 raise error.Abort(
-                    _('svn: no revision found after start revision %d')
+                    _(b'svn: no revision found after start revision %d')
                     % self.startrev
                 )
 
@@ -628,13 +631,13 @@
                 stop = revnum + 1
             self._fetch_revisions(revnum, stop)
             if rev not in self.commits:
-                raise error.Abort(_('svn: revision %s not found') % revnum)
+                raise error.Abort(_(b'svn: revision %s not found') % revnum)
         revcommit = self.commits[rev]
         # caller caches the result, so free it here to release memory
         del self.commits[rev]
         return revcommit
 
-    def checkrevformat(self, revstr, mapname='splicemap'):
+    def checkrevformat(self, revstr, mapname=b'splicemap'):
         """ fails if revision format does not match the correct format"""
         if not re.match(
             r'svn:[0-9a-f]{8,8}-[0-9a-f]{4,4}-'
@@ -643,12 +646,12 @@
             revstr,
         ):
             raise error.Abort(
-                _('%s entry %s is not a valid revision' ' identifier')
+                _(b'%s entry %s is not a valid revision' b' identifier')
                 % (mapname, revstr)
             )
 
     def numcommits(self):
-        return int(self.head.rsplit('@', 1)[1]) - self.startrev
+        return int(self.head.rsplit(b'@', 1)[1]) - self.startrev
 
     def gettags(self):
         tags = {}
@@ -689,7 +692,7 @@
                     srctagspath = copies.pop()[0]
 
                 for source, sourcerev, dest in copies:
-                    if not dest.startswith(tagspath + '/'):
+                    if not dest.startswith(tagspath + b'/'):
                         continue
                     for tag in pendings:
                         if tag[0].startswith(dest):
@@ -709,14 +712,14 @@
                 addeds = dict(
                     (p, e.copyfrom_path)
                     for p, e in origpaths.iteritems()
-                    if e.action == 'A' and e.copyfrom_path
+                    if e.action == b'A' and e.copyfrom_path
                 )
                 badroots = set()
                 for destroot in addeds:
                     for source, sourcerev, dest in pendings:
                         if not dest.startswith(
-                            destroot + '/'
-                        ) or source.startswith(addeds[destroot] + '/'):
+                            destroot + b'/'
+                        ) or source.startswith(addeds[destroot] + b'/'):
                             continue
                         badroots.add(destroot)
                         break
@@ -726,13 +729,13 @@
                         p
                         for p in pendings
                         if p[2] != badroot
-                        and not p[2].startswith(badroot + '/')
+                        and not p[2].startswith(badroot + b'/')
                     ]
 
                 # Tell tag renamings from tag creations
                 renamings = []
                 for source, sourcerev, dest in pendings:
-                    tagname = dest.split('/')[-1]
+                    tagname = dest.split(b'/')[-1]
                     if source.startswith(srctagspath):
                         renamings.append([source, sourcerev, tagname])
                         continue
@@ -761,18 +764,18 @@
             return
         if self.convertfp is None:
             self.convertfp = open(
-                os.path.join(self.wc, '.svn', 'hg-shamap'), 'ab'
+                os.path.join(self.wc, b'.svn', b'hg-shamap'), b'ab'
             )
         self.convertfp.write(
-            util.tonativeeol('%s %d\n' % (destrev, self.revnum(rev)))
+            util.tonativeeol(b'%s %d\n' % (destrev, self.revnum(rev)))
         )
         self.convertfp.flush()
 
     def revid(self, revnum, module=None):
-        return 'svn:%s%s@%s' % (self.uuid, module or self.module, revnum)
+        return b'svn:%s%s@%s' % (self.uuid, module or self.module, revnum)
 
     def revnum(self, rev):
-        return int(rev.split('@')[-1])
+        return int(rev.split(b'@')[-1])
 
     def latest(self, path, stop=None):
         """Find the latest revid affecting path, up to stop revision
@@ -800,7 +803,7 @@
                             continue
                         newpath = paths[p].copyfrom_path + path[len(p) :]
                         self.ui.debug(
-                            "branch renamed from %s to %s at %d\n"
+                            b"branch renamed from %s to %s at %d\n"
                             % (path, newpath, revnum)
                         )
                         path = newpath
@@ -813,20 +816,20 @@
 
         if not path.startswith(self.rootmodule):
             # Requests on foreign branches may be forbidden at server level
-            self.ui.debug('ignoring foreign branch %r\n' % path)
+            self.ui.debug(b'ignoring foreign branch %r\n' % path)
             return None
 
         if stop is None:
             stop = svn.ra.get_latest_revnum(self.ra)
         try:
-            prevmodule = self.reparent('')
-            dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
+            prevmodule = self.reparent(b'')
+            dirent = svn.ra.stat(self.ra, path.strip(b'/'), stop)
             self.reparent(prevmodule)
         except svn.core.SubversionException:
             dirent = None
         if not dirent:
             raise SvnPathNotFound(
-                _('%s not found up to revision %d') % (path, stop)
+                _(b'%s not found up to revision %d') % (path, stop)
             )
 
         # stat() gives us the previous revision on this line of
@@ -843,11 +846,11 @@
             # the whole history.
             revnum, realpath = findchanges(path, stop)
             if revnum is None:
-                self.ui.debug('ignoring empty branch %r\n' % realpath)
+                self.ui.debug(b'ignoring empty branch %r\n' % realpath)
                 return None
 
         if not realpath.startswith(self.rootmodule):
-            self.ui.debug('ignoring foreign branch %r\n' % realpath)
+            self.ui.debug(b'ignoring foreign branch %r\n' % realpath)
             return None
         return self.revid(revnum, realpath)
 
@@ -858,8 +861,8 @@
         svnurl = self.baseurl + quote(module)
         prevmodule = self.prevmodule
         if prevmodule is None:
-            prevmodule = ''
-        self.ui.debug("reparent to %s\n" % svnurl)
+            prevmodule = b''
+        self.ui.debug(b"reparent to %s\n" % svnurl)
         svn.ra.reparent(self.ra, svnurl)
         self.prevmodule = module
         return prevmodule
@@ -874,7 +877,7 @@
             self.reparent(self.module)
 
         progress = self.ui.makeprogress(
-            _('scanning paths'), unit=_('paths'), total=len(paths)
+            _(b'scanning paths'), unit=_(b'paths'), total=len(paths)
         )
         for i, (path, ent) in enumerate(paths):
             progress.update(i, item=path)
@@ -894,37 +897,37 @@
                 if not copyfrom_path:
                     continue
                 self.ui.debug(
-                    "copied to %s from %s@%s\n"
+                    b"copied to %s from %s@%s\n"
                     % (entrypath, copyfrom_path, ent.copyfrom_rev)
                 )
                 copies[self.recode(entrypath)] = self.recode(copyfrom_path)
             elif kind == 0:  # gone, but had better be a deleted *file*
-                self.ui.debug("gone from %s\n" % ent.copyfrom_rev)
+                self.ui.debug(b"gone from %s\n" % ent.copyfrom_rev)
                 pmodule, prevnum = revsplit(parents[0])[1:]
-                parentpath = pmodule + "/" + entrypath
+                parentpath = pmodule + b"/" + entrypath
                 fromkind = self._checkpath(entrypath, prevnum, pmodule)
 
                 if fromkind == svn.core.svn_node_file:
                     removed.add(self.recode(entrypath))
                 elif fromkind == svn.core.svn_node_dir:
-                    oroot = parentpath.strip('/')
-                    nroot = path.strip('/')
+                    oroot = parentpath.strip(b'/')
+                    nroot = path.strip(b'/')
                     children = self._iterfiles(oroot, prevnum)
                     for childpath in children:
                         childpath = childpath.replace(oroot, nroot)
-                        childpath = self.getrelpath("/" + childpath, pmodule)
+                        childpath = self.getrelpath(b"/" + childpath, pmodule)
                         if childpath:
                             removed.add(self.recode(childpath))
                 else:
                     self.ui.debug(
-                        'unknown path in revision %d: %s\n' % (revnum, path)
+                        b'unknown path in revision %d: %s\n' % (revnum, path)
                     )
             elif kind == svn.core.svn_node_dir:
-                if ent.action == 'M':
+                if ent.action == b'M':
                     # If the directory just had a prop change,
                     # then we shouldn't need to look for its children.
                     continue
-                if ent.action == 'R' and parents:
+                if ent.action == b'R' and parents:
                     # If a directory is replacing a file, mark the previous
                     # file as deleted
                     pmodule, prevnum = revsplit(parents[0])[1:]
@@ -935,12 +938,12 @@
                         # We do not know what files were kept or removed,
                         # mark them all as changed.
                         for childpath in self._iterfiles(pmodule, prevnum):
-                            childpath = self.getrelpath("/" + childpath)
+                            childpath = self.getrelpath(b"/" + childpath)
                             if childpath:
                                 changed.add(self.recode(childpath))
 
                 for childpath in self._iterfiles(path, revnum):
-                    childpath = self.getrelpath("/" + childpath)
+                    childpath = self.getrelpath(b"/" + childpath)
                     if childpath:
                         changed.add(self.recode(childpath))
 
@@ -956,12 +959,12 @@
                 if not copyfrompath:
                     continue
                 self.ui.debug(
-                    "mark %s came from %s:%d\n"
+                    b"mark %s came from %s:%d\n"
                     % (path, copyfrompath, ent.copyfrom_rev)
                 )
                 children = self._iterfiles(ent.copyfrom_path, ent.copyfrom_rev)
                 for childpath in children:
-                    childpath = self.getrelpath("/" + childpath, pmodule)
+                    childpath = self.getrelpath(b"/" + childpath, pmodule)
                     if not childpath:
                         continue
                     copytopath = path + childpath[len(copyfrompath) :]
@@ -983,7 +986,8 @@
             the revision is a branch root.
             """
             self.ui.debug(
-                "parsing revision %d (%d changes)\n" % (revnum, len(orig_paths))
+                b"parsing revision %d (%d changes)\n"
+                % (revnum, len(orig_paths))
             )
 
             branched = False
@@ -1012,11 +1016,11 @@
                         if prevnum >= self.startrev:
                             parents = [previd]
                             self.ui.note(
-                                _('found parent of branch %s at %d: %s\n')
+                                _(b'found parent of branch %s at %d: %s\n')
                                 % (self.module, prevnum, prevmodule)
                             )
                 else:
-                    self.ui.debug("no copyfrom path, don't know what to do.\n")
+                    self.ui.debug(b"no copyfrom path, don't know what to do.\n")
 
             paths = []
             # filter out unrelated paths
@@ -1028,22 +1032,24 @@
             # Example SVN datetime. Includes microseconds.
             # ISO-8601 conformant
             # '2007-01-04T17:35:00.902377Z'
-            date = dateutil.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
-            if self.ui.configbool('convert', 'localtimezone'):
+            date = dateutil.parsedate(
+                date[:19] + b" UTC", [b"%Y-%m-%dT%H:%M:%S"]
+            )
+            if self.ui.configbool(b'convert', b'localtimezone'):
                 date = makedatetimestamp(date[0])
 
             if message:
                 log = self.recode(message)
             else:
-                log = ''
+                log = b''
 
             if author:
                 author = self.recode(author)
             else:
-                author = ''
+                author = b''
 
             try:
-                branch = self.module.split("/")[-1]
+                branch = self.module.split(b"/")[-1]
                 if branch == self.trunkname:
                     branch = None
             except IndexError:
@@ -1051,7 +1057,7 @@
 
             cset = commit(
                 author=author,
-                date=dateutil.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
+                date=dateutil.datestr(date, b'%Y-%m-%d %H:%M:%S %1%2'),
                 desc=log,
                 parents=parents,
                 branch=branch,
@@ -1068,7 +1074,7 @@
             return cset, branched
 
         self.ui.note(
-            _('fetching revision log for "%s" from %d to %d\n')
+            _(b'fetching revision log for "%s" from %d to %d\n')
             % (self.module, from_revnum, to_revnum)
         )
 
@@ -1083,7 +1089,7 @@
                         lastonbranch = True
                         break
                     if not paths:
-                        self.ui.debug('revision %d has no entries\n' % revnum)
+                        self.ui.debug(b'revision %d has no entries\n' % revnum)
                         # If we ever leave the loop on an empty
                         # revision, do not try to get a parent branch
                         lastonbranch = lastonbranch or revnum == 0
@@ -1114,7 +1120,7 @@
             (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') % to_revnum
+                    _(b'svn: branch has no revision %s') % to_revnum
                 )
             raise
 
@@ -1135,8 +1141,8 @@
             io.close()
             if isinstance(info, list):
                 info = info[-1]
-            mode = ("svn:executable" in info) and 'x' or ''
-            mode = ("svn:special" in info) and 'l' or mode
+            mode = (b"svn:executable" in info) and b'x' or b''
+            mode = (b"svn:special" in info) and b'l' or mode
         except svn.core.SubversionException as e:
             notfound = (
                 svn.core.SVN_ERR_FS_NOT_FOUND,
@@ -1145,20 +1151,20 @@
             if e.apr_err in notfound:  # File not found
                 return None, None
             raise
-        if mode == 'l':
-            link_prefix = "link "
+        if mode == b'l':
+            link_prefix = b"link "
             if data.startswith(link_prefix):
                 data = data[len(link_prefix) :]
         return data, mode
 
     def _iterfiles(self, path, revnum):
         """Enumerate all files in path at revnum, recursively."""
-        path = path.strip('/')
+        path = path.strip(b'/')
         pool = svn.core.Pool()
-        rpath = '/'.join([self.baseurl, quote(path)]).strip('/')
+        rpath = b'/'.join([self.baseurl, quote(path)]).strip(b'/')
         entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool)
         if path:
-            path += '/'
+            path += b'/'
         return (
             (path + p)
             for p, e in entries.iteritems()
@@ -1175,24 +1181,24 @@
         #   "/CMFPlone/branches/Plone-2_0-branch/tests/PloneTestCase.py"
         # that is to say "tests/PloneTestCase.py"
         if path.startswith(module):
-            relative = path.rstrip('/')[len(module) :]
-            if relative.startswith('/'):
+            relative = path.rstrip(b'/')[len(module) :]
+            if relative.startswith(b'/'):
                 return relative[1:]
-            elif relative == '':
+            elif relative == b'':
                 return relative
 
         # The path is outside our tracked tree...
-        self.ui.debug('%r is not under %r, ignoring\n' % (path, module))
+        self.ui.debug(b'%r is not under %r, ignoring\n' % (path, module))
         return None
 
     def _checkpath(self, path, revnum, module=None):
         if module is not None:
-            prevmodule = self.reparent('')
-            path = module + '/' + path
+            prevmodule = self.reparent(b'')
+            path = module + b'/' + path
         try:
             # ra.check_path does not like leading slashes very much, it leads
             # to PROPFIND subversion errors
-            return svn.ra.check_path(self.ra, path.strip('/'), revnum)
+            return svn.ra.check_path(self.ra, path.strip(b'/'), revnum)
         finally:
             if module is not None:
                 self.reparent(prevmodule)
@@ -1210,9 +1216,9 @@
         # supplied URL
         relpaths = []
         for p in paths:
-            if not p.startswith('/'):
-                p = self.module + '/' + p
-            relpaths.append(p.strip('/'))
+            if not p.startswith(b'/'):
+                p = self.module + b'/' + p
+            relpaths.append(p.strip(b'/'))
         args = [
             self.baseurl,
             relpaths,
@@ -1223,11 +1229,11 @@
             strict_node_history,
         ]
         # developer config: convert.svn.debugsvnlog
-        if not self.ui.configbool('convert', 'svn.debugsvnlog'):
+        if not self.ui.configbool(b'convert', b'svn.debugsvnlog'):
             return directlogstream(*args)
         arg = encodeargs(args)
         hgexe = procutil.hgexecutable()
-        cmd = '%s debugsvnlog' % procutil.shellquote(hgexe)
+        cmd = b'%s debugsvnlog' % procutil.shellquote(hgexe)
         stdin, stdout = procutil.popen2(procutil.quotecommand(cmd))
         stdin.write(arg)
         try:
@@ -1235,8 +1241,8 @@
         except IOError:
             raise error.Abort(
                 _(
-                    'Mercurial failed to run itself, check'
-                    ' hg executable is in PATH'
+                    b'Mercurial failed to run itself, check'
+                    b' hg executable is in PATH'
                 )
             )
         return logstream(stdout)
@@ -1272,18 +1278,18 @@
             os.chdir(self.cwd)
 
     def join(self, name):
-        return os.path.join(self.wc, '.svn', name)
+        return os.path.join(self.wc, b'.svn', name)
 
     def revmapfile(self):
-        return self.join('hg-shamap')
+        return self.join(b'hg-shamap')
 
     def authorfile(self):
-        return self.join('hg-authormap')
+        return self.join(b'hg-authormap')
 
     def __init__(self, ui, repotype, path):
 
         converter_sink.__init__(self, ui, repotype, path)
-        commandline.__init__(self, ui, 'svn')
+        commandline.__init__(self, ui, b'svn')
         self.delete = []
         self.setexec = []
         self.delexec = []
@@ -1292,51 +1298,53 @@
         self.cwd = encoding.getcwd()
 
         created = False
-        if os.path.isfile(os.path.join(path, '.svn', 'entries')):
+        if os.path.isfile(os.path.join(path, b'.svn', b'entries')):
             self.wc = os.path.realpath(path)
-            self.run0('update')
+            self.run0(b'update')
         else:
             if not re.search(br'^(file|http|https|svn|svn\+ssh)\://', path):
                 path = os.path.realpath(path)
                 if os.path.isdir(os.path.dirname(path)):
-                    if not os.path.exists(os.path.join(path, 'db', 'fs-type')):
+                    if not os.path.exists(
+                        os.path.join(path, b'db', b'fs-type')
+                    ):
                         ui.status(
-                            _("initializing svn repository '%s'\n")
+                            _(b"initializing svn repository '%s'\n")
                             % os.path.basename(path)
                         )
-                        commandline(ui, 'svnadmin').run0('create', path)
+                        commandline(ui, b'svnadmin').run0(b'create', path)
                         created = path
                     path = util.normpath(path)
-                    if not path.startswith('/'):
-                        path = '/' + path
-                    path = 'file://' + path
+                    if not path.startswith(b'/'):
+                        path = b'/' + path
+                    path = b'file://' + path
 
             wcpath = os.path.join(
-                encoding.getcwd(), os.path.basename(path) + '-wc'
+                encoding.getcwd(), os.path.basename(path) + b'-wc'
             )
             ui.status(
-                _("initializing svn working copy '%s'\n")
+                _(b"initializing svn working copy '%s'\n")
                 % os.path.basename(wcpath)
             )
-            self.run0('checkout', path, wcpath)
+            self.run0(b'checkout', path, wcpath)
 
             self.wc = wcpath
         self.opener = vfsmod.vfs(self.wc)
         self.wopener = vfsmod.vfs(self.wc)
-        self.childmap = mapfile(ui, self.join('hg-childmap'))
+        self.childmap = mapfile(ui, self.join(b'hg-childmap'))
         if util.checkexec(self.wc):
             self.is_exec = util.isexec
         else:
             self.is_exec = None
 
         if created:
-            hook = os.path.join(created, 'hooks', 'pre-revprop-change')
-            fp = open(hook, 'wb')
+            hook = os.path.join(created, b'hooks', b'pre-revprop-change')
+            fp = open(hook, b'wb')
             fp.write(pre_revprop_change)
             fp.close()
             util.setflags(hook, False, True)
 
-        output = self.run0('info')
+        output = self.run0(b'info')
         self.uuid = self.uuid_re.search(output).group(1).strip()
 
     def wjoin(self, *names):
@@ -1348,7 +1356,7 @@
         # already tracked entries, so we have to track and filter them
         # ourselves.
         m = set()
-        output = self.run0('ls', recursive=True, xml=True)
+        output = self.run0(b'ls', recursive=True, xml=True)
         doc = xml.dom.minidom.parseString(output)
         for e in doc.getElementsByTagName(r'entry'):
             for n in e.childNodes:
@@ -1367,7 +1375,7 @@
         return m
 
     def putfile(self, filename, flags, data):
-        if 'l' in flags:
+        if b'l' in flags:
             self.wopener.symlink(data, filename)
         else:
             try:
@@ -1387,12 +1395,12 @@
 
             if self.is_exec:
                 if wasexec:
-                    if 'x' not in flags:
+                    if b'x' not in flags:
                         self.delexec.append(filename)
                 else:
-                    if 'x' in flags:
+                    if b'x' in flags:
                         self.setexec.append(filename)
-                util.setflags(self.wjoin(filename), False, 'x' in flags)
+                util.setflags(self.wjoin(filename), False, b'x' in flags)
 
     def _copyfile(self, source, dest):
         # SVN's copy command pukes if the destination file exists, but
@@ -1402,13 +1410,13 @@
         exists = os.path.lexists(wdest)
         if exists:
             fd, tempname = pycompat.mkstemp(
-                prefix='hg-copy-', dir=os.path.dirname(wdest)
+                prefix=b'hg-copy-', dir=os.path.dirname(wdest)
             )
             os.close(fd)
             os.unlink(tempname)
             os.rename(wdest, tempname)
         try:
-            self.run0('copy', source, dest)
+            self.run0(b'copy', source, dest)
         finally:
             self.manifest.add(dest)
             if exists:
@@ -1424,7 +1432,7 @@
             if os.path.isdir(self.wjoin(f)):
                 dirs.add(f)
             i = len(f)
-            for i in iter(lambda: f.rfind('/', 0, i), -1):
+            for i in iter(lambda: f.rfind(b'/', 0, i), -1):
                 dirs.add(f[:i])
         return dirs
 
@@ -1434,21 +1442,21 @@
         ]
         if add_dirs:
             self.manifest.update(add_dirs)
-            self.xargs(add_dirs, 'add', non_recursive=True, quiet=True)
+            self.xargs(add_dirs, b'add', non_recursive=True, quiet=True)
         return add_dirs
 
     def add_files(self, files):
         files = [f for f in files if f not in self.manifest]
         if files:
             self.manifest.update(files)
-            self.xargs(files, 'add', quiet=True)
+            self.xargs(files, b'add', quiet=True)
         return files
 
     def addchild(self, parent, child):
         self.childmap[parent] = child
 
     def revid(self, rev):
-        return "svn:%s@%s" % (self.uuid, rev)
+        return b"svn:%s@%s" % (self.uuid, rev)
 
     def putcommit(
         self, files, copies, parents, commit, source, revmap, full, cleanp2
@@ -1480,49 +1488,49 @@
                 self._copyfile(s, d)
             self.copies = []
         if self.delete:
-            self.xargs(self.delete, 'delete')
+            self.xargs(self.delete, b'delete')
             for f in self.delete:
                 self.manifest.remove(f)
             self.delete = []
         entries.update(self.add_files(files.difference(entries)))
         if self.delexec:
-            self.xargs(self.delexec, 'propdel', 'svn:executable')
+            self.xargs(self.delexec, b'propdel', b'svn:executable')
             self.delexec = []
         if self.setexec:
-            self.xargs(self.setexec, 'propset', 'svn:executable', '*')
+            self.xargs(self.setexec, b'propset', b'svn:executable', b'*')
             self.setexec = []
 
-        fd, messagefile = pycompat.mkstemp(prefix='hg-convert-')
+        fd, messagefile = pycompat.mkstemp(prefix=b'hg-convert-')
         fp = os.fdopen(fd, r'wb')
         fp.write(util.tonativeeol(commit.desc))
         fp.close()
         try:
             output = self.run0(
-                'commit',
+                b'commit',
                 username=stringutil.shortuser(commit.author),
                 file=messagefile,
-                encoding='utf-8',
+                encoding=b'utf-8',
             )
             try:
                 rev = self.commit_re.search(output).group(1)
             except AttributeError:
                 if not files:
-                    return parents[0] if parents else 'None'
-                self.ui.warn(_('unexpected svn output:\n'))
+                    return parents[0] if parents else b'None'
+                self.ui.warn(_(b'unexpected svn output:\n'))
                 self.ui.warn(output)
-                raise error.Abort(_('unable to cope with svn output'))
+                raise error.Abort(_(b'unable to cope with svn output'))
             if commit.rev:
                 self.run(
-                    'propset',
-                    'hg:convert-rev',
+                    b'propset',
+                    b'hg:convert-rev',
                     commit.rev,
                     revprop=True,
                     revision=rev,
                 )
-            if commit.branch and commit.branch != 'default':
+            if commit.branch and commit.branch != b'default':
                 self.run(
-                    'propset',
-                    'hg:convert-branch',
+                    b'propset',
+                    b'hg:convert-branch',
                     commit.branch,
                     revprop=True,
                     revision=rev,
@@ -1534,7 +1542,7 @@
             os.unlink(messagefile)
 
     def puttags(self, tags):
-        self.ui.warn(_('writing Subversion tags is not yet implemented\n'))
+        self.ui.warn(_(b'writing Subversion tags is not yet implemented\n'))
         return None, None
 
     def hascommitfrommap(self, rev):
@@ -1549,8 +1557,8 @@
             return True
         raise error.Abort(
             _(
-                'splice map revision %s not found in subversion '
-                'child map (revision lookups are not implemented)'
+                b'splice map revision %s not found in subversion '
+                b'child map (revision lookups are not implemented)'
             )
             % rev
         )