Skip to content

♻️ Refactor collect_items to use CollectOptions struct#2522

Merged
ChanTsune merged 1 commit into
mainfrom
cli/refactor/internal-path-worker
Dec 27, 2025
Merged

♻️ Refactor collect_items to use CollectOptions struct#2522
ChanTsune merged 1 commit into
mainfrom
cli/refactor/internal-path-worker

Conversation

@ChanTsune
Copy link
Copy Markdown
Owner

@ChanTsune ChanTsune commented Dec 27, 2025

Redesign the collect_items function to improve API clarity

  • Add CollectOptions struct to group traversal/filtering parameters
  • Change collect_items to accept a single path instead of multiple paths
  • Add collect_items_from_paths convenience wrapper for multi-path use
  • Update all call sites (create, append, update, stdio) to use new API
  • Add Debug derives to TimeFilter and TimeFilters for consistency

This refactoring:

  • Eliminates 10 positional parameters in favor of a structured options type
  • Removes the need for #[allow(clippy::too_many_arguments)]
  • Makes order preservation explicit (caller controls iteration)

Summary by CodeRabbit

  • Refactor

    • Unified item collection behind a single options-driven workflow for consistent traversal and filtering.
    • Improved time-filtering support, including an "older-than" timestamp option for retention/selection.
  • Tests

    • Added and updated unit tests and helpers to cover the new collection and time-filter behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 27, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Consolidates per-path traversal and filtering flags into a new CollectOptions struct and replaces the multi-parameter collect_items API with collect_items_from_paths(&paths, &CollectOptions). Call sites in create/append/update/stdio now build CollectOptions and call the new wrapper. Time filters gained older_than and derive traits.

Changes

Cohort / File(s) Summary
Core API & collector
cli/src/command/core.rs
Added CollectOptions<'a>; replaced multi-parameter collect_items with per-path collect_items(path, options) and public collect_items_from_paths(paths, &CollectOptions); introduced shared hardlink resolver across paths; moved traversal, gitignore, nodump, follow-link, one-filesystem, filter and time-filter logic to use options.
Time filter types
cli/src/command/core/time_filter.rs
TimeFilter and TimeFilters now derive Clone and Debug; TimeFilter gained older_than: Option<SystemTime).
CLI call sites
cli/src/command/append.rs, cli/src/command/create.rs, cli/src/command/update.rs, cli/src/command/stdio.rs
Replaced direct collect_items(...) calls with construction of CollectOptions from CLI flags and calls to collect_items_from_paths(&files, &collect_options); updated imports to use CollectOptions and collect_items_from_paths.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through flags and bundled them tight,
A little struct to keep options right.
Paths line up neat, old times now in sight,
Hardlinks remembered, traversal polite.
Hooray — collection’s tidy tonight! 🥕

Pre-merge checks and finishing touches

✅ 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 accurately describes the main refactoring: replacing collect_items parameters with a CollectOptions struct to improve API clarity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cli/refactor/internal-path-worker

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 711fa0b and 3286c61.

📒 Files selected for processing (6)
  • cli/src/command/append.rs
  • cli/src/command/core.rs
  • cli/src/command/core/time_filter.rs
  • cli/src/command/create.rs
  • cli/src/command/stdio.rs
  • cli/src/command/update.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • cli/src/command/create.rs
  • cli/src/command/core/time_filter.rs
🧰 Additional context used
🧬 Code graph analysis (4)
cli/src/command/append.rs (1)
cli/src/command/core.rs (1)
  • collect_items_from_paths (309-323)
cli/src/command/update.rs (2)
cli/src/command/core.rs (4)
  • collect_items_from_paths (309-323)
  • collect_split_archives (491-508)
  • create_entry (534-604)
  • entry_option (606-626)
cli/src/cli.rs (1)
  • files (176-186)
cli/src/command/stdio.rs (1)
cli/src/command/core.rs (3)
  • collect_items_from_paths (309-323)
  • collect_split_archives (491-508)
  • entry_option (606-626)
cli/src/command/core.rs (3)
cli/src/command/core/path.rs (1)
  • new (28-38)
cli/src/command/core/path_filter.rs (1)
  • new (12-20)
