From c1392d6e1cc8bb21dd8e59c4226f6d9154e1844e Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Wed, 22 Dec 2021 23:30:30 +0100 Subject: The calling process must have a common parent with delta Ensures that no unrelated process is found when selectively refreshing a pid range. --- src/utils/process.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/utils/process.rs b/src/utils/process.rs index 26d68d68..cc75e31c 100644 --- a/src/utils/process.rs +++ b/src/utils/process.rs @@ -364,7 +364,11 @@ trait ProcessInterface { }; iter_parents(self, pid, &mut sum_distance); - Some((length_of_process_chain, args)) + if length_of_process_chain == usize::MAX { + None + } else { + Some((length_of_process_chain, args)) + } } _ => None, }) @@ -848,6 +852,20 @@ pub mod tests { calling_process_cmdline(ProcInfo::new(), guess_git_blame_filename_extension); } + #[test] + fn test_process_blame_no_parent_found() { + let two_trees = MockProcInfo::with(&[ + (2, 100, "-shell", None), + (3, 100, "git blame src/main.rs", Some(2)), + (4, 100, "call_delta.sh", None), + (5, 100, "delta", Some(4)), + ]); + assert_eq!( + calling_process_cmdline(two_trees, guess_git_blame_filename_extension), + None + ); + } + #[test] fn test_process_blame_info_with_parent() { let no_processes = MockProcInfo::with(&[]); -- cgit v1.2.3