# HG changeset patch # User Mads Kiilerich # Date 2022-03-07 16:47:13 # Node ID da519b9782e89304652f477144cfd083374c568f # Parent 017595560fc1e0f2acc086c63ed5f8906011d77b hg: support Mercurial 6.1 without util.url diff --git a/kallithea/lib/vcs/backends/git/repository.py b/kallithea/lib/vcs/backends/git/repository.py --- a/kallithea/lib/vcs/backends/git/repository.py +++ b/kallithea/lib/vcs/backends/git/repository.py @@ -19,7 +19,12 @@ import urllib.parse import urllib.request from collections import OrderedDict -import mercurial.util # import url as hg_url + +try: + from mercurial.utils.urlutil import url as hg_url +except ImportError: # urlutil was introduced in Mercurial 5.8 + from mercurial.util import url as hg_url + from dulwich.client import SubprocessGitClient from dulwich.config import ConfigFile from dulwich.objects import Tag @@ -226,7 +231,7 @@ class GitRepository(BaseRepository): if parsed_url.scheme not in ['http', 'https']: raise urllib.error.URLError("Unsupported protocol in URL %r" % url) - url_obj = mercurial.util.url(safe_bytes(url)) + url_obj = hg_url(safe_bytes(url)) test_uri, handlers = get_urllib_request_handlers(url_obj) if not test_uri.endswith(b'info/refs'): test_uri = test_uri.rstrip(b'/') + b'/info/refs' diff --git a/kallithea/lib/vcs/backends/hg/repository.py b/kallithea/lib/vcs/backends/hg/repository.py --- a/kallithea/lib/vcs/backends/hg/repository.py +++ b/kallithea/lib/vcs/backends/hg/repository.py @@ -34,7 +34,12 @@ import mercurial.sshpeer import mercurial.tags import mercurial.ui import mercurial.unionrepo -import mercurial.util + + +try: + from mercurial.utils.urlutil import url as hg_url +except ImportError: # urlutil was introduced in Mercurial 5.8 + from mercurial.util import url as hg_url from kallithea.lib.vcs.backends.base import BaseRepository, CollectionGenerator from kallithea.lib.vcs.exceptions import (BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, @@ -336,7 +341,7 @@ class MercurialRepository(BaseRepository if '+' in parsed_url.scheme: # strip 'git+' for hg-git URLs url = url.split(b'+', 1)[1] - url_obj = mercurial.util.url(url) + url_obj = hg_url(url) test_uri, handlers = get_urllib_request_handlers(url_obj) url_obj.passwd = b'*****' diff --git a/kallithea/lib/vcs/utils/helpers.py b/kallithea/lib/vcs/utils/helpers.py --- a/kallithea/lib/vcs/utils/helpers.py +++ b/kallithea/lib/vcs/utils/helpers.py @@ -245,7 +245,7 @@ def get_urllib_request_handlers(url_obj) if authinfo: # authinfo is a tuple (realm, uris, user, password) where 'uris' itself # is a tuple of URIs. - # If url_obj is obtained via mercurial.util.url, the obtained authinfo + # If url_obj is obtained via mercurial urlutil, the obtained authinfo # values will be bytes, e.g. # (None, (b'http://127.0.0.1/repo', b'127.0.0.1'), b'user', b'pass') # However, urllib expects strings, not bytes, so we must convert them.