allow truncating repo browser list - Setting.repository_truncate_at

pull/5438/head
Markus Kahl 8 years ago
parent 455240c843
commit c7cec30020
  1. 8
      app/controllers/repositories_controller.rb
  2. 13
      app/models/repository.rb
  3. 1
      app/views/settings/_repositories.html.erb
  4. 2
      config/locales/en.yml
  5. 3
      config/settings.yml
  6. 19
      lib/open_project/scm/adapters.rb
  7. BIN
      spec/fixtures/repositories/subversion_repository.tar.gz
  8. 29
      spec/models/repository/git_spec.rb
  9. 29
      spec/models/repository/subversion_spec.rb

@ -129,8 +129,10 @@ class RepositoriesController < ApplicationController
@repository.update_required_storage
end
@entries = @repository.entries(@path, @rev)
limit = Setting.repository_truncate_at
@entries = @repository.entries(@path, @rev, limit: limit)
@changeset = @repository.find_changeset_by_name(@rev)
if request.xhr?
if @entries && @repository.valid?
render(partial: 'dir_list_content')
@ -140,6 +142,10 @@ class RepositoriesController < ApplicationController
elsif @entries.nil? && @repository.invalid?
show_error_not_found
else
if @entries.truncated?
flash[:warning] = I18n.t "repositories.truncated", limit: limit, truncated: @entries.truncated
end
@changesets = @repository.latest_changesets(@path, @rev)
@properties = @repository.properties(@path, @rev)
render action: 'show'

@ -144,8 +144,17 @@ class Repository < ActiveRecord::Base
scm.entry(path, identifier)
end
def entries(path = nil, identifier = nil)
scm.entries(path, identifier)
def entries(path = nil, identifier = nil, limit: nil)
entries = scm.entries(path, identifier)
if limit && limit < entries.size
result = OpenProject::Scm::Adapters::Entries.new entries.take(limit)
result.truncated = entries.size - result.size
result
else
entries
end
end
def branches

@ -90,6 +90,7 @@ See doc/COPYRIGHT.rdoc for more details.
<div class="form--field-instructions"><%= l(:text_comma_separated) %></div>
</div>
<div class="form--field"><%= setting_text_field :repository_log_display_limit, size: 6 %></div>
<div class="form--field"><%= setting_text_field :repository_truncate_at, size: 6 %></div>
<div class="form--field"><%= setting_check_box :repository_authentication_caching_enabled %></div>
</section>
<%= render partial: 'repositories_checkout' %>

@ -1813,6 +1813,7 @@ en:
managed_url: "Managed URL"
password: "Repository Password"
username: "Repository username"
truncated: "Sorry, we had to truncate this directory to %{limit} files. %{truncated} entries were omitted from the list."
named_repository: "%{vendor_name} repository"
update_settings_successful: "The settings have been sucessfully saved."
url: "URL to repository"
@ -1902,6 +1903,7 @@ en:
setting_repository_checkout_base_url: "Checkout base URL"
setting_repository_checkout_text: "Checkout instruction text"
setting_repository_log_display_limit: "Maximum number of revisions displayed on file log"
setting_repository_truncate_at: "Maximum number of files displayed in the repository browser"
setting_rest_api_enabled: "Enable REST web service"
setting_self_registration: "Self-registration"
setting_sequential_project_identifiers: "Generate sequential project identifiers"

@ -323,6 +323,9 @@ registration_footer:
repository_storage_cache_minutes:
default: 720
format: int
repository_truncate_at:
default: 500
format: int
repository_checkout_data:
serialized: true
default:

@ -31,13 +31,30 @@ module OpenProject
module Adapters
class Entries < Array
def sort_by_name
sort do |x, y|
sorted = sort do |x, y|
if x.kind == y.kind
x.name.to_s <=> y.name.to_s
else
x.kind <=> y.kind
end
end
entries = Entries.new sorted
entries.truncated = truncated
entries
end
def truncated=(truncated)
@truncated = truncated
end
def truncated
@truncated
end
def truncated?
@truncated
end
end

@ -160,6 +160,35 @@ describe Repository::Git, type: :model do
expect(instance.scm).to be_available
end
describe "#entries" do
let(:entries) { instance.entries }
it "lists 10 entries" do
expect(entries.size).to eq 10
end
describe "with limit: 5" do
let(:directories) { entries.select { |e| e.kind == "dir" } }
let(:files) { entries.select { |e| e.kind == "file" } }
let(:limited_entries) { instance.entries limit: 5 }
before do
expect(directories.size).to eq 3
end
it "lists 5 entries only, directories first" do
expected_entries = (directories + files.take(2)).map(&:path)
expect(limited_entries.map(&:path)).to eq expected_entries
end
it "indicates 5 omitted entries" do
expect(limited_entries.truncated).to eq 5
end
end
end
it 'should fetch changesets from scratch' do
expect(instance.changesets.count).to eq(22)
expect(instance.file_changes.count).to eq(34)

@ -327,6 +327,35 @@ describe Repository::Subversion, type: :model do
end
end
describe "#entries" do
let(:entries) { instance.entries }
it "lists 10 entries" do
expect(entries.size).to eq 10
end
describe "with limit: 5" do
let(:directories) { entries.select { |e| e.kind == "dir" } }
let(:files) { entries.select { |e| e.kind == "file" } }
let(:limited_entries) { instance.entries limit: 5 }
before do
expect(directories.size).to eq 3
end
it "lists 5 entries only, directories first" do
expected_entries = (directories + files.take(2)).map(&:path)
expect(limited_entries.map(&:path)).to eq expected_entries
end
it "indicates 5 omitted entries" do
expect(limited_entries.truncated).to eq 5
end
end
end
it_behaves_like 'is a countable repository' do
let(:repository) { instance }
end

Loading…
Cancel
Save