diff options
author | Sean McGivern <sean@gitlab.com> | 2019-03-04 12:22:44 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-03-04 12:22:44 +0300 |
commit | fd50ba4240469615458d5554e24613b432b6c6c0 (patch) | |
tree | e94346e0c16b5dea928653f54dc5288689886393 /lib/gitlab/git/rugged_impl/repository.rb | |
parent | d4a2cd793992f96a24170a4d356f7849cf10e9cb (diff) | |
parent | fb6a4e21d4a5142e72ac5864fae29192cfc59d64 (diff) |
Merge branch 'sh-rugged-find-commit' into 'master'
Bring back Rugged implementation of find_commit
See merge request gitlab-org/gitlab-ce!25477
Diffstat (limited to 'lib/gitlab/git/rugged_impl/repository.rb')
-rw-r--r-- | lib/gitlab/git/rugged_impl/repository.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/gitlab/git/rugged_impl/repository.rb b/lib/gitlab/git/rugged_impl/repository.rb new file mode 100644 index 00000000000..135c47017b3 --- /dev/null +++ b/lib/gitlab/git/rugged_impl/repository.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +# NOTE: This code is legacy. Do not add/modify code here unless you have +# discussed with the Gitaly team. See +# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code +# for more details. + +# rubocop:disable Gitlab/ModuleWithInstanceVariables +module Gitlab + module Git + module RuggedImpl + module Repository + FEATURE_FLAGS = %i(rugged_find_commit).freeze + + def alternate_object_directories + relative_object_directories.map { |d| File.join(path, d) } + end + + ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES = %w[ + GIT_OBJECT_DIRECTORY_RELATIVE + GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE + ].freeze + + def relative_object_directories + Gitlab::Git::HookEnv.all(gl_repository).values_at(*ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES).flatten.compact + end + + def rugged + @rugged ||= ::Rugged::Repository.new(path, alternates: alternate_object_directories) + rescue ::Rugged::RepositoryError, ::Rugged::OSError + raise ::Gitlab::Git::Repository::NoRepository.new('no repository for such path') + end + + def cleanup + @rugged&.close + end + + # Return the object that +revspec+ points to. If +revspec+ is an + # annotated tag, then return the tag's target instead. + def rev_parse_target(revspec) + obj = rugged.rev_parse(revspec) + Ref.dereference_object(obj) + end + end + end + end +end +# rubocop:enable Gitlab/ModuleWithInstanceVariables |