Commit 87467127 authored by Maxim Rydkin's avatar Maxim Rydkin

replace `is_ancestor?` with `ancestor?`

parent 5f72aaa3
...@@ -49,7 +49,7 @@ class Deployment < ActiveRecord::Base ...@@ -49,7 +49,7 @@ class Deployment < ActiveRecord::Base
# created before then could have a `sha` referring to a commit that no # created before then could have a `sha` referring to a commit that no
# longer exists in the repository, so just ignore those. # longer exists in the repository, so just ignore those.
begin begin
project.repository.is_ancestor?(commit.id, sha) project.repository.ancestor?(commit.id, sha)
rescue Rugged::OdbError rescue Rugged::OdbError
false false
end end
......
...@@ -944,7 +944,7 @@ class Repository ...@@ -944,7 +944,7 @@ class Repository
if branch_commit if branch_commit
same_head = branch_commit.id == root_ref_commit.id same_head = branch_commit.id == root_ref_commit.id
!same_head && is_ancestor?(branch_commit.id, root_ref_commit.id) !same_head && ancestor?(branch_commit.id, root_ref_commit.id)
else else
nil nil
end end
...@@ -958,12 +958,12 @@ class Repository ...@@ -958,12 +958,12 @@ class Repository
nil nil
end end
def is_ancestor?(ancestor_id, descendant_id) def ancestor?(ancestor_id, descendant_id)
return false if ancestor_id.nil? || descendant_id.nil? return false if ancestor_id.nil? || descendant_id.nil?
Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled| Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled|
if is_enabled if is_enabled
raw_repository.is_ancestor?(ancestor_id, descendant_id) raw_repository.ancestor?(ancestor_id, descendant_id)
else else
rugged_is_ancestor?(ancestor_id, descendant_id) rugged_is_ancestor?(ancestor_id, descendant_id)
end end
......
...@@ -439,7 +439,7 @@ module Gitlab ...@@ -439,7 +439,7 @@ module Gitlab
end end
# Returns true is +from+ is direct ancestor to +to+, otherwise false # Returns true is +from+ is direct ancestor to +to+, otherwise false
def is_ancestor?(from, to) def ancestor?(from, to)
gitaly_commit_client.is_ancestor(from, to) gitaly_commit_client.is_ancestor(from, to)
end end
......
...@@ -2036,23 +2036,23 @@ describe Repository, models: true do ...@@ -2036,23 +2036,23 @@ describe Repository, models: true do
end end
end end
describe '#is_ancestor?' do describe '#ancestor?' do
let(:commit) { repository.commit } let(:commit) { repository.commit }
let(:ancestor) { commit.parents.first } let(:ancestor) { commit.parents.first }
context 'with Gitaly enabled' do context 'with Gitaly enabled' do
it 'it is an ancestor' do it 'it is an ancestor' do
expect(repository.is_ancestor?(ancestor.id, commit.id)).to eq(true) expect(repository.ancestor?(ancestor.id, commit.id)).to eq(true)
end end
it 'it is not an ancestor' do it 'it is not an ancestor' do
expect(repository.is_ancestor?(commit.id, ancestor.id)).to eq(false) expect(repository.ancestor?(commit.id, ancestor.id)).to eq(false)
end end
it 'returns false on nil-values' do it 'returns false on nil-values' do
expect(repository.is_ancestor?(nil, commit.id)).to eq(false) expect(repository.ancestor?(nil, commit.id)).to eq(false)
expect(repository.is_ancestor?(ancestor.id, nil)).to eq(false) expect(repository.ancestor?(ancestor.id, nil)).to eq(false)
expect(repository.is_ancestor?(nil, nil)).to eq(false) expect(repository.ancestor?(nil, nil)).to eq(false)
end end
end end
...@@ -2063,17 +2063,17 @@ describe Repository, models: true do ...@@ -2063,17 +2063,17 @@ describe Repository, models: true do
end end
it 'it is an ancestor' do it 'it is an ancestor' do
expect(repository.is_ancestor?(ancestor.id, commit.id)).to eq(true) expect(repository.ancestor?(ancestor.id, commit.id)).to eq(true)
end end
it 'it is not an ancestor' do it 'it is not an ancestor' do
expect(repository.is_ancestor?(commit.id, ancestor.id)).to eq(false) expect(repository.ancestor?(commit.id, ancestor.id)).to eq(false)
end end
it 'returns false on nil-values' do it 'returns false on nil-values' do
expect(repository.is_ancestor?(nil, commit.id)).to eq(false) expect(repository.ancestor?(nil, commit.id)).to eq(false)
expect(repository.is_ancestor?(ancestor.id, nil)).to eq(false) expect(repository.ancestor?(ancestor.id, nil)).to eq(false)
expect(repository.is_ancestor?(nil, nil)).to eq(false) expect(repository.ancestor?(nil, nil)).to eq(false)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment