Commit 29668aec authored by Nick Thomas's avatar Nick Thomas

Use `git update-ref --stdin -z` to speed up TestEnv.set_repo_refs

Previously, we were calling `git update-ref <ref> <sha>` about 30 times per
test using `create(:project)` or similar.
parent 5ef2bd19
...@@ -204,20 +204,18 @@ module TestEnv ...@@ -204,20 +204,18 @@ module TestEnv
end end
def set_repo_refs(repo_path, branch_sha) def set_repo_refs(repo_path, branch_sha)
instructions = branch_sha.map {|branch, sha| "update refs/heads/#{branch}\x00#{sha}\x00" }.join("\x00") << "\x00"
update_refs = %W(#{Gitlab.config.git.bin_path} update-ref --stdin -z)
reset = proc do
IO.popen(update_refs, "w") {|io| io.write(instructions) }
$?.success?
end
Dir.chdir(repo_path) do Dir.chdir(repo_path) do
branch_sha.each do |branch, sha|
# Try to reset without fetching to avoid using the network. # Try to reset without fetching to avoid using the network.
reset = %W(#{Gitlab.config.git.bin_path} update-ref refs/heads/#{branch} #{sha}) unless reset.call
unless system(*reset) raise 'Could not fetch test seed repository.' unless system(*%W(#{Gitlab.config.git.bin_path} fetch origin))
if system(*%W(#{Gitlab.config.git.bin_path} fetch origin)) raise 'The fetched test seed does not contain the required revision.' unless reset.call
unless system(*reset)
raise 'The fetched test seed '\
'does not contain the required revision.'
end
else
raise 'Could not fetch test seed repository.'
end
end
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