History

[tree-diff] test modification within a directory

Sebastian Thiel committed 5 years ago

Commit ff82a821 parent c223e312 files · +71 −19Browse files

Showing the changes to git-diff/src (1 of 2 files). Show all

Unified · Split

git-diff/src/visit/changes.rs+33−11
@@ -37,6 +37,7 @@ impl<'a> visit::Changes<'a> { · 36 unmodified lines
3737 /// * it does a breadth first iteration as buffer space only fits two trees, the current one on the one we compare with.
3838 /// * does not do rename tracking but attempts to reduce allocations to zero (so performance is mostly determined
3939 /// by the delegate implementation which should be as specific as possible.
40+ /// * cycle checking is not performed, but can be performed in the delegate
4041 pub fn needed_to_obtain<LocateFn, R>(
4142 mut self,
4243 other: immutable::TreeIter<'a>,
@@ -58,15 +59,27 @@ impl<'a> visit::Changes<'a> { · 15 unmodified lines
5859 delegate.pop_path_component();
5960 }
6061 match (lhs_entries.next(), rhs_entries.next()) {
61− (None, None) => match state.trees.pop_front() {
62− Some((None, Some(rhs))) => {
63− delegate.set_current_path(rhs.parent_path_id.clone());
64− rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;
65− avoid_popping_path = Some(());
66− }
67− None => return Ok(()),
68− _ => todo!("all other combinations to re-stock iterators"),
69− },
62+ (None, None) => {
63+ match state.trees.pop_front() {
64+ Some((None, Some(rhs))) => {
65+ delegate.set_current_path(rhs.parent_path_id.clone());
66+ rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;
67+ }
68+ Some((Some(lhs), Some(rhs))) => {
69+ delegate.set_current_path(lhs.parent_path_id.clone());
70+ lhs_entries = locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound(lhs.tree_id))?;
71+ rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;
72+ }
73+ Some((Some(_lhs), None)) => {
74+ todo!("locate none|tree");
75+ // delegate.set_current_path(lhs.parent_path_id.clone());
76+ // lhs_entries = locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound(lhs.tree_id))?;
77+ }
78+ Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"),
79+ None => return Ok(()),
80+ };
81+ avoid_popping_path = Some(());
82+ }
7083 (Some(lhs), Some(rhs)) => {
7184 use std::cmp::Ordering::*;
7285 let (lhs, rhs) = (lhs?, rhs?);
@@ -75,7 +88,7 @@ impl<'a> visit::Changes<'a> { · 2 unmodified lines
7588 use tree::EntryMode::*;
7689 match (lhs.mode, rhs.mode) {
7790 (Tree, Tree) => {
78− let _path_id = delegate.push_tracked_path_component(lhs.filename);
91+ let path_id = delegate.push_tracked_path_component(lhs.filename);
7992 if lhs.oid != rhs.oid
8093 && delegate
8194 .record(Change::Modification {
@@ -88,7 +101,16 @@ impl<'a> visit::Changes<'a> { · 6 unmodified lines
88101 {
89102 return Err(Cancelled);
90103 }
91− todo!("schedule tree|tree iteration schedule the trees with stack")
104+ state.trees.push_back((
105+ Some(TreeInfo {
106+ tree_id: lhs.oid.to_owned(),
107+ parent_path_id: path_id.clone(),
108+ }),
109+ Some(TreeInfo {
110+ tree_id: rhs.oid.to_owned(),
111+ parent_path_id: path_id,
112+ }),
113+ ));
92114 }
93115 (lhs_mode, Tree) if lhs_mode.is_no_tree() => {
94116 let path_id = delegate.push_tracked_path_component(lhs.filename);