annotate pylons_app/controllers/changelog.py @ 142:f7218849798a

Changeg graph to changelog, and changelog to shortlog
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 09 May 2010 17:22:30 +0200
parents 20dc7a5eb748
children f191f99f59c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import logging
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
2 from pylons import request, response, session, tmpl_context as c, url, config, \
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
3 app_globals as g
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from pylons.controllers.util import abort, redirect
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from pylons_app.lib.base import BaseController, render
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from pylons_app.lib.utils import get_repo_slug
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from pylons_app.model.hg_model import HgModel
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
8
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
9 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
10 from pylons_app.lib.filters import age as _age, person
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
11 from simplejson import dumps
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
12 from mercurial.node import short
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 from webhelpers.paginate import Page
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
14
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
15
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 log = logging.getLogger(__name__)
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 class ChangelogController(BaseController):
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 def __before__(self):
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 c.repos_prefix = config['repos_name']
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 c.repo_name = get_repo_slug(request)
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 def index(self):
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
25 # Return a rendered template
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 hg_model = HgModel()
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
27 if request.POST.get('size'):
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
28 c.size = int(request.params.get('size', 20))
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
29 else:
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
30 c.size = int(request.params.get('size', 20))
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
31 c.jsdata, c.canvasheight = self.graph(hg_model.get_repo(c.repo_name), c.size)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
32
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
33 return render('changelog/changelog.html')
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
34
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
35
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
36 def graph(self, repo, size):
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
37 revcount = size
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 p = int(request.params.get('page', 1))
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
39 c.pagination = Page(repo.revisions, page=p, item_count=len(repo.revisions), items_per_page=revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
40 if not repo.revisions:return dumps([]), 0
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
41
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
42 max_rev = repo.revisions[-1]
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
43 offset = 1 if p == 1 else ((p - 1) * revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
44 rev_start = repo.revisions[(-1 * offset)]
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
45 bg_height = 39
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
46
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
47 revcount = min(max_rev, revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
48 rev_end = max(0, rev_start - revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
49 dag = graph_rev(repo.repo, rev_start, rev_end)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
50 tree = list(colored(dag))
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
51 canvasheight = (len(tree) + 1) * bg_height - 27
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
52 data = []
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
53 for (id, type, ctx, vtx, edges) in tree:
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
54 if type != CHANGESET:
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
55 continue
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
56 node = short(ctx.node())
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
57 age = _age(ctx.date())
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
58 desc = ctx.description()
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
59 user = person(ctx.user())
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
60 branch = ctx.branch()
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
61 branch = branch, repo.repo.branchtags().get(branch) == ctx.node()
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
62 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
63
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
64 return dumps(data), canvasheight
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
65