Skip to main content

normalise_machine_paths

Function normalise_machine_paths 

Source
pub fn normalise_machine_paths(
    text: &str,
    root: &Path,
    home: Option<&Path>,
) -> String
Expand description

The repository root written as <repo> and the home directory as <home>.

These are mj_uc_normalise’s first rules, in its order: the canonical (symlinks resolved) spelling of the root, then the spelling the caller gave, then the home directory. The canonical spelling goes first because the given one can be a suffix of it (a temporary directory reached through a symlink), and the root before the home because a checkout usually lives inside one. A trailing separator is not part of a spelling, and a spelling that is empty without it, the filesystem root, replaces nothing.

use majordomus_cli::redaction::normalise_machine_paths;

let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("home");
let root = home.join("checkout");
std::fs::create_dir_all(&root).unwrap();

let text = format!("{}/src/lib.rs and {}/.cache", root.display(), home.display());
let out = normalise_machine_paths(&text, &root, Some(&home));
assert_eq!(out, "<repo>/src/lib.rs and <home>/.cache");