summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2016-11-04 04:47:39 +0000
committerNick Thomas <nick@gitlab.com>2016-11-07 11:24:06 +0000
commit29668aec46f0c7479bf974e6d27ace866c800940 (patch)
tree5bf44fba3edacb745a42cc8f5a99ae9efa75a62b /spec
parent5ef2bd192aa9b3ecbfc23e83c6984e2a818fb736 (diff)
downloadgitlab-ce-29668aec46f0c7479bf974e6d27ace866c800940.tar.gz
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.
Diffstat (limited to 'spec')
-rw-r--r--spec/support/test_env.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index c79975d8667..778e665500d 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -204,20 +204,18 @@ module TestEnv
end
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
- branch_sha.each do |branch, sha|
- # Try to reset without fetching to avoid using the network.
- reset = %W(#{Gitlab.config.git.bin_path} update-ref refs/heads/#{branch} #{sha})
- unless system(*reset)
- if system(*%W(#{Gitlab.config.git.bin_path} fetch origin))
- 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
+ # Try to reset without fetching to avoid using the network.
+ unless reset.call
+ raise 'Could not fetch test seed repository.' unless system(*%W(#{Gitlab.config.git.bin_path} fetch origin))
+ raise 'The fetched test seed does not contain the required revision.' unless reset.call
end
end
end