comparison mercurial/hgweb/webcommands.py @ 6691:0dba955c2636

add graph page to hgweb
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 18 Jun 2008 07:06:41 +0200
parents be55b1a6d4b1
children 8251ffb35725
comparison
equal deleted inserted replaced
6690:127e8c3466d1 6691:0dba955c2636
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 8 import os, mimetypes, re, cgi
9 import webutil 9 import webutil
10 from mercurial import revlog, archival 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 12 from mercurial.util import binary, datestr
13 from mercurial.repo import RepoError 13 from mercurial.repo import RepoError
14 from common import paritygen, staticfile, get_contact, ErrorResponse 14 from common import paritygen, staticfile, get_contact, ErrorResponse
15 from common import HTTP_OK, HTTP_NOT_FOUND 15 from common import HTTP_OK, HTTP_NOT_FOUND
16 from mercurial import graphmod
16 17
17 # __all__ is populated with the allowed commands. Be sure to add to it if 18 # __all__ is populated with the allowed commands. Be sure to add to it if
18 # you're adding a new command, or the new command won't work. 19 # you're adding a new command, or the new command won't work.
19 20
20 __all__ = [ 21 __all__ = [
21 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', 22 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
22 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog', 23 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog',
23 'archive', 'static', 24 'archive', 'static', 'graph',
24 ] 25 ]
25 26
26 def log(web, req, tmpl): 27 def log(web, req, tmpl):
27 if 'file' in req.form and req.form['file'][0]: 28 if 'file' in req.form and req.form['file'][0]:
28 return filelog(web, req, tmpl) 29 return filelog(web, req, tmpl)
572 # readable by the user running the CGI script 573 # readable by the user running the CGI script
573 static = web.config("web", "static", 574 static = web.config("web", "static",
574 os.path.join(web.templatepath, "static"), 575 os.path.join(web.templatepath, "static"),
575 untrusted=False) 576 untrusted=False)
576 return [staticfile(static, fname, req)] 577 return [staticfile(static, fname, req)]
578
579 def graph(web, req, tmpl):
580 rev = webutil.changectx(web.repo, req).rev()
581 revcount = int(req.form.get('revcount', [25])[0])
582 bg_height = 39
583
584 max_rev = web.repo.changelog.count() - 1
585 revnode = web.repo.changelog.node(rev)
586 revnode_hex = hex(revnode)
587 uprev = min(max_rev, rev + revcount)
588 downrev = max(0, rev - revcount)
589 lessrev = max(0, rev - revcount / 2)
590
591 maxchanges = web.maxshortchanges or web.maxchanges
592 count = web.repo.changelog.count()
593 changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx)
594
595 tree = list(graphmod.graph(web.repo, rev, rev - revcount))
596 canvasheight = (len(tree) + 1) * bg_height - 27;
597
598 data = []
599 for i, (ctx, vtx, edges) in enumerate(tree):
600 node = short(ctx.node())
601 age = templatefilters.age(ctx.date())
602 desc = templatefilters.firstline(ctx.description())
603 desc = cgi.escape(desc)
604 user = cgi.escape(templatefilters.person(ctx.user()))
605 data.append((node, vtx, edges, desc, user, age, ctx.tags()))
606
607 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev,
608 lessrev=lessrev, revcountmore=revcount and 2 * revcount or 1,
609 revcountless=revcount / 2, downrev=downrev,
610 canvasheight=canvasheight, bg_height=bg_height,
611 jsdata=data, node=revnode_hex, changenav=changenav)