add local cache repository for speed purpose (subversion) or for browsing a external repository

for SCM that can handle only local copy (git).


git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1899 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Nicolas Chuche
2008-09-22 18:46:46 +00:00
parent 9b94342bc3
commit 89b8bf3dc5
41 changed files with 216 additions and 12 deletions

View File

@@ -47,11 +47,17 @@ module Redmine
end
end
def initialize(url, root_url=nil, login=nil, password=nil)
def initialize(url, root_url=nil, login=nil, password=nil, cache_path=nil)
@url = url
@login = login if login && !login.empty?
@password = (password || "") if @login
@root_url = root_url.blank? ? retrieve_root_url : root_url
if cache_path.blank?
@root_url = root_url.blank? ? retrieve_root_url : root_url
else
@orig_url = @url
@url = @root_url = cache_path
end
end
def adapter_name
@@ -145,7 +151,22 @@ module Redmine
end
end
def remove_cache
remove_directory(@root_url) if not @orig_url.blank? and File.directory?(@root_url)
end
private
def remove_directory(path)
Dir.entries(path).each do |f|
next if %w[. ..].include?(f)
name = "#{path}/#{f}"
File.directory?(name) ? remove_directory(name) : File.unlink(name)
end
Dir.rmdir path
rescue Errno::ENOENT => e
logger.error(e.to_s)
end
def retrieve_root_url
info = self.info
info ? info.root_url : nil
@@ -194,7 +215,7 @@ module Redmine
self.class.strip_credential(cmd)
end
end
class Entries < Array
def sort_by_name
sort {|x,y|

View File

@@ -25,6 +25,11 @@ module Redmine
# Git executable name
GIT_BIN = "git"
def initialize(url, root_url=nil, login=nil, password=nil, cache_path=nil)
super(url, root_url, login, password, cache_path)
@url += "/.git/" unless cache_path.blank?
end
# Get the revision of a particuliar file
def get_rev (rev,path)
@@ -263,9 +268,20 @@ module Redmine
return nil if $? && $?.exitstatus != 0
cat
end
def create_cache
cmd = "#{GIT_BIN} clone #{@orig_url} #{@root_url}"
shellout(cmd) { |io| io.read }
end
def synchronize
return unless File.directory?(@url)
cmd = "#{GIT_BIN} --git-dir #{@url} pull"
shellout(cmd)
end
end
end
end
end

View File

@@ -25,7 +25,7 @@ module Redmine
# SVN executable name
SVN_BIN = "svn"
class << self
def client_version
@@client_version ||= (svn_binary_version || [])
@@ -213,6 +213,18 @@ module Redmine
return nil if $? && $?.exitstatus != 0
blame
end
def create_cache
return if @orig_url.blank?
cmd = "#{SVN_BIN} checkout --non-interactive #{@orig_url} #{@root_url}"
shellout(cmd) { |io| io.read }
end
def synchronize
return if @orig_url.blank?
cmd = "#{SVN_BIN} update --non-interactive"
Dir.chdir(@root_url) { shellout(cmd) { |io| io.read } }
end
private
@@ -222,6 +234,7 @@ module Redmine
str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank?
str
end
end
end
end