[PATCH] Accept file://localhost/ style urls as local

Christian Ebert blacktrash at gmx.net
Thu Sep 6 13:14:48 CDT 2007


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1189102172 -7200
# Node ID f5d46788104cf43b909192fbbd1b37344af38a56
# Parent  f8c36b215281a7e8f3aaed632206d3627ee21e6e
Accept file://localhost/ style urls as local

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -14,7 +14,7 @@ platform-specific details from the core.
 
 from i18n import _
 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil
-import os, stat, threading, time, calendar, ConfigParser, locale, glob
+import os, stat, threading, time, calendar, ConfigParser, locale, glob, socket
 
 try:
     set = set
@@ -1674,10 +1674,24 @@ def bytecount(nbytes):
             return format % (nbytes / float(divisor))
     return units[-1][2] % nbytes
 
+def _hostnames():
+    hnames = socket.gethostbyaddr(socket.gethostname())
+    hl = ['127.0.0.1']
+    for h in hnames:
+        if isinstance(h, str):
+            h = [h]
+        hl += h
+    return hl
+
 def drop_scheme(scheme, path):
     sc = scheme + ':'
     if path.startswith(sc):
-        path = path[len(sc):]
-        if path.startswith('//'):
-            path = path[2:]
+        roots = ['']
+        if scheme == 'file':
+            roots = _hostnames() + roots
+        for r in roots:
+            fullsc = sc + '//' + r
+            if path.startswith(fullsc):
+                return path[len(fullsc):]
+        return path[len(sc):]
     return path



More information about the Mercurial-devel mailing list