mercurial/hg.py
changeset 44571 6a8738dc4a01
parent 44434 2f290136b7d6
child 44657 843418dc0b1b
--- a/mercurial/hg.py	Tue Mar 17 17:26:05 2020 -0400
+++ b/mercurial/hg.py	Wed Mar 18 15:08:14 2020 -0400
@@ -60,12 +60,19 @@
     path = util.expandpath(util.urllocalpath(path))
 
     try:
-        isfile = os.path.isfile(path)
+        # we use os.stat() directly here instead of os.path.isfile()
+        # because the latter started returning `False` on invalid path
+        # exceptions starting in 3.8 and we care about handling
+        # invalid paths specially here.
+        st = os.stat(path)
+        isfile = stat.S_ISREG(st.st_mode)
     # Python 2 raises TypeError, Python 3 ValueError.
     except (TypeError, ValueError) as e:
         raise error.Abort(
             _(b'invalid path %s: %s') % (path, pycompat.bytestr(e))
         )
+    except OSError:
+        isfile = False
 
     return isfile and bundlerepo or localrepo