From 76b2b801e6b757bd645d09f38cf0854718a83337 Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Mon, 26 Feb 2018 21:00:12 -0800 Subject: [PATCH 1/2] Add ability to lockfile to retrieve spec repo for pod name --- CHANGELOG.md | 4 ++++ lib/cocoapods-core/lockfile.rb | 16 ++++++++++++++-- spec/lockfile_spec.rb | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c9d23ed..3213eee04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ##### Enhancements +* Add ability to lockfile to retrieve spec repo for pod name + [Dimitris Koutsogiorgas](https://github.com/dnkoutso) + [#434](https://github.com/CocoaPods/Core/pull/434) + * `HTTP::perform_head_request` now includes a 1-byte `Range` header in the fallback GET request. [Kyle Fleming](https://github.com/kylefleming) diff --git a/lib/cocoapods-core/lockfile.rb b/lib/cocoapods-core/lockfile.rb index 2bc1785d7..d172b5d0a 100644 --- a/lib/cocoapods-core/lockfile.rb +++ b/lib/cocoapods-core/lockfile.rb @@ -77,7 +77,7 @@ def pod_names # Returns the version of the given Pod. # - # @param [name] The name of the Pod (root name of the specification). + # @param [String] pod_name The name of the Pod (root name of the specification). # # @return [Version] The version of the pod. # @@ -92,9 +92,21 @@ def version(pod_name) pod_versions[root_name] end + # Returns the source of the given Pod. + # + # @param [String] pod_name The name of the Pod (root name of the specification). + # + # @return [String] The source of the pod. + # + # @return [Nil] If there is no source stored for the given name. + # + def spec_repo(pod_name) + pods_by_spec_repo.detect { |key, values| break key if values.include?(pod_name) } + end + # Returns the checksum for the given Pod. # - # @param [name] The name of the Pod (root name of the specification). + # @param [String] name The name of the Pod (root name of the specification). # # @return [String] The checksum of the specification for the given Pod. # diff --git a/spec/lockfile_spec.rb b/spec/lockfile_spec.rb index 8a91d54fc..730893754 100644 --- a/spec/lockfile_spec.rb +++ b/spec/lockfile_spec.rb @@ -185,6 +185,12 @@ def self.specs_by_source @lockfile.version('BananaLib').should == Version.new('1.0') end + it 'returns the spec repo of a given pod' do + @lockfile.spec_repo('BananaLib').should == 'https://github.com/CocoaPods/Specs.git' + @lockfile.spec_repo('JSONKit').should.be.nil + @lockfile.spec_repo('monkey').should == 'https://github.com/CocoaPods/Specs.git' + end + it 'returns the checksum for the given Pod' do @lockfile.checksum('BananaLib').should == 'd46ca864666e216300a0653de197668b12e732a1' end From f5710a3b5da378e9b293e396103c935361d97b10 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 5 Mar 2018 14:52:11 -0800 Subject: [PATCH 2/2] [Lockfile] Cache the spec repos by pod so the hash only needs to be traversed once --- lib/cocoapods-core/lockfile.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/cocoapods-core/lockfile.rb b/lib/cocoapods-core/lockfile.rb index d172b5d0a..7bd23633f 100644 --- a/lib/cocoapods-core/lockfile.rb +++ b/lib/cocoapods-core/lockfile.rb @@ -101,7 +101,7 @@ def version(pod_name) # @return [Nil] If there is no source stored for the given name. # def spec_repo(pod_name) - pods_by_spec_repo.detect { |key, values| break key if values.include?(pod_name) } + spec_repos_by_pod[pod_name] end # Returns the checksum for the given Pod. @@ -248,6 +248,17 @@ def checksum_data internal_data['SPEC CHECKSUMS'] || {} end + # @return [Hash{String => String}] A hash containing the spec repo used for the specification + # by the name of the root spec. + # + def spec_repos_by_pod + @spec_repos_by_pod ||= pods_by_spec_repo.each_with_object({}) do |(spec_repo, pods), spec_repos_by_pod| + pods.each do |pod| + spec_repos_by_pod[pod] = spec_repo + end + end + end + #-------------------------------------------------------------------------# # !@group Comparison with a Podfile