cli/src/utils/fs/nodump.rs (3)
  • is_nodump (15-20)
  • is_nodump (28-31)
  • is_nodump (43-45)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: Test WebAssembly (beta, wasm32-unknown-unknown)
  • GitHub Check: tier1 (windows-latest, nightly)
  • GitHub Check: tier3 (ubuntu-latest, stable, x86_64-unknown-fuchsia)
  • GitHub Check: tier1 (macos-latest, nightly)
  • GitHub Check: tier1 (ubuntu-latest, beta)
  • GitHub Check: tier1 (ubuntu-latest, nightly)
  • GitHub Check: tier1 (ubuntu-22.04-arm, stable)
  • GitHub Check: tier1 (ubuntu-22.04-arm, nightly)
  • GitHub Check: tier1 (ubuntu-latest, stable)
  • GitHub Check: Test WebAssembly (stable, wasm32-unknown-emscripten)
  • GitHub Check: Test WebAssembly (nightly-2025-12-09, wasm32-unknown-emscripten)
  • GitHub Check: Test WebAssembly (stable, wasm32-wasip2)
  • GitHub Check: Test WebAssembly (beta, wasm32-unknown-emscripten)
  • GitHub Check: Test WebAssembly (nightly-2025-12-09, wasm32-unknown-unknown)
  • GitHub Check: Test WebAssembly (beta, wasm32-unknown-unknown)
  • GitHub Check: Test WebAssembly (stable, wasm32-unknown-unknown)
  • GitHub Check: msrv (ubuntu-latest, portable-network-archive)
  • GitHub Check: msrv (ubuntu-latest, libpna)
  • GitHub Check: tier3_cross (redoxos/redoxer, x86_64-unknown-redox)
🔇 Additional comments (7)
cli/src/command/update.rs (1)

13-17: LGTM! Clean refactoring to CollectOptions struct.

The refactoring successfully consolidates traversal and filtering parameters into a single CollectOptions struct, replacing the previous multi-parameter approach. The recursive flag handling correctly uses !args.no_recursive to respect both the --recursive (default true) and --no-recursive flags.

Also applies to: 441-452

cli/src/command/append.rs (1)

9-12: LGTM! Consistent refactoring across commands.

The append command correctly adopts the same CollectOptions pattern as the update command, with proper handling of the recursive flags using !args.no_recursive.

Also applies to: 428-439

cli/src/command/stdio.rs (1)

542-553: Create path correctly handles recursive flag.

The create path properly uses !args.no_recursive to respect both --recursive (default true) and --no-recursive flags.

cli/src/command/core.rs (4)

30-45: LGTM! Well-designed options struct.

The CollectOptions struct successfully consolidates 10 previously separate parameters into a cohesive, well-documented configuration type. The lifetime parameter correctly handles borrowed filter references, and the documentation clearly explains the struct's purpose.


300-323: LGTM! Cross-path hardlink detection correctly implemented.

The function properly shares a single HardlinkResolver across all input paths (line 313), enabling cross-path hardlink recognition as documented. The past review concern about hardlink state not being shared has been correctly addressed in this implementation.


369-484: LGTM! Comprehensive traversal implementation.

The per-path collection correctly implements all traversal options, filtering, and classification logic. The function properly handles:

  • Directory recursion based on options.recursive
  • Path filtering via options.filter
  • Gitignore rules via per-directory .gitignore files
  • Time-based filtering when active
  • Hardlink detection via shared resolver
  • Broken symlink tolerance
  • Unsupported file type errors

Note: Each top-level path creates its own Ignore instance (line 374), treating CLI path arguments independently for gitignore purposes.


1243-1345: LGTM! Tests properly updated for new API.

The test helper default_collect_options provides clean defaults, and all tests correctly exercise the new collect_items_from_paths API with CollectOptions. The test coverage maintains verification of key behaviors: non-recursive collection, directory retention, and recursive traversal.


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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ChanTsune, 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 focuses on enhancing the maintainability and clarity of the filesystem item collection logic. By introducing a CollectOptions struct, it centralizes various parameters that control how files and directories are gathered for archiving. This change streamlines the core collect_items function, making its signature cleaner and its usage more structured, while also providing a convenient wrapper for handling multiple input paths.

Highlights

  • API Refactoring: The collect_items function has been redesigned to improve API clarity by consolidating numerous traversal and filtering parameters into a new CollectOptions struct.
  • Function Signature Change: The original collect_items function now accepts a single path and the CollectOptions struct, significantly reducing its argument count and removing the need for #[allow(clippy::too_many_arguments)].
  • New Convenience Wrapper: A new function, collect_items_from_paths, has been introduced to handle scenarios where multiple paths need to be processed, preserving the order of items as specified by the caller.
  • Call Site Updates: All existing call sites for collect_items across various commands (append, create, stdio, update) have been updated to utilize the new CollectOptions struct and collect_items_from_paths where appropriate.
  • Debug Derives: #[derive(Clone, Debug)] has been added to the TimeFilter and TimeFilters structs for consistency and easier debugging.
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.

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

The pull request refactors the collect_items function by introducing a CollectOptions struct to consolidate its numerous parameters and splitting it into collect_items (for single paths) and collect_items_from_paths (for multiple paths). The TimeFilter and TimeFilters structs were also updated with Clone and Debug derives. The reviewer noted that this refactoring inadvertently changed the behavior of hardlink detection and .gitignore processing, as HardlinkResolver and Ignore are now re-initialized for each path, preventing state sharing across top-level path arguments. The suggested fix is to initialize these stateful components once in collect_items_from_paths and pass them as mutable references to collect_items to restore the original behavior, requiring corresponding test updates.

