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