]> source.dussan.org Git - redmine.git/commitdiff
* use svnsync instead of checkout for subversion cache
authorNicolas Chuche <nicolas.chuche@barna.be>
Wed, 24 Sep 2008 20:08:51 +0000 (20:08 +0000)
committerNicolas Chuche <nicolas.chuche@barna.be>
Wed, 24 Sep 2008 20:08:51 +0000 (20:08 +0000)
* 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

app/models/repository.rb
lib/redmine/scm/adapters/subversion_adapter.rb

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