diff options
Diffstat (limited to 'lib/gitlab/git/repository.rb')
-rw-r--r-- | lib/gitlab/git/repository.rb | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 312e05b5f54..1bf796e167d 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -398,7 +398,7 @@ module Gitlab end def new_blobs(newrevs, dynamic_timeout: nil) - newrevs = Array.wrap(newrevs).reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA } + newrevs = Array.wrap(newrevs).reject { |rev| rev.blank? || rev == ::Gitlab::Git::SHA1_BLANK_SHA } return [] if newrevs.empty? newrevs = newrevs.uniq.sort @@ -416,7 +416,7 @@ module Gitlab # GitalyClient.medium_timeout and dynamic timeout if the dynamic # timeout is set, otherwise it'll always use the medium timeout. def blobs(revisions, with_paths: false, dynamic_timeout: nil) - revisions = revisions.reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA } + revisions = revisions.reject { |rev| rev.blank? || rev == ::Gitlab::Git::SHA1_BLANK_SHA } return [] if revisions.blank? @@ -458,7 +458,7 @@ module Gitlab @raw_changes_between[[old_rev, new_rev]] ||= begin - return [] if new_rev.blank? || new_rev == Gitlab::Git::BLANK_SHA + return [] if new_rev.blank? || new_rev == Gitlab::Git::SHA1_BLANK_SHA wrapped_gitaly_errors do gitaly_repository_client.raw_changes_between(old_rev, new_rev) @@ -752,7 +752,7 @@ module Gitlab # new_sha # reference: # - # When new_sha is Gitlab::Git::BLANK_SHA, then this will be deleted + # When new_sha is Gitlab::Git::SHA1_BLANK_SHA, then this will be deleted def update_refs(ref_list) wrapped_gitaly_errors do gitaly_ref_client.update_refs(ref_list: ref_list) if ref_list.any? @@ -1089,6 +1089,10 @@ module Gitlab @praefect_info_client ||= Gitlab::GitalyClient::PraefectInfoService.new(self) end + def gitaly_analysis_client + @gitaly_analysis_client ||= Gitlab::GitalyClient::AnalysisService.new(self) + end + def branch_names_contains_sha(sha, limit: 0) gitaly_ref_client.branch_names_contains_sha(sha, limit: limit) end @@ -1202,6 +1206,12 @@ module Gitlab end end + def object_format + wrapped_gitaly_errors do + gitaly_repository_client.object_format.format + end + end + def get_file_attributes(revision, file_paths, attributes) wrapped_gitaly_errors do gitaly_repository_client @@ -1211,24 +1221,49 @@ module Gitlab end end - def object_format - wrapped_gitaly_errors do - gitaly_repository_client.object_format.format - end - end - # rubocop: disable CodeReuse/ActiveRecord -- not an active record operation - def detect_generated_files(revision, paths) - return Set.new if paths.blank? - - get_file_attributes(revision, paths, Gitlab::Git::ATTRIBUTE_OVERRIDES[:generated]) + def detect_generated_files(base, head, changed_paths) + return Set.new if changed_paths.blank? + + # Check .gitattributes overrides first + checked_files = get_file_attributes( + base, + changed_paths.map(&:path), + Gitlab::Git::ATTRIBUTE_OVERRIDES[:generated] + ).map { |attrs| { path: attrs[:path], generated: attrs[:value] == "set" } } + + # Check automatic generated file detection for the remaining paths + overridden_paths = checked_files.pluck(:path) + remainder = changed_paths.reject { |changed_path| overridden_paths.include?(changed_path.path) } + checked_files += check_blobs_generated(base, head, remainder) if remainder.present? + + checked_files + .select { |attrs| attrs[:generated] } .pluck(:path) .to_set + + rescue Gitlab::Git::CommandError => e + # An exception can be raised due to an unknown revision or paths. + Gitlab::ErrorTracking.track_exception( + e, + gl_project_path: @gl_project_path, + base: base, + head: head, + paths: changed_paths.map(&:path) + ) + + Set.new end # rubocop: enable CodeReuse/ActiveRecord private + def check_blobs_generated(base, head, changed_paths) + wrapped_gitaly_errors do + gitaly_analysis_client.check_blobs_generated(base, head, changed_paths) + end + end + def repository_info_size_megabytes bytes = gitaly_repository_client.repository_info.size |