Class: Gemstar::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/gemstar/project.rb

Defined Under Namespace

Classes: UnsupportedProjectError

Constant Summary collapse

REVISION_HISTORY_LIMIT =
100
SUPPORTED_PROJECT_FILES =
[
  "Gemfile",
  "Gemfile.lock",
  "config/importmap.rb",
  "package.json",
  "package-lock.json",
  "uv.lock",
  "Cargo.toml",
  "Cargo.lock"
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory:) ⇒ Project

Returns a new instance of Project.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gemstar/project.rb', line 79

def initialize(directory:)
  @directory = File.expand_path(directory)
  @gemfile_path = File.join(@directory, "Gemfile")
  @lockfile_path = File.join(@directory, "Gemfile.lock")
  @importmap_path = File.join(@directory, "config", "importmap.rb")
  @package_json_path = File.join(@directory, "package.json")
  @package_lock_path = File.join(@directory, "package-lock.json")
  @uv_lock_path = File.join(@directory, "uv.lock")
  @cargo_toml_path = File.join(@directory, "Cargo.toml")
  @cargo_lock_path = File.join(@directory, "Cargo.lock")
  @name = File.basename(@directory)
  @lockfile_cache = {}
  @importmap_cache = {}
  @package_lock_cache = {}
  @uv_lock_cache = {}
  @cargo_lock_cache = {}
  @gem_states_cache = {}
  @gem_added_on_cache = {}
  @history_cache = {}
end

Instance Attribute Details

#cargo_lock_pathObject (readonly)

Returns the value of attribute cargo_lock_path.



36
37
38
# File 'lib/gemstar/project.rb', line 36

def cargo_lock_path
  @cargo_lock_path
end

#cargo_toml_pathObject (readonly)

Returns the value of attribute cargo_toml_path.



35
36
37
# File 'lib/gemstar/project.rb', line 35

def cargo_toml_path
  @cargo_toml_path
end

#directoryObject (readonly)

Returns the value of attribute directory.



28
29
30
# File 'lib/gemstar/project.rb', line 28

def directory
  @directory
end

#gemfile_pathObject (readonly)

Returns the value of attribute gemfile_path.



29
30
31
# File 'lib/gemstar/project.rb', line 29

def gemfile_path
  @gemfile_path
end

#importmap_pathObject (readonly)

Returns the value of attribute importmap_path.



31
32
33
# File 'lib/gemstar/project.rb', line 31

def importmap_path
  @importmap_path
end

#lockfile_pathObject (readonly)

Returns the value of attribute lockfile_path.



30
31
32
# File 'lib/gemstar/project.rb', line 30

def lockfile_path
  @lockfile_path
end

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/gemstar/project.rb', line 37

def name
  @name
end

#package_json_pathObject (readonly)

Returns the value of attribute package_json_path.



32
33
34
# File 'lib/gemstar/project.rb', line 32

def package_json_path
  @package_json_path
end

#package_lock_pathObject (readonly)

Returns the value of attribute package_lock_path.



33
34
35
# File 'lib/gemstar/project.rb', line 33

def package_lock_path
  @package_lock_path
end

#uv_lock_pathObject (readonly)

Returns the value of attribute uv_lock_path.



34
35
36
# File 'lib/gemstar/project.rb', line 34

def uv_lock_path
  @uv_lock_path
end

Class Method Details

.from_cli_argument(input) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gemstar/project.rb', line 39

def self.from_cli_argument(input)
  expanded_input = File.expand_path(input)
  if File.directory?(expanded_input)
    directory = expanded_input
  else
    basename = File.basename(expanded_input)
    directory =
      case basename
      when "Gemfile", "Gemfile.lock", "package.json", "package-lock.json", "uv.lock", "Cargo.toml", "Cargo.lock"
        File.dirname(expanded_input)
      when "importmap.rb"
        File.dirname(expanded_input, 2)
      end
  end

  unless directory
    unsupported_directory = File.directory?(expanded_input) ? expanded_input : File.dirname(expanded_input)
    raise UnsupportedProjectError, unsupported_directory
  end

  raise UnsupportedProjectError, directory unless supported_project_directory?(directory)

  new(directory: directory)
