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 @@ -245,7 +245,7 @@ class RepoFilesView(RepoAppView): return branch_name, sha_commit_id, is_head - def _get_tree_at_commit(self, c, commit_id, f_path, full_load=False): + def _get_tree_at_commit(self, c, commit_id, f_path, full_load=False, at_rev=None): repo_id = self.db_repo.repo_id force_recache = self.get_recache_flag() @@ -263,17 +263,18 @@ class RepoFilesView(RepoAppView): @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache_on) - def compute_file_tree(ver, repo_id, commit_id, f_path, full_load): + def compute_file_tree(ver, repo_id, commit_id, f_path, full_load, at_rev): log.debug('Generating cached file tree at ver:%s for repo_id: %s, %s, %s', ver, repo_id, commit_id, f_path) c.full_load = full_load return render( 'rhodecode:templates/files/files_browser_tree.mako', - self._get_template_context(c), self.request) + self._get_template_context(c), self.request, at_rev) return compute_file_tree( - rc_cache.FILE_TREE_CACHE_VER, self.db_repo.repo_id, commit_id, f_path, full_load) + rc_cache.FILE_TREE_CACHE_VER, self.db_repo.repo_id, commit_id, + f_path, full_load, at_rev) def _get_archive_spec(self, fname): log.debug('Detecting archive spec for: `%s`', fname) @@ -617,15 +618,12 @@ class RepoFilesView(RepoAppView): c.renderer = view_name == 'repo_files:rendered' or \ not self.request.GET.get('no-render', False) - # redirect to given commit_id from form if given - get_commit_id = self.request.GET.get('at_rev', None) - if get_commit_id: - self._get_commit_or_redirect(get_commit_id) + commit_id, f_path = self._get_commit_and_path() - commit_id, f_path = self._get_commit_and_path() c.commit = self._get_commit_or_redirect(commit_id) c.branch = self.request.GET.get('branch', None) c.f_path = f_path + at_rev = self.request.GET.get('at') # prev link try: @@ -705,7 +703,7 @@ class RepoFilesView(RepoAppView): c.authors = [] # this loads a simple tree without metadata to speed things up # later via ajax we call repo_nodetree_full and fetch whole - c.file_tree = self._get_tree_at_commit(c, c.commit.raw_id, f_path) + c.file_tree = self._get_tree_at_commit(c, c.commit.raw_id, f_path, at_rev=at_rev) c.readme_data, c.readme_file = \ self._get_readme_data(self.db_repo, c.visual.default_renderer, @@ -782,9 +780,10 @@ class RepoFilesView(RepoAppView): c.file = dir_node c.commit = commit + at_rev = self.request.GET.get('at') html = self._get_tree_at_commit( - c, commit.raw_id, dir_node.path, full_load=True) + c, commit.raw_id, dir_node.path, full_load=True, at_rev=at_rev) return Response(html) @@ -1038,10 +1037,24 @@ class RepoFilesView(RepoAppView): file_history, _hist = self._get_node_history(commit, f_path) res = [] - for obj in file_history: + for section_items, section in file_history: + items = [] + for obj_id, obj_text, obj_type in section_items: + at_rev = '' + if obj_type in ['branch', 'bookmark', 'tag']: + at_rev = obj_text + entry = { + 'id': obj_id, + 'text': obj_text, + 'type': obj_type, + 'at_rev': at_rev + } + + items.append(entry) + res.append({ - 'text': obj[1], - 'children': [{'id': o[0], 'text': o[1], 'type': o[2]} for o in obj[0]] + 'text': section, + 'children': items }) data = { 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 = 'v2' +FILE_TREE_CACHE_VER = 'v3' def configure_dogpile_cache(settings): diff --git a/rhodecode/public/js/src/rhodecode/files.js b/rhodecode/public/js/src/rhodecode/files.js --- a/rhodecode/public/js/src/rhodecode/files.js +++ b/rhodecode/public/js/src/rhodecode/files.js @@ -372,9 +372,13 @@ var getFilesMetadata = function() { var url_data = { 'repo_name': templateContext.repo_name, 'commit_id': state.commit_id, - 'f_path': state.f_path + 'f_path': state.f_path, }; + if (atRef !== '') { + url_data['at'] = atRef + } + var url = pyroutes.url('repo_nodetree_full', url_data); metadataRequest = $.ajax({url: url}); diff --git a/rhodecode/templates/files/base.mako b/rhodecode/templates/files/base.mako --- a/rhodecode/templates/files/base.mako +++ b/rhodecode/templates/files/base.mako @@ -1,10 +1,25 @@ -<%def name="refs(commit)"> - ## Build a cache of refs for selector +<%def name="refs(commit, at_rev=None)"> + + ## Build a cache of refs for selector, based on this the files ref selector gets pre-selected values - } - + % if h.is_svn(c.rhodecode_repo): + ## since SVN doesn't have an commit<->refs association, we simply inject it + ## based on our at_rev marker + % if at_rev and at_rev.startswith('branches/'): + <% + commit.branch = at_rev + %> + % endif + % if at_rev and at_rev.startswith('tags/'): + <% + commit.tags.append(at_rev) + %> + % endif + + % endif %if commit.merge: diff --git a/rhodecode/templates/files/files.mako b/rhodecode/templates/files/files.mako --- a/rhodecode/templates/files/files.mako +++ b/rhodecode/templates/files/files.mako @@ -158,18 +158,24 @@ select2FileHistorySwitcher('#file_refs_filter', loadUrl, initialCommitData); + // switcher for files $('#file_refs_filter').on('change', function(e) { var data = $('#file_refs_filter').select2('data'); var commit_id = data.id; + var params = { + 'repo_name': templateContext.repo_name, + 'commit_id': commit_id, + 'f_path': state.f_path + }; + + if(data.at_rev !== undefined && data.at_rev !== "") { + params['at'] = data.at_rev; + } if ("${c.annotate}" === "True") { - var url = pyroutes.url('repo_files:annotated', - {'repo_name': templateContext.repo_name, - 'commit_id': commit_id, 'f_path': state.f_path}); + var url = pyroutes.url('repo_files:annotated', params); } else { - var url = pyroutes.url('repo_files', - {'repo_name': templateContext.repo_name, - 'commit_id': commit_id, 'f_path': state.f_path}); + var url = pyroutes.url('repo_files', params); } window.location = url; @@ -334,6 +340,7 @@ select2RefFileSwitcher('#refs_filter', loadUrl, initialCommitData); + // switcher for file tree $('#refs_filter').on('change', function(e) { var data = $('#refs_filter').select2('data'); window.location = data.files_url diff --git a/rhodecode/templates/files/files_browser_tree.mako b/rhodecode/templates/files/files_browser_tree.mako --- a/rhodecode/templates/files/files_browser_tree.mako +++ b/rhodecode/templates/files/files_browser_tree.mako @@ -41,7 +41,6 @@ % endif % else: - ${node.name} diff --git a/rhodecode/templates/files/files_source_header.mako b/rhodecode/templates/files/files_source_header.mako --- a/rhodecode/templates/files/files_source_header.mako +++ b/rhodecode/templates/files/files_source_header.mako @@ -33,7 +33,7 @@

${_('File last commit')}:

${h.show_id(c.file_last_commit)} - ${file_base.refs(c.file_last_commit)} + ${file_base.refs(c.file_last_commit)}
@@ -46,7 +46,7 @@ ${h.show_id(c.commit)} - ${file_base.refs(c.commit)} + ${file_base.refs(c.commit, request.GET.get('at'))} diff --git a/rhodecode/templates/files/files_tree_header.mako b/rhodecode/templates/files/files_tree_header.mako --- a/rhodecode/templates/files/files_tree_header.mako +++ b/rhodecode/templates/files/files_tree_header.mako @@ -33,7 +33,8 @@ - ${file_base.refs(c.commit)} + ${file_base.refs(c.commit, request.GET.get('at'))} +