http: query server for capabilities
authorVadim Gelfer <vadim.gelfer@gmail.com>
Thu, 15 Jun 2006 17:07:30 -0700
changeset 2442 c660691fb45d
parent 2441 801dfe0aa53a
child 2443 bd9c39e8f38b
child 2444 5eb02f9ed804
child 2449 6ff30968f911
http: query server for capabilities
mercurial/hgweb/hgweb_mod.py
mercurial/httprepo.py
--- a/mercurial/hgweb/hgweb_mod.py	Thu Jun 15 16:41:49 2006 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Jun 15 17:07:30 2006 -0700
@@ -833,3 +833,9 @@
                                                   "static"))
         req.write(staticfile(static, fname)
                   or self.t("error", error="%r not found" % fname))
+
+    def do_capabilities(self, req):
+        resp = ''
+        req.httphdr("application/mercurial-0.1", length=len(resp))
+        req.write(resp)
+
--- a/mercurial/httprepo.py	Thu Jun 15 16:41:49 2006 -0700
+++ b/mercurial/httprepo.py	Thu Jun 15 17:07:30 2006 -0700
@@ -71,7 +71,7 @@
 
 class httprepository(remoterepository):
     def __init__(self, ui, path):
-        self.capabilities = ()
+        self.caps = None
         scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
         if query or frag:
             raise util.Abort(_('unsupported URL component: "%s"') %
@@ -145,6 +145,18 @@
         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
         urllib2.install_opener(opener)
 
+    # look up capabilities only when needed
+
+    def get_caps(self):
+        if self.caps is None:
+            try:
+                self.caps = self.do_read('capabilities').split()
+            except hg.RepoError:
+                self.caps = ()
+        return self.caps
+
+    capabilities = property(get_caps)
+
     def dev(self):
         return -1