end

.supported_project_directory?(directory) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
# File 'lib/gemstar/project.rb', line 64

def self.supported_project_directory?(directory)
  File.file?(File.join(directory, "Gemfile")) ||
    File.file?(File.join(directory, "Gemfile.lock")) ||
    File.file?(File.join(directory, "config", "importmap.rb")) ||
    File.file?(File.join(directory, "package.json")) ||
    File.file?(File.join(directory, "package-lock.json")) ||
    File.file?(File.join(directory, "uv.lock")) ||
    File.file?(File.join(directory, "Cargo.toml")) ||
    File.file?(File.join(directory, "Cargo.lock"))
end

.supported_project_files_sentenceObject



75
76
77
# File 'lib/gemstar/project.rb', line 75

def self.supported_project_files_sentence
  "#{SUPPORTED_PROJECT_FILES[0...-1].join(", ")}, and #{SUPPORTED_PROJECT_FILES[-1]}"
end

Instance Method Details

#cargo_lock?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/gemstar/project.rb', line 160

def cargo_lock?
  File.file?(cargo_lock_path)
end

#cargo_lock_for_revision(revision_id) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/gemstar/project.rb', line 317

def cargo_lock_for_revision(revision_id)
  cache_key = revision_id || "worktree"
  return @cargo_lock_cache[cache_key] if @cargo_lock_cache.key?(cache_key)
  return @cargo_lock_cache[cache_key] = current_cargo_lock if revision_id.nil? || revision_id == "worktree"
  return nil unless cargo_lock?

  relative_cargo_lock_path = git_repo.relative_path(cargo_lock_path)
  return nil if relative_cargo_lock_path.nil?

  content = git_repo.try_git_command(["show", "#{revision_id}:#{relative_cargo_lock_path}"])
  return nil if content.nil? || content.empty?

  @cargo_lock_cache[cache_key] = Gemstar::CargoLockFile.new(content: content)
end

#cargo_toml?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/gemstar/project.rb', line 156

def cargo_toml?
  File.file?(cargo_toml_path)
end

#clear_cache!Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/gemstar/project.rb', line 170

def clear_cache!
  @current_lockfile = nil
  @current_importmap = nil
  @current_package_lock = nil
  @current_uv_lock = nil
  @current_cargo_lock = nil
  @lockfile_cache.clear
  @importmap_cache.clear
  @package_lock_cache.clear
  @uv_lock_cache.clear
  @cargo_lock_cache.clear
  @gem_states_cache.clear
  @gem_added_on_cache.clear
  @history_cache.clear
end

#current_cargo_lockObject



164
165
166
167
168
# File 'lib/gemstar/project.rb', line 164

def current_cargo_lock
  return nil unless cargo_lock?

  @current_cargo_lock ||= Gemstar::CargoLockFile.new(path: cargo_lock_path)
end

#current_importmapObject



126
127
128
129
130
# File 'lib/gemstar/project.rb', line 126

def current_importmap
  return nil unless importmap?

  @current_importmap ||= Gemstar::ImportmapFile.new(path: importmap_path, vendor_reader: importmap_vendor_reader("worktree"))
end

#current_lockfileObject



112
113
114
115
116
# File 'lib/gemstar/project.rb', line 112

def current_lockfile
  return nil unless lockfile?

  @current_lockfile ||= Gemstar::LockFile.new(path: lockfile_path)
end

#current_package_lockObject



140
141
142
143
144
# File 'lib/gemstar/project.rb', line 140

def current_package_lock
  return nil unless package_lock?

  @current_package_lock ||= Gemstar::PackageLockFile.new(path: package_lock_path)
end

#current_uv_lockObject



150
151
152
153
154
# File 'lib/gemstar/project.rb', line 150

