This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinfo.rb
More file actions
170 lines (142 loc) · 4.64 KB
/
Copy pathinfo.rb
File metadata and controls
170 lines (142 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# frozen_string_literal: true
module Git
module Pkgs
module Commands
class Info
include Output
def initialize(args)
@args = args
@options = parse_options
end
def run
if @options[:ecosystems]
output_ecosystems
return
end
repo = Repository.new
require_database(repo)
db_path = Database.path(repo.git_dir)
Database.connect(repo.git_dir)
puts "Database Info"
puts "=" * 40
puts
# File info
db_size = File.size(db_path)
puts "Location: #{db_path}"
puts "Size: #{format_size(db_size)}"
puts
# Row counts
puts "Row Counts"
puts "-" * 40
counts = {
"Branches" => Models::Branch.count,
"Commits" => Models::Commit.count,
"Branch-Commits" => Models::BranchCommit.count,
"Manifests" => Models::Manifest.count,
"Dependency Changes" => Models::DependencyChange.count,
"Dependency Snapshots" => Models::DependencySnapshot.count
}
counts.each do |name, count|
puts " #{name.ljust(22)} #{count.to_s.rjust(10)}"
end
puts " #{'-' * 34}"
puts " #{'Total'.ljust(22)} #{counts.values.sum.to_s.rjust(10)}"
puts
# Branch info
puts "Branches"
puts "-" * 40
Models::Branch.all.each do |branch|
commit_count = branch.commits.count
last_sha = branch.last_analyzed_sha&.slice(0, 7) || "none"
puts " #{branch.name}: #{commit_count} commits (last: #{last_sha})"
end
puts
# Snapshot coverage
puts "Snapshot Coverage"
puts "-" * 40
total_dep_commits = Models::Commit.where(has_dependency_changes: true).count
snapshot_commits = Models::Commit
.join(:dependency_snapshots, commit_id: :id)
.distinct
.count
puts " Commits with dependency changes: #{total_dep_commits}"
puts " Commits with snapshots: #{snapshot_commits}"
if total_dep_commits > 0
ratio = (snapshot_commits.to_f / total_dep_commits * 100).round(1)
if snapshot_commits > 0
puts " Coverage: #{ratio}% (1 snapshot per ~#{(total_dep_commits / snapshot_commits)} changes)"
else
puts " Coverage: #{ratio}%"
end
end
end
def output_ecosystems
require "bibliothecary"
all_ecosystems = Bibliothecary::Parsers.constants.map do |c|
parser = Bibliothecary::Parsers.const_get(c)
parser.platform_name if parser.respond_to?(:platform_name)
end.compact.sort
configured = Config.ecosystems
filtering = configured.any?
puts "Available Ecosystems"
puts "=" * 40
puts
enabled_ecos = []
disabled_ecos = []
all_ecosystems.each do |eco|
if Config.filter_ecosystem?(eco)
disabled_ecos << eco
else
enabled_ecos << eco
end
end
puts "Enabled:"
if enabled_ecos.any?
enabled_ecos.each { |eco| puts " #{Color.green(eco)}" }
else
puts " (none)"
end
puts
puts "Disabled:"
if disabled_ecos.any?
disabled_ecos.each { |eco| puts " #{eco}" }
else
puts " (none)"
end
puts
if filtering
puts "Filtering: only #{configured.join(', ')}"
else
puts "All ecosystems enabled"
end
puts "Configure with: git config --add pkgs.ecosystems <name>"
end
def format_size(bytes)
units = %w[B KB MB GB]
unit_index = 0
size = bytes.to_f
while size >= 1024 && unit_index < units.length - 1
size /= 1024
unit_index += 1
end
"#{size.round(1)} #{units[unit_index]}"
end
def parse_options
options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: git pkgs info [options]"
opts.on("--ecosystems", "Show available ecosystems and filter status") do
options[:ecosystems] = true
end
opts.on("-h", "--help", "Show this help") do
puts opts
exit
end
end
parser.parse!(@args)
options
end
end
end
end
end