summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2017-03-03 14:41:46 +0200
committerJames Lopez <james@jameslopez.es>2017-03-15 10:32:50 +0100
commit8b2a13a107913692d3e172599161264eebac96fd (patch)
tree4d2811f8ae3f3e2c246e3dede95c801a32ad30b3
parent9226ce9e3090dcedcb5c9fa8595d75b5eb295726 (diff)
downloadgitlab-ce-fix/speed-gh-pr-import.tar.gz
Fetch GH PR source refs in bulkfix/speed-gh-pr-import
-rw-r--r--app/models/repository.rb5
-rw-r--r--lib/gitlab/github_import/importer.rb12
-rw-r--r--lib/gitlab/github_import/pull_request_formatter.rb4
3 files changed, 18 insertions, 3 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 6ab04440ca8..840ad386875 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -1032,6 +1032,11 @@ class Repository
Gitlab::Popen.popen(args, path_to_repo)
end
+ def fetch_refs(source_path, refspecs)
+ args = %W(#{Gitlab.config.git.bin_path} fetch --no-tags -f #{source_path}) + refspecs
+ Gitlab::Popen.popen(args, path_to_repo)
+ end
+
def create_ref(ref, ref_path)
fetch_ref(path_to_repo, ref, ref_path)
end
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index eea4a91f17d..0c7c9327c50 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -130,13 +130,23 @@ module Gitlab
def import_pull_requests
fetch_resources(:pull_requests, repo, state: :all, sort: :created, direction: :asc, per_page: 100) do |pull_requests|
+ project.repository.expire_branches_cache
+
+ refspecs = pull_requests.map do |raw|
+ gh_pull_request = PullRequestFormatter.new(project, raw, client)
+ next if gh_pull_request.source_branch_exists?
+
+ "pull/#{gh_pull_request.number}/head:#{gh_pull_request.source_branch_name}"
+ end
+
+ project.repository.fetch_refs(repo_url, refspecs.compact)
+
pull_requests.each do |raw|
gh_pull_request = PullRequestFormatter.new(project, raw, client)
next unless gh_pull_request.valid?
begin
- restore_source_branch(gh_pull_request) unless gh_pull_request.source_branch_exists?
restore_target_branch(gh_pull_request) unless gh_pull_request.target_branch_exists?
merge_request = gh_pull_request.create!
diff --git a/lib/gitlab/github_import/pull_request_formatter.rb b/lib/gitlab/github_import/pull_request_formatter.rb
index add7236e339..ed90c3617fd 100644
--- a/lib/gitlab/github_import/pull_request_formatter.rb
+++ b/lib/gitlab/github_import/pull_request_formatter.rb
@@ -39,7 +39,7 @@ module Gitlab
def source_branch_name
@source_branch_name ||= begin
if cross_project?
- "pull/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}"
+ "pull-source/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}"
else
source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}"
end
@@ -52,7 +52,7 @@ module Gitlab
def target_branch_name
@target_branch_name ||= begin
- target_branch_exists? ? target_branch_ref : "pull/#{number}/#{target_branch_ref}"
+ target_branch_exists? ? target_branch_ref : "pull-target/#{number}/#{target_branch_ref}"
end
end