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
50 ///50 ///
51 /// [git_cmp_c]: https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/tree-diff.c#L49:L6551 /// [git_cmp_c]: https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/tree-diff.c#L49:L65
52 /// [git_cmp_rs]: https://github.com/Byron/gitoxide/blob/a4d5f99c8dc99bf814790928a3bf9649cd99486b/git-object/src/mutable/tree.rs#L52-L5552 /// [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>(
54 mut self,54 mut self,
55 other: immutable::TreeIter<'a>,55 other: immutable::TreeIter<'a>,
56 mut state: StateMut,56 mut state: StateMut,
57 mut locate: LocateFn,57 mut find: FindFn,
58 delegate: &mut R,58 delegate: &mut R,
59 ) -> Result<(), Error>59 ) -> Result<(), Error>
60 where60 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>>,
62 R: tree::Visit,62 R: tree::Visit,
63 StateMut: BorrowMut<tree::State>,63 StateMut: BorrowMut<tree::State>,
64 {64 {
@@ -66,32 +66,34 @@ impl<'a> tree::Changes<'a> { · 1 unmodified line
66 state.clear();66 state.clear();
67 let mut lhs_entries = peekable(self.0.take().unwrap_or_default());67 let mut lhs_entries = peekable(self.0.take().unwrap_or_default());
68 let mut rhs_entries = peekable(other);68 let mut rhs_entries = peekable(other);
69 let mut avoid_popping_path: Option<()> = None;69 let mut pop_path = false;
70 70
71 loop {71 loop {
72 if avoid_popping_path.take().is_none() {72 if pop_path {
73 delegate.pop_path_component();73 delegate.pop_path_component();
74 }74 }
75 pop_path = true;
76
75 match (lhs_entries.next(), rhs_entries.next()) {77 match (lhs_entries.next(), rhs_entries.next()) {
76 (None, None) => {78 (None, None) => {
77 match state.trees.pop_front() {79 match state.trees.pop_front() {
78 Some((None, Some(rhs))) => {80 Some((None, Some(rhs))) => {
79 delegate.pop_front_tracked_path_and_set_current();81 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 })?);
81 }83 }
82 Some((Some(lhs), Some(rhs))) => {84 Some((Some(lhs), Some(rhs))) => {
83 delegate.pop_front_tracked_path_and_set_current();85 delegate.pop_front_tracked_path_and_set_current();
84 lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);86 lhs_entries = peekable(find(&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 })?);87 rhs_entries = peekable(find(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
86 }88 }
87 Some((Some(lhs), None)) => {89 Some((Some(lhs), None)) => {
88 delegate.pop_front_tracked_path_and_set_current();90 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 })?);
90 }92 }
91 Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"),93 Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"),
92 None => return Ok(()),94 None => return Ok(()),
93 };95 };
94 avoid_popping_path = Some(());96 pop_path = false;
95 }97 }
96 (Some(lhs), Some(rhs)) => {98 (Some(lhs), Some(rhs)) => {
97 use std::cmp::Ordering::*;99 use std::cmp::Ordering::*;