changeset 49:728167aff824

Cloning a forest is now possible over HTTP.
author Simon Law <simon@akoha.org>
date Mon, 09 Jul 2007 18:04:44 -0400
parents d8e40f82bb3d
children 904f45baaf83
files forest.py
diffstat 1 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/forest.py	Mon Jul 09 17:46:20 2007 -0400
+++ b/forest.py	Mon Jul 09 18:04:44 2007 -0400
@@ -49,7 +49,8 @@
 import re
 
 from mercurial import commands, hg, node, util
-from mercurial import localrepo, httprepo, sshrepo, sshserver
+from mercurial import localrepo, sshrepo, sshserver, httprepo
+from mercurial.hgweb import hgweb_mod
 if not hasattr(commands, "findcmd"):
     from mercurial.cmdutil import findcmd
 else:
@@ -138,7 +139,6 @@
     if 'forests' not in self.capabilities:
         raise util.Abort(_("Remote forests cannot be cloned because the other repository doesn't support the forest extension."))
     data = self.call("forests", walkhg=("", "True")[walkhg])
-    print data
     return data.splitlines()
 
 sshrepo.sshrepository.forests = _sshrepo_forests
@@ -178,16 +178,39 @@
     """
     if 'forests' not in self.capabilities:
         raise util.Abort(_("Remote forests cannot be cloned because the other repository doesn't support the forest extension."))
-    d = self.do_read("forests", walkhg=("", "True")[walkhg])
-    success, data = d[:-1].split(" ", 1)
-    if int(success):
-        return data.splitlines()
-    else:
-        self.raise_(hg.RepoError(data))
+    data = self.do_read("forests", walkhg=("", "True")[walkhg])
+    return data.splitlines()
 
 httprepo.httprepository.forests = _httprepo_forests
 
 
+def _httpserver_do_capabilities(self, req):
+    caps = ['lookup', 'changegroupsubset', 'forests']
+    if self.configbool('server', 'uncompressed'):
+        caps.append('stream=%d' % self.repo.revlogversion)
+    # XXX: make configurable and/or share code with do_unbundle:
+    unbundleversions = ['HG10GZ', 'HG10BZ', 'HG10UN']
+    if unbundleversions:
+        caps.append('unbundle=%s' % ','.join(unbundleversions))
+    resp = ' '.join(caps)
+    req.httphdr("application/mercurial-0.1", length=len(resp))
+    req.write(resp)
+
+hgweb_mod.hgweb.do_capabilities = _httpserver_do_capabilities
+
+
+def _httpserver_do_forests(self, req):
+    resp = ""
+    if req.form.has_key('walkhg'):
+        f = self.repo.forests(bool(req.form['walkhg'][0]))
+        resp = "\n".join(f)
+    req.httphdr("application/mercurial-0.1", length=len(resp))
+    req.write(resp)
+
+
+hgweb_mod.hgweb.do_forests = _httpserver_do_forests
+
+
 tree_section_re = re.compile(r"^tree(\w+)$")
 
 def tree_sections(cfg, withtop=True):