summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-05-10 09:29:55 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2018-05-14 10:46:17 -0500
commit5d63e91a8387a3faf95eff4ac6f6a28be4a53377 (patch)
tree04d46b863dc272080365f50014ba4eef5ef47cef
parent9cf92f40b0d17b1a55152b54b86e9f4270979db6 (diff)
downloadgitlab-ce-5d63e91a8387a3faf95eff4ac6f6a28be4a53377.tar.gz
Merge branch 'backport-rd-5566-improve-performance-of-repository-size-limit-check' into 'master'
Backport some changes from gitlab-ee!5476 See merge request gitlab-org/gitlab-ce!18760
-rw-r--r--lib/gitlab/git/blob.rb6
-rw-r--r--lib/gitlab/git/raw_diff_change.rb3
-rw-r--r--lib/gitlab/git/repository.rb41
-rw-r--r--spec/lib/gitlab/git/blob_spec.rb20
-rw-r--r--spec/lib/gitlab/git/raw_diff_change_spec.rb2
5 files changed, 55 insertions, 17 deletions
diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb
index eabcf46cf58..d78d29b7ac6 100644
--- a/lib/gitlab/git/blob.rb
+++ b/lib/gitlab/git/blob.rb
@@ -62,6 +62,12 @@ module Gitlab
end
end
+ # Returns an array of Blob instances just with the metadata, that means
+ # the data attribute has no content.
+ def batch_metadata(repository, blob_references)
+ batch(repository, blob_references, blob_size_limit: 0)
+ end
+
# Find LFS blobs given an array of sha ids
# Returns array of Gitlab::Git::Blob
# Does not guarantee blob data will be set
diff --git a/lib/gitlab/git/raw_diff_change.rb b/lib/gitlab/git/raw_diff_change.rb
index 6042e993113..98de9328071 100644
--- a/lib/gitlab/git/raw_diff_change.rb
+++ b/lib/gitlab/git/raw_diff_change.rb
@@ -28,13 +28,14 @@ module Gitlab
# 85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee
def parse(raw_change)
@blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(' ', 4)
+ @blob_size = @blob_size.to_i
@operation = extract_operation
@old_path, @new_path = extract_paths(raw_paths)
end
def extract_paths(file_path)
case operation
- when :renamed
+ when :copied, :renamed
file_path.split(/\t/)
when :deleted
[file_path, nil]
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index b145001a024..5d47f8b2075 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -579,29 +579,40 @@ module Gitlab
count_commits(from: from, to: to, **options)
end
+ # Counts the amount of commits between `from` and `to`.
+ def count_commits_between(from, to, options = {})
+ count_commits(from: from, to: to, **options)
+ end
+
# old_rev and new_rev are commit ID's
# the result of this method is an array of Gitlab::Git::RawDiffChange
def raw_changes_between(old_rev, new_rev)
- gitaly_migrate(:raw_changes_between) do |is_enabled|
- if is_enabled
- gitaly_repository_client.raw_changes_between(old_rev, new_rev)
- .each_with_object([]) do |msg, arr|
- msg.raw_changes.each { |change| arr << ::Gitlab::Git::RawDiffChange.new(change) }
- end
- else
- result = []
+ @raw_changes_between ||= {}
- circuit_breaker.perform do
- Open3.pipeline_r(git_diff_cmd(old_rev, new_rev), format_git_cat_file_script, git_cat_file_cmd) do |last_stdout, wait_threads|
- last_stdout.each_line { |line| result << ::Gitlab::Git::RawDiffChange.new(line.chomp!) }
+ @raw_changes_between[[old_rev, new_rev]] ||= begin
+ return [] if new_rev.blank? || new_rev == Gitlab::Git::BLANK_SHA
- if wait_threads.any? { |waiter| !waiter.value&.success? }
- raise ::Gitlab::Git::Repository::GitError, "Unabled to obtain changes between #{old_rev} and #{new_rev}"
+ gitaly_migrate(:raw_changes_between) do |is_enabled|
+ if is_enabled
+ gitaly_repository_client.raw_changes_between(old_rev, new_rev)
+ .each_with_object([]) do |msg, arr|
+ msg.raw_changes.each { |change| arr << ::Gitlab::Git::RawDiffChange.new(change) }
+ end
+ else
+ result = []
+
+ circuit_breaker.perform do
+ Open3.pipeline_r(git_diff_cmd(old_rev, new_rev), format_git_cat_file_script, git_cat_file_cmd) do |last_stdout, wait_threads|
+ last_stdout.each_line { |line| result << ::Gitlab::Git::RawDiffChange.new(line.chomp!) }
+
+ if wait_threads.any? { |waiter| !waiter.value&.success? }
+ raise ::Gitlab::Git::Repository::GitError, "Unabled to obtain changes between #{old_rev} and #{new_rev}"
+ end
end
end
- end
- result
+ result
+ end
end
end
rescue ArgumentError => e
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb
index 67d898e787e..e2547ed0311 100644
--- a/spec/lib/gitlab/git/blob_spec.rb
+++ b/spec/lib/gitlab/git/blob_spec.rb
@@ -251,6 +251,26 @@ describe Gitlab::Git::Blob, seed_helper: true do
end
end
+ describe '.batch_metadata' do
+ let(:blob_references) do
+ [
+ [SeedRepo::Commit::ID, "files/ruby/popen.rb"],
+ [SeedRepo::Commit::ID, 'six']
+ ]
+ end
+
+ subject { described_class.batch_metadata(repository, blob_references) }
+
+ it 'returns an empty data attribute' do
+ first_blob, last_blob = subject
+
+ expect(first_blob.data).to be_blank
+ expect(first_blob.path).to eq("files/ruby/popen.rb")
+ expect(last_blob.data).to be_blank
+ expect(last_blob.path).to eq("six")
+ end
+ end
+
describe '.batch_lfs_pointers' do
let(:tree_object) { repository.rugged.rev_parse('master^{tree}') }
diff --git a/spec/lib/gitlab/git/raw_diff_change_spec.rb b/spec/lib/gitlab/git/raw_diff_change_spec.rb
index eedde34534f..a0bb37fd84a 100644
--- a/spec/lib/gitlab/git/raw_diff_change_spec.rb
+++ b/spec/lib/gitlab/git/raw_diff_change_spec.rb
@@ -12,7 +12,7 @@ describe Gitlab::Git::RawDiffChange do
expect(change.operation).to eq(:unknown)
expect(change.old_path).to be_blank
expect(change.new_path).to be_blank
- expect(change.blob_size).to be_blank
+ expect(change.blob_size).to eq(0)
end
end