def current_uv_lock
  return nil unless uv_lock?

  @current_uv_lock ||= Gemstar::UvLockFile.new(path: uv_lock_path)
end

#default_from_revision_idObject



208
209
210
211
212
# File 'lib/gemstar/project.rb', line 208

def default_from_revision_id
  default_changed_revision_id ||
    gemfile_revision_history(limit: 1).first&.dig(:id) ||
    "worktree"
end

#gem_states(from_revision_id: default_from_revision_id, to_revision_id: "worktree") ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/gemstar/project.rb', line 332

def gem_states(from_revision_id: default_from_revision_id, to_revision_id: "worktree")
  cache_key = [from_revision_id, to_revision_id]
  return @gem_states_cache[cache_key] if @gem_states_cache.key?(cache_key)

  from_lockfile = lockfile_for_revision(from_revision_id)
  to_lockfile = lockfile_for_revision(to_revision_id)
  from_specs = from_lockfile&.specs || {}
  to_specs = to_lockfile&.specs || {}

  gem_states = (from_specs.keys | to_specs.keys).map do |gem_name|
    old_version = from_specs[gem_name]
    new_version = to_specs[gem_name]
    effective_lockfile = new_version ? to_lockfile : from_lockfile
    bundle_origins = effective_lockfile&.origins_for(gem_name) || []

    {
      name: gem_name,
      package_scope: "gems",
      package_type_label: "Gem",
      old_version: old_version,
      new_version: new_version,
      status: gem_status(old_version, new_version),
      version_label: version_label(old_version, new_version),
      platform: effective_lockfile&.platform_for(gem_name),
      source: effective_lockfile&.source_for(gem_name),
      bundle_origins: bundle_origins,
      bundle_origin_labels: bundle_origin_labels(bundle_origins)
    }
  end

  from_importmap = importmap_for_revision(from_revision_id)
  to_importmap = importmap_for_revision(to_revision_id)
  from_js_specs = from_importmap&.specs || {}
  to_js_specs = to_importmap&.specs || {}
  js_states = (from_js_specs.keys | to_js_specs.keys).map do |package_name|
    old_target = from_js_specs[package_name]
    new_target = to_js_specs[package_name]
    old_source = from_importmap&.source_for(package_name) || {}
    new_source = to_importmap&.source_for(package_name) || {}
    old_source = enrich_importmap_source(old_source, from_lockfile)
    new_source = enrich_importmap_source(new_source, to_lockfile)
    effective_source = new_target ? new_source : old_source
    old_package_version = js_package_version(old_source)
    new_package_version = js_package_version(new_source)
    comparison_old = old_package_version || old_target
    comparison_new = new_package_version || new_target

    {
      name: package_name,
      package_scope: "js",
      package_type_label: "JS",
      package_source_file: :importmap,
      old_version: old_package_version,
      new_version: new_package_version,
      raw_old_version: old_target,
      raw_new_version: new_target,
      status: gem_status(comparison_old, comparison_new),
      version_label: js_version_label(old_target, new_target, old_source, new_source),
      platform: nil,
      source: effective_source,
      bundle_origins: [],
      bundle_origin_labels: []
    }
  end

  from_package_lock = package_lock_for_revision(from_revision_id)
  to_package_lock = package_lock_for_revision(to_revision_id)
  from_npm_specs = from_package_lock&.specs || {}
  to_npm_specs = to_package_lock&.specs || {}
  npm_states = (from_npm_specs.keys | to_npm_specs.keys).map do |package_name|
    old_version = from_npm_specs[package_name]
    new_version = to_npm_specs[package_name]
    effective_package_lock = new_version ? to_package_lock : from_package_lock

    {
      name: package_name,
      package_scope: "js",
      package_type_label: "JS",
      package_source_file: :package_lock,
      old_version: old_version,
      new_version: new_version,
      status: gem_status(old_version, new_version),
      version_label: version_label(old_version, new_version),
      platform: nil,
      source: effective_package_lock&.source_for(package_name),
      bundle_origins: [],
      bundle_origin_labels: []
    }
  end

  from_uv_lock = uv_lock_for_revision(from_revision_id)
  to_uv_lock = uv_lock_for_revision(to_revision_id)
  from_python_specs = from_uv_lock&.specs || {}
  to_python_specs = to_uv_lock&.specs || {}
  python_states = (from_python_specs.keys | to_python_specs.keys).map do |package_name|
    old_version = from_python_specs[package_name]
    new_version = to_python_specs[package_name]
    effective_uv_lock = new_version ? to_uv_lock : from_uv_lock

    {
      name: package_name,
      package_scope: "python",
      package_type_label: "Python",
      package_source_file: :uv_lock,
      old_version: old_version,
      new_version: new_version,
      status: gem_status(old_version, new_version),
      version_label: version_label(old_version, new_version),
      platform: nil,
      source: effective_uv_lock&.source_for(package_name),
      bundle_origins: [],
      bundle_origin_labels: []
    }
  end

  from_cargo_lock = cargo_lock_for_revision(from_revision_id)
  to_cargo_lock = cargo_lock_for_revision(to_revision_id)
  from_cargo_specs = from_cargo_lock&.specs || {}
  to_cargo_specs = to_cargo_lock&.specs || {}
  cargo_states = (from_cargo_specs.keys | to_cargo_specs.keys).map do |package_key|
    old_version = from_cargo_specs[package_key]
    new_version = to_cargo_specs[package_key]
    effective_cargo_lock = new_version ? to_cargo_lock : from_cargo_lock
    source = effective_cargo_lock&.source_for(package_key)
    package_name = source&.dig(:package_name) || package_key
    display_name = package_key == package_name ? package_name : "#{package_name} @ #{new_version || old_version}"

    {
      name: display_name,
      metadata_package_name: package_name,
      package_lock_key: package_key,
      package_scope: "cargo",
      package_type_label: "Crate",
      package_source_file: :cargo_lock,
      old_version: old_version,
      new_version: new_version,
      status: gem_status(old_version, new_version),
      version_label: version_label(old_version, new_version),
      platform: nil,
      source: source,
      bundle_origins: [],
      bundle_origin_labels: []
    }
  end

  @gem_states_cache[cache_key] = (gem_states + js_states + npm_states + python_states + cargo_states).sort_by { |gem| [gem[:name], gem[:package_scope], gem[:package_source_file].to_s] }
