[PATCH] Accept file://localhost/ style urls as local
Brendan Cully
brendan at kublai.com
Thu Sep 6 21:28:10 CDT 2007
On Thursday, 06 September 2007 at 20:14, Christian Ebert wrote:
> # 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
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.
More information about the Mercurial-devel
mailing list