Skip to content

Warn on duplicate update targets and avoid quadratic entry matching#3175

Merged
ChanTsune merged 2 commits into
mainfrom
cli/update/entry-matching-improvements
Jul 8, 2026
Merged

Warn on duplicate update targets and avoid quadratic entry matching#3175
ChanTsune merged 2 commits into
mainfrom
cli/update/entry-matching-improvements

Conversation

@ChanTsune

@ChanTsune ChanTsune commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Resolves two review leftovers from #3007 in update's entry matching: a warning is now emitted when different source paths collapse onto the same archive entry name (identical-path duplicates from overlapping sources stay silent), and the matching loop is rewritten from O(N×M) shift_remove to O(1) lookups while preserving insertion order.

Notes

  • Archive output is unchanged; the only user-visible delta is the new stderr warning, which also applies to the shared compat bsdtar -u path.

Refs #1547

Summary by CodeRabbit

  • Bug Fixes

    • Improved update behavior when multiple source paths map to the same archive entry, including idempotent handling of duplicate source arguments.
    • Added clearer stderr warnings when different source spellings resolve to the same target, while preserving the first mapping.
    • Prevented already-matched archive entries from being re-added during updates, avoiding inconsistencies.
  • Tests

    • Added CLI integration coverage for duplicate and overlapping update sources, including warning assertions.

@github-actions github-actions Bot added the cli This issue is about cli application label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 07a7ad8d-1b53-4c5e-94c5-cbd1605d24c0

📥 Commits

Reviewing files that changed from the base of the PR and between 4725f66 and 573741b.

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

📝 Walkthrough

Walkthrough

The update matching in run_update_archive now consumes archive-entry matches from an IndexMap value slot, warns on colliding source spellings, and only appends entries that were never consumed. New CLI tests cover duplicate and non-duplicate source combinations.

Changes

Duplicate target handling

Layer / File(s) Summary
Mapping logic and remaining-entries loop
cli/src/command/update.rs
Matching logic now uses Option-wrapped map values consumed via get_mut/take instead of shift_remove, warns when multiple sources map to the same entry, and the remaining-entries loop iterates only unconsumed values via into_values().flatten().
Integration tests for duplicate targets
cli/tests/cli/update.rs, cli/tests/cli/update/duplicate_targets.rs
Registers a new duplicate_targets test module with four tests covering duplicate sources, overlapping directory/file arguments, single-source updates, and colliding path spellings that trigger the warning.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant run_update_archive
  participant target_files_mapping
  participant Archive

  CLI->>run_update_archive: invoke update with source paths
  run_update_archive->>target_files_mapping: build entry_name -> Option((idx, item))
  target_files_mapping-->>run_update_archive: duplicate entry name detected
  run_update_archive->>run_update_archive: warn about colliding source spellings
  loop for each archive entry
    run_update_archive->>target_files_mapping: get_mut(entry_name).and_then(Option::take)
    target_files_mapping-->>run_update_archive: consumed item or None
    run_update_archive->>Archive: apply matched update
  end
  run_update_archive->>target_files_mapping: into_values().flatten()
  target_files_mapping-->>run_update_archive: remaining unconsumed entries
  run_update_archive->>Archive: append remaining entries
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: duplicate-target warnings and faster entry matching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli/update/entry-matching-improvements

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.

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

Copy link
Copy Markdown
Contributor

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 optimizes the archive update process by changing the target files mapping from using shift_remove (which is O(n)) to using Option::take with get_mut (which is O(1)), avoiding quadratic complexity. It also introduces warnings when distinct source paths map to the same archive entry while remaining idempotent (and silent) when the exact same path is specified multiple times. Additionally, comprehensive integration tests have been added to verify these behaviors. There are no review comments to address, and I have no further feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@github-actions github-actions Bot added the break API braking change label Jul 8, 2026
@ChanTsune
ChanTsune force-pushed the cli/update/entry-matching-improvements branch from 4725f66 to 573741b Compare July 8, 2026 06:00
@ChanTsune
ChanTsune merged commit 696f9dd into main Jul 8, 2026
109 of 110 checks passed
@ChanTsune
ChanTsune deleted the cli/update/entry-matching-improvements branch July 8, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

break API braking change cli This issue is about cli application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant