MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / normalize_worktree

Function normalize_worktree

src/sessions/git_correlation.rs:310–324  ·  view source on GitHub ↗

Lexically normalizes a worktree path for stable equality: trims whitespace, converts backslashes to forward slashes, and strips trailing slashes (keeping a lone `/`). Deliberately does **not** hit the filesystem — writers should pass already-resolved worktree roots (e.g. from [`crate::worktree::git_worktree_root`]); this keeps readers and writers agreeing even when the path no longer exists.

(path: &str)

Source from the content-addressed store, hash-verified

308/// from [`crate::worktree::git_worktree_root`]); this keeps readers and
309/// writers agreeing even when the path no longer exists.
310pub fn normalize_worktree(path: &str) -> String {
311 let mut normalized = path.trim().replace('\\', "/");
312 if let Some(stripped) = normalized.strip_prefix("//?/UNC/") {
313 normalized = format!("//{stripped}");
314 } else if let Some(stripped) = normalized.strip_prefix("//?/") {
315 normalized = stripped.to_string();
316 }
317 if let Some(stripped) = normalized.strip_prefix("/private/var/") {
318 normalized = format!("/var/{stripped}");
319 }
320 while normalized.len() > 1 && normalized.ends_with('/') {
321 normalized.pop();
322 }
323 normalized
324}
325
326/// Validates and lowercases a (possibly abbreviated) commit sha. Requires
327/// 6–64 hex characters: shorter prefixes are too ambiguous to index-match

Calls

no outgoing calls