Skip to content

Cli/list/format bsdtar#2788

Merged
ChanTsune merged 4 commits into
mainfrom
cli/list/format-bsdtar
Feb 28, 2026
Merged

Cli/list/format bsdtar#2788
ChanTsune merged 4 commits into
mainfrom
cli/list/format-bsdtar

Conversation

@ChanTsune
Copy link
Copy Markdown
Owner

@ChanTsune ChanTsune commented Feb 28, 2026

Summary by CodeRabbit

  • New Features

    • Added option to append trailing slashes to directory names in list outputs.
  • Improvements

    • Standardized and simplified permission display across all output formats.
    • Improved column alignment and spacing for BSD tar-style listings and other tabular outputs.
    • Consistent formatting applied to JSON, CSV, and TSV outputs.
  • Tests

    • Updated listing tests to match the new standardized output spacing and alignment.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 list command's bsdtar output format by introducing more precise column alignment for user, group, and size information, and adding a configurable option for directory trailing slashes. It also streamlines the internal handling of file permissions to better mimic bsdtar's specific display characteristics, resulting in a more faithful reproduction of its output.

Highlights

  • Refined bsdtar Output Formatting: The bsdtar output format for the list command has been improved to more closely match the native bsdtar utility. This includes adjustments to column widths for user, group, and size fields, as well as specific handling for directory trailing slashes.
  • Introduced dir_trailing_slash Option: A new dir_trailing_slash option has been added to control whether directories in the list output should have a trailing slash. This option is now enabled by default for bsdtar format when listing from standard I/O.
  • Refactored Permission Display Logic: The logic for generating permission strings has been refactored into a new PermissionDisplay struct. This new structure provides a dedicated bsdtar variant to ensure accurate representation of hardlinks ('h') and ACLs ('+') without showing extended attributes ('@'), aligning with bsdtar's archive_entry_strmode.
  • Updated Test Snapshots: Existing test cases for bsdtar format listing have been updated to reflect the new column alignment and directory trailing slash behavior, ensuring consistency and correctness of the output.
Changelog
  • cli/src/command/list.rs
    • Refactored permission string generation into a new PermissionDisplay struct to handle bsdtar specific formatting.
    • Adjusted column width calculations for user, group, and size fields in bsd_tar_list_entries_to for improved alignment.
    • Added dir_trailing_slash field to ListOptions and integrated its usage for directory classification.
  • cli/src/command/stdio.rs
    • Modified run_list_archive to set classify to false and dir_trailing_slash to true by default for bsdtar format.
  • cli/tests/cli/list/option_format_bsdtar.rs
    • Updated expected output in list_format_bsdtar, list_format_bsdtar_with_filter, list_format_bsdtar_with_directory_filter, and list_format_bsdtar_solid tests to match the new bsdtar formatting.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4209830 and 64d2135.

📒 Files selected for processing (3)
  • cli/src/command/list.rs
  • cli/src/command/stdio.rs
  • cli/tests/cli/list/option_format_bsdtar.rs
✅ Files skipped from review due to trivial changes (1)
  • cli/tests/cli/list/option_format_bsdtar.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • cli/src/command/stdio.rs

📝 Walkthrough

Walkthrough

Adds a dir_trailing_slash option to ListOptions and replaces ad-hoc permission formatting with a centralized PermissionDisplay used across all list output formats; updates width/alignment logic and test expectations for bsdtar output.

Changes

Cohort / File(s) Summary
Permission Display & List Rendering
cli/src/command/list.rs
Adds PermissionDisplay abstraction and migrates all permission formatting to it; updates width calculations (e.g., uname_width/gname_widthu_width/gs_width) and adjusts output rendering paths for Line, JsonL, Table, Tree, BsdTar, Csv, and Tsv.
ListOptions fields & initialization
cli/src/command/list.rs, cli/src/command/stdio.rs
Introduces pub(crate) dir_trailing_slash: bool on ListOptions; initializes it to false in list_archive and sets dir_trailing_slash: true while disabling classify in run_list_archive.
Tests: bsdtar formatting
cli/tests/cli/list/option_format_bsdtar.rs
Updates expected bsdtar output strings to reflect normalized spacing and the new permission/owner/group alignment produced by PermissionDisplay.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through columns, tidy and bright,
Swapped scattered letters for one neat sight.
A slash for a folder, permissions aligned,
I pranced through the list and left no gap behind. 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly refers to the main change: BSD tar format improvements for the list command, which aligns with the significant refactoring of permission display formatting and column alignment in the bsdtar output.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cli/list/format-bsdtar

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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_width and gs_width are 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_owner is true or uname is empty, the uid is formatted with a trailing space: format!("{} ", p.uid()). This value is then left-padded to u_width in 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 than u_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.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9457c55 and 4209830.

📒 Files selected for processing (3)
  • cli/src/command/list.rs
  • cli/src/command/stdio.rs
  • cli/tests/cli/list/option_format_bsdtar.rs

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cli/src/command/list.rs Outdated
Comment thread cli/src/command/list.rs
@github-actions github-actions Bot added the cli This issue is about cli application label Feb 28, 2026
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.
@ChanTsune ChanTsune force-pushed the cli/list/format-bsdtar branch from 4209830 to 64d2135 Compare February 28, 2026 11:10
@ChanTsune ChanTsune merged commit aa67122 into main Feb 28, 2026
129 of 133 checks passed
@ChanTsune ChanTsune deleted the cli/list/format-bsdtar branch February 28, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli This issue is about cli application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant