class CodeCache::Repo::SVN

Public Class Methods

new(url, options = {}) click to toggle source
Calls superclass method CodeCache::Repo::new
# File lib/code_cache/repo/svn.rb, line 6
def initialize(url, options = {})
  super(url, options)
end

Public Instance Methods

check_repo(url) click to toggle source

Check access to the repo in question

# File lib/code_cache/repo/svn.rb, line 86
def check_repo(url)
  output = `svn ls #{url} 2>&1`
  if ($? != 0)
    raise BadRepo.new(url + "<<<" + output.to_s + ">>>")
  end
end
checkout( revision, destination, branch=nil ) click to toggle source

Checkout a particular revision from the repo into the destination Caches the checkout in the process

# File lib/code_cache/repo/svn.rb, line 12
def checkout( revision, destination, branch=nil )
 
  puts "Checking out branch in not supported for SVN" if branch
  
  if revision != :head
    raise "Checking out revisions other than head currently not supported"
  end
  
  cache_destination = location_in_cache(revision)
  
  # Try and copy into the cache first
  begin
    perform_cache_checkout_or_update(cache_destination)
    FileUtils.mkdir_p(destination)
    
    FileUtils.cp_r(cache_destination+'/.', destination)
    # Ensure the final copy is consistent
    raise CopyError if !Dir.exist?(destination)
    output = perform_update(destination)
    if !output[:status]
      raise UpdateError.new(output)
    end
    
  rescue => e
    puts "Unhandled randomness: " + e.to_s + ' - ' + e.backtrace.to_s
    # If we can't copy into the cache, copy directly to the destination
    perform_checkout(destination)
  end
  
  true
end
perform_cache_checkout_or_update(destination, attempts = 3) click to toggle source
# File lib/code_cache/repo/svn.rb, line 44
def perform_cache_checkout_or_update(destination, attempts = 3)
  update_result = perform_update(destination)
  if update_result[:status] == true
    return true
  else
    checkout_result = perform_checkout(destination)
    if checkout_result[:status]
      return true
    else
      # Cache update in progress, retry with some sleeps
      if checkout_result[:output] =~ /E155037/
        sleep 1
        if attempts > 0
          perform_cache_checkout_or_update( destination, attempts-1 )
        else
          return false
        end
 
      # Cache has become corrupted
      elsif checkout_result[:output] =~ /E155004/  
        raise CacheCorruptionError.new(url)
      else
        raise UnknownCheckoutError.new(url)
      end
    end
  end
end
perform_checkout(destination) click to toggle source
# File lib/code_cache/repo/svn.rb, line 79
def perform_checkout(destination)
  output = `svn co #{url} #{destination} 2>&1`
  status = $? == 0
  { :output => output, :status => status }
end
perform_update(destination) click to toggle source

Perform an svn update on a directory – checks its a valid svn dir first

# File lib/code_cache/repo/svn.rb, line 73
def perform_update(destination)
  output = `svn info #{destination} 2>&1 && svn up #{destination} 2>&1`
  status = $? == 0
  { :output => output, :status => status }
end
split_url() click to toggle source

Split the url into a unique array for the cache path

# File lib/code_cache/repo/svn.rb, line 94
def split_url
  url.split('//').drop(1).collect{ |e| e.split('/') }.flatten
end