* use svnsync instead of checkout for subversion cache

* create repositories cache directory if it doesn't exists (default to RAILS_ROOT/tmp/scm)


git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1906 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Nicolas Chuche
2008-09-24 20:08:51 +00:00
parent 89b8bf3dc5
commit fdbe52a2f7
2 changed files with 27 additions and 5 deletions

View File

@@ -142,8 +142,11 @@ class Repository < ActiveRecord::Base
private
def repositories_cache_directory
dir = Setting.repositories_cache_directory.gsub(/^([^#{File::SEPARATOR}].*)/, RAILS_ROOT + '/\1')
return dir if File.directory?(dir)
unless @cache_directory
@cache_directory = Setting.repositories_cache_directory.gsub(/^([^#{File::SEPARATOR}].*)/, RAILS_ROOT + '/\1/')
Dir.mkdir(@cache_directory, File.umask(0077)) unless File.directory?(@cache_directory)
end
@cache_directory
end
def before_save

View File

@@ -26,6 +26,11 @@ module Redmine
# SVN executable name
SVN_BIN = "svn"
def initialize(url, root_url=nil, login=nil, password=nil, cache_path=nil)
super(url, root_url, login, password, cache_path)
@url = 'file://' + @url unless cache_path.blank?
end
class << self
def client_version
@@client_version ||= (svn_binary_version || [])
@@ -216,14 +221,28 @@ module Redmine
def create_cache
return if @orig_url.blank?
cmd = "#{SVN_BIN} checkout --non-interactive #{@orig_url} #{@root_url}"
cmd = "svnadmin create #{@root_url}"
shellout(cmd) { |io| io.read }
File.open("#{@root_url}/hooks/pre-revprop-change", "w") do |io|
io.puts <<'EOF'
#!/bin/sh
USER="$3"
if [ "$USER" = "svnsync" ]; then exit 0; fi
echo "Only the svnsync user can change revprops" >&2
exit 1
EOF
end
File.chmod 0500, "#{root_url}/hooks/pre-revprop-change"
cmd = "svnsync init --username svnsync #{@url} #{@orig_url}"
shellout(cmd) { |io| io.read }
synchronize
end
def synchronize
return if @orig_url.blank?
cmd = "#{SVN_BIN} update --non-interactive"
Dir.chdir(@root_url) { shellout(cmd) { |io| io.read } }
cmd = "svnsync sync #{@url}"
shellout(cmd) { |io| io.read }
end
private