comparison rhodecode/controllers/changelog.py @ 2031:82a88013a3fd

merge 1.3 into stable
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 26 Feb 2012 17:25:09 +0200
parents da8f1d1b22de 324ac367a4da
children a437a986d399
comparison
equal deleted inserted replaced
2005:ab0e122b38a7 2031:82a88013a3fd
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) 2009-2011 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
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 28
28 from mercurial import graphmod 29 from mercurial import graphmod
29 from pylons import request, session, tmpl_context as c 30 from pylons import request, url, session, tmpl_context as c
31 from pylons.controllers.util import redirect
32 from pylons.i18n.translation import _
30 33
34 import rhodecode.lib.helpers as h
31 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator 35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
32 from rhodecode.lib.base import BaseRepoController, render 36 from rhodecode.lib.base import BaseRepoController, render
33 from rhodecode.lib.helpers import RepoPage 37 from rhodecode.lib.helpers import RepoPage
34 from rhodecode.lib.compat import json 38 from rhodecode.lib.compat import json
39
40 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
41 from rhodecode.model.db import Repository
35 42
36 log = logging.getLogger(__name__) 43 log = logging.getLogger(__name__)
37 44
38 45
39 class ChangelogController(BaseRepoController): 46 class ChangelogController(BaseRepoController):
60 else: 67 else:
61 c.size = int(session.get('changelog_size', default)) 68 c.size = int(session.get('changelog_size', default))
62 69
63 p = int(request.params.get('page', 1)) 70 p = int(request.params.get('page', 1))
64 branch_name = request.params.get('branch', None) 71 branch_name = request.params.get('branch', None)
65 c.total_cs = len(c.rhodecode_repo) 72 try:
66 c.pagination = RepoPage(c.rhodecode_repo, page=p, 73 if branch_name:
67 item_count=c.total_cs, items_per_page=c.size, 74 collection = [z for z in
68 branch_name=branch_name) 75 c.rhodecode_repo.get_changesets(start=0,
76 branch_name=branch_name)]
77 c.total_cs = len(collection)
78 else:
79 collection = c.rhodecode_repo
80 c.total_cs = len(c.rhodecode_repo)
69 81
70 self._graph(c.rhodecode_repo, c.total_cs, c.size, p) 82 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
83 items_per_page=c.size, branch=branch_name)
84 collection = list(c.pagination)
85 page_revisions = [x.raw_id for x in collection]
86 c.comments = c.rhodecode_db_repo.comments(page_revisions)
87
88 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
89 log.error(traceback.format_exc())
90 h.flash(str(e), category='warning')
91 return redirect(url('home'))
92
93 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
94
95 c.branch_name = branch_name
96 c.branch_filters = [('', _('All Branches'))] + \
97 [(k, k) for k in c.rhodecode_repo.branches.keys()]
71 98
72 return render('changelog/changelog.html') 99 return render('changelog/changelog.html')
73 100
74 def changelog_details(self, cs): 101 def changelog_details(self, cs):
75 if request.environ.get('HTTP_X_PARTIAL_XHR'): 102 if request.environ.get('HTTP_X_PARTIAL_XHR'):
76 c.cs = c.rhodecode_repo.get_changeset(cs) 103 c.cs = c.rhodecode_repo.get_changeset(cs)
77 return render('changelog/changelog_details.html') 104 return render('changelog/changelog_details.html')
78 105
79 def _graph(self, repo, repo_size, size, p): 106 def _graph(self, repo, collection, repo_size, size, p):
80 """ 107 """
81 Generates a DAG graph for mercurial 108 Generates a DAG graph for mercurial
82 109
83 :param repo: repo instance 110 :param repo: repo instance
84 :param size: number of commits to show 111 :param size: number of commits to show
85 :param p: page number 112 :param p: page number
86 """ 113 """
87 if not repo.revisions: 114 if not collection:
88 c.jsdata = json.dumps([]) 115 c.jsdata = json.dumps([])
89 return 116 return
90 117
91 revcount = min(repo_size, size)
92 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
93 try:
94 rev_end = repo.revisions.index(repo.revisions[(-1 * offset)])
95 except IndexError:
96 rev_end = repo.revisions.index(repo.revisions[-1])
97 rev_start = max(0, rev_end - revcount)
98
99 data = [] 118 data = []
100 rev_end += 1 119 revs = [x.revision for x in collection]
101 120
102 if repo.alias == 'git': 121 if repo.alias == 'git':
103 for _ in xrange(rev_start, rev_end): 122 for _ in revs:
104 vtx = [0, 1] 123 vtx = [0, 1]
105 edges = [[0, 0, 1]] 124 edges = [[0, 0, 1]]
106 data.append(['', vtx, edges]) 125 data.append(['', vtx, edges])
107 126
108 elif repo.alias == 'hg': 127 elif repo.alias == 'hg':
109 revs = list(reversed(xrange(rev_start, rev_end)))
110 c.dag = graphmod.colored(graphmod.dagwalker(repo._repo, revs)) 128 c.dag = graphmod.colored(graphmod.dagwalker(repo._repo, revs))
111 for (id, type, ctx, vtx, edges) in c.dag: 129 for (id, type, ctx, vtx, edges) in c.dag:
112 if type != graphmod.CHANGESET: 130 if type != graphmod.CHANGESET:
113 continue 131 continue
114 data.append(['', vtx, edges]) 132 data.append(['', vtx, edges])