Commit 5dc84fa5 authored by Marin Jankovski's avatar Marin Jankovski

Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce

parents 0ccc4f19 c4aa7003
...@@ -22,6 +22,8 @@ v 7.11.0 (unreleased) ...@@ -22,6 +22,8 @@ v 7.11.0 (unreleased)
- Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention. - Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention.
- Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention. - Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention.
- When use change branches link at MR form - save source branch selection instead of target one - When use change branches link at MR form - save source branch selection instead of target one
- Improve handling of large diffs
-
- Show Atom feed buttons everywhere where applicable. - Show Atom feed buttons everywhere where applicable.
- Add project activity atom feed. - Add project activity atom feed.
- Don't crash when an MR from a fork has a cross-reference comment from the target project on one of its commits. - Don't crash when an MR from a fork has a cross-reference comment from the target project on one of its commits.
......
...@@ -7,14 +7,23 @@ module DiffHelper ...@@ -7,14 +7,23 @@ module DiffHelper
end end
end end
def safe_diff_files(diffs) def allowed_diff_lines
diffs.first(allowed_diff_size).map do |diff| if diff_hard_limit_enabled?
Gitlab::Diff::File.new(diff) Commit::DIFF_HARD_LIMIT_LINES
else
Commit::DIFF_SAFE_LINES
end end
end end
def show_diff_size_warning?(diffs) def safe_diff_files(diffs)
diffs.size > allowed_diff_size lines = 0
safe_files = []
diffs.first(allowed_diff_size).each do |diff|
lines += diff.diff.lines.count
break if lines > allowed_diff_lines
safe_files << Gitlab::Diff::File.new(diff)
end
safe_files
end end
def diff_hard_limit_enabled? def diff_hard_limit_enabled?
......
...@@ -25,12 +25,16 @@ module EventsHelper ...@@ -25,12 +25,16 @@ module EventsHelper
def event_filter_link(key, tooltip) def event_filter_link(key, tooltip)
key = key.to_s key = key.to_s
active = if @event_filter.active? key active = 'active' if @event_filter.active?(key)
'active' link_opts = {
end class: 'event_filter_link',
id: "#{key}_event_filter",
title: "Filter by #{tooltip.downcase}",
data: { toggle: 'tooltip', placement: 'top' }
}
content_tag :li, class: "filter_icon #{active}" do content_tag :li, class: "filter_icon #{active}" do
link_to request.path, class: 'has_tooltip event_filter_link', id: "#{key}_event_filter", 'data-original-title' => 'Filter by ' + tooltip.downcase do link_to request.path, link_opts do
icon(icon_for_event[key]) + content_tag(:span, ' ' + tooltip) icon(icon_for_event[key]) + content_tag(:span, ' ' + tooltip)
end end
end end
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
= parallel_diff_btn = parallel_diff_btn
= render 'projects/diffs/stats', diffs: diffs = render 'projects/diffs/stats', diffs: diffs
- if show_diff_size_warning?(diffs) - diff_files = safe_diff_files(diffs)
= render 'projects/diffs/warning', diffs: diffs
- if diff_files.count < diffs.size
= render 'projects/diffs/warning', diffs: diffs, shown_files_count: diff_files.count
.files .files
- safe_diff_files(diffs).each_with_index do |diff_file, index| - diff_files.each_with_index do |diff_file, index|
= render 'projects/diffs/file', diff_file: diff_file, i: index, project: project = render 'projects/diffs/file', diff_file: diff_file, i: index, project: project
- if @diff_timeout - if @diff_timeout
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
= link_to "Email patch", merge_request_path(@merge_request, format: :patch), class: "btn btn-warning btn-sm" = link_to "Email patch", merge_request_path(@merge_request, format: :patch), class: "btn btn-warning btn-sm"
%p %p
To preserve performance only To preserve performance only
%strong #{allowed_diff_size} of #{diffs.size} %strong #{shown_files_count} of #{diffs.size}
files are displayed. files are displayed.
...@@ -73,4 +73,4 @@ cd /home/git/gitlab; \ ...@@ -73,4 +73,4 @@ cd /home/git/gitlab; \
sudo service gitlab start; \ sudo service gitlab start; \
sudo service nginx restart; \ sudo service nginx restart; \
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
``` ```
\ No newline at end of file
...@@ -94,7 +94,7 @@ sudo docker build --tag gitlab-data docker/data/ ...@@ -94,7 +94,7 @@ sudo docker build --tag gitlab-data docker/data/
sudo docker build --tag gitlab-app:7.10.1 docker/app/ sudo docker build --tag gitlab-app:7.10.1 docker/app/
``` ```
After this run the images as described in the prepivous section. After this run the images as described in the previous section.
We assume using a data volume container, this will simplify migrations and backups. We assume using a data volume container, this will simplify migrations and backups.
This empty container will exist to persist as volumes the 3 directories used by GitLab, so remember not to delete it. This empty container will exist to persist as volumes the 3 directories used by GitLab, so remember not to delete it.
...@@ -152,4 +152,4 @@ sudo docker push sytse/gitlab_data ...@@ -152,4 +152,4 @@ sudo docker push sytse/gitlab_data
## Troubleshooting ## Troubleshooting
Please see the [troubleshooting](troubleshooting.md) file in this directory. Please see the [troubleshooting](troubleshooting.md) file in this directory.
\ No newline at end of file
...@@ -5,7 +5,8 @@ describe DiffHelper do ...@@ -5,7 +5,8 @@ describe DiffHelper do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:commit) { project.commit(sample_commit.id) } let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.diffs.first } let(:diffs) { commit.diffs }
let(:diff) { diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff) } let(:diff_file) { Gitlab::Diff::File.new(diff) }
describe 'diff_hard_limit_enabled?' do describe 'diff_hard_limit_enabled?' do
...@@ -30,6 +31,57 @@ describe DiffHelper do ...@@ -30,6 +31,57 @@ describe DiffHelper do
end end
end end
describe 'allowed_diff_lines' do
it 'should return hard limit for number of lines in a diff if force diff is true' do
allow(controller).to receive(:params) { { force_show_diff: true } }
expect(allowed_diff_lines).to eq(50000)
end
it 'should return safe limit for numbers of lines a diff if force diff is false' do
expect(allowed_diff_lines).to eq(5000)
end
end
describe 'safe_diff_files' do
it 'should return all files from a commit that is smaller than safe limits' do
expect(safe_diff_files(diffs).length).to eq(2)
end
it 'should return only the first file if the diff line count in the 2nd file takes the total beyond safe limits' do
diffs[1].diff.stub(lines: [""] * 4999) #simulate 4999 lines
expect(safe_diff_files(diffs).length).to eq(1)
end
it 'should return all files from a commit that is beyond safe limit for numbers of lines if force diff is true' do
allow(controller).to receive(:params) { { force_show_diff: true } }
diffs[1].diff.stub(lines: [""] * 4999) #simulate 4999 lines
expect(safe_diff_files(diffs).length).to eq(2)
end
it 'should return only the first file if the diff line count in the 2nd file takes the total beyond hard limits' do
allow(controller).to receive(:params) { { force_show_diff: true } }
diffs[1].diff.stub(lines: [""] * 49999) #simulate 49999 lines
expect(safe_diff_files(diffs).length).to eq(1)
end
it 'should return only a safe number of file diffs if a commit touches more files than the safe limits' do
large_diffs = diffs * 100 #simulate 200 diffs
expect(safe_diff_files(large_diffs).length).to eq(100)
end
it 'should return all file diffs if a commit touches more files than the safe limits but force diff is true' do
allow(controller).to receive(:params) { { force_show_diff: true } }
large_diffs = diffs * 100 #simulate 200 diffs
expect(safe_diff_files(large_diffs).length).to eq(200)
end
it 'should return a limited file diffs if a commit touches more files than the hard limits and force diff is true' do
allow(controller).to receive(:params) { { force_show_diff: true } }
very_large_diffs = diffs * 1000 #simulate 2000 diffs
expect(safe_diff_files(very_large_diffs).length).to eq(1000)
end
end
describe 'parallel_diff' do describe 'parallel_diff' do
it 'should return an array of arrays containing the parsed diff' do it 'should return an array of arrays containing the parsed diff' do
expect(parallel_diff(diff_file, 0)). expect(parallel_diff(diff_file, 0)).
......
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