refactor(mv): split src/core/mv.rs into responsibility-oriented submodules#11
Merged
Merged
Conversation
…dules Break the 1750-line src/core/mv.rs into a module directory organized by responsibility, without any behavior or public API change: - validate.rs: path resolution and existence/collision validation - case_only.rs: case-only rename detection and planning - plan.rs: replacement planning (external/internal/directory), link rewriting construction, ReplacementPlan bookkeeping - apply.rs: filesystem mutation (apply_replacements, line-ending preservation, rename-with-cross-device-fallback, rollback execution) - preview.rs: build_move_preview and print_dry_run_report - mod.rs: pub fn mv / pub fn preview_move and the three orchestration routines (regular file / case-only / directory), plus the existing tests module (kept intact to preserve coverage and minimize risk) The MoveTransaction data model already lives in src/core/model/move_transaction.rs and is reused as-is. All 275 tests pass; scripts/precheck.sh passes locally. Refs #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Split the 1750-line
src/core/mv.rsinto a module directory organized byresponsibility. The public API (
pub fn mv,pub fn preview_move) and everyobservable behavior are unchanged — this is a pure structural refactor with
minor naming/comment polish (no logic rewrites, no signature changes).
Linked Issue
Closes #10
New layout
The
MoveTransactiondata model already lives insrc/core/model/move_transaction.rsand is reused as-is — no new transactionmodule is introduced.
Why this split (and not a different one)
The review brief suggested six candidate seams:
validate / plan / apply / case_only / preview / transaction. I kept five of them and merged the sixth inthe most faithful way to the code as it actually stands today:
transactionis not a new module. TheMoveTransactiontype is alreadyin
src/core/model/move_transaction.rs. The only transactional logic left inmv.rswasexecute_with_rollback, a thin wrapper that runs a closure androlls back on failure. That wrapper lives with its sole caller category —
file-writing — so it now sits in
apply.rsnext toapply_replacements.case_onlyis its own module, not a branch ofplan, because it has itsown destination-detection logic (
resolve_case_only_destination) and its ownfilename-case-preserving relative-path routine, and both need to be usable
before regular planning kicks in. Keeping it separate makes the "am I a
case-only rename?" question a one-file read.
planis the largest module because replacement construction, directorymapping and
ReplacementPlanbookkeeping are all one job: "turn a move into aconcrete set of per-file rewrites, pure computation, no I/O". Splitting it
further would just scatter tightly coupled helpers.
mod.rskeeps the three orchestrators (mv_regular_file,mv_case_only_file,mv_directory+ their preview twins) because each oneis a short top-level recipe that reads top-down and calls into every other
submodule. They are the natural home for cross-module coordination.
Notes for review
pub(super)so nothing new is exposed outsidethe
mvmodule.mod testsis preserved verbatim insidemod.rs. Moving thetests into per-submodule files would have been cleaner on paper, but every
existing test relies on
use super::*and a mix of private helpers fromdifferent seams; keeping them together now avoids subtle coverage regressions
and minimizes diff noise. Per-module test co-location can be a follow-up when
we do the "second-stage" local abstractions the review doc mentions.
Line count after: 6 files, 895 / 535 / 193 / 118 / 110 / 80 lines.
Testing
scripts/precheck.shpasses locally (cargo test: 275 passed, 1 ignored (9 suites))suite (including the 19 tests that exercise
apply_replacements,build_link_replacement,find_reference_definition_url_span,execute_with_rollback, andtry_rename_regular_file_with) alreadycovers the affected surface.