Repository navigation
pushd: route the Dir operand through cd's search funnel and preserve the // prefix - #3259
Merged
Merged
Conversation
… // prefix GNU pushd_builtin delegates its Dir operand to cd_builtin (builtins/pushd.def:296-302), so cd's CDPATH loop (builtins/cd.def:353-388) and the cdable_vars fallback are pushd's own resolution too. cd gains a pub(crate) wrapper (resolve_search_operand) over its existing private resolve_cdpath/resolve_cdable_vars stages, run in cd's order over a Target built the way resolve_target builds a plain operand; pushd consumes the funnel and keeps its own failure diagnostics. cd's existing logic is unchanged. For the // face: pushd's normalize_stack_dir rebuilt paths from components under a hardcoded single-slash prefix, so exactly two leading slashes could never survive. It now re-applies the prefix through cd's preserve_leading_double_slash (visibility widened pub(super) -> pub(crate), logic unchanged), taking the evidence spelling from the operand itself for absolute operands and from $PWD for relative ones, never from the joined text (the rubash#2211 rule). Refs #3196 Refs #3197
…e // prefix The components cell read as a product failure (PWD and stack top showing a single slash), but instrumented probes on the head build show normalize_stack_dir, bindpwd and the saved stack all carrying //<scratch>/sub verbatim, and the raw child stdout is byte-exact //<scratch>/sub — the GNU form (cd.def change_to_directory via sh_canonpath). The slash was lost in the pin's own run_script normalization: the scratch spelling starts with `/`, so replace(scratch, "WORK") matches from the second slash of a preserved // prefix and consumes it. Replace the fused /<scratch> form first (-> //WORK), then the bare scratch. Expectations unchanged; the base fail-first shape is preserved (base output carries no // to fuse, so the cell still reads WORK/sub against the //WORK/sub expectation). Refs #3197
caomengxuan666
marked this pull request as ready for review
November 10, 2026 13:00
This was referenced Nov 10, 2026
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.
Refs #3196
Refs #3197
What this changes
pushd's Dir operand now goes through cd's own directory-search funnel, and the exactly-two-slashes prefix survives in the spellingpushdstores on the stack and binds to$PWD.cd_builtin(builtins/pushd.def:296-302), whose CDPATH loop (builtins/cd.def:353-388) and cdable_vars fallback decide the spelling.pushdpreviously normalized the raw operand itself and never searched CDPATH. cd.rs gains apub(crate)wrapper (resolve_search_operand/SearchResolution) over cd's existing privateresolve_cdpathandresolve_cdable_varsstages, run in cd's order over a Target built the way cd builds a plain operand;pushdconsumes the outcome and announces hits the way cd announces them (a non-empty CDPATH unit echoes the found directory, cdable_vars echoes the variable's raw value, before the dirs listing). cd's own logic is untouched.normalize_stack_dirrebuilt the path from components under a hardcoded single-/prefix, so a//prefix could never survive. It now re-applies the prefix through cd's existingpreserve_leading_double_slash(cd/paths.rs, the cd inside un-redirected command substitution resolves against startup cwd after the shell has cd'd #2211 mechanism), with the slash evidence taken from the spelling the path was built from — the operand itself for an absolute operand, the base$PWDfor a relative one — never the joined text. GNU anchor:change_to_directory(builtins/cd.def:522ff) canonicalizes viash_canonpath; exactly two leading slashes are preserved, three or more collapse to one (oracle-verified:pushd //binds//,pushd //tmp/../tmpbinds//tmp).Regression pins
tests/issue3196_pushd_cdpath_regressions.rs— 6 cells: seed CDPATH form, unit forms, CDPATH-beats-cwd and slash operands, empty-unit silent hit, miss/dot-led/-ncontrols, cdable_vars through pushd.tests/issue3197_pushd_double_slash_regressions.rs— 3 cells://root form plus popd return, single/triple-slash andcd //controls, components/dotdot/relative-from-//forms.One pin-harness note: the 3197 pin's scratch-path normalization originally replaced the bare scratch spelling first; because the scratch itself starts with
/, that match began at the second slash of a preserved//value and consumed the prefix under test, so the components cell reported a product failure that byte-level probes disproved (raw child stdout is//<scratch>/subverbatim, and the instrumented bindpwd/stack values carry//end to end). The harness now replaces the fused/<scratch>form first. Expectations and assertions are unchanged, and the base fail-first shape is preserved (see below).本 PR 删除了什么
src/builtins/pushd.rs: the Dir arm's directnormalize_stack_dir(&dir, …)call on the raw operand (superseded by cd-funnel resolution before normalization).src/builtins/pushd/stack.rs: the prefix-arm lines insidenormalize_stack_dirthat rebuilt the result under a single-/prefix with no way to represent//(superseded by re-applying the prefix through cd's preservation helper).src/builtins/cd/paths.rs: thepub(super)visibility specifier onpreserve_leading_double_slash, widened topub(crate)so pushd reuses the one implementation; the function's logic is unchanged.tests/issue3197_pushd_double_slash_regressions.rs: the single-expression scratch replacement inrun_script, superseded by the two-stage replacement described above.Verification (Simular box, serial cargo lock,
CARGO_INCREMENTAL=0,-j 2)Base
9ec03556with only the pins added (fail-first, matching the pin design cell for cell):Head
f45d120b:test resultline): all green, exceptissue423_interactive_cd_child_cwd_regressionsat 0 passed / 2 failed with the identical two test names red on the base commit — an environment shape (missing PTY harness binary), not a regression of this change. The Windows-gated stems in the set run 0 tests on Linux.RUSTFLAGS="-D warnings"check over lib and bins: rc 0.cargo fmt --checkon the working tree: rc 0.python3 scripts/check-marker-literals.py: rc 0.