git.delta.rocks / jrsonnet / refs/commits / 5858c9313e03

difftreelog

feat simplify root-based paths

ymrzwqxrYaroslav Bolyukin2026-05-05parent: #7e18d98.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
2use 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};
77
8use 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 = diff
45 .components()
46 .take_while(|c| matches!(c, Component::ParentDir))
47 .count();
48 let base_depth = base
49 .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 }