diff options
Diffstat (limited to 'apps/servers/octopus/supergit/src/files.rs')
-rw-r--r-- | apps/servers/octopus/supergit/src/files.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/apps/servers/octopus/supergit/src/files.rs b/apps/servers/octopus/supergit/src/files.rs index fa68fbc2f3dc..c593a4923921 100644 --- a/apps/servers/octopus/supergit/src/files.rs +++ b/apps/servers/octopus/supergit/src/files.rs @@ -1,7 +1,7 @@ use crate::{Branch, BranchIter, Commit, HashId}; use atomptr::AtomPtr; use git2::{ObjectType, TreeWalkMode, TreeWalkResult}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, BTreeSet}; use std::{path::PathBuf, sync::Arc}; /// A tree of files @@ -76,6 +76,27 @@ impl FileTree { pub fn load(&self, path: &str) -> Option<Yield> { self.get_entry(path).and_then(|e| e.load(&self.repo)) } + + /// Get the history of a path with a branch iterator + /// + /// This function is very computationally intensive, because it + /// will step through the entire iterator to pull commits from, + /// and see if they touch the respective path. + pub fn history(&self, iter: BranchIter, path: &str) -> Vec<Commit> { + iter.filter_map(|c| { + if c.commit() + .get_paths() + .into_iter() + .collect::<BTreeSet<_>>() + .contains(path) + { + Some(c.commit().clone()) + } else { + None + } + }) + .collect() + } } /// Data yielded from loading a part of the file tree |