end

#gemfile?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/gemstar/project.rb', line 118

def gemfile?
  File.file?(gemfile_path)
end

#gemfile_revision_history(limit: REVISION_HISTORY_LIMIT) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/gemstar/project.rb', line 199

def gemfile_revision_history(limit: REVISION_HISTORY_LIMIT)
  return [] unless gemfile?

  relative_path = git_repo.relative_path(gemfile_path)
  return [] if relative_path.nil?

  history_for_paths([relative_path], limit: limit)
end

#git_repoObject



100
101
102
# File 'lib/gemstar/project.rb', line 100

def git_repo
  @git_repo ||= Gemstar::GitRepo.new(directory)
end

#git_rootObject



104
105
106
# File 'lib/gemstar/project.rb', line 104

def git_root
  git_repo.tree_root_directory
end

#importmap?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/gemstar/project.rb', line 122

def importmap?
  File.file?(importmap_path)
end

#importmap_for_revision(revision_id) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/gemstar/project.rb', line 272

def importmap_for_revision(revision_id)
  cache_key = revision_id || "worktree"
  return @importmap_cache[cache_key] if @importmap_cache.key?(cache_key)
  return @importmap_cache[cache_key] = current_importmap if revision_id.nil? || revision_id == "worktree"
  return nil unless importmap?

  relative_importmap_path = git_repo.relative_path(importmap_path)
  return nil if relative_importmap_path.nil?

  content = git_repo.try_git_command(["show", "#{revision_id}:#{relative_importmap_path}"])
  return nil if content.nil? || content.empty?

  @importmap_cache[cache_key] = Gemstar::ImportmapFile.new(content: content, vendor_reader: importmap_vendor_reader(revision_id))
