Show More
@@ -1,111 +1,115 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 modify |
|
13 | # This program is free software: you can redistribute it and/or modify | |
14 | # it under the terms of the GNU General Public License as published by |
|
14 | # it under the terms of the GNU General Public License as published by | |
15 | # the Free Software Foundation, either version 3 of the License, or |
|
15 | # the Free Software Foundation, either version 3 of the License, or | |
16 | # (at your option) any later version. |
|
16 | # (at your option) any later version. | |
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, see <http://www.gnu.org/licenses/>. |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 |
|
25 | |||
26 | import logging |
|
26 | import logging | |
27 |
|
27 | |||
28 | try: |
|
28 | try: | |
29 | import json |
|
29 | import json | |
30 | except ImportError: |
|
30 | except ImportError: | |
31 | #python 2.5 compatibility |
|
31 | #python 2.5 compatibility | |
32 | import simplejson as json |
|
32 | import simplejson as json | |
33 |
|
33 | |||
34 | from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev |
|
34 | from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev | |
35 | from pylons import request, session, tmpl_context as c |
|
35 | from pylons import request, session, tmpl_context as c | |
36 |
|
36 | |||
37 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
37 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
38 | from rhodecode.lib.base import BaseRepoController, render |
|
38 | from rhodecode.lib.base import BaseRepoController, render | |
39 | from rhodecode.lib.helpers import RepoPage |
|
39 | from rhodecode.lib.helpers import RepoPage | |
40 |
|
40 | |||
41 | log = logging.getLogger(__name__) |
|
41 | log = logging.getLogger(__name__) | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | class ChangelogController(BaseRepoController): |
|
44 | class ChangelogController(BaseRepoController): | |
45 |
|
45 | |||
46 | @LoginRequired() |
|
46 | @LoginRequired() | |
47 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
47 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
48 | 'repository.admin') |
|
48 | 'repository.admin') | |
49 | def __before__(self): |
|
49 | def __before__(self): | |
50 | super(ChangelogController, self).__before__() |
|
50 | super(ChangelogController, self).__before__() | |
51 | c.affected_files_cut_off = 60 |
|
51 | c.affected_files_cut_off = 60 | |
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, |
|
71 | c.pagination = RepoPage(c.rhodecode_repo, page=p, | |
72 | item_count=c.total_cs, items_per_page=c.size, |
|
72 | item_count=c.total_cs, items_per_page=c.size, | |
73 | branch_name=branch_name) |
|
73 | branch_name=branch_name) | |
74 |
|
74 | |||
75 | self._graph(c.rhodecode_repo, c.total_cs, c.size, p) |
|
75 | self._graph(c.rhodecode_repo, c.total_cs, c.size, p) | |
76 |
|
76 | |||
77 | return render('changelog/changelog.html') |
|
77 | return render('changelog/changelog.html') | |
78 |
|
78 | |||
79 | def _graph(self, repo, repo_size, 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: |
|
87 | if not repo.revisions: | |
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 | try: | |
|
94 | rev_start = repo.revisions.index(repo.revisions[(-1 * offset)]) | |||
|
95 | except IndexError: | |||
|
96 | rev_start = repo.revisions.index(repo.revisions[-1]) | |||
94 | rev_end = max(0, rev_start - revcount) |
|
97 | rev_end = max(0, rev_start - revcount) | |
95 |
|
98 | |||
|
99 | ||||
96 | data = [] |
|
100 | data = [] | |
97 | if repo.alias == 'git': |
|
101 | if repo.alias == 'git': | |
98 | for _ in xrange(rev_end, rev_start): |
|
102 | for _ in xrange(rev_end, rev_start): | |
99 | vtx = [0, 1] |
|
103 | vtx = [0, 1] | |
100 | edges = [[0, 0, 1]] |
|
104 | edges = [[0, 0, 1]] | |
101 | data.append(['', vtx, edges]) |
|
105 | data.append(['', vtx, edges]) | |
102 |
|
106 | |||
103 | elif repo.alias == 'hg': |
|
107 | elif repo.alias == 'hg': | |
104 | dag = graph_rev(repo._repo, rev_start, rev_end) |
|
108 | dag = graph_rev(repo._repo, rev_start, rev_end) | |
105 | c.dag = tree = list(colored(dag)) |
|
109 | c.dag = tree = list(colored(dag)) | |
106 | for (id, type, ctx, vtx, edges) in tree: |
|
110 | for (id, type, ctx, vtx, edges) in tree: | |
107 | if type != CHANGESET: |
|
111 | if type != CHANGESET: | |
108 | continue |
|
112 | continue | |
109 | data.append(['', vtx, edges]) |
|
113 | data.append(['', vtx, edges]) | |
110 |
|
114 | |||
111 | c.jsdata = json.dumps(data) |
|
115 | c.jsdata = json.dumps(data) |
General Comments 0
You need to be logged in to leave comments.
Login now