Merge branch 'git-write-ref-prep' into 'master'
Gitlab::Git::Repository#write_ref client-prep take 2 Closes gitaly#793 See merge request gitlab-org/gitlab-ce!16287
This commit is contained in:
commit
4fc0a09017
4 changed files with 19 additions and 11 deletions
|
@ -1149,7 +1149,7 @@ class Project < ActiveRecord::Base
|
||||||
def change_head(branch)
|
def change_head(branch)
|
||||||
if repository.branch_exists?(branch)
|
if repository.branch_exists?(branch)
|
||||||
repository.before_change_head
|
repository.before_change_head
|
||||||
repository.write_ref('HEAD', "refs/heads/#{branch}")
|
repository.raw_repository.write_ref('HEAD', "refs/heads/#{branch}", shell: false)
|
||||||
repository.copy_gitattributes(branch)
|
repository.copy_gitattributes(branch)
|
||||||
repository.after_change_head
|
repository.after_change_head
|
||||||
reload_default_branch
|
reload_default_branch
|
||||||
|
|
|
@ -260,7 +260,7 @@ class Repository
|
||||||
|
|
||||||
# This will still fail if the file is corrupted (e.g. 0 bytes)
|
# This will still fail if the file is corrupted (e.g. 0 bytes)
|
||||||
begin
|
begin
|
||||||
write_ref(keep_around_ref_name(sha), sha)
|
raw_repository.write_ref(keep_around_ref_name(sha), sha, shell: false)
|
||||||
rescue Rugged::ReferenceError => ex
|
rescue Rugged::ReferenceError => ex
|
||||||
Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
|
Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
|
||||||
rescue Rugged::OSError => ex
|
rescue Rugged::OSError => ex
|
||||||
|
@ -274,10 +274,6 @@ class Repository
|
||||||
ref_exists?(keep_around_ref_name(sha))
|
ref_exists?(keep_around_ref_name(sha))
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_ref(ref_path, sha)
|
|
||||||
rugged.references.create(ref_path, sha, force: true)
|
|
||||||
end
|
|
||||||
|
|
||||||
def diverging_commit_counts(branch)
|
def diverging_commit_counts(branch)
|
||||||
root_ref_hash = raw_repository.commit(root_ref).id
|
root_ref_hash = raw_repository.commit(root_ref).id
|
||||||
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
|
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
|
||||||
|
|
|
@ -1103,14 +1103,27 @@ module Gitlab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_ref(ref_path, ref)
|
def write_ref(ref_path, ref, old_ref: nil, shell: true)
|
||||||
|
if shell
|
||||||
|
shell_write_ref(ref_path, ref, old_ref)
|
||||||
|
else
|
||||||
|
rugged_write_ref(ref_path, ref)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def shell_write_ref(ref_path, ref, old_ref)
|
||||||
raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ')
|
raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ')
|
||||||
raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00")
|
raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00")
|
||||||
|
raise ArgumentError, "invalid old_ref #{old_ref.inspect}" if !old_ref.nil? && old_ref.include?("\x00")
|
||||||
|
|
||||||
input = "update #{ref_path}\x00#{ref}\x00\x00"
|
input = "update #{ref_path}\x00#{ref}\x00#{old_ref}\x00"
|
||||||
run_git!(%w[update-ref --stdin -z]) { |stdin| stdin.write(input) }
|
run_git!(%w[update-ref --stdin -z]) { |stdin| stdin.write(input) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rugged_write_ref(ref_path, ref)
|
||||||
|
rugged.references.create(ref_path, ref, force: true)
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_ref(source_repository, source_ref:, target_ref:)
|
def fetch_ref(source_repository, source_ref:, target_ref:)
|
||||||
Gitlab::Git.check_namespace!(source_repository)
|
Gitlab::Git.check_namespace!(source_repository)
|
||||||
source_repository = RemoteRepository.new(source_repository) unless source_repository.is_a?(RemoteRepository)
|
source_repository = RemoteRepository.new(source_repository) unless source_repository.is_a?(RemoteRepository)
|
||||||
|
|
|
@ -1871,9 +1871,8 @@ describe Project do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates the new reference with rugged' do
|
it 'creates the new reference with rugged' do
|
||||||
expect(project.repository.rugged.references).to receive(:create).with('HEAD',
|
expect(project.repository.raw_repository).to receive(:write_ref).with('HEAD', "refs/heads/#{project.default_branch}", shell: false)
|
||||||
"refs/heads/#{project.default_branch}",
|
|
||||||
force: true)
|
|
||||||
project.change_head(project.default_branch)
|
project.change_head(project.default_branch)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue