00000070
  C   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þ[u©VnP¸VDHÓ@þÎ„™l?Ë_ŠI|¥�+Wé3ž¯ÁÉ ?÷     # convcmd - convert extension commands definition
#
# Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

import collections
import os
import shutil

from mercurial.i18n import _
from mercurial.pycompat import open
from mercurial import (
    encoding,
    error,
    hg,
    pycompat,
    scmutil,
    util,
)
from mercurial.utils import dateutil

from . import (
    bzr,
    common,
    cvs,
    darcs,
    filemap,
    git,
    gnuarch,
    hg as hgconvert,
    monotone,
    p4,
    subversion,
)

mapfile = common.mapfile
MissingTool = common.MissingTool
NoRepo = common.NoRepo
SKIPREV = common.SKIPREV

bzr_source = bzr.bzr_source
convert_cvs = cvs.convert_cvs
convert_git = git.convert_git
darcs_source = darcs.darcs_source
gnuarch_source = gnuarch.gnuarch_source
mercurial_sink = hgconvert.mercurial_sink
mercurial_source = hgconvert.mercurial_source
monotone_source = monotone.monotone_source
p4_source = p4.p4_source
svn_sink = subversion.svn_sink
svn_source = subversion.svn_source

orig_encoding = b'ascii'


def readauthormap(ui, authorfile, authors=None):
    if authors is None:
        authors = {}
    with open(authorfile, b'rb') as afile:
        for line in afile:

            line = line.strip()
            if not line or line.startswith(b'#'):
                continue

            try:
                srcauthor, dstauthor = line.split(b'=', 1)
            except ValueError:
                msg = _(b'ignoring bad line in author map file %s: %s\n')
                ui.warn(msg % (authorfile, line.rstrip()))
                continue

            srcauthor = srcauthor.strip()
            dstauthor = dstauthor.strip()
            if authors.get(srcauthor) in (None, dstauthor):
                msg = _(b'mapping author %s to %s\n')
                ui.debug(msg % (srcauthor, dstauthor))
                authors[srcauthor] = dstauthor
                continue

            m = _(b'overriding mapping for author %s, was %s, will be %s\n')
            ui.status(m % (srcauthor, authors[srcauthor], dstauthor))
    return authors


def recode(s):
    if isinstance(s, str):
        return s.encode(pycompat.sysstr(orig_encoding), 'replace')
    else:
        return s.decode('utf-8').encode(
            pycompat.sysstr(orig_encoding), 'replace'
        )


def mapbranch(branch, branchmap):
    """
    >>> bmap = {b'default': b'branch1'}
    >>> for i in [b'', None]:
    ...     mapbranch(i, bmap)
    'branch1'
    'branch1'
    >>> bmap = {b'None': b'branch2'}
    >>> for i in [b'', None]:
    ...     mapbranch(i, bmap)
    'branch2'
    'branch2'
    >>> bmap = {b'None': b'branch3', b'default': b'branch4'}
    >>> for i in [b'None', b'', None, b'default', b'branch5']:
    ...     mapbranch(i, bmap)
    'branch3'
    'branch4'
    'branch4'
    'branch4'
    'branch5'
    """
    # If branch is None or empty, this commit is coming from the source
    # repository's default branch and destined for the default branch in the
    # 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 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(b'None', branch)
    return branch


source_converters = [
    (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_converte