[PATCH] Accept file://localhost/ style urls as local
Christian Ebert
blacktrash at gmx.net
Fri Sep 7 20:13:35 CDT 2007
* Brendan Cully on Thursday, September 06, 2007 at 19:28:10 -0700
> I'd be tempted to just skip over the host part of a file: URL --
> anything other than a local hostname is probably useless anyway. But
> if that's a bad idea, I think we should at least look for localhost
> and 127.0.0.1 statically before doing any address lookup. That saves
> any silly DNS lookups for 99% of the time.
Another attempt:
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1189077749 -7200
# Node ID acd92fec1e5a481b52ce989597a3113c465cf2f0
# Parent f8c36b215281a7e8f3aaed632206d3627ee21e6e
Drop local hostnames with url scheme in file urls
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 _localhostnames():
+ hl = []
+ for h in socket.gethostbyaddr(socket.gethostname()):
+ 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:]
+ if scheme == 'file' and not path.startswith('/'):
+ if path[:10] in ('localhost/', '127.0.0.1/'):
+ return path[9:]
+ for h in _localhostnames():
+ if path.startswith(h + '/'):
+ return path[len(h):]
return path
More information about the Mercurial-devel
mailing list