summaryrefslogtreecommitdiff
path: root/lib/gitlab/git/tag.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/git/tag.rb')
-rw-r--r--lib/gitlab/git/tag.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/gitlab/git/tag.rb b/lib/gitlab/git/tag.rb
index 8a8f7b051ed..f1560650569 100644
--- a/lib/gitlab/git/tag.rb
+++ b/lib/gitlab/git/tag.rb
@@ -1,17 +1,86 @@
module Gitlab
module Git
class Tag < Ref
+ extend Gitlab::EncodingHelper
+
attr_reader :object_sha
+ MAX_TAG_MESSAGE_DISPLAY_SIZE = 10.megabytes
+
+ class << self
+ def get_tag_message(repository, tag_name)
+ BatchLoader.for({ repository: repository, tag_name: tag_name }).batch do |items, loader|
+ items_by_repo = items.group_by { |i| i[:repository] }
+
+ items_by_repo.each do |repo, items|
+ tag_names = items.map { |i| i[:tag_name] }
+
+ messages = get_tag_messages(repository, tag_names)
+
+ messages.each do |name, message|
+ loader.call({ repository: repository, tag_name: name }, message)
+ end
+ end
+ end
+ end
+
+ def get_tag_messages(repository, tag_names)
+ repository.gitaly_migrate(:tag_messages) do |is_enabled|
+ if is_enabled
+ repository.gitaly_ref_client.get_tag_messages(tag_names)
+ else
+ tag_names.map do |name|
+ tag = repository.rugged.tags[name]
+ next [name, ""] unless tag
+
+ annotation = tag.annotation
+ next [name, ""] unless tag.annotation
+
+ [name, annotation.message]
+ end.to_h
+ end
+ end
+ end
+
+ def new_from_gitaly(repository, gitaly_tag)
+ if gitaly_tag.target_commit.present?
+ commit = Gitlab::Git::Commit.decorate(repository, gitaly_tag.target_commit)
+ end
+
+ tag = new(repository, encode!(gitaly_tag.name.dup), gitaly_tag.id, commit, encode!(gitaly_tag.message.chomp))
+ tag.init_from_gitaly(gitaly_tag)
+
+ tag
+ end
+ end
+
def initialize(repository, name, target, target_commit, message = nil)
super(repository, name, target, target_commit)
+ @repository = repository
@message = message
end
+ def init_from_gitaly(gitaly_tag)
+ @raw_tag = gitaly_tag
+ @message = message_from_gitaly_tag
+ end
+
def message
encode! @message
end
+
+ private
+
+ def message_from_gitaly_tag
+ return @raw_tag.message.dup if @raw_tag.message.present?
+
+ if @raw_tag.message_size > MAX_TAG_MESSAGE_DISPLAY_SIZE
+ '--tag message is too big'
+ else
+ self.class.get_tag_message(@repository, name)
+ end
+ end
end
end
end