Mercurial > hg
changeset 7345:55651328dfcc
hgweb: fix up the less/more links on the graph page
Previously, they pointed to a non-intuitive revision, and got borked when
using a URL-specified style combined with alternate revcounts.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 07 Nov 2008 23:31:12 +0100 |
parents | 2dc868712dcc |
children | 1a5c9ca2bfd5 |
files | mercurial/hgweb/hgweb_mod.py mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py templates/coal/graph.tmpl templates/gitweb/graph.tmpl tests/test-hgweb-commands.out |
diffstat | 6 files changed, 45 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py Fri Oct 31 15:28:06 2008 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Fri Nov 07 23:31:12 2008 +0100 @@ -228,23 +228,16 @@ def motd(**map): yield self.config("web", "motd", "") - def sessionvars(**map): - fields = [] - if 'style' in req.form: - style = req.form['style'][0] - if style != self.config('web', 'style', ''): - fields.append(('style', style)) - - separator = req.url[-1] == '?' and ';' or '?' - for name, value in fields: - yield dict(name=name, value=value, separator=separator) - separator = ';' - # figure out which style to use + vars = {} style = self.config("web", "style", "") if 'style' in req.form: style = req.form['style'][0] + vars['style'] = style + + start = req.url[-1] == '?' and '&' or '?' + sessionvars = webutil.sessionvars(vars, start) mapfile = style_map(self.templatepath, style) if not self.reponame:
--- a/mercurial/hgweb/webcommands.py Fri Oct 31 15:28:06 2008 +0100 +++ b/mercurial/hgweb/webcommands.py Fri Nov 07 23:31:12 2008 +0100 @@ -5,7 +5,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, mimetypes, re, cgi +import os, mimetypes, re, cgi, copy import webutil from mercurial import revlog, archival, templatefilters from mercurial.node import short, hex, nullid @@ -619,20 +619,27 @@ rev = webutil.changectx(web.repo, req).rev() bg_height = 39 + revcount = 25 + if 'revcount' in req.form: + revcount = int(req.form.get('revcount', [revcount])[0]) + tmpl.defaults['sessionvars']['revcount'] = revcount + + lessvars = copy.copy(tmpl.defaults['sessionvars']) + lessvars['revcount'] = revcount / 2 + morevars = copy.copy(tmpl.defaults['sessionvars']) + morevars['revcount'] = revcount * 2 + max_rev = len(web.repo) - 1 - revcount = min(max_rev, int(req.form.get('revcount', [25])[0])) + revcount = min(max_rev, revcount) revnode = web.repo.changelog.node(rev) revnode_hex = hex(revnode) uprev = min(max_rev, rev + revcount) downrev = max(0, rev - revcount) - lessrev = max(0, rev - revcount / 2) - count = len(web.repo) changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx) tree = list(graphmod.graph(web.repo, rev, downrev)) canvasheight = (len(tree) + 1) * bg_height - 27; - data = [] for i, (ctx, vtx, edges) in enumerate(tree): node = short(ctx.node()) @@ -645,7 +652,6 @@ data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, - lessrev=lessrev, revcountmore=revcount and 2 * revcount or 1, - revcountless=revcount / 2, downrev=downrev, - canvasheight=canvasheight, bg_height=bg_height, - jsdata=data, node=revnode_hex, changenav=changenav) + lessvars=lessvars, morevars=morevars, downrev=downrev, + canvasheight=canvasheight, jsdata=data, bg_height=bg_height, + node=revnode_hex, changenav=changenav)
--- a/mercurial/hgweb/webutil.py Fri Oct 31 15:28:06 2008 +0100 +++ b/mercurial/hgweb/webutil.py Fri Nov 07 23:31:12 2008 +0100 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os +import os, copy from mercurial import match, patch from mercurial.node import hex, nullid from mercurial.repo import RepoError @@ -196,3 +196,19 @@ block.append(chunk) yield tmpl('diffblock', parity=parity.next(), lines=prettyprintlines(''.join(block))) + +class sessionvars(object): + def __init__(self, vars, start='?'): + self.start = start + self.vars = vars + def __getitem__(self, key): + return self.vars[key] + def __setitem__(self, key, value): + self.vars[key] = value + def __copy__(self): + return sessionvars(copy.copy(self.vars), self.start) + def __iter__(self): + separator = self.start + for key, value in self.vars.iteritems(): + yield {'name': key, 'value': str(value), 'separator': separator} + separator = '&'
--- a/templates/coal/graph.tmpl Fri Oct 31 15:28:06 2008 +0100 +++ b/templates/coal/graph.tmpl Fri Nov 07 23:31:12 2008 +0100 @@ -37,8 +37,8 @@ </form> <div class="navigate"> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a> +<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a> +<a href="{url}graph/{rev}{morevars%urlparameter}">more</a> | rev {rev}: {changenav%navgraphentry} </div> @@ -102,8 +102,8 @@ </script> <div class="navigate"> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a> +<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a> +<a href="{url}graph/{rev}{morevars%urlparameter}">more</a> | rev {rev}: {changenav%navgraphentry} </div>
--- a/templates/gitweb/graph.tmpl Fri Oct 31 15:28:06 2008 +0100 +++ b/templates/gitweb/graph.tmpl Fri Nov 07 23:31:12 2008 +0100 @@ -25,8 +25,8 @@ <a href="{url}tags{sessionvars%urlparameter}">tags</a> | <a href="{url}file/#node|short#{sessionvars%urlparameter}">files</a> <br/> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a> +<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a> +<a href="{url}graph/{rev}{morevars%urlparameter}">more</a> | #changenav%navgraphentry#<br/> </div> @@ -111,8 +111,8 @@ </script> <div class="page_nav"> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a> -<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a> +<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a> +<a href="{url}graph/{rev}{morevars%urlparameter}">more</a> | {changenav%navgraphentry} </div>