end

#lockfile?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/gemstar/project.rb', line 108

def lockfile?
  File.file?(lockfile_path)
end

#lockfile_for_revision(revision_id) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/gemstar/project.rb', line 257

def lockfile_for_revision(revision_id)
  cache_key = revision_id || "worktree"
  return @lockfile_cache[cache_key] if @lockfile_cache.key?(cache_key)
  return @lockfile_cache[cache_key] = current_lockfile if revision_id.nil? || revision_id == "worktree"
  return nil unless lockfile?

  relative_lockfile_path = git_repo.relative_path(lockfile_path)
  return nil if relative_lockfile_path.nil?

  content = git_repo.try_git_command(["show", "#{revision_id}:#{relative_lockfile_path}"])
  return nil if content.nil? || content.empty?

  @lockfile_cache[cache_key] = Gemstar::LockFile.new(content: content)
end

#lockfile_revision_history(limit: REVISION_HISTORY_LIMIT) ⇒ Object



190
191
192
193
194
195
196
197
# File 'lib/gemstar/project.rb', line 190

def lockfile_revision_history(limit: REVISION_HISTORY_LIMIT)
  return [] unless lockfile?

  relative_path = git_repo.relative_path(lockfile_path)
  return [] if relative_path.nil?

  history_for_paths([relative_path], limit: limit)
end

#package_added_on(package_name, package_scope:, revision_id: "worktree", source_file: nil, package_key: nil) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/gemstar/project.rb', line 480

def package_added_on(package_name, package_scope:, revision_id: "worktree", source_file: nil, package_key: nil)
  lookup_name = package_key || package_name
  cache_key = [lookup_name, package_scope, source_file, revision_id]
  return @gem_added_on_cache[cache_key] if @gem_added_on_cache.key?(cache_key)

  tracked_file, reader =
    if source_file == :importmap
      [importmap_path, method(:importmap_for_revision)]
    elsif source_file == :package_lock
      [package_lock_path, method(:package_lock_for_revision)]
    elsif source_file == :uv_lock
      [uv_lock_path, method(:uv_lock_for_revision)]
    elsif source_file == :cargo_lock
      [cargo_lock_path, method(:cargo_lock_for_revision)]
    elsif package_scope == "js"
      [importmap_path, method(:importmap_for_revision)]
    elsif package_scope == "python"
      [uv_lock_path, method(:uv_lock_for_revision)]
    elsif package_scope == "cargo"
      [cargo_lock_path, method(:cargo_lock_for_revision)]
    else
      [lockfile_path, method(:lockfile_for_revision)]
    end
  return @gem_added_on_cache[cache_key] = nil unless File.file?(tracked_file)

  target_snapshot = reader.call(revision_id)
  return @gem_added_on_cache[cache_key] = nil unless target_snapshot&.specs&.key?(lookup_name)

  relative_path = git_repo.relative_path(tracked_file)
  return @gem_added_on_cache[cache_key] = nil if relative_path.nil?

  first_seen_revision = history_for_paths([relative_path], limit: nil, reverse: true).find do |revision|
    snapshot = reader.call(revision[:id])
    snapshot&.specs&.key?(lookup_name)
  end

  return @gem_added_on_cache[cache_key] = worktree_added_on_info(tracked_file) if first_seen_revision.nil? && revision_id == "worktree"
  return @gem_added_on_cache[cache_key] = nil unless first_seen_revision

  @gem_added_on_cache[cache_key] = {
    project_name: name,
    date: first_seen_revision[:authored_at].strftime("%Y-%m-%d"),
    revision: first_seen_revision[:short_sha],
    revision_url: revision_url(first_seen_revision[:id]),
    worktree: false
  }
end

#package_collection_labelObject



