##// END OF EJS Templates
backout revision e5abb9efaf2c
marcink -
r2228:eb64d783 beta
parent child Browse files
Show More
@@ -1,140 +1,135 b''
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 mercurial import graphmod
29 from mercurial import graphmod
30 from pylons import request, url, session, tmpl_context as c
30 from pylons import request, url, session, tmpl_context as c
31 from pylons.controllers.util import redirect
31 from pylons.controllers.util import redirect
32 from pylons.i18n.translation import _
32 from pylons.i18n.translation import _
33
33
34 import rhodecode.lib.helpers as h
34 import rhodecode.lib.helpers as h
35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
36 from rhodecode.lib.base import BaseRepoController, render
36 from rhodecode.lib.base import BaseRepoController, render
37 from rhodecode.lib.helpers import RepoPage
37 from rhodecode.lib.helpers import RepoPage
38 from rhodecode.lib.compat import json
38 from rhodecode.lib.compat import json
39
39
40 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
40 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
41 from rhodecode.model.db import Repository
41 from rhodecode.model.db import Repository
42
42
43 log = logging.getLogger(__name__)
43 log = logging.getLogger(__name__)
44
44
45
45
46 class ChangelogController(BaseRepoController):
46 class ChangelogController(BaseRepoController):
47
47
48 @LoginRequired()
48 @LoginRequired()
49 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
49 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
50 'repository.admin')
50 'repository.admin')
51 def __before__(self):
51 def __before__(self):
52 super(ChangelogController, self).__before__()
52 super(ChangelogController, self).__before__()
53 c.affected_files_cut_off = 60
53 c.affected_files_cut_off = 60
54
54
55 def index(self):
55 def index(self):
56 limit = 100
56 limit = 100
57 default = 20
57 default = 20
58 if request.params.get('size'):
58 if request.params.get('size'):
59 try:
59 try:
60 int_size = int(request.params.get('size'))
60 int_size = int(request.params.get('size'))
61 except ValueError:
61 except ValueError:
62 int_size = default
62 int_size = default
63 int_size = int_size if int_size <= limit else limit
63 int_size = int_size if int_size <= limit else limit
64 c.size = int_size
64 c.size = int_size
65 session['changelog_size'] = c.size
65 session['changelog_size'] = c.size
66 session.save()
66 session.save()
67 else:
67 else:
68 c.size = int(session.get('changelog_size', default))
68 c.size = int(session.get('changelog_size', default))
69
69
70 p = int(request.params.get('page', 1))
70 p = int(request.params.get('page', 1))
71 branch_name = request.params.get('branch', None)
71 branch_name = request.params.get('branch', None)
72 try:
72 try:
73 if branch_name:
73 if branch_name:
74 collection = [z for z in
74 collection = [z for z in
75 c.rhodecode_repo.get_changesets(start=0,
75 c.rhodecode_repo.get_changesets(start=0,
76 branch_name=branch_name)]
76 branch_name=branch_name)]
77 c.total_cs = len(collection)
77 c.total_cs = len(collection)
78 else:
78 else:
79 collection = c.rhodecode_repo
79 collection = c.rhodecode_repo
80 c.total_cs = len(c.rhodecode_repo)
80 c.total_cs = len(c.rhodecode_repo)
81
81
82 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
82 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
83 items_per_page=c.size, branch=branch_name)
83 items_per_page=c.size, branch=branch_name)
84 collection = list(c.pagination)
84 collection = list(c.pagination)
85 page_revisions = [x.raw_id for x in collection]
85 page_revisions = [x.raw_id for x in collection]
86 c.comments = c.rhodecode_db_repo.comments(page_revisions)
86 c.comments = c.rhodecode_db_repo.comments(page_revisions)
87
87
88 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
88 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
89 log.error(traceback.format_exc())
89 log.error(traceback.format_exc())
90 h.flash(str(e), category='warning')
90 h.flash(str(e), category='warning')
91 return redirect(url('home'))
91 return redirect(url('home'))
92
92
93 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
93 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
94
94
95 c.branch_name = branch_name
95 c.branch_name = branch_name
96 c.branch_filters = [('', _('All Branches'))] + \
96 c.branch_filters = [('', _('All Branches'))] + \
97 [(k, k) for k in c.rhodecode_repo.branches.keys()]
97 [(k, k) for k in c.rhodecode_repo.branches.keys()]
98
98
99 return render('changelog/changelog.html')
99 return render('changelog/changelog.html')
100
100
101 def changelog_details(self, cs):
101 def changelog_details(self, cs):
102 if request.environ.get('HTTP_X_PARTIAL_XHR'):
102 if request.environ.get('HTTP_X_PARTIAL_XHR'):
103 c.cs = c.rhodecode_repo.get_changeset(cs)
103 c.cs = c.rhodecode_repo.get_changeset(cs)
104 return render('changelog/changelog_details.html')
104 return render('changelog/changelog_details.html')
105
105
106 def _graph(self, repo, collection, repo_size, size, p):
106 def _graph(self, repo, collection, repo_size, size, p):
107 """
107 """
108 Generates a DAG graph for mercurial
108 Generates a DAG graph for mercurial
109
109
110 :param repo: repo instance
110 :param repo: repo instance
111 :param size: number of commits to show
111 :param size: number of commits to show
112 :param p: page number
112 :param p: page number
113 """
113 """
114 if not collection:
114 if not collection:
115 c.jsdata = json.dumps([])
115 c.jsdata = json.dumps([])
116 return
116 return
117
117
118 data = []
118 data = []
119 revs = [x.revision for x in collection]
119 revs = [x.revision for x in collection]
120
120
121 if repo.alias == 'git':
121 if repo.alias == 'git':
122 for _ in revs:
122 for _ in revs:
123 vtx = [0, 1]
123 vtx = [0, 1]
124 edges = [[0, 0, 1]]
124 edges = [[0, 0, 1]]
125 data.append(['', vtx, edges])
125 data.append(['', vtx, edges])
126
126
127 elif repo.alias == 'hg':
127 elif repo.alias == 'hg':
128 dag = graphmod.dagwalker(repo._repo, revs)
128 dag = graphmod.dagwalker(repo._repo, revs)
129 try:
129 c.dag = graphmod.colored(dag, repo._repo)
130 c.dag = graphmod.colored(dag)
131 except:
132 #HG 2.2+
133 c.dag = graphmod.colored(dag, repo._repo)
134
135 for (id, type, ctx, vtx, edges) in c.dag:
130 for (id, type, ctx, vtx, edges) in c.dag:
136 if type != graphmod.CHANGESET:
131 if type != graphmod.CHANGESET:
137 continue
132 continue
138 data.append(['', vtx, edges])
133 data.append(['', vtx, edges])
139
134
140 c.jsdata = json.dumps(data)
135 c.jsdata = json.dumps(data)
General Comments 0
You need to be logged in to leave comments. Login now