Commit c43395da authored by Phil Hughes's avatar Phil Hughes

Merge branch 'jdb/remove-unused-tree-files' into 'master'

Remove unused tree files

See merge request gitlab-org/gitlab!53188
parents 5d2941d6 3ee2cd7d
......@@ -6,28 +6,6 @@ module TreeHelper
FILE_LIMIT = 1_000
# Sorts a repository's tree so that folders are before files and renders
# their corresponding partials
#
# tree - A `Tree` object for the current tree
# rubocop: disable CodeReuse/ActiveRecord
def render_tree(tree)
# Sort submodules and folders together by name ahead of files
folders, files, submodules = tree.trees, tree.blobs, tree.submodules
tree = []
items = (folders + submodules).sort_by(&:name) + files
if items.size > FILE_LIMIT
tree << render(partial: 'projects/tree/truncated_notice_tree_row',
locals: { limit: FILE_LIMIT, total: items.size })
items = items.take(FILE_LIMIT)
end
tree << render(partial: 'projects/tree/tree_row', collection: items) if items.present?
tree.join.html_safe
end
# rubocop: enable CodeReuse/ActiveRecord
# Return an image icon depending on the file type and mode
#
# type - String type of the tree item; either 'folder' or 'file'
......@@ -37,20 +15,6 @@ module TreeHelper
sprite_icon(file_type_icon_class(type, mode, name))
end
# Using Rails `*_path` methods can be slow, especially when generating
# many paths, as with a repository tree that has thousands of items.
def fast_project_blob_path(project, blob_path)
ActionDispatch::Journey::Router::Utils.escape_path(
File.join(relative_url_root, project.path_with_namespace, '-', 'blob', blob_path)
)
end
def fast_project_tree_path(project, tree_path)
ActionDispatch::Journey::Router::Utils.escape_path(
File.join(relative_url_root, project.path_with_namespace, '-', 'tree', tree_path)
)
end
# Simple shortcut to File.join
def tree_join(*args)
File.join(*args)
......@@ -167,13 +131,6 @@ module TreeHelper
Gitlab.config.gitlab.relative_url_root.presence || '/'
end
# project and path are used on the EE version
def tree_content_data(logs_path, project, path)
{
"logs-path" => logs_path
}
end
def breadcrumb_data_attributes
attrs = {
can_collaborate: can_collaborate_with_project?(@project).to_s,
......
- if readme.rich_viewer
%article.file-holder.readme-holder{ id: 'readme', class: [("limited-width-container" unless fluid_layout)] }
.js-file-title.file-title-flex-parent
.file-header-content
= blob_icon readme.mode, readme.name
= link_to project_blob_path(@project, tree_join(@ref, readme.path)) do
%strong
= readme.name
= render 'projects/blob/viewer', viewer: readme.rich_viewer, viewer_url: project_blob_path(@project, tree_join(@ref, readme.path), viewer: :rich, format: :json)
.tree-content-holder.js-tree-content{ data: tree_content_data(@logs_path, @project, @path) }
.table-holder.bordered-box
%table.table#tree-slider{ class: "table_#{@hex_path} tree-table" }
%thead
%tr
%th= s_('ProjectFileTree|Name')
%th.d-none.d-sm-table-cell
.float-left= _('Last commit')
%th.text-right= _('Last update')
- if @path.present?
%tr.tree-item
%td.tree-item-file-name
= link_to "..", project_tree_path(@project, up_dir_path), class: 'gl-ml-3'
%td
%td.d-none.d-sm-table-cell
= render_tree(tree)
- if tree.readme
= render "projects/tree/readme", readme: tree.readme
- if can_edit_tree?
= render 'projects/blob/upload', title: _('Upload New File'), placeholder: _('Upload New File'), button_title: _('Upload file'), form_path: project_create_blob_path(@project, @id), method: :post
= render 'projects/blob/new_dir'
- tree_row_name = tree_row.name
- tree_row_type = tree_row.type
%tr{ class: "tree-item file_#{hexdigest(tree_row_name)}" }
%td.tree-item-file-name
- if tree_row_type == :tree
= tree_icon('folder', tree_row.mode, tree_row.name)
- path = flatten_tree(@path, tree_row)
%a.str-truncated{ href: fast_project_tree_path(@project, tree_join(@id || @commit.id, path)), title: path }
%span= path
- elsif tree_row_type == :blob
= tree_icon('file', tree_row.mode, tree_row_name)
%a.str-truncated{ href: fast_project_blob_path(@project, tree_join(@id || @commit.id, tree_row_name)), title: tree_row_name }
%span= tree_row_name
- if @lfs_blob_ids.include?(tree_row.id)
%span.badge.label-lfs.gl-ml-2 LFS
- elsif tree_row_type == :commit
= tree_icon('archive', tree_row.mode, tree_row.name)
= submodule_link(tree_row, @ref)
%td.d-none.d-sm-table-cell.tree-commit
%td.tree-time-ago.text-right
%span.log_loading.hide
= loading_icon
Loading commit data...
%tr.tree-truncated-warning
%td{ colspan: '3' }
= sprite_icon('warning-solid')
%span
Too many items to show. To preserve performance only
%strong #{number_with_delimiter(limit)} of #{number_with_delimiter(total)}
items are displayed.
......@@ -4,15 +4,6 @@ module EE
module TreeHelper
extend ::Gitlab::Utils::Override
override :tree_content_data
def tree_content_data(logs_path, project, path)
super.merge({
"path-locks-available" => project.feature_available?(:file_locks).to_s,
"path-locks-toggle" => toggle_project_path_locks_path(project),
"path-locks-path" => path
})
end
override :vue_file_list_data
def vue_file_list_data(project, ref)
super.merge({
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe TreeHelper do
let(:project) { create(:project, :repository) }
describe '#tree_content_data' do
let(:logs_path) { "#{project.full_path}/refs/master/logs_tree/" }
let(:path) { '.gitlab/template_test' }
context 'when file locks is available' do
it 'returns the logs path' do
stub_licensed_features(file_locks: true)
tree_content_data = {
"logs-path" => logs_path,
"path-locks-available" => "true",
"path-locks-toggle" => toggle_project_path_locks_path(project),
"path-locks-path" => path
}
expect(helper.tree_content_data(logs_path, project, path)).to eq(tree_content_data)
end
end
context 'when file lock is not available' do
it 'returns the path information' do
stub_licensed_features(file_locks: false)
tree_content_data = {
"logs-path" => logs_path,
"path-locks-available" => "false",
"path-locks-toggle" => toggle_project_path_locks_path(project),
"path-locks-path" => path
}
expect(helper.tree_content_data(logs_path, project, path)).to eq(tree_content_data)
end
end
end
end
......@@ -19,94 +19,6 @@ RSpec.describe TreeHelper do
)
end
describe '.render_tree' do
before do
@id = sha
@path = ""
@project = project
@lfs_blob_ids = []
end
it 'displays all entries without a warning' do
tree = repository.tree(sha, 'files')
html = render_tree(tree)
expect(html).not_to have_selector('.tree-truncated-warning')
end
it 'truncates entries and adds a warning' do
stub_const('TreeHelper::FILE_LIMIT', 1)
tree = repository.tree(sha, 'files')
html = render_tree(tree)
expect(html).to have_selector('.tree-truncated-warning', count: 1)
expect(html).to have_selector('.tree-item-file-name', count: 1)
end
end
describe '.fast_project_blob_path' do
it 'generates the same path as project_blob_path' do
blob_path = repository.tree(sha, 'with space').entries.first.path
fast_path = fast_project_blob_path(project, blob_path)
std_path = project_blob_path(project, blob_path)
expect(fast_path).to eq(std_path)
end
it 'generates the same path with encoded file names' do
tree = repository.tree(sha, 'encoding')
blob_path = tree.entries.find { |entry| entry.path == 'encoding/テスト.txt' }.path
fast_path = fast_project_blob_path(project, blob_path)
std_path = project_blob_path(project, blob_path)
expect(fast_path).to eq(std_path)
end
it 'respects a configured relative URL' do
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root')
blob_path = repository.tree(sha, '').entries.first.path
fast_path = fast_project_blob_path(project, blob_path)
expect(fast_path).to start_with('/gitlab/root')
end
it 'encodes files starting with #' do
filename = '#test-file'
create_file(filename)
fast_path = fast_project_blob_path(project, filename)
expect(fast_path).to end_with('%23test-file')
end
end
describe '.fast_project_tree_path' do
let(:tree_path) { repository.tree(sha, 'with space').path }
let(:fast_path) { fast_project_tree_path(project, tree_path) }
let(:std_path) { project_tree_path(project, tree_path) }
it 'generates the same path as project_tree_path' do
expect(fast_path).to eq(std_path)
end
it 'respects a configured relative URL' do
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root')
expect(fast_path).to start_with('/gitlab/root')
end
it 'encodes files starting with #' do
filename = '#test-file'
create_file(filename)
fast_path = fast_project_tree_path(project, filename)
expect(fast_path).to end_with('%23test-file')
end
end
describe 'flatten_tree' do
let(:tree) { repository.tree(sha, 'files') }
let(:root_path) { 'files' }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'projects/tree/_tree_row' do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
# rubocop: disable Rails/FindBy
# This is not ActiveRecord where..first
let(:blob_item) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files/ruby').first }
# rubocop: enable Rails/FindBy
before do
assign(:project, project)
assign(:repository, repository)
assign(:id, File.join('master', ''))
assign(:lfs_blob_ids, [])
end
it 'renders blob item' do
render_partial(blob_item)
expect(rendered).to have_content(blob_item.name)
expect(rendered).not_to have_selector('.label-lfs', text: 'LFS')
end
describe 'LFS blob' do
before do
assign(:lfs_blob_ids, [blob_item].map(&:id))
render_partial(blob_item)
end
it 'renders LFS badge' do
expect(rendered).to have_selector('.label-lfs', text: 'LFS')
end
end
def render_partial(items)
render partial: 'projects/tree/tree_row', collection: [items].flatten
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment