Mercurial > kallithea
diff 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 |
line wrap: on
line diff
--- a/rhodecode/controllers/changelog.py Sun Feb 19 20:21:14 2012 +0200 +++ b/rhodecode/controllers/changelog.py Sun Feb 26 17:25:09 2012 +0200 @@ -7,7 +7,7 @@ :created_on: Apr 21, 2010 :author: marcink - :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> + :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> :license: GPLv3, see COPYING for more details. """ # This program is free software: you can redistribute it and/or modify @@ -24,15 +24,22 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import logging +import traceback from mercurial import graphmod -from pylons import request, session, tmpl_context as c +from pylons import request, url, session, tmpl_context as c +from pylons.controllers.util import redirect +from pylons.i18n.translation import _ +import rhodecode.lib.helpers as h from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseRepoController, render from rhodecode.lib.helpers import RepoPage from rhodecode.lib.compat import json +from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError +from rhodecode.model.db import Repository + log = logging.getLogger(__name__) @@ -62,12 +69,32 @@ p = int(request.params.get('page', 1)) branch_name = request.params.get('branch', None) - c.total_cs = len(c.rhodecode_repo) - c.pagination = RepoPage(c.rhodecode_repo, page=p, - item_count=c.total_cs, items_per_page=c.size, - branch_name=branch_name) + try: + if branch_name: + collection = [z for z in + c.rhodecode_repo.get_changesets(start=0, + branch_name=branch_name)] + c.total_cs = len(collection) + else: + collection = c.rhodecode_repo + c.total_cs = len(c.rhodecode_repo) - self._graph(c.rhodecode_repo, c.total_cs, c.size, p) + c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, + items_per_page=c.size, branch=branch_name) + collection = list(c.pagination) + page_revisions = [x.raw_id for x in collection] + c.comments = c.rhodecode_db_repo.comments(page_revisions) + + except (RepositoryError, ChangesetDoesNotExistError, Exception), e: + log.error(traceback.format_exc()) + h.flash(str(e), category='warning') + return redirect(url('home')) + + self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p) + + c.branch_name = branch_name + c.branch_filters = [('', _('All Branches'))] + \ + [(k, k) for k in c.rhodecode_repo.branches.keys()] return render('changelog/changelog.html') @@ -76,7 +103,7 @@ c.cs = c.rhodecode_repo.get_changeset(cs) return render('changelog/changelog_details.html') - def _graph(self, repo, repo_size, size, p): + def _graph(self, repo, collection, repo_size, size, p): """ Generates a DAG graph for mercurial @@ -84,29 +111,20 @@ :param size: number of commits to show :param p: page number """ - if not repo.revisions: + if not collection: c.jsdata = json.dumps([]) return - revcount = min(repo_size, size) - offset = 1 if p == 1 else ((p - 1) * revcount + 1) - try: - rev_end = repo.revisions.index(repo.revisions[(-1 * offset)]) - except IndexError: - rev_end = repo.revisions.index(repo.revisions[-1]) - rev_start = max(0, rev_end - revcount) - data = [] - rev_end += 1 + revs = [x.revision for x in collection] if repo.alias == 'git': - for _ in xrange(rev_start, rev_end): + for _ in revs: vtx = [0, 1] edges = [[0, 0, 1]] data.append(['', vtx, edges]) elif repo.alias == 'hg': - revs = list(reversed(xrange(rev_start, rev_end))) c.dag = graphmod.colored(graphmod.dagwalker(repo._repo, revs)) for (id, type, ctx, vtx, edges) in c.dag: if type != graphmod.CHANGESET: