Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit e99c15e

Browse files
committed
Add quiet mode
1 parent 0d8eec1 commit e99c15e

File tree

9 files changed

+70
-44
lines changed

9 files changed

+70
-44
lines changed

lib/git/pkgs.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ module Pkgs
4242
class Error < StandardError; end
4343
class NotInitializedError < Error; end
4444
class NotInGitRepoError < Error; end
45+
46+
class << self
47+
attr_accessor :quiet
48+
end
49+
self.quiet = false
4550
end
4651
end

lib/git/pkgs/cli.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def initialize(args)
5050
end
5151

5252
def run
53+
parse_global_options
54+
5355
command = @args.shift
5456

5557
case command
@@ -66,6 +68,18 @@ def run
6668
end
6769
end
6870

71+
def parse_global_options
72+
while @args.first&.start_with?("-")
73+
case @args.first
74+
when "-q", "--quiet"
75+
Git::Pkgs.quiet = true
76+
@args.shift
77+
else
78+
break
79+
end
80+
end
81+
end
82+
6983
def run_command(command)
7084
command = ALIASES.fetch(command, command)
7185
# Convert kebab-case or snake_case to PascalCase
@@ -94,6 +108,7 @@ def print_help
94108
puts "Options:"
95109
puts " -h, --help Show this help message"
96110
puts " -v, --version Show version"
111+
puts " -q, --quiet Suppress informational messages"
97112
puts
98113
puts "Run 'git pkgs <command> -h' for command-specific options."
99114
end

lib/git/pkgs/commands/branch.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def add_branch
4444

4545
existing = Models::Branch.find_by(name: branch_name)
4646
if existing
47-
puts "Branch '#{branch_name}' already tracked (#{existing.commits.count} commits)"
48-
puts "Use 'git pkgs update' to refresh"
47+
info "Branch '#{branch_name}' already tracked (#{existing.commits.count} commits)"
48+
info "Use 'git pkgs update' to refresh"
4949
return
5050
end
5151

@@ -54,7 +54,7 @@ def add_branch
5454
branch = Models::Branch.create!(name: branch_name)
5555
analyzer = Analyzer.new(repo)
5656

57-
puts "Analyzing branch: #{branch_name}"
57+
info "Analyzing branch: #{branch_name}"
5858

5959
walker = repo.walk(branch_name)
6060
commits = walker.to_a
@@ -66,10 +66,10 @@ def add_branch
6666

6767
Database.optimize_for_reads
6868

69-
puts "\rDone!#{' ' * 20}"
70-
puts "Analyzed #{total} commits"
71-
puts "Found #{stats[:dependency_commits]} commits with dependency changes"
72-
puts "Stored #{stats[:snapshots_stored]} snapshots"
69+
info "\rDone!#{' ' * 20}"
70+
info "Analyzed #{total} commits"
71+
info "Found #{stats[:dependency_commits]} commits with dependency changes"
72+
info "Stored #{stats[:snapshots_stored]} snapshots"
7373
end
7474

7575
def list_branches
@@ -111,7 +111,7 @@ def remove_branch
111111
branch.branch_commits.delete_all
112112
branch.destroy
113113

114-
puts "Removed branch '#{branch_name}' (#{count} branch-commit links)"
114+
info "Removed branch '#{branch_name}' (#{count} branch-commit links)"
115115
end
116116

117117
def bulk_process_commits(commits, branch, analyzer, total, repo)
@@ -196,7 +196,7 @@ def bulk_process_commits(commits, branch, analyzer, total, repo)
196196

197197
commits.each do |rugged_commit|
198198
processed += 1
199-
print "\rProcessing commit #{processed}/#{total}..." if processed % 50 == 0 || processed == total
199+
print "\rProcessing commit #{processed}/#{total}..." if !Git::Pkgs.quiet && (processed % 50 == 0 || processed == total)
200200

201201
next if rugged_commit.parents.length > 1
202202

lib/git/pkgs/commands/diff_driver.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def install_driver
100100
end
101101
end
102102

103-
puts "Installed textconv driver for lockfiles."
104-
puts " git config: diff.pkgs.textconv = git-pkgs diff-driver"
105-
puts " .gitattributes: #{new_entries.count} lockfile patterns added"
106-
puts
107-
puts "Now 'git diff' on lockfiles shows dependency changes."
108-
puts "Use 'git diff --no-textconv' to see raw diff."
103+
info "Installed textconv driver for lockfiles."
104+
info " git config: diff.pkgs.textconv = git-pkgs diff-driver"
105+
info " .gitattributes: #{new_entries.count} lockfile patterns added"
106+
info ""
107+
info "Now 'git diff' on lockfiles shows dependency changes."
108+
info "Use 'git diff --no-textconv' to see raw diff."
109109
end
110110

111111
def uninstall_driver
@@ -118,7 +118,7 @@ def uninstall_driver
118118
File.write(gitattributes_path, lines.join)
119119
end
120120

121-
puts "Uninstalled diff driver."
121+
info "Uninstalled diff driver."
122122
end
123123

124124
def read_file(path)

lib/git/pkgs/commands/hooks.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ def install_hooks(repo)
4040
if File.exist?(hook_path)
4141
content = File.read(hook_path)
4242
if content.include?("git-pkgs")
43-
puts "Hook #{hook_name} already contains git-pkgs"
43+
info "Hook #{hook_name} already contains git-pkgs"
4444
next
4545
end
4646

4747
File.open(hook_path, "a") do |f|
4848
f.puts "\n# git-pkgs auto-update"
4949
f.puts "git pkgs update 2>/dev/null || true"
5050
end
51-
puts "Appended git-pkgs to existing #{hook_name} hook"
51+
info "Appended git-pkgs to existing #{hook_name} hook"
5252
else
5353
File.write(hook_path, HOOK_SCRIPT)
5454
File.chmod(0o755, hook_path)
55-
puts "Created #{hook_name} hook"
55+
info "Created #{hook_name} hook"
5656
end
5757
end
5858

59-
puts "Hooks installed successfully"
59+
info "Hooks installed successfully"
6060
end
6161

6262
def uninstall_hooks(repo)
@@ -70,7 +70,7 @@ def uninstall_hooks(repo)
7070

7171
if content.strip == HOOK_SCRIPT.strip
7272
File.delete(hook_path)
73-
puts "Removed #{hook_name} hook"
73+
info "Removed #{hook_name} hook"
7474
elsif content.include?("git-pkgs")
7575
new_content = content.lines.reject { |line|
7676
line.include?("git-pkgs") || line.include?("git pkgs")
@@ -79,15 +79,15 @@ def uninstall_hooks(repo)
7979

8080
if new_content.strip.empty? || new_content.strip == "#!/bin/sh"
8181
File.delete(hook_path)
82-
puts "Removed #{hook_name} hook"
82+
info "Removed #{hook_name} hook"
8383
else
8484
File.write(hook_path, new_content)
85-
puts "Removed git-pkgs from #{hook_name} hook"
85+
info "Removed git-pkgs from #{hook_name} hook"
8686
end
8787
end
8888
end
8989

90-
puts "Hooks uninstalled successfully"
90+
info "Hooks uninstalled successfully"
9191
end
9292

9393
def show_status(repo)

lib/git/pkgs/commands/init.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run
2121
error "Branch '#{branch_name}' not found" unless repo.branch_exists?(branch_name)
2222

2323
if Database.exists?(repo.git_dir) && !@options[:force]
24-
puts "Database already exists. Use --force to rebuild."
24+
info "Database already exists. Use --force to rebuild."
2525
return
2626
end
2727

@@ -33,7 +33,7 @@ def run
3333
branch = Models::Branch.find_or_create(branch_name)
3434
analyzer = Analyzer.new(repo)
3535

36-
puts "Analyzing branch: #{branch_name}"
36+
info "Analyzing branch: #{branch_name}"
3737

3838
walker = repo.walk(branch_name, @options[:since])
3939
commits = walker.to_a
@@ -43,17 +43,17 @@ def run
4343

4444
branch.update(last_analyzed_sha: repo.branch_target(branch_name))
4545

46-
print "\rCreating indexes..."
46+
print "\rCreating indexes..." unless Git::Pkgs.quiet
4747
Database.create_bulk_indexes
4848
Database.optimize_for_reads
4949

5050
cache_stats = analyzer.cache_stats
5151

52-
puts "\rDone!#{' ' * 20}"
53-
puts "Analyzed #{total} commits"
54-
puts "Found #{stats[:dependency_commits]} commits with dependency changes"
55-
puts "Stored #{stats[:snapshots_stored]} snapshots (every #{SNAPSHOT_INTERVAL} changes)"
56-
puts "Blob cache: #{cache_stats[:cached_blobs]} unique blobs, #{cache_stats[:blobs_with_hits]} had cache hits"
52+
info "\rDone!#{' ' * 20}"
53+
info "Analyzed #{total} commits"
54+
info "Found #{stats[:dependency_commits]} commits with dependency changes"
55+
info "Stored #{stats[:snapshots_stored]} snapshots (every #{SNAPSHOT_INTERVAL} changes)"
56+
info "Blob cache: #{cache_stats[:cached_blobs]} unique blobs, #{cache_stats[:blobs_with_hits]} had cache hits"
5757

5858
unless @options[:no_hooks]
5959
Commands::Hooks.new(["--install"]).run
@@ -137,7 +137,7 @@ def bulk_process_commits(commits, branch, analyzer, total)
137137

138138
commits.each do |rugged_commit|
139139
processed += 1
140-
print "\rProcessing commit #{processed}/#{total}..." if processed % 50 == 0 || processed == total
140+
print "\rProcessing commit #{processed}/#{total}..." if !Git::Pkgs.quiet && (processed % 50 == 0 || processed == total)
141141

142142
next if rugged_commit.parents.length > 1 # skip merge commits
143143

lib/git/pkgs/commands/update.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run
2626
current_sha = repo.branch_target(branch_name)
2727

2828
if since_sha == current_sha
29-
puts "Already up to date."
29+
info "Already up to date."
3030
return
3131
end
3232

@@ -54,13 +54,13 @@ def run
5454
dependency_commits = 0
5555
last_position = Models::BranchCommit.where(branch: branch).maximum(:position) || 0
5656

57-
puts "Updating branch: #{branch_name}"
58-
puts "Found #{total} new commits"
57+
info "Updating branch: #{branch_name}"
58+
info "Found #{total} new commits"
5959

6060
ActiveRecord::Base.transaction do
6161
commits.each do |rugged_commit|
6262
processed += 1
63-
print "\rProcessing commit #{processed}/#{total}..."
63+
print "\rProcessing commit #{processed}/#{total}..." unless Git::Pkgs.quiet
6464

6565
result = analyzer.analyze_commit(rugged_commit, snapshot)
6666

@@ -114,9 +114,9 @@ def run
114114
branch.update(last_analyzed_sha: current_sha)
115115
end
116116

117-
puts "\nDone!"
118-
puts "Processed #{total} new commits"
119-
puts "Found #{dependency_commits} commits with dependency changes"
117+
info "\nDone!"
118+
info "Processed #{total} new commits"
119+
info "Found #{dependency_commits} commits with dependency changes"
120120
end
121121

122122
def parse_options

lib/git/pkgs/commands/upgrade.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def run
2121
current = Database::SCHEMA_VERSION
2222

2323
if stored >= current
24-
puts "Database is up to date (version #{current})"
24+
info "Database is up to date (version #{current})"
2525
return
2626
end
2727

28-
puts "Upgrading database from version #{stored} to #{current}..."
29-
puts "This requires re-indexing the repository."
30-
puts
28+
info "Upgrading database from version #{stored} to #{current}..."
29+
info "This requires re-indexing the repository."
30+
info ""
3131

3232
# Run init --force
3333
Init.new(["--force"]).run

lib/git/pkgs/output.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def parse_time(str)
1414
rescue ArgumentError
1515
error "Invalid date format: #{str}"
1616
end
17+
18+
# Print informational/status message. Suppressed in quiet mode.
19+
def info(msg)
20+
puts msg unless Git::Pkgs.quiet
21+
end
22+
1723
# Print error message and exit with code 1.
1824
# Use for user errors (bad input, invalid refs) and system errors (db missing).
1925
# When format is :json, outputs JSON to stdout; otherwise outputs text to stderr.

0 commit comments

Comments
 (0)