Comment thread cli/src/command/core.rs Outdated
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.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63c53aa and 711fa0b.

📒 Files selected for processing (6)
  • cli/src/command/append.rs
  • cli/src/command/core.rs
  • cli/src/command/core/time_filter.rs
  • cli/src/command/create.rs
  • cli/src/command/stdio.rs
  • cli/src/command/update.rs
🧰 Additional context used
🧬 Code graph analysis (4)
cli/src/command/core.rs (2)
cli/src/command/core/path_filter.rs (1)
  • new (12-20)
cli/src/utils/fs/nodump.rs (3)
  • is_nodump (15-20)
  • is_nodump (28-31)
  • is_nodump (43-45)
cli/src/command/create.rs (1)
cli/src/command/core.rs (2)
  • collect_items_from_paths (309-318)
  • create_entry (526-596)
cli/src/command/stdio.rs (1)
cli/src/command/core.rs (1)
  • collect_items_from_paths (309-318)
cli/src/command/update.rs (1)
cli/src/command/core.rs (1)
  • collect_items_from_paths (309-318)
🔇 Additional comments (12)
cli/src/command/core/time_filter.rs (1)

6-6: LGTM! Standard trait derives added for consistency.

Adding Clone and Debug derives enables CollectOptions to derive these traits as well, which is a good practice for option structs.

Also applies to: 54-54

cli/src/command/stdio.rs (1)

11-14: LGTM! Import updates align with the refactored API.

The imports correctly reflect the new CollectOptions-based collection API.

cli/src/command/append.rs (2)

428-439: LGTM! Correct CollectOptions construction.

The option struct is correctly constructed with all required fields mapped from the CLI arguments.


9-12: LGTM! Import updates reflect the new API.

Imports correctly updated to use CollectOptions and collect_items_from_paths.

cli/src/command/update.rs (2)

441-452: LGTM! Consistent CollectOptions construction.

The options are correctly constructed following the same pattern as other command modules.


13-17: LGTM! Import updates are correct.

Imports properly updated for the refactored API.

cli/src/command/create.rs (2)

421-432: LGTM! Proper options construction.

The CollectOptions struct is correctly populated with all necessary fields.


9-12: LGTM! Import changes align with refactoring.

Imports correctly updated to support the new collection API.

cli/src/command/core.rs (4)

30-45: LGTM! Well-documented options struct.

The CollectOptions struct effectively consolidates the 10+ parameters into a single, well-documented type. The documentation clearly explains the purpose of this refactoring.


300-318: LGTM! Order-preserving wrapper function.

The collect_items_from_paths wrapper correctly iterates over paths and aggregates results while preserving order. The documentation clearly states the order preservation guarantee, which is important for predictable archive behavior.


361-476: LGTM! Refactored function maintains correct behavior.

The refactored collect_items function correctly uses all fields from CollectOptions:

  • Lines 366: options.follow_links for hardlink resolver
  • Lines 369-377: options.recursive, options.follow_links, options.follow_command_links, options.one_file_system for walkdir configuration
  • Lines 386: options.follow_links and options.follow_command_links for should_follow logic
  • Lines 392: options.filter for exclusion
  • Lines 399-411: options.gitignore for gitignore handling
  • Lines 413-426: options.nodump for nodump checking
  • Lines 439: options.keep_dir for directory retention
  • Lines 452-459: options.time_filters for time-based filtering

All parameters are correctly threaded through the logic without behavioral changes.


1235-1263: LGTM! Test helper and tests updated correctly.

The default_collect_options helper provides sensible defaults for testing, and the tests are properly updated to use the new API. The test logic remains unchanged.

Comment thread cli/src/command/stdio.rs
@github-actions github-actions Bot added the cli This issue is about cli application label Dec 27, 2025
Redesign the collect_items function to improve API clarity

- Add CollectOptions struct to group traversal/filtering parameters
- Change collect_items to accept a single path instead of multiple paths
- Add collect_items_from_paths convenience wrapper for multi-path use
- Update all call sites (create, append, update, stdio) to use new API
- Add Debug derives to TimeFilter and TimeFilters for consistency

This refactoring:
- Eliminates 10 positional parameters in favor of a structured options type
- Removes the need for #[allow(clippy::too_many_arguments)]
- Makes order preservation explicit (caller controls iteration)
@ChanTsune ChanTsune force-pushed the cli/refactor/internal-path-worker branch from 711fa0b to 3286c61 Compare December 27, 2025 13:51
@ChanTsune ChanTsune merged commit f2f9d47 into main Dec 27, 2025
100 checks passed
@ChanTsune ChanTsune deleted the cli/refactor/internal-path-worker branch December 27, 2025 22:13
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