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

Commit 72b1d43

Browse files
committed
Add pager support for long output and --no-pager option across commands
1 parent d3c06a7 commit 72b1d43

File tree

16 files changed

+358
-29
lines changed

16 files changed

+358
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Pager support for long output (respects `GIT_PAGER`, `core.pager`, `PAGER`)
4+
- `--no-pager` option for commands with long output
35
- `git pkgs stats` now supports `--since` and `--until` date filters
46
- Consistent error handling across all commands (JSON errors when `--format=json`)
57
- `git pkgs update` now uses a transaction for atomicity and better performance

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,27 @@ NO_COLOR=1 git pkgs diff --from=HEAD~10
340340

341341
Or set `NO_COLOR` in your shell profile to disable colors permanently. See [no-color.org](https://no-color.org/) for details.
342342

343+
## Pager
344+
345+
Long output is piped through a pager, following git's precedence:
346+
347+
1. `GIT_PAGER` environment variable
348+
2. `core.pager` git config
349+
3. `PAGER` environment variable
350+
4. `less -FRSX` as fallback
351+
352+
To disable paging for a single command:
353+
354+
```bash
355+
git pkgs history --no-pager
356+
```
357+
358+
To disable paging entirely, set your pager to `cat` or empty string:
359+
360+
```bash
361+
git config core.pager cat
362+
```
363+
343364
## Performance
344365

345366
Benchmarked on a MacBook Pro analyzing [octobox](https://github.com/octobox/octobox) (5191 commits, 8 years of history): init takes about 18 seconds at roughly 300 commits/sec, producing an 8.3 MB database. About half the commits (2531) had dependency changes.

lib/git/pkgs/commands/blame.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,24 @@ def run
6969
end
7070
puts JSON.pretty_generate(json_data)
7171
else
72-
grouped = blame_data.group_by { |d| [d[:manifest], d[:ecosystem]] }
72+
paginate { output_text(blame_data) }
73+
end
74+
end
75+
76+
def output_text(blame_data)
77+
grouped = blame_data.group_by { |d| [d[:manifest], d[:ecosystem]] }
7378

74-
grouped.each do |(manifest, ecosystem), deps|
75-
puts "#{manifest} (#{ecosystem}):"
79+
grouped.each do |(manifest, ecosystem), deps|
80+
puts "#{manifest} (#{ecosystem}):"
7681

77-
max_name_len = deps.map { |d| d[:name].length }.max
78-
max_author_len = deps.map { |d| d[:author].length }.max
82+
max_name_len = deps.map { |d| d[:name].length }.max
83+
max_author_len = deps.map { |d| d[:author].length }.max
7984

80-
deps.sort_by { |d| d[:name] }.each do |dep|
81-
date = dep[:date].strftime("%Y-%m-%d")
82-
puts " #{dep[:name].ljust(max_name_len)} #{dep[:author].ljust(max_author_len)} #{date} #{dep[:sha]}"
83-
end
84-
puts
85+
deps.sort_by { |d| d[:name] }.each do |dep|
86+
date = dep[:date].strftime("%Y-%m-%d")
87+
puts " #{dep[:name].ljust(max_name_len)} #{dep[:author].ljust(max_author_len)} #{date} #{dep[:sha]}"
8588
end
89+
puts
8690
end
8791
end
8892

@@ -122,6 +126,10 @@ def parse_options
122126
options[:format] = v
123127
end
124128

129+
opts.on("--no-pager", "Do not pipe output into a pager") do
130+
options[:no_pager] = true
131+
end
132+
125133
opts.on("-h", "--help", "Show this help") do
126134
puts opts
127135
exit

lib/git/pkgs/commands/diff.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def run
5252
return
5353
end
5454

55+
paginate { output_text(from_commit, to_commit, changes) }
56+
end
57+
58+
def output_text(from_commit, to_commit, changes)
5559
puts "Dependency changes from #{from_commit.short_sha} to #{to_commit.short_sha}:"
5660
puts
5761

@@ -133,6 +137,10 @@ def parse_options
133137
options[:ecosystem] = v
134138
end
135139

140+
opts.on("--no-pager", "Do not pipe output into a pager") do
141+
options[:no_pager] = true
142+
end
143+
136144
opts.on("-h", "--help", "Show this help") do
137145
puts opts
138146
exit

lib/git/pkgs/commands/history.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run
5858
if @options[:format] == "json"
5959
output_json(changes)
6060
else
61-
output_text(changes, package_name)
61+
paginate { output_text(changes, package_name) }
6262
end
6363
end
6464

@@ -145,6 +145,10 @@ def parse_options
145145
options[:until] = v
146146
end
147147

148+
opts.on("--no-pager", "Do not pipe output into a pager") do
149+
options[:no_pager] = true
150+
end
151+
148152
opts.on("-h", "--help", "Show this help") do
149153
puts opts
150154
exit

lib/git/pkgs/commands/list.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ def run
4242
require "json"
4343
puts JSON.pretty_generate(deps)
4444
else
45-
grouped = deps.group_by { |d| [d[:manifest_path], d[:ecosystem]] }
45+
paginate { output_text(deps) }
46+
end
47+
end
4648

47-
grouped.each do |(path, platform), manifest_deps|
48-
puts "#{path} (#{platform}):"
49-
manifest_deps.sort_by { |d| d[:name] }.each do |dep|
50-
type_suffix = dep[:dependency_type] ? " [#{dep[:dependency_type]}]" : ""
51-
puts " #{dep[:name]} #{dep[:requirement]}#{type_suffix}"
52-
end
53-
puts
49+
def output_text(deps)
50+
grouped = deps.group_by { |d| [d[:manifest_path], d[:ecosystem]] }
51+
52+
grouped.each do |(path, platform), manifest_deps|
53+
puts "#{path} (#{platform}):"
54+
manifest_deps.sort_by { |d| d[:name] }.each do |dep|
55+
type_suffix = dep[:dependency_type] ? " [#{dep[:dependency_type]}]" : ""
56+
puts " #{dep[:name]} #{dep[:requirement]}#{type_suffix}"
5457
end
58+
puts
5559
end
5660
end
5761

@@ -139,6 +143,10 @@ def parse_options
139143
options[:format] = v
140144
end
141145

146+
opts.on("--no-pager", "Do not pipe output into a pager") do
147+
options[:no_pager] = true
148+
end
149+
142150
opts.on("-h", "--help", "Show this help") do
143151
puts opts
144152
exit

lib/git/pkgs/commands/log.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def run
3838
if @options[:format] == "json"
3939
output_json(commits)
4040
else
41-
output_text(commits)
41+
paginate { output_text(commits) }
4242
end
4343
end
4444

@@ -138,6 +138,10 @@ def parse_options
138138
options[:format] = v
139139
end
140140

141+
opts.on("--no-pager", "Do not pipe output into a pager") do
142+
options[:no_pager] = true
143+
end
144+
141145
opts.on("-h", "--help", "Show this help") do
142146
puts opts
143147
exit

lib/git/pkgs/commands/search.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def run
4545
if @options[:format] == "json"
4646
output_json(matches, pattern)
4747
else
48-
output_text(matches, pattern)
48+
paginate { output_text(matches, pattern) }
4949
end
5050
end
5151

@@ -132,6 +132,10 @@ def parse_options
132132
options[:format] = v
133133
end
134134

135+
opts.on("--no-pager", "Do not pipe output into a pager") do
136+
options[:no_pager] = true
137+
end
138+
135139
opts.on("-h", "--help", "Show this help") do
136140
puts opts
137141
exit

lib/git/pkgs/commands/show.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def run
4141
if @options[:format] == "json"
4242
output_json(commit, changes)
4343
else
44-
output_text(commit, changes)
44+
paginate { output_text(commit, changes) }
4545
end
4646
end
4747

@@ -141,6 +141,10 @@ def parse_options
141141
options[:format] = v
142142
end
143143

144+
opts.on("--no-pager", "Do not pipe output into a pager") do
145+
options[:no_pager] = true
146+
end
147+
144148
opts.on("-h", "--help", "Show this help") do
145149
puts opts
146150
exit

lib/git/pkgs/commands/stale.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def run
7171
return
7272
end
7373

74+
paginate { output_text(outdated_data) }
75+
end
76+
77+
def output_text(outdated_data)
7478
puts "Dependencies by last update:"
7579
puts
7680

@@ -102,6 +106,10 @@ def parse_options
102106
options[:days] = v
103107
end
104108

109+
opts.on("--no-pager", "Do not pipe output into a pager") do
110+
options[:no_pager] = true
111+
end
112+
105113
opts.on("-h", "--help", "Show this help") do
106114
puts opts
107115
exit

0 commit comments

Comments
 (0)