Show More
@@ -1,157 +1,157 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # This program is free software: you can redistribute it and/or modify |
|
2 | # This program is free software: you can redistribute it and/or modify | |
3 | # it under the terms of the GNU General Public License as published by |
|
3 | # it under the terms of the GNU General Public License as published by | |
4 | # the Free Software Foundation, either version 3 of the License, or |
|
4 | # the Free Software Foundation, either version 3 of the License, or | |
5 | # (at your option) any later version. |
|
5 | # (at your option) any later version. | |
6 | # |
|
6 | # | |
7 | # This program is distributed in the hope that it will be useful, |
|
7 | # This program is distributed in the hope that it will be useful, | |
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | # GNU General Public License for more details. |
|
10 | # GNU General Public License for more details. | |
11 | # |
|
11 | # | |
12 | # You should have received a copy of the GNU General Public License |
|
12 | # You should have received a copy of the GNU General Public License | |
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | """ |
|
14 | """ | |
15 | kallithea.controllers.changelog |
|
15 | kallithea.controllers.changelog | |
16 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
16 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
17 |
|
17 | |||
18 | changelog controller for Kallithea |
|
18 | changelog controller for Kallithea | |
19 |
|
19 | |||
20 | This file was forked by the Kallithea project in July 2014. |
|
20 | This file was forked by the Kallithea project in July 2014. | |
21 | Original author and date, and relevant copyright and licensing information is below: |
|
21 | Original author and date, and relevant copyright and licensing information is below: | |
22 | :created_on: Apr 21, 2010 |
|
22 | :created_on: Apr 21, 2010 | |
23 | :author: marcink |
|
23 | :author: marcink | |
24 | :copyright: (c) 2013 RhodeCode GmbH, and others. |
|
24 | :copyright: (c) 2013 RhodeCode GmbH, and others. | |
25 | :license: GPLv3, see LICENSE.md for more details. |
|
25 | :license: GPLv3, see LICENSE.md for more details. | |
26 | """ |
|
26 | """ | |
27 |
|
27 | |||
28 | import logging |
|
28 | import logging | |
29 | import traceback |
|
29 | import traceback | |
30 |
|
30 | |||
31 | from tg import request, session |
|
31 | from tg import request, session | |
32 | from tg import tmpl_context as c |
|
32 | from tg import tmpl_context as c | |
33 | from tg.i18n import ugettext as _ |
|
33 | from tg.i18n import ugettext as _ | |
34 | from webob.exc import HTTPBadRequest, HTTPFound, HTTPNotFound |
|
34 | from webob.exc import HTTPBadRequest, HTTPFound, HTTPNotFound | |
35 |
|
35 | |||
36 | from kallithea.controllers import base |
|
36 | from kallithea.controllers import base | |
37 | from kallithea.lib import webutils |
|
37 | from kallithea.lib import webutils | |
38 | from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired |
|
38 | from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired | |
39 | from kallithea.lib.graphmod import graph_data |
|
39 | from kallithea.lib.graphmod import graph_data | |
40 | from kallithea.lib.page import Page |
|
40 | from kallithea.lib.page import Page | |
41 | from kallithea.lib.utils2 import safe_int |
|
41 | from kallithea.lib.utils2 import safe_int | |
42 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, EmptyRepositoryError, NodeDoesNotExistError, RepositoryError |
|
42 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, EmptyRepositoryError, NodeDoesNotExistError, RepositoryError | |
43 | from kallithea.lib.webutils import url |
|
43 | from kallithea.lib.webutils import url | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | log = logging.getLogger(__name__) |
|
46 | log = logging.getLogger(__name__) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | class ChangelogController(base.BaseRepoController): |
|
49 | class ChangelogController(base.BaseRepoController): | |
50 |
|
50 | |||
51 | def _before(self, *args, **kwargs): |
|
51 | def _before(self, *args, **kwargs): | |
52 | super(ChangelogController, self)._before(*args, **kwargs) |
|
52 | super(ChangelogController, self)._before(*args, **kwargs) | |
53 | c.affected_files_cut_off = 60 |
|
53 | c.affected_files_cut_off = 60 | |
54 |
|
54 | |||
55 | @staticmethod |
|
55 | @staticmethod | |
56 | def __get_cs(rev, repo): |
|
56 | def __get_cs(rev, repo): | |
57 | """ |
|
57 | """ | |
58 | Safe way to get changeset. If error occur fail with error message. |
|
58 | Safe way to get changeset. If error occur fail with error message. | |
59 |
|
59 | |||
60 | :param rev: revision to fetch |
|
60 | :param rev: revision to fetch | |
61 | :param repo: repo instance |
|
61 | :param repo: repo instance | |
62 | """ |
|
62 | """ | |
63 |
|
63 | |||
64 | try: |
|
64 | try: | |
65 | return c.db_repo_scm_instance.get_changeset(rev) |
|
65 | return c.db_repo_scm_instance.get_changeset(rev) | |
66 | except EmptyRepositoryError as e: |
|
66 | except EmptyRepositoryError as e: | |
67 | webutils.flash(_('There are no changesets yet'), category='error') |
|
67 | webutils.flash(_('There are no changesets yet'), category='error') | |
68 | except RepositoryError as e: |
|
68 | except RepositoryError as e: | |
69 | log.error(traceback.format_exc()) |
|
69 | log.error(traceback.format_exc()) | |
70 | webutils.flash(e, category='error') |
|
70 | webutils.flash(e, category='error') | |
71 | raise HTTPBadRequest() |
|
71 | raise HTTPBadRequest() | |
72 |
|
72 | |||
73 | @LoginRequired(allow_default_user=True) |
|
73 | @LoginRequired(allow_default_user=True) | |
74 | @HasRepoPermissionLevelDecorator('read') |
|
74 | @HasRepoPermissionLevelDecorator('read') | |
75 | def index(self, repo_name, revision=None, f_path=None): |
|
75 | def index(self, repo_name, revision=None, f_path=None): | |
76 | limit = 2000 |
|
76 | limit = 2000 | |
77 | default = 100 |
|
77 | default = 100 | |
78 | if request.GET.get('size'): |
|
78 | if request.GET.get('size'): | |
79 | c.size = max(min(safe_int(request.GET.get('size')), limit), 1) |
|
79 | c.size = max(min(safe_int(request.GET.get('size')), limit), 1) | |
80 | session['changelog_size'] = c.size |
|
80 | session['changelog_size'] = c.size | |
81 | session.save() |
|
81 | session.save() | |
82 | else: |
|
82 | else: | |
83 | c.size = int(session.get('changelog_size', default)) |
|
83 | c.size = int(session.get('changelog_size', default)) | |
84 | # min size must be 1 |
|
84 | # min size must be 1 | |
85 | c.size = max(c.size, 1) |
|
85 | c.size = max(c.size, 1) | |
86 | p = safe_int(request.GET.get('page'), 1) |
|
86 | p = safe_int(request.GET.get('page'), 1) | |
87 | branch_name = request.GET.get('branch', None) |
|
87 | branch_name = request.GET.get('branch', None) | |
88 | if (branch_name and |
|
88 | if (branch_name and | |
89 | branch_name not in c.db_repo_scm_instance.branches and |
|
89 | branch_name not in c.db_repo_scm_instance.branches and | |
90 | branch_name not in c.db_repo_scm_instance.closed_branches and |
|
90 | branch_name not in c.db_repo_scm_instance.closed_branches and | |
91 | not revision |
|
91 | not revision | |
92 | ): |
|
92 | ): | |
93 | raise HTTPFound(location=url('changelog_file_home', repo_name=c.repo_name, |
|
93 | raise HTTPFound(location=url('changelog_file_home', repo_name=c.repo_name, | |
94 | revision=branch_name, f_path=f_path or '')) |
|
94 | revision=branch_name, f_path=f_path or '')) | |
95 |
|
95 | |||
96 | if revision == 'tip': |
|
96 | if revision == 'tip': | |
97 | revision = None |
|
97 | revision = None | |
98 |
|
98 | |||
99 | c.changelog_for_path = f_path |
|
99 | c.changelog_for_path = f_path | |
100 | try: |
|
100 | try: | |
101 |
|
101 | |||
102 | if f_path: |
|
102 | if f_path: | |
103 | log.debug('generating changelog for path %s', f_path) |
|
103 | log.debug('generating changelog for path %s', f_path) | |
104 | # get the history for the file ! |
|
104 | # get the history for the file ! | |
105 | tip_cs = c.db_repo_scm_instance.get_changeset() |
|
105 | tip_cs = c.db_repo_scm_instance.get_changeset() | |
106 | try: |
|
106 | try: | |
107 | collection = tip_cs.get_file_history(f_path) |
|
107 | collection = tip_cs.get_file_history(f_path) | |
108 | except (NodeDoesNotExistError, ChangesetError): |
|
108 | except (NodeDoesNotExistError, ChangesetError): | |
109 | # this node is not present at tip ! |
|
109 | # this node is not present at tip ! | |
110 | try: |
|
110 | try: | |
111 | cs = self.__get_cs(revision, repo_name) |
|
111 | cs = self.__get_cs(revision, repo_name) | |
112 | collection = cs.get_file_history(f_path) |
|
112 | collection = cs.get_file_history(f_path) | |
113 | except RepositoryError as e: |
|
113 | except RepositoryError as e: | |
114 | webutils.flash(e, category='warning') |
|
114 | webutils.flash(e, category='warning') | |
115 | raise HTTPFound(location=webutils.url('changelog_home', repo_name=repo_name)) |
|
115 | raise HTTPFound(location=webutils.url('changelog_home', repo_name=repo_name)) | |
116 | else: |
|
116 | else: | |
117 |
collection = c.db_repo_scm_instance.get_changesets( |
|
117 | collection = c.db_repo_scm_instance.get_changesets(end=revision, | |
118 | branch_name=branch_name, reverse=True) |
|
118 | branch_name=branch_name, reverse=True) | |
119 | c.total_cs = len(collection) |
|
119 | c.total_cs = len(collection) | |
120 |
|
120 | |||
121 | c.cs_pagination = Page(collection, page=p, item_count=c.total_cs, items_per_page=c.size, |
|
121 | c.cs_pagination = Page(collection, page=p, item_count=c.total_cs, items_per_page=c.size, | |
122 | branch=branch_name) |
|
122 | branch=branch_name) | |
123 |
|
123 | |||
124 | page_revisions = [x.raw_id for x in c.cs_pagination] |
|
124 | page_revisions = [x.raw_id for x in c.cs_pagination] | |
125 | c.cs_comments = c.db_repo.get_comments(page_revisions) |
|
125 | c.cs_comments = c.db_repo.get_comments(page_revisions) | |
126 | c.cs_statuses = c.db_repo.statuses(page_revisions) |
|
126 | c.cs_statuses = c.db_repo.statuses(page_revisions) | |
127 | except EmptyRepositoryError as e: |
|
127 | except EmptyRepositoryError as e: | |
128 | webutils.flash(e, category='warning') |
|
128 | webutils.flash(e, category='warning') | |
129 | raise HTTPFound(location=url('summary_home', repo_name=c.repo_name)) |
|
129 | raise HTTPFound(location=url('summary_home', repo_name=c.repo_name)) | |
130 | except (RepositoryError, ChangesetDoesNotExistError, Exception) as e: |
|
130 | except (RepositoryError, ChangesetDoesNotExistError, Exception) as e: | |
131 | log.error(traceback.format_exc()) |
|
131 | log.error(traceback.format_exc()) | |
132 | webutils.flash(e, category='error') |
|
132 | webutils.flash(e, category='error') | |
133 | raise HTTPFound(location=url('changelog_home', repo_name=c.repo_name)) |
|
133 | raise HTTPFound(location=url('changelog_home', repo_name=c.repo_name)) | |
134 |
|
134 | |||
135 | c.branch_name = branch_name |
|
135 | c.branch_name = branch_name | |
136 | c.branch_filters = [('', _('None'))] + \ |
|
136 | c.branch_filters = [('', _('None'))] + \ | |
137 | [(k, k) for k in c.db_repo_scm_instance.branches] |
|
137 | [(k, k) for k in c.db_repo_scm_instance.branches] | |
138 | if c.db_repo_scm_instance.closed_branches: |
|
138 | if c.db_repo_scm_instance.closed_branches: | |
139 | prefix = _('(closed)') + ' ' |
|
139 | prefix = _('(closed)') + ' ' | |
140 | c.branch_filters += [('-', '-')] + \ |
|
140 | c.branch_filters += [('-', '-')] + \ | |
141 | [(k, prefix + k) for k in c.db_repo_scm_instance.closed_branches] |
|
141 | [(k, prefix + k) for k in c.db_repo_scm_instance.closed_branches] | |
142 | revs = [] |
|
142 | revs = [] | |
143 | if not f_path: |
|
143 | if not f_path: | |
144 | revs = [x.revision for x in c.cs_pagination] |
|
144 | revs = [x.revision for x in c.cs_pagination] | |
145 | c.jsdata = graph_data(c.db_repo_scm_instance, revs) |
|
145 | c.jsdata = graph_data(c.db_repo_scm_instance, revs) | |
146 |
|
146 | |||
147 | c.revision = revision # requested revision ref |
|
147 | c.revision = revision # requested revision ref | |
148 | c.first_revision = c.cs_pagination[0] # pagination is never empty here! |
|
148 | c.first_revision = c.cs_pagination[0] # pagination is never empty here! | |
149 | return base.render('changelog/changelog.html') |
|
149 | return base.render('changelog/changelog.html') | |
150 |
|
150 | |||
151 | @LoginRequired(allow_default_user=True) |
|
151 | @LoginRequired(allow_default_user=True) | |
152 | @HasRepoPermissionLevelDecorator('read') |
|
152 | @HasRepoPermissionLevelDecorator('read') | |
153 | def changelog_details(self, cs): |
|
153 | def changelog_details(self, cs): | |
154 | if request.environ.get('HTTP_X_PARTIAL_XHR'): |
|
154 | if request.environ.get('HTTP_X_PARTIAL_XHR'): | |
155 | c.cs = c.db_repo_scm_instance.get_changeset(cs) |
|
155 | c.cs = c.db_repo_scm_instance.get_changeset(cs) | |
156 | return base.render('changelog/changelog_details.html') |
|
156 | return base.render('changelog/changelog_details.html') | |
157 | raise HTTPNotFound() |
|
157 | raise HTTPNotFound() |
General Comments 0
You need to be logged in to leave comments.
Login now