##// END OF EJS Templates
files: use a common function to handle url-by-refs, and fix landing refs for SVN....
marcink -
r4373:702c378c stable
parent child Browse files
Show More
@@ -531,8 +531,6 b' class BaseReferencesView(RepoAppView):'
531 531 """
532 532 def load_default_context(self):
533 533 c = self._get_local_tmpl_context()
534
535
536 534 return c
537 535
538 536 def load_refs_context(self, ref_items, partials_template):
@@ -562,7 +560,9 b' class BaseReferencesView(RepoAppView):'
562 560 'repo_files',
563 561 repo_name=self.db_repo_name,
564 562 f_path=ref_name if is_svn else '',
565 commit_id=commit_id)
563 commit_id=commit_id,
564 _query=dict(at=ref_name)
565 )
566 566
567 567 else:
568 568 files_url = h.route_path(
@@ -570,7 +570,8 b' class BaseReferencesView(RepoAppView):'
570 570 repo_name=self.db_repo_name,
571 571 f_path=ref_name if is_svn else '',
572 572 commit_id=ref_name,
573 _query=dict(at=ref_name))
573 _query=dict(at=ref_name)
574 )
574 575
575 576 data.append({
576 577 "name": _render('name', ref_name, files_url, closed),
@@ -594,11 +594,15 b' class RepoFilesView(RepoAppView):'
594 594 renderer=None)
595 595 def repo_files_default(self):
596 596 c = self.load_default_context()
597
598 landing_url = h.route_path(
599 'repo_files', repo_name=c.repo_name,
600 commit_id=c.rhodecode_db_repo.landing_ref_name, f_path='',
601 _query={'at': c.rhodecode_db_repo.landing_ref_name})
597 ref_name = c.rhodecode_db_repo.landing_ref_name
598 landing_url = h.repo_files_by_ref_url(
599 c.rhodecode_db_repo.repo_name,
600 c.rhodecode_db_repo.repo_type,
601 f_path='',
602 ref_name=ref_name,
603 commit_id='tip',
604 query=dict(at=ref_name)
605 )
602 606
603 607 raise HTTPFound(landing_url)
604 608
@@ -256,29 +256,34 b' tooltip = _ToolTip()'
256 256 files_icon = u'<i class="file-breadcrumb-copy tooltip icon-clipboard clipboard-action" data-clipboard-text="{}" title="Copy file path"></i>'
257 257
258 258
259 def files_breadcrumbs(repo_name, commit_id, file_path, landing_ref_name=None, at_ref=None,
260 limit_items=False, linkify_last_item=False, hide_last_item=False, copy_path_icon=True):
259 def files_breadcrumbs(repo_name, repo_type, commit_id, file_path, landing_ref_name=None, at_ref=None,
260 limit_items=False, linkify_last_item=False, hide_last_item=False,
261 copy_path_icon=True):
261 262 if isinstance(file_path, str):
262 263 file_path = safe_unicode(file_path)
263 264
264 265 if at_ref:
265 266 route_qry = {'at': at_ref}
266 default_commit_id = at_ref or landing_ref_name or commit_id
267 default_landing_ref = at_ref or landing_ref_name or commit_id
267 268 else:
268 269 route_qry = None
269 default_commit_id = commit_id
270 default_landing_ref = commit_id
270 271
271 # first segment is a `..` link to repo files
272 # first segment is a `HOME` link to repo files root location
272 273 root_name = literal(u'<i class="icon-home"></i>')
274
273 275 url_segments = [
274 276 link_to(
275 277 root_name,
276 route_path(
277 'repo_files',
278 repo_name=repo_name,
279 commit_id=default_commit_id,
280 f_path='',
281 _query=route_qry),
278 repo_files_by_ref_url(
279 repo_name,
280 repo_type,
281 f_path=None, # None here is a special case for SVN repos,
282 # that won't prefix with a ref
283 ref_name=default_landing_ref,
284 commit_id=commit_id,
285 query=route_qry
286 )
282 287 )]
283 288
284 289 path_segments = file_path.split('/')
@@ -301,12 +306,14 b' def files_breadcrumbs(repo_name, commit_'
301 306 url_segments.append(
302 307 link_to(
303 308 segment_html,
304 route_path(
305 'repo_files',
306 repo_name=repo_name,
307 commit_id=default_commit_id,
309 repo_files_by_ref_url(
310 repo_name,
311 repo_type,
308 312 f_path='/'.join(path_segments[:cnt + 1]),
309 _query=route_qry),
313 ref_name=default_landing_ref,
314 commit_id=commit_id,
315 query=route_qry
316 ),
310 317 ))
311 318
312 319 limited_url_segments = url_segments[:1] + ['...'] + url_segments[-5:]
@@ -337,6 +344,54 b' def files_url_data(request):'
337 344 return json.dumps(matchdict)
338 345
339 346
347 def repo_files_by_ref_url(db_repo_name, db_repo_type, f_path, ref_name, commit_id, query=None, ):
348 _is_svn = is_svn(db_repo_type)
349 final_f_path = f_path
350
351 if _is_svn:
352 """
353 For SVN the ref_name cannot be used as a commit_id, it needs to be prefixed with
354 actually commit_id followed by the ref_name. This should be done only in case
355 This is a initial landing url, without additional paths.
356
357 like: /1000/tags/1.0.0/?at=tags/1.0.0
358 """
359
360 if ref_name and ref_name != 'tip':
361 # NOTE(marcink): for svn the ref_name is actually the stored path, so we prefix it
362 # for SVN we only do this magic prefix if it's root, .eg landing revision
363 # of files link. If we are in the tree we don't need this since we traverse the url
364 # that has everything stored
365 if f_path in ['', '/']:
366 final_f_path = '/'.join([ref_name, f_path])
367
368 # SVN always needs a commit_id explicitly, without a named REF
369 default_commit_id = commit_id
370 else:
371 """
372 For git and mercurial we construct a new URL using the names instead of commit_id
373 like: /master/some_path?at=master
374 """
375 # We currently do not support branches with slashes
376 if '/' in ref_name:
377 default_commit_id = commit_id
378 else:
379 default_commit_id = ref_name
380
381 # sometimes we pass f_path as None, to indicate explicit no prefix,
382 # we translate it to string to not have None
383 final_f_path = final_f_path or ''
384
385 files_url = route_path(
386 'repo_files',
387 repo_name=db_repo_name,
388 commit_id=default_commit_id,
389 f_path=final_f_path,
390 _query=query
391 )
392 return files_url
393
394
340 395 def code_highlight(code, lexer, formatter, use_hl_filter=False):
341 396 """
342 397 Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``.
@@ -47,7 +47,7 b' from .utils import ('
47 47 FreshRegionCache, ActiveRegionCache)
48 48
49 49
50 FILE_TREE_CACHE_VER = 'v3'
50 FILE_TREE_CACHE_VER = 'v4'
51 51
52 52
53 53 def configure_dogpile_cache(settings):
@@ -365,7 +365,7 b''
365 365 <ul id="context-pages" class="navigation horizontal-list">
366 366 <li class="${h.is_active('summary', active)}"><a class="menulink" href="${h.route_path('repo_summary', repo_name=c.repo_name)}"><div class="menulabel">${_('Summary')}</div></a></li>
367 367 <li class="${h.is_active('commits', active)}"><a class="menulink" href="${h.route_path('repo_commits', repo_name=c.repo_name)}"><div class="menulabel">${_('Commits')}</div></a></li>
368 <li class="${h.is_active('files', active)}"><a class="menulink" href="${h.route_path('repo_files', repo_name=c.repo_name, commit_id=c.rhodecode_db_repo.landing_ref_name, f_path='', _query={'at':c.rhodecode_db_repo.landing_ref_name})}"><div class="menulabel">${_('Files')}</div></a></li>
368 <li class="${h.is_active('files', active)}"><a class="menulink" href="${h.repo_files_by_ref_url(c.repo_name, c.rhodecode_db_repo.repo_type, f_path='', ref_name=c.rhodecode_db_repo.landing_ref_name, commit_id='tip', query={'at':c.rhodecode_db_repo.landing_ref_name})}"><div class="menulabel">${_('Files')}</div></a></li>
369 369 <li class="${h.is_active('compare', active)}"><a class="menulink" href="${h.route_path('repo_compare_select',repo_name=c.repo_name)}"><div class="menulabel">${_('Compare')}</div></a></li>
370 370
371 371 ## TODO: anderson: ideally it would have a function on the scm_instance "enable_pullrequest() and enable_fork()"
@@ -36,7 +36,7 b''
36 36 <ul>
37 37 <li class="breadcrumb-path">
38 38 <div>
39 ${h.files_breadcrumbs(c.repo_name, c.commit.raw_id, c.f_path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True, hide_last_item=False, linkify_last_item=True, copy_path_icon=False)} /
39 ${h.files_breadcrumbs(c.repo_name, c.rhodecode_db_repo.repo_type, c.commit.raw_id, c.f_path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True, hide_last_item=False, linkify_last_item=True, copy_path_icon=False)} /
40 40 </div>
41 41 </li>
42 42 <li class="location-path">
@@ -4,10 +4,10 b''
4 4 at_ref = request.GET.get('at')
5 5 if at_ref:
6 6 query={'at': at_ref}
7 default_commit_id = at_ref or c.rhodecode_db_repo.landing_ref_name
7 default_landing_ref = at_ref or c.rhodecode_db_repo.landing_ref_name
8 8 else:
9 9 query=None
10 default_commit_id = c.commit.raw_id
10 default_landing_ref = c.commit.raw_id
11 11 %>
12 12 <div id="file-tree-wrapper" class="browser-body ${('full-load' if c.full_load else '')}">
13 13 <table class="code-browser rctable repo_summary">
@@ -24,7 +24,7 b''
24 24 <tbody id="tbody">
25 25 <tr>
26 26 <td colspan="5">
27 ${h.files_breadcrumbs(c.repo_name, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True)}
27 ${h.files_breadcrumbs(c.repo_name, c.rhodecode_db_repo.repo_type, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True)}
28 28 </td>
29 29 </tr>
30 30
@@ -44,7 +44,7 b''
44 44 % endif
45 45 </span>
46 46 % else:
47 <a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=default_commit_id,f_path=h.safe_unicode(node.path), _query=query)}">
47 <a href="${h.repo_files_by_ref_url(c.repo_name, c.rhodecode_db_repo.repo_type, f_path=h.safe_unicode(node.path), ref_name=default_landing_ref, commit_id=c.commit.raw_id, query=query)}">
48 48 <i class="${('icon-file-text browser-file' if node.is_file() else 'icon-directory browser-dir')}"></i>${node.name}
49 49 </a>
50 50 % endif
@@ -35,7 +35,7 b''
35 35 <div class="path-items">
36 36 <li class="breadcrumb-path">
37 37 <div>
38 ${h.files_breadcrumbs(c.repo_name, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True, hide_last_item=True, copy_path_icon=False)} /
38 ${h.files_breadcrumbs(c.repo_name, c.rhodecode_db_repo.repo_type, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True, hide_last_item=True, copy_path_icon=False)} /
39 39 </div>
40 40 </li>
41 41 <li class="location-path">
@@ -36,7 +36,7 b''
36 36 <ul>
37 37 <li class="breadcrumb-path">
38 38 <div>
39 ${h.files_breadcrumbs(c.repo_name, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True, hide_last_item=True, copy_path_icon=False)} /
39 ${h.files_breadcrumbs(c.repo_name, c.rhodecode_db_repo.repo_type, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'), limit_items=True, hide_last_item=True, copy_path_icon=False)} /
40 40 </div>
41 41 </li>
42 42 <li class="location-path">
@@ -98,7 +98,7 b''
98 98
99 99 <div class="path clear-fix">
100 100 <div class="pull-left">
101 ${h.files_breadcrumbs(c.repo_name, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'))}
101 ${h.files_breadcrumbs(c.repo_name, c.rhodecode_db_repo.repo_type, c.commit.raw_id, c.file.path, c.rhodecode_db_repo.landing_ref_name, request.GET.get('at'))}
102 102 </div>
103 103
104 104 <div class="pull-right stats">
@@ -93,7 +93,7 b''
93 93
94 94 <div class="path clear-fix">
95 95 <div class="pull-left">
96 ${h.files_breadcrumbs(entry['repository'], entry.get('commit_id', 'tip'), entry['f_path'], linkify_last_item=True)}
96 ${h.files_breadcrumbs(entry['repository'], repo_type, entry.get('commit_id', 'tip'), entry['f_path'], linkify_last_item=True)}
97 97 </div>
98 98
99 99 <div class="pull-right stats">
General Comments 0
You need to be logged in to leave comments. Login now