From patchwork Thu Jan 31 18:57:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [STABLE] hgweb: add a `web.view` to control filtering From: Pierre-Yves David X-Patchwork-Id: 774 Message-Id: <4a841ef7813f99bc7f09.1359658628@crater2.logilab.fr> To: mercurial-devel@selenic.com Cc: pierre-yves.david@logilab.fr Date: Thu, 31 Jan 2013 19:57:08 +0100 # HG changeset patch # User Pierre-Yves David # Date 1359658615 -3600 # Branch stable # Node ID 4a841ef7813f99bc7f091110e2f0dc8db82dfb86 # Parent 2a1fac3650a5b4d650198604c82ab59969500374 hgweb: add a `web.view` to control filtering This options add a new `web.view` to control filter level of hgweb. This option have two purposes: 1) Allow fall back to unfiltered version in case a yet undetected by critical bug is found in filtering after 2.5 release 2) People use hgweb as a local repoviewer. When they have secret changesets, they wants to use "visible" filter not "served" diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -1457,5 +1457,11 @@ The full set of options is: ``style`` Which template map style to use. ``templates`` Where to find the HTML templates. Default is install path. + +``view`` + Controls Changesets filter to hgweb. Possible values are ``served``, + ``visible`` and ``all``. Default is ``served``. The ``served`` filter only + shows changesets that can be pulled from the hgweb instance. The``visible`` + filter includes secret changesets but still excludes "hidden" one. 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 @@ -5,11 +5,11 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. import os -from mercurial import ui, hg, hook, error, encoding, templater, util +from mercurial import ui, hg, hook, error, encoding, templater, util, repoview from common import get_stat, ErrorResponse, permhooks, caching from common import HTTP_OK, HTTP_NOT_MODIFIED, HTTP_BAD_REQUEST from common import HTTP_NOT_FOUND, HTTP_SERVER_ERROR from request import wsgirequest import webcommands, protocol, webutil @@ -57,11 +57,18 @@ class hgweb(object): u = ui.ui() self.repo = hg.repository(u, repo) else: self.repo = repo - self.repo = self.repo.filtered('served') + viewconfig = self.config('web', 'view', 'served') + if viewconfig == 'all': + self.repo = self.repo.unfiltered() + elif viewconfig in repoview.filtertable: + self.repo = self.repo.filtered(viewconfig) + else: + self.repo = self.repo.filtered('served') + self.repo.ui.setconfig('ui', 'report_untrusted', 'off') self.repo.ui.setconfig('ui', 'nontty', 'true') hook.redirect(True) self.mtime = -1 self.size = -1 @@ -94,11 +101,17 @@ class hgweb(object): # rollbacks made less than a second ago if st.st_mtime != self.mtime or st.st_size != self.size: self.mtime = st.st_mtime self.size = st.st_size self.repo = hg.repository(self.repo.ui, self.repo.root) - self.repo = self.repo.filtered('served') + viewconfig = self.config('web', 'view', 'served') + if viewconfig == 'all': + self.repo = self.repo.unfiltered() + elif viewconfig in repoview.filtertable: + self.repo = self.repo.filtered(viewconfig) + else: + self.repo = self.repo.filtered('served') self.maxchanges = int(self.config("web", "maxchanges", 10)) self.stripecount = int(self.config("web", "stripes", 1)) self.maxshortchanges = int(self.config("web", "maxshortchanges", 60)) self.maxfiles = int(self.config("web", "maxfiles", 10)) diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t --- a/tests/test-obsolete.t +++ b/tests/test-obsolete.t @@ -741,10 +741,28 @@ check graph view check filelog view $ "$TESTDIR/get-with-headers.py" --headeronly localhost:$HGPORT 'log/'`hg id --debug --id`/'babar' 200 Script output follows + + $ "$TESTDIR/get-with-headers.py" --headeronly localhost:$HGPORT 'rev/68' + 200 Script output follows + $ "$TESTDIR/get-with-headers.py" --headeronly localhost:$HGPORT 'rev/67' + 500 Internal Server Error + [1] + +check that web.view config option: + + $ kill `cat hg.pid` + $ cat >> .hg/hgrc << EOF + > [web] + > view=all + > EOF + $ wait + $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log + $ "$TESTDIR/get-with-headers.py" --headeronly localhost:$HGPORT 'rev/67' + 200 Script output follows $ kill `cat hg.pid` Checking _enable=False warning if obsolete marker exists $ echo '[extensions]' >> $HGRCPATH