History

refactor

Sebastian Thiel committed 5 years ago

Commit 109c4e01 parent e7a7ee81 file · +43 −38Browse files

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

Unified · Split

git-diff/src/visit/changes.rs+43−38
@@ -90,43 +90,7 @@ impl<'a> visit::Changes<'a> { · 89 unmodified lines
9090 let (lhs, rhs) = (lhs?, rhs?);
9191 match lhs.filename.cmp(rhs.filename) {
9292 Equal => handle_lhs_and_rhs_with_equal_filenames(lhs, rhs, &mut state.trees, delegate)?,
93− Less => {
94− delete_entry_schedule_recursion(lhs, &mut state.trees, delegate)?;
95− 'inner_less: loop {
96− match lhs_entries.peek() {
97− Some(Ok(lhs)) => match lhs.filename.cmp(rhs.filename) {
98− Equal => {
99− let lhs =
100− lhs_entries.next().transpose()?.expect("the peeked item tobe present");
101− handle_lhs_and_rhs_with_equal_filenames(
102− lhs,
103− rhs,
104− &mut state.trees,
105− delegate,
106− )?;
107− break 'inner_less;
108− }
109− Less => {
110− let lhs =
111− lhs_entries.next().transpose()?.expect("the peeked item tobe present");
112− delegate.pop_path_component();
113− delete_entry_schedule_recursion(lhs, &mut state.trees, delegate)?;
114− }
115− Greater => {
116− delegate.pop_path_component();
117− add_entry_schedule_recursion(rhs, &mut state.trees, delegate)?;
118− break 'inner_less;
119− }
120− },
121− Some(Err(err)) => return Err(Error::EntriesDecode(err.to_owned())),
122− None => {
123− delegate.pop_path_component();
124− add_entry_schedule_recursion(rhs, &mut state.trees, delegate)?;
125− break 'inner_less;
126− }
127− }
128− }
129− }
93+ Less => catchup_lhs_with_rhs(&mut lhs_entries, lhs, rhs, &mut state.trees, delegate)?,
13094 Greater => {
13195 add_entry_schedule_recursion(rhs, &mut state.trees, delegate)?;
13296 'inner_greater: loop {
@@ -237,6 +201,45 @@ fn add_entry_schedule_recursion<R: visit::Record>( · 104 unmodified lines
237201 Ok(())
238202 }
239203
204+fn catchup_lhs_with_rhs<R: visit::Record>(
205+ lhs_entries: &mut IteratorType<immutable::TreeIter<'_>>,
206+ lhs: immutable::tree::Entry<'_>,
207+ rhs: immutable::tree::Entry<'_>,
208+ queue: &mut VecDeque<TreeInfoPair<R::PathId>>,
209+ delegate: &mut R,
210+) -> Result<(), Error> {
211+ use std::cmp::Ordering::*;
212+ delete_entry_schedule_recursion(lhs, queue, delegate)?;
213+ loop {
214+ match lhs_entries.peek() {
215+ Some(Ok(lhs)) => match lhs.filename.cmp(rhs.filename) {
216+ Equal => {
217+ let lhs = lhs_entries.next().expect("the peeked item to be present")?;
218+ handle_lhs_and_rhs_with_equal_filenames(lhs, rhs, queue, delegate)?;
219+ break;
220+ }
221+ Less => {
222+ let lhs = lhs_entries.next().expect("the peeked item to be present")?;
223+ delegate.pop_path_component();
224+ delete_entry_schedule_recursion(lhs, queue, delegate)?;
225+ }
226+ Greater => {
227+ delegate.pop_path_component();
228+ add_entry_schedule_recursion(rhs, queue, delegate)?;
229+ break;
230+ }
231+ },
232+ Some(Err(err)) => return Err(Error::EntriesDecode(err.to_owned())),
233+ None => {
234+ delegate.pop_path_component();
235+ add_entry_schedule_recursion(rhs, queue, delegate)?;
236+ break;
237+ }
238+ }
239+ }
240+ Ok(())
241+}
242+
240243 fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>(
241244 lhs: immutable::tree::Entry<'_>,
242245 rhs: immutable::tree::Entry<'_>,
@@ -346,6 +349,8 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 103 unmodified lines
346349 Ok(())
347350 }
348351
349−fn peekable<I: Iterator>(iter: I) -> std::mem::ManuallyDrop<std::iter::Peekable<I>> {
352+type IteratorType<I> = std::mem::ManuallyDrop<std::iter::Peekable<I>>;
353+
354+fn peekable<I: Iterator>(iter: I) -> IteratorType<I> {
350355 std::mem::ManuallyDrop::new(iter.peekable())
351356 }