From: Nicolas Chuche Date: Wed, 24 Sep 2008 20:08:51 +0000 (+0000) Subject: * use svnsync instead of checkout for subversion cache X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fdbe52a2f77a2a61cfec8ce8d69a317ef4a69979;p=redmine.git * 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 --- diff --git a/app/models/repository.rb b/app/models/repository.rb index 9ff22330a..b0a7a0a16 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb index 109e9e756..bd04f582b 100644 --- a/lib/redmine/scm/adapters/subversion_adapter.rb +++ b/lib/redmine/scm/adapters/subversion_adapter.rb @@ -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