diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-05-02 11:12:15 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-05-07 16:37:49 +0300 |
commit | 713c7fa9a56fbbe301fb21b36fc9002aee0901e8 (patch) | |
tree | ca2f054016341f0353035823568e936a85c7460b /lib | |
parent | 40655a48f13efb3a0a18f0b0bc4727c786df6a77 (diff) |
Client implementation GetRawChanges
Part of https://gitlab.com/gitlab-org/gitaly/issues/1138
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/raw_diff_change.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 6 |
3 files changed, 34 insertions, 9 deletions
diff --git a/lib/gitlab/git/raw_diff_change.rb b/lib/gitlab/git/raw_diff_change.rb index 92f6c45ce25..6042e993113 100644 --- a/lib/gitlab/git/raw_diff_change.rb +++ b/lib/gitlab/git/raw_diff_change.rb @@ -6,7 +6,15 @@ module Gitlab attr_reader :blob_id, :blob_size, :old_path, :new_path, :operation def initialize(raw_change) - parse(raw_change) + if raw_change.is_a?(Gitaly::GetRawChangesResponse::RawChange) + @blob_id = raw_change.blob_id + @blob_size = raw_change.size + @old_path = raw_change.old_path.presence + @new_path = raw_change.new_path.presence + @operation = raw_change.operation&.downcase || :unknown + else + parse(raw_change) + end end private diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 60ce8cfc195..bc61834ff7d 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -581,19 +581,30 @@ module Gitlab # 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) - result = [] + 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!) } + 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}" + 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 + + result end end - - result + rescue ArgumentError => e + raise Gitlab::Git::Repository::GitError.new(e) end # Returns the SHA of the most recent common ancestor of +from+ and +to+ diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 498187997e1..662b3d6cd0c 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -293,6 +293,12 @@ module Gitlab response = GitalyClient.call(@storage, :repository_service, :calculate_checksum, request) response.checksum.presence end + + def raw_changes_between(from, to) + request = Gitaly::GetRawChangesRequest.new(repository: @gitaly_repo, from_revision: from, to_revision: to) + + GitalyClient.call(@storage, :repository_service, :get_raw_changes, request) + end end end end |