Show More
@@ -1,121 +1,125 | |||||
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) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
|
10 | :copyright: (C) 2010-2012 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 | import traceback |
|
27 | import traceback | |
28 |
|
28 | |||
29 | from pylons import request, url, session, tmpl_context as c |
|
29 | from pylons import request, url, session, tmpl_context as c | |
30 | from pylons.controllers.util import redirect |
|
30 | from pylons.controllers.util import redirect | |
31 | from pylons.i18n.translation import _ |
|
31 | from pylons.i18n.translation import _ | |
32 |
|
32 | |||
33 | import rhodecode.lib.helpers as h |
|
33 | import rhodecode.lib.helpers as h | |
34 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
34 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
35 | from rhodecode.lib.base import BaseRepoController, render |
|
35 | from rhodecode.lib.base import BaseRepoController, render | |
36 | from rhodecode.lib.helpers import RepoPage |
|
36 | from rhodecode.lib.helpers import RepoPage | |
37 | from rhodecode.lib.compat import json |
|
37 | from rhodecode.lib.compat import json | |
38 | from rhodecode.lib.graphmod import _colored, _dagwalker |
|
38 | from rhodecode.lib.graphmod import _colored, _dagwalker | |
39 | from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError |
|
39 | from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ | |
|
40 | EmptyRepositoryError | |||
40 | from rhodecode.lib.utils2 import safe_int |
|
41 | from rhodecode.lib.utils2 import safe_int | |
41 |
|
42 | |||
42 | log = logging.getLogger(__name__) |
|
43 | log = logging.getLogger(__name__) | |
43 |
|
44 | |||
44 |
|
45 | |||
45 | class ChangelogController(BaseRepoController): |
|
46 | class ChangelogController(BaseRepoController): | |
46 |
|
47 | |||
47 | @LoginRequired() |
|
48 | @LoginRequired() | |
48 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
49 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
49 | 'repository.admin') |
|
50 | 'repository.admin') | |
50 | def __before__(self): |
|
51 | def __before__(self): | |
51 | super(ChangelogController, self).__before__() |
|
52 | super(ChangelogController, self).__before__() | |
52 | c.affected_files_cut_off = 60 |
|
53 | c.affected_files_cut_off = 60 | |
53 |
|
54 | |||
54 | def index(self): |
|
55 | def index(self): | |
55 | limit = 100 |
|
56 | limit = 100 | |
56 | default = 20 |
|
57 | default = 20 | |
57 | if request.GET.get('size'): |
|
58 | if request.GET.get('size'): | |
58 | c.size = max(min(safe_int(request.GET.get('size')), limit), 1) |
|
59 | c.size = max(min(safe_int(request.GET.get('size')), limit), 1) | |
59 | session['changelog_size'] = c.size |
|
60 | session['changelog_size'] = c.size | |
60 | session.save() |
|
61 | session.save() | |
61 | else: |
|
62 | else: | |
62 | c.size = int(session.get('changelog_size', default)) |
|
63 | c.size = int(session.get('changelog_size', default)) | |
63 | # min size must be 1 |
|
64 | # min size must be 1 | |
64 | c.size = max(c.size, 1) |
|
65 | c.size = max(c.size, 1) | |
65 | p = safe_int(request.GET.get('page', 1), 1) |
|
66 | p = safe_int(request.GET.get('page', 1), 1) | |
66 | branch_name = request.GET.get('branch', None) |
|
67 | branch_name = request.GET.get('branch', None) | |
67 | try: |
|
68 | try: | |
68 | if branch_name: |
|
69 | if branch_name: | |
69 | collection = [z for z in |
|
70 | collection = [z for z in | |
70 | c.rhodecode_repo.get_changesets(start=0, |
|
71 | c.rhodecode_repo.get_changesets(start=0, | |
71 | branch_name=branch_name)] |
|
72 | branch_name=branch_name)] | |
72 | c.total_cs = len(collection) |
|
73 | c.total_cs = len(collection) | |
73 | else: |
|
74 | else: | |
74 | collection = c.rhodecode_repo |
|
75 | collection = c.rhodecode_repo | |
75 | c.total_cs = len(c.rhodecode_repo) |
|
76 | c.total_cs = len(c.rhodecode_repo) | |
76 |
|
77 | |||
77 | c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, |
|
78 | c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, | |
78 | items_per_page=c.size, branch=branch_name) |
|
79 | items_per_page=c.size, branch=branch_name) | |
79 | collection = list(c.pagination) |
|
80 | collection = list(c.pagination) | |
80 | page_revisions = [x.raw_id for x in collection] |
|
81 | page_revisions = [x.raw_id for x in collection] | |
81 | c.comments = c.rhodecode_db_repo.get_comments(page_revisions) |
|
82 | c.comments = c.rhodecode_db_repo.get_comments(page_revisions) | |
82 | c.statuses = c.rhodecode_db_repo.statuses(page_revisions) |
|
83 | c.statuses = c.rhodecode_db_repo.statuses(page_revisions) | |
|
84 | except (EmptyRepositoryError), e: | |||
|
85 | h.flash(str(e), category='warning') | |||
|
86 | return redirect(url('summary_home', repo_name=c.repo_name)) | |||
83 | except (RepositoryError, ChangesetDoesNotExistError, Exception), e: |
|
87 | except (RepositoryError, ChangesetDoesNotExistError, Exception), e: | |
84 | log.error(traceback.format_exc()) |
|
88 | log.error(traceback.format_exc()) | |
85 | h.flash(str(e), category='error') |
|
89 | h.flash(str(e), category='error') | |
86 | return redirect(url('changelog_home', repo_name=c.repo_name)) |
|
90 | return redirect(url('changelog_home', repo_name=c.repo_name)) | |
87 |
|
91 | |||
88 | self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p) |
|
92 | self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p) | |
89 |
|
93 | |||
90 | c.branch_name = branch_name |
|
94 | c.branch_name = branch_name | |
91 | c.branch_filters = [('', _('All Branches'))] + \ |
|
95 | c.branch_filters = [('', _('All Branches'))] + \ | |
92 | [(k, k) for k in c.rhodecode_repo.branches.keys()] |
|
96 | [(k, k) for k in c.rhodecode_repo.branches.keys()] | |
93 |
|
97 | |||
94 | return render('changelog/changelog.html') |
|
98 | return render('changelog/changelog.html') | |
95 |
|
99 | |||
96 | def changelog_details(self, cs): |
|
100 | def changelog_details(self, cs): | |
97 | if request.environ.get('HTTP_X_PARTIAL_XHR'): |
|
101 | if request.environ.get('HTTP_X_PARTIAL_XHR'): | |
98 | c.cs = c.rhodecode_repo.get_changeset(cs) |
|
102 | c.cs = c.rhodecode_repo.get_changeset(cs) | |
99 | return render('changelog/changelog_details.html') |
|
103 | return render('changelog/changelog_details.html') | |
100 |
|
104 | |||
101 | def _graph(self, repo, collection, repo_size, size, p): |
|
105 | def _graph(self, repo, collection, repo_size, size, p): | |
102 | """ |
|
106 | """ | |
103 | Generates a DAG graph for mercurial |
|
107 | Generates a DAG graph for mercurial | |
104 |
|
108 | |||
105 | :param repo: repo instance |
|
109 | :param repo: repo instance | |
106 | :param size: number of commits to show |
|
110 | :param size: number of commits to show | |
107 | :param p: page number |
|
111 | :param p: page number | |
108 | """ |
|
112 | """ | |
109 | if not collection: |
|
113 | if not collection: | |
110 | c.jsdata = json.dumps([]) |
|
114 | c.jsdata = json.dumps([]) | |
111 | return |
|
115 | return | |
112 |
|
116 | |||
113 | data = [] |
|
117 | data = [] | |
114 | revs = [x.revision for x in collection] |
|
118 | revs = [x.revision for x in collection] | |
115 |
|
119 | |||
116 | dag = _dagwalker(repo, revs, repo.alias) |
|
120 | dag = _dagwalker(repo, revs, repo.alias) | |
117 | dag = _colored(dag) |
|
121 | dag = _colored(dag) | |
118 | for (id, type, ctx, vtx, edges) in dag: |
|
122 | for (id, type, ctx, vtx, edges) in dag: | |
119 | data.append(['', vtx, edges]) |
|
123 | data.append(['', vtx, edges]) | |
120 |
|
124 | |||
121 | c.jsdata = json.dumps(data) |
|
125 | c.jsdata = json.dumps(data) |
General Comments 0
You need to be logged in to leave comments.
Login now