supergit: fix base_history function

wip/yesman
Katharina Fey 3 years ago
parent 3b65ab3fe1
commit 441b53ad83
  1. 54
      apps/servers/octopus/supergit/src/files/tree.rs

@ -31,48 +31,30 @@ impl FileTree {
} }
/// Get the history of a path with a branch iterator /// Get the history of a path with a branch iterator
///
/// This function is computationally light, by not checking for
/// renames between commits. This is done by resolving a path to
/// a tree reference, and comparing references at the same
/// position between two commits.
pub fn base_history(&self, iter: BranchIter, path: &str) -> Option<Vec<Commit>> { pub fn base_history(&self, iter: BranchIter, path: &str) -> Option<Vec<Commit>> {
let mut iter = iter.peekable(); let mut iter = iter.peekable();
let entry = self.resolve(path)?;
let trgid = entry.id();
let mut commits = vec![]; let mut commits = vec![];
// Iterate over the branch in commit pairs // Iterate over the branch in commit pairs
while let (Some(a), b) = iter.next_pair() { while let (Some(a), b) = iter.next_pair() {
dbg!(&a.commit()); let _a = a.commit().clone();
let ta = self.checkout(a.commit().id.clone()); let a = self.checkout(a.commit().id.clone()).resolve(path);
let te_a = dbg!(ta.resolve(dbg!(path))); let b = b.and_then(|c| self.checkout(c.commit().id.clone()).resolve(path));
let b = match b { match (a, b) {
Some(b) => b, // If a path exists in both commits, check if they are
None if te_a.is_some() => { // the same Ref. If they are not, a changed the path.
// If b doesn't exist, but the path exists in a, (Some(a), Some(b)) if a != b => commits.push(_a),
// then it is safe to assume that a introduces the // If a path only exists in a then it was created
// path (Some(_), None) => commits.push(_a),
commits.push(a.commit().clone()); // If a path only exists in b, then it was deleted
break; (None, Some(_)) => commits.push(_a),
} (_, _) => {}
None => break,
};
let tb = self.checkout(b.commit().id.clone());
let te_b = match ta.resolve(path) {
Some(b) => b,
None => continue,
};
let te_a = match te_a {
Some(a) => a,
None => continue,
};
// If the two tree nodes are not equal, add the commit to
// the list. This means that the `a` commit changed
// something in the path.
if dbg!(te_a != te_b) {
commits.push(a.commit().clone());
} }
} }

Loading…
Cancel
Save