[issue728] hg doesn't like URLs of form file://localhost/...

Christian Ebert blacktrash at gmx.net
Thu Sep 6 11:28:04 UTC 2007


* Jens Alfke on Thursday, September 06, 2007 at 06:37:46 -0000
> The "hg" command recognizes URLs beginning with "file:///", but not ones 
> beginning with "file://localhost/", which should be considered equivalent. 
> Instead, it returns a "repository not found" error.

In fact "file://127.0.0.1/" or "file://::1/" might be valid as
well.

> Unfortunately the latter, unsupported syntax is the one that's generated by Mac 
> OS X API calls like [NSURL fileURLWithPath:].

You could try this here patch against crew.

If someone could tell me if "file://localhost/" style is accepted
on other platforms besides darwin or not, I could try to
implement the necessary conditionals.

c


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1189077749 -7200
# Node ID acd92fec1e5a481b52ce989597a3113c465cf2f0
# Parent  f8c36b215281a7e8f3aaed632206d3627ee21e6e
Accept file://localhost/ style locations

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,23 @@ def bytecount(nbytes):
             return format % (nbytes / float(divisor))
     return units[-1][2] % nbytes
 
+def _hostnames():
+    hnames = socket.gethostbyaddr(socket.gethostname())
+    localaddresses = ['127.0.0.1']
+    for i in hnames:
+        if isinstance(i, str):
+            i = [i]
+        localaddresses += i
+    return localaddresses
+
 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
-- 
keyword extension for Mercurial (http://selenic.com/mercurial):
<http://www.blacktrash.org/hg/hgkeyword/>
Mercurial crew development repository + keyword extension:
<http://www.blacktrash.org/hg/hg-crew-keyword/>



More information about the Mercurial-devel mailing list