--- a/hgext/convert/convcmd.py Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/convert/convcmd.py Sun Oct 06 09:48:39 2019 -0400
@@ -52,7 +52,7 @@
svn_sink = subversion.svn_sink
svn_source = subversion.svn_source
-orig_encoding = 'ascii'
+orig_encoding = b'ascii'
def recode(s):
@@ -90,36 +90,36 @@
# destination repository. For such commits, using a literal "default"
# in branchmap below allows the user to map "default" to an alternate
# default branch in the destination repository.
- branch = branchmap.get(branch or 'default', branch)
+ branch = branchmap.get(branch or b'default', branch)
# At some point we used "None" literal to denote the default branch,
# attempt to use that for backward compatibility.
if not branch:
- branch = branchmap.get('None', branch)
+ branch = branchmap.get(b'None', branch)
return branch
source_converters = [
- ('cvs', convert_cvs, 'branchsort'),
- ('git', convert_git, 'branchsort'),
- ('svn', svn_source, 'branchsort'),
- ('hg', mercurial_source, 'sourcesort'),
- ('darcs', darcs_source, 'branchsort'),
- ('mtn', monotone_source, 'branchsort'),
- ('gnuarch', gnuarch_source, 'branchsort'),
- ('bzr', bzr_source, 'branchsort'),
- ('p4', p4_source, 'branchsort'),
+ (b'cvs', convert_cvs, b'branchsort'),
+ (b'git', convert_git, b'branchsort'),
+ (b'svn', svn_source, b'branchsort'),
+ (b'hg', mercurial_source, b'sourcesort'),
+ (b'darcs', darcs_source, b'branchsort'),
+ (b'mtn', monotone_source, b'branchsort'),
+ (b'gnuarch', gnuarch_source, b'branchsort'),
+ (b'bzr', bzr_source, b'branchsort'),
+ (b'p4', p4_source, b'branchsort'),
]
sink_converters = [
- ('hg', mercurial_sink),
- ('svn', svn_sink),
+ (b'hg', mercurial_sink),
+ (b'svn', svn_sink),
]
def convertsource(ui, path, type, revs):
exceptions = []
if type and type not in [s[0] for s in source_converters]:
- raise error.Abort(_('%s: invalid source repository type') % type)
+ raise error.Abort(_(b'%s: invalid source repository type') % type)
for name, source, sortmode in source_converters:
try:
if not type or name == type:
@@ -128,22 +128,22 @@
exceptions.append(inst)
if not ui.quiet:
for inst in exceptions:
- ui.write("%s\n" % pycompat.bytestr(inst.args[0]))
- raise error.Abort(_('%s: missing or unsupported repository') % path)
+ ui.write(b"%s\n" % pycompat.bytestr(inst.args[0]))
+ raise error.Abort(_(b'%s: missing or unsupported repository') % path)
def convertsink(ui, path, type):
if type and type not in [s[0] for s in sink_converters]:
- raise error.Abort(_('%s: invalid destination repository type') % type)
+ raise error.Abort(_(b'%s: invalid destination repository type') % type)
for name, sink in sink_converters:
try:
if not type or name == type:
return sink(ui, name, path)
except NoRepo as inst:
- ui.note(_("convert: %s\n") % inst)
+ ui.note(_(b"convert: %s\n") % inst)
except MissingTool as inst:
- raise error.Abort('%s\n' % inst)
- raise error.Abort(_('%s: unknown repository type') % path)
+ raise error.Abort(b'%s\n' % inst)
+ raise error.Abort(_(b'%s: unknown repository type') % path)
class progresssource(object):
@@ -151,7 +151,7 @@
self.ui = ui
self.source = source
self.progress = ui.makeprogress(
- _('getting files'), unit=_('files'), total=filecount
+ _(b'getting files'), unit=_(b'files'), total=filecount
)
def getfile(self, file, rev):
@@ -189,12 +189,12 @@
if authorfile and os.path.exists(authorfile):
self.readauthormap(authorfile)
# Extend/Override with new author map if necessary
- if opts.get('authormap'):
- self.readauthormap(opts.get('authormap'))
+ if opts.get(b'authormap'):
+ self.readauthormap(opts.get(b'authormap'))
self.authorfile = self.dest.authorfile()
- self.splicemap = self.parsesplicemap(opts.get('splicemap'))
- self.branchmap = mapfile(ui, opts.get('branchmap'))
+ self.splicemap = self.parsesplicemap(opts.get(b'splicemap'))
+ self.branchmap = mapfile(ui, opts.get(b'branchmap'))
def parsesplicemap(self, path):
""" check and validate the splicemap format and
@@ -211,21 +211,21 @@
return {}
m = {}
try:
- fp = open(path, 'rb')
+ fp = open(path, b'rb')
for i, line in enumerate(util.iterfile(fp)):
line = line.splitlines()[0].rstrip()
if not line:
# Ignore blank lines
continue
# split line
- lex = common.shlexer(data=line, whitespace=',')
+ lex = common.shlexer(data=line, whitespace=b',')
line = list(lex)
# check number of parents
if not (2 <= len(line) <= 3):
raise error.Abort(
_(
- 'syntax error in %s(%d): child parent1'
- '[,parent2] expected'
+ b'syntax error in %s(%d): child parent1'
+ b'[,parent2] expected'
)
% (path, i + 1)
)
@@ -239,7 +239,7 @@
# if file does not exist or error reading, exit
except IOError:
raise error.Abort(
- _('splicemap file not found or error reading %s:') % path
+ _(b'splicemap file not found or error reading %s:') % path
)
return m
@@ -251,7 +251,7 @@
parents = {}
numcommits = self.source.numcommits()
progress = self.ui.makeprogress(
- _('scanning'), unit=_('revisions'), total=numcommits
+ _(b'scanning'), unit=_(b'revisions'), total=numcommits
)
while visit:
n = visit.pop(0)
@@ -283,8 +283,8 @@
# Could be in source but not converted during this run
self.ui.warn(
_(
- 'splice map revision %s is not being '
- 'converted, ignoring\n'
+ b'splice map revision %s is not being '
+ b'converted, ignoring\n'
)
% c
)
@@ -296,7 +296,7 @@
continue
# Parent is not in dest and not being converted, not good
if p not in parents:
- raise error.Abort(_('unknown splice map parent: %s') % p)
+ raise error.Abort(_(b'unknown splice map parent: %s') % p)
pc.append(p)
parents[c] = pc
@@ -369,7 +369,7 @@
def makeclosesorter():
"""Close order sort."""
keyfn = lambda n: (
- 'close' not in self.commitcache[n].extra,
+ b'close' not in self.commitcache[n].extra,
self.commitcache[n].sortkey,
)
@@ -392,16 +392,16 @@
return picknext
- if sortmode == 'branchsort':
+ if sortmode == b'branchsort':
picknext = makebranchsorter()
- elif sortmode == 'datesort':
+ elif sortmode == b'datesort':
picknext = makedatesorter()
- elif sortmode == 'sourcesort':
+ elif sortmode == b'sourcesort':
picknext = makesourcesorter()
- elif sortmode == 'closesort':
+ elif sortmode == b'closesort':
picknext = makeclosesorter()
else:
- raise error.Abort(_('unknown sort mode: %s') % sortmode)
+ raise error.Abort(_(b'unknown sort mode: %s') % sortmode)
children, actives = mapchildren(parents)
@@ -420,7 +420,7 @@
pendings[c].remove(n)
except ValueError:
raise error.Abort(
- _('cycle detected between %s and %s')
+ _(b'cycle detected between %s and %s')
% (recode(c), recode(n))
)
if not pendings[c]:
@@ -429,45 +429,47 @@
pendings[c] = None
if len(s) != len(parents):
- raise error.Abort(_("not all revisions were sorted"))
+ raise error.Abort(_(b"not all revisions were sorted"))
return s
def writeauthormap(self):
authorfile = self.authorfile
if authorfile:
- self.ui.status(_('writing author map file %s\n') % authorfile)
- ofile = open(authorfile, 'wb+')
+ self.ui.status(_(b'writing author map file %s\n') % authorfile)
+ ofile = open(authorfile, b'wb+')
for author in self.authors:
ofile.write(
- util.tonativeeol("%s=%s\n" % (author, self.authors[author]))
+ util.tonativeeol(
+ b"%s=%s\n" % (author, self.authors[author])
+ )
)
ofile.close()
def readauthormap(self, authorfile):
- afile = open(authorfile, 'rb')
+ afile = open(authorfile, b'rb')
for line in afile:
line = line.strip()
- if not line or line.startswith('#'):
+ if not line or line.startswith(b'#'):
continue
try:
- srcauthor, dstauthor = line.split('=', 1)
+ srcauthor, dstauthor = line.split(b'=', 1)
except ValueError:
- msg = _('ignoring bad line in author map file %s: %s\n')
+ msg = _(b'ignoring bad line in author map file %s: %s\n')
self.ui.warn(msg % (authorfile, line.rstrip()))
continue
srcauthor = srcauthor.strip()
dstauthor = dstauthor.strip()
if self.authors.get(srcauthor) in (None, dstauthor):
- msg = _('mapping author %s to %s\n')
+ msg = _(b'mapping author %s to %s\n')
self.ui.debug(msg % (srcauthor, dstauthor))
self.authors[srcauthor] = dstauthor
continue
- m = _('overriding mapping for author %s, was %s, will be %s\n')
+ m = _(b'overriding mapping for author %s, was %s, will be %s\n')
self.ui.status(m % (srcauthor, self.authors[srcauthor], dstauthor))
afile.close()
@@ -481,7 +483,7 @@
def copy(self, rev):
commit = self.commitcache[rev]
- full = self.opts.get('full')
+ full = self.opts.get(b'full')
changes = self.source.getchanges(rev, full)
if isinstance(changes, bytes):
if changes == SKIPREV:
@@ -503,8 +505,8 @@
try:
parents = self.splicemap[rev]
self.ui.status(
- _('spliced in %s as parents of %s\n')
- % (_(' and ').join(parents), rev)
+ _(b'spliced in %s as parents of %s\n')
+ % (_(b' and ').join(parents), rev)
)
parents = [self.map.get(p, p) for p in parents]
except KeyError:
@@ -536,34 +538,34 @@
self.source.before()
self.dest.before()
self.source.setrevmap(self.map)
- self.ui.status(_("scanning source...\n"))
+ self.ui.status(_(b"scanning source...\n"))
heads = self.source.getheads()
parents = self.walktree(heads)
self.mergesplicemap(parents, self.splicemap)
- self.ui.status(_("sorting...\n"))
+ self.ui.status(_(b"sorting...\n"))
t = self.toposort(parents, sortmode)
num = len(t)
c = None
- self.ui.status(_("converting...\n"))
+ self.ui.status(_(b"converting...\n"))
progress = self.ui.makeprogress(
- _('converting'), unit=_('revisions'), total=len(t)
+ _(b'converting'), unit=_(b'revisions'), total=len(t)
)
for i, c in enumerate(t):
num -= 1
desc = self.commitcache[c].desc
- if "\n" in desc:
+ if b"\n" in desc:
desc = desc.splitlines()[0]
# convert log message to local encoding without using
# tolocal() because the encoding.encoding convert()
# uses is 'utf-8'
- self.ui.status("%d %s\n" % (num, recode(desc)))
- self.ui.note(_("source: %s\n") % recode(c))
+ self.ui.status(b"%d %s\n" % (num, recode(desc)))
+ self.ui.note(_(b"source: %s\n") % recode(c))
progress.update(i)
self.copy(c)
progress.complete()
- if not self.ui.configbool('convert', 'skiptags'):
+ if not self.ui.configbool(b'convert', b'skiptags'):
tags = self.source.gettags()
ctags = {}
for k in tags:
@@ -610,45 +612,47 @@
opts = pycompat.byteskwargs(opts)
global orig_encoding
orig_encoding = encoding.encoding
- encoding.encoding = 'UTF-8'
+ encoding.encoding = b'UTF-8'
# support --authors as an alias for --authormap
- if not opts.get('authormap'):
- opts['authormap'] = opts.get('authors')
+ if not opts.get(b'authormap'):
+ opts[b'authormap'] = opts.get(b'authors')
if not dest:
- dest = hg.defaultdest(src) + "-hg"
- ui.status(_("assuming destination %s\n") % dest)
+ dest = hg.defaultdest(src) + b"-hg"
+ ui.status(_(b"assuming destination %s\n") % dest)
- destc = convertsink(ui, dest, opts.get('dest_type'))
+ destc = convertsink(ui, dest, opts.get(b'dest_type'))
destc = scmutil.wrapconvertsink(destc)
try:
srcc, defaultsort = convertsource(
- ui, src, opts.get('source_type'), opts.get('rev')
+ ui, src, opts.get(b'source_type'), opts.get(b'rev')
)
except Exception:
for path in destc.created:
shutil.rmtree(path, True)
raise
- sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort')
+ sortmodes = (b'branchsort', b'datesort', b'sourcesort', b'closesort')
sortmode = [m for m in sortmodes if opts.get(m)]
if len(sortmode) > 1:
- raise error.Abort(_('more than one sort mode specified'))
+ raise error.Abort(_(b'more than one sort mode specified'))
if sortmode:
sortmode = sortmode[0]
else:
sortmode = defaultsort
- if sortmode == 'sourcesort' and not srcc.hasnativeorder():
+ if sortmode == b'sourcesort' and not srcc.hasnativeorder():
raise error.Abort(
- _('--sourcesort is not supported by this data source')
+ _(b'--sourcesort is not supported by this data source')
)
- if sortmode == 'closesort' and not srcc.hasnativeclose():
- raise error.Abort(_('--closesort is not supported by this data source'))
+ if sortmode == b'closesort' and not srcc.hasnativeclose():
+ raise error.Abort(
+ _(b'--closesort is not supported by this data source')
+ )
- fmap = opts.get('filemap')
+ fmap = opts.get(b'filemap')
if fmap:
srcc = filemap.filemap_source(ui, srcc, fmap)
destc.setfilemapmode(True)