diff options
author | Katharina Fey <kookie@spacekookie.de> | 2020-06-22 16:33:28 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2020-06-22 16:33:28 +0200 |
commit | a0dca8186bdef76e09e9c388d7f85839e85ce8db (patch) | |
tree | e10257f724b01ddc9b8244c9b2429921612b6856 /src/git/tree.rs | |
parent | 367cb0b2358be04d18dfea963d1c42044893e3b4 (diff) |
git: refactoring git module to have a unified actions API
Diffstat (limited to '')
-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)] |