Show More
@@ -56,9 +56,11 b' class FilesController(BaseRepoController' | |||
|
56 | 56 | super(FilesController, self).__before__() |
|
57 | 57 | c.cut_off_limit = self.cut_off_limit |
|
58 | 58 | |
|
59 | def __get_cs(self, rev, repo_name): | |
|
59 | def __get_cs_or_redirect(self, rev, repo_name): | |
|
60 | 60 | """ |
|
61 |
Safe way to get changeset if error |
|
|
61 | Safe way to get changeset if error occur it redirects to tip with | |
|
62 | proper message | |
|
63 | ||
|
62 | 64 | :param rev: revision to fetch |
|
63 | 65 | :param repo_name: repo name to redirect after |
|
64 | 66 | """ |
@@ -74,69 +76,61 b' class FilesController(BaseRepoController' | |||
|
74 | 76 | redirect(h.url('files_home', repo_name=repo_name, revision='tip')) |
|
75 | 77 | |
|
76 | 78 | def index(self, repo_name, revision, f_path): |
|
79 | #reditect to given revision from form if given | |
|
80 | post_revision = request.POST.get('at_rev', None) | |
|
81 | if post_revision: | |
|
82 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
|
83 | redirect(url('files_home', repo_name=c.repo_name, | |
|
84 | revision=cs.raw_id, f_path=f_path)) | |
|
77 | 85 | |
|
78 | try: | |
|
79 | #reditect to given revision from form | |
|
80 | post_revision = request.POST.get('at_rev', None) | |
|
81 | if post_revision: | |
|
82 | post_revision = c.rhodecode_repo.get_changeset(post_revision).raw_id | |
|
83 | redirect(url('files_home', repo_name=c.repo_name, | |
|
84 | revision=post_revision, f_path=f_path)) | |
|
85 | 86 | |
|
86 | c.branch = request.GET.get('branch', None) | |
|
87 | c.changeset = self.__get_cs_or_redirect(revision, repo_name) | |
|
88 | c.branch = request.GET.get('branch', None) | |
|
89 | c.f_path = f_path | |
|
87 | 90 | |
|
88 | c.f_path = f_path | |
|
89 | ||
|
90 | c.changeset = c.rhodecode_repo.get_changeset(revision) | |
|
91 | cur_rev = c.changeset.revision | |
|
91 | cur_rev = c.changeset.revision | |
|
92 | 92 | |
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
93 | #prev link | |
|
94 | try: | |
|
95 | prev_rev = c.rhodecode_repo.get_changeset(cur_rev).prev(c.branch) | |
|
96 | c.url_prev = url('files_home', repo_name=c.repo_name, | |
|
97 | revision=prev_rev.raw_id, f_path=f_path) | |
|
98 | if c.branch: | |
|
99 | c.url_prev += '?branch=%s' % c.branch | |
|
100 | except (ChangesetDoesNotExistError, VCSError): | |
|
101 | c.url_prev = '#' | |
|
102 | 102 | |
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
103 | #next link | |
|
104 | try: | |
|
105 | next_rev = c.rhodecode_repo.get_changeset(cur_rev).next(c.branch) | |
|
106 | c.url_next = url('files_home', repo_name=c.repo_name, | |
|
107 | revision=next_rev.raw_id, f_path=f_path) | |
|
108 | if c.branch: | |
|
109 | c.url_next += '?branch=%s' % c.branch | |
|
110 | except (ChangesetDoesNotExistError, VCSError): | |
|
111 | c.url_next = '#' | |
|
112 | 112 | |
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 | except RepositoryError, e: | |
|
118 | h.flash(str(e), category='warning') | |
|
119 | redirect(h.url('files_home', repo_name=repo_name, revision=revision)) | |
|
120 | ||
|
121 | except EmptyRepositoryError, e: | |
|
122 | h.flash(_('There are no files yet'), category='warning') | |
|
123 | redirect(h.url('summary_home', repo_name=repo_name)) | |
|
124 | ||
|
113 | #files | |
|
114 | try: | |
|
115 | c.files_list = c.changeset.get_node(f_path) | |
|
116 | c.file_history = self._get_history(c.rhodecode_repo, | |
|
117 | c.files_list, f_path) | |
|
125 | 118 | except RepositoryError, e: |
|
126 | 119 | h.flash(str(e), category='warning') |
|
127 |
redirect(h.url('files_home', repo_name=repo_name, |
|
|
128 | ||
|
120 | redirect(h.url('files_home', repo_name=repo_name, | |
|
121 | revision=revision)) | |
|
129 | 122 | |
|
130 | 123 | |
|
131 | 124 | return render('files/files.html') |
|
132 | 125 | |
|
133 | 126 | def rawfile(self, repo_name, revision, f_path): |
|
134 | cs = self.__get_cs(revision, repo_name) | |
|
127 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
|
135 | 128 | try: |
|
136 | 129 | file_node = cs.get_node(f_path) |
|
137 | 130 | except RepositoryError, e: |
|
138 | 131 | h.flash(str(e), category='warning') |
|
139 |
redirect(h.url('files_home', repo_name=repo_name, |
|
|
132 | redirect(h.url('files_home', repo_name=repo_name, | |
|
133 | revision=cs.raw_id)) | |
|
140 | 134 | |
|
141 | 135 | fname = f_path.split('/')[-1].encode('utf8', 'replace') |
|
142 | 136 | response.content_type = file_node.mimetype |
@@ -144,26 +138,29 b' class FilesController(BaseRepoController' | |||
|
144 | 138 | return file_node.content |
|
145 | 139 | |
|
146 | 140 | def raw(self, repo_name, revision, f_path): |
|
147 | cs = self.__get_cs(revision, repo_name) | |
|
141 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
|
148 | 142 | try: |
|
149 | 143 | file_node = cs.get_node(f_path) |
|
150 | 144 | except RepositoryError, e: |
|
151 | 145 | h.flash(str(e), category='warning') |
|
152 |
redirect(h.url('files_home', repo_name=repo_name, |
|
|
146 | redirect(h.url('files_home', repo_name=repo_name, | |
|
147 | revision=cs.raw_id)) | |
|
153 | 148 | |
|
154 | 149 | response.content_type = 'text/plain' |
|
155 | 150 | |
|
156 | 151 | return file_node.content |
|
157 | 152 | |
|
158 | 153 | def annotate(self, repo_name, revision, f_path): |
|
159 | cs = self.__get_cs(revision, repo_name) | |
|
154 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
|
160 | 155 | try: |
|
161 | 156 | c.file = cs.get_node(f_path) |
|
162 | 157 | except RepositoryError, e: |
|
163 | 158 | h.flash(str(e), category='warning') |
|
164 |
redirect(h.url('files_home', repo_name=repo_name, |
|
|
159 | redirect(h.url('files_home', repo_name=repo_name, | |
|
160 | revision=cs.raw_id)) | |
|
165 | 161 | |
|
166 |
c.file_history = self._get_history(c.rhodecode_repo, |
|
|
162 | c.file_history = self._get_history(c.rhodecode_repo, | |
|
163 | c.file, f_path) | |
|
167 | 164 | c.cs = cs |
|
168 | 165 | c.f_path = f_path |
|
169 | 166 |
General Comments 0
You need to be logged in to leave comments.
Login now