243
244
245
# File 'lib/gemstar/project.rb', line 243

def package_collection_label
  package_scopes == [:gems] ? "Gems" : "Packages"
end

#package_item_labelObject



247
248
249
250
251
252
253
254
255
# File 'lib/gemstar/project.rb', line 247

def package_item_label
  case package_scopes
  when [:gems] then "gem"
  when [:js] then "JavaScript package"
  when [:python] then "Python package"
  when [:cargo] then "Rust crate"
  else "package"
  end
end

#package_json?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/gemstar/project.rb', line 136

def package_json?
  File.file?(package_json_path)
end

#package_lock?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/gemstar/project.rb', line 132

def package_lock?
  File.file?(package_lock_path)
end

#package_lock_for_revision(revision_id) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/gemstar/project.rb', line 287

def package_lock_for_revision(revision_id)
  cache_key = revision_id || "worktree"
  return @package_lock_cache[cache_key] if @package_lock_cache.key?(cache_key)
  return @package_lock_cache[cache_key] = current_package_lock if revision_id.nil? || revision_id == "worktree"
  return nil unless package_lock?

  relative_package_lock_path = git_repo.relative_path(package_lock_path)
  return nil if relative_package_lock_path.nil?

  content = git_repo.try_git_command(["show", "#{revision_id}:#{relative_package_lock_path}"])
  return nil if content.nil? || content.empty?

  @package_lock_cache[cache_key] = Gemstar::PackageLockFile.new(content: content)
end

#package_scope_optionsObject



234
235
236
237
238
239
240
241
# File 'lib/gemstar/project.rb', line 234

def package_scope_options
  package_scopes.map do |scope|
    {
      id: package_scope_id(scope),
      label: package_scope_label(scope)
    }
  end
end

#package_scopesObject



225
226
227
228
229
230
231
232
# File 'lib/gemstar/project.rb', line 225

def package_scopes
  scopes = []
  scopes << :gems if gemfile? || lockfile?
  scopes << :js if importmap? || package_lock? || package_json?
  scopes << :python if uv_lock?
  scopes << :cargo if cargo_toml? || cargo_lock?
  scopes
end

#revision_history(limit: REVISION_HISTORY_LIMIT) ⇒ Object



186
187
188
# File 'lib/gemstar/project.rb', line 186

def revision_history(limit: REVISION_HISTORY_LIMIT)
  history_for_paths(tracked_git_paths, limit: limit)
end

#revision_options(limit: REVISION_HISTORY_LIMIT) ⇒ Object



214
215
216
217
218
219
220
221
222
223
# File 'lib/gemstar/project.rb', line 214

def revision_options(limit: REVISION_HISTORY_LIMIT)
  [{ id: "worktree", label: "Worktree", description: "Current project files in the working tree" }] +
    revision_history(limit: limit).map do |revision|
      {
        id: revision[:id],
        label: revision[:short_sha],
        description: "#{revision[:subject]} (#{revision[:authored_at].strftime("%Y-%m-%d %H:%M")})"
      }
    end
end

#uv_lock?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/gemstar/project.rb', line 146

def uv_lock?
  File.file?(uv_lock_path)
end

#uv_lock_for_revision(revision_id) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/gemstar/project.rb', line 302

def uv_lock_for_revision(revision_id)
  cache_key = revision_id || "worktree"
  return @uv_lock_cache[cache_key] if @uv_lock_cache.key?(cache_key)
  return @uv_lock_cache[cache_key] = current_uv_lock if revision_id.nil? || revision_id == "worktree"
  return nil unless uv_lock?

  relative_uv_lock_path = git_repo.relative_path(uv_lock_path)
  return nil if relative_uv_lock_path.nil?

  content = git_repo.try_git_command(["show", "#{revision_id}:#{relative_uv_lock_path}"])
  return nil if content.nil? || content.empty?

  @uv_lock_cache[cache_key] = Gemstar::UvLockFile.new(content: content)
end