summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-28 17:22:45 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-28 17:22:45 +0200
commit1c5876eb7b2deb069d919bd19b51c9f6218e0f41 (patch)
tree0d93953103153bcadc96ee9688a1cca43a9711a0 /lib
parentb4f16faafd5bff1683996152b49342743a0f1a8b (diff)
downloadgitlab-ce-1c5876eb7b2deb069d919bd19b51c9f6218e0f41.tar.gz
Do gitolite calls async. Remove satellite with project remove
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/backend/gitolite.rb14
-rw-r--r--lib/gitlab/backend/gitolite_config.rb38
-rw-r--r--lib/gitlab/popen.rb18
-rw-r--r--lib/gitlab/satellite/satellite.rb12
-rw-r--r--lib/tasks/sidekiq.rake2
5 files changed, 55 insertions, 29 deletions
diff --git a/lib/gitlab/backend/gitolite.rb b/lib/gitlab/backend/gitolite.rb
index 3b8a2090f73..d026b76f5ef 100644
--- a/lib/gitlab/backend/gitolite.rb
+++ b/lib/gitlab/backend/gitolite.rb
@@ -22,7 +22,8 @@ module Gitlab
end
end
- def update_repository project
+ def update_repository project_id
+ project = Project.find(project_id)
config.update_project!(project)
end
@@ -33,8 +34,15 @@ module Gitlab
end
end
- def remove_repository project
- config.destroy_project!(project)
+ # Remove repository from gitolite
+ #
+ # name - project path with namespace
+ #
+ # Ex.
+ # remove_repository("gitlab/gitlab-ci")
+ #
+ def remove_repository(name)
+ config.destroy_project!(name)
end
def url_to_repo path
diff --git a/lib/gitlab/backend/gitolite_config.rb b/lib/gitlab/backend/gitolite_config.rb
index e4ebd595a93..748f9d74390 100644
--- a/lib/gitlab/backend/gitolite_config.rb
+++ b/lib/gitlab/backend/gitolite_config.rb
@@ -4,6 +4,8 @@ require 'fileutils'
module Gitlab
class GitoliteConfig
+ include Gitlab::Popen
+
class PullError < StandardError; end
class PushError < StandardError; end
class BrokenGitolite < StandardError; end
@@ -87,12 +89,14 @@ module Gitlab
Gitlab::GitLogger.error(message)
end
- def destroy_project(project)
- # do rm-rf only if repository exists
- if project.repository
- FileUtils.rm_rf(project.repository.path_to_repo)
- end
- conf.rm_repo(project.path_with_namespace)
+ def path_to_repo(name)
+ File.join(Gitlab.config.gitolite.repos_path, "#{name}.git")
+ end
+
+ def destroy_project(name)
+ full_path = path_to_repo(name)
+ FileUtils.rm_rf(full_path) if File.exists?(full_path)
+ conf.rm_repo(name)
end
def clean_repo repo_name
@@ -210,14 +214,14 @@ module Gitlab
end
def push
- output, status = popen('git add -A')
+ output, status = popen('git add -A', tmp_conf_path)
raise "Git add failed." unless status.zero?
# git commit returns 0 on success, and 1 if there is nothing to commit
- output, status = popen('git commit -m "GitLab"')
+ output, status = popen('git commit -m "GitLab"', tmp_conf_path)
raise "Git add failed." unless [0,1].include?(status)
- output, status = popen('git push')
+ output, status = popen('git push', tmp_conf_path)
if output =~ /remote\: FATAL/
raise BrokenGitolite, output
@@ -230,20 +234,8 @@ module Gitlab
end
end
- def popen(cmd, path = nil)
- path ||= File.join(config_tmp_dir,'gitolite')
- vars = { "PWD" => path }
- options = { :chdir => path }
-
- @cmd_output = ""
- @cmd_status = 0
- Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
- @cmd_status = wait_thr.value.exitstatus
- @cmd_output << stdout.read
- @cmd_output << stderr.read
- end
-
- return @cmd_output, @cmd_status
+ def tmp_conf_path
+ File.join(config_tmp_dir,'gitolite')
end
end
end
diff --git a/lib/gitlab/popen.rb b/lib/gitlab/popen.rb
new file mode 100644
index 00000000000..f2cfd8073e3
--- /dev/null
+++ b/lib/gitlab/popen.rb
@@ -0,0 +1,18 @@
+module Gitlab
+ module Popen
+ def popen(cmd, path)
+ vars = { "PWD" => path }
+ options = { :chdir => path }
+
+ @cmd_output = ""
+ @cmd_status = 0
+ Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
+ @cmd_status = wait_thr.value.exitstatus
+ @cmd_output << stdout.read
+ @cmd_output << stderr.read
+ end
+
+ return @cmd_output, @cmd_status
+ end
+ end
+end
diff --git a/lib/gitlab/satellite/satellite.rb b/lib/gitlab/satellite/satellite.rb
index 164af55d895..d8e8f58963b 100644
--- a/lib/gitlab/satellite/satellite.rb
+++ b/lib/gitlab/satellite/satellite.rb
@@ -3,6 +3,8 @@ module Gitlab
module Satellite
class Satellite
+ include Gitlab::Popen
+
PARKING_BRANCH = "__parking_branch"
attr_accessor :project
@@ -24,8 +26,10 @@ module Gitlab
end
def create
- create_cmd = "git clone #{project.url_to_repo} #{path}"
- if system(create_cmd)
+ output, status = popen("git clone #{project.url_to_repo} #{path}",
+ Gitlab.config.satellites.path)
+
+ if status.zero?
true
else
Gitlab::GitLogger.error("Failed to create satellite for #{project.name_with_namespace}")
@@ -66,6 +70,10 @@ module Gitlab
@repo ||= Grit::Repo.new(path)
end
+ def destroy
+ FileUtils.rm_rf(path)
+ end
+
private
# Clear the working directory
diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake
index 0d2ec6f332c..e4eb0e6776f 100644
--- a/lib/tasks/sidekiq.rake
+++ b/lib/tasks/sidekiq.rake
@@ -6,7 +6,7 @@ namespace :sidekiq do
desc "GITLAB | Start sidekiq"
task :start do
- run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &"
+ run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitolite,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &"
end
def pidfile