From a78fc34690b4d1be93b5511f5ca3694d8de0b55a Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 29 Mar 2008 04:01:26 +0000 Subject: [PATCH 1/3] Only update once for list and sources -u git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1673 3d4018f9-ac1a-0410-99e9-8a154d859a19 --- ChangeLog | 2 ++ lib/rubygems/commands/query_command.rb | 2 +- lib/rubygems/commands/sources_command.rb | 2 +- lib/rubygems/source_info_cache.rb | 35 +++++++++++++++-------- test/test_gem_commands_query_command.rb | 3 ++ test/test_gem_commands_sources_command.rb | 2 ++ 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a358bb86..1eed0aa3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ * lib/rubygems.rb: Added Gem.ruby_version, Gem.read_binary, Gem.binary_mode. * lib/, test/: Read files in binary mode for windows and ruby 1.9. + * lib/rubygems/commands/update_command.rb: Only update once. + * lib/rubygems/commands/sources_command.rb: Ditto. * doc/release_notes/rel_1_1_0.rdoc: RubyGems 1.1.0 release notes. * lib/rubygems/rubygems_version.rb: 1.1.0. diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index fdc5a6a4..df17cc87 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -83,7 +83,7 @@ def execute say begin - Gem::SourceInfoCache.cache.refresh options[:all] + Gem::SourceInfoCache.cache options[:all] rescue Gem::RemoteFetcher::FetchError # no network end diff --git a/lib/rubygems/commands/sources_command.rb b/lib/rubygems/commands/sources_command.rb index 6d9d5b5b..1558d79b 100644 --- a/lib/rubygems/commands/sources_command.rb +++ b/lib/rubygems/commands/sources_command.rb @@ -69,7 +69,7 @@ def execute end if options[:update] then - Gem::SourceInfoCache.cache.refresh true + Gem::SourceInfoCache.cache true Gem::SourceInfoCache.cache.flush say "source cache successfully updated" diff --git a/lib/rubygems/source_info_cache.rb b/lib/rubygems/source_info_cache.rb index 9383f636..3305903b 100644 --- a/lib/rubygems/source_info_cache.rb +++ b/lib/rubygems/source_info_cache.rb @@ -31,14 +31,14 @@ class Gem::SourceInfoCache include Gem::UserInteraction - @cache = nil - @system_cache_file = nil - @user_cache_file = nil + ## + # The singleton Gem::SourceInfoCache. If +all+ is true, a full refresh will + # be performed if the singleton instance is being initialized. - def self.cache + def self.cache(all = false) return @cache if @cache @cache = new - @cache.refresh false if Gem.configuration.update_sources + @cache.refresh all if Gem.configuration.update_sources @cache end @@ -62,6 +62,15 @@ def self.latest_user_cache_file "latest_#{File.basename user_cache_file}" end + ## + # Reset all singletons, discarding any changes. + + def self.reset + @cache = nil + @system_cache_file = nil + @user_cache_file = nil + end + ## # Search all source indexes. See Gem::SourceInfoCache#search. @@ -122,13 +131,6 @@ def cache_file try_file(user_cache_file) or raise "unable to locate a writable cache file") end - - ## - # Force cache file to be reset, useful for integration testing of rubygems - - def reset_cache_file - @cache_file = nil - end ## # Write the cache to a local file (if it is dirty). @@ -245,6 +247,13 @@ def reset_cache_data @cache_data = nil end + ## + # Force cache file to be reset, useful for integration testing of rubygems + + def reset_cache_file + @cache_file = nil + end + ## # Searches all source indexes. See Gem::SourceIndex#search for details on # +pattern+ and +platform_only+. If +all+ is set to true, the full index @@ -350,5 +359,7 @@ def write_cache end end + reset + end diff --git a/test/test_gem_commands_query_command.rb b/test/test_gem_commands_query_command.rb index 7e714190..a62f61eb 100644 --- a/test/test_gem_commands_query_command.rb +++ b/test/test_gem_commands_query_command.rb @@ -26,6 +26,7 @@ def test_execute cache.update cache.write_cache cache.reset_cache_data + Gem::SourceInfoCache.reset a2_name = @a2.full_name @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name @@ -44,6 +45,7 @@ def test_execute *** REMOTE GEMS *** a (2) +pl (1) EOF assert_equal expected, @ui.output @@ -55,6 +57,7 @@ def test_execute_all cache.update cache.write_cache cache.reset_cache_data + Gem::SourceInfoCache.reset a1_name = @a1.full_name a2_name = @a2.full_name diff --git a/test/test_gem_commands_sources_command.rb b/test/test_gem_commands_sources_command.rb index 7ba88fad..f15d44df 100644 --- a/test/test_gem_commands_sources_command.rb +++ b/test/test_gem_commands_sources_command.rb @@ -181,6 +181,8 @@ def test_execute_update @cmd.handle_options %w[--update] util_setup_source_info_cache + Gem::SourceInfoCache.reset + util_setup_fake_fetcher si = Gem::SourceIndex.new si.add_spec @a1 From 8e71b0d59cb933c460bdf232f3ca744110468aa7 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 29 Mar 2008 05:39:22 +0000 Subject: [PATCH 2/3] Fix Gem::SourceIndex so legacy platform gems don't get updated repeatedly. git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1675 3d4018f9-ac1a-0410-99e9-8a154d859a19 --- ChangeLog | 2 ++ lib/rubygems/source_index.rb | 11 +++++++++-- test/test_gem_source_index.rb | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1eed0aa3..d6d82f00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ * lib/, test/: Read files in binary mode for windows and ruby 1.9. * lib/rubygems/commands/update_command.rb: Only update once. * lib/rubygems/commands/sources_command.rb: Ditto. + * lib/rubygems/source_index.rb: Fix #remove_extra, #find_missing so + legacy platform gems don't get updated repeatedly. * doc/release_notes/rel_1_1_0.rdoc: RubyGems 1.1.0 release notes. * lib/rubygems/rubygems_version.rb: 1.1.0. diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb index 61f5324a..be71488d 100644 --- a/lib/rubygems/source_index.rb +++ b/lib/rubygems/source_index.rb @@ -430,15 +430,22 @@ def fetch_quick_index(source_uri, all) # Make a list of full names for all the missing gemspecs. def find_missing(spec_names) + unless defined? @originals then + @originals = {} + each do |full_name, spec| + @originals[spec.original_name] = spec + end + end + spec_names.find_all { |full_name| - specification(full_name).nil? + @originals[full_name].nil? } end def remove_extra(spec_names) dictionary = spec_names.inject({}) { |h, k| h[k] = true; h } each do |name, spec| - remove_spec name unless dictionary.include? name + remove_spec name unless dictionary.include? spec.original_name end end diff --git a/test/test_gem_source_index.rb b/test/test_gem_source_index.rb index 74aa91d6..838a6408 100644 --- a/test/test_gem_source_index.rb +++ b/test/test_gem_source_index.rb @@ -398,10 +398,12 @@ def test_outdated def test_remove_extra @source_index.add_spec @a1 @source_index.add_spec @a2 + @source_index.add_spec @pl1 - @source_index.remove_extra [@a1.full_name] + @source_index.remove_extra [@a1.full_name, @pl1.full_name] - assert_equal [@a1.full_name], @source_index.gems.map { |n,s| n } + assert_equal [@a1.full_name], + @source_index.gems.map { |n,s| n }.sort end def test_remove_extra_no_changes From a5eb203a7ae082a5d8f7a4ec3cd596a72b43f752 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 29 Mar 2008 05:51:38 +0000 Subject: [PATCH 3/3] Add note about gem list --all git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1676 3d4018f9-ac1a-0410-99e9-8a154d859a19 --- doc/release_notes/rel_1_1_0.rdoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/release_notes/rel_1_1_0.rdoc b/doc/release_notes/rel_1_1_0.rdoc index bc8d56fc..1114465f 100644 --- a/doc/release_notes/rel_1_1_0.rdoc +++ b/doc/release_notes/rel_1_1_0.rdoc @@ -7,7 +7,10 @@ New features: * RubyGems now uses persistent connections on index updates. Index updates are much faster now. * RubyGems only updates from a latest index by default, cutting candidate gems - for updates to roughly 1/4 (at present). + for updates to roughly 1/4 (at present). Index updates are even faster + still. + * `gem list -r` may only show the latest version of a gem, add --all to see + all gems. * `gem spec` now extracts specifications from .gem files. * `gem query --installed` to aid automation of checking for gems. @@ -40,8 +43,8 @@ For a full list of changes to RubyGems, see the ChangeLog file. == How can I get RubyGems? -NOTE: If you have installed RubyGems using a package you may want to install a -new RubyGems through the same packaging system. +NOTE: If you have installed RubyGems using a package system you may want to +install a new RubyGems through the same packaging system. If you have a recent version of RubyGems (0.8.5 or later), then all you need to do is: