##// END OF EJS Templates
in case of empty directory don't redirect to changelog, it causes an redirection loop
marcink -
r3794:222e9432 beta
parent child Browse files
Show More
@@ -1,172 +1,175
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 ChangesetError, NodeDoesNotExistError
40 ChangesetError, NodeDoesNotExistError, EmptyRepositoryError
41 from rhodecode.lib.utils2 import safe_int
41 from rhodecode.lib.utils2 import safe_int
42 from webob.exc import HTTPNotFound
42 from webob.exc import HTTPNotFound
43
43
44 log = logging.getLogger(__name__)
44 log = logging.getLogger(__name__)
45
45
46
46
47 def _load_changelog_summary():
47 def _load_changelog_summary():
48 p = safe_int(request.GET.get('page'), 1)
48 p = safe_int(request.GET.get('page'), 1)
49 size = safe_int(request.GET.get('size'), 10)
49 size = safe_int(request.GET.get('size'), 10)
50
50
51 def url_generator(**kw):
51 def url_generator(**kw):
52 return url('changelog_summary_home',
52 return url('changelog_summary_home',
53 repo_name=c.rhodecode_db_repo.repo_name, size=size, **kw)
53 repo_name=c.rhodecode_db_repo.repo_name, size=size, **kw)
54
54
55 collection = c.rhodecode_repo
55 collection = c.rhodecode_repo
56
56
57 c.repo_changesets = RepoPage(collection, page=p,
57 c.repo_changesets = RepoPage(collection, page=p,
58 items_per_page=size,
58 items_per_page=size,
59 url=url_generator)
59 url=url_generator)
60 page_revisions = [x.raw_id for x in list(c.repo_changesets)]
60 page_revisions = [x.raw_id for x in list(c.repo_changesets)]
61 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
61 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
62 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
62 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
63
63
64
64
65 class ChangelogController(BaseRepoController):
65 class ChangelogController(BaseRepoController):
66
66
67 def __before__(self):
67 def __before__(self):
68 super(ChangelogController, self).__before__()
68 super(ChangelogController, self).__before__()
69 c.affected_files_cut_off = 60
69 c.affected_files_cut_off = 60
70
70
71 def _graph(self, repo, revs_int, repo_size, size, p):
71 def _graph(self, repo, revs_int, repo_size, size, p):
72 """
72 """
73 Generates a DAG graph for repo
73 Generates a DAG graph for repo
74
74
75 :param repo:
75 :param repo:
76 :param revs_int:
76 :param revs_int:
77 :param repo_size:
77 :param repo_size:
78 :param size:
78 :param size:
79 :param p:
79 :param p:
80 """
80 """
81 if not revs_int:
81 if not revs_int:
82 c.jsdata = json.dumps([])
82 c.jsdata = json.dumps([])
83 return
83 return
84
84
85 data = []
85 data = []
86 revs = revs_int
86 revs = revs_int
87
87
88 dag = _dagwalker(repo, revs, repo.alias)
88 dag = _dagwalker(repo, revs, repo.alias)
89 dag = _colored(dag)
89 dag = _colored(dag)
90 for (id, type, ctx, vtx, edges) in dag:
90 for (id, type, ctx, vtx, edges) in dag:
91 data.append(['', vtx, edges])
91 data.append(['', vtx, edges])
92
92
93 c.jsdata = json.dumps(data)
93 c.jsdata = json.dumps(data)
94
94
95 @LoginRequired()
95 @LoginRequired()
96 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
96 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
97 'repository.admin')
97 'repository.admin')
98 def index(self, repo_name, revision=None, f_path=None):
98 def index(self, repo_name, revision=None, f_path=None):
99 limit = 100
99 limit = 100
100 default = 20
100 default = 20
101 if request.GET.get('size'):
101 if request.GET.get('size'):
102 c.size = max(min(safe_int(request.GET.get('size')), limit), 1)
102 c.size = max(min(safe_int(request.GET.get('size')), limit), 1)
103 session['changelog_size'] = c.size
103 session['changelog_size'] = c.size
104 session.save()
104 session.save()
105 else:
105 else:
106 c.size = int(session.get('changelog_size', default))
106 c.size = int(session.get('changelog_size', default))
107 # min size must be 1
107 # min size must be 1
108 c.size = max(c.size, 1)
108 c.size = max(c.size, 1)
109 p = safe_int(request.GET.get('page', 1), 1)
109 p = safe_int(request.GET.get('page', 1), 1)
110 branch_name = request.GET.get('branch', None)
110 branch_name = request.GET.get('branch', None)
111 c.changelog_for_path = f_path
111 c.changelog_for_path = f_path
112 try:
112 try:
113
113
114 if f_path:
114 if f_path:
115 log.debug('generating changelog for path %s' % f_path)
115 log.debug('generating changelog for path %s' % f_path)
116 # get the history for the file !
116 # get the history for the file !
117 tip_cs = c.rhodecode_repo.get_changeset()
117 tip_cs = c.rhodecode_repo.get_changeset()
118 try:
118 try:
119 collection = tip_cs.get_file_history(f_path)
119 collection = tip_cs.get_file_history(f_path)
120 except (NodeDoesNotExistError, ChangesetError):
120 except (NodeDoesNotExistError, ChangesetError):
121 #this node is not present at tip !
121 #this node is not present at tip !
122 try:
122 try:
123 cs = self.__get_cs_or_redirect(revision, repo_name)
123 cs = self.__get_cs_or_redirect(revision, repo_name)
124 collection = cs.get_file_history(f_path)
124 collection = cs.get_file_history(f_path)
125 except RepositoryError, e:
125 except RepositoryError, e:
126 h.flash(str(e), category='warning')
126 h.flash(str(e), category='warning')
127 redirect(h.url('changelog_home', repo_name=repo_name))
127 redirect(h.url('changelog_home', repo_name=repo_name))
128 collection = list(reversed(collection))
128 collection = list(reversed(collection))
129 else:
129 else:
130 collection = c.rhodecode_repo.get_changesets(start=0,
130 collection = c.rhodecode_repo.get_changesets(start=0,
131 branch_name=branch_name)
131 branch_name=branch_name)
132 c.total_cs = len(collection)
132 c.total_cs = len(collection)
133
133
134 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
134 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
135 items_per_page=c.size, branch=branch_name)
135 items_per_page=c.size, branch=branch_name)
136 collection = list(c.pagination)
136 collection = list(c.pagination)
137 page_revisions = [x.raw_id for x in c.pagination]
137 page_revisions = [x.raw_id for x in c.pagination]
138 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
138 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
139 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
139 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
140 except (EmptyRepositoryError), e:
141 h.flash(str(e), category='warning')
142 return redirect(url('summary_home', repo_name=c.repo_name))
140 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
143 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
141 log.error(traceback.format_exc())
144 log.error(traceback.format_exc())
142 h.flash(str(e), category='error')
145 h.flash(str(e), category='error')
143 return redirect(url('changelog_home', repo_name=c.repo_name))
146 return redirect(url('changelog_home', repo_name=c.repo_name))
144
147
145 c.branch_name = branch_name
148 c.branch_name = branch_name
146 c.branch_filters = [('', _('All Branches'))] + \
149 c.branch_filters = [('', _('All Branches'))] + \
147 [(k, k) for k in c.rhodecode_repo.branches.keys()]
150 [(k, k) for k in c.rhodecode_repo.branches.keys()]
148 _revs = []
151 _revs = []
149 if not f_path:
152 if not f_path:
150 _revs = [x.revision for x in c.pagination]
153 _revs = [x.revision for x in c.pagination]
151 self._graph(c.rhodecode_repo, _revs, c.total_cs, c.size, p)
154 self._graph(c.rhodecode_repo, _revs, c.total_cs, c.size, p)
152
155
153 return render('changelog/changelog.html')
156 return render('changelog/changelog.html')
154
157
155 @LoginRequired()
158 @LoginRequired()
156 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
159 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
157 'repository.admin')
160 'repository.admin')
158 def changelog_details(self, cs):
161 def changelog_details(self, cs):
159 if request.environ.get('HTTP_X_PARTIAL_XHR'):
162 if request.environ.get('HTTP_X_PARTIAL_XHR'):
160 c.cs = c.rhodecode_repo.get_changeset(cs)
163 c.cs = c.rhodecode_repo.get_changeset(cs)
161 return render('changelog/changelog_details.html')
164 return render('changelog/changelog_details.html')
162 raise HTTPNotFound()
165 raise HTTPNotFound()
163
166
164 @LoginRequired()
167 @LoginRequired()
165 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
168 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
166 'repository.admin')
169 'repository.admin')
167 def changelog_summary(self, repo_name):
170 def changelog_summary(self, repo_name):
168 if request.environ.get('HTTP_X_PARTIAL_XHR'):
171 if request.environ.get('HTTP_X_PARTIAL_XHR'):
169 _load_changelog_summary()
172 _load_changelog_summary()
170
173
171 return render('changelog/changelog_summary_data.html')
174 return render('changelog/changelog_summary_data.html')
172 raise HTTPNotFound()
175 raise HTTPNotFound()
General Comments 0
You need to be logged in to leave comments. Login now