Autodetect static-http
authorMatt Mackall <mpm@selenic.com>
Wed, 22 Oct 2008 15:41:32 -0500
changeset 7211 25c0dee16ee0
parent 7210 833d1250ce00
child 7212 402d317778d3
Autodetect static-http
doc/hg.1.txt
mercurial/commands.py
mercurial/httprepo.py
mercurial/statichttprepo.py
tests/test-static-http
tests/test-static-http.out
--- a/doc/hg.1.txt	Wed Oct 22 14:30:34 2008 -0500
+++ b/doc/hg.1.txt	Wed Oct 22 15:41:32 2008 -0500
@@ -30,10 +30,7 @@
 
 repository path::
     either the pathname of a local repository or the URI of a remote
-    repository. There are two available URI protocols, http:// which is
-    fast and the static-http:// protocol which is much slower but does not
-    require a special server on the web host.
-
+    repository.
 
 include::hg.1.gendoc.txt[]
 
--- a/mercurial/commands.py	Wed Oct 22 14:30:34 2008 -0500
+++ b/mercurial/commands.py	Wed Oct 22 15:41:32 2008 -0500
@@ -2071,13 +2071,10 @@
       http://[user[:pass]@]host[:port]/[path]
       https://[user[:pass]@]host[:port]/[path]
       ssh://[user[:pass]@]host[:port]/[path]
-      static-http://host[:port]/[path]
 
     Paths in the local filesystem can either point to Mercurial
     repositories or to bundle files (as created by 'hg bundle' or
-    'hg incoming --bundle'). The static-http:// protocol, albeit slow,
-    allows access to a Mercurial repository where you simply use a web
-    server to publish the .hg directory as static content.
+    'hg incoming --bundle').
 
     An optional identifier after # indicates a particular branch, tag,
     or changeset to pull.
--- a/mercurial/httprepo.py	Wed Oct 22 14:30:34 2008 -0500
+++ b/mercurial/httprepo.py	Wed Oct 22 15:41:32 2008 -0500
@@ -6,10 +6,10 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-from node import bin, hex
+from node import bin, hex, nullid
 from i18n import _
 import repo, os, urllib, urllib2, urlparse, zlib, util, httplib
-import errno, keepalive, socket, changegroup
+import errno, keepalive, socket, changegroup, statichttprepo
 
 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
     def __init__(self, ui):
@@ -455,6 +455,13 @@
 def instance(ui, path, create):
     if create:
         raise util.Abort(_('cannot create new http repository'))
-    if path.startswith('https:'):
-        return httpsrepository(ui, path)
-    return httprepository(ui, path)
+    try:
+        if path.startswith('https:'):
+            inst = httpsrepository(ui, path)
+        else:
+            inst = httprepository(ui, path)
+        inst.between([(nullid, nullid)])
+        return inst
+    except repo.RepoError:
+        ui.note('(falling back to static-http)\n')
+        return statichttprepo.instance(ui, "static-" + path, create)
--- a/mercurial/statichttprepo.py	Wed Oct 22 14:30:34 2008 -0500
+++ b/mercurial/statichttprepo.py	Wed Oct 22 15:41:32 2008 -0500
@@ -76,7 +76,7 @@
         self.decodepats = None
 
     def url(self):
-        return 'static-' + self._url
+        return self._url
 
     def local(self):
         return False
--- a/tests/test-static-http	Wed Oct 22 14:30:34 2008 -0500
+++ b/tests/test-static-http	Wed Oct 22 15:41:32 2008 -0500
@@ -2,7 +2,7 @@
 
 cp "$TESTDIR"/printenv.py .
 
-http_proxy= hg clone static-http://localhost:$HGPORT/ copy
+http_proxy= hg clone http://localhost:$HGPORT/ copy
 echo $?
 test -d copy || echo copy: No such file or directory
 
--- a/tests/test-static-http.out	Wed Oct 22 14:30:34 2008 -0500
+++ b/tests/test-static-http.out	Wed Oct 22 15:41:32 2008 -0500
@@ -1,4 +1,4 @@
-abort: Connection refused
+abort: error: Connection refused
 255
 copy: No such file or directory
 changeset:   0:53e17d176ae6
@@ -21,7 +21,7 @@
 1 files, 1 changesets, 1 total revisions
 foo
 adding quux
-changegroup hook: HG_NODE=34401e0e9971e9720b613d9089ffa9a6eefb3d2d HG_SOURCE=pull HG_URL=static-http://localhost/remote 
+changegroup hook: HG_NODE=34401e0e9971e9720b613d9089ffa9a6eefb3d2d HG_SOURCE=pull HG_URL=http://localhost/remote 
 pulling from static-http://localhost/remote
 searching for changes
 adding changesets