# HG changeset patch # User Marcin Kuzminski # Date 1371299871 -7200 # Node ID 267bb347d68cac089197e769bd83e3acebce671f # Parent 334ac2635e670a8ab2067d7595463cea5899fe9c Added missing __get_cs_or_redirect method for file history. Fixes issue with displaying a history of file that is not present at tip. diff -r 334ac2635e67 -r 267bb347d68c rhodecode/controllers/changelog.py --- a/rhodecode/controllers/changelog.py Thu Jun 13 01:33:08 2013 +0200 +++ b/rhodecode/controllers/changelog.py Sat Jun 15 14:37:51 2013 +0200 @@ -29,6 +29,7 @@ from pylons import request, url, session, tmpl_context as c from pylons.controllers.util import redirect from pylons.i18n.translation import _ +from webob.exc import HTTPNotFound, HTTPBadRequest import rhodecode.lib.helpers as h from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator @@ -39,7 +40,7 @@ from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ ChangesetError, NodeDoesNotExistError, EmptyRepositoryError from rhodecode.lib.utils2 import safe_int -from webob.exc import HTTPNotFound + log = logging.getLogger(__name__) @@ -68,6 +69,33 @@ super(ChangelogController, self).__before__() c.affected_files_cut_off = 60 + def __get_cs_or_redirect(self, rev, repo, redirect_after=True, + partial=False): + """ + Safe way to get changeset if error occur it redirects to changeset with + proper message. If partial is set then don't do redirect raise Exception + instead + + :param rev: revision to fetch + :param repo: repo instance + """ + + try: + return c.rhodecode_repo.get_changeset(rev) + except EmptyRepositoryError, e: + if not redirect_after: + return None + h.flash(h.literal(_('There are no changesets yet')), + category='warning') + redirect(url('changelog_home', repo_name=repo.repo_name)) + + except RepositoryError, e: + log.error(traceback.format_exc()) + h.flash(str(e), category='warning') + if not partial: + redirect(h.url('changelog_home', repo_name=repo.repo_name)) + raise HTTPBadRequest() + def _graph(self, repo, revs_int, repo_size, size, p): """ Generates a DAG graph for repo @@ -120,7 +148,7 @@ except (NodeDoesNotExistError, ChangesetError): #this node is not present at tip ! try: - cs = self.__get_cs_or_redirect(revision, repo_name) + cs = self.__get_css_or_redirect(revision, repo_name) collection = cs.get_file_history(f_path) except RepositoryError, e: h.flash(str(e), category='warning')