History

[git-diff] refactor

Sebastian Thiel committed 5 years ago

Commit fa8b4e81 parent 9ade04c1 file · +12 −10Browse files

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

Unified · Split

git-diff/src/tree/changes.rs+12−10
@@ -50,15 +50,15 @@ impl<'a> tree::Changes<'a> { · 49 unmodified lines
5050 ///
5151 /// [git_cmp_c]: https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/tree-diff.c#L49:L65
5252 /// [git_cmp_rs]: https://github.com/Byron/gitoxide/blob/a4d5f99c8dc99bf814790928a3bf9649cd99486b/git-object/src/mutable/tree.rs#L52-L55
53− pub fn needed_to_obtain<LocateFn, R, StateMut>(
53+ pub fn needed_to_obtain<FindFn, R, StateMut>(
5454 mut self,
5555 other: immutable::TreeIter<'a>,
5656 mut state: StateMut,
57− mut locate: LocateFn,
57+ mut find: FindFn,
5858 delegate: &mut R,
5959 ) -> Result<(), Error>
6060 where
61− LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>,
61+ FindFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>,
6262 R: tree::Visit,
6363 StateMut: BorrowMut<tree::State>,
6464 {
@@ -66,32 +66,34 @@ impl<'a> tree::Changes<'a> { · 1 unmodified line
6666 state.clear();
6767 let mut lhs_entries = peekable(self.0.take().unwrap_or_default());
6868 let mut rhs_entries = peekable(other);
69− let mut avoid_popping_path: Option<()> = None;
69+ let mut pop_path = false;
7070
7171 loop {
72− if avoid_popping_path.take().is_none() {
72+ if pop_path {
7373 delegate.pop_path_component();
7474 }
75+ pop_path = true;
76+
7577 match (lhs_entries.next(), rhs_entries.next()) {
7678 (None, None) => {
7779 match state.trees.pop_front() {
7880 Some((None, Some(rhs))) => {
7981 delegate.pop_front_tracked_path_and_set_current();
80− rhs_entries = peekable(locate(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
82+ rhs_entries = peekable(find(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
8183 }
8284 Some((Some(lhs), Some(rhs))) => {
8385 delegate.pop_front_tracked_path_and_set_current();
84− lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);
85− rhs_entries = peekable(locate(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
86+ lhs_entries = peekable(find(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);
87+ rhs_entries = peekable(find(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
8688 }
8789 Some((Some(lhs), None)) => {
8890 delegate.pop_front_tracked_path_and_set_current();
89− lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);
91+ lhs_entries = peekable(find(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);
9092 }
9193 Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"),
9294 None => return Ok(()),
9395 };
94− avoid_popping_path = Some(());
96+ pop_path = false;
9597 }
9698 (Some(lhs), Some(rhs)) => {
9799 use std::cmp::Ordering::*;