##// END OF EJS Templates
disabled edition of binary files
marcink -
r1313:856be614 beta
parent child Browse files
Show More
@@ -1,410 +1,414 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.files
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 Files controller for RhodeCode
7 7
8 8 :created_on: Apr 21, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import os
27 27 import logging
28 28 import mimetypes
29 29 import traceback
30 30
31 31 from pylons import request, response, session, tmpl_context as c, url
32 32 from pylons.i18n.translation import _
33 33 from pylons.controllers.util import redirect
34 34
35 35 from vcs.backends import ARCHIVE_SPECS
36 36 from vcs.exceptions import RepositoryError, ChangesetDoesNotExistError, \
37 37 EmptyRepositoryError, ImproperArchiveTypeError, VCSError
38 38 from vcs.nodes import FileNode, NodeKind
39 39 from vcs.utils import diffs as differ
40 40
41 41 from rhodecode.lib import convert_line_endings, detect_mode
42 42 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
43 43 from rhodecode.lib.base import BaseRepoController, render
44 44 from rhodecode.lib.utils import EmptyChangeset
45 45 import rhodecode.lib.helpers as h
46 46 from rhodecode.model.repo import RepoModel
47 47
48 48 log = logging.getLogger(__name__)
49 49
50 50
51 51 class FilesController(BaseRepoController):
52 52
53 53 @LoginRequired()
54 54 def __before__(self):
55 55 super(FilesController, self).__before__()
56 56 c.cut_off_limit = self.cut_off_limit
57 57
58 58 def __get_cs_or_redirect(self, rev, repo_name):
59 59 """
60 60 Safe way to get changeset if error occur it redirects to tip with
61 61 proper message
62 62
63 63 :param rev: revision to fetch
64 64 :param repo_name: repo name to redirect after
65 65 """
66 66
67 67 try:
68 68 return c.rhodecode_repo.get_changeset(rev)
69 69 except EmptyRepositoryError, e:
70 70 h.flash(_('There are no files yet'), category='warning')
71 71 redirect(h.url('summary_home', repo_name=repo_name))
72 72
73 73 except RepositoryError, e:
74 74 h.flash(str(e), category='warning')
75 75 redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
76 76
77 77 def __get_filenode_or_redirect(self, repo_name, cs, path):
78 78 """
79 79 Returns file_node, if error occurs or given path is directory,
80 80 it'll redirect to top level path
81 81
82 82 :param repo_name: repo_name
83 83 :param cs: given changeset
84 84 :param path: path to lookup
85 85 """
86 86
87 87 try:
88 88 file_node = cs.get_node(path)
89 89 if file_node.is_dir():
90 90 raise RepositoryError('given path is a directory')
91 91 except RepositoryError, e:
92 92 h.flash(str(e), category='warning')
93 93 redirect(h.url('files_home', repo_name=repo_name,
94 94 revision=cs.raw_id))
95 95
96 96 return file_node
97 97
98 98 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
99 99 'repository.admin')
100 100 def index(self, repo_name, revision, f_path):
101 101 #reditect to given revision from form if given
102 102 post_revision = request.POST.get('at_rev', None)
103 103 if post_revision:
104 104 cs = self.__get_cs_or_redirect(post_revision, repo_name)
105 105 redirect(url('files_home', repo_name=c.repo_name,
106 106 revision=cs.raw_id, f_path=f_path))
107 107
108 108 c.changeset = self.__get_cs_or_redirect(revision, repo_name)
109 109 c.branch = request.GET.get('branch', None)
110 110 c.f_path = f_path
111 111
112 112 cur_rev = c.changeset.revision
113 113
114 114 #prev link
115 115 try:
116 116 prev_rev = c.rhodecode_repo.get_changeset(cur_rev).prev(c.branch)
117 117 c.url_prev = url('files_home', repo_name=c.repo_name,
118 118 revision=prev_rev.raw_id, f_path=f_path)
119 119 if c.branch:
120 120 c.url_prev += '?branch=%s' % c.branch
121 121 except (ChangesetDoesNotExistError, VCSError):
122 122 c.url_prev = '#'
123 123
124 124 #next link
125 125 try:
126 126 next_rev = c.rhodecode_repo.get_changeset(cur_rev).next(c.branch)
127 127 c.url_next = url('files_home', repo_name=c.repo_name,
128 128 revision=next_rev.raw_id, f_path=f_path)
129 129 if c.branch:
130 130 c.url_next += '?branch=%s' % c.branch
131 131 except (ChangesetDoesNotExistError, VCSError):
132 132 c.url_next = '#'
133 133
134 134 #files or dirs
135 135 try:
136 136 c.files_list = c.changeset.get_node(f_path)
137 137
138 138 if c.files_list.is_file():
139 139 c.file_history = self._get_node_history(c.changeset, f_path)
140 140 else:
141 141 c.file_history = []
142 142 except RepositoryError, e:
143 143 h.flash(str(e), category='warning')
144 144 redirect(h.url('files_home', repo_name=repo_name,
145 145 revision=revision))
146 146
147 147 return render('files/files.html')
148 148
149 149 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
150 150 'repository.admin')
151 151 def rawfile(self, repo_name, revision, f_path):
152 152 cs = self.__get_cs_or_redirect(revision, repo_name)
153 153 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
154 154
155 155 response.content_disposition = 'attachment; filename=%s' % \
156 156 f_path.split(os.sep)[-1].encode('utf8', 'replace')
157 157
158 158 response.content_type = file_node.mimetype
159 159 return file_node.content
160 160
161 161 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
162 162 'repository.admin')
163 163 def raw(self, repo_name, revision, f_path):
164 164 cs = self.__get_cs_or_redirect(revision, repo_name)
165 165 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
166 166
167 167 raw_mimetype_mapping = {
168 168 # map original mimetype to a mimetype used for "show as raw"
169 169 # you can also provide a content-disposition to override the
170 170 # default "attachment" disposition.
171 171 # orig_type: (new_type, new_dispo)
172 172
173 173 # show images inline:
174 174 'image/x-icon': ('image/x-icon', 'inline'),
175 175 'image/png': ('image/png', 'inline'),
176 176 'image/gif': ('image/gif', 'inline'),
177 177 'image/jpeg': ('image/jpeg', 'inline'),
178 178 'image/svg+xml': ('image/svg+xml', 'inline'),
179 179 }
180 180
181 181 mimetype = file_node.mimetype
182 182 try:
183 183 mimetype, dispo = raw_mimetype_mapping[mimetype]
184 184 except KeyError:
185 185 # we don't know anything special about this, handle it safely
186 186 if file_node.is_binary:
187 187 # do same as download raw for binary files
188 188 mimetype, dispo = 'application/octet-stream', 'attachment'
189 189 else:
190 190 # do not just use the original mimetype, but force text/plain,
191 191 # otherwise it would serve text/html and that might be unsafe.
192 192 # Note: underlying vcs library fakes text/plain mimetype if the
193 193 # mimetype can not be determined and it thinks it is not
194 194 # binary.This might lead to erroneous text display in some
195 195 # cases, but helps in other cases, like with text files
196 196 # without extension.
197 197 mimetype, dispo = 'text/plain', 'inline'
198 198
199 199 if dispo == 'attachment':
200 200 dispo = 'attachment; filename=%s' % \
201 201 f_path.split(os.sep)[-1].encode('utf8', 'replace')
202 202
203 203 response.content_disposition = dispo
204 204 response.content_type = mimetype
205 205 return file_node.content
206 206
207 207 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
208 208 'repository.admin')
209 209 def annotate(self, repo_name, revision, f_path):
210 210 c.cs = self.__get_cs_or_redirect(revision, repo_name)
211 211 c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path)
212 212
213 213 c.file_history = self._get_node_history(c.cs, f_path)
214 214 c.f_path = f_path
215 215 return render('files/files_annotate.html')
216 216
217 217 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')
218 218 def edit(self, repo_name, revision, f_path):
219 219 r_post = request.POST
220 220
221 221 c.cs = self.__get_cs_or_redirect(revision, repo_name)
222 222 c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path)
223 223
224 if c.file.is_binary:
225 return redirect(url('files_home', repo_name=c.repo_name,
226 revision=c.cs.raw_id, f_path=f_path))
227
224 228 c.file_history = self._get_node_history(c.cs, f_path)
225 229 c.f_path = f_path
226 230
227 231 if r_post:
228 232
229 233 old_content = c.file.content
230 234 sl = old_content.splitlines(1)
231 235 first_line = sl[0] if sl else ''
232 236 # modes: 0 - Unix, 1 - Mac, 2 - DOS
233 237 mode = detect_mode(first_line, 0)
234 238 content = convert_line_endings(r_post.get('content'), mode)
235 239
236 240 message = r_post.get('message') or (_('Edited %s via RhodeCode')
237 241 % (f_path))
238 242 author = self.rhodecode_user.full_contact
239 243
240 244 if content == old_content:
241 245 h.flash(_('No changes'),
242 246 category='warning')
243 247 return redirect(url('changeset_home', repo_name=c.repo_name,
244 248 revision='tip'))
245 249
246 250 try:
247 251 self.scm_model.commit_change(repo=c.rhodecode_repo,
248 252 repo_name=repo_name, cs=c.cs,
249 253 user=self.rhodecode_user,
250 254 author=author, message=message,
251 255 content=content, f_path=f_path)
252 256 h.flash(_('Successfully committed to %s' % f_path),
253 257 category='success')
254 258
255 259 except Exception:
256 260 log.error(traceback.format_exc())
257 261 h.flash(_('Error occurred during commit'), category='error')
258 262 return redirect(url('changeset_home',
259 263 repo_name=c.repo_name, revision='tip'))
260 264
261 265 return render('files/files_edit.html')
262 266
263 267 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
264 268 'repository.admin')
265 269 def archivefile(self, repo_name, fname):
266 270
267 271 fileformat = None
268 272 revision = None
269 273 ext = None
270 274
271 275 for a_type, ext_data in ARCHIVE_SPECS.items():
272 276 archive_spec = fname.split(ext_data[1])
273 277 if len(archive_spec) == 2 and archive_spec[1] == '':
274 278 fileformat = a_type or ext_data[1]
275 279 revision = archive_spec[0]
276 280 ext = ext_data[1]
277 281
278 282 try:
279 283 dbrepo = RepoModel().get_by_repo_name(repo_name)
280 284 if dbrepo.enable_downloads is False:
281 285 return _('downloads disabled')
282 286
283 287 cs = c.rhodecode_repo.get_changeset(revision)
284 288 content_type = ARCHIVE_SPECS[fileformat][0]
285 289 except ChangesetDoesNotExistError:
286 290 return _('Unknown revision %s') % revision
287 291 except EmptyRepositoryError:
288 292 return _('Empty repository')
289 293 except (ImproperArchiveTypeError, KeyError):
290 294 return _('Unknown archive type')
291 295
292 296 response.content_type = content_type
293 297 response.content_disposition = 'attachment; filename=%s-%s%s' \
294 298 % (repo_name, revision, ext)
295 299
296 300 import tempfile
297 301 archive = tempfile.mkstemp()[1]
298 302 t = open(archive, 'wb')
299 303 cs.fill_archive(stream=t, kind=fileformat)
300 304
301 305 def get_chunked_archive(archive):
302 306 stream = open(archive, 'rb')
303 307 while True:
304 308 data = stream.read(4096)
305 309 if not data:
306 310 os.remove(archive)
307 311 break
308 312 yield data
309 313
310 314 return get_chunked_archive(archive)
311 315
312 316 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
313 317 'repository.admin')
314 318 def diff(self, repo_name, f_path):
315 319 diff1 = request.GET.get('diff1')
316 320 diff2 = request.GET.get('diff2')
317 321 c.action = request.GET.get('diff')
318 322 c.no_changes = diff1 == diff2
319 323 c.f_path = f_path
320 324 c.big_diff = False
321 325
322 326 try:
323 327 if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]:
324 328 c.changeset_1 = c.rhodecode_repo.get_changeset(diff1)
325 329 node1 = c.changeset_1.get_node(f_path)
326 330 else:
327 331 c.changeset_1 = EmptyChangeset(repo=c.rhodecode_repo)
328 332 node1 = FileNode('.', '', changeset=c.changeset_1)
329 333
330 334 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]:
331 335 c.changeset_2 = c.rhodecode_repo.get_changeset(diff2)
332 336 node2 = c.changeset_2.get_node(f_path)
333 337 else:
334 338 c.changeset_2 = EmptyChangeset(repo=c.rhodecode_repo)
335 339 node2 = FileNode('.', '', changeset=c.changeset_2)
336 340 except RepositoryError:
337 341 return redirect(url('files_home',
338 342 repo_name=c.repo_name, f_path=f_path))
339 343
340 344 if c.action == 'download':
341 345 diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2),
342 346 format='gitdiff')
343 347
344 348 diff_name = '%s_vs_%s.diff' % (diff1, diff2)
345 349 response.content_type = 'text/plain'
346 350 response.content_disposition = 'attachment; filename=%s' \
347 351 % diff_name
348 352 return diff.raw_diff()
349 353
350 354 elif c.action == 'raw':
351 355 diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2),
352 356 format='gitdiff')
353 357 response.content_type = 'text/plain'
354 358 return diff.raw_diff()
355 359
356 360 elif c.action == 'diff':
357 361 if node1.is_binary or node2.is_binary:
358 362 c.cur_diff = _('Binary file')
359 363 elif node1.size > self.cut_off_limit or \
360 364 node2.size > self.cut_off_limit:
361 365 c.cur_diff = ''
362 366 c.big_diff = True
363 367 else:
364 368 diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2),
365 369 format='gitdiff')
366 370 c.cur_diff = diff.as_html()
367 371 else:
368 372
369 373 #default option
370 374 if node1.is_binary or node2.is_binary:
371 375 c.cur_diff = _('Binary file')
372 376 elif node1.size > self.cut_off_limit or \
373 377 node2.size > self.cut_off_limit:
374 378 c.cur_diff = ''
375 379 c.big_diff = True
376 380
377 381 else:
378 382 diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2),
379 383 format='gitdiff')
380 384 c.cur_diff = diff.as_html()
381 385
382 386 if not c.cur_diff and not c.big_diff:
383 387 c.no_changes = True
384 388 return render('files/file_diff.html')
385 389
386 390 def _get_node_history(self, cs, f_path):
387 391 changesets = cs.get_file_history(f_path)
388 392 hist_l = []
389 393
390 394 changesets_group = ([], _("Changesets"))
391 395 branches_group = ([], _("Branches"))
392 396 tags_group = ([], _("Tags"))
393 397
394 398 for chs in changesets:
395 399 n_desc = 'r%s:%s' % (chs.revision, chs.short_id)
396 400 changesets_group[0].append((chs.raw_id, n_desc,))
397 401
398 402 hist_l.append(changesets_group)
399 403
400 404 for name, chs in c.rhodecode_repo.branches.items():
401 405 #chs = chs.split(':')[-1]
402 406 branches_group[0].append((chs, name),)
403 407 hist_l.append(branches_group)
404 408
405 409 for name, chs in c.rhodecode_repo.tags.items():
406 410 #chs = chs.split(':')[-1]
407 411 tags_group[0].append((chs, name),)
408 412 hist_l.append(tags_group)
409 413
410 414 return hist_l
@@ -1,95 +1,97 b''
1 1 <%inherit file="/base/base.html"/>
2 2
3 3 <%def name="title()">
4 4 ${c.repo_name} ${_('File annotate')} - ${c.rhodecode_name}
5 5 </%def>
6 6
7 7 <%def name="breadcrumbs_links()">
8 8 ${h.link_to(u'Home',h.url('/'))}
9 9 &raquo;
10 10 ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))}
11 11 &raquo;
12 12 ${_('annotate')} @ R${c.cs.revision}:${h.short_id(c.cs.raw_id)}
13 13 </%def>
14 14
15 15 <%def name="page_nav()">
16 16 ${self.menu('files')}
17 17 </%def>
18 18 <%def name="main()">
19 19 <div class="box">
20 20 <!-- box / title -->
21 21 <div class="title">
22 22 ${self.breadcrumbs()}
23 23 <ul class="links">
24 24 <li>
25 25 <span style="text-transform: uppercase;"><a href="#">${_('branch')}: ${c.cs.branch}</a></span>
26 26 </li>
27 27 </ul>
28 28 </div>
29 29 <div class="table">
30 30 <div id="files_data">
31 31 <h3 class="files_location">${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.cs.revision,c.file.path)}</h3>
32 32 <dl class="overview">
33 33 <dt>${_('Revision')}</dt>
34 34 <dd>${h.link_to("r%s:%s" % (c.file.last_changeset.revision,h.short_id(c.file.last_changeset.raw_id)),
35 35 h.url('changeset_home',repo_name=c.repo_name,revision=c.file.last_changeset.raw_id))} </dd>
36 36 <dt>${_('Size')}</dt>
37 37 <dd>${h.format_byte_size(c.file.size,binary=True)}</dd>
38 38 <dt>${_('Mimetype')}</dt>
39 39 <dd>${c.file.mimetype}</dd>
40 40 <dt>${_('Options')}</dt>
41 41 <dd>${h.link_to(_('show source'),
42 42 h.url('files_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path))}
43 43 / ${h.link_to(_('show as raw'),
44 44 h.url('files_raw_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path))}
45 45 / ${h.link_to(_('download as raw'),
46 46 h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path))}
47 % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
47 % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
48 % if not c.file.is_binary:
48 49 / ${h.link_to(_('edit'),
49 50 h.url('files_edit_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path))}
51 % endif
50 52 % endif
51 53 </dd>
52 54 <dt>${_('History')}</dt>
53 55 <dd>
54 56 <div>
55 57 ${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='get')}
56 58 ${h.hidden('diff2',c.file.last_changeset.raw_id)}
57 59 ${h.select('diff1',c.file.last_changeset.raw_id,c.file_history)}
58 60 ${h.submit('diff','diff to revision',class_="ui-button-small")}
59 61 ${h.submit('show_rev','show at revision',class_="ui-button-small")}
60 62 ${h.end_form()}
61 63 </div>
62 64 </dd>
63 65 </dl>
64 66 <div id="body" class="codeblock">
65 67 <div class="code-header">
66 68 <div class="revision">${c.file.name}@r${c.file.last_changeset.revision}:${h.short_id(c.file.last_changeset.raw_id)}</div>
67 69 <div class="commit">"${c.file.message}"</div>
68 70 </div>
69 71 <div class="code-body">
70 72 %if c.file.is_binary:
71 73 ${_('Binary file (%s)') % c.file.mimetype}
72 74 %else:
73 75 % if c.file.size < c.cut_off_limit:
74 76 ${h.pygmentize_annotation(c.repo_name,c.file,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
75 77 %else:
76 78 ${_('File is to big to display')} ${h.link_to(_('show as raw'),
77 79 h.url('files_raw_home',repo_name=c.repo_name,revision=c.cs.revision,f_path=c.f_path))}
78 80 %endif
79 81 <script type="text/javascript">
80 82 YAHOO.util.Event.onDOMReady(function(){
81 83 YAHOO.util.Event.addListener('show_rev','click',function(e){
82 84 YAHOO.util.Event.preventDefault(e);
83 85 var cs = YAHOO.util.Dom.get('diff1').value;
84 86 var url = "${h.url('files_annotate_home',repo_name=c.repo_name,revision='__CS__',f_path=c.f_path)}".replace('__CS__',cs);
85 87 window.location = url;
86 88 });
87 89 });
88 90 </script>
89 91 %endif
90 92 </div>
91 93 </div>
92 94 </div>
93 95 </div>
94 96 </div>
95 97 </%def> No newline at end of file
@@ -1,95 +1,97 b''
1 1 <dl>
2 2 <dt>${_('Revision')}</dt>
3 3 <dd>
4 4 ${h.link_to("r%s:%s" % (c.files_list.last_changeset.revision,h.short_id(c.files_list.last_changeset.raw_id)),
5 5 h.url('changeset_home',repo_name=c.repo_name,revision=c.files_list.last_changeset.raw_id))}
6 6 </dd>
7 7 <dt>${_('Size')}</dt>
8 8 <dd>${h.format_byte_size(c.files_list.size,binary=True)}</dd>
9 9 <dt>${_('Mimetype')}</dt>
10 10 <dd>${c.files_list.mimetype}</dd>
11 11 <dt>${_('Options')}</dt>
12 12 <dd>${h.link_to(_('show annotation'),
13 13 h.url('files_annotate_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.f_path))}
14 14 / ${h.link_to(_('show as raw'),
15 15 h.url('files_raw_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.f_path))}
16 16 / ${h.link_to(_('download as raw'),
17 17 h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.f_path))}
18 18 % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
19 % if not c.files_list.is_binary:
19 20 / ${h.link_to(_('edit'),
20 21 h.url('files_edit_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.f_path))}
22 % endif
21 23 % endif
22 24 </dd>
23 25 <dt>${_('History')}</dt>
24 26 <dd>
25 27 <div>
26 28 ${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='get')}
27 29 ${h.hidden('diff2',c.files_list.last_changeset.raw_id)}
28 30 ${h.select('diff1',c.files_list.last_changeset.raw_id,c.file_history)}
29 31 ${h.submit('diff','diff to revision',class_="ui-button-small")}
30 32 ${h.submit('show_rev','show at revision',class_="ui-button-small")}
31 33 ${h.end_form()}
32 34 </div>
33 35 </dd>
34 36 </dl>
35 37
36 38
37 39 <div id="body" class="codeblock">
38 40 <div class="code-header">
39 41 <div class="revision">${c.files_list.name}@r${c.files_list.last_changeset.revision}:${h.short_id(c.files_list.last_changeset.raw_id)}</div>
40 42 <div class="commit">"${c.files_list.last_changeset.message}"</div>
41 43 </div>
42 44 <div class="code-body">
43 45 %if c.files_list.is_binary:
44 46 ${_('Binary file (%s)') % c.files_list.mimetype}
45 47 %else:
46 48 % if c.files_list.size < c.cut_off_limit:
47 49 ${h.pygmentize(c.files_list,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")}
48 50 %else:
49 51 ${_('File is to big to display')} ${h.link_to(_('show as raw'),
50 52 h.url('files_raw_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.f_path))}
51 53 %endif
52 54
53 55 <script type="text/javascript">
54 56 function highlight_lines(lines){
55 57 for(pos in lines){
56 58 YUD.setStyle('L'+lines[pos],'background-color','#FFFFBE');
57 59 }
58 60 }
59 61 page_highlights = location.href.substring(location.href.indexOf('#')+1).split('L');
60 62 if (page_highlights.length == 2){
61 63 highlight_ranges = page_highlights[1].split(",");
62 64
63 65 var h_lines = [];
64 66 for (pos in highlight_ranges){
65 67 var _range = highlight_ranges[pos].split('-');
66 68 if(_range.length == 2){
67 69 var start = parseInt(_range[0]);
68 70 var end = parseInt(_range[1]);
69 71 if (start < end){
70 72 for(var i=start;i<=end;i++){
71 73 h_lines.push(i);
72 74 }
73 75 }
74 76 }
75 77 else{
76 78 h_lines.push(parseInt(highlight_ranges[pos]));
77 79 }
78 80 }
79 81 highlight_lines(h_lines);
80 82 }
81 83 </script>
82 84 %endif
83 85 </div>
84 86 </div>
85 87
86 88 <script type="text/javascript">
87 89 YAHOO.util.Event.onDOMReady(function(){
88 90 YAHOO.util.Event.addListener('show_rev','click',function(e){
89 91 YAHOO.util.Event.preventDefault(e);
90 92 var cs = YAHOO.util.Dom.get('diff1').value;
91 93 var url = "${h.url('files_home',repo_name=c.repo_name,revision='__CS__',f_path=c.f_path)}".replace('__CS__',cs);
92 94 window.location = url;
93 95 });
94 96 });
95 97 </script> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now