diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-03-11 11:56:19 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-03-13 13:28:17 +0000 |
commit | 9df7dda2d366174b80fd401b696931c638fb1b6c (patch) | |
tree | f33cf303de523875502e4c62007a3f0ea31cca96 /lib | |
parent | 812b64ed86fd1c80658877488a6ea7c4372f2a07 (diff) | |
download | gitlab-ce-9df7dda2d366174b80fd401b696931c638fb1b6c.tar.gz |
Merge branch 'sh-rugged-commit-tree-entry' into 'master'
Bring back Rugged implementation of commit_tree_entry
See merge request gitlab-org/gitlab-ce!25896
(cherry picked from commit 97357c5bb6594be793c1af332bed8f942f2d72d2)
4ee08fd1 Add back Rugged support for retrieving a commit tree entry
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/commit.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/git/rugged_impl/commit.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/git/rugged_impl/repository.rb | 2 |
3 files changed, 30 insertions, 1 deletions
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 491e4b47196..e5bbd500e98 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -314,11 +314,16 @@ module Gitlab def tree_entry(path) return unless path.present? + commit_tree_entry(path) + end + + def commit_tree_entry(path) # We're only interested in metadata, so limit actual data to 1 byte # since Gitaly doesn't support "send no data" option. entry = @repository.gitaly_commit_client.tree_entry(id, path, 1) return unless entry + # To be compatible with the rugged format entry = entry.to_h entry.delete(:data) entry[:name] = File.basename(path) diff --git a/lib/gitlab/git/rugged_impl/commit.rb b/lib/gitlab/git/rugged_impl/commit.rb index 251802878c3..f6777dfa0c3 100644 --- a/lib/gitlab/git/rugged_impl/commit.rb +++ b/lib/gitlab/git/rugged_impl/commit.rb @@ -43,6 +43,30 @@ module Gitlab end end + override :commit_tree_entry + def commit_tree_entry(path) + if Feature.enabled?(:rugged_commit_tree_entry) + rugged_tree_entry(path) + else + super + end + end + + # Is this the same as Blob.find_entry_by_path ? + def rugged_tree_entry(path) + rugged_commit.tree.path(path) + rescue Rugged::TreeError + nil + end + + def rugged_commit + @rugged_commit ||= if raw_commit.is_a?(Rugged::Commit) + raw_commit + else + @repository.rev_parse_target(id) + end + end + def init_from_rugged(commit) author = commit.author committer = commit.committer diff --git a/lib/gitlab/git/rugged_impl/repository.rb b/lib/gitlab/git/rugged_impl/repository.rb index fe0120b1199..c0a91f59ab9 100644 --- a/lib/gitlab/git/rugged_impl/repository.rb +++ b/lib/gitlab/git/rugged_impl/repository.rb @@ -12,7 +12,7 @@ module Gitlab module Repository extend ::Gitlab::Utils::Override - FEATURE_FLAGS = %i(rugged_find_commit rugged_tree_entries rugged_tree_entry rugged_commit_is_ancestor).freeze + FEATURE_FLAGS = %i(rugged_find_commit rugged_tree_entries rugged_tree_entry rugged_commit_is_ancestor rugged_commit_tree_entry).freeze def alternate_object_directories relative_object_directories.map { |d| File.join(path, d) } |