Skip to content

Commit

Permalink
Enable caching for specs and remove configurable git cache size.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed May 10, 2012
1 parent f03ed11 commit 9838d17
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion lib/cocoapods/config.rb
Expand Up @@ -28,7 +28,6 @@ def initialize
@repos_dir = Pathname.new(File.expand_path("~/.cocoapods"))
@verbose = @silent = @force_doc = false
@clean = @generate_docs = @doc_install = @integrate_targets = true
@git_cache_size = 500
end

def project_root
Expand Down
11 changes: 5 additions & 6 deletions lib/cocoapods/downloader/git.rb
Expand Up @@ -9,6 +9,8 @@ class Git < Downloader
include Config::Mixin
executable :git

MAX_CACHE_SIZE = 500

def download
prepare_cache
puts '->'.green << ' Cloning git repo' if config.verbose?
Expand All @@ -23,7 +25,7 @@ def download
end

def prepare_cache
unless cache_exist? || config.git_cache_size == 0
unless cache_exist?
puts '->'.green << " Creating cache git repo (#{cache_path})" if config.verbose?
cache_path.rmtree if cache_path.exist?
cache_path.mkpath
Expand All @@ -35,7 +37,7 @@ def removed_cached_repos_if_needed
return unless caches_dir.exist?
Dir.chdir(caches_dir) do
repos = Pathname.new(caches_dir).children.select { |c| c.directory? }.sort_by(&:ctime)
while caches_size >= config.git_cache_size && !repos.empty?
while caches_size >= MAX_CACHE_SIZE && !repos.empty?
dir = repos.shift
puts '->'.yellow << " Removing git cache for `#{origin_url(dir)}'" if config.verbose?
dir.rmtree
Expand All @@ -60,8 +62,7 @@ def caches_dir
end

def clone_url
# git_cache_size = 0 disables the cache
config.git_cache_size == 0 ? url : cache_path
cache_path
end

def caches_size
Expand All @@ -70,7 +71,6 @@ def caches_size
end

def update_cache
return if config.git_cache_size == 0
puts '->'.green << " Updating cache git repo (#{cache_path})" if config.verbose?
Dir.chdir(cache_path) do
git "reset --hard HEAD"
Expand All @@ -80,7 +80,6 @@ def update_cache
end

def ensure_ref_exists(ref)
return if config.git_cache_size == 0
Dir.chdir(cache_path) { git "rev-list --max-count=1 #{ref}" }
return if $? == 0
# Skip pull if not needed
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -53,7 +53,6 @@ def xit(description, *args)
config = Pod::Config.instance
config.silent = true
config.repos_dir = SpecHelper.tmp_repos_path
config.git_cache_size = 0

require 'tmpdir'

Expand Down

0 comments on commit 9838d17

Please sign in to comment.