rubygems-generate_index 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e89ec0ba401376957ef5cd59bfaecd5e77bc043775fa0f4414332dffab489aa
4
- data.tar.gz: 9032f6fe7bb94da4d1b9c11bfd29bbbd0f6bb4bc74d054c2825c833121ea84c0
3
+ metadata.gz: 1ad952327cbcaa7acf0cae3fa55046eb6453bec284c897fcf2b02f49ff1a6cc1
4
+ data.tar.gz: 0bad6263323bd12ff67c039cbc80246df6631dfa285876585336b91d5620ff7f
5
5
  SHA512:
6
- metadata.gz: ad0f57dd0f7a01f1b6702848190c5623af4787ffde8817ee090fb334b1c575f47f112f21aee01d047dbe12df1409635a40abb55ae9617bd3c29dd913de91c458
7
- data.tar.gz: ee119a9d5bad9b7045d22868eaf08e4c2efbc9097eb03ed1f9cd2f3b858da00fbedc596fc839d22aa2db7f6a51ea41cef7ae3ce3fd4fc7f8d94ce1130bf24b75
6
+ metadata.gz: e0ff2c9f9aec05d64453bbe3a8a5092cd43649e87cf1fd2000ad36e7c29b4a35e5223d9ff7319f4cbcf1e0f7d8371a2f573958c68937cc6667afc9d17cca47d7
7
+ data.tar.gz: 4f7f011e4624a6d3600fdc95b4bc14e4c408b05c7ce377b17206a70a3248594004a79dba3f25a3a08fa1a7da4c52002f064e2497d7a35eae68f1412f88ad7044
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubygems-generate_index (1.0.0)
4
+ rubygems-generate_index (1.1.0)
5
5
  compact_index (~> 0.14.0)
6
6
 
7
7
  GEM
@@ -63,4 +63,4 @@ DEPENDENCIES
63
63
  test-unit (~> 3.0)
64
64
 
65
65
  BUNDLED WITH
66
- 2.4.19
66
+ 2.4.22
@@ -12,7 +12,7 @@ class Gem::Commands::GenerateIndexCommand < Gem::Command
12
12
  def initialize
13
13
  super "generate_index",
14
14
  "Generates the index files for a gem server directory",
15
- :directory => ".", :build_modern => true
15
+ :directory => ".", :build_modern => true, :build_compact => true
16
16
 
17
17
  @deprecated_options = { "generate_index" => {} } unless defined?(@deprecated_options)
18
18
 
@@ -30,15 +30,20 @@ class Gem::Commands::GenerateIndexCommand < Gem::Command
30
30
  deprecate_option("--modern", version: "4.0", extra_msg: "Modern indexes (specs, latest_specs, and prerelease_specs) are always generated, so this option is not needed.")
31
31
  deprecate_option("--no-modern", version: "4.0", extra_msg: "The `--no-modern` option is currently ignored. Modern indexes (specs, latest_specs, and prerelease_specs) are always generated.")
32
32
 
33
+ add_option "--[no-]compact",
34
+ "Generate compact index files" do |value, options|
35
+ options[:build_compact] = value
36
+ end
37
+
33
38
  add_option "--update",
34
- "Update modern indexes with gems added",
39
+ "Update modern and compact indices with gems added",
35
40
  "since the last update" do |value, options|
36
41
  options[:update] = value
37
42
  end
38
43
  end
39
44
 
40
45
  def defaults_str # :nodoc:
41
- "--directory . --modern"
46
+ "--directory . --modern --compact"
42
47
  end
43
48
 
44
49
  def description # :nodoc:
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "compact_index"
3
4
  require "rubygems"
4
5
  require "rubygems/package"
5
6
  require "tmpdir"
@@ -23,6 +24,11 @@ class Gem::Indexer
23
24
 
24
25
  attr_accessor :build_modern
25
26
 
27
+ ##
28
+ # Build compact index files when true
29
+
30
+ attr_accessor :build_compact
31
+
26
32
  ##
27
33
  # Index install location
28
34
 
@@ -64,6 +70,7 @@ class Gem::Indexer
64
70
  options = { :build_modern => true }.merge options
65
71
 
66
72
  @build_modern = options[:build_modern]
73
+ @build_compact = options[:build_compact]
67
74
 
68
75
  @dest_directory = directory
69
76
  @directory = Dir.mktmpdir "gem_generate_index"
@@ -103,6 +110,7 @@ class Gem::Indexer
103
110
  Gem::Specification._resort! specs
104
111
  build_marshal_gemspecs specs
105
112
  build_modern_indices specs if @build_modern
113
+ build_compact_index specs if @build_compact
106
114
 
107
115
  compress_indices
108
116
  end
@@ -196,6 +204,57 @@ class Gem::Indexer
196
204
  "#{@prerelease_specs_index}.gz"]
197
205
  end
198
206
 
