Mercurial > kallithea
comparison rhodecode/controllers/changelog.py @ 3996:267bb347d68c
Added missing __get_cs_or_redirect method for file history.
Fixes issue with displaying a history of file that is not present at tip.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 15 Jun 2013 14:37:51 +0200 |
parents | 5293d4bbb1ea |
children | 218ed589e44a |
comparison
equal
deleted
inserted
replaced
3995:334ac2635e67 | 3996:267bb347d68c |
---|---|
27 import traceback | 27 import traceback |
28 | 28 |
29 from pylons import request, url, session, tmpl_context as c | 29 from pylons import request, url, session, tmpl_context as c |
30 from pylons.controllers.util import redirect | 30 from pylons.controllers.util import redirect |
31 from pylons.i18n.translation import _ | 31 from pylons.i18n.translation import _ |
32 from webob.exc import HTTPNotFound, HTTPBadRequest | |
32 | 33 |
33 import rhodecode.lib.helpers as h | 34 import rhodecode.lib.helpers as h |
34 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | 35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
35 from rhodecode.lib.base import BaseRepoController, render | 36 from rhodecode.lib.base import BaseRepoController, render |
36 from rhodecode.lib.helpers import RepoPage | 37 from rhodecode.lib.helpers import RepoPage |
37 from rhodecode.lib.compat import json | 38 from rhodecode.lib.compat import json |
38 from rhodecode.lib.graphmod import _colored, _dagwalker | 39 from rhodecode.lib.graphmod import _colored, _dagwalker |
39 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ | 40 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ |
40 ChangesetError, NodeDoesNotExistError, EmptyRepositoryError | 41 ChangesetError, NodeDoesNotExistError, EmptyRepositoryError |
41 from rhodecode.lib.utils2 import safe_int | 42 from rhodecode.lib.utils2 import safe_int |
42 from webob.exc import HTTPNotFound | 43 |
43 | 44 |
44 log = logging.getLogger(__name__) | 45 log = logging.getLogger(__name__) |
45 | 46 |
46 | 47 |
47 def _load_changelog_summary(): | 48 def _load_changelog_summary(): |
65 class ChangelogController(BaseRepoController): | 66 class ChangelogController(BaseRepoController): |
66 | 67 |
67 def __before__(self): | 68 def __before__(self): |
68 super(ChangelogController, self).__before__() | 69 super(ChangelogController, self).__before__() |
69 c.affected_files_cut_off = 60 | 70 c.affected_files_cut_off = 60 |
71 | |
72 def __get_cs_or_redirect(self, rev, repo, redirect_after=True, | |
73 partial=False): | |
74 """ | |
75 Safe way to get changeset if error occur it redirects to changeset with | |
76 proper message. If partial is set then don't do redirect raise Exception | |
77 instead | |
78 | |
79 :param rev: revision to fetch | |
80 :param repo: repo instance | |
81 """ | |
82 | |
83 try: | |
84 return c.rhodecode_repo.get_changeset(rev) | |
85 except EmptyRepositoryError, e: | |
86 if not redirect_after: | |
87 return None | |
88 h.flash(h.literal(_('There are no changesets yet')), | |
89 category='warning') | |
90 redirect(url('changelog_home', repo_name=repo.repo_name)) | |
91 | |
92 except RepositoryError, e: | |
93 log.error(traceback.format_exc()) | |
94 h.flash(str(e), category='warning') | |
95 if not partial: | |
96 redirect(h.url('changelog_home', repo_name=repo.repo_name)) | |
97 raise HTTPBadRequest() | |
70 | 98 |
71 def _graph(self, repo, revs_int, repo_size, size, p): | 99 def _graph(self, repo, revs_int, repo_size, size, p): |
72 """ | 100 """ |
73 Generates a DAG graph for repo | 101 Generates a DAG graph for repo |
74 | 102 |
118 try: | 146 try: |
119 collection = tip_cs.get_file_history(f_path) | 147 collection = tip_cs.get_file_history(f_path) |
120 except (NodeDoesNotExistError, ChangesetError): | 148 except (NodeDoesNotExistError, ChangesetError): |
121 #this node is not present at tip ! | 149 #this node is not present at tip ! |
122 try: | 150 try: |
123 cs = self.__get_cs_or_redirect(revision, repo_name) | 151 cs = self.__get_css_or_redirect(revision, repo_name) |
124 collection = cs.get_file_history(f_path) | 152 collection = cs.get_file_history(f_path) |
125 except RepositoryError, e: | 153 except RepositoryError, e: |
126 h.flash(str(e), category='warning') | 154 h.flash(str(e), category='warning') |
127 redirect(h.url('changelog_home', repo_name=repo_name)) | 155 redirect(h.url('changelog_home', repo_name=repo_name)) |
128 collection = list(reversed(collection)) | 156 collection = list(reversed(collection)) |