##// END OF EJS Templates
small fixes, and optimization for changelog graph
marcink -
r1109:41a695e6 beta
parent child Browse files
Show More
@@ -1,105 +1,105 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.changelog
3 rhodecode.controllers.changelog
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 changelog controller for rhodecode
6 changelog controller for rhodecode
7
7
8 :created_on: Apr 21, 2010
8 :created_on: Apr 21, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 import logging
28 import logging
29
29
30 try:
30 try:
31 import json
31 import json
32 except ImportError:
32 except ImportError:
33 #python 2.5 compatibility
33 #python 2.5 compatibility
34 import simplejson as json
34 import simplejson as json
35
35
36 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev
36 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev
37 from pylons import request, session, tmpl_context as c
37 from pylons import request, session, tmpl_context as c
38
38
39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
40 from rhodecode.lib.base import BaseRepoController, render
40 from rhodecode.lib.base import BaseRepoController, render
41 from rhodecode.lib.helpers import RepoPage
41 from rhodecode.lib.helpers import RepoPage
42
42
43 log = logging.getLogger(__name__)
43 log = logging.getLogger(__name__)
44
44
45 class ChangelogController(BaseRepoController):
45 class ChangelogController(BaseRepoController):
46
46
47 @LoginRequired()
47 @LoginRequired()
48 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
48 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
49 'repository.admin')
49 'repository.admin')
50 def __before__(self):
50 def __before__(self):
51 super(ChangelogController, self).__before__()
51 super(ChangelogController, self).__before__()
52
52
53 def index(self):
53 def index(self):
54 limit = 100
54 limit = 100
55 default = 20
55 default = 20
56 if request.params.get('size'):
56 if request.params.get('size'):
57 try:
57 try:
58 int_size = int(request.params.get('size'))
58 int_size = int(request.params.get('size'))
59 except ValueError:
59 except ValueError:
60 int_size = default
60 int_size = default
61 int_size = int_size if int_size <= limit else limit
61 int_size = int_size if int_size <= limit else limit
62 c.size = int_size
62 c.size = int_size
63 session['changelog_size'] = c.size
63 session['changelog_size'] = c.size
64 session.save()
64 session.save()
65 else:
65 else:
66 c.size = int(session.get('changelog_size', default))
66 c.size = int(session.get('changelog_size', default))
67
67
68 p = int(request.params.get('page', 1))
68 p = int(request.params.get('page', 1))
69 branch_name = request.params.get('branch', None)
69 branch_name = request.params.get('branch', None)
70 c.total_cs = len(c.rhodecode_repo)
70 c.total_cs = len(c.rhodecode_repo)
71 c.pagination = RepoPage(c.rhodecode_repo, page=p, item_count=c.total_cs,
71 c.pagination = RepoPage(c.rhodecode_repo, page=p, item_count=c.total_cs,
72 items_per_page=c.size, branch_name=branch_name)
72 items_per_page=c.size, branch_name=branch_name)
73
73
74 self._graph(c.rhodecode_repo, c.size, p)
74 self._graph(c.rhodecode_repo, c.total_cs, c.size, p)
75
75
76 return render('changelog/changelog.html')
76 return render('changelog/changelog.html')
77
77
78
78
79 def _graph(self, repo, size, p):
79 def _graph(self, repo, repo_size, size, p):
80 """
80 """
81 Generates a DAG graph for mercurial
81 Generates a DAG graph for mercurial
82
82
83 :param repo: repo instance
83 :param repo: repo instance
84 :param size: number of commits to show
84 :param size: number of commits to show
85 :param p: page number
85 :param p: page number
86 """
86 """
87 if not repo.revisions or repo.alias == 'git':
87 if not repo.revisions or repo.alias == 'git':
88 c.jsdata = json.dumps([])
88 c.jsdata = json.dumps([])
89 return
89 return
90
90
91 revcount = min(repo.size, size)
91 revcount = min(repo_size, size)
92 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
92 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
93 rev_start = repo.revisions.index(repo.revisions[(-1 * offset)])
93 rev_start = repo.revisions.index(repo.revisions[(-1 * offset)])
94 rev_end = max(0, rev_start - revcount)
94 rev_end = max(0, rev_start - revcount)
95
95
96 dag = graph_rev(repo._repo, rev_start, rev_end)
96 dag = graph_rev(repo._repo, rev_start, rev_end)
97 c.dag = tree = list(colored(dag))
97 c.dag = tree = list(colored(dag))
98 data = []
98 data = []
99 for (id, type, ctx, vtx, edges) in tree:
99 for (id, type, ctx, vtx, edges) in tree:
100 if type != CHANGESET:
100 if type != CHANGESET:
101 continue
101 continue
102 data.append(('', vtx, edges))
102 data.append(('', vtx, edges))
103
103
104 c.jsdata = json.dumps(data)
104 c.jsdata = json.dumps(data)
105
105
General Comments 0
You need to be logged in to leave comments. Login now