summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2011-12-05 09:43:53 +0200
committerDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2011-12-05 09:43:53 +0200
commitbdc658095c6bc7e7a2a49447b404156f3f947fe1 (patch)
tree4458e4804b0e5b21807ca16e4ade1d3211f5f404 /lib
parent8134fe0efe287f6512b7684d4c654b2d43f3df9d (diff)
downloadgitlab-ce-bdc658095c6bc7e7a2a49447b404156f3f947fe1.tar.gz
refcatoring. cleaning after gitosis
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlabhq/git_host.rb15
-rw-r--r--lib/gitlabhq/gitosis.rb76
-rw-r--r--lib/tasks/gitolite_rebuild.rake11
3 files changed, 20 insertions, 82 deletions
diff --git a/lib/gitlabhq/git_host.rb b/lib/gitlabhq/git_host.rb
index 714d92f537a..9a6eecb3f0a 100644
--- a/lib/gitlabhq/git_host.rb
+++ b/lib/gitlabhq/git_host.rb
@@ -1,18 +1,21 @@
require File.join(Rails.root, "lib", "gitlabhq", "gitolite")
-require File.join(Rails.root, "lib", "gitlabhq", "gitosis")
module Gitlabhq
class GitHost
def self.system
- if GIT_HOST["system"] == "gitosis"
- Gitlabhq::Gitosis
- else
- Gitlabhq::Gitolite
- end
+ Gitlabhq::Gitolite
end
def self.admin_uri
GIT_HOST["admin_uri"]
end
+
+ def self.url_to_repo(path)
+ if !GIT_HOST["port"] or GIT_HOST["port"] == 22
+ "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git"
+ else
+ "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git"
+ end
+ end
end
end
diff --git a/lib/gitlabhq/gitosis.rb b/lib/gitlabhq/gitosis.rb
deleted file mode 100644
index a3dbcc80b22..00000000000
--- a/lib/gitlabhq/gitosis.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-require 'inifile'
-require 'timeout'
-require 'fileutils'
-
-module Gitlabhq
- class Gitosis
- class AccessDenied < StandardError; end
-
- def pull
- # create tmp dir
- @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}")
-
- Dir.mkdir @local_dir
-
- `git clone #{GitHost.admin_uri} #{@local_dir}/gitosis`
- end
-
- def push
- Dir.chdir(File.join(@local_dir, "gitosis"))
- `git add -A`
- `git commit -am "Gitlab"`
- `git push`
- Dir.chdir(Rails.root)
-
- FileUtils.rm_rf(@local_dir)
- end
-
- def configure
- status = Timeout::timeout(20) do
- File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f|
- begin
- f.flock(File::LOCK_EX)
- pull
- yield(self)
- push
- ensure
- f.flock(File::LOCK_UN)
- end
- end
- end
- rescue Exception => ex
- raise Gitosis::AccessDenied.new("gitosis timeout")
- end
-
- def destroy_project(project)
- `sudo -u git rm -rf #{project.path_to_repo}`
-
- conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
-
- conf.delete_section("group #{project.path}")
-
- conf.write
- end
-
- #update or create
- def update_keys(user, key)
- File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) }
- end
-
- def delete_key(user)
- File.unlink(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"))
- `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub`
- end
-
- #update or create
- def update_project(repo_name, name_writers)
- # write config file
- conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
-
- conf["group #{repo_name}"]['writable'] = repo_name
- conf["group #{repo_name}"]['members'] = name_writers.join(' ')
-
- conf.write
- end
- end
-end
diff --git a/lib/tasks/gitolite_rebuild.rake b/lib/tasks/gitolite_rebuild.rake
new file mode 100644
index 00000000000..5cf496196eb
--- /dev/null
+++ b/lib/tasks/gitolite_rebuild.rake
@@ -0,0 +1,11 @@
+desc "Rebuild each project at gitolite config"
+task :gitolite_rebuild => :environment do
+ puts "Starting..."
+ Project.find_each(:batch_size => 100) do |project|
+ puts
+ puts "=== #{project.name}"
+ project.update_repository
+ puts
+ end
+ puts "Done"
+end