aboutsummaryrefslogtreecommitdiff
path: root/apps/servers/octopus/supergit/src/files.rs
diff options
context:
space:
mode:
authorKaiden Fey <kookie@spacekookie.de>2020-11-10 11:12:29 +0100
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:47 +0100
commita2513a72e699f0db1c345e952b336c6cbc912a3e (patch)
tree4f0bbc8a0a571852eb8dbde76ed51af016bbfd1e /apps/servers/octopus/supergit/src/files.rs
parent9cc32b516d3046c9b96e804bfc15c31e97353b53 (diff)
supergit: implementing simple file-history search
This is done by stepping through a branch iterator to diff commits to see where they changed. This is somewhat computationally intensive, and also doesn't work well yet because iterator stepping is done internally and there is no API to extend iterators before they are run. That means that histories can only be read from first-parent iterators. Ideally we would do two things here: 1. build an API to let iterators extend themselves, either breadth first, or depth first. But maybe that would be too much complexity for the iterator module? 2. figure out a better way to get the history of a file. At the moment we are stepping through commits and diffing them with parents to find the set of changed paths. I don't _think_ there is a way to simply compare refs, but maybe there is.
Diffstat (limited to '')
-rw-r--r--apps/servers/octopus/supergit/src/files.rs23
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