difftreelog
feat simplify root-based paths
in: master
1 file changed
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth2use std::cell::RefCell;2use std::cell::RefCell;3use std::{3use std::{4 any::Any,4 any::Any,5 path::{Path, PathBuf},5 path::{Component, Path, PathBuf},6};6};778use jrsonnet_gcmodule::Trace;8use jrsonnet_gcmodule::Trace;40 if from.is_relative() {40 if from.is_relative() {41 return from.to_string_lossy().into_owned();41 return from.to_string_lossy().into_owned();42 }42 }43 pathdiff::diff_paths(from, base)43 let diff = pathdiff::diff_paths(from, base).expect("base is absolute");44 .expect("base is absolute")44 let parents = diff45 .components()46 .take_while(|c| matches!(c, Component::ParentDir))47 .count();48 let base_depth = base49 .components()50 .filter(|c| matches!(c, Component::Normal(_)))51 .count();52 if parents > 0 && parents >= base_depth {53 return from.to_string_lossy().into_owned();54 }45 .to_string_lossy()55 diff.to_string_lossy().into_owned()46 .into_owned()47 }56 }48 }57 }