diff options
Diffstat (limited to 'src/git/tree.rs')
-rw-r--r-- | src/git/tree.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/git/tree.rs b/src/git/tree.rs index 457eb40..5343a57 100644 --- a/src/git/tree.rs +++ b/src/git/tree.rs @@ -57,6 +57,38 @@ impl Tree { vec }) } + + /// Get all the commits that touch a file + pub(crate) fn grab_path_history(&self, mut path: String) -> String { + let mut path: Vec<String> = path + .split("/") + .filter_map(|seg| match seg { + "" => None, + val => Some(val.into()), + }) + .collect(); + + let leaf = if path.len() > 0 { + let rest = path.split_off(1); + let mut curr = self.inner.get(&path[0]).unwrap(); + + for dir in rest { + match curr { + TreeNode::Dir(d) => curr = d.children.inner.get(&dir).unwrap(), + TreeNode::File(_) => break, // we reached the leaf + } + } + + curr + } else { + panic!("No valid path!"); + }; + + match leaf { + TreeNode::File(f) => f.id.clone(), + _ => panic!("Not a leaf!"), + } + } } #[derive(Clone, Debug)] |