Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup alias and import maps using Pattern instead of String #8852

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
02cc745
Fix clippy warning error
mischnic Jul 25, 2024
3dd0ffd
Fix broken link
mischnic Jul 25, 2024
9899285
Request::request_pattern
mischnic Jul 25, 2024
e43e162
Fix typo: seqment -> segment
mischnic Jul 26, 2024
e2e8287
Add more pattern helpers
mischnic Jul 25, 2024
a13bb8c
Pattern::with_normalized_path
mischnic Jul 26, 2024
f6caca0
Work
mischnic Jul 25, 2024
bbd0951
Work
mischnic Jul 26, 2024
e03a471
Work
mischnic Jul 26, 2024
a803526
Work
mischnic Jul 26, 2024
513cd4b
Cleanup
mischnic Jul 26, 2024
10c8991
Lint
mischnic Jul 26, 2024
971c7c8
Fix todo
mischnic Jul 26, 2024
8cd0734
Fix Pattern suffix and prefix methods
mischnic Jul 29, 2024
b1dffd2
Fixup
mischnic Jul 29, 2024
4f96c51
More debug logging
mischnic Jul 29, 2024
fe94378
Fix Pattern suffix and prefix methods
mischnic Jul 29, 2024
7b09250
Pattern::normalize for singleton alternatives
mischnic Jul 29, 2024
097df11
Pattern::spread_into_star multiple stars
mischnic Jul 29, 2024
1330eb9
Pattern::spread_into_star noop fix
mischnic Jul 29, 2024
f90bf06
More debug logging
mischnic Jul 29, 2024
ca18c7b
Reenable tests
mischnic Jul 30, 2024
e31aa73
Cleanup
mischnic Jul 30, 2024
9e590a4
More Pattern::request_pattern
mischnic Jul 30, 2024
c50fac6
Remove debug logging
mischnic Jul 30, 2024
f03be42
Cleanup
mischnic Jul 30, 2024
449e71a
Cleanup
mischnic Jul 30, 2024
04387a6
Rename
mischnic Jul 30, 2024
a28a16a
Fix `Cannot find module` error message
mischnic Jul 30, 2024
2b9b33a
Update snapshots
mischnic Jul 30, 2024
ba1a610
Review: skip empty parts
mischnic Jul 30, 2024
66bb0fb
Review: split_could_match instead of must_match
mischnic Jul 30, 2024
937e3f2
Review: properly check if `request == prefix`
mischnic Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions crates/turbo-tasks-fs/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,62 +65,62 @@ pub fn unix_to_sys(path: &str) -> Cow<'_, str> {
}

/// Normalizes a /-separated path into a form that contains no leading /, no
/// double /, no "." seqment, no ".." seqment.
/// double /, no "." segment, no ".." segment.
///
/// Returns None if the path would need to start with ".." to be equal.
pub fn normalize_path(str: &str) -> Option<String> {
let mut seqments = Vec::new();
for seqment in str.split('/') {
match seqment {
let mut segments = Vec::new();
for segment in str.split('/') {
match segment {
"." | "" => {}
".." => {
seqments.pop()?;
segments.pop()?;
}
seqment => {
seqments.push(seqment);
segment => {
segments.push(segment);
}
}
}
Some(seqments.join("/"))
Some(segments.join("/"))
}

/// Normalizes a /-separated request into a form that contains no leading /, no
/// double /, and no "." or ".." seqments in the middle of the request. A
/// request might only start with a single "." seqment and no ".." segements, or
/// any positive number of ".." seqments but no "." seqment.
/// double /, and no "." or ".." segments in the middle of the request. A
/// request might only start with a single "." segment and no ".." segments, or
/// any positive number of ".." segments but no "." segment.
pub fn normalize_request(str: &str) -> String {
let mut seqments = vec!["."];
let mut segments = vec!["."];
// Keeps track of our directory depth so that we can pop directories when
// encountering a "..". If this is positive, then we're inside a directory
// and we can pop that. If it's 0, then we can't pop the directory and we must
// keep the ".." in our seqments. This is not the same as the seqments.len(),
// keep the ".." in our segments. This is not the same as the segments.len(),
// because we cannot pop a kept ".." when encountering another "..".
let mut depth = 0;
let mut popped_dot = false;
for seqment in str.split('/') {
match seqment {
for segment in str.split('/') {
match segment {
"." => {}
".." => {
if depth > 0 {
depth -= 1;
seqments.pop();
segments.pop();
} else {
// The first time we push a "..", we need to remove the "." we include by
// default.
if !popped_dot {
popped_dot = true;
seqments.pop();
segments.pop();
}
seqments.push(seqment);
segments.push(segment);
}
}
seqment => {
seqments.push(seqment);
segment => {
segments.push(segment);
depth += 1;
}
}
}
seqments.join("/")
segments.join("/")
}

/// Converts a disk access Result<T> into a Result<Some<T>>, where a NotFound
Expand Down
Loading
Loading