207
+ ##
208
+ # Builds compact index files
209
+
210
+ def build_compact_index(specs)
211
+ gems = compact_index_gems(specs)
212
+
213
+ progress = ui.progress_reporter gems.count + 2,
214
+ "Generating compact index files for #{gems.count} gems",
215
+ "Complete"
216
+
217
+ Gem.time "Generated compact index files" do
218
+ info_dir = File.join(@directory, "info")
219
+ FileUtils.mkdir_p info_dir, :mode => 0o700
220
+
221
+ gems.each do |gem|
222
+ info = CompactIndex.info(gem.versions)
223
+
224
+ info_checksum = Digest::MD5.hexdigest(info)
225
+ gem[:versions].last[:info_checksum] = info_checksum
226
+
227
+ info_path = File.join(@directory, "info", gem.name)
228
+ if File.exist?(info_path)
229
+ raise "info file already exists: #{info_path}"
230
+ end
231
+
232
+ File.open(info_path, "wb") do |io|
233
+ io.write info
234
+ end
235
+
236
+ progress.updated "/info/#{gem.name}"
237
+ end
238
+
239
+ File.open(File.join(@directory, "names"), "wb") do |io|
240
+ io.write CompactIndex.names(gems.map(&:name))
241
+ end
242
+ progress.updated "/names"
243
+
244
+ CompactIndex::VersionsFile.new(
245
+ File.join(@directory, "versions")
246
+ ).create(
247
+ gems,
248
+ )
249
+
250
+ progress.updated "/versions"
251
+
252
+ @files << info_dir << File.join(@directory, "names") << File.join(@directory, "versions")
253
+
254
+ progress.done
255
+ end
256
+ end
257
+
199
258
  def map_gems_to_specs(gems)
200
259
  gems.map do |gemfile|
201
260
  if File.size(gemfile) == 0
@@ -389,6 +448,12 @@ class Gem::Indexer
389
448
  @prerelease_specs_index)
390
449
  end
391
450
 
451
+ if @build_compact
452
+ Gem.time "Updated compact index files" do
453
+ files += update_compact_index released, @dest_directory, @directory
454
+ end
455
+ end
456
+
392
457
  compress_indices
393
458
 
394
459
  verbose = Gem.configuration.really_verbose
@@ -439,6 +504,87 @@ class Gem::Indexer
439
504
  end
440
505
  end
441
506
 
507
+ ##
508
+ # Combines specs in +index+ and +source+ then writes out a new
509
+ # compact index to +dest+.
510
+
511
+ def update_compact_index(new_specs, source, dest)
512
+ files = []
513
+ source_versions_path = File.join(source, "versions")
514
+ versions_file = CompactIndex::VersionsFile.new source_versions_path
515
+
516
+ gems = compact_index_gems new_specs
517
+
518
+ FileUtils.mkdir_p File.join(dest, "info")
519
+
520
+ new_names = []
521
+ gems.each do |gem|
522
+ existing_info_path = File.join(source, "info", gem.name)
523
+ if File.exist? existing_info_path
524
+ info = Gem.read_binary(existing_info_path) +
525
+ CompactIndex.info(gem.versions).sub(/\A---\n/, "")
526
+ else
527
+ new_names << gem.name
528
+ info = CompactIndex.info gem.versions
529
+ end
530
+
531
+ info_checksum = Digest::MD5.hexdigest(info)
532
+ gem[:versions].last[:info_checksum] = info_checksum
533
+
534
+ info_path = File.join(dest, "info", gem.name)
535
+ if File.exist?(info_path)
536
+ raise "info file already exists: #{info_path}"
537
+ end
538
+
539
+ File.open(info_path, "wb") do |io|
540
+ io.write info
541
+ end
542
+ files << info_path
543
+ end
544
+
545
+ versions_path = File.join(dest, "versions")
546
+ File.open(versions_path, "wb") do |io|
547
+ io.write versions_file.contents(gems)
548
+ end
549
+ files << versions_path
550
+
551
+ unless new_names.empty?
552
+ old_names = Gem.read_binary(File.join(source, "names")).lines(chomp: true)[2..]
553
+ names_path = File.join(dest, "names")
554
+
555
+ names = old_names + new_names
556
+ names.sort!
557
+
558
+ File.open(names_path, "wb") do |io|
559
+ io.write CompactIndex.names(names)
560
+ end
561
+
562
+ files << names_path
563
+ end
564
+
565
+ files
566
+ end
567
+
568
+ def compact_index_gems(specs)
569
+ versions_by_name = Hash.new {|h, k| h[k] = [] }
570
+ specs.each do |spec|
571
+ checksum = spec.loaded_from && Digest::SHA256.file(spec.loaded_from).base64digest!
572
+ versions_by_name[spec.name] << CompactIndex::GemVersion.new(
573
+ spec.version.version,
574
+ spec.platform,
575
+ checksum,
576
+ nil, # info_checksum
577
+ spec.dependencies.map {|d| CompactIndex::Dependency.new(d.name, d.requirement.to_s) },
578
+ spec.required_ruby_version&.to_s,
579
+ spec.required_rubygems_version&.to_s
580
+ )
581
+ end
582
+ versions_by_name.map do |name, versions|
583
+ versions.sort!
584
+ CompactIndex::Gem.new(name, versions)
585
+ end.tap(&:sort!)
586
+ end
587
+
442
588
  private
443
589
 
444
590
  def marshal_load(string)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubygems-generate_index"
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
  s.authors = ["Jim Weirich", "Chad Fowler", "Eric Hodel", "Luis Lavena", "Aaron Patterson", "Samuel Giddins", "André Arko", "Evan Phoenix", "Hiroshi SHIBATA"]
7
7
  s.email = ["", "", "drbrain@segment7.net", "luislavena@gmail.com", "aaron@tenderlovemaking.com", "segiddins@segiddins.me", "andre@arko.net", "evan@phx.io", "hsbt@ruby-lang.org"]
8
8
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "CODE_OF_CONDUCT.md"
27
27
  ]
28
28
 
29
- s.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
29
+ s.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
30
30
  s.required_rubygems_version = Gem::Requirement.new(">= 0")
31
31
 
32
32
  s.add_dependency "compact_index", "~> 0.14.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubygems-generate_index
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: exe
18
18
  cert_chain: []
19
- date: 2023-11-26 00:00:00.000000000 Z
19
+ date: 2023-11-27 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: compact_index
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 2.6.0
85
+ version: 3.0.0
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="