# HG changeset patch # User Dirkjan Ochtman # Date 2008-02-21 14:00:25 # Node ID c050548307a40be0d8787f71082c52159c1a8c97 # Parent 8bc4fe428103ab2b5a332b9c92589247b7f455e5 hgweb: use bundletypes from mercurial.changegroup diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -53,6 +53,9 @@ bundletypes = { "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. diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -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 @@ class hgweb(object): 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 @@ class hgweb(object): 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."): diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py +++ b/mercurial/hgweb/protocol.py @@ -101,14 +101,7 @@ def changegroupsubset(web, req): 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)