##// END OF EJS Templates
fixes issue #502, float division error on setting maxsize of changelog to 0
marcink -
r2628:4548912f beta
parent child Browse files
Show More
@@ -1,124 +1,125 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.changelog
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 changelog controller for rhodecode
7 7
8 8 :created_on: Apr 21, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 27 import traceback
28 28
29 29 from pylons import request, url, session, tmpl_context as c
30 30 from pylons.controllers.util import redirect
31 31 from pylons.i18n.translation import _
32 32
33 33 import rhodecode.lib.helpers as h
34 34 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
35 35 from rhodecode.lib.base import BaseRepoController, render
36 36 from rhodecode.lib.helpers import RepoPage
37 37 from rhodecode.lib.compat import json
38 38 from rhodecode.lib.graphmod import _colored, _dagwalker
39 39 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
40 40
41 41 log = logging.getLogger(__name__)
42 42
43 43
44 44 class ChangelogController(BaseRepoController):
45 45
46 46 @LoginRequired()
47 47 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
48 48 'repository.admin')
49 49 def __before__(self):
50 50 super(ChangelogController, self).__before__()
51 51 c.affected_files_cut_off = 60
52 52
53 53 def index(self):
54 54 limit = 100
55 55 default = 20
56 56 if request.params.get('size'):
57 57 try:
58 58 int_size = int(request.params.get('size'))
59 59 except ValueError:
60 60 int_size = default
61 61 int_size = int_size if int_size <= limit else limit
62 62 c.size = int_size
63 63 session['changelog_size'] = c.size
64 64 session.save()
65 65 else:
66 66 c.size = int(session.get('changelog_size', default))
67
67 # min size must be 1
68 c.size = max(c.size, 1)
68 69 p = int(request.params.get('page', 1))
69 70 branch_name = request.params.get('branch', None)
70 71 try:
71 72 if branch_name:
72 73 collection = [z for z in
73 74 c.rhodecode_repo.get_changesets(start=0,
74 75 branch_name=branch_name)]
75 76 c.total_cs = len(collection)
76 77 else:
77 78 collection = c.rhodecode_repo
78 79 c.total_cs = len(c.rhodecode_repo)
79 80
80 81 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
81 82 items_per_page=c.size, branch=branch_name)
82 83 collection = list(c.pagination)
83 84 page_revisions = [x.raw_id for x in collection]
84 85 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
85 86 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
86 87 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
87 88 log.error(traceback.format_exc())
88 89 h.flash(str(e), category='warning')
89 90 return redirect(url('home'))
90 91
91 92 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
92 93
93 94 c.branch_name = branch_name
94 95 c.branch_filters = [('', _('All Branches'))] + \
95 96 [(k, k) for k in c.rhodecode_repo.branches.keys()]
96 97
97 98 return render('changelog/changelog.html')
98 99
99 100 def changelog_details(self, cs):
100 101 if request.environ.get('HTTP_X_PARTIAL_XHR'):
101 102 c.cs = c.rhodecode_repo.get_changeset(cs)
102 103 return render('changelog/changelog_details.html')
103 104
104 105 def _graph(self, repo, collection, repo_size, size, p):
105 106 """
106 107 Generates a DAG graph for mercurial
107 108
108 109 :param repo: repo instance
109 110 :param size: number of commits to show
110 111 :param p: page number
111 112 """
112 113 if not collection:
113 114 c.jsdata = json.dumps([])
114 115 return
115 116
116 117 data = []
117 118 revs = [x.revision for x in collection]
118 119
119 120 dag = _dagwalker(repo, revs, repo.alias)
120 121 dag = _colored(dag)
121 122 for (id, type, ctx, vtx, edges) in dag:
122 123 data.append(['', vtx, edges])
123 124
124 125 c.jsdata = json.dumps(data)
General Comments 0
You need to be logged in to leave comments. Login now