History

[tree-diff] [FAIL] try to use peekable()…

…but it doesn't work because it thinks there is a destructor present, even though it's not. These are implemented for Rc/Box/Arc versions of the iterator, but not for the bare one.

Sebastian Thiel committed 5 years ago

Commit 0dcdc0e1 parent bbe7beb1 file · +16 −8Browse files

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

Unified · Split

git-diff/src/visit/changes.rs+16−8
@@ -51,8 +51,8 @@ impl<'a> visit::Changes<'a> { · 50 unmodified lines
5151 R: visit::Record,
5252 {
5353 state.clear();
54− let mut lhs_entries = self.0.take().unwrap_or_default();
55− let mut rhs_entries = other;
54+ let mut lhs_entries = self.0.take().unwrap_or_default().peekable();
55+ let mut rhs_entries = other.peekable();
5656 let mut avoid_popping_path: Option<()> = None;
5757
5858 dbg!("================= START ===================");
@@ -65,16 +65,24 @@ impl<'a> visit::Changes<'a> { · 6 unmodified lines
6565 match state.trees.pop_front() {
6666 Some((None, Some(rhs))) => {
6767 delegate.set_current_path(rhs.parent_path_id.clone());
68− rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;
68+ rhs_entries = locate(&rhs.tree_id, &mut state.buf2)
69+ .ok_or(Error::NotFound(rhs.tree_id))?
70+ .peekable();
6971 }
7072 Some((Some(lhs), Some(rhs))) => {
7173 delegate.set_current_path(lhs.parent_path_id.clone());
72− lhs_entries = locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound(lhs.tree_id))?;
73− rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;
74+ lhs_entries = locate(&lhs.tree_id, &mut state.buf1)
75+ .ok_or(Error::NotFound(lhs.tree_id))?
76+ .peekable();
77+ rhs_entries = locate(&rhs.tree_id, &mut state.buf2)
78+ .ok_or(Error::NotFound(rhs.tree_id))?
79+ .peekable();
7480 }
7581 Some((Some(lhs), None)) => {
7682 delegate.set_current_path(lhs.parent_path_id.clone());
77− lhs_entries = locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound(lhs.tree_id))?;
83+ lhs_entries = locate(&lhs.tree_id, &mut state.buf1)
84+ .ok_or(Error::NotFound(lhs.tree_id))?
85+ .peekable();
7886 }
7987 Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"),
8088 None => return Ok(()),
@@ -189,13 +197,13 @@ impl<'a> visit::Changes<'a> { · 108 unmodified lines
189197 };
190198 }
191199 Less => {
192− let mut cursor = lhs;
200+ let cursor = lhs;
193201 loop {
194202 delete_entry_schedule_recursion(&cursor, &mut state.trees, delegate)?;
195203
196204 match lhs_entries.next() {
197205 Some(entry) => {
198− let entry = entry?;
206+ let _entry = entry?;
199207 // if entry.filename == rhs.
200208 todo!("peek entry, see if we caught up, ")
201209 }