# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
# Date 1620205172 -7200
#      Wed May 05 10:59:32 2021 +0200
# Node ID dbe317d59de0b49b1426430dc4ba3646d39086a6
# Parent  b46639f34ff66857fc4cf29eb4dddbb5e696b779
compat: add support for mercurial 5.8

diff --git a/hggit/__init__.py b/hggit/__init__.py
--- a/hggit/__init__.py
+++ b/hggit/__init__.py
@@ -145,8 +145,6 @@
     exchange,
     extensions,
     hg,
-    ui as hgui,
-    util as hgutil,
     localrepo,
     manifest,
     pycompat,
@@ -201,7 +199,7 @@
 
 
 def _local(path):
-    p = hgutil.url(path).localpath()
+    p = compat.url(path).localpath()
     if _isgitdir(p):
         return gitrepo
     # detect git ssh urls (which mercurial thinks is a file-like path)
@@ -521,9 +519,15 @@
     return orig(self, path) or _isgitdir(path)
 
 
-if (hgutil.safehasattr(hgui, b'path') and
-    hgutil.safehasattr(hgui.path, b'_isvalidlocalpath')):
-    extensions.wrapfunction(hgui.path, b'_isvalidlocalpath', isvalidlocalpath)
+extensions.wrapfunction(compat.path, b'_isvalidlocalpath', isvalidlocalpath)
+
+
+def isurllocal(orig, path):
+    # recognise git scp-style paths when cloning
+    return orig(path) and not util.isgitsshuri(path._origpath)
+
+
+extensions.wrapfunction(compat.url, b'islocal', isurllocal)
 
 
 def islocal(orig, path):
@@ -539,7 +543,7 @@
     return orig(path) or util.isgitsshuri(path)
 
 
-extensions.wrapfunction(hgutil, b'hasscheme', hasscheme)
+extensions.wrapfunction(compat.urlutil, b'hasscheme', hasscheme)
 
 
 @util.transform_notgit
diff --git a/hggit/compat.py b/hggit/compat.py
--- a/hggit/compat.py
+++ b/hggit/compat.py
@@ -4,9 +4,22 @@
 from mercurial import (
     error,
     pycompat,
+    ui,
+    util as hgutil,
 )
 
 try:
+    # added in 5.8
+    from mercurial.utils import urlutil
+
+    url = urlutil.url
+    path = urlutil.path
+except ImportError:
+    urlutil = hgutil
+    url = hgutil.url
+    path = ui.path
+
+try:
     from mercurial.cmdutil import check_at_most_one_arg
 except (ImportError, AttributeError):
     # added in 5.3
diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -33,6 +33,7 @@
 )
 
 from . import _ssh
+from . import compat
 from . import git2hg
 from . import hg2git
 from . import util
@@ -1851,7 +1852,7 @@
 
             # not available in dulwich 0.19, used on Python 2.7
             if hasattr(client, 'get_credentials_from_store'):
-                urlobj = hgutil.url(uri)
+                urlobj = compat.url(uri)
                 auth = client.get_credentials_from_store(
                     urlobj.scheme,
                     urlobj.host,
@@ -1885,7 +1886,7 @@
             )
 
         if uri.startswith(b'file://'):
-            return client.LocalGitClient(), hgutil.url(uri).path
+            return client.LocalGitClient(), compat.url(uri).path
 
         # if its not git or git+ssh, try a local url..
         return client.SubprocessGitClient(), uri
diff --git a/hggit/gitrepo.py b/hggit/gitrepo.py
--- a/hggit/gitrepo.py
+++ b/hggit/gitrepo.py
@@ -1,9 +1,9 @@
 from __future__ import generator_stop
 
 from .util import isgitsshuri
+from . import compat
 from mercurial import (
     error,
-    util
 )
 from mercurial.wireprotov1peer import (
         batchable,
@@ -140,5 +140,5 @@
     if isgitsshuri(path):
         return True
 
-    u = util.url(path)
+    u = compat.url(path)
     return not u.scheme or u.scheme == b'file'
diff --git a/tests/test-networking.t b/tests/test-networking.t
--- a/tests/test-networking.t
+++ b/tests/test-networking.t
@@ -88,6 +88,8 @@
   $ hg add thefile
   $ fn_hg_commit -m 'add the file'
   $ hg book -r tip master
+  $ hg path default
+  git@git-server:/srv/repo.git
   $ hg push
   Warning: Permanently added * (glob) (?)
   pushing to git@git-server:/srv/repo.git