diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-04-18 15:24:16 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-04-18 15:24:16 +0300 |
commit | cbd4a653dfe97ccfed6d5a0b703d75ead4ac4754 (patch) | |
tree | c8575dee7b8a73d97632996a9eb054927a39a077 | |
parent | b155626bcd46ece9d3900dc9b4fe08a0a29ce1e1 (diff) | |
parent | 29c9c11653909db580062346e9a16ed2657c1142 (diff) |
Merge branch 'gitaly-ruby-monkey' into 'master'
Make monkey patches easier to find
See merge request gitlab-org/gitaly!679
-rw-r--r-- | ruby/lib/gitlab/git.rb | 88 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/gitlab_projects.rb | 36 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 57 |
3 files changed, 95 insertions, 86 deletions
diff --git a/ruby/lib/gitlab/git.rb b/ruby/lib/gitlab/git.rb index b3bbd8e97..9ceb46eea 100644 --- a/ruby/lib/gitlab/git.rb +++ b/ruby/lib/gitlab/git.rb @@ -39,92 +39,8 @@ Dir["#{dir}/git/**/*.rb"].sort.each do |ruby_file| end require_relative 'git/gitaly_remote_repository.rb' - -module Gitlab - module Git - class Repository - def self.from_gitaly(gitaly_repository, call) - new( - gitaly_repository, - GitalyServer.repo_path(call), - GitalyServer.gl_repository(call), - Gitlab::Git::GitlabProjects.from_gitaly(gitaly_repository, call), - GitalyServer.repo_alt_dirs(call) - ) - end - - attr_reader :path - - def initialize(gitaly_repository, path, gl_repository, gitlab_projects, combined_alt_dirs="") - @gitaly_repository = gitaly_repository - - @alternate_object_directories = combined_alt_dirs - .split(File::PATH_SEPARATOR) - .map { |d| File.join(path, d) } - - @storage = gitaly_repository.storage_name - @relative_path = gitaly_repository.relative_path - @path = path - @gl_repository = gl_repository - @gitlab_projects = gitlab_projects - @attributes = Gitlab::Git::InfoAttributes.new(path) - end - - def circuit_breaker - FakeCircuitBreaker - end - - def gitaly_repository - @gitaly_repository - end - - def alternate_object_directories - @alternate_object_directories - end - - def relative_object_directories - raise "don't use relative object directories in gitaly-ruby" - end - - # This method was prematurely deleted from gitlab-ce. TODO: implement it in Go. - def fsck - msg, status = run_git(%W[--git-dir=#{path} fsck], nice: true) - raise GitError.new("Could not fsck repository: #{msg}") unless status.zero? - end - end - - class GitlabProjects - def self.from_gitaly(gitaly_repository, call) - storage_path = GitalyServer.storage_path(call) - - Gitlab::Git::GitlabProjects.new( - storage_path, - gitaly_repository.relative_path, - global_hooks_path: Gitlab.config.gitlab_shell.hooks_path, - logger: Rails.logger - ) - end - - def initialize(shard_path, repository_relative_path, global_hooks_path:, logger:) - @shard_path = shard_path - @repository_relative_path = repository_relative_path - - @logger = logger - @global_hooks_path = global_hooks_path - @output = StringIO.new - end - - - def shard_name - raise "don't use shard_name in gitaly-ruby" - end - - def shard_path - @shard_path - end - end - end -end +require_relative 'git/repository.rb' +require_relative 'git/gitlab_projects.rb' class String # Because we are not rendering HTML, this is a no-op in gitaly-ruby. diff --git a/ruby/lib/gitlab/git/gitlab_projects.rb b/ruby/lib/gitlab/git/gitlab_projects.rb new file mode 100644 index 000000000..f2d0004de --- /dev/null +++ b/ruby/lib/gitlab/git/gitlab_projects.rb @@ -0,0 +1,36 @@ +module Gitlab + module Git + # These are monkey patches on top of the vendored version of GitlabProjects. + class GitlabProjects + def self.from_gitaly(gitaly_repository, call) + storage_path = GitalyServer.storage_path(call) + + Gitlab::Git::GitlabProjects.new( + storage_path, + gitaly_repository.relative_path, + global_hooks_path: Gitlab.config.gitlab_shell.hooks_path, + logger: Rails.logger + ) + end + + def initialize(shard_path, repository_relative_path, global_hooks_path:, logger:) + @shard_path = shard_path + @repository_relative_path = repository_relative_path + + @logger = logger + @global_hooks_path = global_hooks_path + @output = StringIO.new + end + + + def shard_name + raise "don't use shard_name in gitaly-ruby" + end + + def shard_path + @shard_path + end + end + end +end + diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb new file mode 100644 index 000000000..b4ef62f81 --- /dev/null +++ b/ruby/lib/gitlab/git/repository.rb @@ -0,0 +1,57 @@ +module Gitlab + module Git + # These are monkey patches on top of the vendored version of Repository. + class Repository + def self.from_gitaly(gitaly_repository, call) + new( + gitaly_repository, + GitalyServer.repo_path(call), + GitalyServer.gl_repository(call), + Gitlab::Git::GitlabProjects.from_gitaly(gitaly_repository, call), + GitalyServer.repo_alt_dirs(call) + ) + end + + attr_reader :path + + def initialize(gitaly_repository, path, gl_repository, gitlab_projects, combined_alt_dirs="") + @gitaly_repository = gitaly_repository + + @alternate_object_directories = combined_alt_dirs + .split(File::PATH_SEPARATOR) + .map { |d| File.join(path, d) } + + @storage = gitaly_repository.storage_name + @relative_path = gitaly_repository.relative_path + @path = path + @gl_repository = gl_repository + @gitlab_projects = gitlab_projects + @attributes = Gitlab::Git::InfoAttributes.new(path) + end + + def circuit_breaker + FakeCircuitBreaker + end + + def gitaly_repository + @gitaly_repository + end + + def alternate_object_directories + @alternate_object_directories + end + + def relative_object_directories + raise "don't use relative object directories in gitaly-ruby" + end + + # This method is mandatory and no longer exists in gitlab-ce. + # TODO: implement it in Go because it is slow, and gitaly-ruby gets restarted a lot. + def fsck + msg, status = run_git(%W[--git-dir=#{path} fsck], nice: true) + raise GitError.new("Could not fsck repository: #{msg}") unless status.zero? + end + end + end +end + |