diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-04-11 12:58:52 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-04-11 12:58:52 +0000 |
commit | b2f57a561f0540f8e33c2d580252e6f95e9cf182 (patch) | |
tree | 943c03c8f06729ba8953e0c4f4054bebf981c6ac /lib | |
parent | c079474b8a32583c92a080e2641c8b03460db712 (diff) | |
parent | c830b8e3b782da466d73892728a8ddb869e7d47c (diff) | |
download | gitlab-ce-b2f57a561f0540f8e33c2d580252e6f95e9cf182.tar.gz |
Merge branch 'zj-info-attributes' into 'master'
Client implementation for InfoAttributes
See merge request gitlab-org/gitlab-ce!18261
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/attributes_parser.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/git/info_attributes.rb | 49 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 9 |
4 files changed, 35 insertions, 59 deletions
diff --git a/lib/gitlab/git/attributes_parser.rb b/lib/gitlab/git/attributes_parser.rb index d8aeabb6cba..08f4d7d4f5c 100644 --- a/lib/gitlab/git/attributes_parser.rb +++ b/lib/gitlab/git/attributes_parser.rb @@ -3,12 +3,8 @@ module Gitlab # Class for parsing Git attribute files and extracting the attributes for # file patterns. class AttributesParser - def initialize(attributes_data) + def initialize(attributes_data = "") @data = attributes_data || "" - - if @data.is_a?(File) - @patterns = parse_file - end end # Returns all the Git attributes for the given path. @@ -28,7 +24,7 @@ module Gitlab # Returns a Hash containing the file patterns and their attributes. def patterns - @patterns ||= parse_file + @patterns ||= parse_data end # Parses an attribute string. @@ -91,8 +87,8 @@ module Gitlab private - # Parses the Git attributes file. - def parse_file + # Parses the Git attributes file contents. + def parse_data pairs = [] comment = '#' diff --git a/lib/gitlab/git/info_attributes.rb b/lib/gitlab/git/info_attributes.rb deleted file mode 100644 index e79a440950b..00000000000 --- a/lib/gitlab/git/info_attributes.rb +++ /dev/null @@ -1,49 +0,0 @@ -# Gitaly note: JV: not sure what to make of this class. Why does it use -# the full disk path of the repository to look up attributes This is -# problematic in Gitaly, because Gitaly hides the full disk path to the -# repository from gitlab-ce. - -module Gitlab - module Git - # Parses gitattributes at `$GIT_DIR/info/attributes` - # - # Unlike Rugged this parser only needs a single IO call (a call to `open`), - # vastly reducing the time spent in extracting attributes. - # - # This class _only_ supports parsing the attributes file located at - # `$GIT_DIR/info/attributes` as GitLab doesn't use any other files - # (`.gitattributes` is copied to this particular path). - # - # Basic usage: - # - # attributes = Gitlab::Git::InfoAttributes.new(some_repo.path) - # - # attributes.attributes('README.md') # => { "eol" => "lf } - class InfoAttributes - delegate :attributes, :patterns, to: :parser - - # path - The path to the Git repository. - def initialize(path) - @repo_path = File.expand_path(path) - end - - def parser - @parser ||= begin - if File.exist?(attributes_path) - File.open(attributes_path, 'r') do |file_handle| - AttributesParser.new(file_handle) - end - else - AttributesParser.new("") - end - end - end - - private - - def attributes_path - @attributes_path ||= File.join(@repo_path, 'info/attributes') - end - end - end -end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 1a58db4e63e..1a0a793564e 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -105,7 +105,6 @@ module Gitlab ) @path = File.join(storage_path, @relative_path) @name = @relative_path.split("/").last - @attributes = Gitlab::Git::InfoAttributes.new(path) end def ==(other) @@ -993,11 +992,32 @@ module Gitlab raise InvalidRef end + def info_attributes + return @info_attributes if @info_attributes + + content = + gitaly_migrate(:get_info_attributes) do |is_enabled| + if is_enabled + gitaly_repository_client.info_attributes + else + attributes_path = File.join(File.expand_path(@path), 'info', 'attributes') + + if File.exist?(attributes_path) + File.read(attributes_path) + else + "" + end + end + end + + @info_attributes = AttributesParser.new(content) + end + # Returns the Git attributes for the given file path. # # See `Gitlab::Git::Attributes` for more information. def attributes(path) - @attributes.attributes(path) + info_attributes.attributes(path) end def gitattribute(path, name) diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 6441065f5fe..39057beefba 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -50,6 +50,15 @@ module Gitlab GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request) end + def info_attributes + request = Gitaly::GetInfoAttributesRequest.new(repository: @gitaly_repo) + + response = GitalyClient.call(@storage, :repository_service, :get_info_attributes, request) + response.each_with_object("") do |message, attributes| + attributes << message.attributes + end + end + def fetch_remote(remote, ssh_auth:, forced:, no_tags:, timeout:, prune: true) request = Gitaly::FetchRemoteRequest.new( repository: @gitaly_repo, remote: remote, force: forced, |