summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-05-14 20:03:15 +0000
committerRobert Speicher <robert@gitlab.com>2017-05-14 20:03:15 +0000
commit133d2bb40a6c8516a8c8c487f347fa99bd7e907c (patch)
treea7ca8b65fc5ddf1a802dd8735d22fd0851886048 /lib
parentf70075b6d09e8cdf0898afb3d8696b881228c363 (diff)
parent99feed6e00e0f012f7e879a710e8b478b6160d2f (diff)
downloadgitlab-ce-133d2bb40a6c8516a8c8c487f347fa99bd7e907c.tar.gz
Merge branch 'fix/support-commit-deltas-only-for-gitaly' into 'master'
Fetch commit deltas from Gitaly Closes gitaly#199 See merge request !11122
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/diff.rb20
-rw-r--r--lib/gitlab/gitaly_client/commit.rb54
2 files changed, 45 insertions, 29 deletions
diff --git a/lib/gitlab/git/diff.rb b/lib/gitlab/git/diff.rb
index 019be151353..31d1b66b4f7 100644
--- a/lib/gitlab/git/diff.rb
+++ b/lib/gitlab/git/diff.rb
@@ -183,6 +183,8 @@ module Gitlab
when Gitaly::CommitDiffResponse
init_from_gitaly(raw_diff)
prune_diff_if_eligible(collapse)
+ when Gitaly::CommitDelta
+ init_from_gitaly(raw_diff)
when nil
raise "Nil as raw diff passed"
else
@@ -278,15 +280,15 @@ module Gitlab
end
end
- def init_from_gitaly(diff_msg)
- @diff = diff_msg.raw_chunks.join
- @new_path = encode!(diff_msg.to_path.dup)
- @old_path = encode!(diff_msg.from_path.dup)
- @a_mode = diff_msg.old_mode.to_s(8)
- @b_mode = diff_msg.new_mode.to_s(8)
- @new_file = diff_msg.from_id == BLANK_SHA
- @renamed_file = diff_msg.from_path != diff_msg.to_path
- @deleted_file = diff_msg.to_id == BLANK_SHA
+ def init_from_gitaly(msg)
+ @diff = msg.raw_chunks.join if msg.respond_to?(:raw_chunks)
+ @new_path = encode!(msg.to_path.dup)
+ @old_path = encode!(msg.from_path.dup)
+ @a_mode = msg.old_mode.to_s(8)
+ @b_mode = msg.new_mode.to_s(8)
+ @new_file = msg.from_id == BLANK_SHA
+ @renamed_file = msg.from_path != msg.to_path
+ @deleted_file = msg.to_id == BLANK_SHA
end
def prune_diff_if_eligible(collapse = false)
diff --git a/lib/gitlab/gitaly_client/commit.rb b/lib/gitlab/gitaly_client/commit.rb
index 8e9323b05e1..15c57420fb2 100644
--- a/lib/gitlab/gitaly_client/commit.rb
+++ b/lib/gitlab/gitaly_client/commit.rb
@@ -5,41 +5,55 @@ module Gitlab
# See http://stackoverflow.com/a/40884093/1856239 and https://github.com/git/git/blob/3ad8b5bf26362ac67c9020bf8c30eee54a84f56d/cache.h#L1011-L1012
EMPTY_TREE_ID = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'.freeze
- attr_accessor :stub
-
def initialize(repository)
@gitaly_repo = repository.gitaly_repository
- @stub = Gitaly::Commit::Stub.new(nil, nil, channel_override: repository.gitaly_channel)
+ @repository = repository
end
def is_ancestor(ancestor_id, child_id)
+ stub = Gitaly::Commit::Stub.new(nil, nil, channel_override: @repository.gitaly_channel)
request = Gitaly::CommitIsAncestorRequest.new(
repository: @gitaly_repo,
ancestor_id: ancestor_id,
child_id: child_id
)
- @stub.commit_is_ancestor(request).value
+ stub.commit_is_ancestor(request).value
+ end
+
+ def diff_from_parent(commit, options = {})
+ request_params = commit_diff_request_params(commit, options)
+ request_params[:ignore_whitespace_change] = options.fetch(:ignore_whitespace_change, false)
+
+ response = diff_service_stub.commit_diff(Gitaly::CommitDiffRequest.new(request_params))
+ Gitlab::Git::DiffCollection.new(response, options)
end
- class << self
- def diff_from_parent(commit, options = {})
- repository = commit.project.repository
- gitaly_repo = repository.gitaly_repository
- stub = Gitaly::Diff::Stub.new(nil, nil, channel_override: repository.gitaly_channel)
- parent = commit.parents[0]
- parent_id = parent ? parent.id : EMPTY_TREE_ID
- request = Gitaly::CommitDiffRequest.new(
- repository: gitaly_repo,
- left_commit_id: parent_id,
- right_commit_id: commit.id,
- ignore_whitespace_change: options.fetch(:ignore_whitespace_change, false),
- paths: options.fetch(:paths, [])
- )
-
- Gitlab::Git::DiffCollection.new(stub.commit_diff(request), options)
+ def commit_deltas(commit)
+ request_params = commit_diff_request_params(commit)
+
+ response = diff_service_stub.commit_delta(Gitaly::CommitDeltaRequest.new(request_params))
+ response.flat_map do |msg|
+ msg.deltas.map { |d| Gitlab::Git::Diff.new(d) }
end
end
+
+ private
+
+ def commit_diff_request_params(commit, options = {})
+ parent_id = commit.parents[0]&.id || EMPTY_TREE_ID
+
+ {
+ repository: @gitaly_repo,
+ left_commit_id: parent_id,
+ right_commit_id: commit.id,
+ paths: options.fetch(:paths, [])
+ }
+ end
+
+ def diff_service_stub
+ Gitaly::Diff::Stub.new(nil, nil, channel_override: @repository.gitaly_channel)
+ end
end
end
end