Mercurial > hg
comparison mercurial/hgweb/webcommands.py @ 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 | 5c95d7667dd1 |
children | 9fe97eea5510 |
comparison
equal
deleted
inserted
replaced
7336:2dc868712dcc | 7345:55651328dfcc |
---|---|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4 # | 4 # |
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 import os, mimetypes, re, cgi | 8 import os, mimetypes, re, cgi, copy |
9 import webutil | 9 import webutil |
10 from mercurial import revlog, archival, templatefilters | 10 from mercurial import revlog, archival, templatefilters |
11 from mercurial.node import short, hex, nullid | 11 from mercurial.node import short, hex, nullid |
12 from mercurial.util import binary, datestr | 12 from mercurial.util import binary, datestr |
13 from mercurial.repo import RepoError | 13 from mercurial.repo import RepoError |
617 | 617 |
618 def graph(web, req, tmpl): | 618 def graph(web, req, tmpl): |
619 rev = webutil.changectx(web.repo, req).rev() | 619 rev = webutil.changectx(web.repo, req).rev() |
620 bg_height = 39 | 620 bg_height = 39 |
621 | 621 |
622 revcount = 25 | |
623 if 'revcount' in req.form: | |
624 revcount = int(req.form.get('revcount', [revcount])[0]) | |
625 tmpl.defaults['sessionvars']['revcount'] = revcount | |
626 | |
627 lessvars = copy.copy(tmpl.defaults['sessionvars']) | |
628 lessvars['revcount'] = revcount / 2 | |
629 morevars = copy.copy(tmpl.defaults['sessionvars']) | |
630 morevars['revcount'] = revcount * 2 | |
631 | |
622 max_rev = len(web.repo) - 1 | 632 max_rev = len(web.repo) - 1 |
623 revcount = min(max_rev, int(req.form.get('revcount', [25])[0])) | 633 revcount = min(max_rev, revcount) |
624 revnode = web.repo.changelog.node(rev) | 634 revnode = web.repo.changelog.node(rev) |
625 revnode_hex = hex(revnode) | 635 revnode_hex = hex(revnode) |
626 uprev = min(max_rev, rev + revcount) | 636 uprev = min(max_rev, rev + revcount) |
627 downrev = max(0, rev - revcount) | 637 downrev = max(0, rev - revcount) |
628 lessrev = max(0, rev - revcount / 2) | |
629 | |
630 count = len(web.repo) | 638 count = len(web.repo) |
631 changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx) | 639 changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx) |
632 | 640 |
633 tree = list(graphmod.graph(web.repo, rev, downrev)) | 641 tree = list(graphmod.graph(web.repo, rev, downrev)) |
634 canvasheight = (len(tree) + 1) * bg_height - 27; | 642 canvasheight = (len(tree) + 1) * bg_height - 27; |
635 | |
636 data = [] | 643 data = [] |
637 for i, (ctx, vtx, edges) in enumerate(tree): | 644 for i, (ctx, vtx, edges) in enumerate(tree): |
638 node = short(ctx.node()) | 645 node = short(ctx.node()) |
639 age = templatefilters.age(ctx.date()) | 646 age = templatefilters.age(ctx.date()) |
640 desc = templatefilters.firstline(ctx.description()) | 647 desc = templatefilters.firstline(ctx.description()) |
643 branch = ctx.branch() | 650 branch = ctx.branch() |
644 branch = branch, web.repo.branchtags().get(branch) == ctx.node() | 651 branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
645 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) | 652 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
646 | 653 |
647 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, | 654 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
648 lessrev=lessrev, revcountmore=revcount and 2 * revcount or 1, | 655 lessvars=lessvars, morevars=morevars, downrev=downrev, |
649 revcountless=revcount / 2, downrev=downrev, | 656 canvasheight=canvasheight, jsdata=data, bg_height=bg_height, |
650 canvasheight=canvasheight, bg_height=bg_height, | 657 node=revnode_hex, changenav=changenav) |
651 jsdata=data, node=revnode_hex, changenav=changenav) |