# HG changeset patch # User Marcin Kuzminski # Date 2020-06-03 18:29:26 # Node ID 702c378c49047dd091eaaaf2142e4add5616fdee # Parent 7db766f93bc4ca1067729eefb0b687cbddf763dd files: use a common function to handle url-by-refs, and fix landing refs for SVN. - fixes #5619 diff --git a/rhodecode/apps/_base/__init__.py b/rhodecode/apps/_base/__init__.py --- a/rhodecode/apps/_base/__init__.py +++ b/rhodecode/apps/_base/__init__.py @@ -531,8 +531,6 @@ class BaseReferencesView(RepoAppView): """ def load_default_context(self): c = self._get_local_tmpl_context() - - return c def load_refs_context(self, ref_items, partials_template): @@ -562,7 +560,9 @@ class BaseReferencesView(RepoAppView): 'repo_files', repo_name=self.db_repo_name, f_path=ref_name if is_svn else '', - commit_id=commit_id) + commit_id=commit_id, + _query=dict(at=ref_name) + ) else: files_url = h.route_path( @@ -570,7 +570,8 @@ class BaseReferencesView(RepoAppView): repo_name=self.db_repo_name, f_path=ref_name if is_svn else '', commit_id=ref_name, - _query=dict(at=ref_name)) + _query=dict(at=ref_name) + ) data.append({ "name": _render('name', ref_name, files_url, closed), diff --git a/rhodecode/apps/repository/views/repo_files.py b/rhodecode/apps/repository/views/repo_files.py --- a/rhodecode/apps/repository/views/repo_files.py +++ b/rhodecode/apps/repository/views/repo_files.py @@ -594,11 +594,15 @@ class RepoFilesView(RepoAppView): renderer=None) def repo_files_default(self): c = self.load_default_context() - - landing_url = 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}) + ref_name = c.rhodecode_db_repo.landing_ref_name + landing_url = h.repo_files_by_ref_url( + c.rhodecode_db_repo.repo_name, + c.rhodecode_db_repo.repo_type, + f_path='', + ref_name=ref_name, + commit_id='tip', + query=dict(at=ref_name) + ) raise HTTPFound(landing_url) diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -256,29 +256,34 @@ tooltip = _ToolTip() files_icon = u'' -def files_breadcrumbs(repo_name, commit_id, file_path, landing_ref_name=None, at_ref=None, - limit_items=False, linkify_last_item=False, hide_last_item=False, copy_path_icon=True): +def files_breadcrumbs(repo_name, repo_type, commit_id, file_path, landing_ref_name=None, at_ref=None, + limit_items=False, linkify_last_item=False, hide_last_item=False, + copy_path_icon=True): if isinstance(file_path, str): file_path = safe_unicode(file_path) if at_ref: route_qry = {'at': at_ref} - default_commit_id = at_ref or landing_ref_name or commit_id + default_landing_ref = at_ref or landing_ref_name or commit_id else: route_qry = None - default_commit_id = commit_id + default_landing_ref = commit_id - # first segment is a `..` link to repo files + # first segment is a `HOME` link to repo files root location root_name = literal(u'') + url_segments = [ link_to( root_name, - route_path( - 'repo_files', - repo_name=repo_name, - commit_id=default_commit_id, - f_path='', - _query=route_qry), + repo_files_by_ref_url( + repo_name, + repo_type, + f_path=None, # None here is a special case for SVN repos, + # that won't prefix with a ref + ref_name=default_landing_ref, + commit_id=commit_id, + query=route_qry + ) )] path_segments = file_path.split('/') @@ -301,12 +306,14 @@ def files_breadcrumbs(repo_name, commit_ url_segments.append( link_to( segment_html, - route_path( - 'repo_files', - repo_name=repo_name, - commit_id=default_commit_id, + repo_files_by_ref_url( + repo_name, + repo_type, f_path='/'.join(path_segments[:cnt + 1]), - _query=route_qry), + ref_name=default_landing_ref, + commit_id=commit_id, + query=route_qry + ), )) limited_url_segments = url_segments[:1] + ['...'] + url_segments[-5:] @@ -337,6 +344,54 @@ def files_url_data(request): return json.dumps(matchdict) +def repo_files_by_ref_url(db_repo_name, db_repo_type, f_path, ref_name, commit_id, query=None, ): + _is_svn = is_svn(db_repo_type) + final_f_path = f_path + + if _is_svn: + """ + For SVN the ref_name cannot be used as a commit_id, it needs to be prefixed with + actually commit_id followed by the ref_name. This should be done only in case + This is a initial landing url, without additional paths. + + like: /1000/tags/1.0.0/?at=tags/1.0.0 + """ + + if ref_name and ref_name != 'tip': + # NOTE(marcink): for svn the ref_name is actually the stored path, so we prefix it + # for SVN we only do this magic prefix if it's root, .eg landing revision + # of files link. If we are in the tree we don't need this since we traverse the url + # that has everything stored + if f_path in ['', '/']: + final_f_path = '/'.join([ref_name, f_path]) + + # SVN always needs a commit_id explicitly, without a named REF + default_commit_id = commit_id + else: + """ + For git and mercurial we construct a new URL using the names instead of commit_id + like: /master/some_path?at=master + """ + # We currently do not support branches with slashes + if '/' in ref_name: + default_commit_id = commit_id + else: + default_commit_id = ref_name + + # sometimes we pass f_path as None, to indicate explicit no prefix, + # we translate it to string to not have None + final_f_path = final_f_path or '' + + files_url = route_path( + 'repo_files', + repo_name=db_repo_name, + commit_id=default_commit_id, + f_path=final_f_path, + _query=query + ) + return files_url + + def code_highlight(code, lexer, formatter, use_hl_filter=False): """ Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``. diff --git a/rhodecode/lib/rc_cache/__init__.py b/rhodecode/lib/rc_cache/__init__.py --- a/rhodecode/lib/rc_cache/__init__.py +++ b/rhodecode/lib/rc_cache/__init__.py @@ -47,7 +47,7 @@ from .utils import ( FreshRegionCache, ActiveRegionCache) -FILE_TREE_CACHE_VER = 'v3' +FILE_TREE_CACHE_VER = 'v4' def configure_dogpile_cache(settings): diff --git a/rhodecode/templates/base/base.mako b/rhodecode/templates/base/base.mako --- a/rhodecode/templates/base/base.mako +++ b/rhodecode/templates/base/base.mako @@ -365,7 +365,7 @@