Cli/list/format bsdtar#2788
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
cli/src/command/list.rs (2)
780-811: Width calculation logic may produce inconsistent column alignment across entries.The width variables
u_widthandgs_widthare updated iteratively as entries are processed, but each entry is written immediately using the current width values. This means earlier entries use narrower widths than later entries if wider values appear later in the iteration.For consistent column alignment across all output lines (matching typical bsdtar behavior), you would need two passes: first to compute max widths, then to format output.
However, if this is intentional to minimize memory usage for streaming output, consider documenting this design decision.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cli/src/command/list.rs` around lines 780 - 811, The current single-pass loop updates u_width and gs_width while immediately formatting lines, causing earlier rows to use smaller widths and misalign columns; change list formatting to a two-pass approach: first iterate over entries to compute final u_width (max uname length) and gs_width (max of gname.len() + size.to_string().len() + 1) using the same logic currently in the loop (respecting options.numeric_owner, PermissionDisplay::bsdtar, bsd_tar_time, etc.), then do a second pass over entries to produce the output using those finalized u_width and gs_width values so all lines use consistent column widths; if streaming was intentional, add a comment documenting that trade-off instead.
791-793: Trailing space in uid format may cause extra whitespace.When
numeric_owneris true orunameis empty, the uid is formatted with a trailing space:format!("{} ", p.uid()). This value is then left-padded tou_widthin the output format string ({uname:<u_width$}). The trailing space becomes part of the string length, potentially causing misalignment when the uid string (including the space) is shorter thanu_width.Consider removing the trailing space here and relying solely on the format string's padding:
Proposed fix
if options.numeric_owner || p.uname().is_empty() { - Cow::Owned(format!("{} ", p.uid())) + Cow::Owned(p.uid().to_string()) } else {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cli/src/command/list.rs` around lines 791 - 793, Remove the hard-coded trailing space when building the uname value so padding is handled only by the format string: in the branch that checks options.numeric_owner or p.uname().is_empty() (the expression producing Cow::Owned(format!("{} ", p.uid()))), return the UID without the trailing space (e.g., format!("{}", p.uid()) or p.uid().to_string()) so the later formatting using the u_width width specifier ({uname:<u_width$}) controls alignment and avoids extra whitespace.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@cli/src/command/list.rs`:
- Around line 780-811: The current single-pass loop updates u_width and gs_width
while immediately formatting lines, causing earlier rows to use smaller widths
and misalign columns; change list formatting to a two-pass approach: first
iterate over entries to compute final u_width (max uname length) and gs_width
(max of gname.len() + size.to_string().len() + 1) using the same logic currently
in the loop (respecting options.numeric_owner, PermissionDisplay::bsdtar,
bsd_tar_time, etc.), then do a second pass over entries to produce the output
using those finalized u_width and gs_width values so all lines use consistent
column widths; if streaming was intentional, add a comment documenting that
trade-off instead.
- Around line 791-793: Remove the hard-coded trailing space when building the
uname value so padding is handled only by the format string: in the branch that
checks options.numeric_owner or p.uname().is_empty() (the expression producing
Cow::Owned(format!("{} ", p.uid()))), return the UID without the trailing space
(e.g., format!("{}", p.uid()) or p.uid().to_string()) so the later formatting
using the u_width width specifier ({uname:<u_width$}) controls alignment and
avoids extra whitespace.
There was a problem hiding this comment.
Code Review
This pull request refactors the bsdtar list format output for better compatibility and code structure. The changes include introducing a PermissionDisplay struct for formatting permissions, which is a good improvement. However, I've found a bug related to spacing between username and groupname in the output, which could lead to them being concatenated. I've also included a couple of suggestions to improve code readability and use more idiomatic Rust.
PermissionDisplay writes 11 chars directly to the formatter, eliminating heap allocation in bsd_tar_list_entries_to. JsonL/CSV paths call .to_string() only where serialization requires it.
4209830 to
64d2135
Compare
Summary by CodeRabbit
New Features
Improvements
Tests