files: fixed the repo switcher at flag beeing nor persistens

- additionally SVN now reports nice switchet refs as other types of vcs
- fixes #5610
- references #5599 (org issue)
This commit is contained in:
Daniel Dourvaris 2020-04-03 22:54:42 +02:00
parent 94902d0880
commit 3fa756fb2c
8 changed files with 70 additions and 31 deletions

View file

@ -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()
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 = {

View file

@ -47,7 +47,7 @@ from .utils import (
FreshRegionCache, ActiveRegionCache)
FILE_TREE_CACHE_VER = 'v2'
FILE_TREE_CACHE_VER = 'v3'
def configure_dogpile_cache(settings):

View file

@ -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});

View file

@ -1,11 +1,26 @@
<%def name="refs(commit)">
## Build a cache of refs for selector
<script>
fileTreeRefs = {
<%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
<script>
fileTreeRefs = {}
</script>
% 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:
<span class="mergetag tag">
<i class="icon-merge">${_('merge')}</i>

View file

@ -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

View file

@ -41,7 +41,6 @@
% endif
</span>
% else:
<a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=h.safe_unicode(node.path), _query=query)}">
<i class="${('icon-file-text browser-file' if node.is_file() else 'icon-directory browser-dir')}"></i>${node.name}
</a>

View file

@ -33,7 +33,7 @@
<p>${_('File last commit')}:</p>
<div class="right-label-summary">
<code><a href="${h.route_path('repo_commit',repo_name=c.repo_name,commit_id=c.file_last_commit.raw_id)}">${h.show_id(c.file_last_commit)}</a></code>
${file_base.refs(c.file_last_commit)}
${file_base.refs(c.file_last_commit)}
</div>
</div>
</div>
@ -46,7 +46,7 @@
<a href="${h.route_path('repo_commit',repo_name=c.repo_name,commit_id=c.commit.raw_id)}">${h.show_id(c.commit)}</a>
</code>
<i class="tooltip icon-clipboard clipboard-action" data-clipboard-text="${c.commit.raw_id}" title="${_('Copy the full commit id')}"></i>
${file_base.refs(c.commit)}
${file_base.refs(c.commit, request.GET.get('at'))}
</div>
</div>
</div>

View file

@ -33,7 +33,8 @@
</code>
<i class="tooltip icon-clipboard clipboard-action" data-clipboard-text="${c.commit.raw_id}" title="${_('Copy the full commit id')}"></i>
${file_base.refs(c.commit)}
${file_base.refs(c.commit, request.GET.get('at'))}
</div>
</div>