summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-01 14:21:16 -0800
committerStan Hu <stanhu@gmail.com>2019-03-04 12:21:31 -0800
commit9d294467bda78c358c868bd2ba3e39c01aea44f8 (patch)
treef13ce8dd6d6ef9751e034d25b2905c001c2073fb /lib
parentdb70f74dfdb0c74866a3b753a302777e7c784241 (diff)
downloadgitlab-ce-9d294467bda78c358c868bd2ba3e39c01aea44f8.tar.gz
Bring back Rugged implementation of CommitIsAncestor
This brings back some of the changes in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20095. For users using Gitaly on top of NFS, accessing the Git data directly via Rugged is more performant than Gitaly. This merge request introduces the feature flag `rugged_commit_is_ancestor` to activate the Rugged path. Part of four Rugged changes identified in https://gitlab.com/gitlab-org/gitlab-ce/issues/57317.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb2
-rw-r--r--lib/gitlab/git/rugged_impl/repository.rb27
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 2bfff8397e8..912253252a8 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -11,7 +11,7 @@ module Gitlab
include Gitlab::Git::WrapsGitalyErrors
include Gitlab::EncodingHelper
include Gitlab::Utils::StrongMemoize
- include Gitlab::Git::RuggedImpl::Repository
+ prepend Gitlab::Git::RuggedImpl::Repository
SEARCH_CONTEXT_LINES = 3
REV_LIST_COMMIT_LIMIT = 2_000
diff --git a/lib/gitlab/git/rugged_impl/repository.rb b/lib/gitlab/git/rugged_impl/repository.rb
index 135c47017b3..d4500573235 100644
--- a/lib/gitlab/git/rugged_impl/repository.rb
+++ b/lib/gitlab/git/rugged_impl/repository.rb
@@ -10,7 +10,9 @@ module Gitlab
module Git
module RuggedImpl
module Repository
- FEATURE_FLAGS = %i(rugged_find_commit).freeze
+ extend ::Gitlab::Utils::Override
+
+ FEATURE_FLAGS = %i(rugged_find_commit rugged_tree_entries rugged_tree_entry rugged_commit_is_ancestor).freeze
def alternate_object_directories
relative_object_directories.map { |d| File.join(path, d) }
@@ -41,6 +43,29 @@ module Gitlab
obj = rugged.rev_parse(revspec)
Ref.dereference_object(obj)
end
+
+ override :ancestor?
+ def ancestor?(from, to)
+ if Feature.enabled?(:rugged_commit_is_ancestor)
+ rugged_is_ancestor?(from, to)
+ else
+ super
+ end
+ end
+
+ def rugged_is_ancestor?(ancestor_id, descendant_id)
+ return false if ancestor_id.nil? || descendant_id.nil?
+
+ rugged_merge_base(ancestor_id, descendant_id) == ancestor_id
+ rescue Rugged::OdbError
+ false
+ end
+
+ def rugged_merge_base(from, to)
+ rugged.merge_base(from, to)
+ rescue Rugged::ReferenceError
+ nil
+ end
end
end
end