summaryrefslogtreecommitdiff
path: root/lib/gitlab/bare_repository_import
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-12-19 23:58:54 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-01-03 16:13:32 -0200
commit582678b5f5e1399603610b20149acf1d305309d3 (patch)
treecaa198556ab907935d5d8ce419c88dffb3a10a8a /lib/gitlab/bare_repository_import
parentd3d617354e0f0da7c8930dd9c089f437603dea20 (diff)
downloadgitlab-ce-582678b5f5e1399603610b20149acf1d305309d3.tar.gz
Import directory tree created with hashed storage using import rake task
Diffstat (limited to 'lib/gitlab/bare_repository_import')
-rw-r--r--lib/gitlab/bare_repository_import/importer.rb9
-rw-r--r--lib/gitlab/bare_repository_import/repository.rb36
2 files changed, 33 insertions, 12 deletions
diff --git a/lib/gitlab/bare_repository_import/importer.rb b/lib/gitlab/bare_repository_import/importer.rb
index 64e41d42709..1f0fdc6685e 100644
--- a/lib/gitlab/bare_repository_import/importer.rb
+++ b/lib/gitlab/bare_repository_import/importer.rb
@@ -14,13 +14,13 @@ module Gitlab
repos_to_import.each do |repo_path|
bare_repo = Gitlab::BareRepositoryImport::Repository.new(import_path, repo_path)
- if bare_repo.hashed? || bare_repo.wiki?
+ unless bare_repo.processable?
log " * Skipping repo #{bare_repo.repo_path}".color(:yellow)
next
end
- log "Processing #{repo_path}".color(:yellow)
+ log "Processing #{repo_path} -> #{bare_repo.project_full_path}".color(:yellow)
new(user, bare_repo).create_project_if_needed
end
@@ -62,6 +62,11 @@ module Gitlab
if project.persisted? && mv_repo(project)
log " * Created #{project.name} (#{project_full_path})".color(:green)
+ # We'd need to keep track of project full path otherwise directory tree
+ # created with hashed storage enabled cannot be usefully imported using
+ # the import rake task.
+ project.write_repository_config(:fullpath, project.full_path)
+
ProjectCacheWorker.perform_async(project.id)
else
log " * Failed trying to create #{project.name} (#{project_full_path})".color(:red)
diff --git a/lib/gitlab/bare_repository_import/repository.rb b/lib/gitlab/bare_repository_import/repository.rb
index fa7891c8dcc..b5907875460 100644
--- a/lib/gitlab/bare_repository_import/repository.rb
+++ b/lib/gitlab/bare_repository_import/repository.rb
@@ -6,39 +6,55 @@ module Gitlab
def initialize(root_path, repo_path)
@root_path = root_path
@repo_path = repo_path
-
@root_path << '/' unless root_path.ends_with?('/')
+ full_path =
+ if hashed? && !wiki?
+ repository.config.get('gitlab.fullpath')
+ else
+ repo_relative_path
+ end
+
# Split path into 'all/the/namespaces' and 'project_name'
- @group_path, _, @project_name = repo_relative_path.rpartition('/')
+ @group_path, _, @project_name = full_path.to_s.rpartition('/')
end
def wiki_exists?
File.exist?(wiki_path)
end
- def wiki?
- @wiki ||= repo_path.end_with?('.wiki.git')
- end
-
def wiki_path
@wiki_path ||= repo_path.sub(/\.git$/, '.wiki.git')
end
- def hashed?
- @hashed ||= group_path.start_with?('@hashed')
- end
-
def project_full_path
@project_full_path ||= "#{group_path}/#{project_name}"
end
+ def processable?
+ return false if wiki?
+
+ group_path.present? && project_name.present?
+ end
+
private
+ def wiki?
+ @wiki ||= repo_path.end_with?('.wiki.git')
+ end
+
+ def hashed?
+ @hashed ||= repo_relative_path.include?('@hashed')
+ end
+
def repo_relative_path
# Remove root path and `.git` at the end
repo_path[@root_path.size...-4]
end
+
+ def repository
+ @repository ||= Rugged::Repository.new(repo_path)
+ end
end
end
end