Skip to content

Commit

Permalink
Instead of maintaining Source#index and Source#remote_index, just hav…
Browse files Browse the repository at this point in the history
…e Source#remote! trigger whether or not to search the remote index (and remember)
  • Loading branch information
Carl Lerche committed Jun 7, 2010
1 parent 2be8e1d commit 2f2b5a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
21 changes: 8 additions & 13 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def initialize(lockfile, dependencies, sources, unlock)

def resolve_remotely!
raise "Specs already loaded" if @specs
@specs = resolve(:specs, remote_index)
@sources.each { |s| s.remote! }
specs
end

def specs
@specs ||= resolve(:local_specs, index)
@specs ||= resolve
end

def requested_specs
Expand Down Expand Up @@ -90,17 +91,11 @@ def last_resolve
def index
@index ||= Index.build do |idx|
@sources.each do |s|
idx.use s.local_specs
idx.use s.specs
end
end
end

def remote_index
@remote_index ||= Index.build do |idx|
@sources.each { |source| idx.use source.specs }
end
end

def no_sources?
@sources.length == 1 && @sources.first.remotes.empty?
end
Expand Down Expand Up @@ -228,18 +223,18 @@ def requested_dependencies
dependencies.reject { |d| !d.should_include? || (d.groups & groups).empty? }
end

def resolve(type, idx)
def resolve
unless @last_resolve.valid_for?(expanded_dependencies)
source_requirements = {}
dependencies.each do |dep|
next unless dep.source
source_requirements[dep.name] = dep.source.send(type)
source_requirements[dep.name] = dep.source.specs
end

# Run a resolve against the locally available gems
@last_resolve = Resolver.resolve(expanded_dependencies, idx, source_requirements, @last_resolve)
@last_resolve = Resolver.resolve(expanded_dependencies, index, source_requirements, @last_resolve)
end
@last_resolve.materialize(type, expand_dependencies(requested_dependencies))
@last_resolve.materialize(expand_dependencies(requested_dependencies))
end
end
end
24 changes: 16 additions & 8 deletions lib/bundler/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ class Rubygems
def initialize(options = {})
@options = options
@remotes = (options["remotes"] || []).map { |r| normalize_uri(r) }
# @caches = (options["caches"] || [])
@allow_remote = false
# Hardcode the paths for now
@installed = {}
@caches = [ Bundler.app_cache ] + Gem.path.map { |p| File.expand_path("#{p}/cache") }
@spec_fetch_map = {}
end

def remote!
@allow_remote = true
end

def hash
Rubygems.hash
end
Expand Down Expand Up @@ -59,11 +63,7 @@ def to_s
end

def specs
@specs ||= fetch_specs
end

def local_specs
@local_specs ||= fetch_local_specs
@specs ||= @allow_remote ? fetch_specs : fetch_local_specs
end

def fetch(spec)
Expand Down Expand Up @@ -227,6 +227,8 @@ def initialize(options)
@options = options
@glob = options["glob"] || DEFAULT_GLOB

@allow_remote = false

if options["path"]
@path = Pathname.new(options["path"]).expand_path(Bundler.root)
end
Expand All @@ -235,6 +237,10 @@ def initialize(options)
@version = options["version"]
end

def remote!
@allow_remote = true
end

def self.from_lock(options)
new(options.merge("path" => options.delete("remote")))
end
Expand Down Expand Up @@ -456,9 +462,11 @@ def unlock!
end

def specs
if @allow_remote
# Start by making sure the git cache is up to date
cache
checkout
cache
checkout
end
local_specs
end

Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def to_hash
lookup.dup
end

def materialize(type, deps)
def materialize(deps)
materialized = self.for(deps, []).to_a
materialized.map! do |s|
next s unless s.is_a?(LazySpecification)
s.__materialize__(s.source.send(type))
s.__materialize__(s.source.specs)
end
SpecSet.new(materialized)
end
Expand Down

0 comments on commit 2f2b5a8

Please sign in to comment.