Commit 467979c6 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'feature/migrate-repository-tags-to-gitaly' into 'master'

Migrate Repository#tags to Gitaly

Closes gitaly#411

See merge request !13092
parents 64131f04 cd5ae5cb
...@@ -391,7 +391,7 @@ gem 'vmstat', '~> 2.3.0' ...@@ -391,7 +391,7 @@ gem 'vmstat', '~> 2.3.0'
gem 'sys-filesystem', '~> 1.1.6' gem 'sys-filesystem', '~> 1.1.6'
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly', '~> 0.18.0' gem 'gitaly', '~> 0.21.0'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false
......
...@@ -269,7 +269,7 @@ GEM ...@@ -269,7 +269,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly (0.18.0) gitaly (0.21.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
...@@ -976,7 +976,7 @@ DEPENDENCIES ...@@ -976,7 +976,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly (~> 0.18.0) gitaly (~> 0.21.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.5.1) gitlab-markup (~> 1.5.1)
......
...@@ -164,20 +164,13 @@ module Gitlab ...@@ -164,20 +164,13 @@ module Gitlab
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/390 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/390
def tags def tags
rugged.references.each("refs/tags/*").map do |ref| gitaly_migrate(:tags) do |is_enabled|
message = nil if is_enabled
tags_from_gitaly
if ref.target.is_a?(Rugged::Tag::Annotation) else
tag_message = ref.target.message tags_from_rugged
if tag_message.respond_to?(:chomp)
message = tag_message.chomp
end
end end
end
target_commit = Gitlab::Git::Commit.find(self, ref.target)
Gitlab::Git::Tag.new(self, ref.name, ref.target, target_commit, message)
end.sort_by(&:name)
end end
# Returns true if the given tag exists # Returns true if the given tag exists
...@@ -1115,6 +1108,27 @@ module Gitlab ...@@ -1115,6 +1108,27 @@ module Gitlab
end end
end end
def tags_from_rugged
rugged.references.each("refs/tags/*").map do |ref|
message = nil
if ref.target.is_a?(Rugged::Tag::Annotation)
tag_message = ref.target.message
if tag_message.respond_to?(:chomp)
message = tag_message.chomp
end
end
target_commit = Gitlab::Git::Commit.find(self, ref.target)
Gitlab::Git::Tag.new(self, ref.name, ref.target, target_commit, message)
end.sort_by(&:name)
end
def tags_from_gitaly
gitaly_ref_client.tags
end
def gitaly_migrate(method, &block) def gitaly_migrate(method, &block)
Gitlab::GitalyClient.migrate(method, &block) Gitlab::GitalyClient.migrate(method, &block)
rescue GRPC::NotFound => e rescue GRPC::NotFound => e
......
...@@ -52,6 +52,12 @@ module Gitlab ...@@ -52,6 +52,12 @@ module Gitlab
consume_branches_response(response) consume_branches_response(response)
end end
def tags
request = Gitaly::FindAllTagsRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_all_tags, request)
consume_tags_response(response)
end
private private
def consume_refs_response(response) def consume_refs_response(response)
...@@ -79,6 +85,25 @@ module Gitlab ...@@ -79,6 +85,25 @@ module Gitlab
end end
end end
def consume_tags_response(response)
response.flat_map do |message|
message.tags.map do |gitaly_tag|
if gitaly_tag.target_commit.present?
commit = GitalyClient::Commit.new(@repository, gitaly_tag.target_commit)
gitaly_commit = Gitlab::Git::Commit.new(commit)
end
Gitlab::Git::Tag.new(
@repository,
encode!(gitaly_tag.name.dup),
gitaly_tag.id,
gitaly_commit,
encode!(gitaly_tag.message.chomp)
)
end
end
end
def commit_from_local_branches_response(response) def commit_from_local_branches_response(response)
# Git messages have no encoding enforcements. However, in the UI we only # Git messages have no encoding enforcements. However, in the UI we only
# handle UTF-8, so basically we cross our fingers that the message force # handle UTF-8, so basically we cross our fingers that the message force
......
...@@ -3,23 +3,33 @@ require "spec_helper" ...@@ -3,23 +3,33 @@ require "spec_helper"
describe Gitlab::Git::Tag, seed_helper: true do describe Gitlab::Git::Tag, seed_helper: true do
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) }
describe 'first tag' do shared_examples 'Gitlab::Git::Repository#tags' do
let(:tag) { repository.tags.first } describe 'first tag' do
let(:tag) { repository.tags.first }
it { expect(tag.name).to eq("v1.0.0") } it { expect(tag.name).to eq("v1.0.0") }
it { expect(tag.target).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") } it { expect(tag.target).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") }
it { expect(tag.dereferenced_target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") } it { expect(tag.dereferenced_target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") }
it { expect(tag.message).to eq("Release") } it { expect(tag.message).to eq("Release") }
end end
describe 'last tag' do
let(:tag) { repository.tags.last }
describe 'last tag' do it { expect(tag.name).to eq("v1.2.1") }
let(:tag) { repository.tags.last } it { expect(tag.target).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") }
it { expect(tag.dereferenced_target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") }
it { expect(tag.message).to eq("Version 1.2.1") }
end
it { expect(tag.name).to eq("v1.2.1") } it { expect(repository.tags.size).to eq(SeedRepo::Repo::TAGS.size) }
it { expect(tag.target).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") }
it { expect(tag.dereferenced_target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") }
it { expect(tag.message).to eq("Version 1.2.1") }
end end
it { expect(repository.tags.size).to eq(SeedRepo::Repo::TAGS.size) } context 'when Gitaly tags feature is enabled' do
it_behaves_like 'Gitlab::Git::Repository#tags'
end
context 'when Gitaly tags feature is disabled', skip_gitaly_mock: true do
it_behaves_like 'Gitlab::Git::Repository#tags'
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment