4096
  5   ˆl–Ým_JJi?u8 Z¸n6Ò˜´o�þB g…Ž2Ûà'óÂƒh¹ÁÀ¿      0
  B   ˆl–ß=¿J
hŠm@Šãn\i¥1hß�þe YÆ@FÇ¤f0ùÃ„p@ ?Â_ŠI|¥�+Wé3ž¯ÂÁ ?÷     # Subversion 1.4/1.5 Python API backend
#
# Copyright(C) 2007 Daniel Holth et al

import codecs
import locale
import os
import pickle
import re
import xml.dom.minidom

from mercurial.i18n import _
from mercurial.pycompat import open
from mercurial import (
    encoding,
    error,
    pycompat,
    util,
    vfs as vfsmod,
)
from mercurial.utils import (
    dateutil,
    procutil,
    stringutil,
)

from . import common

stringio = util.stringio
propertycache = util.propertycache
urlerr = util.urlerr
urlreq = util.urlreq

commandline = common.commandline
commit = common.commit
converter_sink = common.converter_sink
converter_source = common.converter_source
decodeargs = common.decodeargs
encodeargs = common.encodeargs
makedatetimestamp = common.makedatetimestamp
mapfile = common.mapfile
MissingTool = common.MissingTool
NoRepo = common.NoRepo

# Subversion stuff. Works best with very recent Python SVN bindings
# e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing
# these bindings.

try:
    import svn
    import svn.client
    import svn.core
    import svn.ra
    import svn.delta
    from . import transport
    import warnings

    warnings.filterwarnings(
        'ignore', module='svn.core', category=DeprecationWarning
    )
    svn.core.SubversionException  # trigger import to catch error

except ImportError:
    svn = None


# In Subversion, paths and URLs are Unicode (encoded as UTF-8), which
# Subversion converts from / to native strings when interfacing with the OS.
# When passing paths and URLs to Subversion, we have to recode them such that
# it roundstrips with what Subversion is doing.

fsencoding = None


def init_fsencoding():
    global fsencoding, fsencoding_is_utf8
    if fsencoding is not None:
        return
    if pycompat.iswindows:
        # On Windows, filenames are Unicode, but we store them using the MBCS
        # encoding.
        fsencoding = 'mbcs'
    else:
        # This is the encoding used to convert UTF-8 back to natively-encoded
        # strings in Subversion 1.14.0 or earlier with APR 1.7.0 or earlier.
        with util.with_lc_ctype():
            fsencoding = locale.nl_langinfo(locale.CODESET) or 'ISO-8859-1'
    fsencoding = codecs.lookup(fsencoding).name
    fsencoding_is_utf8 = fsencoding == codecs.lookup('utf-8').name


def fs2svn(s):
    if fsencoding_is_utf8:
        return s
    else:
        return s.decode(fsencoding).encode('utf-8')


def formatsvndate(date):
    return dateutil.datestr(date, b'%Y-%m-%dT%H:%M:%S.000000Z')


def parsesvndate(s):
    # Example SVN datetime. Includes microseconds.
    # ISO-8601 conformant
    # '2007-01-04T17:35:00.902377Z'
    return dateutil.parsedate(s[:19] + b' UTC', [b'%Y-%m-%dT%H:%M:%S'])


class SvnPathNotFound(Exception):
    pass


def revsplit(rev):
    """Parse a revision string and return (uuid, path, revnum).
    >>> revsplit(b'svn:a2147622-4a9f-4db4-a8d3-13562ff547b2'
    ...          b'/proj%20B/mytrunk/mytrunk@1')
    ('a2147622-4a9f-4db4-a8d3-13562ff547b2', '/proj%20B/mytrunk/mytrunk', 1)
    >>> revsplit(b'svn:8af66a51-67f5-4354-b62c-98d67cc7be1d@1')
    ('', '', 1)
    >>> revsplit(b'@7')
    ('', '', 7)
    >>> revsplit(b'7')
    ('', '', 0)
    >>> revsplit(b'bad')
    ('', '', 0)
    """
    parts = rev.rsplit(b'@', 1)
    revnum = 0
    if len(parts) > 1:
        revnum = int(parts[1])
    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 = b'/' + parts[1]
    return uuid, mod, revnum


def quote(s):
    # As of svn 1.7, many svn calls expect "canonical" paths. In
    # theory, we should call svn.core.*canonicalize() on all paths
    # before passing them to the API.  Instead, we assume the base url
    # is canonical and copy the behaviour of svn URL encoding function
    # so we can extend it safely with new components. The "safe"
    # char