changeset 6152:c050548307a4

hgweb: use bundletypes from mercurial.changegroup
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 21 Feb 2008 15:00:25 +0100
parents 8bc4fe428103
children 09a8be3e5bfb
files mercurial/changegroup.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/protocol.py
diffstat 3 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Wed Feb 20 13:38:16 2008 -0800
+++ b/mercurial/changegroup.py	Thu Feb 21 15:00:25 2008 +0100
@@ -53,6 +53,9 @@
     "HG10GZ": ("HG10GZ", lambda: zlib.compressobj()),
 }
 
+# hgweb uses this list to communicate it's preferred type
+bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
+
 def writebundle(cg, filename, bundletype):
     """Write a bundle file and return its filename.
 
--- a/mercurial/hgweb/hgweb_mod.py	Wed Feb 20 13:38:16 2008 -0800
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Feb 21 15:00:25 2008 +0100
@@ -9,7 +9,7 @@
 import os, mimetypes, re
 from mercurial.node import *
 from mercurial import mdiff, ui, hg, util, archival, patch, hook
-from mercurial import revlog, templater, templatefilters
+from mercurial import revlog, templater, templatefilters, changegroup
 from common import get_mtime, style_map, paritygen, countgen, get_contact
 from common import ErrorResponse
 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
@@ -92,6 +92,7 @@
         self.reponame = name
         self.archives = 'zip', 'gz', 'bz2'
         self.stripecount = 1
+        self._capabilities = None
         # a repo owner may set web.templates in .hg/hgrc to get any file
         # readable by the user running the CGI script
         self.templatepath = self.config("web", "templates",
@@ -123,6 +124,18 @@
             self.maxfiles = int(self.config("web", "maxfiles", 10))
             self.allowpull = self.configbool("web", "allowpull", True)
             self.encoding = self.config("web", "encoding", util._encoding)
+            self._capabilities = None
+
+    def capabilities(self):
+        if self._capabilities is not None:
+            return self._capabilities
+        caps = ['lookup', 'changegroupsubset']
+        if self.configbool('server', 'uncompressed'):
+            caps.append('stream=%d' % self.repo.changelog.version)
+        if changegroup.bundlepriority:
+            caps.append('unbundle=%s' % ','.join(changegroup.bundlepriority))
+        self._capabilities = caps
+        return caps
 
     def run(self):
         if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
--- a/mercurial/hgweb/protocol.py	Wed Feb 20 13:38:16 2008 -0800
+++ b/mercurial/hgweb/protocol.py	Thu Feb 21 15:00:25 2008 +0100
@@ -101,14 +101,7 @@
     req.write(z.flush())
 
 def capabilities(web, req):
-    caps = ['lookup', 'changegroupsubset']
-    if web.configbool('server', 'uncompressed'):
-        caps.append('stream=%d' % web.repo.changelog.version)
-    # 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)
+    resp = ' '.join(web.capabilities())
     req.respond(HTTP_OK, HGTYPE, length=len(resp))
     req.write(resp)