Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /lib/gitlab/diff
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r--lib/gitlab/diff/file.rb8
-rw-r--r--lib/gitlab/diff/formatters/base_formatter.rb11
-rw-r--r--lib/gitlab/diff/position.rb13
3 files changed, 30 insertions, 2 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index d1398ddb642..72dcc4fde71 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -225,6 +225,10 @@ module Gitlab
new_path.presence || old_path
end
+ def file_hash
+ Digest::SHA1.hexdigest(file_path)
+ end
+
def added_lines
@stats&.additions || diff_lines.count(&:added?)
end
@@ -237,6 +241,10 @@ module Gitlab
"#{file_path}-#{new_file?}-#{deleted_file?}-#{renamed_file?}"
end
+ def file_identifier_hash
+ Digest::SHA1.hexdigest(file_identifier)
+ end
+
def diffable?
repository.attributes(file_path).fetch('diff') { true }
end
diff --git a/lib/gitlab/diff/formatters/base_formatter.rb b/lib/gitlab/diff/formatters/base_formatter.rb
index 9704aed82c1..31eeadc45f7 100644
--- a/lib/gitlab/diff/formatters/base_formatter.rb
+++ b/lib/gitlab/diff/formatters/base_formatter.rb
@@ -6,6 +6,7 @@ module Gitlab
class BaseFormatter
attr_reader :old_path
attr_reader :new_path
+ attr_reader :file_identifier_hash
attr_reader :base_sha
attr_reader :start_sha
attr_reader :head_sha
@@ -16,6 +17,7 @@ module Gitlab
attrs[:diff_refs] = diff_file.diff_refs
attrs[:old_path] = diff_file.old_path
attrs[:new_path] = diff_file.new_path
+ attrs[:file_identifier_hash] = diff_file.file_identifier_hash
end
if diff_refs = attrs[:diff_refs]
@@ -26,6 +28,7 @@ module Gitlab
@old_path = attrs[:old_path]
@new_path = attrs[:new_path]
+ @file_identifier_hash = attrs[:file_identifier_hash]
@base_sha = attrs[:base_sha]
@start_sha = attrs[:start_sha]
@head_sha = attrs[:head_sha]
@@ -36,7 +39,7 @@ module Gitlab
end
def to_h
- {
+ out = {
base_sha: base_sha,
start_sha: start_sha,
head_sha: head_sha,
@@ -44,6 +47,12 @@ module Gitlab
new_path: new_path,
position_type: position_type
}
+
+ if Feature.enabled?(:file_identifier_hash)
+ out[:file_identifier_hash] = file_identifier_hash
+ end
+
+ out
end
def position_type
diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb
index 10ad23b7774..e43f301c280 100644
--- a/lib/gitlab/diff/position.rb
+++ b/lib/gitlab/diff/position.rb
@@ -9,6 +9,7 @@ module Gitlab
delegate :old_path,
:new_path,
+ :file_identifier_hash,
:base_sha,
:start_sha,
:head_sha,
@@ -156,13 +157,23 @@ module Gitlab
position_type == 'text'
end
+ def find_diff_file_from(diffable)
+ diff_files = diffable.diffs(diff_options).diff_files
+
+ if Feature.enabled?(:file_identifier_hash) && file_identifier_hash.present?
+ diff_files.find { |df| df.file_identifier_hash == file_identifier_hash }
+ else
+ diff_files.first
+ end
+ end
+
private
def find_diff_file(repository)
return unless diff_refs.complete?
return unless comparison = diff_refs.compare_in(repository.project)
- comparison.diffs(diff_options).diff_files.first
+ find_diff_file_from(comparison)
end
def get_formatter_class(type)