Commit 7fc185ab authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Ref contains oid check done by Gitaly

These two endpoints are in opt-out, and no one noticed. Has been running
on .com for 4 months now and considered stable.

Closes https://gitlab.com/gitlab-org/gitaly/issues/884
parent 40683268
---
title: Refs containting sha checks are done by Gitaly
merge_request:
author:
type: other
...@@ -1467,25 +1467,11 @@ module Gitlab ...@@ -1467,25 +1467,11 @@ module Gitlab
end end
def branch_names_contains_sha(sha) def branch_names_contains_sha(sha)
gitaly_migrate(:branch_names_contains_sha, gitaly_ref_client.branch_names_contains_sha(sha)
status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
if is_enabled
gitaly_ref_client.branch_names_contains_sha(sha)
else
refs_contains_sha('refs/heads/', sha)
end
end
end end
def tag_names_contains_sha(sha) def tag_names_contains_sha(sha)
gitaly_migrate(:tag_names_contains_sha, gitaly_ref_client.tag_names_contains_sha(sha)
status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
if is_enabled
gitaly_ref_client.tag_names_contains_sha(sha)
else
refs_contains_sha('refs/tags/', sha)
end
end
end end
def search_files_by_content(query, ref) def search_files_by_content(query, ref)
...@@ -1620,27 +1606,6 @@ module Gitlab ...@@ -1620,27 +1606,6 @@ module Gitlab
end end
end end
def refs_contains_sha(refs_prefix, sha)
refs_prefix << "/" unless refs_prefix.ends_with?('/')
# By forcing the output to %(refname) each line wiht a ref will start with
# the ref prefix. All other lines can be discarded.
args = %W(for-each-ref --contains=#{sha} --format=%(refname) #{refs_prefix})
names, code = run_git(args)
return [] unless code.zero?
refs = []
left_slice_count = refs_prefix.length
names.lines.each do |line|
next unless line.start_with?(refs_prefix)
refs << encode_utf8(line.rstrip[left_slice_count..-1])
end
refs
end
def rugged_write_config(full_path:) def rugged_write_config(full_path:)
rugged.config['gitlab.fullpath'] = full_path rugged.config['gitlab.fullpath'] = full_path
end end
......
...@@ -615,32 +615,22 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -615,32 +615,22 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
describe '#branch_names_contains_sha' do describe '#branch_names_contains_sha' do
shared_examples 'returning the right branches' do let(:head_id) { repository.rugged.head.target.oid }
let(:head_id) { repository.rugged.head.target.oid } let(:new_branch) { head_id }
let(:new_branch) { head_id } let(:utf8_branch) { 'branch-é' }
let(:utf8_branch) { 'branch-é' }
before do before do
repository.create_branch(new_branch, 'master') repository.create_branch(new_branch, 'master')
repository.create_branch(utf8_branch, 'master') repository.create_branch(utf8_branch, 'master')
end
after do
repository.delete_branch(new_branch)
repository.delete_branch(utf8_branch)
end
it 'displays that branch' do
expect(repository.branch_names_contains_sha(head_id)).to include('master', new_branch, utf8_branch)
end
end end
context 'when Gitaly is enabled' do after do
it_behaves_like 'returning the right branches' repository.delete_branch(new_branch)
repository.delete_branch(utf8_branch)
end end
context 'when Gitaly is disabled', :disable_gitaly do it 'displays that branch' do
it_behaves_like 'returning the right branches' expect(repository.branch_names_contains_sha(head_id)).to include('master', new_branch, utf8_branch)
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